diff options
| author | Amaury Pouly <amaury.pouly@gmail.com> | 2012-11-27 22:38:48 +0100 |
|---|---|---|
| committer | Amaury Pouly <amaury.pouly@gmail.com> | 2012-11-27 22:38:48 +0100 |
| commit | 8189732e52080353dbf38933a8c71c6dc6811f2a (patch) | |
| tree | 299a1b0ac3b40db750f45bc5d790cc9c8f80b63a /utils/imxtools/sbtools/sbtoelf.c | |
| parent | 7dc3e939d2cd0a39035587f211587167eb6671de (diff) | |
| download | rockbox-8189732e52080353dbf38933a8c71c6dc6811f2a.zip rockbox-8189732e52080353dbf38933a8c71c6dc6811f2a.tar.gz rockbox-8189732e52080353dbf38933a8c71c6dc6811f2a.tar.bz2 rockbox-8189732e52080353dbf38933a8c71c6dc6811f2a.tar.xz | |
sbtoelf: implement sb extraction for sb1
Load, fill and call/jump instructions are extracted as elf files
like for sb2. Because of the size limitations of the sb1
instructions, the resulting elf files can easily have hundreds of
sections. The (currently) implemented elf simplification method
will hopefully reduce this to a few sections only
Change-Id: I8fd6ed935ac3128f244bbd71c782e2a0a1c6d44a
Diffstat (limited to 'utils/imxtools/sbtools/sbtoelf.c')
| -rw-r--r-- | utils/imxtools/sbtools/sbtoelf.c | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c index 01a51ca..f86200f 100644 --- a/utils/imxtools/sbtools/sbtoelf.c +++ b/utils/imxtools/sbtools/sbtoelf.c @@ -157,12 +157,56 @@ static void extract_sb_file(struct sb_file_t *file) extract_sb_section(&file->sections[i]); } +static void extract_elf(struct elf_params_t *elf, int count) +{ + char *filename = xmalloc(strlen(g_out_prefix) + 32); + sprintf(filename, "%s.%d.elf", g_out_prefix, count); + if(g_debug) + printf("Write boot content to %s\n", filename); + + FILE *fd = fopen(filename, "wb"); + free(filename); + + if(fd == NULL) + return ; + elf_simplify(elf); + elf_write_file(elf, elf_write, elf_printf, fd); + fclose(fd); +} + static void extract_sb1_file(struct sb1_file_t *file) { - FILE *f = fopen(g_out_prefix, "wb"); - if(f == NULL) - bugp("Cannot open %s for writing\n", g_out_prefix); - fclose(f); + int elf_count = 0; + struct elf_params_t elf; + elf_init(&elf); + + for(int i = 0; i < file->nr_insts; i++) + { + struct sb1_inst_t *inst = &file->insts[i]; + switch(inst->cmd) + { + case SB1_INST_LOAD: + elf_add_load_section(&elf, inst->addr, inst->size, inst->data); + break; + case SB1_INST_FILL: + elf_add_fill_section(&elf, inst->addr, inst->size, inst->pattern); + break; + case SB1_INST_CALL: + case SB1_INST_JUMP: + elf_set_start_addr(&elf, inst->addr); + extract_elf(&elf, elf_count++); + elf_release(&elf); + elf_init(&elf); + break; + default: + /* ignore mode and nop */ + break; + } + } + + if(!elf_is_empty(&elf)) + extract_elf(&elf, elf_count); + elf_release(&elf); } static void usage(void) |