From f3eef3cfb6ffd7d519d513e9cb28b52f063aaf89 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 3 Jan 2023 10:55:39 +0100 Subject: [PATCH] Fix IMR type parsing The IMR type can be specified either in the TOML configuration file or on the command line. The command line value should override the one from the configuration file. But the current code overwrites the configuration file value with the default value even if no value has been specified on the command line, which is wrong. Fix this by using the default value when reading the configuration file and only overwriting it when the respective command line parameter is used. Signed-off-by: Guennadi Liakhovetski --- src/adsp_config.c | 6 ++++-- src/rimage.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/adsp_config.c b/src/adsp_config.c index 25091940a..8d213e93f 100644 --- a/src/adsp_config.c +++ b/src/adsp_config.c @@ -1579,7 +1579,8 @@ static int parse_adsp_file_ext_v1_8(const toml_table_t *toml, struct parse_ctx * out->ext_len = sizeof(struct sof_man_adsp_meta_file_ext_v1_8); /* configurable fields */ - out->imr_type = parse_uint32_hex_key(adsp_file_ext, &ctx, "imr_type", 0, &ret); + out->imr_type = parse_uint32_hex_key(adsp_file_ext, &ctx, "imr_type", + MAN_DEFAULT_IMR_TYPE, &ret); if (ret < 0) return ret; @@ -1699,7 +1700,8 @@ static int parse_adsp_file_ext_v2_5(const toml_table_t *toml, struct parse_ctx * out->ext_len = sizeof(struct sof_man_adsp_meta_file_ext_v2_5); /* configurable fields */ - out->imr_type = parse_uint32_hex_key(adsp_file_ext, &ctx, "imr_type", 0, &ret); + out->imr_type = parse_uint32_hex_key(adsp_file_ext, &ctx, "imr_type", + MAN_DEFAULT_IMR_TYPE, &ret); if (ret < 0) return ret; diff --git a/src/rimage.c b/src/rimage.c index 96194977c..7c985e157 100644 --- a/src/rimage.c +++ b/src/rimage.c @@ -43,6 +43,7 @@ int main(int argc, char *argv[]) int imr_type = MAN_DEFAULT_IMR_TYPE; int use_ext_man = 0; unsigned int pv_bit = 0; + bool imr_type_override = false; memset(&image, 0, sizeof(image)); @@ -68,6 +69,7 @@ int main(int argc, char *argv[]) break; case 'i': imr_type = atoi(optarg); + imr_type_override = true; break; case 'f': image.fw_ver_string = optarg; @@ -170,17 +172,20 @@ int main(int argc, char *argv[]) /* set IMR Type and the PV bit in found machine definition */ if (image.adsp->man_v1_8) { - image.adsp->man_v1_8->adsp_file_ext.imr_type = imr_type; + if (imr_type_override) + image.adsp->man_v1_8->adsp_file_ext.imr_type = imr_type; image.adsp->man_v1_8->css.reserved0 = pv_bit; } if (image.adsp->man_v2_5) { - image.adsp->man_v2_5->adsp_file_ext.imr_type = imr_type; + if (imr_type_override) + image.adsp->man_v2_5->adsp_file_ext.imr_type = imr_type; image.adsp->man_v2_5->css.reserved0 = pv_bit; } if (image.adsp->man_ace_v1_5) { - image.adsp->man_ace_v1_5->adsp_file_ext.imr_type = imr_type; + if (imr_type_override) + image.adsp->man_ace_v1_5->adsp_file_ext.imr_type = imr_type; image.adsp->man_ace_v1_5->css.reserved0 = pv_bit; }