Blame view
arch/x86/boot/compressed/mkpiggy.c
2.83 KB
02a884c0f x86, boot: determ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/* ----------------------------------------------------------------------- * * * Copyright (C) 2009 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. * * H. Peter Anvin <hpa@linux.intel.com> * * ----------------------------------------------------------------------- */ /* * Compute the desired load offset from a compressed program; outputs * a small assembly wrapper with the appropriate symbols defined. */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <inttypes.h> |
12871c568 x86, mkpiggy: Don... |
32 |
#include <tools/le_byteshift.h> |
02a884c0f x86, boot: determ... |
33 34 35 36 37 38 |
int main(int argc, char *argv[]) { uint32_t olen; long ilen; unsigned long offs; |
e6023367d x86, kaslr: Preve... |
39 |
unsigned long run_size; |
49449c30c x86: mkpiggy.c: E... |
40 41 |
FILE *f = NULL; int retval = 1; |
02a884c0f x86, boot: determ... |
42 |
|
e6023367d x86, kaslr: Preve... |
43 44 45 46 |
if (argc < 3) { fprintf(stderr, "Usage: %s compressed_file run_size ", argv[0]); |
49449c30c x86: mkpiggy.c: E... |
47 |
goto bail; |
02a884c0f x86, boot: determ... |
48 49 50 51 52 53 54 |
} /* Get the information for the compressed kernel image first */ f = fopen(argv[1], "r"); if (!f) { perror(argv[1]); |
49449c30c x86: mkpiggy.c: E... |
55 |
goto bail; |
02a884c0f x86, boot: determ... |
56 57 58 59 60 61 |
} if (fseek(f, -4L, SEEK_END)) { perror(argv[1]); } |
6670e9cda x86, build: Make ... |
62 63 64 |
if (fread(&olen, sizeof(olen), 1, f) != 1) { perror(argv[1]); |
49449c30c x86: mkpiggy.c: E... |
65 |
goto bail; |
6670e9cda x86, build: Make ... |
66 |
} |
02a884c0f x86, boot: determ... |
67 |
ilen = ftell(f); |
12871c568 x86, mkpiggy: Don... |
68 |
olen = get_unaligned_le32(&olen); |
02a884c0f x86, boot: determ... |
69 70 71 72 73 74 75 76 |
/* * Now we have the input (compressed) and output (uncompressed) * sizes, compute the necessary decompression offset... */ offs = (olen > ilen) ? olen - ilen : 0; offs += olen >> 12; /* Add 8 bytes for each 32K block */ |
303148045 x86: support XZ-c... |
77 |
offs += 64*1024 + 128; /* Add 64K + 128 bytes slack */ |
02a884c0f x86, boot: determ... |
78 |
offs = (offs+4095) & ~4095; /* Round to a 4K boundary */ |
e6023367d x86, kaslr: Preve... |
79 |
run_size = atoi(argv[2]); |
02a884c0f x86, boot: determ... |
80 |
|
041d5f94c Rename .rodata.co... |
81 82 |
printf(".section \".rodata..compressed\",\"a\",@progbits "); |
02a884c0f x86, boot: determ... |
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
printf(".globl z_input_len "); printf("z_input_len = %lu ", ilen); printf(".globl z_output_len "); printf("z_output_len = %lu ", (unsigned long)olen); printf(".globl z_extract_offset "); printf("z_extract_offset = 0x%lx ", offs); /* z_extract_offset_negative allows simplification of head_32.S */ printf(".globl z_extract_offset_negative "); printf("z_extract_offset_negative = -0x%lx ", offs); |
e6023367d x86, kaslr: Preve... |
100 101 102 103 |
printf(".globl z_run_size "); printf("z_run_size = %lu ", run_size); |
02a884c0f x86, boot: determ... |
104 105 106 107 108 109 110 111 112 |
printf(".globl input_data, input_data_end "); printf("input_data: "); printf(".incbin \"%s\" ", argv[1]); printf("input_data_end: "); |
49449c30c x86: mkpiggy.c: E... |
113 114 115 116 117 |
retval = 0; bail: if (f) fclose(f); return retval; |
02a884c0f x86, boot: determ... |
118 |
} |