From 22459361c9da144759c431cbafe7a48eedc072d4 Mon Sep 17 00:00:00 2001 From: Rohan Sahay Date: Fri, 17 Mar 2023 03:51:28 +0530 Subject: [PATCH] [Silabs] Adds support for GSDK LWIP library (#25713) * Adds support for GSDK LwIP * Adds suggested changes * Adds help prompt * Adds fixes to port to GSDK LwIP * Adds fix for use_silabs_lwip_lib usage * Comments code to make use of SDK LwIP permanently, will make changes later to support flag * Removes "external" lwip_platform build changes * Port changes for SiWx917 * Adds support for flag --use_lwip_lib * Adds bugfix for flag lwip_ipv6 * Port changes to SiWx917 * Restyled by shfmt * Adds changes to default to GSDK LwIP * Revert whitespace change --------- Co-authored-by: Restyled.io Co-authored-by: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> --- scripts/examples/gn_efr32_example.sh | 6 + src/platform/silabs/SiWx917/wifi_args.gni | 5 +- src/platform/silabs/efr32/wifi_args.gni | 5 +- third_party/silabs/efr32_sdk.gni | 2 +- third_party/silabs/lwip.gni | 211 ++++++++++++++++++++++ 5 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 third_party/silabs/lwip.gni diff --git a/scripts/examples/gn_efr32_example.sh b/scripts/examples/gn_efr32_example.sh index 09bdf90afb0312..b94c8485d8c2c7 100755 --- a/scripts/examples/gn_efr32_example.sh +++ b/scripts/examples/gn_efr32_example.sh @@ -113,6 +113,8 @@ if [ "$#" == "0" ]; then enable Addition data advertissing and rotating device ID --use_ot_lib use the silabs openthread library + --use_chip_lwip_lib + use the chip lwip library --no-version Skip the silabs formating for the Matter software version string Currently : v1.0-- @@ -180,6 +182,10 @@ else optArgs+="use_silabs_thread_lib=true chip_openthread_target=$SILABS_THREAD_TARGET openthread_external_platform=\"""\" use_thread_coap_lib=true " shift ;; + --use_chip_lwip_lib) + optArgs+="lwip_root=\""//third_party/connectedhomeip/third_party/lwip"\" " + shift + ;; # Option not to be used until ot-efr32 github is updated # --use_ot_github_sources) # optArgs+="openthread_root=\"//third_party/connectedhomeip/third_party/openthread/ot-efr32/openthread\" openthread_efr32_root=\"//third_party/connectedhomeip/third_party/openthread/ot-efr32/src/src\"" diff --git a/src/platform/silabs/SiWx917/wifi_args.gni b/src/platform/silabs/SiWx917/wifi_args.gni index d63fb5e1d89a2c..4698b4fd1f768b 100644 --- a/src/platform/silabs/SiWx917/wifi_args.gni +++ b/src/platform/silabs/SiWx917/wifi_args.gni @@ -31,8 +31,11 @@ chip_crypto = "platform" # examples/platform/efr32/EFR32DeviceDataProvider is now used. chip_use_transitional_commissionable_data_provider = false -#lwip_platform = "external" lwip_platform = "silabs" + +# Use GSDK lwip instead of CHIP +lwip_root = "${efr32_sdk_build_root}" + lwip_ipv6 = true lwip_ipv4 = true lwip_api = true diff --git a/src/platform/silabs/efr32/wifi_args.gni b/src/platform/silabs/efr32/wifi_args.gni index 792ed41081ce38..cb6a8f45fe4478 100644 --- a/src/platform/silabs/efr32/wifi_args.gni +++ b/src/platform/silabs/efr32/wifi_args.gni @@ -34,8 +34,11 @@ if (chip_crypto == "") { # examples/platform/efr32/EFR32DeviceDataProvider is now used. chip_use_transitional_commissionable_data_provider = false -#lwip_platform = "external" lwip_platform = "silabs" + +# Use GSDK lwip instead of CHIP +lwip_root = "${efr32_sdk_build_root}" + lwip_ipv6 = true lwip_ipv4 = true lwip_api = true diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 24add51f0e7280..dbc44bea5c3e3f 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -250,7 +250,7 @@ template("efr32_sdk") { } else { defines += [ "LWIP_IPV4=0" ] } - if (lwip_ipv4) { + if (lwip_ipv6) { defines += [ "LWIP_IPV6=1" ] } else { defines += [ "LWIP_IPV6=0" ] diff --git a/third_party/silabs/lwip.gni b/third_party/silabs/lwip.gni new file mode 100644 index 00000000000000..1637b9e5a856b2 --- /dev/null +++ b/third_party/silabs/lwip.gni @@ -0,0 +1,211 @@ +# Copyright (c) 2023 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build_overrides/efr32_sdk.gni") +import("//build_overrides/lwip.gni") + +# Defines a lwIP build target. +# +# lwIP depends on external header files to compile. This template defines +# a combined build of the lwIP sources plus target configuration. +template("lwip_target") { + _lwip_root = "${efr32_sdk_build_root}/gecko_sdk/util/third_party/lwip/lwip" + + lwip_target_name = target_name + + # Apply overrides for lwIP features. + forward_variables_from(invoker, + [ + "lwip_ipv4", + "lwip_ipv6", + "lwip_api", + "lwip_ethernet", + "lwip_slip", + "lwip_6lowpan", + ]) + + if (!defined(lwip_ipv4)) { + lwip_ipv4 = true + } + if (!defined(lwip_ipv6)) { + lwip_ipv6 = true + } + if (!defined(lwip_api)) { + lwip_api = true + } + if (!defined(lwip_ethernet)) { + lwip_ethernet = true + } + if (!defined(lwip_slip)) { + lwip_slip = false + } + if (!defined(lwip_6lowpan)) { + lwip_6lowpan = false + } + + config("${lwip_target_name}_base_config") { + include_dirs = [ "${_lwip_root}/src/include" ] + } + + source_set(lwip_target_name) { + forward_variables_from(invoker, + [ + "sources", + "public", + "public_configs", + "public_deps", + ]) + + # lwIP headers become empty if the relevant feature is disabled, so the + # whole interface can be public regardless of build options. + public += [ + "${_lwip_root}/src/include/lwip/api.h", + "${_lwip_root}/src/include/lwip/autoip.h", + "${_lwip_root}/src/include/lwip/debug.h", + "${_lwip_root}/src/include/lwip/def.h", + "${_lwip_root}/src/include/lwip/dhcp.h", + "${_lwip_root}/src/include/lwip/dhcp6.h", + "${_lwip_root}/src/include/lwip/dns.h", + "${_lwip_root}/src/include/lwip/err.h", + "${_lwip_root}/src/include/lwip/etharp.h", + "${_lwip_root}/src/include/lwip/ethip6.h", + "${_lwip_root}/src/include/lwip/icmp.h", + "${_lwip_root}/src/include/lwip/icmp6.h", + "${_lwip_root}/src/include/lwip/if_api.h", + "${_lwip_root}/src/include/lwip/igmp.h", + "${_lwip_root}/src/include/lwip/inet.h", + "${_lwip_root}/src/include/lwip/inet_chksum.h", + "${_lwip_root}/src/include/lwip/init.h", + "${_lwip_root}/src/include/lwip/ip.h", + "${_lwip_root}/src/include/lwip/ip4_frag.h", + "${_lwip_root}/src/include/lwip/ip6.h", + "${_lwip_root}/src/include/lwip/ip6_addr.h", + "${_lwip_root}/src/include/lwip/ip6_frag.h", + "${_lwip_root}/src/include/lwip/ip_addr.h", + "${_lwip_root}/src/include/lwip/mem.h", + "${_lwip_root}/src/include/lwip/memp.h", + "${_lwip_root}/src/include/lwip/mld6.h", + "${_lwip_root}/src/include/lwip/nd6.h", + "${_lwip_root}/src/include/lwip/netbuf.h", + "${_lwip_root}/src/include/lwip/netdb.h", + "${_lwip_root}/src/include/lwip/netif.h", + "${_lwip_root}/src/include/lwip/netifapi.h", + "${_lwip_root}/src/include/lwip/opt.h", + "${_lwip_root}/src/include/lwip/pbuf.h", + "${_lwip_root}/src/include/lwip/priv/tcp_priv.h", + "${_lwip_root}/src/include/lwip/priv/tcpip_priv.h", + "${_lwip_root}/src/include/lwip/prot/autoip.h", + "${_lwip_root}/src/include/lwip/prot/dhcp.h", + "${_lwip_root}/src/include/lwip/prot/dns.h", + "${_lwip_root}/src/include/lwip/prot/ethernet.h", + "${_lwip_root}/src/include/lwip/prot/icmp6.h", + "${_lwip_root}/src/include/lwip/prot/igmp.h", + "${_lwip_root}/src/include/lwip/prot/mld6.h", + "${_lwip_root}/src/include/lwip/prot/nd6.h", + "${_lwip_root}/src/include/lwip/raw.h", + "${_lwip_root}/src/include/lwip/snmp.h", + "${_lwip_root}/src/include/lwip/sockets.h", + "${_lwip_root}/src/include/lwip/stats.h", + "${_lwip_root}/src/include/lwip/sys.h", + "${_lwip_root}/src/include/lwip/tcp.h", + "${_lwip_root}/src/include/lwip/tcpip.h", + "${_lwip_root}/src/include/lwip/timeouts.h", + "${_lwip_root}/src/include/lwip/udp.h", + ] + + sources += [ + "${_lwip_root}/src/core/def.c", + "${_lwip_root}/src/core/dns.c", + "${_lwip_root}/src/core/inet_chksum.c", + "${_lwip_root}/src/core/init.c", + "${_lwip_root}/src/core/ip.c", + "${_lwip_root}/src/core/mem.c", + "${_lwip_root}/src/core/memp.c", + "${_lwip_root}/src/core/netif.c", + "${_lwip_root}/src/core/pbuf.c", + "${_lwip_root}/src/core/raw.c", + "${_lwip_root}/src/core/stats.c", + "${_lwip_root}/src/core/sys.c", + "${_lwip_root}/src/core/tcp.c", + "${_lwip_root}/src/core/tcp_in.c", + "${_lwip_root}/src/core/tcp_out.c", + "${_lwip_root}/src/core/timeouts.c", + "${_lwip_root}/src/core/udp.c", + "${_lwip_root}/src/include/lwip/priv/api_msg.h", + "${_lwip_root}/src/include/lwip/priv/memp_std.h", + "${_lwip_root}/src/include/lwip/priv/nd6_priv.h", + ] + + if (lwip_ipv4) { + sources += [ + "${_lwip_root}/src/core/ipv4/autoip.c", + "${_lwip_root}/src/core/ipv4/dhcp.c", + "${_lwip_root}/src/core/ipv4/etharp.c", + "${_lwip_root}/src/core/ipv4/icmp.c", + "${_lwip_root}/src/core/ipv4/igmp.c", + "${_lwip_root}/src/core/ipv4/ip4.c", + "${_lwip_root}/src/core/ipv4/ip4_addr.c", + "${_lwip_root}/src/core/ipv4/ip4_frag.c", + ] + } + + if (lwip_ipv6) { + sources += [ + "${_lwip_root}/src/core/ipv6/dhcp6.c", + "${_lwip_root}/src/core/ipv6/ethip6.c", + "${_lwip_root}/src/core/ipv6/icmp6.c", + "${_lwip_root}/src/core/ipv6/inet6.c", + "${_lwip_root}/src/core/ipv6/ip6.c", + "${_lwip_root}/src/core/ipv6/ip6_addr.c", + "${_lwip_root}/src/core/ipv6/ip6_frag.c", + "${_lwip_root}/src/core/ipv6/mld6.c", + "${_lwip_root}/src/core/ipv6/nd6.c", + ] + } + + if (lwip_api) { + sources += [ + "${_lwip_root}/src/api/api_lib.c", + "${_lwip_root}/src/api/api_msg.c", + "${_lwip_root}/src/api/err.c", + "${_lwip_root}/src/api/if_api.c", + "${_lwip_root}/src/api/netbuf.c", + "${_lwip_root}/src/api/netdb.c", + "${_lwip_root}/src/api/netifapi.c", + "${_lwip_root}/src/api/sockets.c", + "${_lwip_root}/src/api/tcpip.c", + ] + } + + if (lwip_ethernet) { + sources += [ "${_lwip_root}/src/netif/ethernet.c" ] + } + + if (lwip_slip) { + sources += [ "${_lwip_root}/src/netif/slipif.c" ] + } + + if (lwip_6lowpan) { + sources += [ "${_lwip_root}/src/netif/lowpan6.c" ] + } + + if (defined(lwip_remove_configs)) { + configs -= lwip_remove_configs + } + if (defined(lwip_add_configs)) { + configs += lwip_add_configs + } + + public_configs += [ ":${lwip_target_name}_base_config" ] + } +}