Skip to content

Commit 28afedb

Browse files
krish2718rlubos
authored andcommitted
drivers: wifi: Add support to flash the patch automatically
If the storing of nRF70 FW patch in external flash (non-XIP) is enabled, user needs to two steps, flash the patch to external flash and regular Zephyr image flash. Add support to automate this process either using DTS or PM: 0. Convert the patch binary to hex using "intelhex" python package. 1. Generate a merged hex file directly if using DTS or patch hex file when using PM and configure PM to merge this. 2. Set the merged image as default hex file for the flash if using DTS, if using PM this is done automatically. This way, without any user involvement we can automate the process. Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
1 parent 643d51f commit 28afedb

File tree

2 files changed

+93
-12
lines changed

2 files changed

+93
-12
lines changed

drivers/wifi/nrf700x/CMakeLists.txt

+88-11
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ zephyr_library_sources_ifdef(CONFIG_NRF700X_UTIL
116116
src/wifi_util.c
117117
)
118118

119-
if (CONFIG_NRF_WIFI_PATCHES_EXT_FLASH_XIP)
119+
if(CONFIG_NRF_WIFI_PATCHES_EXT_FLASH_XIP)
120120
# Run patches from the external flash (XIP). No need to copy.
121121
zephyr_code_relocate(FILES src/fw_load.c LOCATION EXTFLASH_RODATA NOCOPY)
122122
endif()
@@ -129,14 +129,91 @@ zephyr_compile_definitions_ifdef(CONFIG_NRF700X_ON_QSPI
129129
)
130130

131131
# RPU FW patch binaries based on the selected configuration
132-
zephyr_compile_definitions_ifdef(CONFIG_NRF700X_SYSTEM_MODE
133-
-DCONFIG_NRF_WIFI_FW_BIN=${OS_AGNOSTIC_BASE}/fw_bins/default/nrf70.bin
134-
)
135-
136-
zephyr_compile_definitions_ifdef(CONFIG_NRF700X_RADIO_TEST
137-
-DCONFIG_NRF_WIFI_FW_BIN=${OS_AGNOSTIC_BASE}/fw_bins/radio_test/nrf70.bin
138-
)
132+
if(CONFIG_NRF700X_SYSTEM_MODE)
133+
set(NRF70_PATCH ${OS_AGNOSTIC_BASE}/fw_bins/default/nrf70.bin)
134+
elseif(CONFIG_NRF700X_RADIO_TEST)
135+
set(NRF70_PATCH ${OS_AGNOSTIC_BASE}/fw_bins/radio_test/nrf70.bin)
136+
elseif(CONFIG_NRF700X_SCAN_ONLY)
137+
set(NRF70_PATCH ${OS_AGNOSTIC_BASE}/fw_bins/scan_only/nrf70.bin)
138+
else()
139+
# Error
140+
message(FATAL_ERROR "Unsupported nRF70 patch configuration")
141+
endif()
139142

140-
zephyr_compile_definitions_ifdef(CONFIG_NRF700X_SCAN_ONLY
141-
-DCONFIG_NRF_WIFI_FW_BIN=${OS_AGNOSTIC_BASE}/fw_bins/scan_only/nrf70.bin
142-
)
143+
zephyr_compile_definitions(
144+
-DCONFIG_NRF_WIFI_FW_BIN=${NRF70_PATCH}
145+
)
146+
147+
if(CONFIG_NRF_WIFI_PATCHES_EXT_FLASH_STORE)
148+
message(STATUS "nRF WiFi FW patch binary will be stored in external flash")
149+
150+
dt_chosen(ext_flash_dev PROPERTY nordic,pm-ext-flash)
151+
if(DEFINED ext_flash_dev)
152+
get_filename_component(qspi_node ${ext_flash_dev} DIRECTORY)
153+
else()
154+
dt_nodelabel(qspi_node NODELABEL "qspi")
155+
endif()
156+
if(DEFINED qspi_node)
157+
dt_reg_addr(xip_addr PATH ${qspi_node} NAME qspi_mm)
158+
if(NOT DEFINED xip_addr)
159+
message(FATAL_ERROR "Unable to find XIP area in dts")
160+
endif()
161+
else()
162+
message(FATAL_ERROR "QSPI node not found in dts")
163+
endif()
164+
165+
if(CONFIG_PARTITION_MANAGER_ENABLED)
166+
add_custom_target(nrf70_wifi_fw_patch_target
167+
DEPENDS ${CMAKE_BINARY_DIR}/zephyr/nrf70.hex
168+
)
169+
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/zephyr/nrf70.hex
170+
COMMAND ${Python3_EXECUTABLE}
171+
-c 'import sys\; import intelhex\; intelhex.bin2hex(sys.argv[1], sys.argv[2], int(sys.argv[3])) '
172+
${NRF70_PATCH}
173+
${CMAKE_BINARY_DIR}/zephyr/nrf70.hex
174+
$<TARGET_PROPERTY:partition_manager,nrf70_wifi_fw_XIP_ABS_ADDR>
175+
)
176+
set_property(
177+
GLOBAL PROPERTY
178+
nrf70_wifi_fw_PM_HEX_FILE
179+
${CMAKE_BINARY_DIR}/zephyr/nrf70.hex
180+
)
181+
set_property(
182+
GLOBAL PROPERTY
183+
nrf70_wifi_fw_PM_TARGET
184+
nrf70_wifi_fw_patch_target
185+
)
186+
else()
187+
dt_nodelabel(nrf70_fw_node NODELABEL "nrf70_fw_partition")
188+
if(NOT DEFINED nrf70_fw_node)
189+
message(FATAL_ERROR "nrf70_fw_partition node not found in dts")
190+
endif()
191+
dt_prop(nrf70_fw_offset PATH ${nrf70_fw_node} PROPERTY reg INDEX 0)
192+
if(NOT DEFINED nrf70_fw_offset)
193+
message(FATAL_ERROR "nrf70_fw_partition.reg not found in dts")
194+
endif()
195+
math(EXPR NRF70_PATCH_ADDR "${xip_addr} + ${nrf70_fw_offset}")
196+
197+
# Using python module instead of intelhex command line tool to handle windows
198+
execute_process(
199+
COMMAND ${Python3_EXECUTABLE}
200+
-c "import sys; import intelhex; intelhex.bin2hex(sys.argv[1], sys.argv[2], int(sys.argv[3]))"
201+
${NRF70_PATCH}
202+
${CMAKE_BINARY_DIR}/zephyr/nrf70.hex
203+
${NRF70_PATCH_ADDR}
204+
RESULT_VARIABLE _bin2hex_result
205+
OUTPUT_VARIABLE _bin2hex_output
206+
ERROR_VARIABLE _bin2hex_error
207+
COMMAND_ECHO STDOUT
208+
)
209+
210+
if(NOT _bin2hex_result EQUAL 0)
211+
message(FATAL_ERROR "Failed to convert binary patch to hex format: \n${_bin2hex_output}\n${_bin2hex_error}")
212+
endif()
213+
214+
set_property(GLOBAL APPEND PROPERTY HEX_FILES_TO_MERGE
215+
${CMAKE_BINARY_DIR}/zephyr/nrf70.hex ${CMAKE_BINARY_DIR}/zephyr/zephyr.hex)
216+
set_property(TARGET runners_yaml_props_target PROPERTY
217+
hex_file ${CMAKE_BINARY_DIR}/zephyr/merged.hex)
218+
endif()
219+
endif()

drivers/wifi/nrf700x/src/fw_load.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ INCBIN(_bin, nrf70_fw, STR(CONFIG_NRF_WIFI_FW_BIN));
7474

7575
#include <patch_info.h>
7676

77-
/* Flash partition for NVS */
77+
#if USE_PARTITION_MANAGER
78+
#include <pm_config.h>
79+
#define NRF70_FW_PATCH_ID PM_NRF70_WIFI_FW_ID
80+
#else
7881
#define NRF70_FW_PATCH_ID FIXED_PARTITION_ID(nrf70_fw_partition)
82+
#endif
7983
static const struct flash_area *fa;
8084

8185
static int nrf_wifi_read_and_download_chunk(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx,

0 commit comments

Comments
 (0)