Index: tools/elf2flt/elf2flt.c |
— | — | @@ -645,6 +645,7 @@ |
646 | 646 | case R_ARM_PLT32: |
647 | 647 | case R_ARM_GOTPC: |
648 | 648 | case R_ARM_GOT32: |
| 649 | + case R_ARM_V4BX: |
649 | 650 | relocation_needed = 0; |
650 | 651 | break; |
651 | 652 | default: |
Index: tools/elf2flt/compress.h |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | #ifndef __ELF2FLT_COMPRESS_H__ |
12 | 12 | #define __ELF2FLT_COMPRESS_H__ |
13 | 13 | |
14 | | -#include <zlib.h> |
| 14 | +//#include <zlib.h> |
15 | 15 | |
16 | 16 | typedef enum |
17 | 17 | { |
— | — | @@ -25,11 +25,15 @@ |
26 | 26 | { |
27 | 27 | stream_type type; |
28 | 28 | const char *mode; |
29 | | - union |
30 | | - { |
31 | | - FILE *filep; |
32 | | - gzFile gzfilep; |
33 | | - } u; |
| 29 | + FILE *filep; |
| 30 | + char* buffer; |
| 31 | + int bufsize; |
| 32 | + int bufused; |
| 33 | +// union |
| 34 | +// { |
| 35 | +// FILE *filep; |
| 36 | +// gzFile gzfilep; |
| 37 | +// } u; |
34 | 38 | } stream; |
35 | 39 | |
36 | 40 | int fopen_stream_u(stream *fp, const char *path, const char *mode); |
Index: tools/elf2flt/compress.c |
— | — | @@ -10,8 +10,10 @@ |
11 | 11 | #include <assert.h> |
12 | 12 | #include <stdio.h> |
13 | 13 | #include <stdlib.h> |
| 14 | +#include <string.h> |
14 | 15 | |
15 | | -#include <zlib.h> |
| 16 | +//#include <zlib.h> |
| 17 | +#include "ucl/ucl.h" |
16 | 18 | #include "compress.h" |
17 | 19 | #include "stubs.h" |
18 | 20 | |
— | — | @@ -24,10 +26,13 @@ |
25 | 27 | int |
26 | 28 | fopen_stream_u(stream *fp, const char *path, const char *mode) |
27 | 29 | { |
28 | | - fp->u.filep = fopen(path, mode); |
29 | | - fp->type = (fp->u.filep) ? UNCOMPRESSED : INVALID; |
| 30 | + fp->filep = fopen(path, mode); |
| 31 | + fp->type = (fp->filep) ? UNCOMPRESSED : INVALID; |
30 | 32 | fp->mode = mode; |
31 | | - return (fp->u.filep) ? 0 : 1; |
| 33 | + fp->buffer = NULL; |
| 34 | + fp->bufsize = 0; |
| 35 | + fp->bufused = 0; |
| 36 | + return (fp->filep) ? 0 : 1; |
32 | 37 | } |
33 | 38 | |
34 | 39 | /* Read from stream. Return number of elements read. */ |
— | — | @@ -39,12 +44,12 @@ |
40 | 45 | |
41 | 46 | switch (str->type) { |
42 | 47 | case UNCOMPRESSED: |
43 | | - read = fread(ptr, size, nmemb, str->u.filep); |
| 48 | + read = fread(ptr, size, nmemb, str->filep); |
44 | 49 | break; |
45 | 50 | |
46 | | - case COMPRESSED: |
47 | | - read = gzread(str->u.gzfilep, ptr, size * nmemb) / size; |
48 | | - break; |
| 51 | +// case COMPRESSED: |
| 52 | +// read = gzread(str->u.gzfilep, ptr, size * nmemb) / size; |
| 53 | +// break; |
49 | 54 | |
50 | 55 | default: |
51 | 56 | abort(); |
— | — | @@ -62,11 +67,19 @@ |
63 | 68 | |
64 | 69 | switch (str->type) { |
65 | 70 | case UNCOMPRESSED: |
66 | | - written = fwrite(ptr, size, nmemb, str->u.filep); |
| 71 | + written = fwrite(ptr, size, nmemb, str->filep); |
67 | 72 | break; |
68 | 73 | |
69 | 74 | case COMPRESSED: |
70 | | - written = gzwrite(str->u.gzfilep, ptr, size * nmemb) / size; |
| 75 | + if (str->bufused + size * nmemb > str->bufsize) |
| 76 | + { |
| 77 | + str->bufsize = (str->bufused + size * nmemb + 0xfff) & ~0xfff; |
| 78 | + str->buffer = (char*)realloc(str->buffer, str->bufsize); |
| 79 | + } |
| 80 | + memcpy(&str->buffer[str->bufused], ptr, size * nmemb); |
| 81 | + str->bufused += size * nmemb; |
| 82 | + written = nmemb; |
| 83 | + //written = gzwrite(str->u.gzfilep, ptr, size * nmemb) / size; |
71 | 84 | break; |
72 | 85 | |
73 | 86 | default: |
— | — | @@ -83,10 +96,34 @@ |
84 | 97 | { |
85 | 98 | switch (str->type) { |
86 | 99 | case UNCOMPRESSED: |
87 | | - return fclose(str->u.filep); |
| 100 | + return fclose(str->filep); |
88 | 101 | |
89 | 102 | case COMPRESSED: |
90 | | - return gzclose(str->u.gzfilep); |
| 103 | + { |
| 104 | + int outsize = str->bufused + str->bufused / 8 + 256; |
| 105 | + str->buffer = (char*)realloc(str->buffer, str->bufused); |
| 106 | + char* buffer = (char*)malloc(outsize); |
| 107 | + int r = ucl_nrv2e_99_compress(str->buffer, str->bufused, buffer, &outsize, 0, 10, NULL, NULL);
|
| 108 | + free(str->buffer); |
| 109 | + if (r != UCL_E_OK)
|
| 110 | + {
|
| 111 | + free(buffer); |
| 112 | + /* this should NEVER happen */
|
| 113 | + printf("internal error - compression failed: %d\n", r);
|
| 114 | + return 2;
|
| 115 | + }
|
| 116 | + buffer = (char*)realloc(buffer, outsize);
|
| 117 | + int done = 0;
|
| 118 | + while (done < outsize)
|
| 119 | + {
|
| 120 | + int bytes = fwrite(&buffer[done], 1, outsize - done, str->filep);
|
| 121 | + if (bytes <= 0) return 3;
|
| 122 | + done += bytes;
|
| 123 | + }
|
| 124 | + free(buffer); |
| 125 | + return fclose(str->filep); |
| 126 | + } |
| 127 | +// return gzclose(str->u.gzfilep); |
91 | 128 | |
92 | 129 | default: |
93 | 130 | abort(); |
— | — | @@ -100,25 +137,26 @@ |
101 | 138 | { |
102 | 139 | switch (str->type) { |
103 | 140 | case UNCOMPRESSED: |
104 | | - return ferror(str->u.filep); |
| 141 | + return ferror(str->filep); |
105 | 142 | |
106 | 143 | case COMPRESSED: |
107 | | - { |
108 | | - const char *err; |
109 | | - int errno; |
| 144 | + return ferror(str->filep); |
| 145 | +// { |
| 146 | +// const char *err; |
| 147 | +// int errno; |
| 148 | +// |
| 149 | +// err = gzerror(str->u.gzfilep, &errno); |
| 150 | +// if (errno == Z_OK || errno == Z_STREAM_END) |
| 151 | +// return 0; |
| 152 | +// else if (errno == Z_ERRNO) |
| 153 | +// return 1; |
| 154 | +// else { |
| 155 | +// fprintf(stderr, "%s\n", err); |
| 156 | +// return 1; |
| 157 | +// } |
| 158 | +// } |
| 159 | +// break; |
110 | 160 | |
111 | | - err = gzerror(str->u.gzfilep, &errno); |
112 | | - if (errno == Z_OK || errno == Z_STREAM_END) |
113 | | - return 0; |
114 | | - else if (errno == Z_ERRNO) |
115 | | - return 1; |
116 | | - else { |
117 | | - fprintf(stderr, "%s\n", err); |
118 | | - return 1; |
119 | | - } |
120 | | - } |
121 | | - break; |
122 | | - |
123 | 161 | default: |
124 | 162 | abort(); |
125 | 163 | } |
— | — | @@ -131,10 +169,10 @@ |
132 | 170 | { |
133 | 171 | switch (str->type) { |
134 | 172 | case UNCOMPRESSED: |
135 | | - return fseek(str->u.filep, offset, whence); |
| 173 | + return fseek(str->filep, offset, whence); |
136 | 174 | |
137 | | - case COMPRESSED: |
138 | | - return gzseek(str->u.gzfilep, offset, whence); |
| 175 | +// case COMPRESSED: |
| 176 | +// return gzseek(str->u.gzfilep, offset, whence); |
139 | 177 | |
140 | 178 | default: |
141 | 179 | abort(); |
— | — | @@ -156,12 +194,12 @@ |
157 | 195 | if (str->type == INVALID) |
158 | 196 | abort(); |
159 | 197 | |
160 | | - fd = fileno(str->u.filep); |
| 198 | + fd = fileno(str->filep); |
161 | 199 | /* Get current (buffered) file position. */ |
162 | | - offset = ftell(str->u.filep); |
| 200 | + offset = ftell(str->filep); |
163 | 201 | |
164 | 202 | /* Make sure there's nothing left in buffers. */ |
165 | | - fflush(str->u.filep); |
| 203 | + fflush(str->filep); |
166 | 204 | |
167 | 205 | /* Reposition underlying FD. (Might be unnecessary?) */ |
168 | 206 | roffset = lseek(fd, offset, SEEK_SET); |
— | — | @@ -169,8 +207,8 @@ |
170 | 208 | assert(roffset == offset); |
171 | 209 | |
172 | 210 | /* Reopen as compressed stream. */ |
173 | | - str->u.gzfilep = gzdopen(fd, str->mode); |
174 | | - gzsetparams(str->u.gzfilep, 9, Z_DEFAULT_STRATEGY); |
| 211 | + //str->u.gzfilep = gzdopen(fd, str->mode); |
| 212 | + //gzsetparams(str->u.gzfilep, 9, Z_DEFAULT_STRATEGY); |
175 | 213 | str->type = COMPRESSED; |
176 | 214 | } |
177 | 215 | |