[Sound-open-firmware] [PATCH 1/3] rimage: validate manifest segments
make sure no manifest segments collide with each other and fail if they do.
Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- rimage/manifest.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
diff --git a/rimage/manifest.c b/rimage/manifest.c index 2b7e07f..b9848d0 100644 --- a/rimage/manifest.c +++ b/rimage/manifest.c @@ -260,6 +260,62 @@ static int man_get_module_manifest(struct image *image, struct module *module, return 0; }
+static inline const char *segment_name(int i) +{ + switch (i) { + case SOF_MAN_SEGMENT_TEXT: + return "TEXT"; + case SOF_MAN_SEGMENT_RODATA: + return "DATA"; + case SOF_MAN_SEGMENT_BSS: + return "BSS"; + default: + return "NONE"; + } +} + +/* make sure no segments collide */ +static int man_module_validate(struct sof_man_module *man_module) +{ + uint32_t istart, iend; + uint32_t jstart, jend; + int i, j; + + for (i = 0; i < 3; i++) { + + istart = man_module->segment[i].v_base_addr; + iend = istart + man_module->segment[i].flags.r.length * + MAN_PAGE_SIZE; + + for (j = 0; j < 3; j++) { + + /* don't validate segment against itself */ + if (i == j) + continue; + + jstart = man_module->segment[j].v_base_addr; + jend = jstart + man_module->segment[j].flags.r.length * + MAN_PAGE_SIZE; + + if (jstart > istart && jstart < iend) + goto err; + + if (jend > istart && jend < iend) + goto err; + } + } + + /* success, no overlapping segments */ + return 0; + +err: + fprintf(stderr, "error: segment %s [0x%8.8x:0x%8.8x] overlaps", + segment_name(i), istart, iend); + fprintf(stderr, " with %s [0x%8.8x:0x%8.8x]\n", + segment_name(j), jstart, jend); + return -EINVAL; +} + static int man_module_create(struct image *image, struct module *module, struct sof_man_module *man_module) { @@ -328,6 +384,10 @@ static int man_module_create(struct image *image, struct module *module,
fprintf(stdout, "\tNo\tAddress\t\tSize\tFile\tType\n");
+ /* validate segments */ + if (man_module_validate(man_module) < 0) + return -EINVAL; + /* find all sections and copy to corresponding segments */ for (i = 0; i < module->hdr.e_shnum; i++) {
Text base is from TEXT_BASE and not TEXT_START
Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- src/platform/apollolake/include/platform/memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/platform/apollolake/include/platform/memory.h b/src/platform/apollolake/include/platform/memory.h index 157be82..5f35927 100644 --- a/src/platform/apollolake/include/platform/memory.h +++ b/src/platform/apollolake/include/platform/memory.h @@ -178,7 +178,7 @@
/* Heap configuration */ #define HEAP_SYSTEM_BASE \ - (REEF_TEXT_START + REEF_TEXT_SIZE + \ + (REEF_TEXT_BASE + REEF_TEXT_SIZE +\ REEF_DATA_SIZE + REEF_BSS_DATA_SIZE) #define HEAP_SYSTEM_SIZE 0x2000
Increase APL text size by 4k to avoid segmemt collision with data.
Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- src/platform/apollolake/include/platform/memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/platform/apollolake/include/platform/memory.h b/src/platform/apollolake/include/platform/memory.h index 5f35927..b4fae8e 100644 --- a/src/platform/apollolake/include/platform/memory.h +++ b/src/platform/apollolake/include/platform/memory.h @@ -168,7 +168,7 @@ #define L2_VECTOR_SIZE 0x1000
#define REEF_TEXT_BASE (L2_SRAM_BASE + L2_VECTOR_SIZE) -#define REEF_TEXT_SIZE 0x18000 +#define REEF_TEXT_SIZE 0x19000
/* initialized data */ #define REEF_DATA_SIZE 0x18000
participants (1)
-
Liam Girdwood