[Sound-open-firmware] [PATCH 2/2] rimage: read the fixup text size form ELF

Xiuli Pan xiuli.pan at linux.intel.com
Fri Mar 2 08:55:27 CET 2018


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

The actual text size will change and the hard code base_fw_text_size_fixup
could not fit the changing size. We should get the fixup size from the
module info just from the memory mapping.

Signed-off-by: Pan Xiuli <xiuli.pan at linux.intel.com>

---
Test with:
Mininow max rt5651 GP-MRB nocodec
SOF master: 1693b66bb1d804ded975767cc1e5911e6ff9c93c
SOF-Tool master: a02abb799405d0e4ad0d6bb46eacf6fbe958c06e
https://github.com/plbossart/sound/tree/topic/sof-v4.14:
9513a73b981bc1917705671ec54402a7e21672eb
---
 rimage/elf.c      |  7 -------
 rimage/manifest.c | 17 ++++++++++++++---
 rimage/rimage.h   |  4 +---
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/rimage/elf.c b/rimage/elf.c
index b96222b..78f6d57 100644
--- a/rimage/elf.c
+++ b/rimage/elf.c
@@ -500,13 +500,6 @@ int elf_parse_module(struct image *image, int module_index, const char *name)
 	if (rem)
 		module->text_file_size += MAN_PAGE_SIZE - rem;
 
-
-	/* apply any base FW fixups */
-	if (image->adsp->base_fw_text_size_fixup &&
-		module->text_start == image->adsp->sram_base) {
-		module->text_file_size += image->adsp->base_fw_text_size_fixup;
-	}
-
 	/* data section */
 	module->data_file_size = module->data_end - module->data_start;
 	rem = module->data_file_size % MAN_PAGE_SIZE;
diff --git a/rimage/manifest.c b/rimage/manifest.c
index b9848d0..337f82a 100644
--- a/rimage/manifest.c
+++ b/rimage/manifest.c
@@ -109,7 +109,7 @@ static uint32_t elf_to_file_offset(struct image *image,
 		} else {
 			/* rodata segment, append to text segment */
 			file_offset = elf_addr - module->data_start +
-				module->foffset + module->text_file_size;
+				module->foffset + module->text_fixup_size;
 
 		}
 	} else if (section->sh_type == SHT_NOBITS) {
@@ -233,6 +233,9 @@ static int man_get_module_manifest(struct image *image, struct module *module,
 	man_module->type.domain_ll = sof_mod.type.domain_ll;
 	man_module->type.load_type = sof_mod.type.load_type;
 
+	/* read out text_fixup_size from memory mapping */
+	module->text_fixup_size = sof_mod.text_size;
+
 	/* text segment */
 	segment = &man_module->segment[SOF_MAN_SEGMENT_TEXT];
 	segment->flags.r.contents = 1;
@@ -361,13 +364,22 @@ static int man_module_create(struct image *image, struct module *module,
 	if (module->text_file_size % MAN_PAGE_SIZE)
 		pages += 1;
 
+	if (module->text_fixup_size == 0)
+		module->text_fixup_size = module->text_file_size;
+
+	/* check if text_file_size is bigger then text_fixup_size */
+	if (module->text_file_size > module->text_fixup_size) {
+		fprintf(stderr, "error: too small text size assigned!\n");
+		return -EINVAL;
+	}
+
 	man_module->segment[SOF_MAN_SEGMENT_TEXT].flags.r.length = pages;
 
 	/* data section */
 	man_module->segment[SOF_MAN_SEGMENT_RODATA].v_base_addr =
 		module->data_start;
 	man_module->segment[SOF_MAN_SEGMENT_RODATA].file_offset =
-			module->foffset + module->text_file_size;
+			module->foffset + module->text_fixup_size;
 	pages = module->data_file_size / MAN_PAGE_SIZE;
 	if (module->data_file_size % MAN_PAGE_SIZE)
 		pages += 1;
@@ -627,7 +639,6 @@ const struct adsp machine_apl = {
 	.machine_id = MACHINE_APOLLOLAKE,
 	.write_firmware = man_write_fw,
 	.man = &apl_manifest,
-	.base_fw_text_size_fixup = 0xa000,
 };
 
 const struct adsp machine_cnl = {
diff --git a/rimage/rimage.h b/rimage/rimage.h
index adcb8c5..654ba90 100644
--- a/rimage/rimage.h
+++ b/rimage/rimage.h
@@ -75,6 +75,7 @@ struct module {
 	/* sizes do include gaps to nearest page */
 	int bss_file_size;
 	int text_file_size;
+	int text_fixup_size;
 	int data_file_size;
 };
 
@@ -135,9 +136,6 @@ struct adsp {
 	enum machine_id machine_id;
 	int (*write_firmware)(struct image *image);
 	struct fw_image_manifest *man;
-
-	/* fixups */
-	uint32_t base_fw_text_size_fixup;	/* added to BASEFW text size */
 };
 
 void module_sha256_create(struct image *image);
-- 
2.7.4



More information about the Sound-open-firmware mailing list