]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/parisc/boot/compressed/misc.c
2 * Definitions and wrapper functions for kernel decompressor
4 * (C) 2017 Helge Deller <deller@gmx.de>
7 #include <linux/uaccess.h>
8 #include <asm/unaligned.h>
18 #define memmove memmove
19 #define memzero(s, n) memset((s), 0, (n))
21 #define malloc malloc_gzip
22 #define free free_gzip
24 /* Symbols defined by linker scripts */
25 extern char input_data
[];
27 extern __le32 output_len
; /* at unaligned address, little-endian */
28 extern char _text
, _end
;
29 extern char _bss
, _ebss
;
30 extern char _startcode_end
;
31 extern void startup_continue(void *entry
, unsigned long cmdline
,
32 unsigned long rd_start
, unsigned long rd_end
) __noreturn
;
34 void error(char *m
) __noreturn
;
36 static unsigned long free_mem_ptr
;
37 static unsigned long free_mem_end_ptr
;
39 #ifdef CONFIG_KERNEL_GZIP
40 #include "../../../../lib/decompress_inflate.c"
43 #ifdef CONFIG_KERNEL_BZIP2
44 #include "../../../../lib/decompress_bunzip2.c"
47 #ifdef CONFIG_KERNEL_LZ4
48 #include "../../../../lib/decompress_unlz4.c"
51 #ifdef CONFIG_KERNEL_LZMA
52 #include "../../../../lib/decompress_unlzma.c"
55 #ifdef CONFIG_KERNEL_LZO
56 #include "../../../../lib/decompress_unlzo.c"
59 #ifdef CONFIG_KERNEL_XZ
60 #include "../../../../lib/decompress_unxz.c"
63 void *memmove(void *dest
, const void *src
, size_t n
)
80 void *memset(void *s
, int c
, size_t count
)
89 void *memcpy(void *d
, const void *s
, size_t len
)
91 char *dest
= (char *)d
;
92 const char *source
= (const char *)s
;
99 size_t strlen(const char *s
)
103 for (sc
= s
; *sc
!= '\0'; ++sc
)
108 char *strchr(const char *s
, int c
)
118 int puts(const char *s
)
120 const char *nuline
= s
;
122 while ((nuline
= strchr(s
, '\n')) != NULL
) {
124 pdc_iodc_print(s
, nuline
- s
);
125 pdc_iodc_print("\r\n", 2);
129 pdc_iodc_print(s
, strlen(s
));
134 static int putchar(int c
)
144 void __noreturn
error(char *x
)
148 puts("\n\n -- System halted");
149 while (1) /* wait forever */
153 static int print_hex(unsigned long num
)
155 const char hex
[] = "0123456789abcdef";
157 int i
= sizeof(str
)-1;
161 str
[i
--] = hex
[num
& 0x0f];
172 int printf(const char *fmt
, ...)
189 print_hex(va_arg(args
, unsigned long));
196 /* helper functions for libgcc */
203 void *malloc(size_t size
)
205 return malloc_gzip(size
);
211 return free_gzip(ptr
);
215 static void flush_data_cache(char *start
, unsigned long length
)
217 char *end
= start
+ length
;
220 asm volatile("fdc 0(%0)" : : "r" (start
));
221 asm volatile("fic 0(%%sr0,%0)" : : "r" (start
));
223 } while (start
< end
);
224 asm volatile("fdc 0(%0)" : : "r" (end
));
229 unsigned long decompress_kernel(unsigned int started_wide
,
230 unsigned int command_line
,
231 const unsigned int rd_start
,
232 const unsigned int rd_end
)
235 unsigned long len
, len_all
;
238 parisc_narrow_firmware
= 0;
241 set_firmware_width_unlocked();
243 putchar('U'); /* if you get this p and no more, string storage */
244 /* in $GLOBAL$ is wrong or %dp is wrong */
245 puts("ncompressing ...\n");
247 output
= (char *) KERNEL_BINARY_TEXT_START
;
248 len_all
= __pa(SZ_end
) - __pa(SZparisc_kernel_start
);
250 if ((unsigned long) &_startcode_end
> (unsigned long) output
)
251 error("Bootcode overlaps kernel code");
253 len
= get_unaligned_le32(&output_len
);
255 error("Output len too big.");
257 memset(&output
[len
], 0, len_all
- len
);
260 * Initialize free_mem_ptr and free_mem_end_ptr.
262 free_mem_ptr
= (unsigned long) &_ebss
;
263 free_mem_ptr
+= 2*1024*1024; /* leave 2 MB for stack */
265 /* Limit memory for bootoader to 1GB */
266 #define ARTIFICIAL_LIMIT (1*1024*1024*1024)
267 free_mem_end_ptr
= PAGE0
->imm_max_mem
;
268 if (free_mem_end_ptr
> ARTIFICIAL_LIMIT
)
269 free_mem_end_ptr
= ARTIFICIAL_LIMIT
;
271 #ifdef CONFIG_BLK_DEV_INITRD
272 /* if we have ramdisk this is at end of memory */
273 if (rd_start
&& rd_start
< free_mem_end_ptr
)
274 free_mem_end_ptr
= rd_start
;
278 printf("startcode_end = %x\n", &_startcode_end
);
279 printf("commandline = %x\n", command_line
);
280 printf("rd_start = %x\n", rd_start
);
281 printf("rd_end = %x\n", rd_end
);
283 printf("free_ptr = %x\n", free_mem_ptr
);
284 printf("free_ptr_end = %x\n", free_mem_end_ptr
);
286 printf("input_data = %x\n", input_data
);
287 printf("input_len = %x\n", input_len
);
288 printf("output = %x\n", output
);
289 printf("output_len = %x\n", len
);
290 printf("output_max = %x\n", len_all
);
293 __decompress(input_data
, input_len
, NULL
, NULL
,
294 output
, 0, NULL
, error
);
296 flush_data_cache(output
, len
);
298 printf("Booting kernel ...\n\n");
300 return (unsigned long) output
;