From d9584d3116afdd19413bd3673249eb343e16285c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 7 Oct 2024 13:40:56 +0530 Subject: [PATCH 1/6] [nrf fromtree] drivers: nrfwifi: Fix the indentation The Cmake indentation is two spaces. Signed-off-by: Chaitanya Tata (cherry picked from commit 3cd470013260ffbf6ffbde7e401d8c3986d48c9a) --- drivers/wifi/nrfwifi/CMakeLists.txt | 64 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 91818f65582..4055384aac7 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -136,39 +136,39 @@ zephyr_compile_definitions_ifdef(CONFIG_NRF70_ON_QSPI ) if (CONFIG_NRF_WIFI_BUILD_ONLY_MODE) -message(WARNING " ------------------------------------------------------------------------- -Building only the nRF70 driver, skipping firmware patch. -This is only for building (CI) purposes and will not work on a real device. ------------------------------------------------------------------------- -") + message(WARNING " + ------------------------------------------------------------------------ + Building only the nRF70 driver, skipping firmware patch. + This is only for building (CI) purposes and will not work on a real device. + ------------------------------------------------------------------------ + ") else() -# RPU FW patch binaries based on the selected configuration -if(CONFIG_NRF70_SYSTEM_MODE) - set(NRF70_PATCH ${FW_BINS_BASE}/default/nrf70.bin) -elseif(CONFIG_NRF70_RADIO_TEST) - set(NRF70_PATCH ${FW_BINS_BASE}/radio_test/nrf70.bin) -elseif(CONFIG_NRF70_SCAN_ONLY) - set(NRF70_PATCH ${FW_BINS_BASE}/scan_only/nrf70.bin) -elseif (CONFIG_NRF70_SYSTEM_WITH_RAW_MODES) - set(NRF70_PATCH ${FW_BINS_BASE}/system_with_raw/nrf70.bin) -else() - # Error - message(FATAL_ERROR "Unsupported nRF70 patch configuration") -endif() - -if(NOT EXISTS ${NRF70_PATCH}) - message(FATAL_ERROR " - ------------------------------------------------------------------------ - Missing blobs for nRF70 device driver, please install by running: - $ west update - $ west blobs fetch hal_nordic - ------------------------------------------------------------------------") -endif() - -zephyr_compile_definitions( - -DCONFIG_NRF_WIFI_FW_BIN=${NRF70_PATCH} -) + # RPU FW patch binaries based on the selected configuration + if(CONFIG_NRF70_SYSTEM_MODE) + set(NRF70_PATCH ${FW_BINS_BASE}/default/nrf70.bin) + elseif(CONFIG_NRF70_RADIO_TEST) + set(NRF70_PATCH ${FW_BINS_BASE}/radio_test/nrf70.bin) + elseif(CONFIG_NRF70_SCAN_ONLY) + set(NRF70_PATCH ${FW_BINS_BASE}/scan_only/nrf70.bin) + elseif (CONFIG_NRF70_SYSTEM_WITH_RAW_MODES) + set(NRF70_PATCH ${FW_BINS_BASE}/system_with_raw/nrf70.bin) + else() + # Error + message(FATAL_ERROR "Unsupported nRF70 patch configuration") + endif() + + if(NOT EXISTS ${NRF70_PATCH}) + message(FATAL_ERROR " + ------------------------------------------------------------------------ + Missing blobs for nRF70 device driver, please install by running: + $ west update + $ west blobs fetch hal_nordic + ------------------------------------------------------------------------") + endif() + + zephyr_compile_definitions( + -DCONFIG_NRF_WIFI_FW_BIN=${NRF70_PATCH} + ) endif() From 8aa253ab49f8c8229769913a4354f34ea54c696b Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Oct 2024 15:49:34 +0200 Subject: [PATCH 2/6] [nrf fromtree] drivers: wifi: Add support to override FW load For using external flash the tooling is only available in NCS, so, use the existing Kconfig option to override the FW loading. Signed-off-by: Chaitanya Tata (cherry picked from commit f20e2d68b054e672831d099ca5ade2e7dc00e33d) --- drivers/wifi/nrfwifi/CMakeLists.txt | 2 +- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 1 + drivers/wifi/nrfwifi/src/fw_load.c | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 4055384aac7..3c912419a9c 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -63,7 +63,7 @@ zephyr_library_sources( src/qspi/src/ficr_prog.c ) -zephyr_library_sources_ifndef(CONFIG_NRF_WIFI_BUILD_ONLY_MODE +zephyr_library_sources_ifdef(CONFIG_NRF_WIFI_PATCHES_BUILTIN src/fw_load.c ) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index e7ee0169300..9152e325139 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -131,6 +131,7 @@ config NRF_WIFI_IF_AUTO_START config NRF_WIFI_PATCHES_BUILTIN bool "Store nRF70 FW patches as part of the driver" default y + depends on !NRF_WIFI_BUILD_ONLY_MODE help Select this option to store nRF70 FW patches as part of the driver. This option impacts the code memory footprint of the driver. diff --git a/drivers/wifi/nrfwifi/src/fw_load.c b/drivers/wifi/nrfwifi/src/fw_load.c index 14087a7d35c..6bf4c85193f 100644 --- a/drivers/wifi/nrfwifi/src/fw_load.c +++ b/drivers/wifi/nrfwifi/src/fw_load.c @@ -18,7 +18,6 @@ LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); #include -#ifdef CONFIG_NRF_WIFI_PATCHES_BUILTIN /* INCBIN macro Taken from https://gist.github.com/mmozeiko/ed9655cf50341553d282 */ #define STR2(x) #x #define STR(x) STR2(x) @@ -56,7 +55,6 @@ LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); extern const char prefix ## _ ## name ## _end[]; INCBIN(_bin, nrf70_fw, STR(CONFIG_NRF_WIFI_FW_BIN)); -#endif /* CONFIG_NRF_WIFI_PATCHES_BUILTIN */ enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) { From a493a542a38c004c46fd89c069840657eadee03e Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Oct 2024 16:18:11 +0200 Subject: [PATCH 3/6] [nrf fromtree] drivers: wifi: nrf: Remove unused linker script This script is needed only when external flash is used to store nRF70 firmware patches. This also uses PM which is supported only in NCS. Signed-off-by: Chaitanya Tata (cherry picked from commit d15b7b5b3af9a1e3e5e6bceb0792bcdc34e9131d) --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 4 -- drivers/wifi/nrfwifi/rpu_fw_patches.ld | 51 -------------------------- 2 files changed, 55 deletions(-) delete mode 100644 drivers/wifi/nrfwifi/rpu_fw_patches.ld diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 9152e325139..3ce4dda16b3 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -136,10 +136,6 @@ config NRF_WIFI_PATCHES_BUILTIN Select this option to store nRF70 FW patches as part of the driver. This option impacts the code memory footprint of the driver. -config CUSTOM_LINKER_SCRIPT - string "Custom linker script for nRF70 FW patches" - default "${ZEPHYR_BASE}/../nrf/drivers/wifi/nrf70/rpu_fw_patches.ld" - config NRF_WIFI_LOW_POWER bool "low power mode in nRF Wi-Fi chipsets" default y diff --git a/drivers/wifi/nrfwifi/rpu_fw_patches.ld b/drivers/wifi/nrfwifi/rpu_fw_patches.ld deleted file mode 100644 index 4ecbaedb096..00000000000 --- a/drivers/wifi/nrfwifi/rpu_fw_patches.ld +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Custom Linker command/script file - * - * Custom Linker script for the Cortex-M platforms. - */ - -#include -#include - -#include -#include - -#if CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP || CONFIG_BOARD_NRF52840DK_NRF52840 -/* - * nRF53/52 series ship an external flash that can be used for XIP using QSPI/SPI. - * - * Note: In nRF7002 external flash using is accessible only using SPI but there is no - * support for XIP, so, relocation cannot be used. - */ -#if CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP -#define EXTFLASH_BASE_ADDR 0x10000000 -#define EXTFLASH_SIZE 0x800000 -#elif CONFIG_BOARD_NRF52840DK_NRF52840 -#define EXTFLASH_BASE_ADDR 0x12000000 -#define EXTFLASH_SIZE 0x800000 -#endif /* CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP */ - -#if USE_PARTITION_MANAGER && PM_EXTERNAL_FLASH_ADDRESS -#include -#define EXTFLASH_ADDRESS (EXTFLASH_BASE_ADDR + PM_EXTERNAL_FLASH_ADDRESS) -#undef EXTFLASH_SIZE -#define EXTFLASH_SIZE (PM_EXTERNAL_FLASH_SIZE) -#else -#define EXTFLASH_ADDRESS (EXTFLASH_BASE_ADDR) -#endif /* USE_PARTITION_MANAGER && PM_EXTERNAL_FLASH_ADDRESS */ - -MEMORY -{ - EXTFLASH (wx) : ORIGIN = EXTFLASH_ADDRESS, LENGTH = EXTFLASH_SIZE -} - -#endif /* CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP || CONFIG_BOARD_NRF52840DK_NRF52840 */ - -#include From ac24e032ab87c4cdd419664c40dad9d21db3427e Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 2 Oct 2024 23:43:10 +0300 Subject: [PATCH 4/6] Revert "[nrf noup] drivers: wifi: nrfwifi: Workaround for build" This reverts commit b757e7ae6b4b2d4731bd7c9cfb5558e37ebbaa6f. Signed-off-by: Chaitanya Tata --- drivers/wifi/nrfwifi/Kconfig.nrfwifi | 33 ---------------------------- 1 file changed, 33 deletions(-) diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index 3ce4dda16b3..3096dd7c76e 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -697,37 +697,4 @@ config NRF_WIFI_BUILD_ONLY_MODE dependency on firmware binary and patches. This is useful to check the build and link errors. -# TODO: Temporary WAR, implement these options in the future -config NRF_WIFI_PATCHES_EXT_FLASH_DISABLED - bool "nRF70 firmware patch external flash support" - help - Select this option to disable external flash support for nRF70 firmware patches - -config NRF_WIFI_FW_PATCH_DFU - bool "nRF70 firmware patch DFU" - help - Select this option to enable DFU for nRF70 firmware patches - -config NRF_WIFI_PATCHES_EXT_FLASH_STORE - bool "nRF70 firmware patch external flash store" - help - Select this option to enable external flash store for nRF70 firmware patches - -config NRF_WIFI_FW_FLASH_CHUNK_SIZE - int "nRF70 firmware patch flash chunk size" - default 8192 - help - Select this option to set the flash chunk size for nRF70 firmware patches - -config NRF_WIFI_PATCHES_EXT_FLASH_XIP - bool "nRF70 firmware patch external flash XIP" - help - Select this option to enable external flash XIP for nRF70 firmware patches - -config NRF_WIFI_FEAT_WMM - bool "WMM/QoS support" - default y - help - This option controls disable/enable of the WMM(Wireless Multi-Media) feature. - endif # WIFI_NRF70 From c396233d956dd7f9c24458063dfb27049c3af8db Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 9 Oct 2024 23:52:44 +0530 Subject: [PATCH 5/6] [nrf fromtree] drivers: nrfwifi: Use Zephyr tooling to load nRF70 FW file Instead of relying on INCBIN macros which do not properly add dependencies, e.g., modifying FW file doesn't trigger rebuild. Use the Zephyr cmake tooling to load the FW patch file as a header. This also improves memory report where the patch target is clearly visible instead of a hidden section. Signed-off-by: Chaitanya Tata (cherry picked from commit b40cb4c46c093c20aba59034b385786e871560fd) --- drivers/wifi/nrfwifi/CMakeLists.txt | 11 +++++-- drivers/wifi/nrfwifi/src/fw_load.c | 49 +++-------------------------- 2 files changed, 12 insertions(+), 48 deletions(-) diff --git a/drivers/wifi/nrfwifi/CMakeLists.txt b/drivers/wifi/nrfwifi/CMakeLists.txt index 3c912419a9c..c3b0efef82b 100644 --- a/drivers/wifi/nrfwifi/CMakeLists.txt +++ b/drivers/wifi/nrfwifi/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # -zephyr_library() +zephyr_library_named(nrfwifi) set(OS_AGNOSTIC_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/drivers/nrf_wifi) set(FW_BINS_BASE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/zephyr/blobs/wifi_fw_bins) @@ -166,8 +166,13 @@ else() ------------------------------------------------------------------------") endif() - zephyr_compile_definitions( - -DCONFIG_NRF_WIFI_FW_BIN=${NRF70_PATCH} + set(gen_inc_dir ${ZEPHYR_BINARY_DIR}/misc/generated) + zephyr_include_directories(${gen_inc_dir}) + set(gen_dir ${gen_inc_dir}/nrf70_fw_patch) + generate_inc_file_for_target( + nrfwifi + ${NRF70_PATCH} + ${gen_dir}/nrf70.bin.inc ) endif() diff --git a/drivers/wifi/nrfwifi/src/fw_load.c b/drivers/wifi/nrfwifi/src/fw_load.c index 6bf4c85193f..9204d295d30 100644 --- a/drivers/wifi/nrfwifi/src/fw_load.c +++ b/drivers/wifi/nrfwifi/src/fw_load.c @@ -17,57 +17,16 @@ LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); #include - -/* INCBIN macro Taken from https://gist.github.com/mmozeiko/ed9655cf50341553d282 */ -#define STR2(x) #x -#define STR(x) STR2(x) - -#ifdef __APPLE__ -#define USTR(x) "_" STR(x) -#else -#define USTR(x) STR(x) -#endif - -#ifdef _WIN32 -#define INCBIN_SECTION ".rdata, \"dr\"" -#elif defined __APPLE__ -#define INCBIN_SECTION "__TEXT,__const" -#else -#define INCBIN_SECTION ".rodata.*" -#endif - -/* this aligns start address to 16 and terminates byte array with explicit 0 - * which is not really needed, feel free to change it to whatever you want/need - */ -#define INCBIN(prefix, name, file) \ - __asm__(".section " INCBIN_SECTION "\n" \ - ".global " USTR(prefix) "_" STR(name) "_start\n" \ - ".balign 16\n" \ - USTR(prefix) "_" STR(name) "_start:\n" \ - ".incbin \"" file "\"\n" \ - \ - ".global " STR(prefix) "_" STR(name) "_end\n" \ - ".balign 1\n" \ - USTR(prefix) "_" STR(name) "_end:\n" \ - ".byte 0\n" \ - ); \ - extern __aligned(16) const char prefix ## _ ## name ## _start[]; \ - extern const char prefix ## _ ## name ## _end[]; - -INCBIN(_bin, nrf70_fw, STR(CONFIG_NRF_WIFI_FW_BIN)); +static const char fw_patch[] = { + #include +}; enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx) { enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; struct nrf_wifi_fmac_fw_info fw_info = { 0 }; - uint8_t *fw_start; - uint8_t *fw_end; - - fw_start = (uint8_t *)_bin_nrf70_fw_start; - fw_end = (uint8_t *)_bin_nrf70_fw_end; - status = nrf_wifi_fmac_fw_parse(rpu_ctx, fw_start, fw_end - fw_start, - &fw_info); + status = nrf_wifi_fmac_fw_parse(rpu_ctx, fw_patch, sizeof(fw_patch), &fw_info); if (status != NRF_WIFI_STATUS_SUCCESS) { LOG_ERR("%s: nrf_wifi_fmac_fw_parse failed", __func__); return status; From 51dc193cd4e5ebb5c84f6c09f86669f28775d9db Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 11 Oct 2024 00:57:13 +0530 Subject: [PATCH 6/6] [nrf noup] samples: net: wifi: Enable Wi-Fi driver in sysbuild builds Make sure Wi-Fi driver is enabled when sysbuild is used. For shields we cannot automate this, as sysbuild doesn't recognize shields, so, Wi-Fi has to be explicitly enabled, this is done for twister. Signed-off-by: Chaitanya Tata --- samples/net/wifi/Kconfig.sysbuild | 13 +++++++++++++ samples/net/wifi/sample.yaml | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 samples/net/wifi/Kconfig.sysbuild diff --git a/samples/net/wifi/Kconfig.sysbuild b/samples/net/wifi/Kconfig.sysbuild new file mode 100644 index 00000000000..158551060c5 --- /dev/null +++ b/samples/net/wifi/Kconfig.sysbuild @@ -0,0 +1,13 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +config WIFI_NRF70 + default y if BOARD_NRF7002DK_NRF5340_CPUAPP || \ + BOARD_NRF7002DK_NRF5340_CPUAPP_NS || \ + BOARD_NRF7002DK_NRF5340_CPUAPP_NRF7001 || \ + BOARD_NRF7002DK_NRF5340_CPUAPP_NRF7001_NS + +source "${ZEPHYR_BASE}/share/sysbuild/Kconfig" diff --git a/samples/net/wifi/sample.yaml b/samples/net/wifi/sample.yaml index 1c106e4897a..51c52edbd6f 100644 --- a/samples/net/wifi/sample.yaml +++ b/samples/net/wifi/sample.yaml @@ -53,6 +53,7 @@ tests: - nrf7002dk/nrf5340/cpuapp/nrf7001 sample.net.wifi.nrf7002ek: extra_args: + - SB_CONFIG_WIFI_NRF70=y - CONFIG_NRF_WIFI_BUILD_ONLY_MODE=y - SHIELD=nrf7002ek platform_allow: @@ -64,6 +65,7 @@ tests: - nucleo_h723zg sample.net.wifi.nrf7002eb: extra_args: + - SB_CONFIG_WIFI_NRF70=y - CONFIG_NRF_WIFI_BUILD_ONLY_MODE=y - SHIELD=nrf7002eb platform_allow: