H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------- * |
| 2 | * |
| 3 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version |
| 7 | * 2 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 | * 02110-1301, USA. |
| 18 | * |
| 19 | * H. Peter Anvin <hpa@linux.intel.com> |
| 20 | * |
Yinghai Lu | d607251 | 2016-04-28 17:09:05 -0700 | [diff] [blame] | 21 | * ----------------------------------------------------------------------- |
| 22 | * |
| 23 | * Outputs a small assembly wrapper with the appropriate symbols defined. |
| 24 | * |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include <stdlib.h> |
| 28 | #include <stdio.h> |
| 29 | #include <string.h> |
| 30 | #include <inttypes.h> |
Matt Fleming | 12871c5 | 2012-02-28 13:37:22 +0000 | [diff] [blame] | 31 | #include <tools/le_byteshift.h> |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 32 | |
| 33 | int main(int argc, char *argv[]) |
| 34 | { |
| 35 | uint32_t olen; |
| 36 | long ilen; |
Geyslan G. Bem | 49449c30c | 2013-10-07 19:16:59 -0300 | [diff] [blame] | 37 | FILE *f = NULL; |
| 38 | int retval = 1; |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 39 | |
Yinghai Lu | 4d2d542 | 2016-04-28 17:09:07 -0700 | [diff] [blame] | 40 | if (argc < 2) { |
| 41 | fprintf(stderr, "Usage: %s compressed_file\n", argv[0]); |
Geyslan G. Bem | 49449c30c | 2013-10-07 19:16:59 -0300 | [diff] [blame] | 42 | goto bail; |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /* Get the information for the compressed kernel image first */ |
| 46 | |
| 47 | f = fopen(argv[1], "r"); |
| 48 | if (!f) { |
| 49 | perror(argv[1]); |
Geyslan G. Bem | 49449c30c | 2013-10-07 19:16:59 -0300 | [diff] [blame] | 50 | goto bail; |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
| 54 | if (fseek(f, -4L, SEEK_END)) { |
| 55 | perror(argv[1]); |
| 56 | } |
Daniel J Blueman | 6670e9c | 2011-02-23 09:33:59 +0800 | [diff] [blame] | 57 | |
| 58 | if (fread(&olen, sizeof(olen), 1, f) != 1) { |
| 59 | perror(argv[1]); |
Geyslan G. Bem | 49449c30c | 2013-10-07 19:16:59 -0300 | [diff] [blame] | 60 | goto bail; |
Daniel J Blueman | 6670e9c | 2011-02-23 09:33:59 +0800 | [diff] [blame] | 61 | } |
| 62 | |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 63 | ilen = ftell(f); |
Matt Fleming | 12871c5 | 2012-02-28 13:37:22 +0000 | [diff] [blame] | 64 | olen = get_unaligned_le32(&olen); |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 65 | |
Denys Vlasenko | 041d5f9 | 2010-02-20 01:03:46 +0100 | [diff] [blame] | 66 | printf(".section \".rodata..compressed\",\"a\",@progbits\n"); |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 67 | printf(".globl z_input_len\n"); |
| 68 | printf("z_input_len = %lu\n", ilen); |
| 69 | printf(".globl z_output_len\n"); |
| 70 | printf("z_output_len = %lu\n", (unsigned long)olen); |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 71 | |
| 72 | printf(".globl input_data, input_data_end\n"); |
| 73 | printf("input_data:\n"); |
| 74 | printf(".incbin \"%s\"\n", argv[1]); |
| 75 | printf("input_data_end:\n"); |
| 76 | |
Geyslan G. Bem | 49449c30c | 2013-10-07 19:16:59 -0300 | [diff] [blame] | 77 | retval = 0; |
| 78 | bail: |
| 79 | if (f) |
| 80 | fclose(f); |
| 81 | return retval; |
H. Peter Anvin | 02a884c | 2009-05-08 17:42:16 -0700 | [diff] [blame] | 82 | } |