From 41cba2f66316d94dc7f5af2c7c2ffe6499004caa Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Thu, 26 Sep 2019 18:32:20 -0700 Subject: [PATCH] Take firmware version and build ID as command line arguments Since rimage is no longer built with the SOF code, the firmware version (SOF_MAJOR and SOF_MINOR) and build ID (SOF_BUILD) are no longer defined during build. So these needs to be passed as command line arguments. Signed-off-by: Daniel Leung --- src/include/rimage/rimage.h | 7 +++++++ src/man_apl.c | 12 ++++++------ src/man_cnl.c | 12 ++++++------ src/man_kbl.c | 6 +++--- src/man_sue.c | 6 +++--- src/man_tgl.c | 12 ++++++------ src/manifest.c | 18 ++++++++++++++++++ src/rimage.c | 34 +++++++++++++++++++++++++++++++++- 8 files changed, 82 insertions(+), 25 deletions(-) diff --git a/src/include/rimage/rimage.h b/src/include/rimage/rimage.h index c10152561..02a840a9a 100644 --- a/src/include/rimage/rimage.h +++ b/src/include/rimage/rimage.h @@ -125,6 +125,13 @@ struct image { char out_rom_file[256]; char out_man_file[256]; char out_unsigned_file[256]; + + /* fw version and build id */ + char* fw_ver_string; + char* fw_ver_build_string; + uint16_t fw_ver_major; + uint16_t fw_ver_minor; + uint16_t fw_ver_build; }; struct mem_zone { diff --git a/src/man_apl.c b/src/man_apl.c index b8365b4c3..b81bb759b 100644 --- a/src/man_apl.c +++ b/src/man_apl.c @@ -49,10 +49,10 @@ struct fw_image_manifest_v1_8 apl_manifest = { .header_id = MAN_CSS_HDR_ID, .padding = 0, .version = { - .major_version = SOF_MAJOR, - .minor_version = SOF_MINOR, + .major_version = 0, + .minor_version = 0, .hotfix_version = 0, - .build_version = SOF_BUILD, + .build_version = 0, }, .modulus_size = MAN_CSS_MOD_SIZE, .exponent_size = MAN_CSS_EXP_SIZE, @@ -116,10 +116,10 @@ struct fw_image_manifest_v1_8 apl_manifest = { .preload_page_count = 0, /* size in pages from $CPD */ .fw_image_flags = SOF_MAN_FW_HDR_FLAGS, .feature_mask = SOF_MAN_FW_HDR_FEATURES, - .major_version = SOF_MAJOR, - .minor_version = SOF_MINOR, + .major_version = 0, + .minor_version = 0, .hotfix_version = 0, - .build_version = SOF_BUILD, + .build_version = 0, .load_offset = MAN_DESC_OFFSET_V1_8, }, }, diff --git a/src/man_cnl.c b/src/man_cnl.c index 264beaf77..72ec89871 100644 --- a/src/man_cnl.c +++ b/src/man_cnl.c @@ -48,10 +48,10 @@ struct fw_image_manifest_v1_8 cnl_manifest = { .header_id = MAN_CSS_HDR_ID, .padding = 0, .version = { - .major_version = SOF_MAJOR, - .minor_version = SOF_MINOR, + .major_version = 0, + .minor_version = 0, .hotfix_version = 0, - .build_version = SOF_BUILD, + .build_version = 0, }, .modulus_size = MAN_CSS_MOD_SIZE, .exponent_size = MAN_CSS_EXP_SIZE, @@ -115,10 +115,10 @@ struct fw_image_manifest_v1_8 cnl_manifest = { .preload_page_count = 0, /* size in pages from $CPD */ .fw_image_flags = SOF_MAN_FW_HDR_FLAGS, .feature_mask = SOF_MAN_FW_HDR_FEATURES, - .major_version = SOF_MAJOR, - .minor_version = SOF_MINOR, + .major_version = 0, + .minor_version = 0, .hotfix_version = 0, - .build_version = SOF_BUILD, + .build_version = 0, .load_offset = 0x30000, }, }, diff --git a/src/man_kbl.c b/src/man_kbl.c index 5bd66964f..4a078e5d9 100644 --- a/src/man_kbl.c +++ b/src/man_kbl.c @@ -37,10 +37,10 @@ struct fw_image_manifest_v1_5 kbl_manifest = { .preload_page_count = 0, .fw_image_flags = SOF_MAN_FW_HDR_FLAGS, .feature_mask = SOF_MAN_FW_HDR_FEATURES, - .major_version = SOF_MAJOR, - .minor_version = SOF_MINOR, + .major_version = 0, + .minor_version = 0, .hotfix_version = 0, - .build_version = SOF_BUILD, + .build_version = 0, .load_offset = 0, .hw_buf_base_addr = KBL_HARDWARE_BUFFER_BASE, .hw_buf_length = KBL_HARDWARE_BUFFER_LEN diff --git a/src/man_sue.c b/src/man_sue.c index db4bfd600..e170d9952 100644 --- a/src/man_sue.c +++ b/src/man_sue.c @@ -17,10 +17,10 @@ struct fw_image_manifest_v1_5_sue sue_manifest = { .preload_page_count = 0, /* size in pages from $CPD */ .fw_image_flags = SOF_MAN_FW_HDR_FLAGS, .feature_mask = SOF_MAN_FW_HDR_FEATURES, - .major_version = SOF_MAJOR, - .minor_version = SOF_MINOR, + .major_version = 0, + .minor_version = 0, .hotfix_version = 0, - .build_version = SOF_BUILD, + .build_version = 0, .load_offset = 0x2000, }, }, diff --git a/src/man_tgl.c b/src/man_tgl.c index 6f8871ce2..f7c3c6f25 100644 --- a/src/man_tgl.c +++ b/src/man_tgl.c @@ -48,10 +48,10 @@ struct fw_image_manifest_v2_5 tgl_manifest = { .header_id = MAN_CSS_HDR_ID, .padding = 0, .version = { - .major_version = SOF_MAJOR, - .minor_version = SOF_MINOR, + .major_version = 0, + .minor_version = 0, .hotfix_version = 0, - .build_version = SOF_BUILD, + .build_version = 0, }, .modulus_size = MAN_CSS_MOD_SIZE, .exponent_size = MAN_CSS_EXP_SIZE, @@ -115,10 +115,10 @@ struct fw_image_manifest_v2_5 tgl_manifest = { .preload_page_count = 0, /* size in pages from $CPD */ .fw_image_flags = SOF_MAN_FW_HDR_FLAGS, .feature_mask = SOF_MAN_FW_HDR_FEATURES, - .major_version = SOF_MAJOR, - .minor_version = SOF_MINOR, + .major_version = 0, + .minor_version = 0, .hotfix_version = 0, - .build_version = SOF_BUILD, + .build_version = 0, .load_offset = 0x30000, }, }, diff --git a/src/manifest.c b/src/manifest.c index 6ca412836..4c14d742c 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -727,6 +727,11 @@ static int man_write_fw_v1_5(struct image *image) m = image->fw_image; desc = image->fw_image + MAN_DESC_OFFSET_V1_5; + /* firmware and build version */ + m->desc.header.major_version = image->fw_ver_major; + m->desc.header.minor_version = image->fw_ver_minor; + m->desc.header.build_version = image->fw_ver_build; + /* create each module */ m->desc.header.num_module_entries = image->num_modules; man_create_modules(image, desc, FILE_TEXT_OFFSET_V1_5); @@ -791,6 +796,11 @@ static int man_write_fw_v1_5_sue(struct image *image) /* create the module */ m = image->fw_image + MAN_DESC_OFFSET_V1_5_SUE; + /* firmware and build version */ + m->desc.header.major_version = image->fw_ver_major; + m->desc.header.minor_version = image->fw_ver_minor; + m->desc.header.build_version = image->fw_ver_build; + /* create each module - subtract the boot loader exec header */ m->desc.header.num_module_entries = image->num_modules - 1; man_create_modules(image, &m->desc, FILE_TEXT_OFFSET_V1_5_SUE); @@ -854,6 +864,14 @@ static int man_write_fw_v1_8(struct image *image) m = image->fw_image; desc = image->fw_image + MAN_DESC_OFFSET_V1_8; + /* firmware and build version */ + m->css.version.major_version = image->fw_ver_major; + m->css.version.minor_version = image->fw_ver_minor; + m->css.version.build_version = image->fw_ver_build; + m->desc.header.major_version = image->fw_ver_major; + m->desc.header.minor_version = image->fw_ver_minor; + m->desc.header.build_version = image->fw_ver_build; + /* create each module */ m->desc.header.num_module_entries = image->num_modules; man_create_modules(image, desc, FILE_TEXT_OFFSET_V1_8); diff --git a/src/rimage.c b/src/rimage.c index 896fe1b7d..98f0f5cdc 100644 --- a/src/rimage.c +++ b/src/rimage.c @@ -40,6 +40,8 @@ static void usage(char *name) #endif /* HAS_FILE_FORMAT_H */ fprintf(stdout, "\t -i set IMR type\n"); fprintf(stdout, "\t -x set xcc module offset\n"); + fprintf(stdout, "\t -f firmware version = x.y\n"); + fprintf(stdout, "\t -b build version\n"); exit(0); } @@ -54,7 +56,7 @@ int main(int argc, char *argv[]) image.xcc_mod_offset = DEFAULT_XCC_MOD_OFFSET; - while ((opt = getopt(argc, argv, "ho:p:m:vba:s:k:l:ri:x:")) != -1) { + while ((opt = getopt(argc, argv, "ho:p:m:va:s:k:l:ri:x:f:b:")) != -1) { switch (opt) { case 'o': image.out_file = optarg; @@ -92,6 +94,12 @@ int main(int argc, char *argv[]) case 'x': image.xcc_mod_offset = atoi(optarg); break; + case 'f': + image.fw_ver_string = optarg; + break; + case 'b': + image.fw_ver_build_string = optarg; + break; case 'h': usage(argv[0]); break; @@ -117,6 +125,30 @@ int main(int argc, char *argv[]) return -EINVAL; } + /* firmware version and build id */ + if (image.fw_ver_string) { + ret = sscanf(image.fw_ver_string, "%hu.%hu", + &image.fw_ver_major, + &image.fw_ver_minor); + + if (ret != 2) { + fprintf(stderr, + "error: cannot parse firmware version\n"); + return -EINVAL; + } + } + + if (image.fw_ver_build_string) { + ret = sscanf(image.fw_ver_build_string, "%hu", + &image.fw_ver_build); + + if (ret != 1) { + fprintf(stderr, + "error: cannot parse build version\n"); + return -EINVAL; + } + } + /* find machine */ for (i = 0; i < ARRAY_SIZE(machine); i++) { if (!strcmp(mach, machine[i]->name)) {