From b5cea7f966e21f6930afe2b8e41edf3b02014231 Mon Sep 17 00:00:00 2001 From: Pan Xiuli Date: Mon, 29 Jan 2018 14:08:13 +0800 Subject: [PATCH] rimage: add check for .bss section We may have heap buffers for base FW, but they are handled by the runtime function. We did not need to set them as bss in FW manifest. So add check to mark the .bss segment as BSS and other segment as HEAP. Then we only update manifest BSS segmet with BSS section. Signed-off-by: Pan Xiuli --- rimage/elf.c | 26 ++++++++++++++++++++------ rimage/rimage.h | 1 + 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/rimage/elf.c b/rimage/elf.c index b91247761..1dc48f3bf 100644 --- a/rimage/elf.c +++ b/rimage/elf.c @@ -27,6 +27,7 @@ static int elf_read_sections(struct image *image, struct module *module) size_t count; int i, ret; uint32_t valid = (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR); + int man_section_idx; /* read in section header */ ret = fseek(module->fd, hdr->e_shoff, SEEK_SET); @@ -50,6 +51,16 @@ static int elf_read_sections(struct image *image, struct module *module) return -errno; } + /* find manifest module data */ + man_section_idx = elf_find_section(image, module, ".bss"); + if (man_section_idx < 0) { + return -EINVAL; + } + module->bss_index = man_section_idx; + + fprintf(stdout, " BSS module metadata section at index %d\n", + man_section_idx); + /* parse each section */ for (i = 0; i < hdr->e_shnum; i++) { @@ -211,7 +222,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) + Elf32_Shdr *section, int index) { switch (section->sh_type) { case SHT_PROGBITS: @@ -236,12 +247,14 @@ static void elf_module_size(struct image *image, struct module *module, break; case SHT_NOBITS: /* bss */ - if (module->bss_start > section->sh_addr) + if (index == module->bss_index) { + /* updated the .bss segment */ module->bss_start = section->sh_addr; - if (module->bss_end < section->sh_addr + section->sh_size) module->bss_end = section->sh_addr + section->sh_size; - - fprintf(stdout, "\tBSS\n"); + fprintf(stdout, "\tBSS\n"); + } else { + fprintf(stdout, "\tHEAP\n"); + } break; default: break; @@ -282,7 +295,8 @@ static void elf_module_limits(struct image *image, struct module *module) section->sh_size); /* text or data section */ - elf_module_size(image, module, section); + elf_module_size(image, module, section, i); + } fprintf(stdout, "\n"); diff --git a/rimage/rimage.h b/rimage/rimage.h index 84ff93f74..a68f1a878 100644 --- a/rimage/rimage.h +++ b/rimage/rimage.h @@ -65,6 +65,7 @@ struct module { int num_sections; int num_bss; int fw_size; + int bss_index; /* sizes do not include any gaps */ int bss_size;