From: Pan Xiuli xiuli.pan@linux.intel.com
Add unsigned firmware support, that can directly use the FW or sign it with other tools.
Signed-off-by: Pan Xiuli xiuli.pan@linux.intel.com
--- Test with: Mininow max rt5651 SOF master: 019637ab250daa53c15da0a0a98c54f1c58d8ca3 SOF-Tool master: 33e4b0cc6f6a44e3e7ee849c04c515a5537242c7 https://github.com/plbossart/sound/tree/topic/sof-v4.14: 6fa721a8b7c6567eea0a2181bf9a3d2a12c31b00 --- rimage/manifest.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
diff --git a/rimage/manifest.c b/rimage/manifest.c index a4780b7..2b7e07f 100644 --- a/rimage/manifest.c +++ b/rimage/manifest.c @@ -51,6 +51,21 @@ static int man_open_rom_file(struct image *image) return 0; }
+static int man_open_unsigned_file(struct image *image) +{ + sprintf(image->out_unsigned_file, "%s.uns", image->out_file); + unlink(image->out_unsigned_file); + + /* open unsigned FW outfile for writing */ + image->out_unsigned_fd = fopen(image->out_unsigned_file, "w"); + if (image->out_unsigned_fd == NULL) { + fprintf(stderr, "error: unable to open %s for writing %d\n", + image->out_unsigned_file, errno); + } + + return 0; +} + static int man_open_manifest_file(struct image *image) { /* open manifest outfile for writing */ @@ -351,6 +366,39 @@ static int man_module_create(struct image *image, struct module *module, return 0; }
+static int man_write_unsigned_mod(struct image *image) +{ + int count; + + /* write metadata file for unsigned FW */ + count = fwrite(image->fw_image + MAN_META_EXT_OFFSET, + sizeof(struct sof_man_adsp_meta_file_ext), 1, + image->out_man_fd); + + /* did the metadata/manifest write succeed ? */ + if (count != 1) { + fprintf(stderr, "error: failed to write meta %s %d\n", + image->out_man_file, -errno); + return -errno; + } + fclose(image->out_man_fd); + + /* now prepare the unsigned rimage */ + count = fwrite(image->fw_image + MAN_FW_DESC_OFFSET, + image->image_end - MAN_FW_DESC_OFFSET, + 1, image->out_unsigned_fd); + + /* did the unsigned FW write succeed ? */ + if (count != 1) { + fprintf(stderr, "error: failed to write firmware %s %d\n", + image->out_unsigned_file, -errno); + return -errno; + } + fclose(image->out_unsigned_fd); + + return 0; +} + static int man_write_fw_mod(struct image *image) { int count; @@ -400,6 +448,11 @@ static int man_write_fw(struct image *image) if (ret < 0) goto err;
+ /* open unsigned firmware */ + ret = man_open_unsigned_file(image); + if (ret < 0) + goto err; + /* create the manifest */ ret = man_open_manifest_file(image); if (ret < 0) @@ -477,6 +530,11 @@ static int man_write_fw(struct image *image) if (ret < 0) goto err;
+ /* write the unsigned files*/ + ret = man_write_unsigned_mod(image); + if (ret < 0) + goto err; + fprintf(stdout, "Firmware manifest and signing completed !\n"); return 0;