2 * Definitions and wrapper functions for kernel decompressor
4 * Copyright IBM Corp. 2010
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
9 #include <linux/uaccess.h>
23 #define memmove memmove
24 #define memzero(s, n) memset((s), 0, (n))
26 /* Symbols defined by linker scripts */
27 extern char input_data[];
29 extern char _text, _end;
30 extern char _bss, _ebss;
32 static void error(char *m);
34 static unsigned long free_mem_ptr;
35 static unsigned long free_mem_end_ptr;
37 #ifdef CONFIG_HAVE_KERNEL_BZIP2
38 #define HEAP_SIZE 0x400000
40 #define HEAP_SIZE 0x10000
43 #ifdef CONFIG_KERNEL_GZIP
44 #include "../../../../lib/decompress_inflate.c"
47 #ifdef CONFIG_KERNEL_BZIP2
48 #include "../../../../lib/decompress_bunzip2.c"
51 #ifdef CONFIG_KERNEL_LZ4
52 #include "../../../../lib/decompress_unlz4.c"
55 #ifdef CONFIG_KERNEL_LZMA
56 #include "../../../../lib/decompress_unlzma.c"
59 #ifdef CONFIG_KERNEL_LZO
60 #include "../../../../lib/decompress_unlzo.c"
63 #ifdef CONFIG_KERNEL_XZ
64 #include "../../../../lib/decompress_unxz.c"
67 static int puts(const char *s)
73 void *memset(void *s, int c, size_t n)
83 void *memcpy(void *dest, const void *src, size_t n)
93 void *memmove(void *dest, const void *src, size_t n)
110 static void error(char *x)
112 unsigned long long psw = 0x000a0000deadbeefULL;
116 puts("\n\n -- System halted");
118 asm volatile("lpsw %0" : : "Q" (psw));
122 * Safe guard the ipl parameter block against a memory area that will be
123 * overwritten. The validity check for the ipl parameter block is complex
124 * (see cio_get_iplinfo and ipl_save_parameters) but if the pointer to
125 * the ipl parameter block intersects with the passed memory area we can
126 * safely assume that we can read from that memory. In that case just copy
127 * the memory to IPL_PARMBLOCK_ORIGIN even if there is no ipl parameter
130 static void check_ipl_parmblock(void *start, unsigned long size)
134 src = (void *)(unsigned long) S390_lowcore.ipl_parmblock_ptr;
135 if (src + PAGE_SIZE <= start || src >= start + size)
137 dst = (void *) IPL_PARMBLOCK_ORIGIN;
138 memmove(dst, src, PAGE_SIZE);
139 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
142 unsigned long decompress_kernel(void)
144 void *output, *kernel_end;
146 output = (void *) ALIGN((unsigned long) &_end + HEAP_SIZE, PAGE_SIZE);
147 kernel_end = output + SZ__bss_start;
148 check_ipl_parmblock((void *) 0, (unsigned long) kernel_end);
150 #ifdef CONFIG_BLK_DEV_INITRD
152 * Move the initrd right behind the end of the decompressed
153 * kernel image. This also prevents initrd corruption caused by
154 * bss clearing since kernel_end will always be located behind the
155 * current bss section..
157 if (INITRD_START && INITRD_SIZE && kernel_end > (void *) INITRD_START) {
158 check_ipl_parmblock(kernel_end, INITRD_SIZE);
159 memmove(kernel_end, (void *) INITRD_START, INITRD_SIZE);
160 INITRD_START = (unsigned long) kernel_end;
165 * Clear bss section. free_mem_ptr and free_mem_end_ptr need to be
166 * initialized afterwards since they reside in bss.
168 memset(&_bss, 0, &_ebss - &_bss);
169 free_mem_ptr = (unsigned long) &_end;
170 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
172 puts("Uncompressing Linux... ");
173 __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
174 puts("Ok, booting the kernel.\n");
175 return (unsigned long) output;