2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-10-14 18:12:16 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2001 MontaVista Software Inc.
|
2010-06-16 15:52:20 +08:00
|
|
|
* Author: Matt Porter <mporter@mvista.com>
|
2009-10-14 18:12:16 +08:00
|
|
|
*
|
2010-01-04 17:16:51 +08:00
|
|
|
* Copyright (C) 2009 Lemote, Inc.
|
|
|
|
* Author: Wu Zhangjin <wuzhangjin@gmail.com>
|
2009-10-14 18:12:16 +08:00
|
|
|
*/
|
|
|
|
|
2024-06-12 13:13:20 +08:00
|
|
|
#define DISABLE_BRANCH_PROFILING
|
|
|
|
|
2009-10-14 18:12:16 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
2014-07-21 01:58:23 +08:00
|
|
|
#include <linux/string.h>
|
2016-06-20 17:27:36 +08:00
|
|
|
#include <linux/libfdt.h>
|
2009-10-14 18:12:16 +08:00
|
|
|
|
|
|
|
#include <asm/addrspace.h>
|
2024-06-11 20:26:44 +08:00
|
|
|
#include <asm/unaligned.h>
|
2009-10-14 18:12:16 +08:00
|
|
|
|
2010-06-16 15:52:20 +08:00
|
|
|
/*
|
|
|
|
* These two variables specify the free mem region
|
2009-10-14 18:12:16 +08:00
|
|
|
* that can be used for temporary malloc area
|
|
|
|
*/
|
|
|
|
unsigned long free_mem_ptr;
|
|
|
|
unsigned long free_mem_end_ptr;
|
|
|
|
|
|
|
|
/* The linker tells us where the image is. */
|
|
|
|
extern unsigned char __image_begin, __image_end;
|
|
|
|
|
|
|
|
/* debug interfaces */
|
2010-12-25 23:11:49 +08:00
|
|
|
#ifdef CONFIG_DEBUG_ZBOOT
|
2009-10-14 18:12:16 +08:00
|
|
|
extern void puts(const char *s);
|
|
|
|
extern void puthex(unsigned long long val);
|
2010-12-25 23:11:49 +08:00
|
|
|
#else
|
|
|
|
#define puts(s) do {} while (0)
|
|
|
|
#define puthex(val) do {} while (0)
|
|
|
|
#endif
|
2009-10-14 18:12:16 +08:00
|
|
|
|
2016-06-20 17:27:36 +08:00
|
|
|
extern char __appended_dtb[];
|
|
|
|
|
2009-10-14 18:12:16 +08:00
|
|
|
void error(char *x)
|
|
|
|
{
|
|
|
|
puts("\n\n");
|
|
|
|
puts(x);
|
|
|
|
puts("\n\n -- System halted");
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
; /* Halt */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* activate the code for pre-boot environment */
|
|
|
|
#define STATIC static
|
|
|
|
|
2013-09-11 18:51:41 +08:00
|
|
|
#ifdef CONFIG_KERNEL_GZIP
|
2009-10-14 18:12:16 +08:00
|
|
|
#include "../../../../lib/decompress_inflate.c"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_KERNEL_BZIP2
|
|
|
|
#include "../../../../lib/decompress_bunzip2.c"
|
|
|
|
#endif
|
|
|
|
|
2013-09-16 23:55:20 +08:00
|
|
|
#ifdef CONFIG_KERNEL_LZ4
|
|
|
|
#include "../../../../lib/decompress_unlz4.c"
|
|
|
|
#endif
|
|
|
|
|
2009-10-14 18:12:16 +08:00
|
|
|
#ifdef CONFIG_KERNEL_LZMA
|
|
|
|
#include "../../../../lib/decompress_unlzma.c"
|
|
|
|
#endif
|
|
|
|
|
2010-01-15 20:34:46 +08:00
|
|
|
#ifdef CONFIG_KERNEL_LZO
|
|
|
|
#include "../../../../lib/decompress_unlzo.c"
|
|
|
|
#endif
|
|
|
|
|
2013-09-11 18:51:41 +08:00
|
|
|
#ifdef CONFIG_KERNEL_XZ
|
|
|
|
#include "../../../../lib/decompress_unxz.c"
|
|
|
|
#endif
|
|
|
|
|
2018-04-06 07:18:18 +08:00
|
|
|
const unsigned long __stack_chk_guard = 0x000a0dff;
|
2014-06-25 07:00:17 +08:00
|
|
|
|
|
|
|
void __stack_chk_fail(void)
|
|
|
|
{
|
|
|
|
error("stack-protector: Kernel stack is corrupted\n");
|
|
|
|
}
|
|
|
|
|
2009-10-14 18:12:16 +08:00
|
|
|
void decompress_kernel(unsigned long boot_heap_start)
|
|
|
|
{
|
2010-06-16 15:52:20 +08:00
|
|
|
unsigned long zimage_start, zimage_size;
|
|
|
|
|
|
|
|
zimage_start = (unsigned long)(&__image_begin);
|
2009-10-14 18:12:16 +08:00
|
|
|
zimage_size = (unsigned long)(&__image_end) -
|
|
|
|
(unsigned long)(&__image_begin);
|
|
|
|
|
|
|
|
puts("zimage at: ");
|
2010-06-16 15:52:20 +08:00
|
|
|
puthex(zimage_start);
|
2009-10-14 18:12:16 +08:00
|
|
|
puts(" ");
|
2010-06-16 15:52:20 +08:00
|
|
|
puthex(zimage_size + zimage_start);
|
2009-10-14 18:12:16 +08:00
|
|
|
puts("\n");
|
|
|
|
|
2010-06-16 15:52:20 +08:00
|
|
|
/* This area are prepared for mallocing when decompressing */
|
2009-10-14 18:12:16 +08:00
|
|
|
free_mem_ptr = boot_heap_start;
|
|
|
|
free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
|
|
|
|
|
2010-06-16 15:52:20 +08:00
|
|
|
/* Display standard Linux/MIPS boot prompt */
|
2009-10-14 18:12:16 +08:00
|
|
|
puts("Uncompressing Linux at load address ");
|
|
|
|
puthex(VMLINUX_LOAD_ADDRESS_ULL);
|
|
|
|
puts("\n");
|
2010-06-16 15:52:20 +08:00
|
|
|
|
2009-10-14 18:12:16 +08:00
|
|
|
/* Decompress the kernel with according algorithm */
|
2015-09-10 06:39:12 +08:00
|
|
|
__decompress((char *)zimage_start, zimage_size, 0, 0,
|
|
|
|
(void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error);
|
2010-06-16 15:52:20 +08:00
|
|
|
|
2016-06-20 17:27:36 +08:00
|
|
|
if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) &&
|
|
|
|
fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) {
|
|
|
|
unsigned int image_size, dtb_size;
|
|
|
|
|
|
|
|
dtb_size = fdt_totalsize((void *)&__appended_dtb);
|
|
|
|
|
|
|
|
/* last four bytes is always image size in little endian */
|
2024-06-11 20:26:44 +08:00
|
|
|
image_size = get_unaligned_le32((void *)&__image_end - 4);
|
2016-06-20 17:27:36 +08:00
|
|
|
|
|
|
|
/* copy dtb to where the booted kernel will expect it */
|
|
|
|
memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size,
|
|
|
|
__appended_dtb, dtb_size);
|
|
|
|
}
|
|
|
|
|
2010-06-16 15:52:20 +08:00
|
|
|
/* FIXME: should we flush cache here? */
|
2009-10-14 18:12:16 +08:00
|
|
|
puts("Now, booting the kernel...\n");
|
|
|
|
}
|