1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Definitions and wrapper functions for kernel decompressor
4 *
5 * Copyright IBM Corp. 2010
6 *
7 * Author(s): Martin Schwidefsky <[email protected]>
8 */
9
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <asm/boot_data.h>
13 #include <asm/page.h>
14 #include "decompressor.h"
15 #include "boot.h"
16
17 /*
18 * gzip declarations
19 */
20 #define STATIC static
21
22 #undef memset
23 #undef memcpy
24 #undef memmove
25 #define memmove memmove
26 #define memzero(s, n) memset((s), 0, (n))
27
28 #if defined(CONFIG_KERNEL_BZIP2)
29 #define BOOT_HEAP_SIZE 0x400000
30 #elif defined(CONFIG_KERNEL_ZSTD)
31 #define BOOT_HEAP_SIZE 0x30000
32 #else
33 #define BOOT_HEAP_SIZE 0x10000
34 #endif
35
36 static unsigned long free_mem_ptr = (unsigned long) _end;
37 static unsigned long free_mem_end_ptr = (unsigned long) _end + BOOT_HEAP_SIZE;
38
39 #ifdef CONFIG_KERNEL_GZIP
40 #include "../../../../lib/decompress_inflate.c"
41 #endif
42
43 #ifdef CONFIG_KERNEL_BZIP2
44 #include "../../../../lib/decompress_bunzip2.c"
45 #endif
46
47 #ifdef CONFIG_KERNEL_LZ4
48 #include "../../../../lib/decompress_unlz4.c"
49 #endif
50
51 #ifdef CONFIG_KERNEL_LZMA
52 #include "../../../../lib/decompress_unlzma.c"
53 #endif
54
55 #ifdef CONFIG_KERNEL_LZO
56 #include "../../../../lib/decompress_unlzo.c"
57 #endif
58
59 #ifdef CONFIG_KERNEL_XZ
60 #include "../../../../lib/decompress_unxz.c"
61 #endif
62
63 #ifdef CONFIG_KERNEL_ZSTD
64 #include "../../../../lib/decompress_unzstd.c"
65 #endif
66
decompress_error(char * m)67 static void decompress_error(char *m)
68 {
69 if (bootdebug)
70 boot_rb_dump();
71 boot_emerg("Decompression error: %s\n", m);
72 boot_emerg(" -- System halted\n");
73 disabled_wait();
74 }
75
mem_safe_offset(void)76 unsigned long mem_safe_offset(void)
77 {
78 return ALIGN(free_mem_end_ptr, PAGE_SIZE);
79 }
80
deploy_kernel(void * output)81 void deploy_kernel(void *output)
82 {
83 __decompress(_compressed_start, _compressed_end - _compressed_start,
84 NULL, NULL, output, vmlinux.image_size, NULL, decompress_error);
85 }
86