From 4cab9f26b64f94ad0d09419d373155a8f77009b1 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sat, 29 Oct 2011 22:27:53 +0000 Subject: [PATCH] sbtools: fix handling of raw mode, have elf_write looks like elf_read, fix uninitiliazed offset of bss sections, add real key override on decrypt git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30858 a1c6a512-1295-4272-9138-f99709370657 --- utils/sbtools/elf.c | 8 +++++++- utils/sbtools/elf.h | 2 +- utils/sbtools/sbtoelf.c | 25 ++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/utils/sbtools/elf.c b/utils/sbtools/elf.c index 896c9cb1c0..718cb58b05 100644 --- a/utils/sbtools/elf.c +++ b/utils/sbtools/elf.c @@ -19,6 +19,7 @@ * ****************************************************************************/ #include "elf.h" +#include "misc.h" /** * Definitions @@ -219,7 +220,8 @@ void elf_add_fill_section(struct elf_params_t *params, sec->pattern = pattern; } -void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *user) +void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, + elf_printf_fn_t printf, void *user) { Elf32_Ehdr ehdr; uint32_t phnum = 0; @@ -236,6 +238,10 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *use sec->offset = offset; offset += sec->size; } + else + { + sec->offset = 0; + } phnum++; sec = sec->next; diff --git a/utils/sbtools/elf.h b/utils/sbtools/elf.h index f85595d784..2166833276 100644 --- a/utils/sbtools/elf.h +++ b/utils/sbtools/elf.h @@ -82,7 +82,7 @@ void elf_add_fill_section(struct elf_params_t *params, uint32_t fill_addr, uint32_t size, uint32_t pattern); uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr); void elf_translate_addresses(struct elf_params_t *params); -void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *user); +void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, elf_printf_fn_t printf, void *user); bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf, void *user); bool elf_is_empty(struct elf_params_t *params); diff --git a/utils/sbtools/sbtoelf.c b/utils/sbtools/sbtoelf.c index 87017ab12d..47aebe7890 100644 --- a/utils/sbtools/sbtoelf.c +++ b/utils/sbtools/sbtoelf.c @@ -86,6 +86,17 @@ static uint8_t instruction_checksum(struct sb_instruction_header_t *hdr) return sum; } +static void elf_printf(void *user, bool error, const char *fmt, ...) +{ + if(!g_debug && !error) + return; + (void) user; + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + static void elf_write(void *user, uint32_t addr, const void *buf, size_t count) { FILE *f = user; @@ -105,7 +116,7 @@ static void extract_elf_section(struct elf_params_t *elf, int count, const char if(fd == NULL) return ; - elf_write_file(elf, elf_write, fd); + elf_write_file(elf, elf_write, elf_printf, fd); fclose(fd); } @@ -481,6 +492,15 @@ static void extract(unsigned long filesize) } } + if(getenv("SB_REAL_KEY") != 0) + { + struct crypto_key_t k; + char *env = getenv("SB_REAL_KEY"); + if(!parse_key(&env, &k) || *env) + bug("Invalid SB_REAL_KEY"); + memcpy(real_key, k.u.key, 16); + } + color(RED); printf(" Summary:\n"); color(GREEN); @@ -751,6 +771,9 @@ int main(int argc, char **argv) add_keys(&g_zero_key, 1); break; } + case 'r': + g_raw_mode = true; + break; case 'a': { struct crypto_key_t key;