Skip to content

Commit

Permalink
rimage: library: calculate hashes correctly
Browse files Browse the repository at this point in the history
Module hash sums are per-file, when building libraries we have to
walk files, not modules, and copy hashes to all modules in each file.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh committed Jan 8, 2025
1 parent 8e75969 commit 9814d45
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tools/rimage/src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,21 @@ static int man_create_modules_in_config(struct image *image, struct sof_man_fw_d

static int man_hash_modules(struct image *image, struct sof_man_fw_desc *desc)
{
struct sof_man_module *man_module;
struct sof_man_module *man_module, *man;
struct manifest_module *mod_file;
size_t mod_offset, mod_size;
int i, ret = 0;
int i, j, idx, ret = 0;

for (i = 0; i < image->num_modules; i++) {
man_module = (void *)desc + SOF_MAN_MODULE_OFFSET(i);
/*
* We walk the array of input module files and calculate a hash-sum of each of
* them. Those files might contain multiple modules, so that we then have to
* find all of them and copy the hash-sum into each one.
*/
for (i = 0, mod_file = image->module;
i < image->num_modules;
i++, mod_file++) {
man_module = (struct sof_man_module *)
((uint8_t *)desc + SOF_MAN_MODULE_OFFSET(mod_file->file.first_module_idx));

if (image->adsp->exec_boot_ldr && i == 0) {
fprintf(stdout, " module: no need to hash %s\n as its exec header\n",
Expand All @@ -787,6 +796,14 @@ static int man_hash_modules(struct image *image, struct sof_man_fw_desc *desc)
ret = hash_sha256(image->fw_image + mod_offset, mod_size, man_module->hash, sizeof(man_module->hash));
if (ret)
break;

/* If the input file contained more than 1 module, copy to the rest */
for (j = 1, idx = mod_file->file.first_module_idx + 1; j < mod_file->file.n_modules;
j++, idx++) {
man = (struct sof_man_module *)
((uint8_t *)desc + SOF_MAN_MODULE_OFFSET(idx));
memcpy(man->hash, man_module->hash, sizeof(man->hash));
}
}

return ret;
Expand Down

0 comments on commit 9814d45

Please sign in to comment.