diff --git a/src/elf.c b/src/elf.c index 851f607..34a9aa7 100644 --- a/src/elf.c +++ b/src/elf.c @@ -243,7 +243,7 @@ int elf_is_rom(struct image *image, Elf32_Shdr *section) } static void elf_module_size(struct image *image, struct module *module, - Elf32_Shdr *section, int index) + Elf32_Shdr *section, uint32_t lma, int index) { switch (section->type) { case SHT_INIT_ARRAY: @@ -252,20 +252,17 @@ static void elf_module_size(struct image *image, struct module *module, /* text or data */ if (section->flags & SHF_EXECINSTR) { /* text */ - if (module->text_start > section->vaddr) - module->text_start = section->vaddr; - if (module->text_end < section->vaddr + section->size) - module->text_end = section->vaddr + - section->size; - + if (module->text_start > lma) + module->text_start = lma; + if (module->text_end < lma + section->size) + module->text_end = lma + section->size; fprintf(stdout, "\tTEXT\t"); } else { /* initialized data, also calc the writable sections */ - if (module->data_start > section->vaddr) - module->data_start = section->vaddr; - if (module->data_end < section->vaddr + section->size) - module->data_end = section->vaddr + - section->size; + if (module->data_start > lma) + module->data_start = lma; + if (module->data_end < lma + section->size) + module->data_end = lma + section->size; fprintf(stdout, "\tDATA\t"); } @@ -329,7 +326,8 @@ static void elf_module_limits(struct image *image, struct module *module) { Elf32_Shdr *section; uint32_t valid = (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR); - int i; + uint32_t section_lma; + int i, j; module->text_start = 0xffffffff; module->data_start = 0xffffffff; @@ -341,7 +339,7 @@ static void elf_module_limits(struct image *image, struct module *module) fprintf(stdout, " Found %d sections, listing valid sections......\n", module->hdr.shnum); - fprintf(stdout, "\tNo\tStart\t\tEnd\t\tSize\tType\tName\n"); + fprintf(stdout, "\tNo\tLMA\t\tVMA\t\tEnd\t\tSize\tType\tName\n"); /* iterate all sections and get size of segments */ for (i = 0; i < module->hdr.shnum; i++) { @@ -359,16 +357,24 @@ static void elf_module_limits(struct image *image, struct module *module) if (elf_is_rom(image, section)) continue; } + /* check programs to get LMA */ + section_lma = section->vaddr; + for (j = 0; j < module->hdr.phnum; j++) { + if (section->vaddr == module->prg[j].vaddr) { + section_lma = module->prg[j].paddr; + break; + } + } - fprintf(stdout, "\t%d\t0x%8.8x\t0x%8.8x\t0x%x", i, - section->vaddr, section->vaddr + section->size, - section->size); + fprintf(stdout, "\t%d\t0x%8.8x\t0x%8.8x\t0x%8.8x\t0x%x", i, + section_lma, section->vaddr, + section->vaddr + section->size, section->size); /* text or data section */ if (image->reloc) elf_module_size_reloc(image, module, section, i); else - elf_module_size(image, module, section, i); + elf_module_size(image, module, section, section_lma, i); /* section name */ fprintf(stdout, "%s\n", module->strings + section->name); diff --git a/src/manifest.c b/src/manifest.c index e38b588..d97ed36 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -126,9 +126,16 @@ static uint32_t elf_to_file_offset(struct image *image, struct sof_man_module *man_module, Elf32_Shdr *section) { - uint32_t elf_addr = section->vaddr, file_offset = 0; + uint32_t elf_addr = section->vaddr, file_offset = 0, i; if (section->type == SHT_PROGBITS || section->type == SHT_INIT_ARRAY) { + /* check programs for lma/vma change */ + for (i = 0; i < module->hdr.phnum; i++) { + if (section->vaddr == module->prg[i].vaddr) { + elf_addr = module->prg[i].paddr; + break; + } + } if (section->flags & SHF_EXECINSTR) { /* text segment */ file_offset = elf_addr - module->text_start +