From dfa5925f3a3304f8d735d6f9dc9e28500f17b0c9 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Wed, 9 Oct 2024 13:36:29 +0800 Subject: [PATCH 1/3] Fix WiFi link error for as default network interface This fixes WiFi doesn't get linked in when configued as default network interface. --- connectivity/netsocket/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/connectivity/netsocket/CMakeLists.txt b/connectivity/netsocket/CMakeLists.txt index 271b0f7854e..51f199d1e63 100644 --- a/connectivity/netsocket/CMakeLists.txt +++ b/connectivity/netsocket/CMakeLists.txt @@ -74,6 +74,12 @@ if("MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=MESH" IN_LIST MBED_CONFIG_DE target_link_libraries(mbed-netsocket-api PUBLIC mbed-nanostack-mbed_mesh_api) endif() +# Similarly if wifi networking is used bring in that library +if("MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=WIFI" IN_LIST MBED_CONFIG_DEFINITIONS) + if(TARGET mbed-wifi) + target_link_libraries(mbed-netsocket-api PUBLIC mbed-wifi) + endif() +endif() if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS) target_link_libraries(mbed-netsocket-api From b3a427945c39dedf6a65435e3421f1add75c203a Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Wed, 16 Oct 2024 14:56:27 +0800 Subject: [PATCH 2/3] Fix creation of mbed-wifi target to top directory The location where the 'mbed-wifi' target is created is now fixed to the top directory. CMake commands e.g. add_custom_command are required to invoke in the same directory as where the 'mbed-wifi' target is created. --- connectivity/drivers/wifi/CMakeLists.txt | 3 +++ connectivity/drivers/wifi/TARGET_STM/CMakeLists.txt | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/connectivity/drivers/wifi/CMakeLists.txt b/connectivity/drivers/wifi/CMakeLists.txt index f729ed603d0..7def3aa1b7f 100644 --- a/connectivity/drivers/wifi/CMakeLists.txt +++ b/connectivity/drivers/wifi/CMakeLists.txt @@ -23,6 +23,9 @@ if("WICED" IN_LIST MBED_TARGET_LABELS) endif() if("STM" IN_LIST MBED_TARGET_LABELS) + if("EMW3080B" IN_LIST MBED_TARGET_LABELS) + create_mbed_wifi_target() + endif() add_subdirectory(TARGET_STM EXCLUDE_FROM_ALL) endif() diff --git a/connectivity/drivers/wifi/TARGET_STM/CMakeLists.txt b/connectivity/drivers/wifi/TARGET_STM/CMakeLists.txt index 2b37c21df56..78d80df1a6f 100644 --- a/connectivity/drivers/wifi/TARGET_STM/CMakeLists.txt +++ b/connectivity/drivers/wifi/TARGET_STM/CMakeLists.txt @@ -2,6 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 if("EMW3080B" IN_LIST MBED_TARGET_LABELS) - create_mbed_wifi_target() add_subdirectory(COMPONENT_EMW3080B EXCLUDE_FROM_ALL) endif() From 67b6fd968483a6940baebf5add292f23a7dec0a3 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Mon, 14 Oct 2024 17:03:36 +0800 Subject: [PATCH 3/3] Support WiFi as default network interface This requires support for weak symbol override. Object files arcived in static library don't always participate in linking, dependent on linker and link order. To fix this, the object files which will override weak symbols are extracted and passed to linker command line separately to actively participate in linking. --- connectivity/drivers/wifi/CMakeLists.txt | 80 +++++++++++++++++++ .../CMakeLists.txt | 7 ++ .../COMPONENT_EMW3080B/CMakeLists.txt | 7 ++ 3 files changed, 94 insertions(+) diff --git a/connectivity/drivers/wifi/CMakeLists.txt b/connectivity/drivers/wifi/CMakeLists.txt index 7def3aa1b7f..066eafd3be5 100644 --- a/connectivity/drivers/wifi/CMakeLists.txt +++ b/connectivity/drivers/wifi/CMakeLists.txt @@ -14,6 +14,35 @@ macro(create_mbed_wifi_target) endif() endmacro() +# Collect sources which need to extract from static library to override +# weak symbols. Their paths are required to relative to this directory +# ,so that they match with entries in static library and their corresponding +# object files there can be found and extracted. +set(MBED_WIFI_OVERRIDE_SOURCES "" CACHE INTERNAL "" FORCE) + +# Add override sources by subdirectories +# +# The input sources are required to relative to their subdirectories +# and will get converted to relative to this directory herein. +function(mbed_wifi_add_override_sources) + set(override_sources ${MBED_WIFI_OVERRIDE_SOURCES}) + + foreach(override_source ${ARGN}) + # Convert to relative to this directory + file(RELATIVE_PATH + override_source_fix + ${CMAKE_CURRENT_FUNCTION_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/${override_source} + ) + + set(override_sources + ${override_sources} + ${override_source_fix} + ) + endforeach() + + set(MBED_WIFI_OVERRIDE_SOURCES ${override_sources} CACHE INTERNAL "" FORCE) +endfunction() # The WICED subdirectory is for wifi drivers developed using Infineon WICED framework. # https://community.infineon.com/t5/Knowledge-Base-Articles/WICED-Wi-Fi-FAQ/ta-p/247356 @@ -39,3 +68,54 @@ if("COMPONENT_ESPRESSIF_ESP8266=1" IN_LIST MBED_TARGET_DEFINITIONS) add_subdirectory(COMPONENT_ESPRESSIF_ESP8266) endif() +# Extract override objects from static library and pass them to +# link options to actively participate in linking and override weak +# symbols. +if(TARGET mbed-wifi AND NOT "${MBED_WIFI_OVERRIDE_SOURCES}" STREQUAL "") + set(override_sources ${MBED_WIFI_OVERRIDE_SOURCES}) + list(TRANSFORM override_sources APPEND ${CMAKE_CXX_OUTPUT_EXTENSION} OUTPUT_VARIABLE override_objects) + list(TRANSFORM override_objects PREPEND ${CMAKE_CURRENT_BINARY_DIR}/ OUTPUT_VARIABLE override_objects_fullpath) + + if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + # Override objects passed via target_link_options are finally + # de-duplicated, so we can avoid multiple definition issue caused + # due to cyclic target link via target_link_libraries. + # + # https://cmake.org/cmake/help/latest/command/target_link_options.html#option-de-duplication + target_link_options(mbed-wifi + INTERFACE + ${override_objects_fullpath} + ) + + # Commands for extracting override objects + foreach(override_object ${override_objects}) + get_filename_component(override_object_dirname ${override_object} DIRECTORY) + + # Extract object files from static library + # + # NOTE: The support has restrictions on input static library: + # 1. No full path match modifier ('P') is specified on creating + # the static library. + # 2. Object file names must be different for just one-level entry + # names in the static library. + # https://sourceware.org/binutils/docs/binutils/ar-cmdline.html + set(extract_commands + ${extract_commands} + COMMAND + ${CMAKE_COMMAND} -E make_directory ${override_object_dirname} + COMMAND + ${CMAKE_AR} x --output ${override_object_dirname} $ ${override_object} + ) + endforeach() + + add_custom_command( + TARGET + mbed-wifi + POST_BUILD + ${extract_commands} + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR} + VERBATIM + ) + endif() +endif() diff --git a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt index 682139f0e84..c17940232dc 100644 --- a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt +++ b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt @@ -12,3 +12,10 @@ target_include_directories(mbed-wifi . ./ESP8266 ) + +# Add sources which contain override symbols +if("MBED_CONF_ESP8266_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS) + mbed_wifi_add_override_sources( + ESP8266Interface.cpp + ) +endif() diff --git a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt index a91dc52b119..ae4a1bb1d09 100644 --- a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt +++ b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt @@ -21,3 +21,10 @@ target_sources(mbed-wifi mx_wifi/core/mx_wifi_ipc.c mx_wifi/core/mx_wifi_slip.c ) + +# Add sources which contain override symbols +if("MBED_CONF_EMW3080B_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS) + mbed_wifi_add_override_sources( + EMW3080BInterface.cpp + ) +endif()