Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | /* |
| 15 | * gzip declarations |
| 16 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #define STATIC static |
| 18 | |
| 19 | #undef memset |
| 20 | #undef memcpy |
| 21 | #define memzero(s, n) memset ((s), 0, (n)) |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static void error(char *m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include "m32r_sio.c" |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static unsigned long free_mem_ptr; |
| 28 | static unsigned long free_mem_end_ptr; |
| 29 | |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 30 | #ifdef CONFIG_KERNEL_BZIP2 |
Geert Uytterhoeven | 9a75c6e | 2012-07-17 15:48:05 -0700 | [diff] [blame] | 31 | void *memset(void *s, int c, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 33 | char *ss = s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 35 | while (n--) |
| 36 | *ss++ = c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | return s; |
| 38 | } |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 39 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 41 | #ifdef CONFIG_KERNEL_GZIP |
Geert Uytterhoeven | a8abbca | 2012-07-17 15:48:04 -0700 | [diff] [blame] | 42 | void *memcpy(void *dest, const void *src, size_t n) |
| 43 | { |
| 44 | char *d = dest; |
| 45 | const char *s = src; |
| 46 | while (n--) |
| 47 | *d++ = *s++; |
| 48 | |
| 49 | return dest; |
| 50 | } |
| 51 | |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 52 | #define BOOT_HEAP_SIZE 0x10000 |
| 53 | #include "../../../../lib/decompress_inflate.c" |
| 54 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 56 | #ifdef CONFIG_KERNEL_BZIP2 |
| 57 | #define BOOT_HEAP_SIZE 0x400000 |
| 58 | #include "../../../../lib/decompress_bunzip2.c" |
| 59 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 61 | #ifdef CONFIG_KERNEL_LZMA |
| 62 | #define BOOT_HEAP_SIZE 0x10000 |
| 63 | #include "../../../../lib/decompress_unlzma.c" |
| 64 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | static void error(char *x) |
| 67 | { |
| 68 | puts("\n\n"); |
| 69 | puts(x); |
| 70 | puts("\n\n -- System halted"); |
| 71 | |
| 72 | while(1); /* Halt */ |
| 73 | } |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | void |
| 76 | decompress_kernel(int mmu_on, unsigned char *zimage_data, |
| 77 | unsigned int zimage_len, unsigned long heap) |
| 78 | { |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 79 | unsigned char *input_data = zimage_data; |
| 80 | int input_len = zimage_len; |
| 81 | unsigned char *output_data; |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | output_data = (unsigned char *)CONFIG_MEMORY_START + 0x2000 |
| 84 | + (mmu_on ? 0x80000000 : 0); |
| 85 | free_mem_ptr = heap; |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 86 | free_mem_end_ptr = free_mem_ptr + BOOT_HEAP_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 88 | puts("\nDecompressing Linux... "); |
Yinghai Lu | 2d3862d | 2015-09-09 15:39:12 -0700 | [diff] [blame^] | 89 | __decompress(input_data, input_len, NULL, NULL, output_data, 0, |
| 90 | NULL, error); |
Hirokazu Takata | 337214e | 2009-10-15 09:21:56 +0900 | [diff] [blame] | 91 | puts("done.\nBooting the kernel.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |