GNU Linux-libre 4.14.262-gnu1
[releases.git] / arch / m32r / boot / compressed / misc.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * arch/m32r/boot/compressed/misc.c
4  *
5  * This is a collection of several routines from gzip-1.0.3
6  * adapted for Linux.
7  *
8  * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
9  *
10  * Adapted for SH by Stuart Menefy, Aug 1999
11  *
12  * 2003-02-12:  Support M32R by Takeo Takahashi
13  */
14
15 /*
16  * gzip declarations
17  */
18 #define STATIC static
19
20 #undef memset
21 #undef memcpy
22 #define memzero(s, n)     memset ((s), 0, (n))
23
24 static void error(char *m);
25
26 #include "m32r_sio.c"
27
28 static unsigned long free_mem_ptr;
29 static unsigned long free_mem_end_ptr;
30
31 #ifdef CONFIG_KERNEL_BZIP2
32 void *memset(void *s, int c, size_t n)
33 {
34         char *ss = s;
35
36         while (n--)
37                 *ss++ = c;
38         return s;
39 }
40 #endif
41
42 #ifdef CONFIG_KERNEL_GZIP
43 void *memcpy(void *dest, const void *src, size_t n)
44 {
45         char *d = dest;
46         const char *s = src;
47         while (n--)
48                 *d++ = *s++;
49
50         return dest;
51 }
52
53 #define BOOT_HEAP_SIZE             0x10000
54 #include "../../../../lib/decompress_inflate.c"
55 #endif
56
57 #ifdef CONFIG_KERNEL_BZIP2
58 #define BOOT_HEAP_SIZE             0x400000
59 #include "../../../../lib/decompress_bunzip2.c"
60 #endif
61
62 #ifdef CONFIG_KERNEL_LZMA
63 #define BOOT_HEAP_SIZE             0x10000
64 #include "../../../../lib/decompress_unlzma.c"
65 #endif
66
67 static void error(char *x)
68 {
69         puts("\n\n");
70         puts(x);
71         puts("\n\n -- System halted");
72
73         while(1);       /* Halt */
74 }
75
76 void
77 decompress_kernel(int mmu_on, unsigned char *zimage_data,
78                   unsigned int zimage_len, unsigned long heap)
79 {
80         unsigned char *input_data = zimage_data;
81         int input_len = zimage_len;
82         unsigned char *output_data;
83
84         output_data = (unsigned char *)CONFIG_MEMORY_START + 0x2000
85                 + (mmu_on ? 0x80000000 : 0);
86         free_mem_ptr = heap;
87         free_mem_end_ptr = free_mem_ptr + BOOT_HEAP_SIZE;
88
89         puts("\nDecompressing Linux... ");
90         __decompress(input_data, input_len, NULL, NULL, output_data, 0,
91                         NULL, error);
92         puts("done.\nBooting the kernel.\n");
93 }