1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | /* ----------------------------------------------------------------------- * |
3 | * |
4 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
5 | * |
6 | * H. Peter Anvin <hpa@linux.intel.com> |
7 | * |
8 | * ----------------------------------------------------------------------- |
9 | * |
10 | * Outputs a small assembly wrapper with the appropriate symbols defined. |
11 | */ |
12 | |
13 | #include <stdlib.h> |
14 | #include <stdio.h> |
15 | #include <string.h> |
16 | #include <inttypes.h> |
17 | #include <tools/le_byteshift.h> |
18 | |
19 | int main(int argc, char *argv[]) |
20 | { |
21 | uint32_t olen; |
22 | long ilen; |
23 | FILE *f = NULL; |
24 | int retval = 1; |
25 | |
26 | if (argc < 2) { |
27 | fprintf(stderr, format: "Usage: %s compressed_file\n" , argv[0]); |
28 | goto bail; |
29 | } |
30 | |
31 | /* Get the information for the compressed kernel image first */ |
32 | |
33 | f = fopen(filename: argv[1], modes: "r" ); |
34 | if (!f) { |
35 | perror(s: argv[1]); |
36 | goto bail; |
37 | } |
38 | |
39 | |
40 | if (fseek(stream: f, off: -4L, SEEK_END)) { |
41 | perror(s: argv[1]); |
42 | } |
43 | |
44 | if (fread(ptr: &olen, size: sizeof(olen), n: 1, stream: f) != 1) { |
45 | perror(s: argv[1]); |
46 | goto bail; |
47 | } |
48 | |
49 | ilen = ftell(stream: f); |
50 | olen = get_unaligned_le32(p: &olen); |
51 | |
52 | printf(format: ".section \".rodata..compressed\",\"a\",@progbits\n" ); |
53 | printf(format: ".globl z_input_len\n" ); |
54 | printf(format: "z_input_len = %lu\n" , ilen); |
55 | printf(format: ".globl z_output_len\n" ); |
56 | printf(format: "z_output_len = %lu\n" , (unsigned long)olen); |
57 | |
58 | printf(format: ".globl input_data, input_data_end\n" ); |
59 | printf(format: "input_data:\n" ); |
60 | printf(format: ".incbin \"%s\"\n" , argv[1]); |
61 | printf(format: "input_data_end:\n" ); |
62 | |
63 | printf(format: ".section \".rodata\",\"a\",@progbits\n" ); |
64 | printf(format: ".globl input_len\n" ); |
65 | printf(format: "input_len:\n\t.long %lu\n" , ilen); |
66 | printf(format: ".globl output_len\n" ); |
67 | printf(format: "output_len:\n\t.long %lu\n" , (unsigned long)olen); |
68 | |
69 | retval = 0; |
70 | bail: |
71 | if (f) |
72 | fclose(stream: f); |
73 | return retval; |
74 | } |
75 | |