From adaa45eebeaf1a772ba57bca76ef9bd04ef7fb90 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Fri, 26 Mar 2021 10:04:37 +0800 Subject: [PATCH 01/13] [fix] the overflow problem of lwip rx thread mailbox. --- .../net/lwip-1.4.1/src/netif/ethernetif.c | 10 ++-- .../net/lwip-2.0.2/src/netif/ethernetif.c | 6 +-- .../net/lwip-2.1.2/src/netif/ethernetif.c | 52 +++++++++---------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index f2570f9e2b..4f01c407a8 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -156,16 +156,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); - + if(RT_TRUE == is_enabled) { dhcp_start((struct netif *)netif->user_data); } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } - + return ERR_OK; } #endif /* RT_LWIP_DHCP */ @@ -648,7 +648,7 @@ static void eth_rx_thread_entry(void* parameter) } /* receive all of buffer */ - while (1) + do { if(device->eth_rx == RT_NULL) break; @@ -664,7 +664,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - } + }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); } else { diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index b93acb1fcf..47146f0b3b 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -173,7 +173,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } return ERR_OK; } @@ -697,7 +697,7 @@ static void eth_rx_thread_entry(void* parameter) } /* receive all of buffer */ - while (1) + do { if(device->eth_rx == RT_NULL) break; @@ -713,7 +713,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - } + }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); } else { diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 52bd0fb7b6..df3f7cd6ce 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -163,16 +163,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); - + if(RT_TRUE == is_enabled) { dhcp_start((struct netif *)netif->user_data); } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } - + return ERR_OK; } #endif /* RT_LWIP_DHCP */ @@ -182,7 +182,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) extern int lwip_ping_recv(int s, int *ttl); extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size); -int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, +int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, uint32_t timeout, struct netdev_ping_resp *ping_resp) { int s, ttl, recv_len, result = 0; @@ -197,7 +197,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, struct addrinfo hint, *res = RT_NULL; struct sockaddr_in *h = RT_NULL; struct in_addr ina; - + RT_ASSERT(netif); RT_ASSERT(host); RT_ASSERT(ping_resp); @@ -216,7 +216,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, return -RT_ERROR; } rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); - + /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { @@ -284,7 +284,7 @@ const struct netdev_ops lwip_netdev_ops = lwip_netdev_set_addr_info, #ifdef RT_LWIP_DNS lwip_netdev_set_dns_server, -#else +#else NULL, #endif /* RT_LWIP_DNS */ @@ -323,7 +323,7 @@ static int netdev_add(struct netif *lwip_netif) { return -ERR_IF; } - + #ifdef SAL_USING_LWIP extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev); /* set the lwIP network interface device protocol family information */ @@ -332,7 +332,7 @@ static int netdev_add(struct netif *lwip_netif) rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN); result = netdev_register(netdev, name, (void *)lwip_netif); - + /* Update netdev info after registered */ netdev->flags = lwip_netif->flags; netdev->mtu = lwip_netif->mtu; @@ -375,7 +375,7 @@ static int netdev_flags_sync(struct netif *lwip_netif) { return -ERR_IF; } - + netdev->mtu = lwip_netif->mtu; netdev->flags |= lwip_netif->flags; @@ -438,7 +438,7 @@ static err_t eth_netif_device_init(struct netif *netif) /* copy device flags to netif flags */ netif->flags = (ethif->flags & 0xff); netif->mtu = ETHERNET_MTU; - + /* set output */ netif->output = etharp_output; @@ -530,7 +530,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ /* set linkoutput */ netif->linkoutput = ethernetif_linkoutput; - + /* get hardware MAC address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); @@ -550,7 +550,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ ipaddr.addr = inet_addr(RT_LWIP_IPADDR); gw.addr = inet_addr(RT_LWIP_GWADDR); netmask.addr = inet_addr(RT_LWIP_MSKADDR); -#else +#else IP4_ADDR(&ipaddr, 0, 0, 0, 0); IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&netmask, 0, 0, 0, 0); @@ -699,10 +699,10 @@ static void eth_rx_thread_entry(void* parameter) } /* receive all of buffer */ - while (1) + do { if(device->eth_rx == RT_NULL) break; - + p = device->eth_rx(&(device->parent)); if (p != RT_NULL) { @@ -715,7 +715,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - } + }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); } else { @@ -725,9 +725,9 @@ static void eth_rx_thread_entry(void* parameter) } #endif -/* this function does not need, - * use eth_system_device_init_private() - * call by lwip_system_init(). +/* this function does not need, + * use eth_system_device_init_private() + * call by lwip_system_init(). */ int eth_system_device_init(void) { @@ -874,22 +874,22 @@ void list_if(void) ip6_addr_t *addr; int addr_state; int i; - + addr = (ip6_addr_t *)&netif->ip6_addr[0]; addr_state = netif->ip6_addr_state[0]; - - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - + for(i=1; iip6_addr[i]; addr_state = netif->ip6_addr_state[i]; - - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); } - + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ From 154d73a4e76f954ad67d94455e6000a3d168fbf6 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Wed, 31 Mar 2021 13:37:19 +0800 Subject: [PATCH 02/13] [fix] iperf speed test have been stable. --- .../lwip-1.4.1/src/include/netif/ethernetif.h | 1 + .../net/lwip-1.4.1/src/netif/ethernetif.c | 17 ++++++++++++----- .../lwip-2.0.2/src/include/netif/ethernetif.h | 1 + .../net/lwip-2.0.2/src/netif/ethernetif.c | 17 ++++++++++++----- .../lwip-2.1.2/src/include/netif/ethernetif.h | 1 + .../net/lwip-2.1.2/src/netif/ethernetif.c | 17 ++++++++++++----- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 1c969e6e25..b3ca8e2ffb 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 4f01c407a8..30e7ee5f6d 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -550,10 +550,16 @@ rt_err_t eth_device_init(struct eth_device * dev, const char *name) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); - else - return ERR_OK; /* netif is not initialized yet, just return. */ + } + + return ERR_OK; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -646,9 +652,10 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + device->rx_notice = RT_FALSE; /* receive all of buffer */ - do + while(1) { if(device->eth_rx == RT_NULL) break; @@ -664,7 +671,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); + } } else { diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index 244bafdd1b..d294c36813 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 47146f0b3b..0146286b2a 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -599,10 +599,16 @@ void eth_device_deinit(struct eth_device *dev) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_ubase_t)dev); - else - return ERR_OK; /* netif is not initialized yet, just return. */ + } + + return ERR_OK; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -695,9 +701,10 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + device->rx_notice = RT_FALSE; /* receive all of buffer */ - do + while(1) { if(device->eth_rx == RT_NULL) break; @@ -713,7 +720,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); + } } else { diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index 244bafdd1b..d294c36813 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -27,6 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; + rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index df3f7cd6ce..e2f8512d53 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -601,10 +601,16 @@ void eth_device_deinit(struct eth_device *dev) rt_err_t eth_device_ready(struct eth_device* dev) { if (dev->netif) + { + if(dev->rx_notice == RT_FALSE) + { + dev->rx_notice = RT_TRUE; + return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); + } /* post message to Ethernet thread */ - return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); - else - return ERR_OK; /* netif is not initialized yet, just return. */ + } + + return ERR_OK; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -697,9 +703,10 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + device->rx_notice = RT_FALSE; /* receive all of buffer */ - do + while(1) { if(device->eth_rx == RT_NULL) break; @@ -715,7 +722,7 @@ static void eth_rx_thread_entry(void* parameter) } } else break; - }while(rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_NO) == RT_EOK); + } } else { From 4431c4796fb3e26fb66c012feb8bf47f3292b473 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Wed, 31 Mar 2021 14:59:12 +0800 Subject: [PATCH 03/13] [fix] remove the possible critical zone risk --- .../net/lwip-1.4.1/src/include/netif/ethernetif.h | 2 +- components/net/lwip-1.4.1/src/netif/ethernetif.c | 12 ++++++++++-- .../net/lwip-2.0.2/src/include/netif/ethernetif.h | 2 +- components/net/lwip-2.0.2/src/netif/ethernetif.c | 12 ++++++++++-- .../net/lwip-2.1.2/src/include/netif/ethernetif.h | 2 +- components/net/lwip-2.1.2/src/netif/ethernetif.c | 12 ++++++++++-- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index b3ca8e2ffb..650ad32eff 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -27,7 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; - rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 30e7ee5f6d..94d1f8d907 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -469,6 +469,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -556,10 +558,12 @@ rt_err_t eth_device_ready(struct eth_device* dev) dev->rx_notice = RT_TRUE; return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); } + else + return RT_EOK; /* post message to Ethernet thread */ } - - return ERR_OK; /* netif is not initialized yet, just return. */ + else + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -652,7 +656,11 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + + rt_enter_critical(); + /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; + rt_exit_critical(); /* receive all of buffer */ while(1) diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index d294c36813..1459e3241d 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -27,7 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; - rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 0146286b2a..28e3822cf7 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -511,6 +511,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -605,10 +607,12 @@ rt_err_t eth_device_ready(struct eth_device* dev) dev->rx_notice = RT_TRUE; return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); } + else + return RT_EOK; /* post message to Ethernet thread */ } - - return ERR_OK; /* netif is not initialized yet, just return. */ + else + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -701,7 +705,11 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + + rt_enter_critical(); + /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; + rt_exit_critical(); /* receive all of buffer */ while(1) diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index d294c36813..1459e3241d 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -27,7 +27,7 @@ struct eth_device rt_uint16_t flags; rt_uint8_t link_changed; rt_uint8_t link_status; - rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */ + rt_uint8_t rx_notice; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index e2f8512d53..09a84f61e5 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -514,6 +514,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ dev->flags = flags; /* link changed status of device */ dev->link_changed = 0x00; + /* avoid send the same mail to mailbox */ + dev->rx_notice = 0x00; dev->parent.type = RT_Device_Class_NetIf; /* register to RT-Thread device manager */ rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR); @@ -607,10 +609,12 @@ rt_err_t eth_device_ready(struct eth_device* dev) dev->rx_notice = RT_TRUE; return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev); } + else + return RT_EOK; /* post message to Ethernet thread */ } - - return ERR_OK; /* netif is not initialized yet, just return. */ + else + return -RT_ERROR; /* netif is not initialized yet, just return. */ } rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) @@ -703,7 +707,11 @@ static void eth_rx_thread_entry(void* parameter) else netifapi_netif_set_link_down(device->netif); } + + rt_enter_critical(); + /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; + rt_exit_critical(); /* receive all of buffer */ while(1) From 2b549d93c88bd0dd55429457f0da9eb199374b3a Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Tue, 6 Apr 2021 10:46:31 +0800 Subject: [PATCH 04/13] [fix] change from enter critical area into disable interrupt. --- components/net/lwip-1.4.1/src/netif/ethernetif.c | 5 +++-- components/net/lwip-2.0.2/src/netif/ethernetif.c | 5 +++-- components/net/lwip-2.1.2/src/netif/ethernetif.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 94d1f8d907..4565f5e528 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -638,6 +638,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t*)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -657,10 +658,10 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } - rt_enter_critical(); + level = rt_hw_interrupt_disable(); /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; - rt_exit_critical(); + rt_hw_interrupt_enable(level); /* receive all of buffer */ while(1) diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 28e3822cf7..1c0f3ca9b2 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -687,6 +687,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -706,10 +707,10 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } - rt_enter_critical(); + level = rt_hw_interrupt_disable(); /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; - rt_exit_critical(); + rt_hw_interrupt_enable(level); /* receive all of buffer */ while(1) diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 09a84f61e5..751a7bbdac 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -689,6 +689,7 @@ static void eth_rx_thread_entry(void* parameter) { if (rt_mb_recv(ð_rx_thread_mb, (rt_ubase_t *)&device, RT_WAITING_FOREVER) == RT_EOK) { + rt_base_t level; struct pbuf *p; /* check link status */ @@ -708,10 +709,10 @@ static void eth_rx_thread_entry(void* parameter) netifapi_netif_set_link_down(device->netif); } - rt_enter_critical(); + level = rt_hw_interrupt_disable(); /* 'rx_notice' will be modify in the interrupt or here */ device->rx_notice = RT_FALSE; - rt_exit_critical(); + rt_hw_interrupt_enable(level); /* receive all of buffer */ while(1) From 3db7a98a18e461236d418e0670de5d8905b11749 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Tue, 6 Apr 2021 11:41:14 +0800 Subject: [PATCH 05/13] [update] change the file encoding to UTF-8. --- .../lwip-1.4.1/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-1.4.1/src/netif/ethernetif.c | 40 +++++++++---------- .../lwip-2.0.2/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-2.0.2/src/netif/ethernetif.c | 32 +++++++-------- .../lwip-2.1.2/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-2.1.2/src/netif/ethernetif.c | 32 +++++++-------- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 650ad32eff..5d278a906e 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 4565f5e528..9654a0c255 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -59,9 +59,9 @@ #define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL) #ifndef RT_LWIP_ETHTHREAD_PRIORITY -#define RT_ETHERNETIF_THREAD_PREORITY 0x90 +#define RT_ETHERNETIF_THREAD_PREORITY 0x90 #else -#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY +#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY #endif #ifndef LWIP_NO_TX_THREAD @@ -70,8 +70,8 @@ */ struct eth_tx_msg { - struct netif *netif; - struct pbuf *buf; + struct netif *netif; + struct pbuf *buf; }; static struct rt_mailbox eth_tx_thread_mb; @@ -368,7 +368,7 @@ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) struct eth_tx_msg msg; struct eth_device* enetif; - RT_ASSERT(netif != RT_NULL); + RT_ASSERT(netif != RT_NULL); enetif = (struct eth_device*)netif->state; /* send a message to eth tx thread */ @@ -382,13 +382,13 @@ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) #else struct eth_device* enetif; - RT_ASSERT(netif != RT_NULL); + RT_ASSERT(netif != RT_NULL); enetif = (struct eth_device*)netif->state; - if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) - { - return ERR_IF; - } + if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) + { + return ERR_IF; + } #endif return ERR_OK; } @@ -481,16 +481,16 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ netif->name[1] = name[1]; /* set hw address to 6 */ - netif->hwaddr_len = 6; + netif->hwaddr_len = 6; /* maximum transfer unit */ - netif->mtu = ETHERNET_MTU; + netif->mtu = ETHERNET_MTU; /* get hardware MAC address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); /* set output */ - netif->output = etharp_output; - netif->linkoutput = ethernetif_linkoutput; + netif->output = etharp_output; + netif->linkoutput = ethernetif_linkoutput; #if LWIP_NETIF_HOSTNAME /* Initialize interface hostname */ @@ -587,12 +587,12 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) /* NOTE: please not use it in interrupt when no RxThread exist */ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) { - if (up == RT_TRUE) - netifapi_netif_set_link_up(dev->netif); - else - netifapi_netif_set_link_down(dev->netif); + if (up == RT_TRUE) + netifapi_netif_set_link_up(dev->netif); + else + netifapi_netif_set_link_down(dev->netif); - return RT_EOK; + return RT_EOK; } #endif @@ -666,7 +666,7 @@ static void eth_rx_thread_entry(void* parameter) /* receive all of buffer */ while(1) { - if(device->eth_rx == RT_NULL) break; + if(device->eth_rx == RT_NULL) break; p = device->eth_rx(&(device->parent)); if (p != RT_NULL) diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index 1459e3241d..66bb8c717e 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 1c0f3ca9b2..e723dcb920 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -884,27 +884,27 @@ void list_if(void) rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); #if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; + { + ip6_addr_t *addr; + int addr_state; + int i; - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; + addr = (ip6_addr_t *)&netif->ip6_addr[0]; + addr_state = netif->ip6_addr_state[0]; - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; + for(i=1; iip6_addr[i]; + addr_state = netif->ip6_addr_state[i]; - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + } - } + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ netif = netif->next; diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index 1459e3241d..66bb8c717e 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 751a7bbdac..2172bc978d 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -886,27 +886,27 @@ void list_if(void) rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); #if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; + { + ip6_addr_t *addr; + int addr_state; + int i; - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; + addr = (ip6_addr_t *)&netif->ip6_addr[0]; + addr_state = netif->ip6_addr_state[0]; - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; + for(i=1; iip6_addr[i]; + addr_state = netif->ip6_addr_state[i]; - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + } - } + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ netif = netif->next; From f083c67f22ac6413fd163b19da841687dbb5e17e Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Sat, 10 Apr 2021 18:07:09 +0800 Subject: [PATCH 06/13] [update] ignore format check for lwip files. --- .ignore_format.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.ignore_format.yml b/.ignore_format.yml index 4a0e8bbec7..5af47eedd4 100644 --- a/.ignore_format.yml +++ b/.ignore_format.yml @@ -1,4 +1,4 @@ -# files format check exclude path, please follow the instructions below to modify; +# files format check exclude path, please follow the instructions below to modify; # If you need to exclude an entire folder, add the folder path in dir_path; # If you need to exclude a file, add the path to the file in file_path. @@ -6,4 +6,7 @@ file_path: - bsp/allwinner_tina/libcpu/cpu.c dir_path: -- tools \ No newline at end of file +- tools +- components/net/lwip-1.4.1 +- components/net/lwip-2.0.2 +- components/net/lwip-2.1.2 \ No newline at end of file From 4e74279d272c3dea6f702258456462cba717d763 Mon Sep 17 00:00:00 2001 From: Jianjia Ma Date: Tue, 13 Apr 2021 18:04:59 +0100 Subject: [PATCH 07/13] Add more trys when switching data width Try a few times before switching to other data widths. The original strategy (simply wait for 20ms ) failed on STM32H743 with an MTFC4GACAJCN-4M (4GB EMMC) when switching data width. (unless the debugging info is enabled, which add more delays) With this EMMC, the fixed delay was set to 50ms for it to be able to work. Instead of a fixed delay, I think we better change to trying a few more times with smaller delays. --- components/drivers/sdio/mmc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/components/drivers/sdio/mmc.c b/components/drivers/sdio/mmc.c index 5aba3dba7a..e48a7ebcfb 100644 --- a/components/drivers/sdio/mmc.c +++ b/components/drivers/sdio/mmc.c @@ -300,7 +300,7 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) MMCSD_BUS_WIDTH_1 }; struct rt_mmcsd_host *host = card->host; - unsigned idx, bus_width = 0; + unsigned idx, trys, bus_width = 0; int err = 0; if (GET_BITS(card->resp_cid, 122, 4) < 4) @@ -335,10 +335,13 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) if (err) continue; - bus_width = bus_widths[idx]; - mmcsd_set_bus_width(host, bus_width); - mmcsd_delay_ms(20); //delay 10ms - err = mmc_compare_ext_csds(card, ext_csd, bus_width); + for(trys = 0; trys < 5; trys++){ + mmcsd_set_bus_width(host, bus_width); + mmcsd_delay_ms(10); + err = mmc_compare_ext_csds(card, ext_csd, bus_width); + if(!err) + break; + } if (!err) { err = bus_width; break; From 398718f0f9323d62a03a6ce441f9ff1cb36d61d1 Mon Sep 17 00:00:00 2001 From: Jianjia Ma Date: Tue, 13 Apr 2021 18:27:53 +0100 Subject: [PATCH 08/13] Update mmc.c --- components/drivers/sdio/mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/drivers/sdio/mmc.c b/components/drivers/sdio/mmc.c index e48a7ebcfb..d8f3a9e0a5 100644 --- a/components/drivers/sdio/mmc.c +++ b/components/drivers/sdio/mmc.c @@ -337,7 +337,7 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) for(trys = 0; trys < 5; trys++){ mmcsd_set_bus_width(host, bus_width); - mmcsd_delay_ms(10); + mmcsd_delay_ms(10); err = mmc_compare_ext_csds(card, ext_csd, bus_width); if(!err) break; From a6ac475df33d6e7ad09abff22879bb42962b4262 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 14 Apr 2021 01:34:28 +0800 Subject: [PATCH 09/13] [ymodem] Check the file path's legitimacy of 'sy' command --- components/utilities/ymodem/ry_sy.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/utilities/ymodem/ry_sy.c b/components/utilities/ymodem/ry_sy.c index a87f6949db..caad51d6cd 100644 --- a/components/utilities/ymodem/ry_sy.c +++ b/components/utilities/ymodem/ry_sy.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2019-12-09 Steven Liu the first version + * 2021-04-14 Meco Man Check the file path's legitimacy of 'sy' command */ #include @@ -219,6 +220,12 @@ static rt_err_t sy(uint8_t argc, char **argv) const char *file_path; rt_device_t dev; + if (argc < 2) + { + rt_kprintf("invalid file path.\n"); + return -RT_ERROR; + } + if (argc > 2) dev = rt_device_find(argv[2]); else From ad9c4ea15b40258de874130c7a6c704e3f870856 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Thu, 15 Apr 2021 12:43:56 +0800 Subject: [PATCH 10/13] [restore] Restore format --- .../lwip-1.4.1/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-1.4.1/src/netif/ethernetif.c | 40 +++++++++---------- .../lwip-2.0.2/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-2.0.2/src/netif/ethernetif.c | 32 +++++++-------- .../lwip-2.1.2/src/include/netif/ethernetif.h | 10 ++--- .../net/lwip-2.1.2/src/netif/ethernetif.c | 32 +++++++-------- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 5d278a906e..650ad32eff 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 9654a0c255..4565f5e528 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -59,9 +59,9 @@ #define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL) #ifndef RT_LWIP_ETHTHREAD_PRIORITY -#define RT_ETHERNETIF_THREAD_PREORITY 0x90 +#define RT_ETHERNETIF_THREAD_PREORITY 0x90 #else -#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY +#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY #endif #ifndef LWIP_NO_TX_THREAD @@ -70,8 +70,8 @@ */ struct eth_tx_msg { - struct netif *netif; - struct pbuf *buf; + struct netif *netif; + struct pbuf *buf; }; static struct rt_mailbox eth_tx_thread_mb; @@ -368,7 +368,7 @@ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) struct eth_tx_msg msg; struct eth_device* enetif; - RT_ASSERT(netif != RT_NULL); + RT_ASSERT(netif != RT_NULL); enetif = (struct eth_device*)netif->state; /* send a message to eth tx thread */ @@ -382,13 +382,13 @@ static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p) #else struct eth_device* enetif; - RT_ASSERT(netif != RT_NULL); + RT_ASSERT(netif != RT_NULL); enetif = (struct eth_device*)netif->state; - if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) - { - return ERR_IF; - } + if (enetif->eth_tx(&(enetif->parent), p) != RT_EOK) + { + return ERR_IF; + } #endif return ERR_OK; } @@ -481,16 +481,16 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ netif->name[1] = name[1]; /* set hw address to 6 */ - netif->hwaddr_len = 6; + netif->hwaddr_len = 6; /* maximum transfer unit */ - netif->mtu = ETHERNET_MTU; + netif->mtu = ETHERNET_MTU; /* get hardware MAC address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); /* set output */ - netif->output = etharp_output; - netif->linkoutput = ethernetif_linkoutput; + netif->output = etharp_output; + netif->linkoutput = ethernetif_linkoutput; #if LWIP_NETIF_HOSTNAME /* Initialize interface hostname */ @@ -587,12 +587,12 @@ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) /* NOTE: please not use it in interrupt when no RxThread exist */ rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up) { - if (up == RT_TRUE) - netifapi_netif_set_link_up(dev->netif); - else - netifapi_netif_set_link_down(dev->netif); + if (up == RT_TRUE) + netifapi_netif_set_link_up(dev->netif); + else + netifapi_netif_set_link_down(dev->netif); - return RT_EOK; + return RT_EOK; } #endif @@ -666,7 +666,7 @@ static void eth_rx_thread_entry(void* parameter) /* receive all of buffer */ while(1) { - if(device->eth_rx == RT_NULL) break; + if(device->eth_rx == RT_NULL) break; p = device->eth_rx(&(device->parent)); if (p != RT_NULL) diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h index 66bb8c717e..1459e3241d 100644 --- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index e723dcb920..1c0f3ca9b2 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -884,27 +884,27 @@ void list_if(void) rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); #if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; + { + ip6_addr_t *addr; + int addr_state; + int i; - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; + addr = (ip6_addr_t *)&netif->ip6_addr[0]; + addr_state = netif->ip6_addr_state[0]; - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; + for(i=1; iip6_addr[i]; + addr_state = netif->ip6_addr_state[i]; - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + } - } + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ netif = netif->next; diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h index 66bb8c717e..1459e3241d 100644 --- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h +++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h @@ -4,16 +4,16 @@ #include "lwip/netif.h" #include -#define NIOCTL_GADDR 0x01 +#define NIOCTL_GADDR 0x01 #ifndef RT_LWIP_ETH_MTU -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 #else -#define ETHERNET_MTU RT_LWIP_ETH_MTU +#define ETHERNET_MTU RT_LWIP_ETH_MTU #endif /* eth flag with auto_linkup or phy_linkup */ -#define ETHIF_LINK_AUTOUP 0x0000 -#define ETHIF_LINK_PHYUP 0x0100 +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 struct eth_device { diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 2172bc978d..751a7bbdac 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -886,27 +886,27 @@ void list_if(void) rt_kprintf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); rt_kprintf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); #if LWIP_IPV6 - { - ip6_addr_t *addr; - int addr_state; - int i; + { + ip6_addr_t *addr; + int addr_state; + int i; - addr = (ip6_addr_t *)&netif->ip6_addr[0]; - addr_state = netif->ip6_addr_state[0]; + addr = (ip6_addr_t *)&netif->ip6_addr[0]; + addr_state = netif->ip6_addr_state[0]; - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - for(i=1; iip6_addr[i]; - addr_state = netif->ip6_addr_state[i]; + for(i=1; iip6_addr[i]; + addr_state = netif->ip6_addr_state[i]; - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), - addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - } + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); + } - } + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ netif = netif->next; From 962a97b683f46d701419533f79955470fa1ab431 Mon Sep 17 00:00:00 2001 From: liuxianliang Date: Thu, 15 Apr 2021 12:50:54 +0800 Subject: [PATCH 11/13] [restore] Restore format --- .../net/lwip-2.1.2/src/netif/ethernetif.c | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 751a7bbdac..81dd792f29 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -163,16 +163,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); - + if(RT_TRUE == is_enabled) { dhcp_start((struct netif *)netif->user_data); } else { - dhcp_stop((struct netif *)netif->user_data); + dhcp_stop((struct netif *)netif->user_data); } - + return ERR_OK; } #endif /* RT_LWIP_DHCP */ @@ -182,7 +182,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) extern int lwip_ping_recv(int s, int *ttl); extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size); -int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, +int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, uint32_t timeout, struct netdev_ping_resp *ping_resp) { int s, ttl, recv_len, result = 0; @@ -197,7 +197,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, struct addrinfo hint, *res = RT_NULL; struct sockaddr_in *h = RT_NULL; struct in_addr ina; - + RT_ASSERT(netif); RT_ASSERT(host); RT_ASSERT(ping_resp); @@ -216,7 +216,7 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, return -RT_ERROR; } rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); - + /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { @@ -284,7 +284,7 @@ const struct netdev_ops lwip_netdev_ops = lwip_netdev_set_addr_info, #ifdef RT_LWIP_DNS lwip_netdev_set_dns_server, -#else +#else NULL, #endif /* RT_LWIP_DNS */ @@ -323,7 +323,7 @@ static int netdev_add(struct netif *lwip_netif) { return -ERR_IF; } - + #ifdef SAL_USING_LWIP extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev); /* set the lwIP network interface device protocol family information */ @@ -332,7 +332,7 @@ static int netdev_add(struct netif *lwip_netif) rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN); result = netdev_register(netdev, name, (void *)lwip_netif); - + /* Update netdev info after registered */ netdev->flags = lwip_netif->flags; netdev->mtu = lwip_netif->mtu; @@ -375,7 +375,7 @@ static int netdev_flags_sync(struct netif *lwip_netif) { return -ERR_IF; } - + netdev->mtu = lwip_netif->mtu; netdev->flags |= lwip_netif->flags; @@ -438,7 +438,7 @@ static err_t eth_netif_device_init(struct netif *netif) /* copy device flags to netif flags */ netif->flags = (ethif->flags & 0xff); netif->mtu = ETHERNET_MTU; - + /* set output */ netif->output = etharp_output; @@ -532,7 +532,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ /* set linkoutput */ netif->linkoutput = ethernetif_linkoutput; - + /* get hardware MAC address */ rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr); @@ -552,7 +552,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_ ipaddr.addr = inet_addr(RT_LWIP_IPADDR); gw.addr = inet_addr(RT_LWIP_GWADDR); netmask.addr = inet_addr(RT_LWIP_MSKADDR); -#else +#else IP4_ADDR(&ipaddr, 0, 0, 0, 0); IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&netmask, 0, 0, 0, 0); @@ -715,10 +715,10 @@ static void eth_rx_thread_entry(void* parameter) rt_hw_interrupt_enable(level); /* receive all of buffer */ - while(1) + while (1) { if(device->eth_rx == RT_NULL) break; - + p = device->eth_rx(&(device->parent)); if (p != RT_NULL) { @@ -741,9 +741,9 @@ static void eth_rx_thread_entry(void* parameter) } #endif -/* this function does not need, - * use eth_system_device_init_private() - * call by lwip_system_init(). +/* this function does not need, + * use eth_system_device_init_private() + * call by lwip_system_init(). */ int eth_system_device_init(void) { @@ -890,22 +890,22 @@ void list_if(void) ip6_addr_t *addr; int addr_state; int i; - + addr = (ip6_addr_t *)&netif->ip6_addr[0]; addr_state = netif->ip6_addr_state[0]; - - rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), + + rt_kprintf("\nipv6 link-local: %s state:%02X %s\n", ip6addr_ntoa(addr), addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); - + for(i=1; iip6_addr[i]; addr_state = netif->ip6_addr_state[i]; - - rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), + + rt_kprintf("ipv6[%d] address: %s state:%02X %s\n", i, ip6addr_ntoa(addr), addr_state, ip6_addr_isvalid(addr_state)?"VALID":"INVALID"); } - + } rt_kprintf("\r\n"); #endif /* LWIP_IPV6 */ From 9be6445890180717be08de4bada1935335c3b62b Mon Sep 17 00:00:00 2001 From: thread-liu Date: Mon, 19 Apr 2021 09:43:56 +0800 Subject: [PATCH 12/13] [update] cmake.py, add c++ support and libpath. --- tools/cmake.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tools/cmake.py b/tools/cmake.py index 5e17643a14..876c3985fe 100644 --- a/tools/cmake.py +++ b/tools/cmake.py @@ -15,8 +15,9 @@ def GenerateCFiles(env,project): """ info = utils.ProjectInfo(env) - + CC = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC) + CXX = os.path.join(rtconfig.EXEC_PATH, rtconfig.CXX) AS = os.path.join(rtconfig.EXEC_PATH, rtconfig.AS) AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR) LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK) @@ -28,20 +29,24 @@ def GenerateCFiles(env,project): if cm_file: cm_file.write("CMAKE_MINIMUM_REQUIRED(VERSION 3.10)\n\n") - cm_file.write("PROJECT(rtthread C ASM)\n") cm_file.write("SET(CMAKE_SYSTEM_NAME Generic)\n") cm_file.write("#SET(CMAKE_VERBOSE_MAKEFILE ON)\n\n") cm_file.write("SET(CMAKE_C_COMPILER \""+ CC + "\")\n") + cm_file.write("SET(CMAKE_CXX_COMPILER \""+ CXX + "\")\n") cm_file.write("SET(CMAKE_ASM_COMPILER \""+ AS + "\")\n") cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n") cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n") - cm_file.write("SET(CMAKE_C_FLAGS \""+ rtconfig.CFLAGS + "\")\n") + cm_file.write("SET(CMAKE_C_FLAGS \""+ rtconfig.CFLAGS + " -nostdlib\")\n") + cm_file.write("SET(CMAKE_CXX_FLAGS \""+ rtconfig.CXXFLAGS + "\")\n") cm_file.write("SET(CMAKE_ASM_FLAGS \""+ rtconfig.AFLAGS + "\")\n") cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub('-T(\s*)', '-T ${CMAKE_SOURCE_DIR}/',rtconfig.LFLAGS) + "\")\n\n") - + + cm_file.write("SET(CMAKE_CXX_STANDARD 14)\n") + cm_file.write("PROJECT(rtthread C CXX ASM)\n") + cm_file.write("INCLUDE_DIRECTORIES(\n") for i in info['CPPPATH']: cm_file.write( "\t" +i + "\n") @@ -58,6 +63,20 @@ def GenerateCFiles(env,project): for f in group['src']: cm_file.write( "\t"+os.path.normpath(f.rfile().abspath)+"\n" ) cm_file.write(")\n\n") + + cm_file.write("LINK_DIRECTORIES(\n") + for group in project: + if 'LIBPATH' in group.keys(): + for f in group['LIBPATH']: + cm_file.write( "\t"+ f + "\n" ) + cm_file.write(")\n\n") + + cm_file.write("LINK_LIBRARIES(\n") + for group in project: + if 'LIBS' in group.keys(): + for f in group['LIBS']: + cm_file.write( "\t"+ "{}\n".format(f)) + cm_file.write(")\n\n") cm_file.write("ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${PROJECT_SOURCES})\n") cm_file.write("ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD \nCOMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)") From f5d636626c9309e57449d06c83009dae3d0455e7 Mon Sep 17 00:00:00 2001 From: thread-liu Date: Mon, 19 Apr 2021 18:28:10 +0800 Subject: [PATCH 13/13] [update] cmake.py, delete extra code. --- tools/cmake.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cmake.py b/tools/cmake.py index 876c3985fe..645bdbb229 100644 --- a/tools/cmake.py +++ b/tools/cmake.py @@ -39,7 +39,7 @@ def GenerateCFiles(env,project): cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n") - cm_file.write("SET(CMAKE_C_FLAGS \""+ rtconfig.CFLAGS + " -nostdlib\")\n") + cm_file.write("SET(CMAKE_C_FLAGS \""+ rtconfig.CFLAGS + "\")\n") cm_file.write("SET(CMAKE_CXX_FLAGS \""+ rtconfig.CXXFLAGS + "\")\n") cm_file.write("SET(CMAKE_ASM_FLAGS \""+ rtconfig.AFLAGS + "\")\n") cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub('-T(\s*)', '-T ${CMAKE_SOURCE_DIR}/',rtconfig.LFLAGS) + "\")\n\n")