From: Michel Pollet Date: Sat, 13 Jun 2015 20:27:35 +0000 (+0100) Subject: elf: Detect start address (for bootloaders) X-Git-Tag: v1.6~67 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=4d01510fc5bc4a0fecb9830817be186342f343f3;p=sx%2Fsimavr.git elf: Detect start address (for bootloaders) Allows loading a bootloader ELF as well as .hex with the right starting PC Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/sim_elf.c b/simavr/sim/sim_elf.c index a0a49ee..33a60ae 100644 --- a/simavr/sim/sim_elf.c +++ b/simavr/sim/sim_elf.c @@ -296,6 +296,9 @@ int elf_read_firmware(const char * file, elf_firmware_t * firmware) ELF32_ST_TYPE(sym.st_info) == STT_OBJECT) { const char * name = elf_strptr(elf, shdr.sh_link, sym.st_name); + // if its a bootloader, this symbol will be the entry point we need + if (!strcmp(name, "__vectors")) + firmware->flashbase = sym.st_value; avr_symbol_t * s = malloc(sizeof(avr_symbol_t) + strlen(name) + 1); strcpy((char*)s->symbol, name); s->addr = sym.st_value; @@ -332,8 +335,9 @@ int elf_read_firmware(const char * file, elf_firmware_t * firmware) if (data_text) { // hdump("code", data_text->d_buf, data_text->d_size); memcpy(firmware->flash + offset, data_text->d_buf, data_text->d_size); + AVR_LOG(NULL, LOG_TRACE, "Loaded %u .text at address 0x%x\n", + (unsigned int)data_text->d_size, firmware->flashbase); offset += data_text->d_size; - AVR_LOG(NULL, LOG_TRACE, "Loaded %u .text\n", (unsigned int)data_text->d_size); } if (data_data) { // hdump("data", data_data->d_buf, data_data->d_size);