0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #define DISABLE_BRANCH_PROFILING
0011
0012 #include <linux/types.h>
0013 #include <linux/kernel.h>
0014 #include <linux/string.h>
0015 #include <linux/libfdt.h>
0016
0017 #include <asm/addrspace.h>
0018 #include <asm/unaligned.h>
0019 #include <asm-generic/vmlinux.lds.h>
0020
0021
0022
0023
0024
0025 unsigned long free_mem_ptr;
0026 unsigned long free_mem_end_ptr;
0027
0028
0029 extern unsigned char __image_begin[], __image_end[];
0030
0031
0032 #ifdef CONFIG_DEBUG_ZBOOT
0033 extern void puts(const char *s);
0034 extern void puthex(unsigned long long val);
0035 #else
0036 #define puts(s) do {} while (0)
0037 #define puthex(val) do {} while (0)
0038 #endif
0039
0040 extern char __appended_dtb[];
0041
0042 void error(char *x)
0043 {
0044 puts("\n\n");
0045 puts(x);
0046 puts("\n\n -- System halted");
0047
0048 while (1)
0049 ;
0050 }
0051
0052
0053 #define STATIC static
0054
0055 #ifdef CONFIG_KERNEL_GZIP
0056 #include "../../../../lib/decompress_inflate.c"
0057 #endif
0058
0059 #ifdef CONFIG_KERNEL_BZIP2
0060 #include "../../../../lib/decompress_bunzip2.c"
0061 #endif
0062
0063 #ifdef CONFIG_KERNEL_LZ4
0064 #include "../../../../lib/decompress_unlz4.c"
0065 #endif
0066
0067 #ifdef CONFIG_KERNEL_LZMA
0068 #include "../../../../lib/decompress_unlzma.c"
0069 #endif
0070
0071 #ifdef CONFIG_KERNEL_LZO
0072 #include "../../../../lib/decompress_unlzo.c"
0073 #endif
0074
0075 #ifdef CONFIG_KERNEL_XZ
0076 #include "../../../../lib/decompress_unxz.c"
0077 #endif
0078
0079 #ifdef CONFIG_KERNEL_ZSTD
0080 #include "../../../../lib/decompress_unzstd.c"
0081 #endif
0082
0083 const unsigned long __stack_chk_guard = 0x000a0dff;
0084
0085 void __stack_chk_fail(void)
0086 {
0087 error("stack-protector: Kernel stack is corrupted\n");
0088 }
0089
0090 void decompress_kernel(unsigned long boot_heap_start)
0091 {
0092 unsigned long zimage_start, zimage_size;
0093
0094 zimage_start = (unsigned long)(__image_begin);
0095 zimage_size = (unsigned long)(__image_end) -
0096 (unsigned long)(__image_begin);
0097
0098 puts("zimage at: ");
0099 puthex(zimage_start);
0100 puts(" ");
0101 puthex(zimage_size + zimage_start);
0102 puts("\n");
0103
0104
0105 free_mem_ptr = boot_heap_start;
0106 free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
0107
0108
0109 puts("Uncompressing Linux at load address ");
0110 puthex(VMLINUX_LOAD_ADDRESS_ULL);
0111 puts("\n");
0112
0113
0114 __decompress((char *)zimage_start, zimage_size, 0, 0,
0115 (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error);
0116
0117 if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) &&
0118 fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) {
0119 unsigned int image_size, dtb_size;
0120
0121 dtb_size = fdt_totalsize((void *)&__appended_dtb);
0122
0123
0124 image_size = get_unaligned_le32((void *)__image_end - 4);
0125
0126
0127 image_size = ALIGN(image_size, STRUCT_ALIGNMENT);
0128
0129 puts("Copy device tree to address ");
0130 puthex(VMLINUX_LOAD_ADDRESS_ULL + image_size);
0131 puts("\n");
0132
0133
0134 memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size,
0135 __appended_dtb, dtb_size);
0136 }
0137
0138
0139 puts("Now, booting the kernel...\n");
0140 }