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