Skip to content

Commit

Permalink
Make ChibiOS lwIP platform independent (#2790)
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
networkfusion committed Nov 14, 2023
1 parent 4ed6ca5 commit f96d2c4
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile.All
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM ghcr.io/nanoframework/dev-container-all:v2.41
FROM ghcr.io/nanoframework/dev-container-all:v2.42
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile.ChibiOS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM ghcr.io/nanoframework/dev-container-chibios:v1.24
FROM ghcr.io/nanoframework/dev-container-chibios:v1.25
2 changes: 1 addition & 1 deletion .devcontainer/scripts/git-pull-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ git pull origin V10.4.1-kernel-only
cd /sources/CMSIS_5
git pull origin 5.5.1
cd /sources/lwip
git pull origin STABLE-2_0_3_RELEASE
git pull origin STABLE-2_1_2_RELEASE # FIXME: if the NXP targets still require STABLE-2_0_3_RELEASE as this is quite old now.
cd /sources/spiffs
git pull origin nf-build
cd /sources/SimpleLinkCC32
Expand Down
10 changes: 3 additions & 7 deletions .devcontainer/sources/Dockerfile.All
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,16 @@ RUN git clone --branch nf-build https://github.com/nanoframework/STM32CubeL4.git
&& git clone --branch v6.3.0_rel --recursive https://github.com/azure-rtos/netxduo.git --depth 1 ./sources/NetxDuo \
&& git clone --branch nanoframework https://github.com/nanoframework/ChibiOS-Contrib.git --depth 1 ./sources/ChibiOs-Contrib

# Clone mbedtls and fatfs
# Clone libs mbedtls and fatfs etc.
RUN git clone --branch mbedtls-2.28.5 https://github.com/ARMmbed/mbedtls.git --depth 1 ./sources/mbedtls \
&& git clone --branch R0.15 https://github.com/abbrev/fatfs.git --depth 1 ./sources/fatfs
&& git clone --branch R0.15 https://github.com/abbrev/fatfs.git --depth 1 ./sources/fatfs \
&& git clone --branch STABLE-2_1_2_RELEASE https://github.com/lwip-tcpip/lwip.git --depth 1 ./sources/lwip

# Clone FreeRTOS and what is needed for ESP32
RUN git clone --branch V10.4.1-kernel-only https://github.com/FreeRTOS/FreeRTOS-Kernel.git --depth 1 ./sources/FreeRTOS \
&& git clone --branch 5.5.1 https://github.com/ARM-software/CMSIS_5.git --depth 1 ./sources/CMSIS_5 \
&& git clone --branch nf-build https://github.com/nanoframework/spiffs.git --depth 1 ./sources/spiffs

# The certificate of this one is not prolely propagated in the base image, ignoring the verification of this clone
ENV GIT_SSL_NO_VERIFY=1
RUN git clone --branch STABLE-2_0_3_RELEASE https://git.savannah.nongnu.org/git/lwip.git --depth 1 ./sources/lwip
ENV GIT_SSL_NO_VERIFY=0

# Clone ESP-IDF
RUN git clone --branch v4.4.6 https://github.com/espressif/esp-idf --depth 1 --recursive ./sources/esp-idf

Expand Down
9 changes: 6 additions & 3 deletions .devcontainer/sources/Dockerfile.ChibiOS
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RUN apt-get update \
# Create needed directories
RUN mkdir -p /usr/local/bin/GCC_URI


# Clone ChibiOS repo
RUN git svn clone http://svn.code.sf.net/p/chibios/code/branches/stable_21.11.x -rHEAD ./sources/ChibiOs
# Alternative source for those having issues with git svn downloads:
Expand All @@ -58,10 +59,12 @@ RUN git clone --branch nf-build https://github.com/nanoframework/STM32CubeL4.git
&& git clone --branch nf-build https://github.com/nanoframework/STM32CubeF4.git --depth 1 ./sources/STM32CubeF4 \
&& git clone --branch nf-build https://github.com/nanoframework/STM32CubeH7.git --depth 1 ./sources/STM32CubeH7 \
&& git clone --branch nanoframework https://github.com/nanoframework/ChibiOS-Contrib.git --depth 1 ./sources/ChibiOs-Contrib
# Clone mbedtls and fatfs
RUN git clone --branch mbedtls-2.28.2 https://github.com/ARMmbed/mbedtls.git --depth 1 ./sources/mbedtls \

# Clone libs including mbedtls and fatfs
RUN git clone --branch mbedtls-2.28.5 https://github.com/ARMmbed/mbedtls.git --depth 1 ./sources/mbedtls \
&& git clone --branch R0.15 https://github.com/abbrev/fatfs.git --depth 1 ./sources/fatfs \
&& git clone --branch nf-build https://github.com/nanoframework/spiffs.git --depth 1 ./sources/spiffs
&& git clone --branch nf-build https://github.com/nanoframework/spiffs.git --depth 1 ./sources/spiffs \
&& git clone --branch STABLE-2_1_2_RELEASE https://github.com/lwip-tcpip/lwip.git --depth 1 ./sources/lwip

# set gcc location
ENV ARM_GCC_PATH=/usr/local/bin/gcc
Expand Down
38 changes: 10 additions & 28 deletions CMake/Modules/FindCHIBIOS_LWIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@
#

include(FetchContent)
FetchContent_GetProperties(lwip)
FetchContent_GetProperties(chibios)

# extract LwIP source files
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xf ${chibios_SOURCE_DIR}/ext/lwip-2.1.2.7z
WORKING_DIRECTORY ${chibios_SOURCE_DIR}/ext/
)

# List of the required lwIp include files.
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/targets/ChibiOS/_Lwip)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${chibios_SOURCE_DIR}/os/various)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${chibios_SOURCE_DIR}/os/various/lwip_bindings)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${chibios_SOURCE_DIR}/ext/lwip/src/include)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${chibios_SOURCE_DIR}/ext/lwip/src/include/lwip)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${chibios_SOURCE_DIR}/ext/lwip/src/include/netif)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${chibios_SOURCE_DIR}/ext/lwip/src/include/posix)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${lwip_SOURCE_DIR}/src/include)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${lwip_SOURCE_DIR}/src/include/lwip)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${lwip_SOURCE_DIR}/src/include/netif)
list(APPEND CHIBIOS_LWIP_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/DeviceInterfaces/Networking.Sntp)

set(LWIP_SRCS
Expand Down Expand Up @@ -103,16 +97,16 @@ foreach(SRC_FILE ${LWIP_SRCS})
find_file(LWIP_SRC_FILE ${SRC_FILE}
PATHS
${chibios_SOURCE_DIR}/os/various
${chibios_SOURCE_DIR}/ext/lwip/src/core
${chibios_SOURCE_DIR}/ext/lwip/src/core/ipv4
${chibios_SOURCE_DIR}/ext/lwip/src/core/ipv6
${chibios_SOURCE_DIR}/ext/lwip/src/api
${chibios_SOURCE_DIR}/ext/lwip/src/netif
${lwip_SOURCE_DIR}/src/core
${lwip_SOURCE_DIR}/src/core/ipv4
${lwip_SOURCE_DIR}/src/core/ipv6
${lwip_SOURCE_DIR}/src/api
${lwip_SOURCE_DIR}/src/netif

${CMAKE_SOURCE_DIR}/targets/ChibiOS/_Lwip

# APPS:
${chibios_SOURCE_DIR}/ext/lwip/src/apps/sntp
${lwip_SOURCE_DIR}/src/apps/sntp

CMAKE_FIND_ROOT_PATH_BOTH
)
Expand All @@ -128,15 +122,3 @@ endforeach()
include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(CHIBIOS_LWIP DEFAULT_MSG CHIBIOS_LWIP_INCLUDE_DIRS CHIBIOS_LWIP_SOURCES)

# setup target to unzip ChibiOS external network components
add_custom_target( CHIBIOS_NETWORK_COMPONENTS ALL )

add_custom_command(TARGET CHIBIOS_NETWORK_COMPONENTS
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E tar xf ${chibios_SOURCE_DIR}/ext/lwip-2.1.2.7z
WORKING_DIRECTORY ${chibios_SOURCE_DIR}/ext/
DEPENDS ${chibios_SOURCE_DIR}/ext/lwip-2.1.2.7z

VERBATIM
)
2 changes: 2 additions & 0 deletions config/user-tools-repos.TEMPLATE.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"CHIBIOS_CONTRIB_SOURCE": "<path-to-local-ChibiOS-contrib-source-mind-the-forward-slash>",
"CHIBIOS_HAL_SOURCE": "<path-to-ChibiOS-source-folder-if-supported-mind-the-forward-slash>",
"STM32_CUBE_PACKAGE_SOURCE": "<path-to-stm32-cubemx-package-mind-the-forward-slash>",
"LWIP_SOURCE": "<path-to-lwip-source-mind-the-forward-slashes>",
"MBEDTLS_SOURCE": "<path-to-mbedtls-source-mind-the-forward-slashes>",
"FATFS_SOURCE": "<path-to-local-FATFS-source-mind-the-forward-slash>",
"SPIFFS_SOURCE": "<path-to-local-SPIFFS-source-mind-the-forward-slash>",
Expand All @@ -37,6 +38,7 @@
"CHIBIOS_CONTRIB_SOURCE": "/sources/ChibiOs-Contrib",
"CHIBIOS_HAL_SOURCE": "/sources/ChibiOs",
"STM32_CUBE_PACKAGE_SOURCE": "/sources/STM32CubeL4",
"LWIP_SOURCE": "/sources/lwip",
"MBEDTLS_SOURCE": "/sources/mbedtls",
"FATFS_SOURCE": "/sources/fatfs",
"SPIFFS_SOURCE": "/sources/spiffs",
Expand Down
48 changes: 48 additions & 0 deletions targets/ChibiOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,54 @@ if(NF_FEATURE_HAS_SDCARD OR NF_FEATURE_HAS_USB_MSD)

endif()

# if networking is enabled add lwIP to the build
if(USE_NETWORKING_OPTION)

# check if LWIP_SOURCE was specified or if it's empty (default is empty)
set(NO_LWIP_SOURCE TRUE)

if(LWIP_SOURCE)
if(NOT ${LWIP_SOURCE} STREQUAL "")
set(NO_LWIP_SOURCE FALSE)
endif()
endif()

# set tag for currently supported version
# WHEN CHANGING THIS MAKE SURE TO UPDATE THE DEV CONTAINERS
set(LWIP_GIT_TAG "STABLE-2_1_2_RELEASE")

if(NO_LWIP_SOURCE)
# no LWIP source specified, download it from it's repo
message(STATUS "LWIP ${LWIP_GIT_TAG} from Git repo")

FetchContent_Declare(
lwip
GIT_REPOSITORY https://github.com/lwip-tcpip/lwip.git
GIT_TAG ${LWIP_GIT_TAG}
)

else()
# LWIP source was specified

message(STATUS "LWIP ${LWIP_GIT_TAG} (source from: ${LWIP_SOURCE})")

FetchContent_Declare(
lwip
SOURCE_DIR ${LWIP_SOURCE}
)

endif()

# Check if population has already been performed
FetchContent_GetProperties(lwip)
if(NOT lwip_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(lwip)
endif()

endif()


# if Mbed TLS is enabled add it to the build
if(USE_SECURITY_MBEDTLS_OPTION OR NF_REQUIRES_MBEDTLS)

Expand Down
4 changes: 2 additions & 2 deletions targets/FreeRTOS/NXP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ endif()

if(NO_LWIP_SOURCE)

message(STATUS "lwIP ${LWIP_GIT_TAG} from savannah.nongnu.org repo")
message(STATUS "lwIP ${LWIP_GIT_TAG} from github.com/lwip-tcpip/lwip repo")

FetchContent_Declare(
lwip
GIT_REPOSITORY https://git.savannah.nongnu.org/git/lwip.git
GIT_REPOSITORY https://github.com/lwip-tcpip/lwip.git
GIT_TAG ${LWIP_GIT_TAG}
)

Expand Down

0 comments on commit f96d2c4

Please sign in to comment.