From ad9e82720c552de8c5c11bb2cc6131fa04dd9cc2 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 3 Jan 2025 18:07:05 +0200 Subject: [PATCH] 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 --- tools/rimage/src/manifest.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/rimage/src/manifest.c b/tools/rimage/src/manifest.c index 02fd2b81de96..639d328c5fd4 100644 --- a/tools/rimage/src/manifest.c +++ b/tools/rimage/src/manifest.c @@ -756,12 +756,16 @@ 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); + 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", @@ -779,6 +783,13 @@ 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; + + 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;