diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2017-01-01 19:46:01 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2017-01-16 19:58:31 +0100 |
commit | 5ff3a3a98f23bb1a0dd1fb97e074ddb80337ae27 (patch) | |
tree | 481f63dc08db67d2355fc70a2463089d8e2654d2 /utils/imxtools/sbtools/sbtoelf.c | |
parent | 2b20026dd755706934f8f8e1a192bffdfc3d717c (diff) | |
download | rockbox-5ff3a3a98f23bb1a0dd1fb97e074ddb80337ae27.tar.gz rockbox-5ff3a3a98f23bb1a0dd1fb97e074ddb80337ae27.zip |
imxtools/sbtools: various fixes
Change bug() macro, fix memory leaks, always use -h for help, fix usage(),
fix comment, remove useless macro
Change-Id: I30554b5e07e6f2845560a570808603cf8c4da5ad
Diffstat (limited to 'utils/imxtools/sbtools/sbtoelf.c')
-rw-r--r-- | utils/imxtools/sbtools/sbtoelf.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c index ac8db068aa..11a46968dd 100644 --- a/utils/imxtools/sbtools/sbtoelf.c +++ b/utils/imxtools/sbtools/sbtoelf.c | |||
@@ -48,15 +48,6 @@ | |||
48 | /* all blocks are sized as a multiple of 0x1ff */ | 48 | /* all blocks are sized as a multiple of 0x1ff */ |
49 | #define PAD_TO_BOUNDARY(x) (((x) + 0x1ff) & ~0x1ff) | 49 | #define PAD_TO_BOUNDARY(x) (((x) + 0x1ff) & ~0x1ff) |
50 | 50 | ||
51 | /* If you find a firmware that breaks the known format ^^ */ | ||
52 | #define assert(a) do { if(!(a)) { fprintf(stderr,"Assertion \"%s\" failed in %s() line %d!\n\nPlease send us your firmware!\n",#a,__func__,__LINE__); exit(1); } } while(0) | ||
53 | |||
54 | #define crypto_cbc(...) \ | ||
55 | do { int ret = crypto_cbc(__VA_ARGS__); \ | ||
56 | if(ret != CRYPTO_ERROR_SUCCESS) \ | ||
57 | bug("crypto_cbc error: %d\n", ret); \ | ||
58 | }while(0) | ||
59 | |||
60 | /* globals */ | 51 | /* globals */ |
61 | 52 | ||
62 | static char *g_out_prefix; | 53 | static char *g_out_prefix; |
@@ -116,7 +107,8 @@ static void extract_sb_section(struct sb_section_t *sec, struct cmd_file_t *cmd_ | |||
116 | 107 | ||
117 | for(int j = 0; j < sec->nr_insts; j++) | 108 | for(int j = 0; j < sec->nr_insts; j++) |
118 | { | 109 | { |
119 | assert(sec->insts[j].inst == SB_INST_DATA); | 110 | if(sec->insts[j].inst != SB_INST_DATA) |
111 | bug("Internal errror: should be a data section\n"); | ||
120 | fwrite(sec->insts[j].data, sec->insts[j].size, 1, fd); | 112 | fwrite(sec->insts[j].data, sec->insts[j].size, 1, fd); |
121 | } | 113 | } |
122 | fclose(fd); | 114 | fclose(fd); |
@@ -185,6 +177,7 @@ static void extract_sb_file(struct sb_file_t *file) | |||
185 | printf("Write command file to %s\n", filename); | 177 | printf("Write command file to %s\n", filename); |
186 | db_generate_file(cmd_file, filename, NULL, generic_std_printf); | 178 | db_generate_file(cmd_file, filename, NULL, generic_std_printf); |
187 | db_free(cmd_file); | 179 | db_free(cmd_file); |
180 | free(filename); | ||
188 | } | 181 | } |
189 | 182 | ||
190 | static void extract_elf(struct elf_params_t *elf, int count) | 183 | static void extract_elf(struct elf_params_t *elf, int count) |
@@ -248,13 +241,13 @@ static void usage(void) | |||
248 | { | 241 | { |
249 | printf("Usage: sbtoelf [options] sb-file\n"); | 242 | printf("Usage: sbtoelf [options] sb-file\n"); |
250 | printf("Options:\n"); | 243 | printf("Options:\n"); |
251 | printf(" -?/--help Display this message\n"); | 244 | printf(" -h/--help Display this message\n"); |
252 | printf(" -o <prefix> Enable output and set prefix\n"); | 245 | printf(" -o <prefix> Enable output and set prefix\n"); |
253 | printf(" -d/--debug Enable debug output*\n"); | 246 | printf(" -d/--debug Enable debug output*\n"); |
254 | printf(" -k <file> Add key file\n"); | 247 | printf(" -k <file> Add key file\n"); |
255 | printf(" -z Add zero key\n"); | 248 | printf(" -z Add zero key\n"); |
256 | printf(" -r Use raw command mode\n"); | 249 | printf(" -r Use raw command mode\n"); |
257 | printf(" -a/--add-key <key> Add single key (hex or usbotp)\n"); | 250 | printf(" -a/--add-key <key> Add single key\n"); |
258 | printf(" -n/--no-color Disable output colors\n"); | 251 | printf(" -n/--no-color Disable output colors\n"); |
259 | printf(" -l/--loopback <file> Produce sb file out of extracted description*\n"); | 252 | printf(" -l/--loopback <file> Produce sb file out of extracted description*\n"); |
260 | printf(" -f/--force Force reading even without a key*\n"); | 253 | printf(" -f/--force Force reading even without a key*\n"); |
@@ -280,7 +273,7 @@ int main(int argc, char **argv) | |||
280 | { | 273 | { |
281 | static struct option long_options[] = | 274 | static struct option long_options[] = |
282 | { | 275 | { |
283 | {"help", no_argument, 0, '?'}, | 276 | {"help", no_argument, 0, 'h'}, |
284 | {"debug", no_argument, 0, 'd'}, | 277 | {"debug", no_argument, 0, 'd'}, |
285 | {"add-key", required_argument, 0, 'a'}, | 278 | {"add-key", required_argument, 0, 'a'}, |
286 | {"no-color", no_argument, 0, 'n'}, | 279 | {"no-color", no_argument, 0, 'n'}, |
@@ -293,7 +286,7 @@ int main(int argc, char **argv) | |||
293 | {0, 0, 0, 0} | 286 | {0, 0, 0, 0} |
294 | }; | 287 | }; |
295 | 288 | ||
296 | int c = getopt_long(argc, argv, "?do:k:zra:nl:f12xsb", long_options, NULL); | 289 | int c = getopt_long(argc, argv, "hdo:k:zra:nl:f12xsb", long_options, NULL); |
297 | if(c == -1) | 290 | if(c == -1) |
298 | break; | 291 | break; |
299 | switch(c) | 292 | switch(c) |
@@ -311,7 +304,7 @@ int main(int argc, char **argv) | |||
311 | case 'd': | 304 | case 'd': |
312 | g_debug = true; | 305 | g_debug = true; |
313 | break; | 306 | break; |
314 | case '?': | 307 | case 'h': |
315 | usage(); | 308 | usage(); |
316 | break; | 309 | break; |
317 | case 'o': | 310 | case 'o': |