xref: /linux/arch/s390/boot/decompressor.c (revision edd4a8667355607345b76d5652adc0f300a28970)
1*edd4a866SHeiko Carstens // SPDX-License-Identifier: GPL-2.0
2*edd4a866SHeiko Carstens /*
3*edd4a866SHeiko Carstens  * Definitions and wrapper functions for kernel decompressor
4*edd4a866SHeiko Carstens  *
5*edd4a866SHeiko Carstens  * Copyright IBM Corp. 2010
6*edd4a866SHeiko Carstens  *
7*edd4a866SHeiko Carstens  * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
8*edd4a866SHeiko Carstens  */
9*edd4a866SHeiko Carstens 
10*edd4a866SHeiko Carstens #include <linux/kernel.h>
11*edd4a866SHeiko Carstens #include <linux/string.h>
12*edd4a866SHeiko Carstens #include <asm/page.h>
13*edd4a866SHeiko Carstens #include "decompressor.h"
14*edd4a866SHeiko Carstens 
15*edd4a866SHeiko Carstens /*
16*edd4a866SHeiko Carstens  * gzip declarations
17*edd4a866SHeiko Carstens  */
18*edd4a866SHeiko Carstens #define STATIC static
19*edd4a866SHeiko Carstens 
20*edd4a866SHeiko Carstens #undef memset
21*edd4a866SHeiko Carstens #undef memcpy
22*edd4a866SHeiko Carstens #undef memmove
23*edd4a866SHeiko Carstens #define memmove memmove
24*edd4a866SHeiko Carstens #define memzero(s, n) memset((s), 0, (n))
25*edd4a866SHeiko Carstens 
26*edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_BZIP2
27*edd4a866SHeiko Carstens #define BOOT_HEAP_SIZE	0x400000
28*edd4a866SHeiko Carstens #elif CONFIG_KERNEL_ZSTD
29*edd4a866SHeiko Carstens #define BOOT_HEAP_SIZE	0x30000
30*edd4a866SHeiko Carstens #else
31*edd4a866SHeiko Carstens #define BOOT_HEAP_SIZE	0x10000
32*edd4a866SHeiko Carstens #endif
33*edd4a866SHeiko Carstens 
34*edd4a866SHeiko Carstens static unsigned long free_mem_ptr = (unsigned long) _end;
35*edd4a866SHeiko Carstens static unsigned long free_mem_end_ptr = (unsigned long) _end + BOOT_HEAP_SIZE;
36*edd4a866SHeiko Carstens 
37*edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_GZIP
38*edd4a866SHeiko Carstens #include "../../../../lib/decompress_inflate.c"
39*edd4a866SHeiko Carstens #endif
40*edd4a866SHeiko Carstens 
41*edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_BZIP2
42*edd4a866SHeiko Carstens #include "../../../../lib/decompress_bunzip2.c"
43*edd4a866SHeiko Carstens #endif
44*edd4a866SHeiko Carstens 
45*edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_LZ4
46*edd4a866SHeiko Carstens #include "../../../../lib/decompress_unlz4.c"
47*edd4a866SHeiko Carstens #endif
48*edd4a866SHeiko Carstens 
49*edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_LZMA
50*edd4a866SHeiko Carstens #include "../../../../lib/decompress_unlzma.c"
51*edd4a866SHeiko Carstens #endif
52*edd4a866SHeiko Carstens 
53*edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_LZO
54*edd4a866SHeiko Carstens #include "../../../../lib/decompress_unlzo.c"
55*edd4a866SHeiko Carstens #endif
56*edd4a866SHeiko Carstens 
57*edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_XZ
58*edd4a866SHeiko Carstens #include "../../../../lib/decompress_unxz.c"
59*edd4a866SHeiko Carstens #endif
60*edd4a866SHeiko Carstens 
61*edd4a866SHeiko Carstens #ifdef CONFIG_KERNEL_ZSTD
62*edd4a866SHeiko Carstens #include "../../../../lib/decompress_unzstd.c"
63*edd4a866SHeiko Carstens #endif
64*edd4a866SHeiko Carstens 
65*edd4a866SHeiko Carstens #define decompress_offset ALIGN((unsigned long)_end + BOOT_HEAP_SIZE, PAGE_SIZE)
66*edd4a866SHeiko Carstens 
67*edd4a866SHeiko Carstens unsigned long mem_safe_offset(void)
68*edd4a866SHeiko Carstens {
69*edd4a866SHeiko Carstens 	/*
70*edd4a866SHeiko Carstens 	 * due to 4MB HEAD_SIZE for bzip2
71*edd4a866SHeiko Carstens 	 * 'decompress_offset + vmlinux.image_size' could be larger than
72*edd4a866SHeiko Carstens 	 * kernel at final position + its .bss, so take the larger of two
73*edd4a866SHeiko Carstens 	 */
74*edd4a866SHeiko Carstens 	return max(decompress_offset + vmlinux.image_size,
75*edd4a866SHeiko Carstens 		   vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size);
76*edd4a866SHeiko Carstens }
77*edd4a866SHeiko Carstens 
78*edd4a866SHeiko Carstens void *decompress_kernel(void)
79*edd4a866SHeiko Carstens {
80*edd4a866SHeiko Carstens 	void *output = (void *)decompress_offset;
81*edd4a866SHeiko Carstens 
82*edd4a866SHeiko Carstens 	__decompress(_compressed_start, _compressed_end - _compressed_start,
83*edd4a866SHeiko Carstens 		     NULL, NULL, output, 0, NULL, error);
84*edd4a866SHeiko Carstens 	return output;
85*edd4a866SHeiko Carstens }
86