[Sound-open-firmware] [PATCH] rimage: add check for .bss section

Xiuli Pan xiuli.pan at linux.intel.com
Mon Jan 29 07:08:13 CET 2018


From: Pan Xiuli <xiuli.pan at linux.intel.com>

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 <xiuli.pan at linux.intel.com>
---
Test with:
GP-MRB with NoCodec, Mininow max rt5651
SOF master: 0505823b9667036202758ea950c3ff3347359730
SOF-Tool master: 8c9ebfe9c4f8037b0d0816dedcb87dabef347c6b
https://github.com/plbossart/sound/tree/topic/sof-v4.14:
5a91e6776d41b0e97828882294cdc00b5c0bafd6
---
 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 b912477..1dc48f3 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 84ff93f..a68f1a8 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;
-- 
2.7.4



More information about the Sound-open-firmware mailing list