Linux Audio

Check our new training course

Loading...
v3.1
 
  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
 33static uint32_t getle32(const void *p)
 34{
 35	const uint8_t *cp = p;
 36
 37	return (uint32_t)cp[0] + ((uint32_t)cp[1] << 8) +
 38		((uint32_t)cp[2] << 16) + ((uint32_t)cp[3] << 24);
 39}
 40
 41int main(int argc, char *argv[])
 42{
 43	uint32_t olen;
 44	long ilen;
 45	unsigned long offs;
 46	FILE *f;
 47
 48	if (argc < 2) {
 49		fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
 50		return 1;
 51	}
 52
 53	/* Get the information for the compressed kernel image first */
 54
 55	f = fopen(argv[1], "r");
 56	if (!f) {
 57		perror(argv[1]);
 58		return 1;
 59	}
 60
 61
 62	if (fseek(f, -4L, SEEK_END)) {
 63		perror(argv[1]);
 64	}
 65
 66	if (fread(&olen, sizeof(olen), 1, f) != 1) {
 67		perror(argv[1]);
 68		return 1;
 69	}
 70
 71	ilen = ftell(f);
 72	olen = getle32(&olen);
 73	fclose(f);
 74
 75	/*
 76	 * Now we have the input (compressed) and output (uncompressed)
 77	 * sizes, compute the necessary decompression offset...
 78	 */
 79
 80	offs = (olen > ilen) ? olen - ilen : 0;
 81	offs += olen >> 12;	/* Add 8 bytes for each 32K block */
 82	offs += 64*1024 + 128;	/* Add 64K + 128 bytes slack */
 83	offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
 84
 85	printf(".section \".rodata..compressed\",\"a\",@progbits\n");
 86	printf(".globl z_input_len\n");
 87	printf("z_input_len = %lu\n", ilen);
 88	printf(".globl z_output_len\n");
 89	printf("z_output_len = %lu\n", (unsigned long)olen);
 90	printf(".globl z_extract_offset\n");
 91	printf("z_extract_offset = 0x%lx\n", offs);
 92	/* z_extract_offset_negative allows simplification of head_32.S */
 93	printf(".globl z_extract_offset_negative\n");
 94	printf("z_extract_offset_negative = -0x%lx\n", offs);
 95
 96	printf(".globl input_data, input_data_end\n");
 97	printf("input_data:\n");
 98	printf(".incbin \"%s\"\n", argv[1]);
 99	printf("input_data_end:\n");
100
101	return 0;
 
 
 
 
102}
v5.9
 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
19int 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, "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(argv[1], "r");
34	if (!f) {
35		perror(argv[1]);
36		goto bail;
37	}
38
39
40	if (fseek(f, -4L, SEEK_END)) {
41		perror(argv[1]);
42	}
43
44	if (fread(&olen, sizeof(olen), 1, f) != 1) {
45		perror(argv[1]);
46		goto bail;
47	}
48
49	ilen = ftell(f);
50	olen = get_unaligned_le32(&olen);
 
 
 
 
 
 
 
 
 
 
 
51
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);
 
 
 
 
 
57
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");
62
63	retval = 0;
64bail:
65	if (f)
66		fclose(f);
67	return retval;
68}