blob: 31903cf9709d6d5b755a22ef0e478ea7fc3585de [file] [log] [blame]
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +08001/*
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +08002 * Copyright 2001 MontaVista Software Inc.
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +08003 * Author: Matt Porter <mporter@mvista.com>
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +08004 *
Wu Zhangjinf7a904d2010-01-04 17:16:51 +08005 * Copyright (C) 2009 Lemote, Inc.
6 * Author: Wu Zhangjin <wuzhangjin@gmail.com>
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +08007 *
Ralf Baechle70342282013-01-22 12:59:30 +01008 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080010 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/types.h>
15#include <linux/kernel.h>
Aurelien Jarno29593fd2014-07-20 19:58:23 +020016#include <linux/string.h>
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080017
18#include <asm/addrspace.h>
19
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +080020/*
21 * These two variables specify the free mem region
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080022 * that can be used for temporary malloc area
23 */
24unsigned long free_mem_ptr;
25unsigned long free_mem_end_ptr;
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080026
27/* The linker tells us where the image is. */
28extern unsigned char __image_begin, __image_end;
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080029
30/* debug interfaces */
31extern void puts(const char *s);
32extern void puthex(unsigned long long val);
33
34void error(char *x)
35{
36 puts("\n\n");
37 puts(x);
38 puts("\n\n -- System halted");
39
40 while (1)
41 ; /* Halt */
42}
43
44/* activate the code for pre-boot environment */
45#define STATIC static
46
Florian Fainelli4e23eb62013-09-11 11:51:41 +010047#ifdef CONFIG_KERNEL_GZIP
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080048#include "../../../../lib/decompress_inflate.c"
49#endif
50
51#ifdef CONFIG_KERNEL_BZIP2
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080052#include "../../../../lib/decompress_bunzip2.c"
53#endif
54
Florian Fainelli31c48672013-09-16 16:55:20 +010055#ifdef CONFIG_KERNEL_LZ4
56#include "../../../../lib/decompress_unlz4.c"
57#endif
58
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080059#ifdef CONFIG_KERNEL_LZMA
60#include "../../../../lib/decompress_unlzma.c"
61#endif
62
Wu Zhangjinfe1d45e2010-01-15 20:34:46 +080063#ifdef CONFIG_KERNEL_LZO
64#include "../../../../lib/decompress_unlzo.c"
65#endif
66
Florian Fainelli4e23eb62013-09-11 11:51:41 +010067#ifdef CONFIG_KERNEL_XZ
68#include "../../../../lib/decompress_unxz.c"
69#endif
70
Ben Chan3b628ca2014-06-24 16:00:17 -070071unsigned long __stack_chk_guard;
72
73void __stack_chk_guard_setup(void)
74{
75 __stack_chk_guard = 0x000a0dff;
76}
77
78void __stack_chk_fail(void)
79{
80 error("stack-protector: Kernel stack is corrupted\n");
81}
82
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080083void decompress_kernel(unsigned long boot_heap_start)
84{
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +080085 unsigned long zimage_start, zimage_size;
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080086
Ben Chan3b628ca2014-06-24 16:00:17 -070087 __stack_chk_guard_setup();
88
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +080089 zimage_start = (unsigned long)(&__image_begin);
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080090 zimage_size = (unsigned long)(&__image_end) -
91 (unsigned long)(&__image_begin);
92
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080093 puts("zimage at: ");
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +080094 puthex(zimage_start);
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080095 puts(" ");
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +080096 puthex(zimage_size + zimage_start);
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +080097 puts("\n");
98
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +080099 /* This area are prepared for mallocing when decompressing */
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +0800100 free_mem_ptr = boot_heap_start;
101 free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
102
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +0800103 /* Display standard Linux/MIPS boot prompt */
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +0800104 puts("Uncompressing Linux at load address ");
105 puthex(VMLINUX_LOAD_ADDRESS_ULL);
106 puts("\n");
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +0800107
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +0800108 /* Decompress the kernel with according algorithm */
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +0800109 decompress((char *)zimage_start, zimage_size, 0, 0,
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +0800110 (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
Wu Zhangjin1e1a77d2010-06-16 15:52:20 +0800111
112 /* FIXME: should we flush cache here? */
Wu Zhangjin1b93b3c2009-10-14 18:12:16 +0800113 puts("Now, booting the kernel...\n");
114}