Skip to content

Commit dba0718

Browse files
committed
Merge branch 'feature/lwip_linux' into 'master'
lwip: Add support for linux target Closes IDF-5707, IDF-5647, and IDF-6003 See merge request espressif/esp-idf!19302
2 parents 20f5f64 + 5d04eba commit dba0718

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1084
-479
lines changed

.gitlab/ci/host-test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,24 @@ test_mqtt_on_host:
336336
- idf.py build
337337
- LSAN_OPTIONS=verbosity=1:log_threads=1 build/host_mqtt_client_test.elf
338338

339+
test_sockets_on_host:
340+
extends: .host_test_template
341+
script:
342+
# test the tcp-client example with system sockets
343+
- cd ${IDF_PATH}/examples/protocols/sockets/tcp_client
344+
- echo 'CONFIG_EXAMPLE_IPV4_ADDR="127.0.0.1"' >> sdkconfig.defaults
345+
- idf.py --preview set-target linux
346+
- idf.py build
347+
- timeout 5 ./build/tcp_client.elf >test.log || true
348+
- grep "Socket unable to connect" test.log
349+
# test the udp-client example with lwip sockets
350+
- cd ${IDF_PATH}/examples/protocols/sockets/udp_client
351+
- echo 'CONFIG_EXAMPLE_IPV4_ADDR="127.0.0.1"' >> sdkconfig.defaults
352+
- idf.py --preview set-target linux
353+
- idf.py build
354+
- timeout 5 ./build/udp_client.elf >test.log || true
355+
- grep "Message sent" test.log
356+
339357
test_eh_frame_parser:
340358
extends: .host_test_template
341359
script:

components/esp_netif/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
idf_build_get_property(target IDF_TARGET)
22

3-
if(${target} STREQUAL "linux")
4-
# Header only library for linux
5-
idf_component_register(INCLUDE_DIRS include)
6-
return()
7-
endif()
8-
93
set(srcs_lwip
104
"lwip/esp_netif_lwip.c"
115
"lwip/esp_netif_sntp.c"
@@ -23,6 +17,12 @@ set(srcs
2317
set(include_dirs "include")
2418
set(priv_include_dirs "private_include")
2519

20+
idf_build_get_property(target IDF_TARGET)
21+
if(${target} STREQUAL "linux")
22+
list(APPEND include_dirs
23+
"linux/stubs/include")
24+
endif()
25+
2626
if(CONFIG_PPP_SUPPORT)
2727
list(APPEND srcs_lwip lwip/esp_netif_lwip_ppp.c)
2828
endif()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
#include_next <endian.h>

components/esp_netif/lwip/esp_netif_lwip.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "esp_netif.h"
1717
#include "esp_netif_private.h"
1818
#include "esp_random.h"
19+
#include "esp_system.h"
1920

2021
#include "lwip/tcpip.h"
2122
#include "lwip/dhcp.h"

components/esp_netif/lwip/esp_netif_lwip_defaults.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#if defined(CONFIG_PPP_SUPPORT)
1111
#include "esp_netif_lwip_ppp.h"
1212
#endif
13+
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
1314

1415
#if CONFIG_ESP_NETIF_BRIDGE_EN
1516
#include "netif/bridgeif.h"
@@ -64,3 +65,5 @@ const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp = &s_n
6465
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_eth = &s_eth_netif_config;
6566
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_sta = &s_wifi_netif_config_sta;
6667
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_ap = &s_wifi_netif_config_ap;
68+
69+
#endif /*CONFIG_ESP_NETIF_TCPIP_LWIP*/

components/lwip/CMakeLists.txt

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
idf_build_get_property(target IDF_TARGET)
2+
if(NOT ${target} STREQUAL "linux")
3+
# ESP platform targets share the same port folder
4+
set(target esp32xx)
5+
endif()
6+
17
set(include_dirs
28
include
39
include/apps
410
include/apps/sntp
511
lwip/src/include
6-
port/esp32/include
7-
port/esp32/include/arch
12+
port/include
13+
port/freertos/include/
14+
port/${target}/include
15+
port/${target}/include/arch
816
)
917

1018
set(srcs
@@ -85,11 +93,11 @@ set(srcs
8593
"lwip/src/netif/ppp/upap.c"
8694
"lwip/src/netif/ppp/utils.c"
8795
"lwip/src/netif/ppp/vj.c"
88-
"port/esp32/hooks/tcp_isn_default.c"
89-
"port/esp32/hooks/lwip_default_hooks.c"
90-
"port/esp32/debug/lwip_debug.c"
91-
"port/esp32/freertos/sys_arch.c"
92-
"port/esp32/sockets_ext.c")
96+
"port/hooks/tcp_isn_default.c"
97+
"port/hooks/lwip_default_hooks.c"
98+
"port/debug/lwip_debug.c"
99+
"port/sockets_ext.c"
100+
"port/freertos/sys_arch.c")
93101

94102
if(CONFIG_LWIP_PPP_SUPPORT)
95103
list(APPEND srcs
@@ -125,10 +133,15 @@ if(CONFIG_LWIP_PPP_SUPPORT)
125133
"lwip/src/netif/ppp/polarssl/sha1.c")
126134
endif()
127135

128-
if(CONFIG_VFS_SUPPORT_IO)
129-
list(APPEND srcs "port/esp32/vfs_lwip.c")
130-
else()
131-
list(APPEND srcs "port/esp32/no_vfs_syscalls.c")
136+
if(NOT ${target} STREQUAL "linux")
137+
# Support for vfs and linker fragments only for target builds
138+
set(priv_requires vfs)
139+
set(linker_fragments linker.lf)
140+
if(CONFIG_VFS_SUPPORT_IO)
141+
list(APPEND srcs "port/${target}/vfs_lwip.c")
142+
else()
143+
list(APPEND srcs "port/${target}/no_vfs_syscalls.c")
144+
endif()
132145
endif()
133146

134147
if(CONFIG_LWIP_ICMP)
@@ -147,9 +160,9 @@ if(CONFIG_LWIP_DHCP_RESTORE_LAST_IP)
147160
endif()
148161

149162
idf_component_register(SRCS "${srcs}"
150-
INCLUDE_DIRS "${include_dirs}"
151-
LDFRAGMENTS linker.lf
152-
PRIV_REQUIRES vfs)
163+
INCLUDE_DIRS ${include_dirs}
164+
LDFRAGMENTS ${linker_fragments}
165+
PRIV_REQUIRES ${priv_requires})
153166

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

190203
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
204+
205+
if(${target} STREQUAL "linux")
206+
set(THREADS_PREFER_PTHREAD_FLAG ON)
207+
find_package(Threads REQUIRED)
208+
target_link_libraries(${COMPONENT_LIB} PRIVATE Threads::Threads)
209+
endif()

components/lwip/apps/dhcpserver/dhcpserver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
//#include "esp_common.h"
76
#include <stdlib.h>
87
#include <string.h>
8+
#include <assert.h>
99
#include "lwip/dhcp.h"
1010
#include "lwip/err.h"
1111
#include "lwip/pbuf.h"

components/lwip/apps/ping/ping.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#if PING_USE_SOCKETS
5656
#include "lwip/sockets.h"
5757
#include "lwip/inet.h"
58+
#include "esp_task.h"
5859
#include "ping/ping_sock.h"
5960
#endif /* PING_USE_SOCKETS */
6061

components/lwip/apps/ping/ping_sock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <stdlib.h>
88
#include <stdbool.h>
9+
#include <sys/time.h>
910
#include "freertos/FreeRTOS.h"
1011
#include "freertos/task.h"
1112
#include "lwip/opt.h"
@@ -231,7 +232,7 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
231232
/* set ICMP type and code field */
232233
ep->packet_hdr->code = 0;
233234
/* ping id should be unique, treat task handle as ping ID */
234-
ep->packet_hdr->id = ((uint32_t)ep->ping_task_hdl) & 0xFFFF;
235+
ep->packet_hdr->id = ((intptr_t)ep->ping_task_hdl) & 0xFFFF;
235236
/* fill the additional data buffer with some data */
236237
char *d = (char *)(ep->packet_hdr) + sizeof(struct icmp_echo_hdr);
237238
for (uint32_t i = 0; i < config->data_size; i++) {

components/lwip/apps/sntp/sntp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#undef SNTP_OPMODE_POLL
1616
#include "lwip/apps/sntp.h"
1717
#include "lwip/tcpip.h"
18+
#include "esp_macros.h"
1819

1920
static const char *TAG = "sntp";
2021

components/lwip/port/esp32/debug/lwip_debug.c renamed to components/lwip/port/debug/lwip_debug.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
146

157
#include "debug/lwip_debug.h"
168
#include "lwip/api.h"

components/lwip/port/esp32/include/arch/perf.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

components/lwip/port/esp32/include/arch/vfs_lwip.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

components/lwip/port/esp32/include/arpa/inet.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

components/lwip/port/esp32/include/debug/lwip_debug.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

components/lwip/port/esp32/include/netdb.h

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)