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>
This commit is contained in:
Liam Girdwood 2018-02-27 16:35:10 +00:00
parent 40664b3f7b
commit 041423bfe3
1 changed files with 60 additions and 0 deletions

View File

@ -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++) {