Skip to content

Commit

Permalink
Support WiFi as default network interface
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ccli8 committed Oct 16, 2024
1 parent dfa9644 commit 7c2d892
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
80 changes: 80 additions & 0 deletions connectivity/drivers/wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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} $<TARGET_FILE_NAME:mbed-wifi> ${override_object}
)
endforeach()

add_custom_command(
TARGET
mbed-wifi
POST_BUILD
${extract_commands}
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
endif()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 7c2d892

Please sign in to comment.