Skip to content

Commit 5fa6a9e

Browse files
committed
esp8266: Add 1_SDK as a build option
1 parent bb087f2 commit 5fa6a9e

File tree

13 files changed

+269
-15
lines changed

13 files changed

+269
-15
lines changed

mos.yml

+21
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ conds:
3737
TCP_MSL: 5000
3838
TCP_WND: 2920
3939

40+
- when: build_vars.MGOS_ESP8266_LWIP == "1_SDK"
41+
apply:
42+
version: 1.4.1
43+
includes:
44+
- src/esp8266/sdk_lwip/include
45+
sources:
46+
- src/esp8266
47+
- src/esp8266/sdk_lwip/src/api
48+
- src/esp8266/sdk_lwip/src/core
49+
- src/esp8266/sdk_lwip/src/core/ipv4
50+
- src/esp8266/sdk_lwip/src/netif
51+
- src/esp8266/sdk_lwip/src/app/dhcpserver.c
52+
cdefs:
53+
EBUF_LWIP: 1
54+
LWIP_OPEN_SRC: 1
55+
PBUF_RSV_FOR_WLAN: 1
56+
LWIP_RAND: os_random
57+
TCP_MSS: 1460
58+
TCP_MSL: 5000
59+
TCP_WND: 2920
60+
4061
# TODO(rojer): When mos supports more elaborate conds, this can be deduped.
4162
- when: mos.platform == "stm32"
4263
apply:

src/esp8266/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# cs_lwip
2+
3+
Cesanta-patched LWIP, historically derived from early code drops by Espressif
4+
5+
# sdk_lwip
6+
7+
Imported from [upstream](https://github.com/espressif/ESP8266_NONOS_SDK/tree/158bb7a53f16cfff21b35fb4ec66fa15261f5a4a):
8+
9+
```
10+
rsync -av --delete ESP8266_NONOS_SDK/third_party/include/{arch,lwip*,netif} sdk_lwip/include/
11+
rsync -av --delete ESP8266_NONOS_SDK/third_party/lwip/{api,app,core,netif} sdk_lwip/src/
12+
```
13+
14+
Applied patch to fix build errors with mos compiler settings:
15+
16+
```
17+
patch -p 1 < sdk_lwip.patch
18+
```

src/esp8266/sdk_lwip.patch

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
--- ./sdk_lwip/include/lwipopts.h.orig 2021-03-07 13:23:09.029912491 +0000
2+
+++ ./sdk_lwip/include/lwipopts.h 2021-03-07 13:25:56.138097825 +0000
3+
@@ -790,7 +790,6 @@
4+
#define LWIP_MDNS 1
5+
#endif
6+
/*
7+
-/*
8+
----------------------------------
9+
---------- DNS options -----------
10+
----------------------------------
11+
--- ./sdk_lwip/include/lwip/ip_addr.h.orig 2021-03-07 13:23:09.025912487 +0000
12+
+++ ./sdk_lwip/include/lwip/ip_addr.h 2021-03-07 13:24:19.973991159 +0000
13+
@@ -210,7 +210,7 @@
14+
#define ip_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
15+
16+
#define ip_addr_debug_print(debug, ipaddr) \
17+
- LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
18+
+ LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, \
19+
ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
20+
ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
21+
ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \
22+
--- ./sdk_lwip/include/lwip/igmp.h.orig 2021-03-07 13:23:09.025912487 +0000
23+
+++ ./sdk_lwip/include/lwip/igmp.h 2021-03-07 13:33:02.535402600 +0000
24+
@@ -97,7 +97,9 @@
25+
err_t igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
26+
void igmp_tmr(void)ICACHE_FLASH_ATTR;
27+
int r_rand(void);
28+
+#ifndef LWIP_RAND
29+
#define LWIP_RAND() r_rand()
30+
+#endif
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
--- ./sdk_lwip/src/core/dhcp.c.orig 2021-03-07 13:23:09.029912491 +0000
35+
+++ ./sdk_lwip/src/core/dhcp.c 2021-03-07 13:57:04.167952143 +0000
36+
@@ -189,6 +189,7 @@
37+
}
38+
vendor_class_len = len;
39+
memcpy(vendor_class_buf, str, len);
40+
+ return ERR_OK;
41+
}
42+
43+
/**
44+
@@ -342,7 +343,7 @@
45+
46+
if (vendor_class_buf != NULL) {
47+
const char *p = (const char*)vendor_class_buf;
48+
- u8_t namelen = (u8_t)os_strlen(p);
49+
+ //u8_t namelen = (u8_t)os_strlen(p);
50+
if (vendor_class_len > 0) {
51+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
52+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
53+
@@ -951,7 +952,7 @@
54+
55+
if (vendor_class_buf != NULL) {
56+
const char *p = (const char*)vendor_class_buf;
57+
- u8_t namelen = (u8_t)os_strlen(p);
58+
+ //u8_t namelen = (u8_t)os_strlen(p);
59+
if (vendor_class_len > 0) {
60+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
61+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
62+
@@ -1162,7 +1163,7 @@
63+
64+
if (vendor_class_buf != NULL) {
65+
const char *p = (const char*)vendor_class_buf;
66+
- u8_t namelen = (u8_t)os_strlen(p);
67+
+ //u8_t namelen = (u8_t)os_strlen(p);
68+
if (vendor_class_len > 0) {
69+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
70+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
71+
@@ -1237,7 +1238,7 @@
72+
73+
if (vendor_class_buf != NULL) {
74+
const char *p = (const char*)vendor_class_buf;
75+
- u8_t namelen = (u8_t)os_strlen(p);
76+
+ //u8_t namelen = (u8_t)os_strlen(p);
77+
if (vendor_class_len > 0) {
78+
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
79+
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
80+
--- ./sdk_lwip/src/core/init.c.orig 2021-03-07 13:23:09.029912491 +0000
81+
+++ ./sdk_lwip/src/core/init.c 2021-03-07 13:58:17.432103852 +0000
82+
@@ -260,7 +260,7 @@
83+
lwip_init(void)
84+
{
85+
MEMP_NUM_TCP_PCB = 5;
86+
- TCP_WND = (4 * TCP_MSS);
87+
+ //TCP_WND = (4 * TCP_MSS);
88+
TCP_MAXRTX = 12;
89+
TCP_SYNMAXRTX = 6;
90+
91+
--- ./sdk_lwip/src/core/dns.c.orig 2021-03-07 13:23:09.029912491 +0000
92+
+++ ./sdk_lwip/src/core/dns.c 2021-03-07 13:45:28.746318109 +0000
93+
@@ -450,7 +450,7 @@
94+
* better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
95+
* was not found in the cached dns_table.
96+
*/
97+
-static u32_t ICACHE_FLASH_ATTR
98+
+u32_t ICACHE_FLASH_ATTR
99+
dns_lookup(const char *name)
100+
{
101+
u8_t i;
102+
--- ./sdk_lwip/src/core/ipv4/igmp.c.orig 2021-03-07 13:23:09.029912491 +0000
103+
+++ ./sdk_lwip/src/core/ipv4/igmp.c 2021-03-07 14:04:05.956800908 +0000
104+
@@ -103,7 +103,7 @@
105+
#ifdef DYC_IGMP_DEBUG
106+
#define IGMP_LOG os_printf
107+
#else
108+
-#define IGMP_LOG //os_printf
109+
+#define IGMP_LOG(a,b,c)
110+
#endif
111+
112+
/*
113+
@@ -150,7 +150,7 @@
114+
static err_t igmp_remove_group(struct igmp_group *group)ICACHE_FLASH_ATTR;
115+
static void igmp_timeout( struct igmp_group *group)ICACHE_FLASH_ATTR;
116+
static void igmp_start_timer(struct igmp_group *group, u8_t max_time)ICACHE_FLASH_ATTR;
117+
-static void igmp_stop_timer(struct igmp_group *group)ICACHE_FLASH_ATTR;
118+
+//static void igmp_stop_timer(struct igmp_group *group)ICACHE_FLASH_ATTR;
119+
static void igmp_delaying_member(struct igmp_group *group, u8_t maxresp)ICACHE_FLASH_ATTR;
120+
static err_t igmp_ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, struct netif *netif)ICACHE_FLASH_ATTR;
121+
static void igmp_send(struct igmp_group *group, u8_t type)ICACHE_FLASH_ATTR;
122+
@@ -739,7 +739,7 @@
123+
*
124+
* @param group the igmp_group for which to stop the timer
125+
*/
126+
-static void
127+
+void
128+
igmp_stop_timer(struct igmp_group *group)
129+
{
130+
group->timer = 0;
131+
--- ./sdk_lwip/src/core/sntp.c.orig 2021-03-07 13:23:09.033912496 +0000
132+
+++ ./sdk_lwip/src/core/sntp.c 2021-03-07 14:00:07.824328524 +0000
133+
@@ -272,7 +272,9 @@
134+
};
135+
static struct sntp_server sntp_servers[SNTP_MAX_SERVERS];
136+
137+
+#if SNTP_GET_SERVERS_FROM_DHCP
138+
static u8_t sntp_set_servers_from_dhcp;
139+
+#endif /* SNTP_GET_SERVERS_FROM_DHCP */
140+
#if SNTP_SUPPORT_MULTIPLE_SERVERS
141+
/** The currently used server (initialized to 0) */
142+
static u8_t sntp_current_server;
143+
@@ -345,7 +347,6 @@
144+
{
145+
long days, rem;
146+
time_t lcltime;
147+
- int i;
148+
int y;
149+
int yleap;
150+
const int *ip;
151+
--- ./sdk_lwip/src/core/timers.c.orig 2021-03-07 13:23:09.033912496 +0000
152+
+++ ./sdk_lwip/src/core/timers.c 2021-03-07 14:00:42.408398071 +0000
153+
@@ -115,7 +115,7 @@
154+
* @param arg unused argument
155+
*/
156+
157+
-static void ICACHE_FLASH_ATTR
158+
+void ICACHE_FLASH_ATTR
159+
tcp_timer_coarse(void *arg)
160+
{
161+
LWIP_UNUSED_ARG(arg);
162+
--- ./sdk_lwip/src/app/dhcpserver.c.orig 2021-03-07 13:23:09.029912491 +0000
163+
+++ ./sdk_lwip/src/app/dhcpserver.c 2021-03-07 14:08:51.113351807 +0000
164+
@@ -37,7 +37,7 @@
165+
void wifi_softap_dhcps_client_leave(u8 *bssid, struct ip_addr *ip,bool force);
166+
uint32 wifi_softap_dhcps_client_update(u8 *bssid, struct ip_addr *ip);
167+
struct netif * eagle_lwip_getif(uint8 index);
168+
-int wifi_softap_set_station_info(char *info, struct ip_addr *addr);
169+
+int wifi_softap_set_station_info(unsigned char *info, struct ip_addr *addr);
170+
171+
/******************************************************************************
172+
* FunctionName : node_insert_to_list
173+
@@ -331,6 +331,8 @@
174+
SendOffer_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
175+
#if DHCPS_DEBUG
176+
os_printf("dhcps: send_offer>>udp_sendto result %x\n",SendOffer_err_t);
177+
+#else
178+
+ (void) SendOffer_err_t;
179+
#endif
180+
if(p->ref != 0){
181+
#if DHCPS_DEBUG
182+
@@ -391,6 +393,8 @@
183+
SendNak_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
184+
#if DHCPS_DEBUG
185+
os_printf("dhcps: send_nak>>udp_sendto result %x\n",SendNak_err_t);
186+
+#else
187+
+ (void) SendNak_err_t;
188+
#endif
189+
if(p->ref != 0){
190+
#if DHCPS_DEBUG
191+
@@ -452,6 +456,8 @@
192+
SendAck_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
193+
#if DHCPS_DEBUG
194+
os_printf("dhcps: send_ack>>udp_sendto result %x\n",SendAck_err_t);
195+
+#else
196+
+ (void) SendAck_err_t;
197+
#endif
198+
199+
if(p->ref != 0){
200+
@@ -942,7 +948,6 @@
201+
bool ICACHE_FLASH_ATTR wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg)
202+
{
203+
bool offer_flag = true;
204+
- uint8 option = 0;
205+
if (optarg == NULL && wifi_softap_dhcps_status() == false)
206+
return false;
207+

src/esp8266/sdk_lwip/include/lwip/igmp.h

+2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ err_t igmp_joingroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
9797
err_t igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
9898
void igmp_tmr(void)ICACHE_FLASH_ATTR;
9999
int r_rand(void);
100+
#ifndef LWIP_RAND
100101
#define LWIP_RAND() r_rand()
102+
#endif
101103
#ifdef __cplusplus
102104
}
103105
#endif

src/esp8266/sdk_lwip/include/lwip/ip_addr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ u8_t ip4_addr_netmask_valid(u32_t netmask)ICACHE_FLASH_ATTR;
210210
#define ip_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
211211

212212
#define ip_addr_debug_print(debug, ipaddr) \
213-
LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
213+
LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, \
214214
ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
215215
ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
216216
ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \

src/esp8266/sdk_lwip/include/lwipopts.h

-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,6 @@
789789
#ifndef LWIP_MDNS
790790
#define LWIP_MDNS 1
791791
#endif
792-
/*
793792
/*
794793
----------------------------------
795794
---------- DNS options -----------

src/esp8266/sdk_lwip/src/app/dhcpserver.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ uint32 dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute
3737
void wifi_softap_dhcps_client_leave(u8 *bssid, struct ip_addr *ip,bool force);
3838
uint32 wifi_softap_dhcps_client_update(u8 *bssid, struct ip_addr *ip);
3939
struct netif * eagle_lwip_getif(uint8 index);
40-
int wifi_softap_set_station_info(char *info, struct ip_addr *addr);
40+
int wifi_softap_set_station_info(unsigned char *info, struct ip_addr *addr);
4141

4242
/******************************************************************************
4343
* FunctionName : node_insert_to_list
@@ -331,6 +331,8 @@ static void ICACHE_FLASH_ATTR send_offer(struct dhcps_msg *m)
331331
SendOffer_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
332332
#if DHCPS_DEBUG
333333
os_printf("dhcps: send_offer>>udp_sendto result %x\n",SendOffer_err_t);
334+
#else
335+
(void) SendOffer_err_t;
334336
#endif
335337
if(p->ref != 0){
336338
#if DHCPS_DEBUG
@@ -391,6 +393,8 @@ static void ICACHE_FLASH_ATTR send_nak(struct dhcps_msg *m)
391393
SendNak_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
392394
#if DHCPS_DEBUG
393395
os_printf("dhcps: send_nak>>udp_sendto result %x\n",SendNak_err_t);
396+
#else
397+
(void) SendNak_err_t;
394398
#endif
395399
if(p->ref != 0){
396400
#if DHCPS_DEBUG
@@ -452,6 +456,8 @@ static void ICACHE_FLASH_ATTR send_ack(struct dhcps_msg *m)
452456
SendAck_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
453457
#if DHCPS_DEBUG
454458
os_printf("dhcps: send_ack>>udp_sendto result %x\n",SendAck_err_t);
459+
#else
460+
(void) SendAck_err_t;
455461
#endif
456462

457463
if(p->ref != 0){
@@ -942,7 +948,6 @@ void ICACHE_FLASH_ATTR dhcps_coarse_tmr(void)
942948
bool ICACHE_FLASH_ATTR wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg)
943949
{
944950
bool offer_flag = true;
945-
uint8 option = 0;
946951
if (optarg == NULL && wifi_softap_dhcps_status() == false)
947952
return false;
948953

src/esp8266/sdk_lwip/src/core/dhcp.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ err_t dhcp_set_vendor_class_identifier(uint8_t len, char *str) {
189189
}
190190
vendor_class_len = len;
191191
memcpy(vendor_class_buf, str, len);
192+
return ERR_OK;
192193
}
193194

194195
/**
@@ -342,7 +343,7 @@ dhcp_select(struct netif *netif)
342343

343344
if (vendor_class_buf != NULL) {
344345
const char *p = (const char*)vendor_class_buf;
345-
u8_t namelen = (u8_t)os_strlen(p);
346+
//u8_t namelen = (u8_t)os_strlen(p);
346347
if (vendor_class_len > 0) {
347348
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
348349
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
@@ -951,7 +952,7 @@ dhcp_discover(struct netif *netif)
951952

952953
if (vendor_class_buf != NULL) {
953954
const char *p = (const char*)vendor_class_buf;
954-
u8_t namelen = (u8_t)os_strlen(p);
955+
//u8_t namelen = (u8_t)os_strlen(p);
955956
if (vendor_class_len > 0) {
956957
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
957958
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
@@ -1162,7 +1163,7 @@ dhcp_renew(struct netif *netif)
11621163

11631164
if (vendor_class_buf != NULL) {
11641165
const char *p = (const char*)vendor_class_buf;
1165-
u8_t namelen = (u8_t)os_strlen(p);
1166+
//u8_t namelen = (u8_t)os_strlen(p);
11661167
if (vendor_class_len > 0) {
11671168
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
11681169
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
@@ -1237,7 +1238,7 @@ dhcp_rebind(struct netif *netif)
12371238

12381239
if (vendor_class_buf != NULL) {
12391240
const char *p = (const char*)vendor_class_buf;
1240-
u8_t namelen = (u8_t)os_strlen(p);
1241+
//u8_t namelen = (u8_t)os_strlen(p);
12411242
if (vendor_class_len > 0) {
12421243
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
12431244
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);

src/esp8266/sdk_lwip/src/core/dns.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr)
450450
* better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
451451
* was not found in the cached dns_table.
452452
*/
453-
static u32_t ICACHE_FLASH_ATTR
453+
u32_t ICACHE_FLASH_ATTR
454454
dns_lookup(const char *name)
455455
{
456456
u8_t i;

src/esp8266/sdk_lwip/src/core/init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void
260260
lwip_init(void)
261261
{
262262
MEMP_NUM_TCP_PCB = 5;
263-
TCP_WND = (4 * TCP_MSS);
263+
//TCP_WND = (4 * TCP_MSS);
264264
TCP_MAXRTX = 12;
265265
TCP_SYNMAXRTX = 6;
266266

0 commit comments

Comments
 (0)