Skip to content

Commit

Permalink
esp8266: Add 1_SDK as a build option
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Mar 7, 2021
1 parent bb087f2 commit 5fa6a9e
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 15 deletions.
21 changes: 21 additions & 0 deletions mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ conds:
TCP_MSL: 5000
TCP_WND: 2920

- when: build_vars.MGOS_ESP8266_LWIP == "1_SDK"
apply:
version: 1.4.1
includes:
- src/esp8266/sdk_lwip/include
sources:
- src/esp8266
- src/esp8266/sdk_lwip/src/api
- src/esp8266/sdk_lwip/src/core
- src/esp8266/sdk_lwip/src/core/ipv4
- src/esp8266/sdk_lwip/src/netif
- src/esp8266/sdk_lwip/src/app/dhcpserver.c
cdefs:
EBUF_LWIP: 1
LWIP_OPEN_SRC: 1
PBUF_RSV_FOR_WLAN: 1
LWIP_RAND: os_random
TCP_MSS: 1460
TCP_MSL: 5000
TCP_WND: 2920

# TODO(rojer): When mos supports more elaborate conds, this can be deduped.
- when: mos.platform == "stm32"
apply:
Expand Down
18 changes: 18 additions & 0 deletions src/esp8266/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# cs_lwip

Cesanta-patched LWIP, historically derived from early code drops by Espressif

# sdk_lwip

Imported from [upstream](https://github.com/espressif/ESP8266_NONOS_SDK/tree/158bb7a53f16cfff21b35fb4ec66fa15261f5a4a):

```
rsync -av --delete ESP8266_NONOS_SDK/third_party/include/{arch,lwip*,netif} sdk_lwip/include/
rsync -av --delete ESP8266_NONOS_SDK/third_party/lwip/{api,app,core,netif} sdk_lwip/src/
```

Applied patch to fix build errors with mos compiler settings:

```
patch -p 1 < sdk_lwip.patch
```
207 changes: 207 additions & 0 deletions src/esp8266/sdk_lwip.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
--- ./sdk_lwip/include/lwipopts.h.orig 2021-03-07 13:23:09.029912491 +0000
+++ ./sdk_lwip/include/lwipopts.h 2021-03-07 13:25:56.138097825 +0000
@@ -790,7 +790,6 @@
#define LWIP_MDNS 1
#endif
/*
-/*
----------------------------------
---------- DNS options -----------
----------------------------------
--- ./sdk_lwip/include/lwip/ip_addr.h.orig 2021-03-07 13:23:09.025912487 +0000
+++ ./sdk_lwip/include/lwip/ip_addr.h 2021-03-07 13:24:19.973991159 +0000
@@ -210,7 +210,7 @@
#define ip_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))

#define ip_addr_debug_print(debug, ipaddr) \
- LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
+ LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, \
ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \
--- ./sdk_lwip/include/lwip/igmp.h.orig 2021-03-07 13:23:09.025912487 +0000
+++ ./sdk_lwip/include/lwip/igmp.h 2021-03-07 13:33:02.535402600 +0000
@@ -97,7 +97,9 @@
err_t igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
void igmp_tmr(void)ICACHE_FLASH_ATTR;
int r_rand(void);
+#ifndef LWIP_RAND
#define LWIP_RAND() r_rand()
+#endif
#ifdef __cplusplus
}
#endif
--- ./sdk_lwip/src/core/dhcp.c.orig 2021-03-07 13:23:09.029912491 +0000
+++ ./sdk_lwip/src/core/dhcp.c 2021-03-07 13:57:04.167952143 +0000
@@ -189,6 +189,7 @@
}
vendor_class_len = len;
memcpy(vendor_class_buf, str, len);
+ return ERR_OK;
}

/**
@@ -342,7 +343,7 @@

if (vendor_class_buf != NULL) {
const char *p = (const char*)vendor_class_buf;
- u8_t namelen = (u8_t)os_strlen(p);
+ //u8_t namelen = (u8_t)os_strlen(p);
if (vendor_class_len > 0) {
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
@@ -951,7 +952,7 @@

if (vendor_class_buf != NULL) {
const char *p = (const char*)vendor_class_buf;
- u8_t namelen = (u8_t)os_strlen(p);
+ //u8_t namelen = (u8_t)os_strlen(p);
if (vendor_class_len > 0) {
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
@@ -1162,7 +1163,7 @@

if (vendor_class_buf != NULL) {
const char *p = (const char*)vendor_class_buf;
- u8_t namelen = (u8_t)os_strlen(p);
+ //u8_t namelen = (u8_t)os_strlen(p);
if (vendor_class_len > 0) {
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
@@ -1237,7 +1238,7 @@

if (vendor_class_buf != NULL) {
const char *p = (const char*)vendor_class_buf;
- u8_t namelen = (u8_t)os_strlen(p);
+ //u8_t namelen = (u8_t)os_strlen(p);
if (vendor_class_len > 0) {
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
--- ./sdk_lwip/src/core/init.c.orig 2021-03-07 13:23:09.029912491 +0000
+++ ./sdk_lwip/src/core/init.c 2021-03-07 13:58:17.432103852 +0000
@@ -260,7 +260,7 @@
lwip_init(void)
{
MEMP_NUM_TCP_PCB = 5;
- TCP_WND = (4 * TCP_MSS);
+ //TCP_WND = (4 * TCP_MSS);
TCP_MAXRTX = 12;
TCP_SYNMAXRTX = 6;

--- ./sdk_lwip/src/core/dns.c.orig 2021-03-07 13:23:09.029912491 +0000
+++ ./sdk_lwip/src/core/dns.c 2021-03-07 13:45:28.746318109 +0000
@@ -450,7 +450,7 @@
* better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
* was not found in the cached dns_table.
*/
-static u32_t ICACHE_FLASH_ATTR
+u32_t ICACHE_FLASH_ATTR
dns_lookup(const char *name)
{
u8_t i;
--- ./sdk_lwip/src/core/ipv4/igmp.c.orig 2021-03-07 13:23:09.029912491 +0000
+++ ./sdk_lwip/src/core/ipv4/igmp.c 2021-03-07 14:04:05.956800908 +0000
@@ -103,7 +103,7 @@
#ifdef DYC_IGMP_DEBUG
#define IGMP_LOG os_printf
#else
-#define IGMP_LOG //os_printf
+#define IGMP_LOG(a,b,c)
#endif

/*
@@ -150,7 +150,7 @@
static err_t igmp_remove_group(struct igmp_group *group)ICACHE_FLASH_ATTR;
static void igmp_timeout( struct igmp_group *group)ICACHE_FLASH_ATTR;
static void igmp_start_timer(struct igmp_group *group, u8_t max_time)ICACHE_FLASH_ATTR;
-static void igmp_stop_timer(struct igmp_group *group)ICACHE_FLASH_ATTR;
+//static void igmp_stop_timer(struct igmp_group *group)ICACHE_FLASH_ATTR;
static void igmp_delaying_member(struct igmp_group *group, u8_t maxresp)ICACHE_FLASH_ATTR;
static err_t igmp_ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, struct netif *netif)ICACHE_FLASH_ATTR;
static void igmp_send(struct igmp_group *group, u8_t type)ICACHE_FLASH_ATTR;
@@ -739,7 +739,7 @@
*
* @param group the igmp_group for which to stop the timer
*/
-static void
+void
igmp_stop_timer(struct igmp_group *group)
{
group->timer = 0;
--- ./sdk_lwip/src/core/sntp.c.orig 2021-03-07 13:23:09.033912496 +0000
+++ ./sdk_lwip/src/core/sntp.c 2021-03-07 14:00:07.824328524 +0000
@@ -272,7 +272,9 @@
};
static struct sntp_server sntp_servers[SNTP_MAX_SERVERS];

+#if SNTP_GET_SERVERS_FROM_DHCP
static u8_t sntp_set_servers_from_dhcp;
+#endif /* SNTP_GET_SERVERS_FROM_DHCP */
#if SNTP_SUPPORT_MULTIPLE_SERVERS
/** The currently used server (initialized to 0) */
static u8_t sntp_current_server;
@@ -345,7 +347,6 @@
{
long days, rem;
time_t lcltime;
- int i;
int y;
int yleap;
const int *ip;
--- ./sdk_lwip/src/core/timers.c.orig 2021-03-07 13:23:09.033912496 +0000
+++ ./sdk_lwip/src/core/timers.c 2021-03-07 14:00:42.408398071 +0000
@@ -115,7 +115,7 @@
* @param arg unused argument
*/

-static void ICACHE_FLASH_ATTR
+void ICACHE_FLASH_ATTR
tcp_timer_coarse(void *arg)
{
LWIP_UNUSED_ARG(arg);
--- ./sdk_lwip/src/app/dhcpserver.c.orig 2021-03-07 13:23:09.029912491 +0000
+++ ./sdk_lwip/src/app/dhcpserver.c 2021-03-07 14:08:51.113351807 +0000
@@ -37,7 +37,7 @@
void wifi_softap_dhcps_client_leave(u8 *bssid, struct ip_addr *ip,bool force);
uint32 wifi_softap_dhcps_client_update(u8 *bssid, struct ip_addr *ip);
struct netif * eagle_lwip_getif(uint8 index);
-int wifi_softap_set_station_info(char *info, struct ip_addr *addr);
+int wifi_softap_set_station_info(unsigned char *info, struct ip_addr *addr);

/******************************************************************************
* FunctionName : node_insert_to_list
@@ -331,6 +331,8 @@
SendOffer_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
#if DHCPS_DEBUG
os_printf("dhcps: send_offer>>udp_sendto result %x\n",SendOffer_err_t);
+#else
+ (void) SendOffer_err_t;
#endif
if(p->ref != 0){
#if DHCPS_DEBUG
@@ -391,6 +393,8 @@
SendNak_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
#if DHCPS_DEBUG
os_printf("dhcps: send_nak>>udp_sendto result %x\n",SendNak_err_t);
+#else
+ (void) SendNak_err_t;
#endif
if(p->ref != 0){
#if DHCPS_DEBUG
@@ -452,6 +456,8 @@
SendAck_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
#if DHCPS_DEBUG
os_printf("dhcps: send_ack>>udp_sendto result %x\n",SendAck_err_t);
+#else
+ (void) SendAck_err_t;
#endif

if(p->ref != 0){
@@ -942,7 +948,6 @@
bool ICACHE_FLASH_ATTR wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg)
{
bool offer_flag = true;
- uint8 option = 0;
if (optarg == NULL && wifi_softap_dhcps_status() == false)
return false;

2 changes: 2 additions & 0 deletions src/esp8266/sdk_lwip/include/lwip/igmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ err_t igmp_joingroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
err_t igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
void igmp_tmr(void)ICACHE_FLASH_ATTR;
int r_rand(void);
#ifndef LWIP_RAND
#define LWIP_RAND() r_rand()
#endif
#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/esp8266/sdk_lwip/include/lwip/ip_addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ u8_t ip4_addr_netmask_valid(u32_t netmask)ICACHE_FLASH_ATTR;
#define ip_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))

#define ip_addr_debug_print(debug, ipaddr) \
LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, \
ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \
Expand Down
1 change: 0 additions & 1 deletion src/esp8266/sdk_lwip/include/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@
#ifndef LWIP_MDNS
#define LWIP_MDNS 1
#endif
/*
/*
----------------------------------
---------- DNS options -----------
Expand Down
9 changes: 7 additions & 2 deletions src/esp8266/sdk_lwip/src/app/dhcpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ uint32 dhcps_lease_time = DHCPS_LEASE_TIME_DEF; //minute
void wifi_softap_dhcps_client_leave(u8 *bssid, struct ip_addr *ip,bool force);
uint32 wifi_softap_dhcps_client_update(u8 *bssid, struct ip_addr *ip);
struct netif * eagle_lwip_getif(uint8 index);
int wifi_softap_set_station_info(char *info, struct ip_addr *addr);
int wifi_softap_set_station_info(unsigned char *info, struct ip_addr *addr);

/******************************************************************************
* FunctionName : node_insert_to_list
Expand Down Expand Up @@ -331,6 +331,8 @@ static void ICACHE_FLASH_ATTR send_offer(struct dhcps_msg *m)
SendOffer_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
#if DHCPS_DEBUG
os_printf("dhcps: send_offer>>udp_sendto result %x\n",SendOffer_err_t);
#else
(void) SendOffer_err_t;
#endif
if(p->ref != 0){
#if DHCPS_DEBUG
Expand Down Expand Up @@ -391,6 +393,8 @@ static void ICACHE_FLASH_ATTR send_nak(struct dhcps_msg *m)
SendNak_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
#if DHCPS_DEBUG
os_printf("dhcps: send_nak>>udp_sendto result %x\n",SendNak_err_t);
#else
(void) SendNak_err_t;
#endif
if(p->ref != 0){
#if DHCPS_DEBUG
Expand Down Expand Up @@ -452,6 +456,8 @@ static void ICACHE_FLASH_ATTR send_ack(struct dhcps_msg *m)
SendAck_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
#if DHCPS_DEBUG
os_printf("dhcps: send_ack>>udp_sendto result %x\n",SendAck_err_t);
#else
(void) SendAck_err_t;
#endif

if(p->ref != 0){
Expand Down Expand Up @@ -942,7 +948,6 @@ void ICACHE_FLASH_ATTR dhcps_coarse_tmr(void)
bool ICACHE_FLASH_ATTR wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg)
{
bool offer_flag = true;
uint8 option = 0;
if (optarg == NULL && wifi_softap_dhcps_status() == false)
return false;

Expand Down
9 changes: 5 additions & 4 deletions src/esp8266/sdk_lwip/src/core/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ err_t dhcp_set_vendor_class_identifier(uint8_t len, char *str) {
}
vendor_class_len = len;
memcpy(vendor_class_buf, str, len);
return ERR_OK;
}

/**
Expand Down Expand Up @@ -342,7 +343,7 @@ dhcp_select(struct netif *netif)

if (vendor_class_buf != NULL) {
const char *p = (const char*)vendor_class_buf;
u8_t namelen = (u8_t)os_strlen(p);
//u8_t namelen = (u8_t)os_strlen(p);
if (vendor_class_len > 0) {
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
Expand Down Expand Up @@ -951,7 +952,7 @@ dhcp_discover(struct netif *netif)

if (vendor_class_buf != NULL) {
const char *p = (const char*)vendor_class_buf;
u8_t namelen = (u8_t)os_strlen(p);
//u8_t namelen = (u8_t)os_strlen(p);
if (vendor_class_len > 0) {
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
Expand Down Expand Up @@ -1162,7 +1163,7 @@ dhcp_renew(struct netif *netif)

if (vendor_class_buf != NULL) {
const char *p = (const char*)vendor_class_buf;
u8_t namelen = (u8_t)os_strlen(p);
//u8_t namelen = (u8_t)os_strlen(p);
if (vendor_class_len > 0) {
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
Expand Down Expand Up @@ -1237,7 +1238,7 @@ dhcp_rebind(struct netif *netif)

if (vendor_class_buf != NULL) {
const char *p = (const char*)vendor_class_buf;
u8_t namelen = (u8_t)os_strlen(p);
//u8_t namelen = (u8_t)os_strlen(p);
if (vendor_class_len > 0) {
LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len < 255);
dhcp_option(dhcp, DHCP_OPTION_US, vendor_class_len);
Expand Down
2 changes: 1 addition & 1 deletion src/esp8266/sdk_lwip/src/core/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ dns_local_addhost(const char *hostname, const ip_addr_t *addr)
* better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
* was not found in the cached dns_table.
*/
static u32_t ICACHE_FLASH_ATTR
u32_t ICACHE_FLASH_ATTR
dns_lookup(const char *name)
{
u8_t i;
Expand Down
2 changes: 1 addition & 1 deletion src/esp8266/sdk_lwip/src/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void
lwip_init(void)
{
MEMP_NUM_TCP_PCB = 5;
TCP_WND = (4 * TCP_MSS);
//TCP_WND = (4 * TCP_MSS);
TCP_MAXRTX = 12;
TCP_SYNMAXRTX = 6;

Expand Down
Loading

0 comments on commit 5fa6a9e

Please sign in to comment.