0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/kernel.h>
0011 #include <linux/string.h>
0012 #include <asm/page.h>
0013 #include "decompressor.h"
0014
0015
0016
0017
0018 #define STATIC static
0019
0020 #undef memset
0021 #undef memcpy
0022 #undef memmove
0023 #define memmove memmove
0024 #define memzero(s, n) memset((s), 0, (n))
0025
0026 #ifdef CONFIG_KERNEL_BZIP2
0027 #define BOOT_HEAP_SIZE 0x400000
0028 #elif CONFIG_KERNEL_ZSTD
0029 #define BOOT_HEAP_SIZE 0x30000
0030 #else
0031 #define BOOT_HEAP_SIZE 0x10000
0032 #endif
0033
0034 static unsigned long free_mem_ptr = (unsigned long) _end;
0035 static unsigned long free_mem_end_ptr = (unsigned long) _end + BOOT_HEAP_SIZE;
0036
0037 #ifdef CONFIG_KERNEL_GZIP
0038 #include "../../../../lib/decompress_inflate.c"
0039 #endif
0040
0041 #ifdef CONFIG_KERNEL_BZIP2
0042 #include "../../../../lib/decompress_bunzip2.c"
0043 #endif
0044
0045 #ifdef CONFIG_KERNEL_LZ4
0046 #include "../../../../lib/decompress_unlz4.c"
0047 #endif
0048
0049 #ifdef CONFIG_KERNEL_LZMA
0050 #include "../../../../lib/decompress_unlzma.c"
0051 #endif
0052
0053 #ifdef CONFIG_KERNEL_LZO
0054 #include "../../../../lib/decompress_unlzo.c"
0055 #endif
0056
0057 #ifdef CONFIG_KERNEL_XZ
0058 #include "../../../../lib/decompress_unxz.c"
0059 #endif
0060
0061 #ifdef CONFIG_KERNEL_ZSTD
0062 #include "../../../../lib/decompress_unzstd.c"
0063 #endif
0064
0065 #define decompress_offset ALIGN((unsigned long)_end + BOOT_HEAP_SIZE, PAGE_SIZE)
0066
0067 unsigned long mem_safe_offset(void)
0068 {
0069
0070
0071
0072
0073
0074 return max(decompress_offset + vmlinux.image_size,
0075 vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size);
0076 }
0077
0078 void *decompress_kernel(void)
0079 {
0080 void *output = (void *)decompress_offset;
0081
0082 __decompress(_compressed_start, _compressed_end - _compressed_start,
0083 NULL, NULL, output, 0, NULL, error);
0084 return output;
0085 }