| 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 <schwidefsky@de.ibm.com> |
| 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 | |
| 67 | static void decompress_error(char *m) |
| 68 | { |
| 69 | if (bootdebug) |
| 70 | boot_rb_dump(); |
| 71 | boot_panic("Decompression error: %s\n" , m); |
| 72 | } |
| 73 | |
| 74 | unsigned long mem_safe_offset(void) |
| 75 | { |
| 76 | return ALIGN(free_mem_end_ptr, PAGE_SIZE); |
| 77 | } |
| 78 | |
| 79 | void deploy_kernel(void *output) |
| 80 | { |
| 81 | __decompress(buf: _compressed_start, len: _compressed_end - _compressed_start, |
| 82 | NULL, NULL, out_buf: output, vmlinux.image_size, NULL, error: decompress_error); |
| 83 | } |
| 84 | |