This source file includes following definitions.
- flush
- print_err
- partial_decompress
1
2
3
4
5
6
7
8 #include "elf.h"
9 #include "page.h"
10 #include "string.h"
11 #include "stdio.h"
12 #include "ops.h"
13 #include "reg.h"
14 #include "types.h"
15
16
17
18
19
20
21
22 #define STATIC static
23 #define INIT
24 #define __always_inline inline
25
26
27
28
29
30
31
32 #ifdef CONFIG_KERNEL_GZIP
33 # include "decompress_inflate.c"
34 #endif
35
36 #ifdef CONFIG_KERNEL_XZ
37 # include "xz_config.h"
38 # include "../../../lib/decompress_unxz.c"
39 #endif
40
41
42 static unsigned long decompressed_bytes;
43 static unsigned long limit;
44 static unsigned long skip;
45 static char *output_buffer;
46
47
48
49
50
51 static long flush(void *v, unsigned long buffer_size)
52 {
53 unsigned long end = decompressed_bytes + buffer_size;
54 unsigned long size = buffer_size;
55 unsigned long offset = 0;
56 char *in = v;
57 char *out;
58
59
60
61
62
63 if (decompressed_bytes >= limit)
64 return -1;
65
66
67 if (end <= skip) {
68 decompressed_bytes += buffer_size;
69 return buffer_size;
70 }
71
72
73 if (decompressed_bytes < skip && end > skip) {
74 offset = skip - decompressed_bytes;
75
76 in += offset;
77 size -= offset;
78 decompressed_bytes += offset;
79 }
80
81 out = &output_buffer[decompressed_bytes - skip];
82 size = min(decompressed_bytes + size, limit) - decompressed_bytes;
83
84 memcpy(out, in, size);
85 decompressed_bytes += size;
86
87 return buffer_size;
88 }
89
90 static void print_err(char *s)
91 {
92
93 if (decompressed_bytes >= limit)
94 return;
95
96 printf("Decompression error: '%s'\n\r", s);
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 long partial_decompress(void *inbuf, unsigned long input_size,
118 void *outbuf, unsigned long output_size, unsigned long _skip)
119 {
120 int ret;
121
122
123
124
125
126 output_size += _skip;
127
128 decompressed_bytes = 0;
129 output_buffer = outbuf;
130 limit = output_size;
131 skip = _skip;
132
133 ret = __decompress(inbuf, input_size, NULL, flush, outbuf,
134 output_size, NULL, print_err);
135
136
137
138
139
140 if (decompressed_bytes < limit)
141 return ret;
142
143 return decompressed_bytes - skip;
144 }