aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/boot/compressed/decompress.c
diff options
context:
space:
mode:
authorWu Zhangjin <wuzhangjin@gmail.com>2009-10-14 06:12:16 -0400
committerRalf Baechle <ralf@linux-mips.org>2009-12-16 20:56:56 -0500
commit1b93b3c3e94be2605759735a89fc935ba5f58dcf (patch)
tree1d49ea7cca709e0380d5463357deb1c632308cc0 /arch/mips/boot/compressed/decompress.c
parentbea4c899f2b5fad80099aea979780ef19f9b1987 (diff)
MIPS: Add support for GZIP / BZIP2 / LZMA compressed kernel images
This patch helps to generate smaller kernel images for linux-MIPS, Here is the effect when using lzma: $ ls -sh vmlinux 7.1M vmlinux $ ls -sh vmlinuz 1.5M vmlinuz Have tested the 32bit kernel on Qemu/Malta and 64bit kernel on FuLoong Mini PC. both of them work well. and also, tested by Alexander Clouter on an AR7 based Linksys WAG54Gv2, and by Manuel Lauss on an Alchemy board. This -v2 version incorporate the feedback from Ralf, and add the following changes: 1. add .ecoff, .bin, .erec format support 2. only enable it and the debug source code for the machines we tested 3. a dozen of fixups and cleanups and if you want to enable it for your board, please try to select SYS_SUPPORTS_ZBOOT for it, and if the board have an 16550 compatible uart, you can select SYS_SUPPORTS_ZBOOT_UART16550 directly. and then sending the relative patches to Ralf. Tested-by: Manuel Lauss <manuel.lauss@googlemail.com> Tested-by: Alexander Clouter <alex@digriz.org.uk> Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/boot/compressed/decompress.c')
-rw-r--r--arch/mips/boot/compressed/decompress.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/arch/mips/boot/compressed/decompress.c b/arch/mips/boot/compressed/decompress.c
new file mode 100644
index 000000000000..67330c2f7318
--- /dev/null
+++ b/arch/mips/boot/compressed/decompress.c
@@ -0,0 +1,126 @@
1/*
2 * Misc. bootloader code for many machines.
3 *
4 * Copyright 2001 MontaVista Software Inc.
5 * Author: Matt Porter <mporter@mvista.com> Derived from
6 * arch/ppc/boot/prep/misc.c
7 *
8 * Copyright (C) 2009 Lemote, Inc. & Institute of Computing Technology
9 * Author: Wu Zhangjin <wuzj@lemote.com>
10 *
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.
15 */
16
17#include <linux/types.h>
18#include <linux/kernel.h>
19
20#include <asm/addrspace.h>
21
22/* These two variables specify the free mem region
23 * that can be used for temporary malloc area
24 */
25unsigned long free_mem_ptr;
26unsigned long free_mem_end_ptr;
27char *zimage_start;
28
29/* The linker tells us where the image is. */
30extern unsigned char __image_begin, __image_end;
31extern unsigned char __ramdisk_begin, __ramdisk_end;
32unsigned long initrd_size;
33
34/* debug interfaces */
35extern void puts(const char *s);
36extern void puthex(unsigned long long val);
37
38void error(char *x)
39{
40 puts("\n\n");
41 puts(x);
42 puts("\n\n -- System halted");
43
44 while (1)
45 ; /* Halt */
46}
47
48/* activate the code for pre-boot environment */
49#define STATIC static
50
51#ifdef CONFIG_KERNEL_GZIP
52void *memcpy(void *dest, const void *src, size_t n)
53{
54 int i;
55 const char *s = src;
56 char *d = dest;
57
58 for (i = 0; i < n; i++)
59 d[i] = s[i];
60 return dest;
61}
62#include "../../../../lib/decompress_inflate.c"
63#endif
64
65#ifdef CONFIG_KERNEL_BZIP2
66void *memset(void *s, int c, size_t n)
67{
68 int i;
69 char *ss = s;
70
71 for (i = 0; i < n; i++)
72 ss[i] = c;
73 return s;
74}
75#include "../../../../lib/decompress_bunzip2.c"
76#endif
77
78#ifdef CONFIG_KERNEL_LZMA
79#include "../../../../lib/decompress_unlzma.c"
80#endif
81
82void decompress_kernel(unsigned long boot_heap_start)
83{
84 int zimage_size;
85
86 /*
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
90 */
91 zimage_start = (char *)(unsigned long)(&__image_begin);
92 zimage_size = (unsigned long)(&__image_end) -
93 (unsigned long)(&__image_begin);
94
95 /*
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
98 */
99 puts("zimage at: ");
100 puthex((unsigned long)zimage_start);
101 puts(" ");
102 puthex((unsigned long)(zimage_size + zimage_start));
103 puts("\n");
104
105 if (initrd_size) {
106 puts("initrd at: ");
107 puthex((unsigned long)(&__ramdisk_begin));
108 puts(" ");
109 puthex((unsigned long)(&__ramdisk_end));
110 puts("\n");
111 }
112
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;
116
117 /* Display standard Linux/MIPS boot prompt for kernel args */
118 puts("Uncompressing Linux at load address ");
119 puthex(VMLINUX_LOAD_ADDRESS_ULL);
120 puts("\n");
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");
126}