Skip to content

Commit 0d664c1

Browse files
committed
rimage: library: calculate hashes correctly
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 <guennadi.liakhovetski@linux.intel.com>
1 parent f7d904e commit 0d664c1

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

tools/rimage/src/manifest.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,12 +767,21 @@ static int man_create_modules_in_config(struct image *image, struct sof_man_fw_d
767767

768768
static int man_hash_modules(struct image *image, struct sof_man_fw_desc *desc)
769769
{
770-
struct sof_man_module *man_module;
770+
struct sof_man_module *man_module, *man;
771+
struct manifest_module *mod_file;
771772
size_t mod_offset, mod_size;
772-
int i, ret = 0;
773+
int i, j, idx, ret = 0;
773774

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

777786
if (image->adsp->exec_boot_ldr && i == 0) {
778787
fprintf(stdout, " module: no need to hash %s\n as its exec header\n",
@@ -790,6 +799,14 @@ static int man_hash_modules(struct image *image, struct sof_man_fw_desc *desc)
790799
ret = hash_sha256(image->fw_image + mod_offset, mod_size, man_module->hash, sizeof(man_module->hash));
791800
if (ret)
792801
break;
802+
803+
/* If the input file contained more than 1 module, copy to the rest */
804+
for (j = 1, idx = mod_file->file.first_module_idx + 1; j < mod_file->file.n_modules;
805+
j++, idx++) {
806+
man = (struct sof_man_module *)
807+
((uint8_t *)desc + SOF_MAN_MODULE_OFFSET(idx));
808+
memcpy(man->hash, man_module->hash, sizeof(man->hash));
809+
}
793810
}
794811

795812
return ret;

0 commit comments

Comments
 (0)