Skip to content

Commit

Permalink
Take firmware version and build ID as command line arguments
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dcpleung committed Nov 12, 2019
1 parent 606b4f0 commit 41cba2f
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 25 deletions.
7 changes: 7 additions & 0 deletions src/include/rimage/rimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/man_apl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/man_cnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/man_kbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/man_sue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/man_tgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
Expand Down
18 changes: 18 additions & 0 deletions src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 33 additions & 1 deletion src/rimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down

0 comments on commit 41cba2f

Please sign in to comment.