Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rimage: manifest: Improve handling of empty segments #8531

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions tools/rimage/src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,21 @@ static int man_get_module_manifest(struct image *image, struct manifest_module *
segment->flags.r.load = 1;
segment->flags.r.readonly = 1;
segment->flags.r.code = 1;
segment->flags.r.type = SOF_MAN_SEGMENT_TEXT;

/* data segment */
segment = &man_module->segment[SOF_MAN_SEGMENT_RODATA];
segment->flags.r.contents = 1;
segment->flags.r.alloc = 1;
segment->flags.r.load = 1;
segment->flags.r.readonly = 1;
segment->flags.r.readonly = 0; /* rodata segment contains also writtable data */
segment->flags.r.data = 1;
segment->flags.r.type = 1;
segment->flags.r.type = SOF_MAN_SEGMENT_RODATA;

/* bss segment */
segment = &man_module->segment[SOF_MAN_SEGMENT_BSS];
segment->flags.r.alloc = 1;
segment->flags.r.type = 2;
segment->flags.r.type = SOF_MAN_SEGMENT_BSS;

fprintf(stdout, " Entry point 0x%8.8x\n", man_module->entry_point);

Expand Down Expand Up @@ -366,22 +367,28 @@ static int man_module_create(struct image *image, struct manifest_module *module
if (err)
return err;


/* data section */
man_module->segment[SOF_MAN_SEGMENT_RODATA].v_base_addr = module->file.data.start;
man_module->segment[SOF_MAN_SEGMENT_RODATA].file_offset = module->foffset +
module->text_fixup_size;

/* file_size is already aligned to MAN_PAGE_SIZE */
pages = module->file.data.file_size / MAN_PAGE_SIZE;

man_module->segment[SOF_MAN_SEGMENT_RODATA].flags.r.length = pages;

/* Copy data sections content */
err = man_copy_elf_sections(image, module, &man_module->segment[SOF_MAN_SEGMENT_RODATA],
module->file.data.first_section);
if (err)
return err;
if (pages) {
man_module->segment[SOF_MAN_SEGMENT_RODATA].v_base_addr = module->file.data.start;
man_module->segment[SOF_MAN_SEGMENT_RODATA].file_offset = module->foffset +
module->text_fixup_size;
/* Copy data sections content */
err = man_copy_elf_sections(image, module,
&man_module->segment[SOF_MAN_SEGMENT_RODATA],
module->file.data.first_section);
if (err)
return err;
} else {
man_module->segment[SOF_MAN_SEGMENT_RODATA].v_base_addr = 0;
man_module->segment[SOF_MAN_SEGMENT_RODATA].file_offset = 0;
man_module->segment[SOF_MAN_SEGMENT_RODATA].flags.ul = 0;
man_module->segment[SOF_MAN_SEGMENT_RODATA].flags.r.type = SOF_MAN_SEGMENT_EMPTY;
}

/* bss is last */

Expand Down
17 changes: 7 additions & 10 deletions tools/rimage/src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,12 @@ void module_print_zones(const struct module *module)
{
fprintf(stdout, "\n\tTotals\tStart\t\tEnd\t\tSize");

fprintf(stdout, "\n\tTEXT\t0x%8.8x\t0x%8.8x\t0x%x\n",
module->text.start, module->text.end,
module->text.end - module->text.start);
fprintf(stdout, "\tDATA\t0x%8.8x\t0x%8.8x\t0x%x\n",
module->data.start, module->data.end,
module->data.end - module->data.start);
fprintf(stdout, "\tBSS\t0x%8.8x\t0x%8.8x\t0x%x\n\n",
module->bss.start, module->bss.end,
module->bss.end - module->bss.start);
fprintf(stdout, "\n\tTEXT\t0x%8.8x\t0x%8.8x\t0x%zx\n",
module->text.start, module->text.end, module->text.file_size);
fprintf(stdout, "\tDATA\t0x%8.8x\t0x%8.8x\t0x%zx\n",
module->data.start, module->data.end, module->data.file_size);
fprintf(stdout, "\tBSS\t0x%8.8x\t0x%8.8x\t0x%zx\n\n",
module->bss.start, module->bss.end, module->bss.file_size);
}

/**
Expand Down Expand Up @@ -252,7 +249,7 @@ static void sections_info_add(struct module_sections_info *info, struct module_s
*/
static void sections_info_finalize(struct module_sections_info *info)
{
info->file_size = info->end - info->start;
info->file_size = (info->end > info->start) ? info->end - info->start : 0;

/* file sizes round up to nearest page */
info->file_size = (info->file_size + MAN_PAGE_SIZE - 1) & ~(MAN_PAGE_SIZE - 1);
Expand Down