Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / x86 / boot / compressed / mkpiggy.c
blob52aa56cdbaccf8df82c94a4a5d66ffd5759d2bb7
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* ----------------------------------------------------------------------- *
4 * Copyright (C) 2009 Intel Corporation. All rights reserved.
6 * H. Peter Anvin <hpa@linux.intel.com>
8 * -----------------------------------------------------------------------
10 * Outputs a small assembly wrapper with the appropriate symbols defined.
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <inttypes.h>
17 #include <tools/le_byteshift.h>
19 int main(int argc, char *argv[])
21 uint32_t olen;
22 long ilen;
23 FILE *f = NULL;
24 int retval = 1;
26 if (argc < 2) {
27 fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
28 goto bail;
31 /* Get the information for the compressed kernel image first */
33 f = fopen(argv[1], "r");
34 if (!f) {
35 perror(argv[1]);
36 goto bail;
40 if (fseek(f, -4L, SEEK_END)) {
41 perror(argv[1]);
44 if (fread(&olen, sizeof(olen), 1, f) != 1) {
45 perror(argv[1]);
46 goto bail;
49 ilen = ftell(f);
50 olen = get_unaligned_le32(&olen);
52 printf(".section \".rodata..compressed\",\"a\",@progbits\n");
53 printf(".globl z_input_len\n");
54 printf("z_input_len = %lu\n", ilen);
55 printf(".globl z_output_len\n");
56 printf("z_output_len = %lu\n", (unsigned long)olen);
58 printf(".globl input_data, input_data_end\n");
59 printf("input_data:\n");
60 printf(".incbin \"%s\"\n", argv[1]);
61 printf("input_data_end:\n");
63 printf(".section \".rodata\",\"a\",@progbits\n");
64 printf(".globl input_len\n");
65 printf("input_len:\n\t.long %lu\n", ilen);
66 printf(".globl output_len\n");
67 printf("output_len:\n\t.long %lu\n", (unsigned long)olen);
69 retval = 0;
70 bail:
71 if (f)
72 fclose(f);
73 return retval;