Skip to content

Commit 29fb893

Browse files
Martinhoff-makerkartben
authored andcommitted
soc: silabs: siwx91x: removed sscanf for nwp firmware version check
This patch removes the use of sscanf to maintain compatibility with tests that use the minimal cpp library. The expected version is now defined using multiple individual values rather than a single formatted string. Signed-off-by: Martin Hoff <[email protected]>
1 parent 53eaf0f commit 29fb893

File tree

4 files changed

+46
-28
lines changed

4 files changed

+46
-28
lines changed

modules/hal_silabs/wiseconnect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ if(CONFIG_SILABS_SIWX91X_NWP)
178178
${WISECONNECT_DIR}/components/sli_wifi_command_engine/inc
179179
)
180180
zephyr_library_sources(
181+
nwp_fw_version.c
181182
${WISECONNECT_DIR}/components/common/src/sl_utility.c
182183
${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ahb_interface/src/rsi_hal_mcu_m4_ram.c
183184
${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ahb_interface/src/rsi_hal_mcu_m4_rom.c
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2025 Silicon Laboratories Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* This value needs to be updated when the Wiseconnect SDK (hal_silabs/wiseconnect) is updated
8+
* Currently mapped to Wiseconnect SDK 3.5.2
9+
*/
10+
11+
#include <nwp_fw_version.h>
12+
13+
const sl_wifi_firmware_version_t siwx91x_nwp_fw_expected_version = {
14+
.rom_id = 0x0B,
15+
.major = 2,
16+
.minor = 14,
17+
.security_version = 5,
18+
.patch_num = 2,
19+
.customer_id = 0,
20+
.build_num = 7,
21+
};

modules/hal_silabs/wiseconnect/nwp_fw_version.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
/* This value needs to be updated when the Wiseconnect SDK (hal_silabs/wiseconnect) is updated
8-
* Actually mapped to Wiseconnect SDK 3.5.0
9-
*/
10-
#define SIWX91X_NWP_FW_EXPECTED_VERSION "B.2.14.5.2.0.7"
7+
#include <sl_wifi_types.h>
8+
9+
extern const sl_wifi_firmware_version_t siwx91x_nwp_fw_expected_version;

soc/silabs/silabs_siwx91x/siwg917/siwx91x_nwp.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ static void siwx91x_configure_network_stack(sl_si91x_boot_configuration_t *boot_
300300

301301
static int siwx91x_check_nwp_version(void)
302302
{
303-
sl_wifi_firmware_version_t expected_version;
304303
sl_wifi_firmware_version_t version;
305304
int ret;
306305

@@ -309,38 +308,29 @@ static int siwx91x_check_nwp_version(void)
309308
return -EINVAL;
310309
}
311310

312-
sscanf(SIWX91X_NWP_FW_EXPECTED_VERSION, "%hhX.%hhd.%hhd.%hhd.%hhd.%hhd.%hd",
313-
&expected_version.rom_id,
314-
&expected_version.major,
315-
&expected_version.minor,
316-
&expected_version.security_version,
317-
&expected_version.patch_num,
318-
&expected_version.customer_id,
319-
&expected_version.build_num);
320-
321311
/* Ignore rom_id:
322-
* B is parsed as an hex value and we get 11 in expected_version.rom_id
323-
* We received rom_id=17 in version.rom_id, we suspect a double hex->decimal conversion
312+
* the right value is 0x0B but we received 17 in version.rom_id, we suspect a double
313+
* hex->decimal conversion
324314
*/
325-
if (expected_version.major != version.major) {
315+
if (siwx91x_nwp_fw_expected_version.major != version.major) {
326316
return -EINVAL;
327317
}
328-
if (expected_version.minor != version.minor) {
318+
if (siwx91x_nwp_fw_expected_version.minor != version.minor) {
329319
return -EINVAL;
330320
}
331-
if (expected_version.security_version != version.security_version) {
321+
if (siwx91x_nwp_fw_expected_version.security_version != version.security_version) {
332322
return -EINVAL;
333323
}
334-
if (expected_version.patch_num != version.patch_num) {
324+
if (siwx91x_nwp_fw_expected_version.patch_num != version.patch_num) {
335325
return -EINVAL;
336326
}
337-
if (expected_version.customer_id != version.customer_id) {
338-
LOG_DBG("customer_id diverge: expected %d, actual %d", expected_version.customer_id,
339-
version.customer_id);
327+
if (siwx91x_nwp_fw_expected_version.customer_id != version.customer_id) {
328+
LOG_DBG("customer_id diverge: expected %d, actual %d",
329+
siwx91x_nwp_fw_expected_version.customer_id, version.customer_id);
340330
}
341-
if (expected_version.build_num != version.build_num) {
342-
LOG_DBG("build_num diverge: expected %d, actual %d", expected_version.build_num,
343-
version.build_num);
331+
if (siwx91x_nwp_fw_expected_version.build_num != version.build_num) {
332+
LOG_DBG("build_num diverge: expected %d, actual %d",
333+
siwx91x_nwp_fw_expected_version.build_num, version.build_num);
344334
}
345335

346336
return 0;
@@ -448,8 +438,15 @@ static int siwx91x_nwp_init(const struct device *dev)
448438
/* Check if the NWP firmware version is correct */
449439
ret = siwx91x_check_nwp_version();
450440
if (ret < 0) {
451-
LOG_ERR("Unexpected NWP firmware version (expected: %s)",
452-
SIWX91X_NWP_FW_EXPECTED_VERSION);
441+
LOG_ERR("Unexpected NWP firmware version (expected: %X.%d.%d.%d.%d.%d.%d)",
442+
siwx91x_nwp_fw_expected_version.rom_id,
443+
siwx91x_nwp_fw_expected_version.major,
444+
siwx91x_nwp_fw_expected_version.minor,
445+
siwx91x_nwp_fw_expected_version.security_version,
446+
siwx91x_nwp_fw_expected_version.patch_num,
447+
siwx91x_nwp_fw_expected_version.customer_id,
448+
siwx91x_nwp_fw_expected_version.build_num);
449+
return -EINVAL;
453450
}
454451

455452
if (IS_ENABLED(CONFIG_SOC_SIWX91X_PM_BACKEND_PMGR)) {

0 commit comments

Comments
 (0)