diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-07-18 00:27:12 +0200 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-07-18 00:27:12 +0200 |
commit | 1c8c24183ed9d89519de2924997593cc81f6f33d (patch) | |
tree | ba4a7babace41a249c44467982d5e6a70b8d7796 /utils/imxtools/sbtools/elftosb.c | |
parent | 3c5ee9ac57cbac4050df1729a28ec39c60d303ff (diff) | |
download | rockbox-1c8c24183ed9d89519de2924997593cc81f6f33d.tar.gz rockbox-1c8c24183ed9d89519de2924997593cc81f6f33d.zip |
sbtools: refactor and cleanup
Factor common elf/sb read/write/printf routines. Factor sb zero
key, move sb version guess.
Change-Id: I5ae1885587456736e782e623610281bbee545039
Diffstat (limited to 'utils/imxtools/sbtools/elftosb.c')
-rw-r--r-- | utils/imxtools/sbtools/elftosb.c | 30 |
1 files changed, 4 insertions, 26 deletions
diff --git a/utils/imxtools/sbtools/elftosb.c b/utils/imxtools/sbtools/elftosb.c index fd44693a94..a18bad6437 100644 --- a/utils/imxtools/sbtools/elftosb.c +++ b/utils/imxtools/sbtools/elftosb.c | |||
@@ -52,24 +52,6 @@ int g_extern_count; | |||
52 | * command file to sb conversion | 52 | * command file to sb conversion |
53 | */ | 53 | */ |
54 | 54 | ||
55 | static bool elf_read(void *user, uint32_t addr, void *buf, size_t count) | ||
56 | { | ||
57 | if(fseek((FILE *)user, addr, SEEK_SET) == -1) | ||
58 | return false; | ||
59 | return fread(buf, 1, count, (FILE *)user) == count; | ||
60 | } | ||
61 | |||
62 | static void elf_printf(void *user, bool error, const char *fmt, ...) | ||
63 | { | ||
64 | if(!g_debug && !error) | ||
65 | return; | ||
66 | (void) user; | ||
67 | va_list args; | ||
68 | va_start(args, fmt); | ||
69 | vprintf(fmt, args); | ||
70 | va_end(args); | ||
71 | } | ||
72 | |||
73 | static void resolve_extern(struct cmd_source_t *src) | 55 | static void resolve_extern(struct cmd_source_t *src) |
74 | { | 56 | { |
75 | if(!src->is_extern) | 57 | if(!src->is_extern) |
@@ -102,7 +84,7 @@ static void load_elf_by_id(struct cmd_file_t *cmd_file, const char *id) | |||
102 | if(g_debug) | 84 | if(g_debug) |
103 | printf("Loading ELF file '%s'...\n", src->filename); | 85 | printf("Loading ELF file '%s'...\n", src->filename); |
104 | elf_init(&src->elf); | 86 | elf_init(&src->elf); |
105 | src->loaded = elf_read_file(&src->elf, elf_read, elf_printf, fd); | 87 | src->loaded = elf_read_file(&src->elf, elf_std_read, elf_std_printf, fd); |
106 | fclose(fd); | 88 | fclose(fd); |
107 | if(!src->loaded) | 89 | if(!src->loaded) |
108 | bug("error loading elf file '%s' (id '%s')\n", src->filename, id); | 90 | bug("error loading elf file '%s' (id '%s')\n", src->filename, id); |
@@ -333,12 +315,6 @@ static void usage(void) | |||
333 | exit(1); | 315 | exit(1); |
334 | } | 316 | } |
335 | 317 | ||
336 | static struct crypto_key_t g_zero_key = | ||
337 | { | ||
338 | .method = CRYPTO_KEY, | ||
339 | .u.key = {0} | ||
340 | }; | ||
341 | |||
342 | int main(int argc, char **argv) | 318 | int main(int argc, char **argv) |
343 | { | 319 | { |
344 | char *cmd_filename = NULL; | 320 | char *cmd_filename = NULL; |
@@ -385,6 +361,8 @@ int main(int argc, char **argv) | |||
385 | } | 361 | } |
386 | case 'z': | 362 | case 'z': |
387 | { | 363 | { |
364 | struct crypto_key_t g_zero_key; | ||
365 | sb_get_zero_key(&g_zero_key); | ||
388 | add_keys(&g_zero_key, 1); | 366 | add_keys(&g_zero_key, 1); |
389 | break; | 367 | break; |
390 | } | 368 | } |
@@ -407,7 +385,7 @@ int main(int argc, char **argv) | |||
407 | break; | 385 | break; |
408 | } | 386 | } |
409 | default: | 387 | default: |
410 | abort(); | 388 | bug("Internal error: unknown option '%c'\n", c); |
411 | } | 389 | } |
412 | } | 390 | } |
413 | 391 | ||