Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LMA: Add changes from FW repo #15

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions src/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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");
}
Expand Down Expand Up @@ -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;
Expand All @@ -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++) {
Expand All @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down