decompress.c 2.6 KB
Newer Older
1 2
/*
 * Copyright 2001 MontaVista Software Inc.
3
 * Author: Matt Porter <mporter@mvista.com>
4
 *
5 6
 * Copyright (C) 2009 Lemote, Inc.
 * Author: Wu Zhangjin <wuzhangjin@gmail.com>
7
 *
R
Ralf Baechle 已提交
8 9
 * This program is free software; you can redistribute	it and/or modify it
 * under  the terms of	the GNU General	 Public License as published by the
10 11 12 13 14 15
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#include <linux/types.h>
#include <linux/kernel.h>
16
#include <linux/string.h>
17 18 19

#include <asm/addrspace.h>

20 21
/*
 * These two variables specify the free mem region
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
 * 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  */
extern void puts(const char *s);
extern void puthex(unsigned long long val);

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

47
#ifdef CONFIG_KERNEL_GZIP
48 49 50 51 52 53 54
#include "../../../../lib/decompress_inflate.c"
#endif

#ifdef CONFIG_KERNEL_BZIP2
#include "../../../../lib/decompress_bunzip2.c"
#endif

55 56 57 58
#ifdef CONFIG_KERNEL_LZ4
#include "../../../../lib/decompress_unlz4.c"
#endif

59 60 61 62
#ifdef CONFIG_KERNEL_LZMA
#include "../../../../lib/decompress_unlzma.c"
#endif

63 64 65 66
#ifdef CONFIG_KERNEL_LZO
#include "../../../../lib/decompress_unlzo.c"
#endif

67 68 69 70
#ifdef CONFIG_KERNEL_XZ
#include "../../../../lib/decompress_unxz.c"
#endif

71 72 73 74 75 76 77 78 79 80 81 82
unsigned long __stack_chk_guard;

void __stack_chk_guard_setup(void)
{
	__stack_chk_guard = 0x000a0dff;
}

void __stack_chk_fail(void)
{
	error("stack-protector: Kernel stack is corrupted\n");
}

83 84
void decompress_kernel(unsigned long boot_heap_start)
{
85 86
	unsigned long zimage_start, zimage_size;

87 88
	__stack_chk_guard_setup();

89
	zimage_start = (unsigned long)(&__image_begin);
90 91 92 93
	zimage_size = (unsigned long)(&__image_end) -
	    (unsigned long)(&__image_begin);

	puts("zimage at:     ");
94
	puthex(zimage_start);
95
	puts(" ");
96
	puthex(zimage_size + zimage_start);
97 98
	puts("\n");

99
	/* This area are prepared for mallocing when decompressing */
100 101 102
	free_mem_ptr = boot_heap_start;
	free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;

103
	/* Display standard Linux/MIPS boot prompt */
104 105 106
	puts("Uncompressing Linux at load address ");
	puthex(VMLINUX_LOAD_ADDRESS_ULL);
	puts("\n");
107

108
	/* Decompress the kernel with according algorithm */
109
	decompress((char *)zimage_start, zimage_size, 0, 0,
110
		   (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
111 112

	/* FIXME: should we flush cache here? */
113 114
	puts("Now, booting the kernel...\n");
}