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 16 17 18
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#include <linux/types.h>
#include <linux/kernel.h>

#include <asm/addrspace.h>

19 20
/*
 * These two variables specify the free mem region
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
 * 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

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

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

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

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

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

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

70 71 72 73 74 75 76 77 78 79 80 81
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");
}

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

86 87
	__stack_chk_guard_setup();

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

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

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

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

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

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