summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2011-10-29 22:27:53 +0000
committerAmaury Pouly <pamaury@rockbox.org>2011-10-29 22:27:53 +0000
commit4cab9f26b64f94ad0d09419d373155a8f77009b1 (patch)
tree72ce7268acb30bb3676ce0469160afcf0897125f
parentfd187ad14cb1248d804d208a92e8d4c8e69c0d12 (diff)
downloadrockbox-4cab9f26b64f94ad0d09419d373155a8f77009b1.tar.gz
rockbox-4cab9f26b64f94ad0d09419d373155a8f77009b1.zip
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
-rw-r--r--utils/sbtools/elf.c8
-rw-r--r--utils/sbtools/elf.h2
-rw-r--r--utils/sbtools/sbtoelf.c25
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 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "elf.h" 21#include "elf.h"
22#include "misc.h"
22 23
23/** 24/**
24 * Definitions 25 * Definitions
@@ -219,7 +220,8 @@ void elf_add_fill_section(struct elf_params_t *params,
219 sec->pattern = pattern; 220 sec->pattern = pattern;
220} 221}
221 222
222void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *user) 223void elf_write_file(struct elf_params_t *params, elf_write_fn_t write,
224 elf_printf_fn_t printf, void *user)
223{ 225{
224 Elf32_Ehdr ehdr; 226 Elf32_Ehdr ehdr;
225 uint32_t phnum = 0; 227 uint32_t phnum = 0;
@@ -236,6 +238,10 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *use
236 sec->offset = offset; 238 sec->offset = offset;
237 offset += sec->size; 239 offset += sec->size;
238 } 240 }
241 else
242 {
243 sec->offset = 0;
244 }
239 245
240 phnum++; 246 phnum++;
241 sec = sec->next; 247 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,
82 uint32_t fill_addr, uint32_t size, uint32_t pattern); 82 uint32_t fill_addr, uint32_t size, uint32_t pattern);
83uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr); 83uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr);
84void elf_translate_addresses(struct elf_params_t *params); 84void elf_translate_addresses(struct elf_params_t *params);
85void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *user); 85void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, elf_printf_fn_t printf, void *user);
86bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf, 86bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf,
87 void *user); 87 void *user);
88bool elf_is_empty(struct elf_params_t *params); 88bool 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)
86 return sum; 86 return sum;
87} 87}
88 88
89static void elf_printf(void *user, bool error, const char *fmt, ...)
90{
91 if(!g_debug && !error)
92 return;
93 (void) user;
94 va_list args;
95 va_start(args, fmt);
96 vprintf(fmt, args);
97 va_end(args);
98}
99
89static void elf_write(void *user, uint32_t addr, const void *buf, size_t count) 100static void elf_write(void *user, uint32_t addr, const void *buf, size_t count)
90{ 101{
91 FILE *f = user; 102 FILE *f = user;
@@ -105,7 +116,7 @@ static void extract_elf_section(struct elf_params_t *elf, int count, const char
105 116
106 if(fd == NULL) 117 if(fd == NULL)
107 return ; 118 return ;
108 elf_write_file(elf, elf_write, fd); 119 elf_write_file(elf, elf_write, elf_printf, fd);
109 fclose(fd); 120 fclose(fd);
110} 121}
111 122
@@ -481,6 +492,15 @@ static void extract(unsigned long filesize)
481 } 492 }
482 } 493 }
483 494
495 if(getenv("SB_REAL_KEY") != 0)
496 {
497 struct crypto_key_t k;
498 char *env = getenv("SB_REAL_KEY");
499 if(!parse_key(&env, &k) || *env)
500 bug("Invalid SB_REAL_KEY");
501 memcpy(real_key, k.u.key, 16);
502 }
503
484 color(RED); 504 color(RED);
485 printf(" Summary:\n"); 505 printf(" Summary:\n");
486 color(GREEN); 506 color(GREEN);
@@ -751,6 +771,9 @@ int main(int argc, char **argv)
751 add_keys(&g_zero_key, 1); 771 add_keys(&g_zero_key, 1);
752 break; 772 break;
753 } 773 }
774 case 'r':
775 g_raw_mode = true;
776 break;
754 case 'a': 777 case 'a':
755 { 778 {
756 struct crypto_key_t key; 779 struct crypto_key_t key;