Skip to content

Commit 4982de4

Browse files
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 8ae3880 commit 4982de4

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
@@ -261,7 +261,6 @@ static void siwx91x_configure_network_stack(sl_si91x_boot_configuration_t *boot_
261261

262262
static int siwx91x_check_nwp_version(void)
263263
{
264-
sl_wifi_firmware_version_t expected_version;
265264
sl_wifi_firmware_version_t version;
266265
int ret;
267266

@@ -270,38 +269,29 @@ static int siwx91x_check_nwp_version(void)
270269
return -EINVAL;
271270
}
272271

273-
sscanf(SIWX91X_NWP_FW_EXPECTED_VERSION, "%hhX.%hhd.%hhd.%hhd.%hhd.%hhd.%hd",
274-
&expected_version.rom_id,
275-
&expected_version.major,
276-
&expected_version.minor,
277-
&expected_version.security_version,
278-
&expected_version.patch_num,
279-
&expected_version.customer_id,
280-
&expected_version.build_num);
281-
282272
/* Ignore rom_id:
283-
* B is parsed as an hex value and we get 11 in expected_version.rom_id
284-
* We received rom_id=17 in version.rom_id, we suspect a double hex->decimal conversion
273+
* the right value is 0x0B but we received 17 in version.rom_id, we suspect a double
274+
* hex->decimal conversion
285275
*/
286-
if (expected_version.major != version.major) {
276+
if (siwx91x_nwp_fw_expected_version.major != version.major) {
287277
return -EINVAL;
288278
}
289-
if (expected_version.minor != version.minor) {
279+
if (siwx91x_nwp_fw_expected_version.minor != version.minor) {
290280
return -EINVAL;
291281
}
292-
if (expected_version.security_version != version.security_version) {
282+
if (siwx91x_nwp_fw_expected_version.security_version != version.security_version) {
293283
return -EINVAL;
294284
}
295-
if (expected_version.patch_num != version.patch_num) {
285+
if (siwx91x_nwp_fw_expected_version.patch_num != version.patch_num) {
296286
return -EINVAL;
297287
}
298-
if (expected_version.customer_id != version.customer_id) {
299-
LOG_DBG("customer_id diverge: expected %d, actual %d", expected_version.customer_id,
300-
version.customer_id);
288+
if (siwx91x_nwp_fw_expected_version.customer_id != version.customer_id) {
289+
LOG_DBG("customer_id diverge: expected %d, actual %d",
290+
siwx91x_nwp_fw_expected_version.customer_id, version.customer_id);
301291
}
302-
if (expected_version.build_num != version.build_num) {
303-
LOG_DBG("build_num diverge: expected %d, actual %d", expected_version.build_num,
304-
version.build_num);
292+
if (siwx91x_nwp_fw_expected_version.build_num != version.build_num) {
293+
LOG_DBG("build_num diverge: expected %d, actual %d",
294+
siwx91x_nwp_fw_expected_version.build_num, version.build_num);
305295
}
306296

307297
return 0;
@@ -414,8 +404,15 @@ static int siwx91x_nwp_init(const struct device *dev)
414404
/* Check if the NWP firmware version is correct */
415405
ret = siwx91x_check_nwp_version();
416406
if (ret < 0) {
417-
LOG_ERR("Unexpected NWP firmware version (expected: %s)",
418-
SIWX91X_NWP_FW_EXPECTED_VERSION);
407+
LOG_ERR("Unexpected NWP firmware version (expected: %X.%d.%d.%d.%d.%d.%d)",
408+
siwx91x_nwp_fw_expected_version.rom_id,
409+
siwx91x_nwp_fw_expected_version.major,
410+
siwx91x_nwp_fw_expected_version.minor,
411+
siwx91x_nwp_fw_expected_version.security_version,
412+
siwx91x_nwp_fw_expected_version.patch_num,
413+
siwx91x_nwp_fw_expected_version.customer_id,
414+
siwx91x_nwp_fw_expected_version.build_num);
415+
return -EINVAL;
419416
}
420417

421418
if (IS_ENABLED(CONFIG_SOC_SIWX91X_PM_BACKEND_PMGR)) {

0 commit comments

Comments
 (0)