Path: blob/master/arch/mips/boot/compressed/decompress.c
26493 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Copyright 2001 MontaVista Software Inc.3* Author: Matt Porter <[email protected]>4*5* Copyright (C) 2009 Lemote, Inc.6* Author: Wu Zhangjin <[email protected]>7*/89#define DISABLE_BRANCH_PROFILING1011#define __NO_FORTIFY12#include <linux/types.h>13#include <linux/kernel.h>14#include <linux/string.h>15#include <linux/libfdt.h>1617#include <asm/addrspace.h>18#include <linux/unaligned.h>19#include <asm-generic/vmlinux.lds.h>2021#include "decompress.h"2223/*24* These two variables specify the free mem region25* that can be used for temporary malloc area26*/27unsigned long free_mem_ptr;28unsigned long free_mem_end_ptr;2930void error(char *x)31{32puts("\n\n");33puts(x);34puts("\n\n -- System halted");3536while (1)37; /* Halt */38}3940/* activate the code for pre-boot environment */41#define STATIC static4243#ifdef CONFIG_KERNEL_GZIP44#include "../../../../lib/decompress_inflate.c"45#endif4647#ifdef CONFIG_KERNEL_BZIP248#include "../../../../lib/decompress_bunzip2.c"49#endif5051#ifdef CONFIG_KERNEL_LZ452#include "../../../../lib/decompress_unlz4.c"53#endif5455#ifdef CONFIG_KERNEL_LZMA56#include "../../../../lib/decompress_unlzma.c"57#endif5859#ifdef CONFIG_KERNEL_LZO60#include "../../../../lib/decompress_unlzo.c"61#endif6263#ifdef CONFIG_KERNEL_XZ64#include "../../../../lib/decompress_unxz.c"65#endif6667#ifdef CONFIG_KERNEL_ZSTD68#include "../../../../lib/decompress_unzstd.c"69#endif7071const unsigned long __stack_chk_guard = 0x000a0dff;7273void __stack_chk_fail(void)74{75error("stack-protector: Kernel stack is corrupted\n");76}7778void decompress_kernel(unsigned long boot_heap_start)79{80unsigned long zimage_start, zimage_size;8182zimage_start = (unsigned long)(__image_begin);83zimage_size = (unsigned long)(__image_end) -84(unsigned long)(__image_begin);8586puts("zimage at: ");87puthex(zimage_start);88puts(" ");89puthex(zimage_size + zimage_start);90puts("\n");9192/* This area are prepared for mallocing when decompressing */93free_mem_ptr = boot_heap_start;94free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;9596/* Display standard Linux/MIPS boot prompt */97puts("Uncompressing Linux at load address ");98puthex(VMLINUX_LOAD_ADDRESS_ULL);99puts("\n");100101/* Decompress the kernel with according algorithm */102__decompress((char *)zimage_start, zimage_size, 0, 0,103(void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error);104105if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) &&106fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) {107unsigned int image_size, dtb_size;108109dtb_size = fdt_totalsize((void *)&__appended_dtb);110111/* last four bytes is always image size in little endian */112image_size = get_unaligned_le32((void *)__image_end - 4);113114/* The device tree's address must be properly aligned */115image_size = ALIGN(image_size, STRUCT_ALIGNMENT);116117puts("Copy device tree to address ");118puthex(VMLINUX_LOAD_ADDRESS_ULL + image_size);119puts("\n");120121/* copy dtb to where the booted kernel will expect it */122memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size,123__appended_dtb, dtb_size);124}125126/* FIXME: should we flush cache here? */127puts("Now, booting the kernel...\n");128}129130131