blob: 370d60881977db4370f1686bee5d3b59a19eba69 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/m32r/boot/compressed/misc.c
3 *
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
6 *
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
8 *
9 * Adapted for SH by Stuart Menefy, Aug 1999
10 *
11 * 2003-02-12: Support M32R by Takeo Takahashi
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/*
15 * gzip declarations
16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#define STATIC static
18
19#undef memset
20#undef memcpy
21#define memzero(s, n) memset ((s), 0, (n))
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static void error(char *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "m32r_sio.c"
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static unsigned long free_mem_ptr;
28static unsigned long free_mem_end_ptr;
29
Hirokazu Takata337214e2009-10-15 09:21:56 +090030#ifdef CONFIG_KERNEL_BZIP2
31static void *memset(void *s, int c, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Hirokazu Takata337214e2009-10-15 09:21:56 +090033 char *ss = s;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Hirokazu Takata337214e2009-10-15 09:21:56 +090035 while (n--)
36 *ss++ = c;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 return s;
38}
Hirokazu Takata337214e2009-10-15 09:21:56 +090039#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Hirokazu Takata337214e2009-10-15 09:21:56 +090041#ifdef CONFIG_KERNEL_GZIP
42#define BOOT_HEAP_SIZE 0x10000
43#include "../../../../lib/decompress_inflate.c"
44#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Hirokazu Takata337214e2009-10-15 09:21:56 +090046#ifdef CONFIG_KERNEL_BZIP2
47#define BOOT_HEAP_SIZE 0x400000
48#include "../../../../lib/decompress_bunzip2.c"
49#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Hirokazu Takata337214e2009-10-15 09:21:56 +090051#ifdef CONFIG_KERNEL_LZMA
52#define BOOT_HEAP_SIZE 0x10000
53#include "../../../../lib/decompress_unlzma.c"
54#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56static void error(char *x)
57{
58 puts("\n\n");
59 puts(x);
60 puts("\n\n -- System halted");
61
62 while(1); /* Halt */
63}
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065void
66decompress_kernel(int mmu_on, unsigned char *zimage_data,
67 unsigned int zimage_len, unsigned long heap)
68{
Hirokazu Takata337214e2009-10-15 09:21:56 +090069 unsigned char *input_data = zimage_data;
70 int input_len = zimage_len;
71 unsigned char *output_data;
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 output_data = (unsigned char *)CONFIG_MEMORY_START + 0x2000
74 + (mmu_on ? 0x80000000 : 0);
75 free_mem_ptr = heap;
Hirokazu Takata337214e2009-10-15 09:21:56 +090076 free_mem_end_ptr = free_mem_ptr + BOOT_HEAP_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Hirokazu Takata337214e2009-10-15 09:21:56 +090078 puts("\nDecompressing Linux... ");
79 decompress(input_data, input_len, NULL, NULL, output_data, NULL, error);
80 puts("done.\nBooting the kernel.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}