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: Set of small improvements #8532

Merged
merged 3 commits into from
Dec 11, 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
1 change: 1 addition & 0 deletions tools/rimage/src/include/rimage/misc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdint.h>

#define DIV_ROUND_UP(val, div) (((val) + (div) - 1) / (div))
#define ALIGN_UP(val, align) (((val) + (align) - 1) & ~((align) - 1))
softwarecki marked this conversation as resolved.
Show resolved Hide resolved

/**
* Reverses the order of bytes in the array
Expand Down
22 changes: 6 additions & 16 deletions tools/rimage/src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,7 @@ static int man_module_create(struct image *image, struct manifest_module *module
}

/* round module end upto nearest page */
if (image->image_end % MAN_PAGE_SIZE) {
image->image_end = (image->image_end / MAN_PAGE_SIZE) + 1;
image->image_end *= MAN_PAGE_SIZE;
}
image->image_end = ALIGN_UP(image->image_end, MAN_PAGE_SIZE);

out:
fprintf(stdout, " Total pages text %d data %d bss %d module file limit: 0x%x\n\n",
Expand Down Expand Up @@ -505,10 +502,7 @@ static int man_module_create_reloc(struct image *image, struct manifest_module *
image->image_end = module->foffset + module->file.elf.file_size;

/* round module end up to nearest page */
if (image->image_end % MAN_PAGE_SIZE) {
image->image_end = (image->image_end / MAN_PAGE_SIZE) + 1;
image->image_end *= MAN_PAGE_SIZE;
}
image->image_end = ALIGN_UP(image->image_end, MAN_PAGE_SIZE);

fprintf(stdout, " Total pages text %d data %d bss %d module file limit: 0x%x\n\n",
man_module->segment[SOF_MAN_SEGMENT_TEXT].flags.r.length,
Expand Down Expand Up @@ -794,8 +788,7 @@ int man_write_fw_v1_5_sue(struct image *image)

/* write preload page count */
preload_size = image->image_end - MAN_DESC_OFFSET_V1_5_SUE;
preload_size += MAN_PAGE_SIZE - (preload_size % MAN_PAGE_SIZE);
m->desc.header.preload_page_count = preload_size / MAN_PAGE_SIZE;
m->desc.header.preload_page_count = DIV_ROUND_UP(preload_size, MAN_PAGE_SIZE);

fprintf(stdout, "Firmware file size 0x%x page count %d\n",
FILE_TEXT_OFFSET_V1_5_SUE - MAN_DESC_OFFSET_V1_5_SUE +
Expand Down Expand Up @@ -992,8 +985,7 @@ int man_write_fw_meu_v1_5(struct image *image)

/* write preload page count */
preload_size = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_5;
preload_size += MAN_PAGE_SIZE - (preload_size % MAN_PAGE_SIZE);
desc->header.preload_page_count = preload_size / MAN_PAGE_SIZE;
desc->header.preload_page_count = DIV_ROUND_UP(preload_size, MAN_PAGE_SIZE);

/* calculate hash for each module */
man_hash_modules(image, desc);
Expand Down Expand Up @@ -1078,8 +1070,7 @@ int man_write_fw_meu_v1_8(struct image *image)

/* write preload page count */
preload_size = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_8;
preload_size += MAN_PAGE_SIZE - (preload_size % MAN_PAGE_SIZE);
desc->header.preload_page_count = preload_size / MAN_PAGE_SIZE;
desc->header.preload_page_count = DIV_ROUND_UP(preload_size, MAN_PAGE_SIZE);

/* calculate hash for each module */
man_hash_modules(image, desc);
Expand Down Expand Up @@ -1167,8 +1158,7 @@ int man_write_fw_meu_v2_5(struct image *image)

/* write preload page count */
preload_size = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_8;
preload_size += MAN_PAGE_SIZE - (preload_size % MAN_PAGE_SIZE);
desc->header.preload_page_count = preload_size / MAN_PAGE_SIZE;
desc->header.preload_page_count = DIV_ROUND_UP(preload_size, MAN_PAGE_SIZE);

/* calculate hash for each module */
man_hash_modules(image, desc);
Expand Down
6 changes: 3 additions & 3 deletions tools/rimage/src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <rimage/elf_file.h>
#include <rimage/file_utils.h>
#include <rimage/rimage.h>

#include <rimage/misc_utils.h>

int module_read_section(const struct module *module, const struct module_section *section,
void *buffer, const size_t size)
Expand Down Expand Up @@ -249,10 +249,10 @@ 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->end - info->start : 0;
size_t size = (info->end > info->start) ? info->end - info->start : 0;
softwarecki marked this conversation as resolved.
Show resolved Hide resolved

/* file sizes round up to nearest page */
info->file_size = (info->file_size + MAN_PAGE_SIZE - 1) & ~(MAN_PAGE_SIZE - 1);
info->file_size = ALIGN_UP(size, MAN_PAGE_SIZE);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions tools/rimage/src/plat_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <rimage/rimage.h>
#include <rimage/manifest.h>
#include <rimage/plat_auth.h>
#include <rimage/misc_utils.h>

void ri_adsp_meta_data_create_v1_8(struct image *image, int meta_start_offset,
int meta_end_offset)
Expand Down Expand Up @@ -52,7 +53,7 @@ void ri_plat_ext_data_create(struct image *image)
fprintf(stdout, " auth: completing authentication manifest\n");

part->length = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_8;
part->length += MAN_PAGE_SIZE - (part->length % MAN_PAGE_SIZE);
part->length = ALIGN_UP(part->length, MAN_PAGE_SIZE);

/* do this here atm */
desc->header.preload_page_count = part->length / MAN_PAGE_SIZE;
Expand All @@ -69,10 +70,9 @@ void ri_plat_ext_data_create_v2_5(struct image *image)
fprintf(stdout, " auth: completing authentication manifest\n");

size = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_8;
size += MAN_PAGE_SIZE - (size % MAN_PAGE_SIZE);

/* do this here atm */
desc->header.preload_page_count = size / MAN_PAGE_SIZE;
desc->header.preload_page_count = DIV_ROUND_UP(size, MAN_PAGE_SIZE);
ext->size = image->image_end;
}

Expand All @@ -87,8 +87,7 @@ void ri_plat_ext_data_create_ace_v1_5(struct image *image)
fprintf(stdout, " auth: completing authentication manifest\n");

size = meta->comp_desc[0].limit_offset - MAN_DESC_OFFSET_V1_8;
size += MAN_PAGE_SIZE - (size % MAN_PAGE_SIZE);

desc->header.preload_page_count = size / MAN_PAGE_SIZE;
desc->header.preload_page_count = DIV_ROUND_UP(size, MAN_PAGE_SIZE);
ext->size = image->image_end;
}
6 changes: 6 additions & 0 deletions tools/rimage/src/rimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ int main(int argc, char *argv[])
goto out;
}

if (image.num_modules > MAX_MODULES) {
softwarecki marked this conversation as resolved.
Show resolved Hide resolved
fprintf(stderr, "error: Too many input modules\n");
ret = -EMFILE;
goto out;
}

/* Some platforms dont have modules configuration in toml file */
if (image.adsp->modules && image.num_modules > image.adsp->modules->mod_man_count) {
fprintf(stderr, "error: Each ELF input module requires entry in toml file.\n");
Expand Down
Loading