Skip to content

Commit

Permalink
Merge branch 'feature/lwip_linux' into 'master'
Browse files Browse the repository at this point in the history
lwip: Add support for linux target

Closes IDF-5707, IDF-5647, and IDF-6003

See merge request espressif/esp-idf!19302
  • Loading branch information
david-cermak committed Jan 31, 2023
2 parents 20f5f64 + 5d04eba commit dba0718
Show file tree
Hide file tree
Showing 80 changed files with 1,084 additions and 479 deletions.
18 changes: 18 additions & 0 deletions .gitlab/ci/host-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ test_mqtt_on_host:
- idf.py build
- LSAN_OPTIONS=verbosity=1:log_threads=1 build/host_mqtt_client_test.elf

test_sockets_on_host:
extends: .host_test_template
script:
# test the tcp-client example with system sockets
- cd ${IDF_PATH}/examples/protocols/sockets/tcp_client
- echo 'CONFIG_EXAMPLE_IPV4_ADDR="127.0.0.1"' >> sdkconfig.defaults
- idf.py --preview set-target linux
- idf.py build
- timeout 5 ./build/tcp_client.elf >test.log || true
- grep "Socket unable to connect" test.log
# test the udp-client example with lwip sockets
- cd ${IDF_PATH}/examples/protocols/sockets/udp_client
- echo 'CONFIG_EXAMPLE_IPV4_ADDR="127.0.0.1"' >> sdkconfig.defaults
- idf.py --preview set-target linux
- idf.py build
- timeout 5 ./build/udp_client.elf >test.log || true
- grep "Message sent" test.log

test_eh_frame_parser:
extends: .host_test_template
script:
Expand Down
12 changes: 6 additions & 6 deletions components/esp_netif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
idf_build_get_property(target IDF_TARGET)

if(${target} STREQUAL "linux")
# Header only library for linux
idf_component_register(INCLUDE_DIRS include)
return()
endif()

set(srcs_lwip
"lwip/esp_netif_lwip.c"
"lwip/esp_netif_sntp.c"
Expand All @@ -23,6 +17,12 @@ set(srcs
set(include_dirs "include")
set(priv_include_dirs "private_include")

idf_build_get_property(target IDF_TARGET)
if(${target} STREQUAL "linux")
list(APPEND include_dirs
"linux/stubs/include")
endif()

if(CONFIG_PPP_SUPPORT)
list(APPEND srcs_lwip lwip/esp_netif_lwip_ppp.c)
endif()
Expand Down
8 changes: 8 additions & 0 deletions components/esp_netif/linux/stubs/include/machine/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#include_next <endian.h>
1 change: 1 addition & 0 deletions components/esp_netif/lwip/esp_netif_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "esp_netif.h"
#include "esp_netif_private.h"
#include "esp_random.h"
#include "esp_system.h"

#include "lwip/tcpip.h"
#include "lwip/dhcp.h"
Expand Down
3 changes: 3 additions & 0 deletions components/esp_netif/lwip/esp_netif_lwip_defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#if defined(CONFIG_PPP_SUPPORT)
#include "esp_netif_lwip_ppp.h"
#endif
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP)

#if CONFIG_ESP_NETIF_BRIDGE_EN
#include "netif/bridgeif.h"
Expand Down Expand Up @@ -64,3 +65,5 @@ const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp = &s_n
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_eth = &s_eth_netif_config;
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_sta = &s_wifi_netif_config_sta;
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_ap = &s_wifi_netif_config_ap;

#endif /*CONFIG_ESP_NETIF_TCPIP_LWIP*/
47 changes: 33 additions & 14 deletions components/lwip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
idf_build_get_property(target IDF_TARGET)
if(NOT ${target} STREQUAL "linux")
# ESP platform targets share the same port folder
set(target esp32xx)
endif()

set(include_dirs
include
include/apps
include/apps/sntp
lwip/src/include
port/esp32/include
port/esp32/include/arch
port/include
port/freertos/include/
port/${target}/include
port/${target}/include/arch
)

set(srcs
Expand Down Expand Up @@ -85,11 +93,11 @@ set(srcs
"lwip/src/netif/ppp/upap.c"
"lwip/src/netif/ppp/utils.c"
"lwip/src/netif/ppp/vj.c"
"port/esp32/hooks/tcp_isn_default.c"
"port/esp32/hooks/lwip_default_hooks.c"
"port/esp32/debug/lwip_debug.c"
"port/esp32/freertos/sys_arch.c"
"port/esp32/sockets_ext.c")
"port/hooks/tcp_isn_default.c"
"port/hooks/lwip_default_hooks.c"
"port/debug/lwip_debug.c"
"port/sockets_ext.c"
"port/freertos/sys_arch.c")

if(CONFIG_LWIP_PPP_SUPPORT)
list(APPEND srcs
Expand Down Expand Up @@ -125,10 +133,15 @@ if(CONFIG_LWIP_PPP_SUPPORT)
"lwip/src/netif/ppp/polarssl/sha1.c")
endif()

if(CONFIG_VFS_SUPPORT_IO)
list(APPEND srcs "port/esp32/vfs_lwip.c")
else()
list(APPEND srcs "port/esp32/no_vfs_syscalls.c")
if(NOT ${target} STREQUAL "linux")
# Support for vfs and linker fragments only for target builds
set(priv_requires vfs)
set(linker_fragments linker.lf)
if(CONFIG_VFS_SUPPORT_IO)
list(APPEND srcs "port/${target}/vfs_lwip.c")
else()
list(APPEND srcs "port/${target}/no_vfs_syscalls.c")
endif()
endif()

if(CONFIG_LWIP_ICMP)
Expand All @@ -147,9 +160,9 @@ if(CONFIG_LWIP_DHCP_RESTORE_LAST_IP)
endif()

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include_dirs}"
LDFRAGMENTS linker.lf
PRIV_REQUIRES vfs)
INCLUDE_DIRS ${include_dirs}
LDFRAGMENTS ${linker_fragments}
PRIV_REQUIRES ${priv_requires})

# lots of LWIP source files evaluate macros that check address of stack variables
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-address)
Expand Down Expand Up @@ -188,3 +201,9 @@ if(CONFIG_LWIP_DHCP_RESTORE_LAST_IP)
endif()

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

if(${target} STREQUAL "linux")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${COMPONENT_LIB} PRIVATE Threads::Threads)
endif()
2 changes: 1 addition & 1 deletion components/lwip/apps/dhcpserver/dhcpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
//#include "esp_common.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "lwip/dhcp.h"
#include "lwip/err.h"
#include "lwip/pbuf.h"
Expand Down
1 change: 1 addition & 0 deletions components/lwip/apps/ping/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#if PING_USE_SOCKETS
#include "lwip/sockets.h"
#include "lwip/inet.h"
#include "esp_task.h"
#include "ping/ping_sock.h"
#endif /* PING_USE_SOCKETS */

Expand Down
3 changes: 2 additions & 1 deletion components/lwip/apps/ping/ping_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <stdlib.h>
#include <stdbool.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "lwip/opt.h"
Expand Down Expand Up @@ -231,7 +232,7 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
/* set ICMP type and code field */
ep->packet_hdr->code = 0;
/* ping id should be unique, treat task handle as ping ID */
ep->packet_hdr->id = ((uint32_t)ep->ping_task_hdl) & 0xFFFF;
ep->packet_hdr->id = ((intptr_t)ep->ping_task_hdl) & 0xFFFF;
/* fill the additional data buffer with some data */
char *d = (char *)(ep->packet_hdr) + sizeof(struct icmp_echo_hdr);
for (uint32_t i = 0; i < config->data_size; i++) {
Expand Down
1 change: 1 addition & 0 deletions components/lwip/apps/sntp/sntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#undef SNTP_OPMODE_POLL
#include "lwip/apps/sntp.h"
#include "lwip/tcpip.h"
#include "esp_macros.h"

static const char *TAG = "sntp";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "debug/lwip_debug.h"
#include "lwip/api.h"
Expand Down
40 changes: 0 additions & 40 deletions components/lwip/port/esp32/include/arch/perf.h

This file was deleted.

23 changes: 0 additions & 23 deletions components/lwip/port/esp32/include/arch/vfs_lwip.h

This file was deleted.

20 changes: 0 additions & 20 deletions components/lwip/port/esp32/include/arpa/inet.h

This file was deleted.

33 changes: 0 additions & 33 deletions components/lwip/port/esp32/include/debug/lwip_debug.h

This file was deleted.

48 changes: 0 additions & 48 deletions components/lwip/port/esp32/include/netdb.h

This file was deleted.

Loading

0 comments on commit dba0718

Please sign in to comment.