2 * Misc. bootloader code for many machines.
4 * Copyright 2001 MontaVista Software Inc.
5 * Author: Matt Porter <mporter@mvista.com> Derived from
6 * arch/ppc/boot/prep/misc.c
8 * Copyright (C) 2009 Lemote, Inc. & Institute of Computing Technology
9 * Author: Wu Zhangjin <wuzj@lemote.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 #include <linux/types.h>
18 #include <linux/kernel.h>
20 #include <asm/addrspace.h>
22 /* These two variables specify the free mem region
23 * that can be used for temporary malloc area
25 unsigned long free_mem_ptr;
26 unsigned long free_mem_end_ptr;
29 /* The linker tells us where the image is. */
30 extern unsigned char __image_begin, __image_end;
31 extern unsigned char __ramdisk_begin, __ramdisk_end;
32 unsigned long initrd_size;
34 /* debug interfaces */
35 extern void puts(const char *s);
36 extern void puthex(unsigned long long val);
42 puts("\n\n -- System halted");
48 /* activate the code for pre-boot environment */
51 #ifdef CONFIG_KERNEL_GZIP
52 void *memcpy(void *dest, const void *src, size_t n)
58 for (i = 0; i < n; i++)
62 #include "../../../../lib/decompress_inflate.c"
65 #ifdef CONFIG_KERNEL_BZIP2
66 void *memset(void *s, int c, size_t n)
71 for (i = 0; i < n; i++)
75 #include "../../../../lib/decompress_bunzip2.c"
78 #ifdef CONFIG_KERNEL_LZMA
79 #include "../../../../lib/decompress_unlzma.c"
82 void decompress_kernel(unsigned long boot_heap_start)
87 * We link ourself to an arbitrary low address. When we run, we
88 * relocate outself to that address. __image_beign points to
89 * the part of the image where the zImage is. -- Tom
91 zimage_start = (char *)(unsigned long)(&__image_begin);
92 zimage_size = (unsigned long)(&__image_end) -
93 (unsigned long)(&__image_begin);
96 * The zImage and initrd will be between start and _end, so they've
97 * already been moved once. We're good to go now. -- Tom
100 puthex((unsigned long)zimage_start);
102 puthex((unsigned long)(zimage_size + zimage_start));
107 puthex((unsigned long)(&__ramdisk_begin));
109 puthex((unsigned long)(&__ramdisk_end));
113 /* this area are prepared for mallocing when decompressing */
114 free_mem_ptr = boot_heap_start;
115 free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
117 /* Display standard Linux/MIPS boot prompt for kernel args */
118 puts("Uncompressing Linux at load address ");
119 puthex(VMLINUX_LOAD_ADDRESS_ULL);
121 /* Decompress the kernel with according algorithm */
122 decompress(zimage_start, zimage_size, 0, 0,
123 (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
124 /* FIXME: is there a need to flush cache here? */
125 puts("Now, booting the kernel...\n");