Linux Audio

Check our new training course

Loading...
v3.15
 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 *
21 * ----------------------------------------------------------------------- */
22
23/*
24 * Compute the desired load offset from a compressed program; outputs
25 * a small assembly wrapper with the appropriate symbols defined.
26 */
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <inttypes.h>
32#include <tools/le_byteshift.h>
33
34int main(int argc, char *argv[])
35{
36	uint32_t olen;
37	long ilen;
38	unsigned long offs;
 
39	FILE *f = NULL;
40	int retval = 1;
41
42	if (argc < 2) {
43		fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
 
44		goto bail;
45	}
46
47	/* Get the information for the compressed kernel image first */
48
49	f = fopen(argv[1], "r");
50	if (!f) {
51		perror(argv[1]);
52		goto bail;
53	}
54
55
56	if (fseek(f, -4L, SEEK_END)) {
57		perror(argv[1]);
58	}
59
60	if (fread(&olen, sizeof(olen), 1, f) != 1) {
61		perror(argv[1]);
62		goto bail;
63	}
64
65	ilen = ftell(f);
66	olen = get_unaligned_le32(&olen);
67
68	/*
69	 * Now we have the input (compressed) and output (uncompressed)
70	 * sizes, compute the necessary decompression offset...
71	 */
72
73	offs = (olen > ilen) ? olen - ilen : 0;
74	offs += olen >> 12;	/* Add 8 bytes for each 32K block */
75	offs += 64*1024 + 128;	/* Add 64K + 128 bytes slack */
76	offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
 
77
78	printf(".section \".rodata..compressed\",\"a\",@progbits\n");
79	printf(".globl z_input_len\n");
80	printf("z_input_len = %lu\n", ilen);
81	printf(".globl z_output_len\n");
82	printf("z_output_len = %lu\n", (unsigned long)olen);
83	printf(".globl z_extract_offset\n");
84	printf("z_extract_offset = 0x%lx\n", offs);
85	/* z_extract_offset_negative allows simplification of head_32.S */
86	printf(".globl z_extract_offset_negative\n");
87	printf("z_extract_offset_negative = -0x%lx\n", offs);
 
 
88
89	printf(".globl input_data, input_data_end\n");
90	printf("input_data:\n");
91	printf(".incbin \"%s\"\n", argv[1]);
92	printf("input_data_end:\n");
93
94	retval = 0;
95bail:
96	if (f)
97		fclose(f);
98	return retval;
99}
v4.6
  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 *
 21 * ----------------------------------------------------------------------- */
 22
 23/*
 24 * Compute the desired load offset from a compressed program; outputs
 25 * a small assembly wrapper with the appropriate symbols defined.
 26 */
 27
 28#include <stdlib.h>
 29#include <stdio.h>
 30#include <string.h>
 31#include <inttypes.h>
 32#include <tools/le_byteshift.h>
 33
 34int main(int argc, char *argv[])
 35{
 36	uint32_t olen;
 37	long ilen;
 38	unsigned long offs;
 39	unsigned long run_size;
 40	FILE *f = NULL;
 41	int retval = 1;
 42
 43	if (argc < 3) {
 44		fprintf(stderr, "Usage: %s compressed_file run_size\n",
 45				argv[0]);
 46		goto bail;
 47	}
 48
 49	/* Get the information for the compressed kernel image first */
 50
 51	f = fopen(argv[1], "r");
 52	if (!f) {
 53		perror(argv[1]);
 54		goto bail;
 55	}
 56
 57
 58	if (fseek(f, -4L, SEEK_END)) {
 59		perror(argv[1]);
 60	}
 61
 62	if (fread(&olen, sizeof(olen), 1, f) != 1) {
 63		perror(argv[1]);
 64		goto bail;
 65	}
 66
 67	ilen = ftell(f);
 68	olen = get_unaligned_le32(&olen);
 69
 70	/*
 71	 * Now we have the input (compressed) and output (uncompressed)
 72	 * sizes, compute the necessary decompression offset...
 73	 */
 74
 75	offs = (olen > ilen) ? olen - ilen : 0;
 76	offs += olen >> 12;	/* Add 8 bytes for each 32K block */
 77	offs += 64*1024 + 128;	/* Add 64K + 128 bytes slack */
 78	offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
 79	run_size = atoi(argv[2]);
 80
 81	printf(".section \".rodata..compressed\",\"a\",@progbits\n");
 82	printf(".globl z_input_len\n");
 83	printf("z_input_len = %lu\n", ilen);
 84	printf(".globl z_output_len\n");
 85	printf("z_output_len = %lu\n", (unsigned long)olen);
 86	printf(".globl z_extract_offset\n");
 87	printf("z_extract_offset = 0x%lx\n", offs);
 88	/* z_extract_offset_negative allows simplification of head_32.S */
 89	printf(".globl z_extract_offset_negative\n");
 90	printf("z_extract_offset_negative = -0x%lx\n", offs);
 91	printf(".globl z_run_size\n");
 92	printf("z_run_size = %lu\n", run_size);
 93
 94	printf(".globl input_data, input_data_end\n");
 95	printf("input_data:\n");
 96	printf(".incbin \"%s\"\n", argv[1]);
 97	printf("input_data_end:\n");
 98
 99	retval = 0;
100bail:
101	if (f)
102		fclose(f);
103	return retval;
104}