Skip to content

Commit

Permalink
rimage: module: Fix section order in output image
Browse files Browse the repository at this point in the history
Fixed the order in which sections are placed in the output firmware image
for platforms using a simple manifest.

Fixes: #8336

Signed-off-by: Adrian Warecki <[email protected]>
  • Loading branch information
softwarecki authored and kv2019i committed Oct 31, 2023
1 parent 165e68f commit 3cb13e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
3 changes: 2 additions & 1 deletion tools/rimage/src/include/rimage/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ struct module_sections_info {
/* sections count */
unsigned int count;

/* First section */
/* sections list */
struct module_section *first_section;
struct module_section *last_section;
};

/*
Expand Down
32 changes: 19 additions & 13 deletions tools/rimage/src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,31 @@ static void sections_info_init(struct module_sections_info *info)
* Adds section to module_sections_info structure
*
* @param info Pointer to a module_sections_info structure
* @param address section address
* @param size section size
* @param section module_section structure
*/
static void sections_info_add(struct module_sections_info *info, const uint32_t address,
const size_t size)
static void sections_info_add(struct module_sections_info *info, struct module_section *section)
{
const uint32_t end = address + size;
const uint32_t end = section->load_address + section->size;

if (address < info->start)
info->start = address;
if (section->load_address < info->start)
info->start = section->load_address;

if (end > info->end)
info->end = end;

info->size += size;
info->size += section->size;
info->count++;

/* Add section to list */
section->next_section = NULL;

if (info->last_section)
info->last_section->next_section = section;

info->last_section = section;

if (!info->first_section)
info->first_section = section;
}

/**
Expand Down Expand Up @@ -356,11 +365,8 @@ void module_parse_sections(struct module *module, const struct memory_config *me
fprintf(stdout, " ROM");
} else {
/* Add section to list */
if (info) {
sections_info_add(info, out_section->load_address, out_section->size);
out_section->next_section = info->first_section;
info->first_section = out_section;
}
if (info)
sections_info_add(info, out_section);
}

module->num_sections++;
Expand Down

0 comments on commit 3cb13e7

Please sign in to comment.