Skip to content

Commit 9814d45

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 8e75969 commit 9814d45

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tools/rimage/src/manifest.c

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

765765
static int man_hash_modules(struct image *image, struct sof_man_fw_desc *desc)
766766
{
767-
struct sof_man_module *man_module;
767+
struct sof_man_module *man_module, *man;
768+
struct manifest_module *mod_file;
768769
size_t mod_offset, mod_size;
769-
int i, ret = 0;
770+
int i, j, idx, ret = 0;
770771

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

774783
if (image->adsp->exec_boot_ldr && i == 0) {
775784
fprintf(stdout, " module: no need to hash %s\n as its exec header\n",
@@ -787,6 +796,14 @@ static int man_hash_modules(struct image *image, struct sof_man_fw_desc *desc)
787796
ret = hash_sha256(image->fw_image + mod_offset, mod_size, man_module->hash, sizeof(man_module->hash));
788797
if (ret)
789798
break;
799+
800+
/* If the input file contained more than 1 module, copy to the rest */
801+
for (j = 1, idx = mod_file->file.first_module_idx + 1; j < mod_file->file.n_modules;
802+
j++, idx++) {
803+
man = (struct sof_man_module *)
804+
((uint8_t *)desc + SOF_MAN_MODULE_OFFSET(idx));
805+
memcpy(man->hash, man_module->hash, sizeof(man->hash));
806+
}
790807
}
791808

792809
return ret;

0 commit comments

Comments
 (0)