1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/h8300/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 h8300 by Yoshinori Sato 2006
11 */
12
13 #include <linux/uaccess.h>
14
15 /*
16 * gzip declarations
17 */
18
19 #define OF(args) args
20 #define STATIC static
21
22 #undef memset
23 #undef memcpy
24 #define memzero(s, n) memset((s), (0), (n))
25
26 extern int _end;
27 static unsigned long free_mem_ptr;
28 static unsigned long free_mem_end_ptr;
29
30 extern char input_data[];
31 extern int input_len;
32 extern char output[];
33
34 #define HEAP_SIZE 0x10000
35
36 #ifdef CONFIG_KERNEL_GZIP
37 #include "../../../../lib/decompress_inflate.c"
38 #endif
39
40 #ifdef CONFIG_KERNEL_LZO
41 #include "../../../../lib/decompress_unlzo.c"
42 #endif
43
memset(void * s,int c,size_t n)44 void *memset(void *s, int c, size_t n)
45 {
46 int i;
47 char *ss = (char *)s;
48
49 for (i = 0; i < n; i++)
50 ss[i] = c;
51 return s;
52 }
53
memcpy(void * dest,const void * src,size_t n)54 void *memcpy(void *dest, const void *src, size_t n)
55 {
56 int i;
57 char *d = (char *)dest, *s = (char *)src;
58
59 for (i = 0; i < n; i++)
60 d[i] = s[i];
61 return dest;
62 }
63
error(char * x)64 static void error(char *x)
65 {
66 while (1)
67 ; /* Halt */
68 }
69
decompress_kernel(void)70 void decompress_kernel(void)
71 {
72 free_mem_ptr = (unsigned long)&_end;
73 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
74
75 __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
76 }
77