Skip to content

Commit e3c8230

Browse files
Martinhoff-makercfriedt
authored andcommitted
soc: silabs: siwx91x: Add firmware version check of NWP
This commit introduces a new function to verify the firmware version of the SiWX917 network coprocessor. It checks the expected version (updated manually after each bump of Wiseconnect SDK in hal_silabs) against the actual version retrieved from the device. Signed-off-by: Martin Hoff <[email protected]>
1 parent 972d5e3 commit e3c8230

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

modules/hal_silabs/wiseconnect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ if(CONFIG_WISECONNECT_NETWORK_STACK)
197197
zephyr_library_sources_ifdef(CONFIG_SIWX91X_FIRMWARE_UPGRADE
198198
${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.c
199199
)
200+
zephyr_include_directories(.)
200201
endif() # CONFIG_WISECONNECT_NETWORK_STACK
201202

202203
if(CONFIG_SOC_SILABS_SLEEPTIMER)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
* Actually mapped to Wiseconnect SDK 3.5.0
9+
*/
10+
#define SIWX91X_NWP_FW_EXPECTED_VERSION "B.2.14.5.2.0.7"

soc/silabs/silabs_siwx91x/siwg917/nwp.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <zephyr/devicetree.h>
1717

1818
#include "nwp.h"
19+
#include "nwp_fw_version.h"
1920
#include "sl_wifi_callback_framework.h"
2021

2122
#include "sl_si91x_ble.h"
@@ -249,6 +250,54 @@ static void siwx91x_configure_network_stack(sl_si91x_boot_configuration_t *boot_
249250
}
250251
}
251252

253+
static int siwx91x_check_nwp_version(void)
254+
{
255+
sl_wifi_firmware_version_t expected_version;
256+
sl_wifi_firmware_version_t version;
257+
int ret;
258+
259+
ret = sl_wifi_get_firmware_version(&version);
260+
if (ret != SL_STATUS_OK) {
261+
return -EINVAL;
262+
}
263+
264+
sscanf(SIWX91X_NWP_FW_EXPECTED_VERSION, "%hhX.%hhd.%hhd.%hhd.%hhd.%hhd.%hd",
265+
&expected_version.rom_id,
266+
&expected_version.major,
267+
&expected_version.minor,
268+
&expected_version.security_version,
269+
&expected_version.patch_num,
270+
&expected_version.customer_id,
271+
&expected_version.build_num);
272+
273+
/* Ignore rom_id:
274+
* B is parsed as an hex value and we get 11 in expected_version.rom_id
275+
* We received rom_id=17 in version.rom_id, we suspect a double hex->decimal conversion
276+
*/
277+
if (expected_version.major != version.major) {
278+
return -EINVAL;
279+
}
280+
if (expected_version.minor != version.minor) {
281+
return -EINVAL;
282+
}
283+
if (expected_version.security_version != version.security_version) {
284+
return -EINVAL;
285+
}
286+
if (expected_version.patch_num != version.patch_num) {
287+
return -EINVAL;
288+
}
289+
if (expected_version.customer_id != version.customer_id) {
290+
LOG_DBG("customer_id diverge: expected %d, actual %d", expected_version.customer_id,
291+
version.customer_id);
292+
}
293+
if (expected_version.build_num != version.build_num) {
294+
LOG_DBG("build_num diverge: expected %d, actual %d", expected_version.build_num,
295+
version.build_num);
296+
}
297+
298+
return 0;
299+
}
300+
252301
int siwx91x_get_nwp_config(sl_wifi_device_configuration_t *get_config, uint8_t wifi_oper_mode,
253302
bool hidden_ssid, uint8_t max_num_sta)
254303
{
@@ -334,7 +383,7 @@ int siwx91x_nwp_mode_switch(uint8_t oper_mode, bool hidden_ssid, uint8_t max_num
334383
static int siwg917_nwp_init(void)
335384
{
336385
sl_wifi_device_configuration_t network_config;
337-
sl_status_t status;
386+
int status;
338387
__maybe_unused sl_wifi_performance_profile_t performance_profile = {
339388
.profile = SI91X_POWER_PROFILE};
340389
__maybe_unused sl_bt_performance_profile_t bt_performance_profile = {
@@ -349,6 +398,13 @@ static int siwg917_nwp_init(void)
349398
return -EINVAL;
350399
}
351400

401+
/* Check if the NWP firmware version is correct */
402+
status = siwx91x_check_nwp_version();
403+
if (status < 0) {
404+
LOG_ERR("Unexpected NWP firmware version (expected: %s)",
405+
SIWX91X_NWP_FW_EXPECTED_VERSION);
406+
}
407+
352408
if (IS_ENABLED(CONFIG_SOC_SIWX91X_PM_BACKEND_PMGR)) {
353409
if (IS_ENABLED(CONFIG_BT_SILABS_SIWX91X)) {
354410
status = sl_si91x_bt_set_performance_profile(&bt_performance_profile);

0 commit comments

Comments
 (0)