net/lwip: add lwip library for the network stack
Subsystems (2)
v6 cover net/lwip: add lwip library for the network stack
changelog:
v6: - fixed review comments for v5 (thanks Ilias and Simon).
- lwip is not under /net, so prior applying patch following
commit is needed to create lwIP merge into U-Boot:
git subtree add --prefix net/lwip/lwip-external https://git.savannah.nongnu.org/git/lwip.git master --squash
v5: - fixed Iliases comments and split big patch on the small
ones.
You also need to issue command:
git subtree add --prefix lib/lwip/lwip-external https://git.savannah.nongnu.org/git/lwip.git master --squash Which will create merge commit of lwip library placing sources
into lib/lwip/lwip-external directory. I do not send it a patch
due to 1. merges are not friendly with git format-patch and 2.
the source code of lwip is 78kb.
v4: - tested with tests/py/ did some minor fixes (out of tree
build, variables set after downloads).
- accounted review comments for documentation.
- implemented dns command
- corrected wget command to not use serverip variable and use just
url string.
v3: - use lwip commands for ping,tftp,wget,dhcp if this patch
applied. Drop CONFIG_LIB_LWIP_REPLACE_<COMMAND> option.
- docs: use rst variant and drop references to RFC.
Maxim Uvarov (14):
net/lwip: add doc/develop/net_lwip.rst
net/lwip: integrate lwIP library
net/lwip: implement dns cmd
net/lwip: implement dhcp cmd
net/lwip: implement tftp cmd
net/lwip: implement wget cmd
net/lwip: implement ping cmd
net/lwip: add lwIP configuration
net/lwip: implement lwIP port to U-Boot
net/lwip: update .gitignore with lwIP
net/lwip: connection between cmd and lwip apps
net/lwip: replace original net commands with lwip
net/lwip: split net.h to net.h, arp.h and eth.h
net/lwip: drop old net/wget
boot/bootmeth_efi.c | 18 +- boot/bootmeth_pxe.c | 21 +- cmd/Makefile | 1 + cmd/net-lwip.c | 306 ++++++++++++++++++ cmd/net.c | 86 +---- cmd/pxe.c | 19 +- doc/develop/index.rst | 1 + doc/develop/net_lwip.rst | 64 ++++ include/net.h | 197 +----------- include/net/arp.h | 7 + include/net/eth.h | 190 +++++++++++ include/net/lwip.h | 66 ++++ include/net/ulwip.h | 68 ++++ include/net/wget.h | 22 -- net/Kconfig | 3 + net/Makefile | 2 +- net/eth-uclass.c | 8 + net/lwip/.gitignore | 8 + net/lwip/Kconfig | 60 ++++ net/lwip/Makefile | 72 +++++ net/lwip/apps/dhcp/lwip-dhcp.c | 51 +++ net/lwip/apps/dns/lwip-dns.c | 46 +++ net/lwip/apps/http/Makefile | 13 + net/lwip/apps/http/lwip-wget.c | 131 ++++++++ net/lwip/apps/ping/Makefile | 11 + net/lwip/apps/ping/lwip_ping.c | 37 +++ net/lwip/apps/ping/lwip_ping.h | 15 + net/lwip/apps/ping/ping.h | 19 ++ net/lwip/apps/tftp/Makefile | 16 + net/lwip/apps/tftp/lwip-tftp.c | 129 ++++++++ net/lwip/lwipopts.h | 195 ++++++++++++ net/lwip/port/if.c | 260 +++++++++++++++ net/lwip/port/include/arch/cc.h | 39 +++ net/lwip/port/include/arch/sys_arch.h | 56 ++++ net/lwip/port/include/limits.h | 0 net/lwip/port/sys-arch.c | 20 ++ net/net.c | 26 +- net/wget.c | 440 -------------------------- 38 files changed, 1966 insertions(+), 757 deletions(-) create mode 100644 cmd/net-lwip.c create mode 100644 doc/develop/net_lwip.rst create mode 100644 include/net/arp.h create mode 100644 include/net/eth.h create mode 100644 include/net/lwip.h create mode 100644 include/net/ulwip.h delete mode 100644 include/net/wget.h create mode 100644 net/lwip/.gitignore create mode 100644 net/lwip/Kconfig create mode 100644 net/lwip/Makefile create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.c create mode 100644 net/lwip/apps/dns/lwip-dns.c create mode 100644 net/lwip/apps/http/Makefile create mode 100644 net/lwip/apps/http/lwip-wget.c create mode 100644 net/lwip/apps/ping/Makefile create mode 100644 net/lwip/apps/ping/lwip_ping.c create mode 100644 net/lwip/apps/ping/lwip_ping.h create mode 100644 net/lwip/apps/ping/ping.h create mode 100644 net/lwip/apps/tftp/Makefile create mode 100644 net/lwip/apps/tftp/lwip-tftp.c create mode 100644 net/lwip/lwipopts.h create mode 100644 net/lwip/port/if.c create mode 100644 net/lwip/port/include/arch/cc.h create mode 100644 net/lwip/port/include/arch/sys_arch.h create mode 100644 net/lwip/port/include/limits.h create mode 100644 net/lwip/port/sys-arch.c delete mode 100644 net/wget.c
Signature · 1 line
2.30.2
PATCH v6 1/14 net/lwip: add doc/develop/net_lwip.rst
Add initial documentation of lwIP network IP stack integration to the U-Boot (net_lwip.rst).
--- doc/develop/index.rst | 1 + doc/develop/net_lwip.rst | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 doc/develop/net_lwip.rst
doc/develop/index.rst +1 -0
@@ -48,6 +48,7 @@ Implementation spl falcon uefi/index + net_lwip vbe version
doc/develop/net_lwip.rst new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCHv6 01/14] net/lwip: add doc/develop/net_lwip.rst
Quoted 58 lines · Maxim Uvarov
Add initial documentation of lwIP network IP stack integration to the U-Boot (
net_lwip.rst).Signed-off-by Maxim Uvarov <[email protected]>Reviewed-by Simon Glass <[email protected]>--- doc/develop/index.rst | 1 + doc/develop/net_lwip.rst | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 doc/develop/net_lwip.rstdoc/develop/index.rst +1
-0@@ -48,6 +48,7 @@ Implementation spl falcon uefi/index + net_lwip vbe versiondoc/develop/net_lwip.rst new file +29
-0@@ -0,0 +1,64 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +LWIP IP stack intergation for U-Boot +==================================== + +Intro +----- + +LWIP is a library implementing network protocols, which is commonly used +on embedded devices. + +https://savannah.nongnu.org/projects/lwip/ + +LwIP license: +LwIP is licensed under a BSD-style license: http://lwip.wikia.com/wiki/License. + +Main features include: + +* Protocols: IP, IPv6, ICMP, ND, MLD, UDP, TCP, IGMP, ARP, PPPoS, PPPoE + +* DHCP client, DNS client (incl. mDNS hostname resolver), + AutoIP/APIPA (Zeroconf), SNMP agent (v1, v2c, v3, private MIB support + & MIB compiler) + +* APIs: specialized APIs for enhanced performance, optional Berkeley-alike + socket API + +* Extended features: IP forwarding over multiple network interfaces, TCP + congestion control, RTT estimation and fast recovery/fast retransmit
doc/develop/net_lwip.rst line 39
Quoted 10 lines
doc/develop/net_lwip.rst new file +10
-0+ +* Addon applications: HTTP(S) server, SNTP client, SMTP(S) client, ping, + NetBIOS nameserver, mDNS responder, MQTT client, TFTP server + +U-Boot implementation details +----------------------------- + +1. In general we can build lwIP as a library and link it against U-Boot or + compile it in the U-Boot tree in the same way as other U-Boot files. There + are few reasons why I selected the second variant: LwIP is very customizable
You can skip the 'I' here, it's not a personal project. Something along the lines of 'the second variant was chosen ...' would work
doc/develop/net_lwip.rst line 51
Quoted 12 lines
doc/develop/net_lwip.rst new file +12
-0+ with defines for features, memory size, types of allocation, some internal + types and platform specific code. It turned out easier to enable/disable + debug which is also done with defines, and is needed periodically. + +2. lwIP has 2 APIs - raw mode and sequential (as lwIP names it, or socket API + as we name it in Linux). +For now only raw API is supported. + +In raw IP mode a callback function for RX path is registered and will be called +when packet is passed to the IP stack and is ready for the application. + +Example is unmodified working ping example from lwip sources which registered
One example is the unmodified etc
doc/develop/net_lwip.rst line 64
Quoted 13 lines
doc/develop/net_lwip.rst new file +13
-0+the callback: + +.. code-block:: c + + ping_pcb = raw_new(IP_PROTO_ICMP); + raw_recv(ping_pcb, ping_recv, NULL); <- ping_recv is app callback. + raw_bind(ping_pcb, IP_ADDR_ANY) + +3. Input and output + +RX packet path is injected to U-Boot eth_rx() polling loop and TX patch is in +eth_send() accordingly. So we do not touch any drivers code and just eat +packets when they are ready.
'That way we can leave the driver code unmodified and consume packets once they are ready'
Thanks
/Ilias
Quoted 3 lines
Signature · 1 line
2.30.2
PATCH v6 2/14 net/lwip: integrate lwIP library
In reply to Maxim UvarovDefine Makefile and Kconfig to build lwIP inside the U-Boot. We compile lwIP the same as the main code, plus we can do optimization for size at compile time with disabling not needed debug asserts, or not used protocols. So we can tune lwIP configuration specially for U-Boot environments.
--- net/Kconfig | 3 +++ net/Makefile | 1 + net/lwip/Kconfig | 60 ++++++++++++++++++++++++++++++++++++++++++ net/lwip/Makefile | 66 +++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 ++++++++++++++ 5 files changed, 150 insertions(+) create mode 100644 net/lwip/Kconfig create mode 100644 net/lwip/Makefile
net/Kconfig +3 -0
@@ -5,9 +5,12 @@ menuconfig NET bool "Networking support" default y + imply LWIP if NET +source net/lwip/Kconfig + config ARP_TIMEOUT int "Milliseconds before trying ARP again" default 5000
net/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_PROT_UDP) += udp.o obj-$(CONFIG_PROT_TCP) += tcp.o obj-$(CONFIG_CMD_WGET) += wget.o +obj-$(CONFIG_LWIP) += lwip/ # Disable this warning as it is triggered by: # sprintf(buf, index ? "foo%d" : "foo", index)
net/lwip/Kconfig new file +60 -0
60 lines not on this page · raw message
net/lwip/Makefile new file +66 -0
66 lines not on this page · raw message
net/net.c +20 -0
@@ -125,6 +125,7 @@#endif #include "dhcpv6.h" #include "net_rand.h" +#include <net/ulwip.h> /** BOOTP EXTENTIONS **/
@@ -452,7 +453,11 @@ int net_loop(enum proto_t protocol)#endif bootstage_mark_name (BOOTSTAGE_ID_ETH_START ,"eth_start" ); +#if defined(CONFIG_LWIP ) + if (!ulwip_enabled() || !ulwip_in_loop()) +#endif net_init (); +if (eth_is_on_demand_init ()) {eth_halt ();eth_set_current ();
@@ -649,6 +654,16 @@ restart:*/ eth_rx (); +if (IS_ENABLED (CONFIG_LWIP ) &&ulwip_enabled ()) { +net_set_state (NETLOOP_CONTINUE ); +if (!ulwip_in_loop ()) { +if (ulwip_app_get_err ()) +net_set_state (NETLOOP_FAIL ); +else +net_set_state (NETLOOP_SUCCESS ); + goto done; + } + }/* * Abort if ctrl-c was pressed. */
@@ -1213,6 +1228,11 @@ void net_process_received_packet(uchar *in_packet, int len)if (len <ETHER_HDR_SIZE )return ; +if (IS_ENABLED (CONFIG_LWIP ) &&ulwip_enabled ()) { +ulwip_poll (); +return ; + } +#if defined(CONFIG_API ) || defined(CONFIG_EFI_LOADER )if (push_packet) { (*push_packet)(in_packet, len);
Signature · 1 line
2.30.2
Re: [PATCHv6 02/14] net/lwip: integrate lwIP library
Quoted 6 lines · Maxim Uvarov
Define
MakefileandKconfigto build lwIP inside the U-Boot. We compile lwIP the same as the main code, plus we can do optimization for size at compile time with disabling not needed debug asserts, or not used protocols. So we can tune lwIP configuration specially for U-Boot environments.+menu "LWIP"
[...]
net/lwip/Kconfig line 6
Quoted 5 lines
net/lwip/Kconfig new file +5
-0+config LWIP + bool "Support LWIP library" + help + Enable the lwIP library code with + all dependencies (cmd commands implemented with lwIP
cmd commands -> commands
net/lwip/Kconfig line 13
Quoted 8 lines
net/lwip/Kconfig new file +7
-0+ library. This option is automatically enabled if CONFIG_NET=y. + lwIP library (https://git.savannah.nongnu.org/git/lwip.git) provides + network stack and application code for U-Boot cmd commands. + Please see doc/develop/net_lwip.rst for more details. + +menu "LWIP options" +
[...]
Thanks
/Ilias
PATCH v6 3/14 net/lwip: implement dns cmd
In reply to Maxim UvarovImplement function for dns command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP.
--- include/net/lwip.h | 17 +++++++++++++ net/lwip/Makefile | 2 ++ net/lwip/apps/dns/lwip-dns.c | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 include/net/lwip.h create mode 100644 net/lwip/apps/dns/lwip-dns.c
include/net/lwip.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +int do_lwip_dns (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]); + +/* +* This function creates the DNS request to resolve a domain host name. Function +* can return immediately if previous request was cached or it might require +* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve +* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the polling loop +* Other value < 0, if error +*/ +int ulwip_dns (char *name,char *varname);
net/lwip/Makefile +2 -0
@@ -64,3 +64,5 @@ obj-$(CONFIG_NET) += $(LWIPDIR)/netif/ethernet.o obj-$(CONFIG_NET) += port/if.o obj-$(CONFIG_NET) += port/sys-arch.o + +obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o
net/lwip/apps/dns/lwip-dns.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCHv6 03/14] net/lwip: implement dns cmd
Quoted 3 lines · Maxim Uvarov
Implement function for dns command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP.
What's compatibility code?
I think something along the lines of
'U-Boot recently got support for an alternative network stack using LWIP. Replace XXXX command with the LWIP variant while keeping the output and error messages identical"
include/net/lwip.h line 7
Quoted 6 lines
include/net/lwip.h new file +6
-0+ +int do_lwip_dns (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]); + +/* +* This function creates the DNS request to resolve a domain host name. Function
You need the name of the function as well. Please have a look at how the rest of the code is documented.
include/net/lwip.h line 11
Quoted 4 lines
include/net/lwip.h new file +4
-0+* can return immediately if previous request was cached or it might require +* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve
@name: etc
Quoted 16 lines
include/net/lwip.h new file +6
-0+* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the polling loop +* Other value < 0, if error +*/ +int ulwip_dns (char *name,char *varname);net/lwip/Makefile +7
-1--- a/net/lwip/Makefile + */ + +#include <common.h> +#include <command.h> +#include <console.h> + +#include <lwip/dns.h>
net/lwip/Makefile
Quoted 10 lines
net/lwip/Makefile +10
-0+#include <lwip/ip_addr.h> + +#include <net/ulwip.h> + +static void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg) +{ + char *varname = (char *)callback_arg; + + if (varname) + env_set(varname, ip4addr_ntoa(ipaddr));
Why do we have to set the varname to the resolved address? Is this something the dns command already does?
Quoted 28 lines
net/lwip/Makefile +25
-0+ + log_info("resolved %s to %s\n", name, ip4addr_ntoa(ipaddr)); + ulwip_exit(0); +} + +int ulwip_dns(char *name, char *varname) +{ + int err; + ip_addr_t ipaddr; /* not used */ + ip_addr_t dns1; + ip_addr_t dns2; + + ipaddr_aton(env_get("dnsip"), &dns1); + ipaddr_aton(env_get("dnsip2"), &dns2); + + dns_init(); + dns_setserver(0, &dns1); + dns_setserver(1, &dns2); + + err = dns_gethostbyname(name, &ipaddr, dns_found_cb, varname); + if (err == ERR_OK) + dns_found_cb(name, &ipaddr, varname); + + return err; +}Signature · 1 line
2.30.2
Thanks
/Ilias
Re: [PATCHv6 03/14] net/lwip: implement dns cmd
Quoted 5 lines · Ilias Apalodimas
Quoted 3 lines · Maxim Uvarov
Implement function for dns command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP.
Quoted 7 lines
What's compatibility code?
I think something along the lines of'U-Boot recently got support for an alternative network stack using LWIP. Replace XXXX command with the LWIP variant while keeping the output and error messages identical"
ok, that message is a good one. By 'compatibility code' I meant code to merge lwip applications and other U-Boot code.
So in general all net/lwip/apps/{dns,ping,wget} and etc. These applications do not have U-Boot headers and can be compiled with
any other lwIP port. I.e. for example, you can take the linux userland port with a tap device and directly compile these apps, run and debug. This might be named lwIP apps code.
And code which does lwIP init, calls application initialization, then goes to net polling loop - I named here 'a compatibility code'. Might be not the base naming, but that was an idea.
Quoted 51 lines
include/net/lwip.h
Quoted 7 lines
include/net/lwip.h new file +6
-0+ +int do_lwip_dns (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]); + +/* +* This function creates the DNS request to resolve a domain host name. Function
You need the name of the function as well. Please have a look at how the rest of the code is documented.
Quoted 1 line
+* can return immediately if previous request was cached or it might
require
include/net/lwip.h line 11
Quoted 3 lines
include/net/lwip.h new file +3
-0+* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve @name: etc
Quoted 11 lines
include/net/lwip.h new file +6
-0+* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the polling loop +* Other value < 0, if error +*/ +int ulwip_dns (char *name,char *varname);net/lwip/Makefile +2
-1--- a/net/lwip/Makefile + */ +net/lwip/Makefile
Quoted 10 lines
net/lwip/Makefile +10
-0+#include <common.h> +#include <command.h> +#include <console.h> + +#include <lwip/dns.h> +#include <lwip/ip_addr.h> + +#include <net/ulwip.h> + +static void dns_found_cb(const char *name, const ip_addr_t *ipaddr,void
*callback_arg)net/lwip/Makefile
Quoted 5 lines
net/lwip/Makefile +5
-0+{ + char *varname = (char *)callback_arg; + + if (varname) + env_set(varname, ip4addr_ntoa(ipaddr));Why do we have to set the varname to the resolved address? Is this something the dns command already does?
Quoted 1 line
Exactly, original command is:
U_BOOT_CMD(
dns, 3, 1, do_dns,
"lookup the IP of a hostname",
"hostname [envvar]"
);
Quoted 32 lines
Quoted 26 lines
net/lwip/Makefile +25
-1+ + log_info("resolved %s to %s\n", name, ip4addr_ntoa(ipaddr)); + ulwip_exit(0); +} + +int ulwip_dns(char *name, char *varname) +{ + int err; + ip_addr_t ipaddr; /* not used */ + ip_addr_t dns1; + ip_addr_t dns2; + + ipaddr_aton(env_get("dnsip"), &dns1); + ipaddr_aton(env_get("dnsip2"), &dns2); + + dns_init(); + dns_setserver(0, &dns1); + dns_setserver(1, &dns2); + + err = dns_gethostbyname(name, &ipaddr, dns_found_cb, varname); + if (err == ERR_OK) + dns_found_cb(name, &ipaddr, varname); + + return err; +} --Quoted 2 lines
2.30.2
Thanks
/Ilias
Re: [PATCHv6 03/14] net/lwip: implement dns cmd
In reply to Ilias ApalodimasOn Mon, 14 Aug 2023 at 20:19, Ilias Apalodimas <[email protected]> wrote:
[...]
Quoted 15 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* +* This function creates the DNS request to resolve a domain host name.Function
You need the name of the function as well. Please have a look at how the rest of the code is documented.
Quoted 1 line
+* can return immediately if previous request was cached or it might
require
include/net/lwip.h line 11
Quoted 3 lines
include/net/lwip.h new file +3
-0+* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve @name: etc
Quoted 7 lines
include/net/lwip.h line 16
Quoted 6 lines
include/net/lwip.h new file +5
-0+* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the polling loop +* Other value < 0, if error +*/
Is there any command to check all the files for the comments style?
[...]
Re: [PATCHv6 03/14] net/lwip: implement dns cmd
Quoted 29 lines · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:19, Ilias Apalodimas <[email protected]> wrote:
[...]
Quoted 15 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* +* This function creates the DNS request to resolve a domain host name.Function
You need the name of the function as well. Please have a look at how the rest of the code is documented.
Quoted 1 line
+* can return immediately if previous request was cached or it might
require
include/net/lwip.h line 11
Quoted 3 lines
include/net/lwip.h new file +3
-0+* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve @name: etc
Quoted 7 lines
include/net/lwip.h line 16
Quoted 6 lines
include/net/lwip.h new file +5
-0+* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the polling loop +* Other value < 0, if error +*/
Quoted 1 line
Is there any command to check all the files for the comments style?
I suspect if you included them in docs, htmldocs/etc would note problems, Heinrich?
Signature · 1 line
Tom
Re: [PATCHv6 03/14] net/lwip: implement dns cmd
Quoted 31 lines · Tom Rini
Quoted 29 lines · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:19, Ilias Apalodimas <[email protected]> wrote:
[...]
Quoted 22 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* +* This function creates the DNS request to resolve a domain host name.Function
You need the name of the function as well. Please have a look at how the rest of the code is documented.
Quoted 1 line
+* can return immediately if previous request was cached or it might
require
include/net/lwip.h line 11
Quoted 3 lines
include/net/lwip.h new file +3
-0+* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve @name: etc
Quoted 6 lines
include/net/lwip.h new file +5
-0+* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the polling loop +* Other value < 0, if error +*/
Quoted 5 lines
Quoted 1 line
Is there any command to check all the files for the comments style?
I suspect if you included them in docs, htmldocs/etc would note problems, Heinrich?
Yes 'make htmldocs' blows up on errors, at least for the EFI subsystem
Cheers
/Ilias
Quoted 2 lines
--
Tom
Re: [PATCHv6 03/14] net/lwip: implement dns cmd
Quoted 38 lines · Ilias Apalodimas
Quoted 3 lines · Tom Rini
Quoted 1 line · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:19, Ilias Apalodimas <
Quoted 7 lines
Quoted 7 lines
wrote:
[...]
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* +* This function creates the DNS request to resolve a domain hostname.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Function
You need the name of the function as well. Please have a look at
how the
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
rest of the code is documented.
Quoted 1 line
+* can return immediately if previous request was cached or it
might
Quoted 17 lines
Quoted 16 lines
Quoted 7 lines
require
include/net/lwip.h line 11
Quoted 3 lines
include/net/lwip.h new file +3
-0+* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve @name: etc
Quoted 7 lines
include/net/lwip.h line 16
Quoted 6 lines
include/net/lwip.h new file +5
-0+* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the polling loop +* Other value < 0, if error +*/ Is there any command to check all the files for the comments style?
Quoted 9 lines
Quoted 3 lines
I suspect if you included them in docs, htmldocs/etc would note problems, Heinrich?
Yes 'make htmldocs' blows up on errors, at least for the EFI subsystem
Cheers
/Ilias
O! Ilias thanks for the reference. First patch for doc/develop/net_lwip.rst needed direct references:
.. kernel-doc:: include/net/lwip.h
:internal:
to force Sphinx to generate docs for these files. (as I understand for .c files it does checks and for .h files it generates docs).
Without specification syntax is not validated. It will be good to do something to check all U-Boot .h files for the common syntax later.
BR,
Maxim.
Quoted 3 lines
Quoted 2 lines
--
Tom
Re: [PATCHv6 03/14] net/lwip: implement dns cmd
Quoted 49 lines · Maxim Uvarov
Quoted 35 lines · Ilias Apalodimas
Quoted 33 lines · Tom Rini
Quoted 30 lines · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:19, Ilias Apalodimas <[email protected]> wrote:
[...]
Quoted 15 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* +* This function creates the DNS request to resolve a domain host name.Function
You need the name of the function as well. Please have a look at how the rest of the code is documented.
Quoted 1 line
+* can return immediately if previous request was cached or it might
require
include/net/lwip.h line 11
Quoted 3 lines
include/net/lwip.h new file +3
-0+* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve @name: etc
Quoted 7 lines
include/net/lwip.h line 16
Quoted 6 lines
include/net/lwip.h new file +5
-0+* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the polling loop +* Other value < 0, if error +*/ Is there any command to check all the files for the comments style?
Quoted 8 lines
Quoted 3 lines
I suspect if you included them in docs, htmldocs/etc would note problems, Heinrich?
Yes 'make htmldocs' blows up on errors, at least for the EFI subsystem
Cheers
/Ilias
Quoted 8 lines
O! Ilias thanks for the reference. First patch for
doc/develop/net_lwip.rstneeded direct references:.. kernel-doc::
include/net/lwip.h
:internal:to force Sphinx to generate docs for these files. (as I understand for .c files it does checks and for .h files it generates docs).
Without specification syntax is not validated. It will be good to do something to check all U-Boot .h files for the common syntax later.
You need comments that look like this
/**
* parse_event_log_header() - Parse and verify the event log header
fields
*
* @buffer: Pointer to the start of the eventlog * @size: Size of the eventlog * @pos: Return offset of the next event in
buffer right
* after the event header i.e specID
*
* Return: status code
*/
Cheers
/Ilias
Quoted 9 lines
BR,
Maxim.Quoted 3 lines
Quoted 3 lines
--
Tom
Re: [PATCHv6 03/14] net/lwip: implement dns cmd
Quoted 77 lines · Ilias Apalodimas
Quoted 4 lines · Maxim Uvarov
On Wed, 16 Aug 2023 at 16:26, Ilias Apalodimas <
Quoted 5 lines · [email protected]> wrote:
Quoted 5 lines · Tom Rini
Quoted 3 lines · Maxim Uvarov
Quoted 1 line
On Mon, 14 Aug 2023 at 20:19, Ilias Apalodimas <
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
wrote:
[...]
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* +* This function creates the DNS request to resolve a domainhost name.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Function
You need the name of the function as well. Please have a look at
how the
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
rest of the code is documented.
Quoted 1 line
+* can return immediately if previous request was cached or it
might
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
require
Review
Quoted 3 lines
(quoted diff) +3
-0+* entering the polling loop for a request to a remote server. +* +* @name dns name to resolve@name: etc
Review
Quoted 3 lines
(quoted diff) +3
-0+* @varname (optional) U-Boot variable name to store the result +* Return: ERR_OK(0) for fetching entry from the cache +* ERR_INPROGRESS(-5) success, can go to the pollingloop
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+* Other value < 0, if error +*/Is there any command to check all the files for the comments style?
I suspect if you included them in docs, htmldocs/etc would note problems, Heinrich?
Quoted 7 lines
Quoted 4 lines
Yes 'make htmldocs' blows up on errors, at least for the EFI subsystem
Cheers
/IliasO! Ilias thanks for the reference. First patch for
doc/develop/net_lwip.rstneeded direct references:Quoted 5 lines
.. kernel-doc::
include/net/lwip.h
:internal:to force Sphinx to generate docs for these files. (as I understand for
.c files it does checks and for .h files it generates docs).
Quoted 2 lines
Without specification syntax is not validated. It will be good to do
something to check all U-Boot .h files for the common syntax later.
You need comments that look like this
/**
*parse_event_log_header()- Parse and verify the event log header
fields
** @buffer: Pointer to the start of the eventlog * @size: Size of the eventlog * @pos: Return offset of the next event in
Quoted 9 lines
buffer right
* after the event header i.e specID
*
* Return: status code
*/Cheers
/Ilias
Yes, I added html generation for these files and now I can fix style.
Quoted 10 lines
Quoted 9 lines
BR,
Maxim.Quoted 3 lines
Quoted 3 lines
--
Tom
PATCH v6 4/14 net/lwip: implement dhcp cmd
In reply to Maxim UvarovImplement function for dhcp command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP.
--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.c
include/net/lwip.h +10 -0
@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If DHCP server +* returns file name, this file will be downloaded with tftp. After this +* function you need to invoke the polling loop to process network communication. +* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );
net/lwip/Makefile +1 -0
@@ -65,4 +65,5 @@ obj-$(CONFIG_NET) += $(LWIPDIR)/netif/ethernet.o obj-$(CONFIG_NET) += port/if.o obj-$(CONFIG_NET) += port/sys-arch.o +obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o
net/lwip/apps/dhcp/lwip-dhcp.c new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 3 lines · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP.
Same as the dns command
Quoted 14 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, · line 20
Quoted 6 lines
include/net/lwip.h +3
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If DHCP server
Sphinx needs something more, please check the existing functions
Quoted 27 lines
include/net/lwip.h +7
-0+* returns file name, this file will be downloaded with tftp. After this +* function you need to invoke the polling loop to process network communication. +* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +17
-1--- a/net/lwip/Makefile + +static struct dhcp dhcp; + +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr", ip4addr_ntoa(&dhcp.offered_ip_addr)); + env_set("netmask", ip4addr_ntoa(&dhcp.offered_sn_mask)); + env_set("serverip", ip4addr_ntoa(&dhcp.server_ip_addr)); + printf("DHCP client bound to address %s\n", ip4addr_ntoa(&dhcp.offered_ip_addr)); + break; + default: + return -1; + } +
net/lwip/Makefile
Quoted 10 lines
net/lwip/Makefile +10
-0+ return 0; +} + +int ulwip_dhcp(void) +{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);
What's (1)?
Quoted 13 lines
net/lwip/Makefile +10
-0+ + if (!netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP)) + dhcp_set_struct(netif, &dhcp); + + err = dhcp_start(netif); + if (err) + printf("dhcp_start error %d\n", err); + + return err; +}Signature · 1 line
2.30.2
Thanks
/Ilias
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 66 lines · Ilias Apalodimas
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and output
is
Quoted 2 lines
the same as the original command. This code called by compatibility code between U-Boot and lwIP.
Same as the dns command
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int
Quoted 14 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, intargc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If DHCP server
Sphinx needs something more, please check the existing functions
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int · line 22
Quoted 2 lines
include/net/lwip.h +2
-0+* returns file name, this file will be downloaded with tftp. After this +* function you need to invoke the polling loop to process network communication.
Quoted 10 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +2
-1--- a/net/lwip/Makefile + +static struct dhcp dhcp;net/lwip/Makefile
Quoted 10 lines
net/lwip/Makefile +10
-0+ +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr", ip4addr_ntoa(&dhcp.offered_ip_addr)); + env_set("netmask", ip4addr_ntoa(&dhcp.offered_sn_mask)); + env_set("serverip", ip4addr_ntoa(&dhcp.server_ip_addr)); + printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 9 lines
net/lwip/Makefile +9
-0+ break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void)
Quoted 10 lines
net/lwip/Makefile
Quoted 6 lines
net/lwip/Makefile +6
-0+{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Only one lwip netif is registered. 1 - here is the index of netif. I don't think that there is any definition for that...
Quoted 18 lines
net/lwip/Makefile
Quoted 2 lines
net/lwip/Makefile +2
-0+ + if (!netif_get_client_data(netif,
LWIP_NETIF_CLIENT_DATA_INDEX_DHCP))Quoted 11 lines
net/lwip/Makefile +8
-1+ dhcp_set_struct(netif, &dhcp); + + err = dhcp_start(netif); + if (err) + printf("dhcp_start error %d\n", err); + + return err; +} --2.30.2
Thanks
/Ilias
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 79 lines · Maxim Uvarov
Quoted 66 lines · Ilias Apalodimas
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and output
is
Quoted 2 lines
the same as the original command. This code called by compatibility code between U-Boot and lwIP.
Same as the dns command
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int
Quoted 14 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, intargc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If DHCP server
Sphinx needs something more, please check the existing functions
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int · line 22
Quoted 2 lines
include/net/lwip.h +2
-0+* returns file name, this file will be downloaded with tftp. After this +* function you need to invoke the polling loop to process network communication.
Quoted 10 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +2
-1--- a/net/lwip/Makefile + +static struct dhcp dhcp;net/lwip/Makefile
Quoted 10 lines
net/lwip/Makefile +10
-0+ +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr", ip4addr_ntoa(&dhcp.offered_ip_addr)); + env_set("netmask", ip4addr_ntoa(&dhcp.offered_sn_mask)); + env_set("serverip", ip4addr_ntoa(&dhcp.server_ip_addr)); + printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 9 lines
net/lwip/Makefile +9
-0+ break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void)Quoted 10 lines
net/lwip/Makefile
Quoted 6 lines
net/lwip/Makefile +6
-0+{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Quoted 3 lines
Only one lwip netif is registered. 1 - here is the index of netif. I don't think that there is any definition for that...
And there's only ever going to be one interface (even if we have ipv4 and ipv60 ? If so, define it to something please, thanks.
Signature · 1 line
Tom
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 91 lines · Tom Rini
Quoted 1 line · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:21, Ilias Apalodimas <
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and
output
Quoted 2 lines
Quoted 2 lines
is
Quoted 1 line
the same as the original command. This code called by compatibility
code
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
between U-Boot and lwIP.
Same as the dns command
Quoted 6 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag,
Quoted 8 lines
3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag,int
Quoted 7 lines
Quoted 7 lines
argc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If DHCP
Quoted 5 lines
Quoted 5 lines
server
Sphinx needs something more, please check the existing functions
Quoted 1 line
include/net/lwip.h +1
-0+* returns file name, this file will be downloaded with tftp. After this
Quoted 12 lines
Quoted 12 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, · line 22
Quoted 1 line
include/net/lwip.h +1
-0+* function you need to invoke the polling loop to process network communication.
Quoted 10 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +2
-1--- a/net/lwip/Makefile + +static struct dhcp dhcp;Quoted 8 lines
Quoted 8 lines
net/lwip/Makefile
Quoted 8 lines
net/lwip/Makefile +8
-0+ +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr", ip4addr_ntoa(&dhcp.offered_ip_addr)); + env_set("netmask",
ip4addr_ntoa(&dhcp.offered_sn_mask));Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("serverip",
ip4addr_ntoa(&dhcp.server_ip_addr));Quoted 21 lines
Quoted 11 lines
Quoted 1 line
+ printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 9 lines
net/lwip/Makefile +9
-0+ break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void)Quoted 10 lines
net/lwip/Makefile
Quoted 6 lines
net/lwip/Makefile +6
-0+{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Quoted 1 line
Only one lwip netif is registered. 1 - here is the index of netif. I
don't
Quoted 9 lines
Quoted 2 lines
think that there is any definition for that...
And there's only ever going to be one interface (even if we have ipv4 and ipv60 ? If so, define it to something please, thanks.
--
Tom
Yes, one interface has 2 addresses ipv4 and ipv6.
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 97 lines · Maxim Uvarov
Quoted 94 lines · Tom Rini
Quoted 1 line · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:21, Ilias Apalodimas <
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and
output
Quoted 2 lines
Quoted 2 lines
is
Quoted 1 line
the same as the original command. This code called by compatibility
code
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
between U-Boot and lwIP.
Same as the dns command
Quoted 6 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag,
Quoted 8 lines
3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag,int
Quoted 7 lines
Quoted 7 lines
argc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If DHCP
Quoted 5 lines
Quoted 5 lines
server
Sphinx needs something more, please check the existing functions
Quoted 1 line
include/net/lwip.h +1
-0+* returns file name, this file will be downloaded with tftp. After this
Quoted 12 lines
Quoted 12 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, · line 22
Quoted 1 line
include/net/lwip.h +1
-0+* function you need to invoke the polling loop to process network communication.
Quoted 10 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +2
-1--- a/net/lwip/Makefile + +static struct dhcp dhcp;Quoted 8 lines
Quoted 8 lines
net/lwip/Makefile
Quoted 8 lines
net/lwip/Makefile +8
-0+ +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr", ip4addr_ntoa(&dhcp.offered_ip_addr)); + env_set("netmask",
ip4addr_ntoa(&dhcp.offered_sn_mask));Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("serverip",
ip4addr_ntoa(&dhcp.server_ip_addr));Quoted 21 lines
Quoted 11 lines
Quoted 1 line
+ printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 9 lines
net/lwip/Makefile +9
-0+ break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void)Quoted 10 lines
net/lwip/Makefile
Quoted 6 lines
net/lwip/Makefile +6
-0+{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Quoted 1 line
Only one lwip netif is registered. 1 - here is the index of netif. I
don't
Quoted 2 lines
think that there is any definition for that...
Quoted 8 lines
Quoted 6 lines
And there's only ever going to be one interface (even if we have ipv4 and ipv60 ? If so, define it to something please, thanks.
--
TomYes, one interface has 2 addresses ipv4 and ipv6.
What about a device like a router which may have multiple wired ethernet interface?
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 108 lines · Peter Robinson
Quoted 5 lines · Maxim Uvarov
Quoted 2 lines · Tom Rini
Quoted 1 line · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:21, Ilias Apalodimas <
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and
output
Quoted 2 lines
Quoted 2 lines
is
Quoted 1 line
the same as the original command. This code called by
compatibility
Quoted 12 lines
Quoted 12 lines
code
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
between U-Boot and lwIP.
Same as the dns command
Quoted 6 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int
Quoted 8 lines
3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, intflag,
Quoted 8 lines
Quoted 8 lines
int
Quoted 7 lines
Quoted 7 lines
argc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If
Quoted 6 lines
Quoted 6 lines
DHCP
Quoted 5 lines
Quoted 5 lines
server
Sphinx needs something more, please check the existing functions
Quoted 1 line
include/net/lwip.h +1
-0+* returns file name, this file will be downloaded with tftp. After
Quoted 2 lines
Quoted 2 lines
this
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/net/lwip.h +1
-0+* function you need to invoke the polling loop to process network
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
communication.
Quoted 9 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +1
-1--- a/net/lwip/Makefile +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/lwip/Makefile
Quoted 8 lines
net/lwip/Makefile +8
-0+static struct dhcp dhcp; + +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 33 lines
Quoted 33 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("netmask",
ip4addr_ntoa(&dhcp.offered_sn_mask));Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("serverip",
ip4addr_ntoa(&dhcp.server_ip_addr));Quoted 21 lines
Quoted 11 lines
Quoted 1 line
+ printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 9 lines
net/lwip/Makefile +9
-0+ break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void)Quoted 10 lines
net/lwip/Makefile
Quoted 6 lines
net/lwip/Makefile +6
-0+{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Quoted 1 line
Only one lwip netif is registered. 1 - here is the index of netif. I
don't
Quoted 2 lines
think that there is any definition for that...
And there's only ever going to be one interface (even if we have ipv4 and ipv60 ? If so, define it to something please, thanks.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
--
TomYes, one interface has 2 addresses ipv4 and ipv6.
What about a device like a router which may have multiple wired ethernet interface?
Yea, looks like we need lwip netif per U-Boots eth_devs. I did not yet support several eth devices, but it will be good to add this to not break existing functionality..
BR,
Maxim.
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 114 lines · Maxim Uvarov
Quoted 112 lines · Peter Robinson
Quoted 5 lines · Maxim Uvarov
Quoted 2 lines · Tom Rini
Quoted 1 line · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:21, Ilias Apalodimas <
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and
output
Quoted 2 lines
Quoted 2 lines
is
Quoted 1 line
the same as the original command. This code called by
compatibility
Quoted 12 lines
Quoted 12 lines
code
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
between U-Boot and lwIP.
Same as the dns command
Quoted 6 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int
Quoted 8 lines
3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, intflag,
Quoted 8 lines
Quoted 8 lines
int
Quoted 7 lines
Quoted 7 lines
argc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int · line 20
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If
Quoted 6 lines
Quoted 6 lines
DHCP
Quoted 5 lines
Quoted 5 lines
server
Sphinx needs something more, please check the existing functions
Quoted 1 line
include/net/lwip.h +1
-0+* returns file name, this file will be downloaded with tftp. After
Quoted 2 lines
Quoted 2 lines
this
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/net/lwip.h +1
-0+* function you need to invoke the polling loop to process network
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
communication.
Quoted 9 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +1
-1--- a/net/lwip/Makefile +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/lwip/Makefile
Quoted 8 lines
net/lwip/Makefile +8
-0+static struct dhcp dhcp; + +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 37 lines
Quoted 36 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("netmask",
ip4addr_ntoa(&dhcp.offered_sn_mask));Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("serverip",
ip4addr_ntoa(&dhcp.server_ip_addr));Quoted 21 lines
Quoted 11 lines
Quoted 1 line
+ printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 9 lines
net/lwip/Makefile +9
-0+ break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void)Quoted 10 lines
net/lwip/Makefile
Quoted 6 lines
net/lwip/Makefile +6
-0+{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Quoted 1 line
Only one lwip netif is registered. 1 - here is the index of netif. I
don't
Quoted 2 lines
think that there is any definition for that...
And there's only ever going to be one interface (even if we have ipv4 and ipv60 ? If so, define it to something please, thanks.
--
Tom
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Yes, one interface has 2 addresses ipv4 and ipv6.
What about a device like a router which may have multiple wired ethernet interface?
Yea, looks like we need lwip netif per U-Boots
eth_devs. I did not yet support several eth devices, but it will be good to add this to not break existing functionality..
The general case ends up being if we have more than one interface, ethact is what's used. I'm unsure off-hand if some of the fancier networking-centric chipsets and devices have something more complex setup in their stacks.
Signature · 1 line
Tom
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 130 lines · Tom Rini
Quoted 1 line · Maxim Uvarov
On Thu, 17 Aug 2023 at 20:04, Peter Robinson <[email protected]>
Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 3 lines · Maxim Uvarov
On Mon, 14 Aug 2023 at 21:29, Tom Rini <[email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · Maxim Uvarov
Quoted 1 line
On Mon, 14 Aug 2023 at 20:21, Ilias Apalodimas <
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage
and
Quoted 25 lines
Quoted 25 lines
Quoted 3 lines
Quoted 3 lines
output
Quoted 2 lines
Quoted 2 lines
is
Quoted 1 line
the same as the original command. This code called by
compatibility
Quoted 12 lines
Quoted 12 lines
code
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
between U-Boot and lwIP.
Same as the dns command
Quoted 6 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int
Quoted 8 lines
3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, intflag,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
int
Quoted 7 lines
Quoted 7 lines
argc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int · line 20
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address.
Quoted 5 lines
Quoted 5 lines
If
Quoted 4 lines
Quoted 4 lines
DHCP
Quoted 3 lines
Quoted 3 lines
server
Sphinx needs something more, please check the existing
functions
Quoted 50 lines
Quoted 50 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int · line 21
Quoted 2 lines
include/net/lwip.h +1
-0+* returns file name, this file will be downloaded with tftp. After
Quoted 2 lines
Quoted 2 lines
this
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/net/lwip.h +1
-0+* function you need to invoke the polling loop to process network
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
communication.
Quoted 9 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +1
-1--- a/net/lwip/Makefile +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/lwip/Makefile
Quoted 8 lines
net/lwip/Makefile +8
-0+static struct dhcp dhcp; + +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 25 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("netmask",
ip4addr_ntoa(&dhcp.offered_sn_mask));Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("serverip",
ip4addr_ntoa(&dhcp.server_ip_addr));Quoted 21 lines
Quoted 21 lines
Quoted 1 line
+ printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 5 lines
net/lwip/Makefile +5
-0+ break; + default: + return -1; + } +net/lwip/Makefile
Quoted 10 lines
net/lwip/Makefile +10
-0+ return 0; +} + +int ulwip_dhcp(void) +{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Only one lwip netif is registered. 1 - here is the index of
netif. I
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
don't
Quoted 2 lines
think that there is any definition for that...
And there's only ever going to be one interface (even if we have
ipv4
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
and ipv60 ? If so, define it to something please, thanks.
--
TomQuoted 8 lines
Quoted 4 lines
Quoted 1 line
Yes, one interface has 2 addresses ipv4 and ipv6.
What about a device like a router which may have multiple wired ethernet interface?
Yea, looks like we need lwip netif per U-Boots
eth_devs. I did not yet support several eth devices, but it will be good to add this to not break existing functionality..
Quoted 8 lines
The general case ends up being if we have more than one interface, ethact is what's used. I'm unsure off-hand if some of the fancier networking-centric chipsets and devices have something more complex setup in their stacks.
--
Tom
Likely the bootloader uses the only one ethernet interface for loading. And it might
be enough to have an IP stack on top of the active eth device only. This is a model
that I am following in these patches.
BR,
Maxim.
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 134 lines · Maxim Uvarov
Quoted 130 lines · Tom Rini
Quoted 114 lines · Maxim Uvarov
Quoted 112 lines · Peter Robinson
Quoted 5 lines · Maxim Uvarov
Quoted 2 lines · Tom Rini
Quoted 1 line · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:21, Ilias Apalodimas <
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and
output
Quoted 2 lines
Quoted 2 lines
is
Quoted 1 line
the same as the original command. This code called by
compatibility
Quoted 12 lines
Quoted 12 lines
code
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
between U-Boot and lwIP.
Same as the dns command
Quoted 6 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int
Quoted 8 lines
3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, intflag,
Quoted 8 lines
Quoted 8 lines
int
Quoted 7 lines
Quoted 7 lines
argc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int · line 20
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If
Quoted 6 lines
Quoted 6 lines
DHCP
Quoted 5 lines
Quoted 5 lines
server
Sphinx needs something more, please check the existing functions
Quoted 1 line
include/net/lwip.h +1
-0+* returns file name, this file will be downloaded with tftp. After
Quoted 2 lines
Quoted 2 lines
this
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/net/lwip.h +1
-0+* function you need to invoke the polling loop to process network
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
communication.
Quoted 9 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +1
-1--- a/net/lwip/Makefile +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/lwip/Makefile
Quoted 8 lines
net/lwip/Makefile +8
-0+static struct dhcp dhcp; + +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 37 lines
Quoted 36 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("netmask",
ip4addr_ntoa(&dhcp.offered_sn_mask));Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("serverip",
ip4addr_ntoa(&dhcp.server_ip_addr));Quoted 21 lines
Quoted 11 lines
Quoted 1 line
+ printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 9 lines
net/lwip/Makefile +9
-0+ break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void)Quoted 10 lines
net/lwip/Makefile
Quoted 6 lines
net/lwip/Makefile +6
-0+{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Quoted 1 line
Only one lwip netif is registered. 1 - here is the index of netif. I
don't
Quoted 2 lines
think that there is any definition for that...
And there's only ever going to be one interface (even if we have ipv4 and ipv60 ? If so, define it to something please, thanks.
--
TomQuoted 8 lines
Quoted 4 lines
Quoted 1 line
Yes, one interface has 2 addresses ipv4 and ipv6.
What about a device like a router which may have multiple wired ethernet interface?
Yea, looks like we need lwip netif per U-Boots
eth_devs. I did not yet support several eth devices, but it will be good to add this to not break existing functionality..The general case ends up being if we have more than one interface, ethact is what's used. I'm unsure off-hand if some of the fancier networking-centric chipsets and devices have something more complex setup in their stacks.
Quoted 7 lines
Quoted 2 lines
--
TomLikely the bootloader uses the only one ethernet interface for loading. And it might be enough to have an IP stack on top of the active eth device only. This is a model that I am following in these patches.
It's possible, yes, that there may only be one active device, but you still will need to be able to handle all of them to at least work out which one has a link that you can bring up to get an IP. There's a bunch of devices that will have two interfaces with the same NIC driver, plus also there's at least a few devices that have an onboard switch (MV88E6XXX) although grep only shows a single one upstream.
Re: [PATCHv6 04/14] net/lwip: implement dhcp cmd
Quoted 143 lines · Peter Robinson
Quoted 134 lines · Maxim Uvarov
Quoted 130 lines · Tom Rini
Quoted 114 lines · Maxim Uvarov
Quoted 112 lines · Peter Robinson
Quoted 5 lines · Maxim Uvarov
Quoted 2 lines · Tom Rini
Quoted 1 line · Maxim Uvarov
On Mon, 14 Aug 2023 at 20:21, Ilias Apalodimas <
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
Implement function for dhcp command with lwIP variant. Usage and
output
Quoted 2 lines
Quoted 2 lines
is
Quoted 1 line
the same as the original command. This code called by
compatibility
Quoted 12 lines
Quoted 12 lines
code
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
between U-Boot and lwIP.
Same as the dns command
Quoted 6 lines
Signed-off-by Maxim Uvarov <[email protected]>--- include/net/lwip.h | 10 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 51++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int
Quoted 8 lines
3 files changed, 62 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.cinclude/net/lwip.h +0
-0@@ -15,3 +15,13 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, intflag,
Quoted 8 lines
Quoted 8 lines
int
Quoted 7 lines
Quoted 7 lines
argc,
include/net/lwip.h int do_lwip_dns(struct cmd_tbl *cmdtp, int · line 20
Quoted 6 lines
include/net/lwip.h +3
-0* Other value < 0, if error */ int ulwip_dns (char *name,char *varname); + +/* +* This function creates the DHCP request to obtain IP address. If
Quoted 6 lines
Quoted 6 lines
DHCP
Quoted 5 lines
Quoted 5 lines
server
Sphinx needs something more, please check the existing functions
Quoted 1 line
include/net/lwip.h +1
-0+* returns file name, this file will be downloaded with tftp. After
Quoted 2 lines
Quoted 2 lines
this
Quoted 1 line
Quoted 1 line
Quoted 1 line
include/net/lwip.h +1
-0+* function you need to invoke the polling loop to process network
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
communication.
Quoted 9 lines
include/net/lwip.h +5
-0+* +* Return: 0 if success +* Other value < 0, if error +*/ +int ulwip_dhcp (void );net/lwip/Makefile +1
-1--- a/net/lwip/Makefile +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/lwip/Makefile
Quoted 8 lines
net/lwip/Makefile +8
-0+static struct dhcp dhcp; + +static int ulwip_dhcp_tmo(void) +{ + switch (dhcp.state) { + case DHCP_STATE_BOUND: + env_set("bootfile", dhcp.boot_file_name); + env_set("ipaddr",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 37 lines
Quoted 36 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("netmask",
ip4addr_ntoa(&dhcp.offered_sn_mask));Quoted 1 line
Quoted 1 line
Quoted 1 line
+ env_set("serverip",
ip4addr_ntoa(&dhcp.server_ip_addr));Quoted 21 lines
Quoted 11 lines
Quoted 1 line
+ printf("DHCP client bound to address %s\n",
ip4addr_ntoa(&dhcp.offered_ip_addr));Quoted 9 lines
net/lwip/Makefile +9
-0+ break; + default: + return -1; + } + + return 0; +} + +int ulwip_dhcp(void)Quoted 10 lines
net/lwip/Makefile
Quoted 6 lines
net/lwip/Makefile +6
-0+{ + int err; + struct netif *netif; + + ulwip_set_tmo(ulwip_dhcp_tmo); + netif = netif_get_by_index(1);What's (1)?
Quoted 1 line
Only one lwip netif is registered. 1 - here is the index of netif. I
don't
Quoted 2 lines
think that there is any definition for that...
And there's only ever going to be one interface (even if we have ipv4 and ipv60 ? If so, define it to something please, thanks.
--
TomQuoted 8 lines
Quoted 4 lines
Quoted 1 line
Yes, one interface has 2 addresses ipv4 and ipv6.
What about a device like a router which may have multiple wired ethernet interface?
Yea, looks like we need lwip netif per U-Boots
eth_devs. I did not yet support several eth devices, but it will be good to add this to not break existing functionality..The general case ends up being if we have more than one interface, ethact is what's used. I'm unsure off-hand if some of the fancier networking-centric chipsets and devices have something more complex setup in their stacks.
Quoted 7 lines
Quoted 2 lines
--
TomLikely the bootloader uses the only one ethernet interface for loading. And it might be enough to have an IP stack on top of the active eth device only. This is a model that I am following in these patches.
Quoted 6 lines
It's possible, yes, that there may only be one active device, but you still will need to be able to handle all of them to at least work out which one has a link that you can bring up to get an IP. There's a bunch of devices that will have two interfaces with the same NIC driver, plus also there's at least a few devices that have an onboard switch (MV88E6XXX) although grep only shows a single one upstream.
Right. You can even simulate this on some other devices via the gadget ethernet driver. In other words, please make sure we don't forget to use "ethact" (see net/eth-uclass.c and net/eth_common.c).
Signature · 1 line
Tom
PATCH v6 5/14 net/lwip: implement tftp cmd
In reply to Maxim UvarovImplement function for dhcp command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP.
--- net/lwip/Makefile | 1 + net/lwip/apps/tftp/Makefile | 16 ++++ net/lwip/apps/tftp/lwip-tftp.c | 129 +++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 net/lwip/apps/tftp/Makefile create mode 100644 net/lwip/apps/tftp/lwip-tftp.c
net/lwip/Makefile +1 -0
@@ -67,3 +67,4 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/
net/lwip/apps/tftp/Makefile new file +16 -0
@@ -0,0 +1,16 @@ + +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include -I$(srctree)/net/lwip +ccflags-y += -I$(obj) + +$(obj)/tftp.o: $(obj)/tftp.c +.PHONY: $(obj)/tftp.c +$(obj)/tftp.c: + cp $(srctree)/net/lwip/lwip-external/src/apps/tftp/tftp.c $(obj)/tftp.c + cp $(srctree)/net/lwip/lwip-external/src/include/lwip/apps/tftp_client.h $(obj)/tftp_client.h + cp $(srctree)/net/lwip/lwip-external/src/include/lwip/apps/tftp_common.h $(obj)/tftp_common.h + cp $(srctree)/net/lwip/lwip-external/contrib/examples/tftp/tftp_example.h $(obj)/tftp_example.h + +obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o +obj-$(CONFIG_CMD_TFTPBOOT) += lwip-tftp.o +
net/lwip/apps/tftp/lwip-tftp.c new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCHv6 05/14] net/lwip: implement tftp cmd
Quoted 10 lines
net/lwip/apps/tftp/lwip-tftp.c new file +10
-0+// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <console.h> +#include <bootstage.h>
net/lwip/apps/tftp/lwip-tftp.c line 20
Quoted 10 lines
net/lwip/apps/tftp/lwip-tftp.c new file +10
-0+ +#include "lwip/apps/tftp_client.h" +#include "lwip/apps/tftp_server.h" +#include <tftp_example.h> + +#include <string.h> + +#include <net/ulwip.h> + +#if LWIP_UDP
Why do we have this? I dont think it makes sense to start reasoning about LWIP config options from within U-Boot code. Instead U-Boot makefiles should enable all the LWIP features we need when a command is included
Quoted 87 lines
net/lwip/apps/tftp/lwip-tftp.c new file +87
-0+ +static ulong daddr; +static ulong size; + +static void *tftp_open (const char *fname,const char *mode,u8_t is_write) +{ +LWIP_UNUSED_ARG (mode); +return NULL ; +} + +static void tftp_close (void *handle) +{ +log_info ("\ndone\n" ); +log_info ("Bytes transferred = %ld (0x%lx hex)\n" , size, size); + +bootstage_mark_name (BOOTSTAGE_KERNELREAD_STOP ,"tftp_done" ); +env_set_ulong ("filesize" , size); +ulwip_exit (0 ); +} + +static int tftp_read (void *handle,void *buf,int bytes) +{ +return 0 ; +} + +static int tftp_write (void *handle,struct pbuf *p) +{ +struct pbuf *q; + +for (q = p; q !=NULL ; q = q->next) { +memcpy ((void *)daddr, q->payload, q->len); + daddr += q->len; + size += q->len; +log_info ("#" ); + } + +return 0 ; +} + +static void tftp_error (void *handle,int err,const char *msg,int size) +{ +char message[100 ]; + +LWIP_UNUSED_ARG (handle); + +memset (message,0 ,sizeof (message)); +MEMCPY (message, msg,LWIP_MIN (sizeof (message)-1 , (size_t )size)); + +log_info ("TFTP error: %d (%s)" , err, message); +} + +static const struct tftp_context tftp = { + tftp_open, + tftp_close, + tftp_read, + tftp_write, + tftp_error +}; + +int ulwip_tftp (ulong addr,char *fname) +{ +void *f = (void *)0x1 ;/* unused fake file handle*/ +err_t err; +ip_addr_t srv; +int ret; +char *server_ip; + +if (!fname || addr ==0 ) +return CMD_RET_FAILURE ; + + size =0 ; + daddr = addr; + server_ip =env_get ("serverip" ); +if (!server_ip) { +log_err ("error: serverip variable has to be set\n" ); +return CMD_RET_FAILURE ; + } + + ret =ipaddr_aton (server_ip, &srv); +if (!ret) { +log_err ("error: ipaddr_aton\n" ); +return CMD_RET_FAILURE ; + } + +log_info ("TFTP from server %s; our IP address is %s\n" , + server_ip,env_get ("ipaddr" )); +log_info ("Filename '%s'.\n" , fname);
net/lwip/apps/tftp/lwip-tftp.c line 117
Quoted 10 lines
net/lwip/apps/tftp/lwip-tftp.c new file +10
-0+log_info ("Load address: 0x%lx\n" , daddr); +log_info ("Loading:" ); + +bootstage_mark_name (BOOTSTAGE_KERNELREAD_START ,"tftp_start" ); + + err =tftp_init_client (&tftp); +if (!(err ==ERR_OK || err ==ERR_USE )) +log_err ("tftp_init_client err: %d\n" , err); + + err =tftp_get (f, &srv,TFTP_PORT , fname,TFTP_MODE_OCTET );
Shouldn't this be part of tftp_read()?
Quoted 15 lines
net/lwip/apps/tftp/lwip-tftp.c new file +12
-0+/* might return different errors, like routing problems */ +if (err !=ERR_OK ) { +log_err ("tftp_get err=%d\n" , err); +return CMD_RET_FAILURE ; + } + +env_set_hex ("fileaddr" , addr); + return err; +} +#else +#error "UDP has to be supported" +#endif /* LWIP_UDP */ Signature · 1 line
2.30.2
Re: [PATCHv6 05/14] net/lwip: implement tftp cmd
Quoted 16 lines · Ilias Apalodimas
Quoted 16 lines
net/lwip/apps/tftp/lwip-tftp.c new file +16
-0+// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <console.h> +#include <bootstage.h> + +#include "lwip/apps/tftp_client.h" +#include "lwip/apps/tftp_server.h" +#include <tftp_example.h> + +#include <string.h>
Quoted 10 lines
net/lwip/apps/tftp/lwip-tftp.c line 20
Quoted 4 lines
net/lwip/apps/tftp/lwip-tftp.c new file +4
-0+ +#include <net/ulwip.h> + +#if LWIP_UDP Why do we have this? I dont think it makes sense to start reasoning about LWIP config options from within U-Boot code. Instead U-Boot makefiles should enable all the LWIP features we need when a command is included
That is how example used it. Agree do drop this if.
Quoted 92 lines
net/lwip/apps/tftp/lwip-tftp.c
Quoted 5 lines
net/lwip/apps/tftp/lwip-tftp.c new file +5
-0+ +static ulong daddr; +static ulong size; + +static void *tftp_open(const char *fname, const char *mode, u8_t
is_write)Quoted 86 lines
net/lwip/apps/tftp/lwip-tftp.c new file +86
-0+{ +LWIP_UNUSED_ARG (mode); +return NULL ; +} + +static void tftp_close (void *handle) +{ +log_info ("\ndone\n" ); +log_info ("Bytes transferred = %ld (0x%lx hex)\n" , size, size); + +bootstage_mark_name (BOOTSTAGE_KERNELREAD_STOP ,"tftp_done" ); +env_set_ulong ("filesize" , size); +ulwip_exit (0 ); +} + +static int tftp_read (void *handle,void *buf,int bytes) +{ +return 0 ; +} + +static int tftp_write (void *handle,struct pbuf *p) +{ +struct pbuf *q; + +for (q = p; q !=NULL ; q = q->next) { +memcpy ((void *)daddr, q->payload, q->len); + daddr += q->len; + size += q->len; +log_info ("#" ); + } + +return 0 ; +} + +static void tftp_error (void *handle,int err,const char *msg,int size) +{ +char message[100 ]; + +LWIP_UNUSED_ARG (handle); + +memset (message,0 ,sizeof (message)); +MEMCPY (message, msg,LWIP_MIN (sizeof (message)-1 , (size_t )size)); + +log_info ("TFTP error: %d (%s)" , err, message); +} + +static const struct tftp_context tftp = { + tftp_open, + tftp_close, + tftp_read, + tftp_write, + tftp_error +}; + +int ulwip_tftp (ulong addr,char *fname) +{ +void *f = (void *)0x1 ;/* unused fake file handle*/ +err_t err; +ip_addr_t srv; +int ret; +char *server_ip; + +if (!fname || addr ==0 ) +return CMD_RET_FAILURE ; + + size =0 ; + daddr = addr; + server_ip =env_get ("serverip" ); +if (!server_ip) { +log_err ("error: serverip variable has to be set\n" ); +return CMD_RET_FAILURE ; + } + + ret =ipaddr_aton (server_ip, &srv); +if (!ret) { +log_err ("error: ipaddr_aton\n" ); +return CMD_RET_FAILURE ; + } + +log_info ("TFTP from server %s; our IP address is %s\n" , + server_ip,env_get ("ipaddr" )); +log_info ("Filename '%s'.\n" , fname); +log_info ("Load address: 0x%lx\n" , daddr); +log_info ("Loading:" ); + +bootstage_mark_name (BOOTSTAGE_KERNELREAD_START ,"tftp_start" );
Quoted 10 lines
net/lwip/apps/tftp/lwip-tftp.c line 117
Quoted 6 lines
net/lwip/apps/tftp/lwip-tftp.c new file +6
-0+ + err =tftp_init_client (&tftp); +if (!(err ==ERR_OK || err ==ERR_USE )) +log_err ("tftp_init_client err: %d\n" , err); + + err =tftp_get (f, &srv,TFTP_PORT , fname,TFTP_MODE_OCTET );Shouldn't this be part of
tftp_read()?
tft_get() actually does some initialization. Then when the polling loop works tftp_write() or tftp_read() callbacks will be called. So here it should stay as is.
Quoted 16 lines
Quoted 15 lines
net/lwip/apps/tftp/lwip-tftp.c new file +12
-1+/* might return different errors, like routing problems */ +if (err !=ERR_OK ) { +log_err ("tftp_get err=%d\n" , err); +return CMD_RET_FAILURE ; + } + +env_set_hex ("fileaddr" , addr); + return err; +} +#else +#error "UDP has to be supported" +#endif /* LWIP_UDP */ --2.30.2
PATCH v6 6/14 net/lwip: implement wget cmd
In reply to Maxim UvarovImplement function for wget command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code
between U-Boot and lwIP.
--- include/net/lwip.h | 13 ++++ net/lwip/Makefile | 1 + net/lwip/apps/http/Makefile | 13 ++++ net/lwip/apps/http/lwip-wget.c | 131 +++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 net/lwip/apps/http/Makefile create mode 100644 net/lwip/apps/http/lwip-wget.c
include/net/lwip.h +13 -0
@@ -25,3 +25,16 @@ int ulwip_dns(char *name, char *varname);* Other value < 0, if error */ int ulwip_dhcp (void ); + +/* +* This function creates the HTTP request to download file from url to the address +* specified in parameters. After this function you need to invoke the polling +* loop to process network communication. +* +* +* @addr start address to download result +* @url url in format http://host[:port]/url +* Return: 0 for success +* !0 if error +*/ +int ulwip_wget (ulong addr,char *url);
net/lwip/Makefile +1 -0
@@ -68,3 +68,4 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ +obj-$(CONFIG_CMD_WGET) += apps/http/
net/lwip/apps/http/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include -I$(srctree)/net/lwip +ccflags-y += -I$(obj) + +$(obj)/http_clinet.o: $(obj)/http_client.c +.PHONY: $(obj)/http_client.c +$(obj)/http_client.c: + cp $(srctree)/net/lwip/lwip-external/src/apps/http/http_client.c $(obj)/http_client.c + cp $(srctree)/net/lwip/lwip-external/src/include/lwip/apps/http_client.h $(obj)/http_client.h + +obj-$(CONFIG_CMD_WGET) += http_client.o +obj-$(CONFIG_CMD_WGET) += lwip-wget.o +
net/lwip/apps/http/lwip-wget.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCHv6 06/14] net/lwip: implement wget cmd
Quoted 4 lines · Maxim Uvarov
Implement function for wget command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code
between U-Boot and lwIP.
Similar comments to previous patches adding commands
include/net/lwip.h int ulwip_dns(char *name, char *varname); · line 39
Quoted 8 lines
Signed-off-by Maxim Uvarov <[email protected]>include/net/lwip.h +7
-0+* +* +* @addr start address to download result +* @url url in format http://host[:port]/url +* Return: 0 for success +* !0 if error +*/
Same here, sphinx needs a different syntax
Quoted 48 lines
include/net/lwip.h +1
-0+int ulwip_wget (ulong addr,char *url);net/lwip/Makefile +1
-0@@ -68,3 +68,4 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ +obj-$(CONFIG_CMD_WGET) += apps/http/net/lwip/apps/http/Makefile new file +13
-0@@ -0,0 +1,13 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include -I$(srctree)/net/lwip +ccflags-y += -I$(obj) + +$(obj)/http_clinet.o: $(obj)/http_client.c +.PHONY: $(obj)/http_client.c +$(obj)/http_client.c: + cp $(srctree)/net/lwip/lwip-external/src/apps/http/http_client.c $(obj)/http_client.c + cp $(srctree)/net/lwip/lwip-external/src/include/lwip/apps/http_client.h $(obj)/http_client.h + +obj-$(CONFIG_CMD_WGET) += http_client.o +obj-$(CONFIG_CMD_WGET) += lwip-wget.o +net/lwip/apps/http/lwip-wget.c new file +13
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <console.h> +#include <vsprintf.h> + +#include "http_client.h" +#include <net/ulwip.h>
net/lwip/apps/http/lwip-wget.c line 23
Quoted 10 lines
net/lwip/apps/http/lwip-wget.c new file +10
-0+ +static ulong daddr; +static httpc_connection_t settings; + +#define SERVER_NAME_SIZE 200 + +static err_t httpc_recv (void *arg,struct altcp_pcb *pcb,struct pbuf *p, +err_t unused_err) +{ +struct pbuf *q;
Please change the p/q stuff to something that's actually readable and hints on what those variables represent
net/lwip/apps/http/lwip-wget.c line 34
Quoted 11 lines
net/lwip/apps/http/lwip-wget.c new file +11
-0+ +if (!p) +return ERR_BUF ; + +for (q = p; q !=NULL ; q = q->next) { +memcpy ((void *)daddr, q->payload, q->len); +log_debug ("downloaded chunk size %d, to addr 0x%lx\n" , q->len, daddr); + daddr += q->len; + } +altcp_recved (pcb, p->tot_len); +pbuf_free (p);
Why is this freed here?
If the caller allocates this, he should also be responsible for freeing it
Quoted 8 lines
net/lwip/apps/http/lwip-wget.c new file +8
-0+return ERR_OK ; +} + +static void httpc_result (void *arg,httpc_result_t httpc_result,u32_t rx_content_len, +u32_t srv_res,err_t err) +{ +if (httpc_result ==HTTPC_RESULT_OK ) { +log_info ("\n%d bytes successfully downloaded.\n" , rx_content_len);
net/lwip/apps/http/lwip-wget.c line 52
Quoted 10 lines
net/lwip/apps/http/lwip-wget.c new file +10
-0+env_set_ulong ("filesize" , rx_content_len); +ulwip_exit (0 ); + }else { +log_err ("\nhttp eroror: %d\n" , httpc_result); +ulwip_exit (-1 ); + } +} + +/* http://hostname:port/url */ +static int parse_url (char *url,char *host,u16 *port)
I think we discussed this already. If the existing wget application doesn't support configurable ports, just skip it on the initial patch and add it in the future
Quoted 82 lines
net/lwip/apps/http/lwip-wget.c new file +79
-0+{ +char *p, *pp; + + p =strstr (url,"http://" ); +if (!p) { +printf ("err: no http://!\n" ); +return -1 ; + } + + p +=strlen ("http://" ); + +/* parse hostname */ + pp =strchr (p,':' ); +if (pp) { +#define PORT_STR_SIZE 5 +char portstr[PORT_STR_SIZE ]; + +if (pp - p >=SERVER_NAME_SIZE ) +return -2 ; +memcpy (host, p, pp - p); + host[pp - p +1 ] ='\0' ; + + p = pp +1 ; + pp =strchr (p,'/' ); +if (!pp) { +printf ("wrong url\n" ); +return -3 ; + } + +if (pp - p >=PORT_STR_SIZE ) +return -4 ; +memcpy (portstr, p, pp - p); + portstr[pp - p] ='\0' ; + *port = (u16 )dectoul (portstr,NULL ); + }else { + pp =strchr (p,'/' ); +if (!pp) { +printf ("wrong url\n" ); +return -5 ; + } + +if (pp - p >=SERVER_NAME_SIZE ) +return -6 ; +memcpy (host, p, pp - p); + host[pp - p +1 ] ='\0' ; + *port =80 ;/* default */ + } + +return 0 ; +} + +int ulwip_wget (ulong addr,char *url) +{ +err_t err; +u16 port; +char server_name[SERVER_NAME_SIZE ]; +httpc_state_t *connection; + + daddr = addr; + + err =parse_url (url, server_name, &port); +if (err) { +log_err ("error parse_url\n" ); +return -1 ; + } + +log_info ("downloading %s to addr 0x%lx\n" , url, addr); +memset (&settings,0 ,sizeof (settings)); + settings.result_fn = httpc_result; + err =httpc_get_file_dns (server_name, port, url, &settings, + httpc_recv,NULL , &connection); +if (err !=ERR_OK ) { +log_err ("httpc_init_connection failed\n" ); +return err; + } + +env_set_hex ("fileaddr" , addr); +return 0 ; +}Signature · 1 line
2.30.2
Thanks
/Ilias
PATCH v6 7/14 net/lwip: implement ping cmd
In reply to Maxim UvarovImplement function for ping command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP. ping uses lwIP contrib/apps/ping/ping.c code.
--- include/net/lwip.h | 28 ++++++++++++++++++++++++- net/lwip/Makefile | 1 + net/lwip/apps/ping/Makefile | 11 ++++++++++ net/lwip/apps/ping/lwip_ping.c | 37 ++++++++++++++++++++++++++++++++++ net/lwip/apps/ping/lwip_ping.h | 15 ++++++++++++++ net/lwip/apps/ping/ping.h | 19 +++++++++++++++++ 6 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 net/lwip/apps/ping/Makefile create mode 100644 net/lwip/apps/ping/lwip_ping.c create mode 100644 net/lwip/apps/ping/lwip_ping.h create mode 100644 net/lwip/apps/ping/ping.h
include/net/lwip.h +27 -1
@@ -2,7 +2,8 @@int do_lwip_dns (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]); - +int do_lwip_ping (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]);/* * This function creates the DNS request to resolve a domain host name. Function * can return immediately if previous request was cached or it might require
@@ -38,3 +39,28 @@ int ulwip_dhcp(void);* !0 if error */ int ulwip_wget (ulong addr,char *url); + +/** +* ulwip_tftp() - load file with tftp +* +* Load file with tftp to specific address +* +* @param addr - address to store downloaded file +* @param filename - file name on remote tftp server to download +* +* +* @return 0 if success, !0 if error +*/ +int ulwip_tftp (ulong addr,const char *filename); + +/* +* This function creates the ping for address provided in parameters. +* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping (char *ping_addr);
net/lwip/Makefile +1 -0
@@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/
net/lwip/apps/ping/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include -I$(srctree)/net/lwip +ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c $(obj)/ping.c + +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o
net/lwip/apps/ping/lwip_ping.c new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo (void ) +{ + +log_err ("ping failed; host %s is not alive\n" ,ipaddr_ntoa (&ip_target)); +return 1 ; +} + +int ulwip_ping (char *ping_addr) +{ +int err; + + err =ipaddr_aton (ping_addr, &ip_target); +if (!err) { +log_err ("wrong ping addr string \"%s\" \n" , ping_addr); +return -1 ; + } + +ulwip_set_tmo (ulwip_ping_tmo); + +ping_init (&ip_target); +ping_send_now (); + +return 0 ; +}
net/lwip/apps/ping/lwip_ping.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include <lwip/ip_addr.h> + +void ping_raw_init (void ); +void ping_send_now (void ); + +#endif /* LWIP_PING_H */
net/lwip/apps/ping/ping.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <net/ulwip.h> +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1/* ping_time is under ifdef*/ +#define PING_RESULT (cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host %s in not alive\n",\ + ipaddr_ntoa(addr)); \ + ulwip_exit(-1); \ + } \ + } while (0); + +void ping_init (const ip_addr_t *ping_addr);
Signature · 1 line
2.30.2
Re: [PATCHv6 07/14] net/lwip: implement ping cmd
include/net/lwip.h int ulwip_dhcp(void); · line 49
Quoted 13 lines · Maxim Uvarov
* can return immediately if previous request was cached or it might require
include/net/lwip.h +8
-0@@ -38,3 +39,28 @@ int ulwip_dhcp(void);* !0 if error */ int ulwip_wget (ulong addr,char *url); + +/** +* ulwip_tftp() - load file with tftp +* +* Load file with tftp to specific address +* +* @param addr - address to store downloaded file +* @param filename - file name on remote tftp server to download
Please fix function comments properly
Quoted 68 lines
include/net/lwip.h +17
-0+* +* +* @return 0 if success, !0 if error +*/ +int ulwip_tftp (ulong addr,const char *filename); + +/* +* This function creates the ping for address provided in parameters. +* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping (char *ping_addr);net/lwip/Makefile +1
-0@@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/net/lwip/apps/ping/Makefile new file +11
-0@@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include -I$(srctree)/net/lwip +ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c $(obj)/ping.c + +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.onet/lwip/apps/ping/lwip_ping.c new file +17
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo (void ) +{ + +log_err ("ping failed; host %s is not alive\n" ,ipaddr_ntoa (&ip_target));
net/lwip/apps/ping/lwip_ping.c line 27
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return 1 ; +} + +int ulwip_ping (char *ping_addr) +{ +int err; + + err =ipaddr_aton (ping_addr, &ip_target); +if (!err) { +log_err ("wrong ping addr string \"%s\" \n" , ping_addr);
Invalid ip address is enough
Quoted 44 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return -1 ; + } + +ulwip_set_tmo (ulwip_ping_tmo); + +ping_init (&ip_target); +ping_send_now (); + +return 0 ; +}net/lwip/apps/ping/lwip_ping.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include <lwip/ip_addr.h> + +void ping_raw_init (void ); +void ping_send_now (void ); + +#endif /* LWIP_PING_H */ net/lwip/apps/ping/ping.h new file +7
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <net/ulwip.h> +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1/* ping_time is under ifdef*/ +#define PING_RESULT (cond) { \
net/lwip/apps/ping/ping.h line 17
Quoted 10 lines
net/lwip/apps/ping/ping.h new file +10
-0+if (cond ==1 ) { \ +printf ("host %s a alive\n" ,ipaddr_ntoa (addr)); \ +printf (" %" U32_F " ms\n" , (sys_now () - ping_time)); \ +ulwip_exit (0 ); \ + }else { \ +printf ("ping failed; host %s in not alive\n" ,\ +ipaddr_ntoa (addr)); \ +ulwip_exit (-1 ); \ + } \ + }while (0 );
On the previous patch you are defining a function to do something similar (httpc_result()). We need to be consistent on this. Can we define a common function for all failures? Certianly don't define a macro here and a function elsewhere
Quoted 5 lines
net/lwip/apps/ping/ping.h new file +2
-0+ +void ping_init (const ip_addr_t *ping_addr);Signature · 1 line
2.30.2
Thanks
/Ilias
Re: [PATCHv6 07/14] net/lwip: implement ping cmd
Quoted 155 lines · Ilias Apalodimas
Quoted 1 line · Maxim Uvarov
* can return immediately if previous request was cached or it might
require
include/net/lwip.h int ulwip_dhcp(void); · line 49
Quoted 12 lines
include/net/lwip.h +8
-0@@ -38,3 +39,28 @@ int ulwip_dhcp(void);* !0 if error */ int ulwip_wget (ulong addr,char *url); + +/** +* ulwip_tftp() - load file with tftp +* +* Load file with tftp to specific address +* +* @param addr - address to store downloaded file +* @param filename - file name on remote tftp server to download Please fix function comments properly
Quoted 34 lines
include/net/lwip.h +17
-0+* +* +* @return 0 if success, !0 if error +*/ +int ulwip_tftp (ulong addr,const char *filename); + +/* +* This function creates the ping for address provided in parameters. +* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping (char *ping_addr);net/lwip/Makefile +1
-0@@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/net/lwip/apps/ping/Makefile new file +0
-0net/lwip/apps/ping/Makefile line 2
Quoted 2 lines
net/lwip/apps/ping/Makefile new file +2
-0@@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include-I$(srctree)/net/lwip
net/lwip/apps/ping/Makefile
Quoted 6 lines
net/lwip/apps/ping/Makefile new file +6
-0+ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c$(obj)/ping.c
Review
Quoted 4 lines
net/lwip/apps/ping/Makefile new file +3
-0+ +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.cQuoted 12 lines
new file mode 100644
index 0000000000..611fcaf591net/lwip/apps/ping/lwip_ping.c new file +7
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include "lwip/opt.h" net/lwip/apps/ping/lwip_ping.c line 17
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo (void ) +{ + + log_err("ping failed; host %s is not alive\n",
ipaddr_ntoa(&ip_target));net/lwip/apps/ping/lwip_ping.c line 27
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return 1 ; +} + +int ulwip_ping (char *ping_addr) +{ +int err; + + err =ipaddr_aton (ping_addr, &ip_target); +if (!err) { +log_err ("wrong ping addr string \"%s\" \n" , ping_addr);Invalid ip address is enough
Review
Quoted 11 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return -1 ; + } + +ulwip_set_tmo (ulwip_ping_tmo); + +ping_init (&ip_target); +ping_send_now (); + +return 0 ; +}(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.hQuoted 40 lines
new file mode 100644
index 0000000000..0374f07d9enet/lwip/apps/ping/lwip_ping.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include <lwip/ip_addr.h> + +void ping_raw_init (void ); +void ping_send_now (void ); + +#endif /* LWIP_PING_H */ net/lwip/apps/ping/ping.h new file +14
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <net/ulwip.h> +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1/* ping_time is under ifdef*/ +#define PING_RESULT (cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host %s in not alive\n",\ + ipaddr_ntoa(addr)); \
Quoted 9 lines
net/lwip/apps/ping/ping.h line 17
Quoted 3 lines
net/lwip/apps/ping/ping.h new file +3
-0+ulwip_exit (-1 ); \ + } \ + }while (0 );On the previous patch you are defining a function to do something similar (
httpc_result()). We need to be consistent on this. Can we define a common function for all failures? Certianly don't define a macro here and a function elsewhere
Ilias, there I reuse lwip example ping.c. It has PING_RESULT which can be redefined by the application.
This is a way to not modify this original ping.c example code. The common part of this function and httpc_result() is ulwip_exit(err) with some additional print (print is differ).
BR,
Maxim.
Quoted 10 lines
Quoted 6 lines
net/lwip/apps/ping/ping.h new file +2
-1+ +void ping_init (const ip_addr_t *ping_addr); --2.30.2
Thanks
/Ilias
Re: [PATCHv6 07/14] net/lwip: implement ping cmd
Hi Maxim,
Quoted 169 lines · Maxim Uvarov
Quoted 155 lines · Ilias Apalodimas
Quoted 1 line · Maxim Uvarov
* can return immediately if previous request was cached or it might
require
include/net/lwip.h int ulwip_dhcp(void); · line 49
Quoted 12 lines
include/net/lwip.h +8
-0@@ -38,3 +39,28 @@ int ulwip_dhcp(void);* !0 if error */ int ulwip_wget (ulong addr,char *url); + +/** +* ulwip_tftp() - load file with tftp +* +* Load file with tftp to specific address +* +* @param addr - address to store downloaded file +* @param filename - file name on remote tftp server to download Please fix function comments properly
Quoted 34 lines
include/net/lwip.h +17
-0+* +* +* @return 0 if success, !0 if error +*/ +int ulwip_tftp (ulong addr,const char *filename); + +/* +* This function creates the ping for address provided in parameters. +* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping (char *ping_addr);net/lwip/Makefile +1
-0@@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/net/lwip/apps/ping/Makefile new file +0
-0net/lwip/apps/ping/Makefile line 2
Quoted 2 lines
net/lwip/apps/ping/Makefile new file +2
-0@@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include-I$(srctree)/net/lwip
net/lwip/apps/ping/Makefile
Quoted 6 lines
net/lwip/apps/ping/Makefile new file +6
-0+ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c$(obj)/ping.c
Review
Quoted 4 lines
net/lwip/apps/ping/Makefile new file +3
-0+ +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.cQuoted 12 lines
new file mode 100644
index 0000000000..611fcaf591net/lwip/apps/ping/lwip_ping.c new file +7
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include "lwip/opt.h" net/lwip/apps/ping/lwip_ping.c line 17
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo (void ) +{ + + log_err("ping failed; host %s is not alive\n",
ipaddr_ntoa(&ip_target));net/lwip/apps/ping/lwip_ping.c line 27
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return 1 ; +} + +int ulwip_ping (char *ping_addr) +{ +int err; + + err =ipaddr_aton (ping_addr, &ip_target); +if (!err) { +log_err ("wrong ping addr string \"%s\" \n" , ping_addr);Invalid ip address is enough
Review
Quoted 11 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return -1 ; + } + +ulwip_set_tmo (ulwip_ping_tmo); + +ping_init (&ip_target); +ping_send_now (); + +return 0 ; +}(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.hQuoted 40 lines
new file mode 100644
index 0000000000..0374f07d9enet/lwip/apps/ping/lwip_ping.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include <lwip/ip_addr.h> + +void ping_raw_init (void ); +void ping_send_now (void ); + +#endif /* LWIP_PING_H */ net/lwip/apps/ping/ping.h new file +14
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <net/ulwip.h> +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1/* ping_time is under ifdef*/ +#define PING_RESULT (cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host %s in not alive\n",\ + ipaddr_ntoa(addr)); \Quoted 9 lines
net/lwip/apps/ping/ping.h line 17
Quoted 3 lines
net/lwip/apps/ping/ping.h new file +3
-0+ulwip_exit (-1 ); \ + } \ + }while (0 );On the previous patch you are defining a function to do something similar (
httpc_result()). We need to be consistent on this. Can we define a common function for all failures? Certianly don't define a macro here and a function elsewhere
Quoted 5 lines
Ilias, there I reuse lwip example
ping.c. It hasPING_RESULTwhich can be redefined by the application.
This is a way to not modify this originalping.cexample code. The common part of this function andhttpc_result()isulwip_exit(err)with some additional print (print is differ).
I'll reply on this patch, although it is a general comment.
I would like to see if we can use the cyclic feature to allow network operations to happen in the background. This would involve splitting each operation into:
- setup start and kick off, e.g. ping_sttart()
- checking what needs doing, e.g. ping_poll()
- finish and clean-up, e.g. ping_finish()
So something like:
ping -B 1.2.3.4
(-B is background)
That would fire off the packet but immediately return with a prompt. When the pings are received they would show on the console, with a new prompt displayed. The same for tftp -B...it would start the transfer but allow other commands to be sent while it is in progress.
Part of the reason for this is that when booting there are a lot of operations which take a long time and nothing happens until everything is done. For example, with standard boot, mmc devices can be shown right away, but USB and network ones take a lot longer, so having OS's on those devices appear later on the slower devices is desirable for the user.
Is this something that lwip can support? It is one reason why I have advocating putting the state in a struct instead of having a lot of separate vars.
Regards,
Simon
Re: [PATCHv6 07/14] net/lwip: implement ping cmd
Quoted 213 lines · Simon Glass
Hi Maxim,
Quoted 2 lines · Maxim Uvarov
On Wed, 16 Aug 2023 at 14:42, Ilias Apalodimas <
Quoted 20 lines
Quoted 18 lines · wrote:
Quoted 1 line · Maxim Uvarov
* can return immediately if previous request was cached or it might
require
include/net/lwip.h int ulwip_dhcp(void); · line 49
Quoted 12 lines
include/net/lwip.h +8
-0@@ -38,3 +39,28 @@ int ulwip_dhcp(void);* !0 if error */ int ulwip_wget (ulong addr,char *url); + +/** +* ulwip_tftp() - load file with tftp +* +* Load file with tftp to specific address +* +* @param addr - address to store downloaded file +* @param filename - file name on remote tftp server to download Please fix function comments properly
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int ulwip_dhcp(void);
Quoted 8 lines
include/net/lwip.h +8
-0+* +* +* @return 0 if success, !0 if error +*/ +int ulwip_tftp (ulong addr,const char *filename); + +/* +* This function creates the ping for address provided in parameters.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
include/net/lwip.h +9
-0+* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping (char *ping_addr);net/lwip/Makefile +0
-0@@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.oQuoted 6 lines
Quoted 6 lines
Review
Quoted 6 lines
net/lwip/Makefile +1
-0obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/(quoted diff) +0
-0b/net/lwip/apps/ping/Makefile
Quoted 105 lines
Quoted 105 lines
net/lwip/apps/ping/Makefile line 2
Quoted 7 lines
new file mode 100644
index 0000000000..dc63feb7b5net/lwip/apps/ping/Makefile new file +2
-0@@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include-I$(srctree)/net/lwip
net/lwip/apps/ping/Makefile
Quoted 6 lines
net/lwip/apps/ping/Makefile new file +6
-0+ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c$(obj)/ping.c
Review
Quoted 4 lines
net/lwip/apps/ping/Makefile new file +3
-0+ +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.cQuoted 12 lines
new file mode 100644
index 0000000000..611fcaf591net/lwip/apps/ping/lwip_ping.c new file +7
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include "lwip/opt.h" net/lwip/apps/ping/lwip_ping.c line 17
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo (void ) +{ + + log_err("ping failed; host %s is not alive\n",
ipaddr_ntoa(&ip_target));net/lwip/apps/ping/lwip_ping.c line 27
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return 1 ; +} + +int ulwip_ping (char *ping_addr) +{ +int err; + + err =ipaddr_aton (ping_addr, &ip_target); +if (!err) { +log_err ("wrong ping addr string \"%s\" \n" , ping_addr);Invalid ip address is enough
Review
Quoted 11 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return -1 ; + } + +ulwip_set_tmo (ulwip_ping_tmo); + +ping_init (&ip_target); +ping_send_now (); + +return 0 ; +}(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.hQuoted 37 lines
new file mode 100644
index 0000000000..0374f07d9enet/lwip/apps/ping/lwip_ping.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include <lwip/ip_addr.h> + +void ping_raw_init (void ); +void ping_send_now (void ); + +#endif /* LWIP_PING_H */ net/lwip/apps/ping/ping.h new file +11
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <net/ulwip.h> +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1/* ping_time is under ifdef*/ +#define PING_RESULT (cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \Quoted 8 lines
Quoted 8 lines
net/lwip/apps/ping/ping.h line 17
Quoted 6 lines
net/lwip/apps/ping/ping.h new file +6
-0+ }else { \ +printf ("ping failed; host %s in not alive\n" ,\ +ipaddr_ntoa (addr)); \ +ulwip_exit (-1 ); \ + } \ + }while (0 );On the previous patch you are defining a function to do something
similar
Quoted 2 lines
Quoted 2 lines
(
httpc_result()). We need to be consistent on this. Can we define a common function for all failures? Certianly don't define a macro hereand
Quoted 7 lines
Quoted 2 lines
a function elsewhere
Ilias, there I reuse lwip example
ping.c. It hasPING_RESULTwhich can be redefined by the application.
This is a way to not modify this originalping.cexample code. The common part of this function andhttpc_result()isulwip_exit(err)with
Quoted 1 line
some additional print (print is differ).
I'll reply on this patch, although it is a general comment.
I would like to see if we can use the cyclic feature to allow network operations to happen in the background. This would involve splitting each operation into:
- setup start and kick off, e.g.
ping_sttart()
- checking what needs doing, e.g.ping_poll()
- finish and clean-up, e.g.ping_finish()So something like:
ping -B 1.2.3.4
(-B is background)
That would fire off the packet but immediately return with a prompt. When the pings are received they would show on the console, with a new prompt displayed. The same for tftp -B...it would start the transfer but allow other commands to be sent while it is in progress.
Part of the reason for this is that when booting there are a lot of operations which take a long time and nothing happens until everything is done. For example, with standard boot, mmc devices can be shown right away, but USB and network ones take a lot longer, so having OS's on those devices appear later on the slower devices is desirable for the user.
Quoted 7 lines
Is this something that lwip can support? It is one reason why I have advocating putting the state in a struct instead of having a lot of separate vars.
Regards,
Simon
This functionality can be added. I do not see any restrictions implementing that.
Added I mean to U-Boot. lwip will definitely work with it.
There is no specific poll() for application. Application just do init() and request
the needed packets (port, type etc, like sockets) and then common lwip poll()
function is called.
To implement background we need to periodically call eth_rx() and ulwip_poll() to feed lwip
stack with rx packets when we are in the cmd shell. I see in some places we call schedule()
to reprogram wdt, if we call rx polling loop in the similar way the app will work in the background.
We might also want to support 2 applications at the same time. Like a telnet server
and ping. Multiply applications also work with lwip.
Even parallel download can save some time:
wget -B http://url1/zImage
wget -B http//url2/dtb
(-B = background)
But I'm thinking if we can implement background in a more generic way in U-Boot cmd. Things like
mount UBI fs, or download from SPI flash is slow. Or probably we can also do some loading while
verifying the zImage checksum.
BR,
Maxim.
Re: [PATCHv6 07/14] net/lwip: implement ping cmd
Hi Maxim,
Quoted 8 lines · Maxim Uvarov
Quoted 4 lines · Simon Glass
Hi Maxim,
On Wed, 16 Aug 2023 at 03:09, Maxim Uvarov <[email protected]>
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
On Wed, 16 Aug 2023 at 14:42, Ilias Apalodimas <
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
* can return immediately if previous request was cached or it
might
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
require
include/net/lwip.h int ulwip_dhcp(void); · line 49
Quoted 12 lines
include/net/lwip.h +8
-0@@ -38,3 +39,28 @@ int ulwip_dhcp(void);* !0 if error */ int ulwip_wget (ulong addr,char *url); + +/** +* ulwip_tftp() - load file with tftp +* +* Load file with tftp to specific address +* +* @param addr - address to store downloaded file +* @param filename - file name on remote tftp server to download Please fix function comments properly
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int ulwip_dhcp(void);
Quoted 8 lines
include/net/lwip.h +8
-0+* +* +* @return 0 if success, !0 if error +*/ +int ulwip_tftp (ulong addr,const char *filename); + +/* +* This function creates the ping for address provided in
parameters.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
include/net/lwip.h +9
-0+* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping (char *ping_addr);net/lwip/Makefile +0
-0@@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.o
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 6 lines
net/lwip/Makefile +1
-0obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/(quoted diff) +0
-0
b/net/lwip/apps/ping/Makefile
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
net/lwip/apps/ping/Makefile line 2
Quoted 7 lines
new file mode 100644
index 0000000000..dc63feb7b5net/lwip/apps/ping/Makefile new file +2
-0@@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include-I$(srctree)/net/lwip
net/lwip/apps/ping/Makefile
Quoted 6 lines
net/lwip/apps/ping/Makefile new file +6
-0+ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c$(obj)/ping.c
Review
Quoted 4 lines
net/lwip/apps/ping/Makefile new file +3
-0+ +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.cQuoted 12 lines
new file mode 100644
index 0000000000..611fcaf591net/lwip/apps/ping/lwip_ping.c new file +7
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include "lwip/opt.h" net/lwip/apps/ping/lwip_ping.c line 17
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo (void ) +{ + + log_err("ping failed; host %s is not alive\n",
ipaddr_ntoa(&ip_target));
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return 1 ; +} + +int ulwip_ping (char *ping_addr) +{ +int err; + + err =ipaddr_aton (ping_addr, &ip_target); +if (!err) { + log_err("wrong ping addr string \"%s\" \n",
ping_addr);
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Invalid ip address is enough
Review
Quoted 11 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return -1 ; + } + +ulwip_set_tmo (ulwip_ping_tmo); + +ping_init (&ip_target); +ping_send_now (); + +return 0 ; +}(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.hQuoted 37 lines
new file mode 100644
index 0000000000..0374f07d9enet/lwip/apps/ping/lwip_ping.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include <lwip/ip_addr.h> + +void ping_raw_init (void ); +void ping_send_now (void ); + +#endif /* LWIP_PING_H */ net/lwip/apps/ping/ping.h new file +11
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <net/ulwip.h> +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1/* ping_time is under ifdef*/ +#define PING_RESULT (cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/lwip/apps/ping/ping.h line 17
Quoted 6 lines
net/lwip/apps/ping/ping.h new file +6
-0+ }else { \ +printf ("ping failed; host %s in not alive\n" ,\ +ipaddr_ntoa (addr)); \ +ulwip_exit (-1 ); \ + } \ + }while (0 );On the previous patch you are defining a function to do something
similar
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(
httpc_result()). We need to be consistent on this. Can we define a common function for all failures? Certianly don't define a macro
here and
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
a function elsewhere
Ilias, there I reuse lwip example
ping.c. It hasPING_RESULTwhich can
be
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
redefined by the application.
This is a way to not modify this originalping.cexample code. The common part of this function andhttpc_result()isulwip_exit(err)
with
Quoted 34 lines
Quoted 34 lines
Quoted 1 line
some additional print (print is differ).
I'll reply on this patch, although it is a general comment.
I would like to see if we can use the cyclic feature to allow network operations to happen in the background. This would involve splitting each operation into:
- setup start and kick off, e.g.
ping_sttart()
- checking what needs doing, e.g.ping_poll()
- finish and clean-up, e.g.ping_finish()So something like:
ping -B 1.2.3.4
(-B is background)
That would fire off the packet but immediately return with a prompt. When the pings are received they would show on the console, with a new prompt displayed. The same for tftp -B...it would start the transfer but allow other commands to be sent while it is in progress.
Part of the reason for this is that when booting there are a lot of operations which take a long time and nothing happens until everything is done. For example, with standard boot, mmc devices can be shown right away, but USB and network ones take a lot longer, so having OS's on those devices appear later on the slower devices is desirable for the user.
Is this something that lwip can support? It is one reason why I have advocating putting the state in a struct instead of having a lot of separate vars.
Quoted 5 lines
Quoted 2 lines
Regards,
SimonThis functionality can be added. I do not see any restrictions
implementing that.
Quoted 3 lines
Added I mean to U-Boot. lwip will definitely work with it.
There is no specific
poll()for application. Application just doinit()
and request
Quoted 1 line
the needed packets (port, type etc, like sockets) and then common lwip
poll()
Quoted 3 lines
function is called.
To implement background we need to periodically call
eth_rx()and
ulwip_poll() to feed lwip
Quoted 1 line
stack with rx packets when we are in the cmd shell. I see in some places
we call schedule()
Quoted 1 line
to reprogram wdt, if we call rx polling loop in the similar way the app
will work in the background.
Quoted 2 lines
We might also want to support 2 applications at the same time. Like a
telnet server
Quoted 8 lines
and ping. Multiply applications also work with lwip.
Even parallel download can save some time:
wget -B http://url1/zImage
wget -B http//url2/dtb
(-B = background)But I'm thinking if we can implement background in a more generic way in
U-Boot cmd. Things like
Quoted 1 line
mount UBI fs, or download from SPI flash is slow. Or probably we can also
do some loading while
Quoted 1 line
verifying the zImage checksum.
Yes, perhaps we can keep a record of the command that is running, with a little bit of state there. But does the stack support two wgets at once?
Regards,
Simon
Re: [PATCHv6 07/14] net/lwip: implement ping cmd
Quoted 264 lines · Simon Glass
Hi Maxim,
Quoted 8 lines · Maxim Uvarov
Quoted 4 lines · Simon Glass
Hi Maxim,
On Wed, 16 Aug 2023 at 03:09, Maxim Uvarov <[email protected]>
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
On Wed, 16 Aug 2023 at 14:42, Ilias Apalodimas <
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Maxim Uvarov
* can return immediately if previous request was cached or it
might
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
require
include/net/lwip.h int ulwip_dhcp(void); · line 49
Quoted 12 lines
include/net/lwip.h +8
-0@@ -38,3 +39,28 @@ int ulwip_dhcp(void);* !0 if error */ int ulwip_wget (ulong addr,char *url); + +/** +* ulwip_tftp() - load file with tftp +* +* Load file with tftp to specific address +* +* @param addr - address to store downloaded file +* @param filename - file name on remote tftp server to download Please fix function comments properly
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/net/lwip.h int ulwip_dhcp(void);
Quoted 8 lines
include/net/lwip.h +8
-0+* +* +* @return 0 if success, !0 if error +*/ +int ulwip_tftp (ulong addr,const char *filename); + +/* +* This function creates the ping for address provided in parameters.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
include/net/lwip.h +9
-0+* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping (char *ping_addr);net/lwip/Makefile +0
-0@@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.oQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 6 lines
net/lwip/Makefile +1
-0obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/(quoted diff) +0
-0b/net/lwip/apps/ping/Makefile
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/lwip/apps/ping/Makefile line 2
Quoted 7 lines
new file mode 100644
index 0000000000..dc63feb7b5net/lwip/apps/ping/Makefile new file +2
-0@@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include-I$(srctree)/net/lwip
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
net/lwip/apps/ping/Makefile
Quoted 6 lines
net/lwip/apps/ping/Makefile new file +6
-0+ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp$(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
$(obj)/ping.c
Review
Quoted 4 lines
net/lwip/apps/ping/Makefile new file +3
-0+ +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.cQuoted 12 lines
new file mode 100644
index 0000000000..611fcaf591net/lwip/apps/ping/lwip_ping.c new file +7
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include "lwip/opt.h" net/lwip/apps/ping/lwip_ping.c line 17
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo (void ) +{ + + log_err("ping failed; host %s is not alive\n",
ipaddr_ntoa(&ip_target));Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return 1 ; +} + +int ulwip_ping (char *ping_addr) +{ +int err; + + err =ipaddr_aton (ping_addr, &ip_target); +if (!err) { + log_err("wrong ping addr string \"%s\" \n",
ping_addr);Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Invalid ip address is enough
Review
Quoted 11 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return -1 ; + } + +ulwip_set_tmo (ulwip_ping_tmo); + +ping_init (&ip_target); +ping_send_now (); + +return 0 ; +}(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.hQuoted 37 lines
new file mode 100644
index 0000000000..0374f07d9enet/lwip/apps/ping/lwip_ping.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include <lwip/ip_addr.h> + +void ping_raw_init (void ); +void ping_send_now (void ); + +#endif /* LWIP_PING_H */ net/lwip/apps/ping/ping.h new file +11
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <net/ulwip.h> +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1/* ping_time is under ifdef*/ +#define PING_RESULT (cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/lwip/apps/ping/ping.h line 17
Quoted 6 lines
net/lwip/apps/ping/ping.h new file +6
-0+ }else { \ +printf ("ping failed; host %s in not alive\n" ,\ +ipaddr_ntoa (addr)); \ +ulwip_exit (-1 ); \ + } \ + }while (0 );On the previous patch you are defining a function to do something
similar
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(
httpc_result()). We need to be consistent on this. Can we definea
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
common function for all failures? Certianly don't define a macro
here and
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
a function elsewhere
Ilias, there I reuse lwip example
ping.c. It hasPING_RESULTwhichcan be
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
redefined by the application.
This is a way to not modify this originalping.cexample code. The common part of this function andhttpc_result()is
ulwip_exit(err)withQuoted 34 lines
Quoted 34 lines
Quoted 1 line
some additional print (print is differ).
I'll reply on this patch, although it is a general comment.
I would like to see if we can use the cyclic feature to allow network operations to happen in the background. This would involve splitting each operation into:
- setup start and kick off, e.g.
ping_sttart()
- checking what needs doing, e.g.ping_poll()
- finish and clean-up, e.g.ping_finish()So something like:
ping -B 1.2.3.4
(-B is background)
That would fire off the packet but immediately return with a prompt. When the pings are received they would show on the console, with a new prompt displayed. The same for tftp -B...it would start the transfer but allow other commands to be sent while it is in progress.
Part of the reason for this is that when booting there are a lot of operations which take a long time and nothing happens until everything is done. For example, with standard boot, mmc devices can be shown right away, but USB and network ones take a lot longer, so having OS's on those devices appear later on the slower devices is desirable for the user.
Is this something that lwip can support? It is one reason why I have advocating putting the state in a struct instead of having a lot of separate vars.
Quoted 5 lines
Quoted 2 lines
Regards,
SimonThis functionality can be added. I do not see any restrictions
implementing that.
Quoted 3 lines
Added I mean to U-Boot. lwip will definitely work with it.
There is no specific
poll()for application. Application just doinit()and request
Quoted 1 line
the needed packets (port, type etc, like sockets) and then common lwip
poll()Quoted 3 lines
function is called.
To implement background we need to periodically call
eth_rx()and
ulwip_poll()to feed lwipQuoted 1 line
stack with rx packets when we are in the cmd shell. I see in some places
we call
schedule()Quoted 1 line
to reprogram wdt, if we call rx polling loop in the similar way the app
will work in the background.
Quoted 2 lines
We might also want to support 2 applications at the same time. Like a
telnet server
Quoted 8 lines
and ping. Multiply applications also work with lwip.
Even parallel download can save some time:
wget -B http://url1/zImage
wget -B http//url2/dtb
(-B = background)But I'm thinking if we can implement background in a more generic way
in U-Boot cmd. Things like
Quoted 1 line
mount UBI fs, or download from SPI flash is slow. Or probably we can
Quoted 9 lines
also do some loading while
Quoted 1 line
verifying the zImage checksum.
Yes, perhaps we can keep a record of the command that is running, with a little bit of state there. But does the stack support two wgets at once?
Regards,
Simon
Yes, it's a complete stack and it supports multiple networking applications.
Re: [PATCHv6 07/14] net/lwip: implement ping cmd
Hi Maxim,
Quoted 250 lines · Maxim Uvarov
Quoted 246 lines · Simon Glass
Hi Maxim,
Quoted 241 lines · Maxim Uvarov
Quoted 207 lines · Simon Glass
Hi Maxim,
Quoted 169 lines · Maxim Uvarov
Quoted 155 lines · Ilias Apalodimas
Quoted 1 line · Maxim Uvarov
* can return immediately if previous request was cached or it might
require
Review int ulwip_dhcp(void); · line 49
Quoted 12 lines
(quoted diff) +8
-0@@ -38,3 +39,28 @@ int ulwip_dhcp(void); * !0 if error */ int ulwip_wget(ulong addr, char *url); + +/** + * ulwip_tftp() - load file with tftp + * + * Load file with tftp to specific address + * + * @param addr - address to store downloaded file + * @param filename - file name on remote tftp server to downloadPlease fix function comments properly
Quoted 34 lines
(quoted diff) +17
-0+ * + * + * @return 0 if success, !0 if error + */ +int ulwip_tftp(ulong addr, const char *filename); + +/* +* This function creates the ping for address provided in parameters. +* After this function you need to invoke the polling +* loop to process network communication. +* +* +* @ping_addr start address to download result +* Return: 0 for success +* !0 if error +*/ +int ulwip_ping(char *ping_addr);net/lwip/Makefile +1
-0@@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/net/lwip/apps/ping/Makefile new file +0
-0net/lwip/apps/ping/Makefile line 2
Quoted 2 lines
net/lwip/apps/ping/Makefile new file +2
-0@@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include-I$(srctree)/net/lwip
net/lwip/apps/ping/Makefile line 8
Quoted 6 lines
net/lwip/apps/ping/Makefile new file +6
-0+ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c$(obj)/ping.c
Review
Quoted 4 lines
net/lwip/apps/ping/Makefile new file +3
-0+ +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.cQuoted 12 lines
new file mode 100644
index 0000000000..611fcaf591net/lwip/apps/ping/lwip_ping.c new file +7
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include "lwip/opt.h" net/lwip/apps/ping/lwip_ping.c line 17
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+#include "lwip/ip_addr.h" +#include "ping.h" +#include "lwip_ping.h" + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo (void ) +{ + + log_err("ping failed; host %s is not alive\n",
ipaddr_ntoa(&ip_target));net/lwip/apps/ping/lwip_ping.c line 27
Quoted 10 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return 1 ; +} + +int ulwip_ping (char *ping_addr) +{ +int err; + + err =ipaddr_aton (ping_addr, &ip_target); +if (!err) { +log_err ("wrong ping addr string \"%s\" \n" , ping_addr);Invalid ip address is enough
Review
Quoted 11 lines
net/lwip/apps/ping/lwip_ping.c new file +10
-0+return -1 ; + } + +ulwip_set_tmo (ulwip_ping_tmo); + +ping_init (&ip_target); +ping_send_now (); + +return 0 ; +}(quoted diff) +0
-0
b/net/lwip/apps/ping/lwip_ping.hQuoted 40 lines
new file mode 100644
index 0000000000..0374f07d9enet/lwip/apps/ping/lwip_ping.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include <lwip/ip_addr.h> + +void ping_raw_init (void ); +void ping_send_now (void ); + +#endif /* LWIP_PING_H */ net/lwip/apps/ping/ping.h new file +14
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <net/ulwip.h> +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1/* ping_time is under ifdef*/ +#define PING_RESULT (cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host %s in not alive\n",\ + ipaddr_ntoa(addr)); \Quoted 9 lines
net/lwip/apps/ping/ping.h line 17
Quoted 3 lines
net/lwip/apps/ping/ping.h new file +3
-0+ulwip_exit (-1 ); \ + } \ + }while (0 );On the previous patch you are defining a function to do something similar (
httpc_result()). We need to be consistent on this. Can we define a common function for all failures? Certianly don't define a macro here and a function elsewhereQuoted 5 lines
Ilias, there I reuse lwip example
ping.c. It hasPING_RESULTwhich can be redefined by the application.
This is a way to not modify this originalping.cexample code. The common part of this function andhttpc_result()isulwip_exit(err)with some additional print (print is differ).I'll reply on this patch, although it is a general comment.
I would like to see if we can use the cyclic feature to allow network operations to happen in the background. This would involve splitting each operation into:
- setup start and kick off, e.g.
ping_sttart()
- checking what needs doing, e.g.ping_poll()
- finish and clean-up, e.g.ping_finish()So something like:
ping -B 1.2.3.4
(-B is background)
That would fire off the packet but immediately return with a prompt. When the pings are received they would show on the console, with a new prompt displayed. The same for tftp -B...it would start the transfer but allow other commands to be sent while it is in progress.
Part of the reason for this is that when booting there are a lot of operations which take a long time and nothing happens until everything is done. For example, with standard boot, mmc devices can be shown right away, but USB and network ones take a lot longer, so having OS's on those devices appear later on the slower devices is desirable for the user.
Quoted 6 lines
Is this something that lwip can support? It is one reason why I have advocating putting the state in a struct instead of having a lot of separate vars.
Regards,
SimonThis functionality can be added. I do not see any restrictions implementing that. Added I mean to U-Boot. lwip will definitely work with it.
There is no specific
poll()for application. Application just doinit()and request the needed packets (port, type etc, like sockets) and then common lwippoll()function is called.To implement background we need to periodically call
eth_rx()andulwip_poll()to feed lwip stack with rx packets when we are in the cmd shell. I see in some places we callschedule()to reprogram wdt, if we call rx polling loop in the similar way the app will work in the background.We might also want to support 2 applications at the same time. Like a telnet server and ping. Multiply applications also work with lwip.
Even parallel download can save some time:
wget -B http://url1/zImage
wget -B http//url2/dtb
(-B = background)But I'm thinking if we can implement background in a more generic way in U-Boot cmd. Things like mount UBI fs, or download from SPI flash is slow. Or probably we can also do some loading while verifying the zImage checksum.
Quoted 7 lines
Quoted 4 lines
Yes, perhaps we can keep a record of the command that is running, with a little bit of state there. But does the stack support two wgets at once?
Regards,
SimonYes, it's a complete stack and it supports multiple networking applications.
Really what I meant was whether it can support several operations at once, based on how you have integrated it into U-Boot, but I suspect the answer is yes.
Regards,
Simon
PATCH v6 8/14 net/lwip: add lwIP configuration
In reply to Maxim Uvarovlwip configuration can be tuned with header file.
--- net/lwip/lwipopts.h | 195 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 net/lwip/lwipopts.h
net/lwip/lwipopts.h new file +195 -0
@@ -0,0 +1,195 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_LWIPOPTS_H +#define LWIP_LWIPOPTS_H + +#include "lwipopts.h" + +#if defined(CONFIG_LWIP_LIB_DEBUG ) +#define LWIP_DEBUG 1 +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#define LWIP_DBG_TYPES_ON LWIP_DBG_ON +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_ON +#define AUTOIP_DEBUG LWIP_DBG_ON +#define DNS_DEBUG LWIP_DBG_ON +#define IP6_DEBUG LWIP_DBG_OFF +#define DHCP6_DEBUG LWIP_DBG_OFF +#else +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF +#define AUTOIP_DEBUG LWIP_DBG_OFF +#define DNS_DEBUG LWIP_DBG_OFF +#define IP6_DEBUG LWIP_DBG_OFF +#define DHCP6_DEBUG LWIP_DBG_OFF +#endif +#define LWIP_TESTMODE 0 + +#if defined(CONFIG_LWIP_LIB_NOASSERT ) +#define LWIP_NOASSERT 1 +#define LWIP_ASSERT (message, assertion) +#endif + +#include "lwip/debug.h" + +#define SYS_LIGHTWEIGHT_PROT 0 +#define NO_SYS 0 + +#define LWIP_IPV6 0 + +#define MEM_ALIGNMENT 1 +#define MEM_SIZE 1600 + +#define MEMP_NUM_PBUF 4 +#define MEMP_NUM_RAW_PCB 2 +#define MEMP_NUM_UDP_PCB 4 +#define MEMP_NUM_TCP_PCB 2 +#define MEMP_NUM_TCP_PCB_LISTEN 2 +#define MEMP_NUM_TCP_SEG 16 +#define MEMP_NUM_REASSDATA 1 +#define MEMP_NUM_ARP_QUEUE 2 +#define MEMP_NUM_SYS_TIMEOUT 4 +#define MEMP_NUM_NETBUF 2 +#define MEMP_NUM_NETCONN 32 +#define MEMP_NUM_TCPIP_MSG_API 8 +#define MEMP_NUM_TCPIP_MSG_INPKT 8 +#define PBUF_POOL_SIZE 8 + +#define LWIP_ARP 1 + +#define IP_FORWARD 0 +#define IP_OPTIONS_ALLOWED 1 +#define IP_REASSEMBLY 1 +#define IP_FRAG 1 +#define IP_REASS_MAXAGE 3 +#define IP_REASS_MAX_PBUFS 4 +#define IP_FRAG_USES_STATIC_BUF 0 + +#define IP_DEFAULT_TTL 255 + +#define LWIP_ICMP 1 + +#define LWIP_RAW 1 + +#if defined(CONFIG_LWIP_LIB_DHCP ) +#define LWIP_DHCP 1 +#define LWIP_DHCP_BOOTP_FILE 1 +#else +#define LWIP_DHCP 0 +#endif +#define LWIP_DHCP_DOES_ACD_CHECK 0 + +#define LWIP_AUTOIP 0 + +#define LWIP_SNMP 0 + +#define LWIP_IGMP 0 + +#if defined(CONFIG_LWIP_LIB_DNS ) +#define LWIP_DNS 1 +#else +#define LWIP_DNS 0 +#endif + +#if defined(CONFIG_LWIP_LIB_TCP ) +#define LWIP_UDP 1 +#else +#define LWIP_UDP 0 +#endif + +#if defined(CONFIG_LWIP_LIB_TCP ) +#define LWIP_TCP 1 +#else +#define LWIP_TCP 0 +#endif + +#define LWIP_LISTEN_BACKLOG 0 + +#define PBUF_LINK_HLEN 14 +#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_HLEN) + +#define LWIP_HAVE_LOOPIF 0 + +#define LWIP_NETCONN 0 +#define LWIP_DISABLE_MEMP_SANITY_CHECKS 1 + +#define LWIP_SOCKET 0 +#define SO_REUSE 0 + +#define LWIP_STATS 0 + +#define PPP_SUPPORT 0 + +#define LWIP_TCPIP_CORE_LOCKING 0 + +#if defined(CONFIG_LWIP_LIB_LOOPBACK ) +#define LWIP_NETIF_LOOPBACK 1 +#else +#define LWIP_NETIF_LOOPBACK 0 +#endif +/* use malloc instead of pool */ +#define MEMP_MEM_MALLOC 1 +#define MEMP_MEM_INIT 1 +#define MEM_LIBC_MALLOC 1 + +#endif /* LWIP_LWIPOPTS_H */
Signature · 1 line
2.30.2
PATCH v6 9/14 net/lwip: implement lwIP port to U-Boot
In reply to Maxim UvarovImplement network lwIP interface connected to the U-boot. Keep original file structure widely used fro lwIP ports. (i.e. port/if.c port/sys-arch.c).
--- net/eth-uclass.c | 8 + net/lwip/port/if.c | 260 ++++++++++++++++++++++++++ net/lwip/port/include/arch/cc.h | 39 ++++ net/lwip/port/include/arch/sys_arch.h | 56 ++++++ net/lwip/port/include/limits.h | 0 net/lwip/port/sys-arch.c | 20 ++ 6 files changed, 383 insertions(+) create mode 100644 net/lwip/port/if.c create mode 100644 net/lwip/port/include/arch/cc.h create mode 100644 net/lwip/port/include/arch/sys_arch.h create mode 100644 net/lwip/port/include/limits.h create mode 100644 net/lwip/port/sys-arch.c
net/eth-uclass.c +8 -0
@@ -32,6 +32,7 @@ DECLARE_GLOBAL_DATA_PTR;struct eth_device_priv {enum eth_state_t state;bool running; +ulwip ulwip; };/**
@@ -347,6 +348,13 @@ int eth_init(void)return ret; } +struct ulwip *eth_lwip_priv (struct udevice *current) +{ +struct eth_device_priv *priv =dev_get_uclass_priv (current); + +return &priv->ulwip; +} +void eth_halt (void ) {struct udevice *current;
net/lwip/port/if.c new file +260 -0
260 lines not on this page · raw message
net/lwip/port/include/arch/cc.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_ARCH_CC_H +#define LWIP_ARCH_CC_H + +#include <linux/types.h> +#include <linux/kernel.h> +//#include <stdlib.h> /* getenv, atoi */ +#include <vsprintf.h> + +#define LWIP_ERRNO_INCLUDE <errno.h> + +#define LWIP_ERRNO_STDINCLUDE 1 +#define LWIP_NO_UNISTD_H 1 +#define LWIP_TIMEVAL_PRIVATE 1 + +extern unsigned int lwip_port_rand (void ); +#define LWIP_RAND () (lwip_port_rand()) + +/* different handling for unit test, normally not needed */ +#ifdef LWIP_NOASSERT_ON_ERROR +#define LWIP_ERROR (message, expression, handler) do { if (!(expression)) { \ + handler; }} while (0) +#endif + +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS + +#define LWIP_PLATFORM_ASSERT (x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ + x, __LINE__, __FILE__); } while (0) + +#define atoi (str) (int)dectoul(str, NULL) + +#define LWIP_ERR_T int + +#endif /* LWIP_ARCH_CC_H */
net/lwip/port/include/arch/sys_arch.h new file +56 -0
56 lines not on this page · raw message
net/lwip/port/include/limits.h new file +0 -0
net/lwip/port/sys-arch.c new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <rand.h> +#include "lwip/opt.h" + +u32_t sys_now (void ) +{ +return get_timer (0 ); +} + +u32_t lwip_port_rand (void ) +{ +return (u32_t )rand (); +} +
Signature · 1 line
2.30.2
Re: [PATCHv6 09/14] net/lwip: implement lwIP port to U-Boot
Quoted 3 lines · Maxim Uvarov
Implement network lwIP interface connected to the U-boot. Keep original file structure widely used fro lwIP ports. (i.e.
port/if.cport/sys-arch.c).
What the patch does is obvious. Try to describe *why* we need this
Quoted 62 lines
Signed-off-by Maxim Uvarov <[email protected]>--- net/eth-uclass.c | 8 + net/lwip/port/if.c | 260 ++++++++++++++++++++++++++ net/lwip/port/include/arch/cc.h | 39 ++++ net/lwip/port/include/arch/sys_arch.h | 56 ++++++ net/lwip/port/include/limits.h | 0 net/lwip/port/sys-arch.c | 20 ++ 6 files changed, 383 insertions(+) create mode 100644 net/lwip/port/if.c create mode 100644 net/lwip/port/include/arch/cc.h create mode 100644 net/lwip/port/include/arch/sys_arch.h create mode 100644 net/lwip/port/include/limits.h create mode 100644 net/lwip/port/sys-arch.cnet/eth-uclass.c +8
-0@@ -32,6 +32,7 @@ DECLARE_GLOBAL_DATA_PTR;struct eth_device_priv {enum eth_state_t state;bool running; +ulwip ulwip; };/** @@ -347,6 +348,13 @@ int eth_init(void)return ret; } +struct ulwip *eth_lwip_priv (struct udevice *current) +{ +struct eth_device_priv *priv =dev_get_uclass_priv (current); + +return &priv->ulwip; +} +void eth_halt (void ) {struct udevice *current;net/lwip/port/if.c new file +14
-0@@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <net/eth.h> +#include "lwip/debug.h" +#include "lwip/arch.h" +#include "netif/etharp.h" +#include "lwip/stats.h" +#include "lwip/def.h"
net/lwip/port/if.c line 24
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include "lwip/sys.h" +#include "lwip/netif.h" +#include "lwip/ethip6.h" + +#include "lwip/ip.h" + +#define IFNAME0 'e' +#define IFNAME1 '0'
Why is this needed and how was 'e0' chosen?
Dont we have a device name in the udevice struct?
net/lwip/port/if.c line 32
Quoted 8 lines
net/lwip/port/if.c new file +8
-0+ +static struct pbuf *low_level_input (struct netif *netif); + +int ulwip_enabled (void ) +{ +struct ulwip *ulwip; + + ulwip =eth_lwip_priv (eth_get_dev ());
eth_get_dev() can return NULL. There are various locations of this call that needs fixing
net/lwip/port/if.c line 70
Quoted 6 lines
net/lwip/port/if.c new file +6
-0+return ulwip->init_done; +} + + +struct ulwip_if { +};
Why the forward declaration?
net/lwip/port/if.c line 40
Quoted 2 lines
net/lwip/port/if.c new file +2
-0+ +#define LWIP_PORT_INIT_NETMASK (addr) IP4_ADDR((addr), 255, 255, 255, 0)
Why are we limiting the netmask to a class C network?
net/lwip/port/if.c line 78
Quoted 6 lines
net/lwip/port/if.c new file +6
-0+ +void ulwip_poll (void ) +{ +struct pbuf *p; +int err; +struct netif *netif =netif_get_by_index (1 );
First of all netif can be NULL. Apart from that always requesting index 1 feels wrong. We should do something similar to eth_get_dev() and get the *active* device correlation to an index
net/lwip/port/if.c line 82
Quoted 4 lines
net/lwip/port/if.c new file +4
-0+ + p =low_level_input (netif); +if (!p) { +log_err ("error p = low_level_input = NULL\n" );
This looks like a debug message.
'Network interface undefined' or something else, which is more readable.
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+return ; + } + +/* ethernet_input always returns ERR_OK */ + err =ethernet_input (p, netif); +if (err) +log_err ("ip4_input err %d\n" , err); + +return ; +}
net/lwip/port/if.c line 102
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+ +static struct pbuf *low_level_input (struct netif *netif) +{ +struct pbuf *p, *q; +u16_t len = net_rx_packet_len; +uchar *data = net_rx_packet; + +/* We allocate a pbuf chain of pbufs from the pool. */ + p =pbuf_alloc (PBUF_RAW , len,PBUF_POOL ); +if (p) {
if (!p) and reverse the logic
Quoted 11 lines
net/lwip/port/if.c new file +11
-0+/* We iterate over the pbuf chain until we have read the entire +* packet into the pbuf. +*/ +for (q = p; q !=NULL ; q = q->next) { +/* +* Read enough bytes to fill this pbuf in the chain. The +* available data in the pbuf is given by the q->len +* variable. +* This does not necessarily have to be a memcpy, you can also preallocate +* pbufs for a DMA-enabled MAC and after receiving truncate it to the +* actually received size. In this case, ensure the tot_len member of the
net/lwip/port/if.c line 123
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+* pbuf is the sum of the chained pbuf len members. +*/ +MEMCPY (q->payload, data, q->len); + data += q->len; + } +// acknowledge that packet has been read(); + +LINK_STATS_INC (link.recv); + }else { +// drop packet();
Is this a commented function that's missing?
Quoted 48 lines
net/lwip/port/if.c new file +48
-0+LINK_STATS_INC (link.memerr); +LINK_STATS_INC (link.drop); + } + +return p; +} + +static int ethernetif_input (struct pbuf *p,struct netif *netif) +{ +struct ethernetif *ethernetif; + + ethernetif = netif->state; + +/* move received packet into a new pbuf */ + p =low_level_input (netif); + +/* if no packet could be read, silently ignore this */ +if (p) { +/* pass all packets to ethernet_input, which decides what packets it supports */ +if (netif->input (p, netif) !=ERR_OK ) { +LWIP_DEBUGF (NETIF_DEBUG , ("%s: IP input error\n" , __func__)); +pbuf_free (p); + p =NULL ; + } + } + +return 0 ; +} + +static err_t low_level_output (struct netif *netif,struct pbuf *p) +{ +int err; + + err =eth_send (p->payload, p->len); +if (err) { +log_err ("eth_send error %d\n" , err); +return ERR_ABRT ; + } +return ERR_OK ; +} + +err_t ulwip_if_init (struct netif *netif) +{ +struct ulwip_if *uif; +struct ulwip *ulwip; + + uif =malloc (sizeof (struct ulwip_if )); +if (!uif) {
net/lwip/port/if.c line 181
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+log_err ("uif: out of memory\n" ); +return ERR_MEM ; + } + netif->state = uif; + + netif->name[0 ] =IFNAME0 ; + netif->name[1 ] =IFNAME1 ; + + netif->hwaddr_len =ETHARP_HWADDR_LEN ; +string_to_enetaddr (env_get ("ethaddr" ), netif->hwaddr);
What if ethaddr is not set?
Quoted 49 lines
net/lwip/port/if.c new file +49
-0+#if defined(CONFIG_LWIP_LIB_DEBUG ) +printf (" MAC: %02X:%02X:%02X:%02X:%02X:%02X\n" , + netif->hwaddr[0 ], netif->hwaddr[1 ], netif->hwaddr[2 ], + netif->hwaddr[3 ], netif->hwaddr[4 ], netif->hwaddr[5 ]); +#endif +#if LWIP_IPV4 + netif->output = etharp_output; +#endif +#if LWIP_IPV6 + netif->output_ip6 = ethip6_output; +#endif + + netif->linkoutput = low_level_output; + netif->mtu =1500 ; + netif->flags =NETIF_FLAG_BROADCAST |NETIF_FLAG_ETHARP |NETIF_FLAG_LINK_UP ; + + ulwip =eth_lwip_priv (eth_get_dev ()); + ulwip->init_done =1 ; +if (IS_ENABLED (CONFIG_LWIP_LIB_DEBUG )) { +log_info ("Initialized LWIP stack\n" ); + } + +return ERR_OK ; +} + +int ulwip_init (void ) +{ +ip4_addr_t ipaddr, netmask, gw; +struct netif *unetif; +struct ulwip *ulwip; +int ret; + + ret =eth_init (); +if (ret) { +log_err ("eth_init error %d\n" , ret); +return ERR_IF ; + } + + ulwip =eth_lwip_priv (eth_get_dev ()); +if (ulwip->init_done) +return CMD_RET_SUCCESS ; + + unetif =malloc (sizeof (struct netif )); +if (!unetif) +return ERR_MEM ; +memset (unetif,0 ,sizeof (struct netif )); + +ip4_addr_set_zero (&gw); +ip4_addr_set_zero (&ipaddr);
net/lwip/port/if.c line 240
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+ip4_addr_set_zero (&netmask); + +ipaddr_aton (env_get ("ipaddr" ), &ipaddr); +ipaddr_aton (env_get ("ipaddr" ), &netmask); + +LWIP_PORT_INIT_NETMASK (&netmask); +if (IS_ENABLED (CONFIG_LWIP_LIB_DEBUG )) { +printf ("Starting lwIP, IP: %s\n" ,ip4addr_ntoa (&ipaddr)); +printf (" GW: %s\n" ,ip4addr_ntoa (&gw)); +printf (" mask: %s\n" ,ip4addr_ntoa (&netmask));
log_info()
Quoted 28 lines
net/lwip/port/if.c new file +20
-0+ } + +if (!netif_add (unetif, &ipaddr, &netmask, &gw, + unetif, ulwip_if_init, ethernetif_input)) +printf ("err: netif_add failed!\n" ); + +netif_set_up (unetif); +netif_set_link_up (unetif); +#if LWIP_IPV6 +netif_create_ip6_linklocal_address (unetif,1 ); +printf (" IPv6: %s\n" ,ip6addr_ntoa (netif_ip6_addr (unetif,0 ))); +#endif /* LWIP_IPV6 */ + +return CMD_RET_SUCCESS ; +} + +/* placeholder, not used now */ +void ulwip_destroy (void ) +{ +}net/lwip/port/include/arch/cc.h new file +2
-0@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +
net/lwip/port/include/arch/cc.h line 12
Quoted 10 lines
net/lwip/port/include/arch/cc.h new file +10
-0+/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_ARCH_CC_H +#define LWIP_ARCH_CC_H + +#include <linux/types.h> +#include <linux/kernel.h> +//#include <stdlib.h> /* getenv, atoi */
Please dont leave comments like that
net/lwip/port/include/arch/cc.h line 19
Quoted 7 lines
net/lwip/port/include/arch/cc.h new file +7
-0+#include <vsprintf.h> + +#define LWIP_ERRNO_INCLUDE <errno.h> + +#define LWIP_ERRNO_STDINCLUDE 1 +#define LWIP_NO_UNISTD_H 1 +#define LWIP_TIMEVAL_PRIVATE 1
Should those be defined in the LWIP config header instead?
net/lwip/port/include/arch/cc.h line 21
Quoted 2 lines
net/lwip/port/include/arch/cc.h new file +2
-0+ +extern unsigned int lwip_port_rand (void );
This is like the forth time we go through this and it's a repeating pattern. Why do we need this extern? Can't we just include the proper header files?
net/lwip/port/include/arch/cc.h line 22
Quoted 1 line
net/lwip/port/include/arch/cc.h new file +1
-0+#define LWIP_RAND () (lwip_port_rand())
This seems quite useless. Just use the function directly
Quoted 30 lines
net/lwip/port/include/arch/cc.h new file +17
-0+ +/* different handling for unit test, normally not needed */ +#ifdef LWIP_NOASSERT_ON_ERROR +#define LWIP_ERROR (message, expression, handler) do { if (!(expression)) { \ + handler; }} while (0) +#endif + +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS + +#define LWIP_PLATFORM_ASSERT (x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ + x, __LINE__, __FILE__); } while (0) + +#define atoi (str) (int)dectoul(str, NULL) + +#define LWIP_ERR_T int + +#endif /* LWIP_ARCH_CC_H */ net/lwip/port/include/arch/sys_arch.h new file +7
-0@@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_ARCH_SYS_ARCH_H
net/lwip/port/include/arch/sys_arch.h line 17
Quoted 10 lines
net/lwip/port/include/arch/sys_arch.h new file +10
-0+#define LWIP_ARCH_SYS_ARCH_H + +#include "lwip/opt.h" +#include "lwip/arch.h" +#include "lwip/err.h" + +#define ERR_NEED_SCHED 123 + +void sys_arch_msleep (u32_t delay_ms); +#define sys_msleep (ms) sys_arch_msleep(ms)
Dont redefine random functions here. U-Boot should already have all the sleep functions you need
net/lwip/port/include/arch/sys_arch.h line 19
Quoted 2 lines
net/lwip/port/include/arch/sys_arch.h new file +2
-0+ +#if SYS_LIGHTWEIGHT_PROT
Is this working? Can we define SYS_LIGHTWEIGHT_PROT?
Quoted 12 lines
net/lwip/port/include/arch/sys_arch.h new file +12
-0+typedef u32_t sys_prot_t ; +#endif /* SYS_LIGHTWEIGHT_PROT */ + +#include <errno.h> + +#define SYS_MBOX_NULL NULL +#define SYS_SEM_NULL NULL + +typedef u32_t sys_prot_t ; + +typedef struct sys_sem *sys_sem_t ; +#define sys_sem_valid (sem) (((sem) != NULL) && (*(sem) != NULL))
net/lwip/port/include/arch/sys_arch.h line 41
Quoted 10 lines
net/lwip/port/include/arch/sys_arch.h new file +10
-0+#define sys_sem_set_invalid (sem) do { if ((sem) != NULL) { *(sem) = NULL; }} while (0) + +/* let sys.h use binary semaphores for mutexes */ +#define LWIP_COMPAT_MUTEX 1 +#define LWIP_COMPAT_MUTEX_ALLOWED 1 + +struct sys_mbox ; +typedef struct sys_mbox *sys_mbox_t ; +#define sys_mbox_valid (mbox) (((mbox) != NULL) && (*(mbox) != NULL)) +#define sys_mbox_set_invalid (mbox) do { if ((mbox) != NULL) { *(mbox) = NULL; }} while (0)
All these macros seem unnecessary. Just assign types to NULL directly etc
net/lwip/port/include/arch/sys_arch.h line 54
Quoted 13 lines
net/lwip/port/include/arch/sys_arch.h new file +13
-0+ +struct sys_thread ; +typedef struct sys_thread *sys_thread_t ; + +static inline u32_t sys_arch_sem_wait (sys_sem_t *sem,u32_t timeout) +{ +return 0 ; +}; + +static inline err_t sys_mbox_trypost (sys_mbox_t *mbox,void *msg) +{ +return 0 ; +};
Are those really needed? Why do we just return 0?
Quoted 19 lines
net/lwip/port/include/arch/sys_arch.h new file +2
-0+ +#endif /* LWIP_ARCH_SYS_ARCH_H */ net/lwip/port/include/limits.h new file +0
-0net/lwip/port/sys-arch.c new file +8
-0@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <rand.h>
net/lwip/port/sys-arch.c line 18
Quoted 10 lines
net/lwip/port/sys-arch.c new file +10
-0+#include "lwip/opt.h" + +u32_t sys_now (void ) +{ +return get_timer (0 ); +} + +u32_t lwip_port_rand (void ) +{ +return (u32_t )rand ();
I dont see why we cant use the U-Boot defined ones directly
Quoted 5 lines
net/lwip/port/sys-arch.c new file +2
-0+} +Signature · 1 line
2.30.2
Thanks
/Ilias
Re: [PATCHv6 09/14] net/lwip: implement lwIP port to U-Boot
Quoted 74 lines · Ilias Apalodimas
Quoted 3 lines · Maxim Uvarov
Implement network lwIP interface connected to the U-boot. Keep original file structure widely used fro lwIP ports. (i.e.
port/if.cport/sys-arch.c).What the patch does is obvious. Try to describe *why* we need this
Quoted 67 lines
Signed-off-by Maxim Uvarov <[email protected]>--- net/eth-uclass.c | 8 + net/lwip/port/if.c | 260 ++++++++++++++++++++++++++ net/lwip/port/include/arch/cc.h | 39 ++++ net/lwip/port/include/arch/sys_arch.h | 56 ++++++ net/lwip/port/include/limits.h | 0 net/lwip/port/sys-arch.c | 20 ++ 6 files changed, 383 insertions(+) create mode 100644 net/lwip/port/if.c create mode 100644 net/lwip/port/include/arch/cc.h create mode 100644 net/lwip/port/include/arch/sys_arch.h create mode 100644 net/lwip/port/include/limits.h create mode 100644 net/lwip/port/sys-arch.cnet/eth-uclass.c +8
-0@@ -32,6 +32,7 @@ DECLARE_GLOBAL_DATA_PTR;struct eth_device_priv {enum eth_state_t state;bool running; +ulwip ulwip; };/** @@ -347,6 +348,13 @@ int eth_init(void)return ret; } +struct ulwip *eth_lwip_priv (struct udevice *current) +{ +struct eth_device_priv *priv =dev_get_uclass_priv (current); + +return &priv->ulwip; +} +void eth_halt (void ) {struct udevice *current;net/lwip/port/if.c new file +19
-0@@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <net/eth.h> +#include "lwip/debug.h" +#include "lwip/arch.h" +#include "netif/etharp.h" +#include "lwip/stats.h" +#include "lwip/def.h" +#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include "lwip/sys.h" +#include "lwip/netif.h" +#include "lwip/ethip6.h"
Quoted 10 lines
net/lwip/port/if.c line 24
Quoted 5 lines
net/lwip/port/if.c new file +5
-0+ +#include "lwip/ip.h" + +#define IFNAME0 'e' +#define IFNAME1 '0'Why is this needed and how was 'e0' chosen?
Dont we have a device name in the udevice struct?
If we assume that we have lwip netif on top of an active U-Boot eth device, then it can be any name.
/** descriptive abbreviation */
char name[2];
./net/lwip/lwip-external/contrib/examples/ethernetif/ethernetif.c:#define IFNAME0 'e' ./net/lwip/lwip-external/contrib/examples/ethernetif/ethernetif.c:#define IFNAME1 'n' ./net/lwip/lwip-external/contrib/ports/unix/port/netif/tapif.c:#define IFNAME0 't' ./net/lwip/lwip-external/contrib/ports/unix/port/netif/tapif.c:#define IFNAME1 'p' ./net/lwip/lwip-external/contrib/ports/unix/port/netif/vdeif.c:#define IFNAME0 'v' ./net/lwip/lwip-external/contrib/ports/unix/port/netif/vdeif.c:#define IFNAME1 'd' ./net/lwip/lwip-external/contrib/ports/win32/pcapif.c:#define IFNAME0
'e'
./net/lwip/lwip-external/contrib/ports/win32/pcapif.c:#define IFNAME1
'0'./net/lwip/lwip-external/src/netif/bridgeif.c:#define IFNAME0 'b' ./net/lwip/lwip-external/src/netif/bridgeif.c:#define IFNAME1 'r' ./net/lwip/port/if.c:#define IFNAME0 'u' ./net/lwip/port/if.c:#define IFNAME1 '0'
Quoted 12 lines
net/lwip/port/if.c line 32
Quoted 8 lines
net/lwip/port/if.c new file +8
-0+ +static struct pbuf *low_level_input (struct netif *netif); + +int ulwip_enabled (void ) +{ +struct ulwip *ulwip; + + ulwip =eth_lwip_priv (eth_get_dev ());
eth_get_dev()can return NULL. There are various locations of this call that needs fixing
ok.
Quoted 10 lines
net/lwip/port/if.c line 70
Quoted 7 lines
net/lwip/port/if.c new file +6
-0+return ulwip->init_done; +} + + +struct ulwip_if { +};Why the forward declaration?
Quoted 6 lines
net/lwip/port/if.c line 40
Quoted 2 lines
net/lwip/port/if.c new file +2
-0+ +#define LWIP_PORT_INIT_NETMASK (addr) IP4_ADDR((addr), 255, 255, 255, 0)Why are we limiting the netmask to a class C network?
that can be completely removed.
Quoted 12 lines
net/lwip/port/if.c line 78
Quoted 6 lines
net/lwip/port/if.c new file +6
-0+ +void ulwip_poll (void ) +{ +struct pbuf *p; +int err; +struct netif *netif =netif_get_by_index (1 );First of all netif can be NULL. Apart from that always requesting index 1 feels wrong. We should do something similar to
eth_get_dev()and get the *active* device correlation to an index
I expect that it will be 1 lwip netif for all eth defs. And only active eth dev works with lwip.
This can be reconsidered but might be not a part of the initial patch set.
Quoted 59 lines
net/lwip/port/if.c line 82
Quoted 4 lines
net/lwip/port/if.c new file +4
-0+ + p =low_level_input (netif); +if (!p) { +log_err ("error p = low_level_input = NULL\n" );This looks like a debug message.
'Network interface undefined' or something else, which is more readable.Quoted 10 lines
net/lwip/port/if.c new file +10
-0+return ; + } + +/* ethernet_input always returns ERR_OK */ + err =ethernet_input (p, netif); +if (err) +log_err ("ip4_input err %d\n" , err); + +return ; +}net/lwip/port/if.c line 102
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+ +static struct pbuf *low_level_input (struct netif *netif) +{ +struct pbuf *p, *q; +u16_t len = net_rx_packet_len; +uchar *data = net_rx_packet; + +/* We allocate a pbuf chain of pbufs from the pool. */ + p =pbuf_alloc (PBUF_RAW , len,PBUF_POOL ); +if (p) {if (!p) and reverse the logic
net/lwip/port/if.c line 71
Quoted 1 line
net/lwip/port/if.c new file +1
-0+/* We iterate over the pbuf chain until we have read the entire
net/lwip/port/if.c
Quoted 5 lines
net/lwip/port/if.c new file +5
-0+* packet into the pbuf. +*/ +for (q = p; q !=NULL ; q = q->next) { +/* +* Read enough bytes to fill this pbuf in the chain. The
net/lwip/port/if.c line 77
Quoted 1 line
net/lwip/port/if.c new file +1
-0+* available data in the pbuf is given by the
q->lennet/lwip/port/if.c line 79
Quoted 2 lines
net/lwip/port/if.c new file +2
-0+* variable. +* This does not necessarily have to be a memcpy, you can also preallocate
net/lwip/port/if.c line 80
Quoted 1 line
net/lwip/port/if.c new file +1
-0+* pbufs for a DMA-enabled MAC and after receiving truncate it to the
net/lwip/port/if.c line 81
Quoted 1 line
net/lwip/port/if.c new file +1
-0+* actually received size. In this case, ensure the
tot_lenmember of thenet/lwip/port/if.c line 123
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+* pbuf is the sum of the chained pbuf len members. +*/ +MEMCPY (q->payload, data, q->len); + data += q->len; + } +// acknowledge that packet has been read(); + +LINK_STATS_INC (link.recv); + }else { +// drop packet();
Quoted 3 lines
Is this a commented function that's missing?
it's a comment. That means lwip does now own this packet and actual drop will be by U-Boot eth dev.
I will remove this comment to not confuse anybody.
Quoted 54 lines
Quoted 9 lines
net/lwip/port/if.c new file +9
-0+LINK_STATS_INC (link.memerr); +LINK_STATS_INC (link.drop); + } + +return p; +} + +static int ethernetif_input (struct pbuf *p,struct netif *netif) +{net/lwip/port/if.c
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+struct ethernetif *ethernetif; + + ethernetif = netif->state; + +/* move received packet into a new pbuf */ + p =low_level_input (netif); + +/* if no packet could be read, silently ignore this */ +if (p) { +/* pass all packets to ethernet_input, which decides what packets it supports */
net/lwip/port/if.c line 112
Quoted 2 lines
net/lwip/port/if.c new file +2
-0+if (netif->input (p, netif) !=ERR_OK ) { + LWIP_DEBUGF(NETIF_DEBUG, ("%s: IP input error\n",
__func__));Quoted 31 lines
net/lwip/port/if.c new file +31
-0+pbuf_free (p); + p =NULL ; + } + } + +return 0 ; +} + +static err_t low_level_output (struct netif *netif,struct pbuf *p) +{ +int err; + + err =eth_send (p->payload, p->len); +if (err) { +log_err ("eth_send error %d\n" , err); +return ERR_ABRT ; + } +return ERR_OK ; +} + +err_t ulwip_if_init (struct netif *netif) +{ +struct ulwip_if *uif; +struct ulwip *ulwip; + + uif =malloc (sizeof (struct ulwip_if )); +if (!uif) { +log_err ("uif: out of memory\n" ); +return ERR_MEM ; + } + netif->state = uif;
Quoted 10 lines
net/lwip/port/if.c line 181
Quoted 6 lines
net/lwip/port/if.c new file +6
-0+ + netif->name[0 ] =IFNAME0 ; + netif->name[1 ] =IFNAME1 ; + + netif->hwaddr_len =ETHARP_HWADDR_LEN ; +string_to_enetaddr (env_get ("ethaddr" ), netif->hwaddr);What if ethaddr is not set?
U-Boot set's it automatically. I think it will generate random one. But even if somehow it will not setstring_to_enetaddr() function just will do nothing.
Quoted 46 lines
Quoted 5 lines
net/lwip/port/if.c new file +5
-0+#if defined(CONFIG_LWIP_LIB_DEBUG ) +printf (" MAC: %02X:%02X:%02X:%02X:%02X:%02X\n" , + netif->hwaddr[0 ], netif->hwaddr[1 ], netif->hwaddr[2 ], + netif->hwaddr[3 ], netif->hwaddr[4 ], netif->hwaddr[5 ]); +#endif net/lwip/port/if.c
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+#if LWIP_IPV4 + netif->output = etharp_output; +#endif +#if LWIP_IPV6 + netif->output_ip6 = ethip6_output; +#endif + + netif->linkoutput = low_level_output; + netif->mtu =1500 ; + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP |
NETIF_FLAG_LINK_UP;Quoted 30 lines
net/lwip/port/if.c new file +30
-0+ + ulwip =eth_lwip_priv (eth_get_dev ()); + ulwip->init_done =1 ; +if (IS_ENABLED (CONFIG_LWIP_LIB_DEBUG )) { +log_info ("Initialized LWIP stack\n" ); + } + +return ERR_OK ; +} + +int ulwip_init (void ) +{ +ip4_addr_t ipaddr, netmask, gw; +struct netif *unetif; +struct ulwip *ulwip; +int ret; + + ret =eth_init (); +if (ret) { +log_err ("eth_init error %d\n" , ret); +return ERR_IF ; + } + + ulwip =eth_lwip_priv (eth_get_dev ()); +if (ulwip->init_done) +return CMD_RET_SUCCESS ; + + unetif =malloc (sizeof (struct netif )); +if (!unetif) +return ERR_MEM ;
Quoted 9 lines
net/lwip/port/if.c line 234
Quoted 8 lines
net/lwip/port/if.c new file +8
-0+memset (unetif,0 ,sizeof (struct netif )); + +ip4_addr_set_zero (&gw); +ip4_addr_set_zero (&ipaddr); +ip4_addr_set_zero (&netmask); + +ipaddr_aton (env_get ("ipaddr" ), &ipaddr); +ipaddr_aton (env_get ("ipaddr" ), &netmask);
Here I missed "netmask" for &netmask.
Quoted 62 lines
net/lwip/port/if.c line 240
Quoted 6 lines
net/lwip/port/if.c new file +6
-0+ +LWIP_PORT_INIT_NETMASK (&netmask); +if (IS_ENABLED (CONFIG_LWIP_LIB_DEBUG )) { +printf ("Starting lwIP, IP: %s\n" ,ip4addr_ntoa (&ipaddr)); +printf (" GW: %s\n" ,ip4addr_ntoa (&gw)); +printf (" mask: %s\n" ,ip4addr_ntoa (&netmask));
log_info()net/lwip/port/if.c
Quoted 11 lines
net/lwip/port/if.c new file +11
-0+ } + +if (!netif_add (unetif, &ipaddr, &netmask, &gw, + unetif, ulwip_if_init, ethernetif_input)) +printf ("err: netif_add failed!\n" ); + +netif_set_up (unetif); +netif_set_link_up (unetif); +#if LWIP_IPV6 +netif_create_ip6_linklocal_address (unetif,1 ); + printf(" IPv6: %s\n",
ip6addr_ntoa(netif_ip6_addr(unetif, 0)));Review
Quoted 10 lines
net/lwip/port/if.c new file +9
-0+#endif /* LWIP_IPV6 */ + +return CMD_RET_SUCCESS ; +} + +/* placeholder, not used now */ +void ulwip_destroy (void ) +{ +}(quoted diff) +0
-0
b/net/lwip/port/include/arch/cc.hQuoted 7 lines
new file mode 100644
index 0000000000..55f7787ce1net/lwip/port/include/arch/cc.h new file +2
-0@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +net/lwip/port/include/arch/cc.h line 12
Quoted 10 lines
net/lwip/port/include/arch/cc.h new file +10
-0+/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_ARCH_CC_H +#define LWIP_ARCH_CC_H + +#include <linux/types.h> +#include <linux/kernel.h> +//#include <stdlib.h> /* getenv, atoi */ Please dont leave comments like that
net/lwip/port/include/arch/cc.h line 19
Quoted 7 lines
net/lwip/port/include/arch/cc.h new file +7
-0+#include <vsprintf.h> + +#define LWIP_ERRNO_INCLUDE <errno.h> + +#define LWIP_ERRNO_STDINCLUDE 1 +#define LWIP_NO_UNISTD_H 1 +#define LWIP_TIMEVAL_PRIVATE 1Should those be defined in the LWIP config header instead?
Quoted 1 line
I would keep it here, like
./net/lwip/lwip-external/contrib/ports/unix/port/include/arch/cc.h does. Because LWIP config is more related to protocol features and settings and this header is about
porr for a specific platform.
Quoted 7 lines
net/lwip/port/include/arch/cc.h line 21
Quoted 2 lines
net/lwip/port/include/arch/cc.h new file +2
-0+ +extern unsigned int lwip_port_rand (void );This is like the forth time we go through this and it's a repeating pattern. Why do we need this extern? Can't we just include the proper header files?
Quoted 5 lines
net/lwip/port/include/arch/cc.h line 22
Quoted 1 line
net/lwip/port/include/arch/cc.h new file +1
-0+#define LWIP_RAND () (lwip_port_rand())This seems quite useless. Just use the function directly
somehow I missed this, this should be direct call:
#include <rand.h>
#define LWIP_RAND() ((u32_t)rand())
Quoted 38 lines
net/lwip/port/include/arch/cc.h
Quoted 4 lines
net/lwip/port/include/arch/cc.h new file +4
-0+ +/* different handling for unit test, normally not needed */ +#ifdef LWIP_NOASSERT_ON_ERROR +#define LWIP_ERROR (message, expression, handler) do { if(!(expression)) { \
net/lwip/port/include/arch/cc.h
Quoted 6 lines
net/lwip/port/include/arch/cc.h new file +6
-0+ handler; }} while (0) +#endif + +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS + +#define LWIP_PLATFORM_ASSERT (x) do {printf("Assertion \"%s\" failed atline %d in %s\n", \
Review
Quoted 8 lines
net/lwip/port/include/arch/cc.h new file +7
-0+ x, __LINE__, __FILE__); } while (0) + +#define atoi (str) (int)dectoul(str, NULL) + +#define LWIP_ERR_T int + +#endif /* LWIP_ARCH_CC_H */ (quoted diff) +0
-0
b/net/lwip/port/include/arch/sys_arch.hQuoted 17 lines
new file mode 100644
index 0000000000..92a8560d49net/lwip/port/include/arch/sys_arch.h new file +12
-0@@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_ARCH_SYS_ARCH_H +#define LWIP_ARCH_SYS_ARCH_H + +#include "lwip/opt.h" +#include "lwip/arch.h" +#include "lwip/err.h"
Quoted 10 lines
net/lwip/port/include/arch/sys_arch.h line 17
Quoted 5 lines
net/lwip/port/include/arch/sys_arch.h new file +5
-0+ +#define ERR_NEED_SCHED 123 + +void sys_arch_msleep (u32_t delay_ms); +#define sys_msleep (ms) sys_arch_msleep(ms)Dont redefine random functions here. U-Boot should already have all the sleep functions you need
dropeed.
Quoted 33 lines
net/lwip/port/include/arch/sys_arch.h line 19
Quoted 2 lines
net/lwip/port/include/arch/sys_arch.h new file +2
-0+ +#if SYS_LIGHTWEIGHT_PROT Is this working? Can we define
SYS_LIGHTWEIGHT_PROT?dropeed.
net/lwip/port/include/arch/sys_arch.h
Quoted 13 lines
net/lwip/port/include/arch/sys_arch.h new file +13
-0+typedef u32_t sys_prot_t ; +#endif /* SYS_LIGHTWEIGHT_PROT */ + +#include <errno.h> + +#define SYS_MBOX_NULL NULL +#define SYS_SEM_NULL NULL + +typedef u32_t sys_prot_t ; + +typedef struct sys_sem *sys_sem_t ; +#define sys_sem_valid (sem) (((sem) != NULL) && (*(sem) != NULL)) +#define sys_sem_set_invalid (sem) do { if ((sem) != NULL) { *(sem) =NULL; }} while (0)
net/lwip/port/include/arch/sys_arch.h
Quoted 9 lines
net/lwip/port/include/arch/sys_arch.h new file +9
-0+ +/* let sys.h use binary semaphores for mutexes */ +#define LWIP_COMPAT_MUTEX 1 +#define LWIP_COMPAT_MUTEX_ALLOWED 1 + +struct sys_mbox ; +typedef struct sys_mbox *sys_mbox_t ; +#define sys_mbox_valid (mbox) (((mbox) != NULL) && (*(mbox) != NULL)) +#define sys_mbox_set_invalid (mbox) do { if ((mbox) != NULL) { *(mbox) =NULL; }} while (0)
Quoted 3 lines
All these macros seem unnecessary. Just assign types to NULL directly etc
ok.
Quoted 16 lines
net/lwip/port/include/arch/sys_arch.h line 54
Quoted 13 lines
net/lwip/port/include/arch/sys_arch.h new file +13
-0+ +struct sys_thread ; +typedef struct sys_thread *sys_thread_t ; + +static inline u32_t sys_arch_sem_wait (sys_sem_t *sem,u32_t timeout) +{ +return 0 ; +}; + +static inline err_t sys_mbox_trypost (sys_mbox_t *mbox,void *msg) +{ +return 0 ; +};Are those really needed? Why do we just return 0?
Quoted 1 line
Not needed, I think I planned to implement socket API later where it's
needed. All these functions and macro can be defined to NULL with #define NO_SYS 1 in the lwip configuration.
This has to be an empty file.
Quoted 24 lines
Review
Quoted 3 lines
net/lwip/port/include/arch/sys_arch.h new file +2
-0+ +#endif /* LWIP_ARCH_SYS_ARCH_H */ (quoted diff) +0
-0
b/net/lwip/port/include/limits.hQuoted 20 lines
new file mode 100644
index 0000000000..e69de29bb2net/lwip/port/sys-arch.c new file +12
-0@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <rand.h> +#include "lwip/opt.h" + +u32_t sys_now (void ) +{
Quoted 10 lines
net/lwip/port/sys-arch.c line 18
Quoted 6 lines
net/lwip/port/sys-arch.c new file +6
-0+return get_timer (0 ); +} + +u32_t lwip_port_rand (void ) +{ +return (u32_t )rand ();I dont see why we cant use the U-Boot defined ones directly
changed.
Quoted 9 lines
Quoted 5 lines
net/lwip/port/sys-arch.c new file +2
-1+} + --2.30.2
Thanks
/Ilias
Re: [PATCHv6 09/14] net/lwip: implement lwIP port to U-Boot
Hi all,
could you please remove the lwip-devel list from CC? I am interested in these mails, but the more you dive into U-Boot specific things here, the less people on our lwip list will be interested in this topic.
Thanks,
Simon
Am 18. August 2023 14:53:43 MESZ schrieb Maxim Uvarov <[email protected]>:
Quoted 611 lines
Quoted 74 lines · Ilias Apalodimas
Quoted 3 lines · Maxim Uvarov
Implement network lwIP interface connected to the U-boot. Keep original file structure widely used fro lwIP ports. (i.e.
port/if.cport/sys-arch.c).What the patch does is obvious. Try to describe *why* we need this
Quoted 67 lines
Signed-off-by Maxim Uvarov <[email protected]>--- net/eth-uclass.c | 8 + net/lwip/port/if.c | 260 ++++++++++++++++++++++++++ net/lwip/port/include/arch/cc.h | 39 ++++ net/lwip/port/include/arch/sys_arch.h | 56 ++++++ net/lwip/port/include/limits.h | 0 net/lwip/port/sys-arch.c | 20 ++ 6 files changed, 383 insertions(+) create mode 100644 net/lwip/port/if.c create mode 100644 net/lwip/port/include/arch/cc.h create mode 100644 net/lwip/port/include/arch/sys_arch.h create mode 100644 net/lwip/port/include/limits.h create mode 100644 net/lwip/port/sys-arch.cnet/eth-uclass.c +8
-0@@ -32,6 +32,7 @@ DECLARE_GLOBAL_DATA_PTR;struct eth_device_priv {enum eth_state_t state;bool running; +ulwip ulwip; };/** @@ -347,6 +348,13 @@ int eth_init(void)return ret; } +struct ulwip *eth_lwip_priv (struct udevice *current) +{ +struct eth_device_priv *priv =dev_get_uclass_priv (current); + +return &priv->ulwip; +} +void eth_halt (void ) {struct udevice *current;net/lwip/port/if.c new file +19
-0@@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <net/eth.h> +#include "lwip/debug.h" +#include "lwip/arch.h" +#include "netif/etharp.h" +#include "lwip/stats.h" +#include "lwip/def.h" +#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include "lwip/sys.h" +#include "lwip/netif.h" +#include "lwip/ethip6.h" Quoted 10 lines
net/lwip/port/if.c line 24
Quoted 5 lines
net/lwip/port/if.c new file +5
-0+ +#include "lwip/ip.h" + +#define IFNAME0 'e' +#define IFNAME1 '0'Why is this needed and how was 'e0' chosen?
Dont we have a device name in the udevice struct?If we assume that we have lwip netif on top of an active U-Boot eth device, then it can be any name.
/** descriptive abbreviation */
char name[2];
./net/lwip/lwip-external/contrib/examples/ethernetif/ethernetif.c:#define IFNAME0 'e' ./net/lwip/lwip-external/contrib/examples/ethernetif/ethernetif.c:#define IFNAME1 'n' ./net/lwip/lwip-external/contrib/ports/unix/port/netif/tapif.c:#define IFNAME0 't' ./net/lwip/lwip-external/contrib/ports/unix/port/netif/tapif.c:#define IFNAME1 'p' ./net/lwip/lwip-external/contrib/ports/unix/port/netif/vdeif.c:#define IFNAME0 'v' ./net/lwip/lwip-external/contrib/ports/unix/port/netif/vdeif.c:#define IFNAME1 'd' ./net/lwip/lwip-external/contrib/ports/win32/pcapif.c:#define IFNAME0
'e' ./net/lwip/lwip-external/contrib/ports/win32/pcapif.c:#define IFNAME1 '0'./net/lwip/lwip-external/src/netif/bridgeif.c:#define IFNAME0 'b' ./net/lwip/lwip-external/src/netif/bridgeif.c:#define IFNAME1 'r' ./net/lwip/port/if.c:#define IFNAME0 'u' ./net/lwip/port/if.c:#define IFNAME1 '0'
Quoted 12 lines
net/lwip/port/if.c line 32
Quoted 8 lines
net/lwip/port/if.c new file +8
-0+ +static struct pbuf *low_level_input (struct netif *netif); + +int ulwip_enabled (void ) +{ +struct ulwip *ulwip; + + ulwip =eth_lwip_priv (eth_get_dev ());
eth_get_dev()can return NULL. There are various locations of this call that needs fixingok.
Quoted 10 lines
net/lwip/port/if.c line 70
Quoted 7 lines
net/lwip/port/if.c new file +6
-0+return ulwip->init_done; +} + + +struct ulwip_if { +};Why the forward declaration?
Quoted 6 lines
net/lwip/port/if.c line 40
Quoted 2 lines
net/lwip/port/if.c new file +2
-0+ +#define LWIP_PORT_INIT_NETMASK (addr) IP4_ADDR((addr), 255, 255, 255, 0)Why are we limiting the netmask to a class C network?
that can be completely removed.
Quoted 12 lines
net/lwip/port/if.c line 78
Quoted 6 lines
net/lwip/port/if.c new file +6
-0+ +void ulwip_poll (void ) +{ +struct pbuf *p; +int err; +struct netif *netif =netif_get_by_index (1 );First of all netif can be NULL. Apart from that always requesting index 1 feels wrong. We should do something similar to
eth_get_dev()and get the *active* device correlation to an indexI expect that it will be 1 lwip netif for all eth defs. And only active eth dev works with lwip.
This can be reconsidered but might be not a part of the initial patch set.Quoted 59 lines
net/lwip/port/if.c line 82
Quoted 4 lines
net/lwip/port/if.c new file +4
-0+ + p =low_level_input (netif); +if (!p) { +log_err ("error p = low_level_input = NULL\n" );This looks like a debug message.
'Network interface undefined' or something else, which is more readable.Quoted 10 lines
net/lwip/port/if.c new file +10
-0+return ; + } + +/* ethernet_input always returns ERR_OK */ + err =ethernet_input (p, netif); +if (err) +log_err ("ip4_input err %d\n" , err); + +return ; +}net/lwip/port/if.c line 102
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+ +static struct pbuf *low_level_input (struct netif *netif) +{ +struct pbuf *p, *q; +u16_t len = net_rx_packet_len; +uchar *data = net_rx_packet; + +/* We allocate a pbuf chain of pbufs from the pool. */ + p =pbuf_alloc (PBUF_RAW , len,PBUF_POOL ); +if (p) {if (!p) and reverse the logic
net/lwip/port/if.c line 71
Quoted 1 line
net/lwip/port/if.c new file +1
-0+/* We iterate over the pbuf chain until we have read the entire
net/lwip/port/if.c
Quoted 5 lines
net/lwip/port/if.c new file +5
-0+* packet into the pbuf. +*/ +for (q = p; q !=NULL ; q = q->next) { +/* +* Read enough bytes to fill this pbuf in the chain. The
net/lwip/port/if.c line 77
Quoted 1 line
net/lwip/port/if.c new file +1
-0+* available data in the pbuf is given by the
q->lennet/lwip/port/if.c line 79
Quoted 2 lines
net/lwip/port/if.c new file +2
-0+* variable. +* This does not necessarily have to be a memcpy, you can also preallocate
net/lwip/port/if.c line 80
Quoted 1 line
net/lwip/port/if.c new file +1
-0+* pbufs for a DMA-enabled MAC and after receiving truncate it to the
net/lwip/port/if.c line 81
Quoted 1 line
net/lwip/port/if.c new file +1
-0+* actually received size. In this case, ensure the
tot_lenmember of thenet/lwip/port/if.c line 123
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+* pbuf is the sum of the chained pbuf len members. +*/ +MEMCPY (q->payload, data, q->len); + data += q->len; + } +// acknowledge that packet has been read(); + +LINK_STATS_INC (link.recv); + }else { +// drop packet(); Quoted 3 lines
Is this a commented function that's missing?
it's a comment. That means lwip does now own this packet and actual drop will be by U-Boot eth dev.
I will remove this comment to not confuse anybody.Quoted 54 lines
Quoted 9 lines
net/lwip/port/if.c new file +9
-0+LINK_STATS_INC (link.memerr); +LINK_STATS_INC (link.drop); + } + +return p; +} + +static int ethernetif_input (struct pbuf *p,struct netif *netif) +{net/lwip/port/if.c
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+struct ethernetif *ethernetif; + + ethernetif = netif->state; + +/* move received packet into a new pbuf */ + p =low_level_input (netif); + +/* if no packet could be read, silently ignore this */ +if (p) { +/* pass all packets to ethernet_input, which decides what packets it supports */
net/lwip/port/if.c line 112
Quoted 2 lines
net/lwip/port/if.c new file +2
-0+if (netif->input (p, netif) !=ERR_OK ) { + LWIP_DEBUGF(NETIF_DEBUG, ("%s: IP input error\n",
__func__));Quoted 31 lines
net/lwip/port/if.c new file +31
-0+pbuf_free (p); + p =NULL ; + } + } + +return 0 ; +} + +static err_t low_level_output (struct netif *netif,struct pbuf *p) +{ +int err; + + err =eth_send (p->payload, p->len); +if (err) { +log_err ("eth_send error %d\n" , err); +return ERR_ABRT ; + } +return ERR_OK ; +} + +err_t ulwip_if_init (struct netif *netif) +{ +struct ulwip_if *uif; +struct ulwip *ulwip; + + uif =malloc (sizeof (struct ulwip_if )); +if (!uif) { +log_err ("uif: out of memory\n" ); +return ERR_MEM ; + } + netif->state = uif;Quoted 10 lines
net/lwip/port/if.c line 181
Quoted 6 lines
net/lwip/port/if.c new file +6
-0+ + netif->name[0 ] =IFNAME0 ; + netif->name[1 ] =IFNAME1 ; + + netif->hwaddr_len =ETHARP_HWADDR_LEN ; +string_to_enetaddr (env_get ("ethaddr" ), netif->hwaddr);What if ethaddr is not set?
U-Boot set's it automatically. I think it will generate random one. But even if somehow it will not set
string_to_enetaddr()function just will do nothing.Quoted 46 lines
Quoted 5 lines
net/lwip/port/if.c new file +5
-0+#if defined(CONFIG_LWIP_LIB_DEBUG ) +printf (" MAC: %02X:%02X:%02X:%02X:%02X:%02X\n" , + netif->hwaddr[0 ], netif->hwaddr[1 ], netif->hwaddr[2 ], + netif->hwaddr[3 ], netif->hwaddr[4 ], netif->hwaddr[5 ]); +#endif net/lwip/port/if.c
Quoted 10 lines
net/lwip/port/if.c new file +10
-0+#if LWIP_IPV4 + netif->output = etharp_output; +#endif +#if LWIP_IPV6 + netif->output_ip6 = ethip6_output; +#endif + + netif->linkoutput = low_level_output; + netif->mtu =1500 ; + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP |
NETIF_FLAG_LINK_UP;Quoted 30 lines
net/lwip/port/if.c new file +30
-0+ + ulwip =eth_lwip_priv (eth_get_dev ()); + ulwip->init_done =1 ; +if (IS_ENABLED (CONFIG_LWIP_LIB_DEBUG )) { +log_info ("Initialized LWIP stack\n" ); + } + +return ERR_OK ; +} + +int ulwip_init (void ) +{ +ip4_addr_t ipaddr, netmask, gw; +struct netif *unetif; +struct ulwip *ulwip; +int ret; + + ret =eth_init (); +if (ret) { +log_err ("eth_init error %d\n" , ret); +return ERR_IF ; + } + + ulwip =eth_lwip_priv (eth_get_dev ()); +if (ulwip->init_done) +return CMD_RET_SUCCESS ; + + unetif =malloc (sizeof (struct netif )); +if (!unetif) +return ERR_MEM ;Quoted 9 lines
net/lwip/port/if.c line 234
Quoted 8 lines
net/lwip/port/if.c new file +8
-0+memset (unetif,0 ,sizeof (struct netif )); + +ip4_addr_set_zero (&gw); +ip4_addr_set_zero (&ipaddr); +ip4_addr_set_zero (&netmask); + +ipaddr_aton (env_get ("ipaddr" ), &ipaddr); +ipaddr_aton (env_get ("ipaddr" ), &netmask);Here I missed "netmask" for &netmask.
Quoted 62 lines
net/lwip/port/if.c line 240
Quoted 6 lines
net/lwip/port/if.c new file +6
-0+ +LWIP_PORT_INIT_NETMASK (&netmask); +if (IS_ENABLED (CONFIG_LWIP_LIB_DEBUG )) { +printf ("Starting lwIP, IP: %s\n" ,ip4addr_ntoa (&ipaddr)); +printf (" GW: %s\n" ,ip4addr_ntoa (&gw)); +printf (" mask: %s\n" ,ip4addr_ntoa (&netmask));
log_info()net/lwip/port/if.c
Quoted 11 lines
net/lwip/port/if.c new file +11
-0+ } + +if (!netif_add (unetif, &ipaddr, &netmask, &gw, + unetif, ulwip_if_init, ethernetif_input)) +printf ("err: netif_add failed!\n" ); + +netif_set_up (unetif); +netif_set_link_up (unetif); +#if LWIP_IPV6 +netif_create_ip6_linklocal_address (unetif,1 ); + printf(" IPv6: %s\n",
ip6addr_ntoa(netif_ip6_addr(unetif, 0)));Review
Quoted 10 lines
net/lwip/port/if.c new file +9
-0+#endif /* LWIP_IPV6 */ + +return CMD_RET_SUCCESS ; +} + +/* placeholder, not used now */ +void ulwip_destroy (void ) +{ +}(quoted diff) +0
-0
b/net/lwip/port/include/arch/cc.hQuoted 7 lines
new file mode 100644
index 0000000000..55f7787ce1net/lwip/port/include/arch/cc.h new file +2
-0@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +net/lwip/port/include/arch/cc.h line 12
Quoted 10 lines
net/lwip/port/include/arch/cc.h new file +10
-0+/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_ARCH_CC_H +#define LWIP_ARCH_CC_H + +#include <linux/types.h> +#include <linux/kernel.h> +//#include <stdlib.h> /* getenv, atoi */ Please dont leave comments like that
net/lwip/port/include/arch/cc.h line 19
Quoted 7 lines
net/lwip/port/include/arch/cc.h new file +7
-0+#include <vsprintf.h> + +#define LWIP_ERRNO_INCLUDE <errno.h> + +#define LWIP_ERRNO_STDINCLUDE 1 +#define LWIP_NO_UNISTD_H 1 +#define LWIP_TIMEVAL_PRIVATE 1Should those be defined in the LWIP config header instead?
Quoted 1 line
I would keep it here, like
./net/lwip/lwip-external/contrib/ports/unix/port/include/arch/cc.hdoes. Because LWIP config is more related to protocol features and settings and this header is about
porr for a specific platform.Quoted 7 lines
net/lwip/port/include/arch/cc.h line 21
Quoted 2 lines
net/lwip/port/include/arch/cc.h new file +2
-0+ +extern unsigned int lwip_port_rand (void );This is like the forth time we go through this and it's a repeating pattern. Why do we need this extern? Can't we just include the proper header files?
Quoted 5 lines
net/lwip/port/include/arch/cc.h line 22
Quoted 1 line
net/lwip/port/include/arch/cc.h new file +1
-0+#define LWIP_RAND () (lwip_port_rand())This seems quite useless. Just use the function directly
somehow I missed this, this should be direct call:
#include <rand.h>
#defineLWIP_RAND()((u32_t)rand())Quoted 38 lines
net/lwip/port/include/arch/cc.h
Quoted 4 lines
net/lwip/port/include/arch/cc.h new file +4
-0+ +/* different handling for unit test, normally not needed */ +#ifdef LWIP_NOASSERT_ON_ERROR +#define LWIP_ERROR (message, expression, handler) do { if(!(expression)) { \
net/lwip/port/include/arch/cc.h
Quoted 6 lines
net/lwip/port/include/arch/cc.h new file +6
-0+ handler; }} while (0) +#endif + +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS + +#define LWIP_PLATFORM_ASSERT (x) do {printf("Assertion \"%s\" failed atline %d in %s\n", \
Review
Quoted 8 lines
net/lwip/port/include/arch/cc.h new file +7
-0+ x, __LINE__, __FILE__); } while (0) + +#define atoi (str) (int)dectoul(str, NULL) + +#define LWIP_ERR_T int + +#endif /* LWIP_ARCH_CC_H */ (quoted diff) +0
-0
b/net/lwip/port/include/arch/sys_arch.hQuoted 17 lines
new file mode 100644
index 0000000000..92a8560d49net/lwip/port/include/arch/sys_arch.h new file +12
-0@@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#ifndef LWIP_ARCH_SYS_ARCH_H +#define LWIP_ARCH_SYS_ARCH_H + +#include "lwip/opt.h" +#include "lwip/arch.h" +#include "lwip/err.h" Quoted 10 lines
net/lwip/port/include/arch/sys_arch.h line 17
Quoted 5 lines
net/lwip/port/include/arch/sys_arch.h new file +5
-0+ +#define ERR_NEED_SCHED 123 + +void sys_arch_msleep (u32_t delay_ms); +#define sys_msleep (ms) sys_arch_msleep(ms)Dont redefine random functions here. U-Boot should already have all the sleep functions you need
dropeed.
Quoted 33 lines
net/lwip/port/include/arch/sys_arch.h line 19
Quoted 2 lines
net/lwip/port/include/arch/sys_arch.h new file +2
-0+ +#if SYS_LIGHTWEIGHT_PROT Is this working? Can we define
SYS_LIGHTWEIGHT_PROT?dropeed.
net/lwip/port/include/arch/sys_arch.h
Quoted 13 lines
net/lwip/port/include/arch/sys_arch.h new file +13
-0+typedef u32_t sys_prot_t ; +#endif /* SYS_LIGHTWEIGHT_PROT */ + +#include <errno.h> + +#define SYS_MBOX_NULL NULL +#define SYS_SEM_NULL NULL + +typedef u32_t sys_prot_t ; + +typedef struct sys_sem *sys_sem_t ; +#define sys_sem_valid (sem) (((sem) != NULL) && (*(sem) != NULL)) +#define sys_sem_set_invalid (sem) do { if ((sem) != NULL) { *(sem) =NULL; }} while (0)
net/lwip/port/include/arch/sys_arch.h
Quoted 9 lines
net/lwip/port/include/arch/sys_arch.h new file +9
-0+ +/* let sys.h use binary semaphores for mutexes */ +#define LWIP_COMPAT_MUTEX 1 +#define LWIP_COMPAT_MUTEX_ALLOWED 1 + +struct sys_mbox ; +typedef struct sys_mbox *sys_mbox_t ; +#define sys_mbox_valid (mbox) (((mbox) != NULL) && (*(mbox) != NULL)) +#define sys_mbox_set_invalid (mbox) do { if ((mbox) != NULL) { *(mbox) =NULL; }} while (0)
Quoted 3 lines
All these macros seem unnecessary. Just assign types to NULL directly etc
ok.
Quoted 16 lines
net/lwip/port/include/arch/sys_arch.h line 54
Quoted 13 lines
net/lwip/port/include/arch/sys_arch.h new file +13
-0+ +struct sys_thread ; +typedef struct sys_thread *sys_thread_t ; + +static inline u32_t sys_arch_sem_wait (sys_sem_t *sem,u32_t timeout) +{ +return 0 ; +}; + +static inline err_t sys_mbox_trypost (sys_mbox_t *mbox,void *msg) +{ +return 0 ; +};Are those really needed? Why do we just return 0?
Quoted 1 line
Not needed, I think I planned to implement socket API later where it's
needed. All these functions and macro can be defined to NULL with #define
NO_SYS1 in the lwip configuration.
This has to be an empty file.Quoted 24 lines
Review
Quoted 3 lines
net/lwip/port/include/arch/sys_arch.h new file +2
-0+ +#endif /* LWIP_ARCH_SYS_ARCH_H */ (quoted diff) +0
-0
b/net/lwip/port/include/limits.hQuoted 20 lines
new file mode 100644
index 0000000000..e69de29bb2net/lwip/port/sys-arch.c new file +12
-0@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* (C) Copyright 2023 Linaro Ltd. <[email protected]> +*/ + +#include <common.h> +#include <rand.h> +#include "lwip/opt.h" + +u32_t sys_now (void ) +{Quoted 10 lines
net/lwip/port/sys-arch.c line 18
Quoted 6 lines
net/lwip/port/sys-arch.c new file +6
-0+return get_timer (0 ); +} + +u32_t lwip_port_rand (void ) +{ +return (u32_t )rand ();I dont see why we cant use the U-Boot defined ones directly
changed.
Quoted 9 lines
Quoted 5 lines
net/lwip/port/sys-arch.c new file +2
-1+} + --2.30.2
Thanks
/Ilias
PATCH v6 10/14 net/lwip: update .gitignore with lwIP
In reply to Maxim Uvarovignore lwIP library code and reused files from the lwIP.
--- net/lwip/.gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 net/lwip/.gitignore
net/lwip/.gitignore new file +8 -0
@@ -0,0 +1,8 @@ +lwip-external +apps/ping/ping.c +apps/http/http_client.c +apps/http/http_client.h +apps/tftp/tftp.c +apps/tftp/tftp_client.h +apps/tftp/tftp_common.h +apps/tftp/tftp_example.h
Signature · 1 line
2.30.2
PATCH v6 11/14 net/lwip: connection between cmd and lwip apps
In reply to Maxim Uvarov--- cmd/Makefile | 1 + cmd/net-lwip.c | 306 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 cmd/net-lwip.c
cmd/Makefile +1 -0
@@ -128,6 +128,7 @@ endif obj-$(CONFIG_CMD_MUX) += mux.o obj-$(CONFIG_CMD_NAND) += nand.o obj-$(CONFIG_CMD_NET) += net.o +obj-$(CONFIG_CMD_NET) += net-lwip.o obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o obj-$(CONFIG_CMD_ONENAND) += onenand.o obj-$(CONFIG_CMD_OSD) += osd.o
cmd/net-lwip.c new file +306 -0
306 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCHv6 11/14] net/lwip: connection between cmd and lwip apps
On Mon, Aug 14, 2023 at 07:32:50PM +0600, Maxim Uvarov wrote:
Commit message missing again
Quoted 17 lines
Signed-off-by Maxim Uvarov <[email protected]>--- cmd/Makefile | 1 + cmd/net-lwip.c | 306 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 cmd/net-lwip.ccmd/net-lwip.c new file +11
-0+static int do_lwip_init (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]) +{ +if (!ulwip_init ()) +return CMD_RET_SUCCESS ; +return CMD_RET_FAILURE ; +} + +static int lwip_empty_tmo (void ) {return 0 ; }; +int (*ulwip_tmo)(void ) = lwip_empty_tmo; +void ulwip_set_tmo (int (*tmo)(void ))
cmd/net-lwip.c line 38
Quoted 10 lines
cmd/net-lwip.c new file +10
-0+{ + ulwip_tmo = tmo; +} + +static void ulwip_clear_tmo (void ) +{ + ulwip_tmo = lwip_empty_tmo; +} + +static void ulwip_timeout_handler (void )
We discussed this in the previous patchset but I am not convinced this is the best approach. Instead of setting the callback function on the dhcp and ping commands and calling a function pointer here, just define discrete function and set them during net_set_timeout_handler() if there is common code like eth_halt() etc just create a function with them
Quoted 111 lines
cmd/net-lwip.c new file +111
-0+{ +eth_halt (); +ulwip_tmo (); +net_set_state (NETLOOP_FAIL );/* we did not get the reply */ +ulwip_loop_set (0 ); +} + +int ulwip_loop (void ) +{ +int ret =CMD_RET_FAILURE ; + +ulwip_loop_set (1 ); +if (!net_loop (LWIP )) + ret =CMD_RET_SUCCESS ; +ulwip_loop_set (0 ); +return ret; +} + +#if defined(CONFIG_CMD_PING ) +int do_lwip_ping (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]) +{ +int ret; + +if (argc <2 ) { +printf ("argc = %d, error\n" , argc); +return CMD_RET_USAGE ; + } + + ret =ulwip_init (); +if (ret) { +log_err ("ulwip_init err %d\n" , ret); +return CMD_RET_FAILURE ; + } + +printf ("Using %s device\n" ,eth_get_name ()); +printf ("pinging addr: %s\n" , argv[1 ]); + +net_set_timeout_handler (1000UL , ulwip_timeout_handler); + +if (ulwip_ping (argv[1 ])) { +printf ("ping init fail\n" ); +return CMD_RET_FAILURE ; + } + +return ulwip_loop (); +} +#endif /* CONFIG_CMD_PING */ + +#if defined(CONFIG_CMD_WGET ) +int do_lwip_wget (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]) +{ +char *url; +int ret; + +if (argc <2 ) +return CMD_RET_USAGE ; + + url = argv[1 ]; + + ret =ulwip_init (); +if (ret) { +log_err ("ulwip_init err %d\n" , ret); +return CMD_RET_FAILURE ; + } + + ret =ulwip_wget (image_load_addr, url); +if (ret) { +log_err ("lwip_wget err %d\n" , ret); +return CMD_RET_FAILURE ; + } + + +return ulwip_loop (); +} +#endif + +#if defined(CONFIG_CMD_TFTPBOOT ) +int do_lwip_tftp (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]) +{ +char *filename; +ulong addr; +char *end; +int ret; + +switch (argc) { +case 1 : + filename =env_get ("bootfile" ); +break ; +case 2 : +/* +* Only one arg - accept two forms: +* Just load address, or just boot file name. The latter +* form must be written in a format which can not be +* mis-interpreted as a valid number. +*/ + addr =hextoul (argv[1 ], &end); +if (end == (argv[1 ] +strlen (argv[1 ]))) { + image_load_addr = addr; + filename =env_get ("bootfile" ); + }else { + filename = argv[1 ]; + } +break ; +case 3 : + image_load_addr =hextoul (argv[1 ],NULL ); + filename = argv[2 ]; +break ; +default :
cmd/net-lwip.c line 159
Quoted 10 lines
cmd/net-lwip.c new file +10
-0+return CMD_RET_USAGE ; + } + + ret =ulwip_init (); +if (ret) { +log_err ("ulwip_init err %d\n" , ret); +return CMD_RET_FAILURE ; + } + + ret =ulwip_tftp (image_load_addr, filename);
filename can be NULL. We went through this on v4 as well. Go through all the comments and fix them before v6.
Quoted 150 lines
cmd/net-lwip.c new file +147
-0+if (ret) +return ret; + +return ulwip_loop (); +} +#endif /* CONFIG_CMD_TFTPBOOT */ + +#if defined(CONFIG_CMD_DHCP ) +int do_lwip_dhcp (void ) +{ +int ret; +char *filename; + + ret =ulwip_init (); +if (ret) { +log_err ("ulwip_init err %d\n" , ret); +return CMD_RET_FAILURE ; + } + + ret =ulwip_dhcp (); + +net_set_timeout_handler (2000UL , ulwip_timeout_handler); + +ulwip_loop (); +if (IS_ENABLED (CONFIG_CMD_TFTPBOOT )) { +ulwip_clear_tmo (); + + filename =env_get ("bootfile" ); +if (!filename) { +log_notice ("no bootfile\n" ); +return CMD_RET_SUCCESS ; + } + + ret =ulwip_init (); +if (ret) { +log_err ("ulwip_init err %d\n" , ret); +return CMD_RET_FAILURE ; + } + +net_set_timeout_handler (20000UL , ulwip_timeout_handler); +ulwip_tftp (image_load_addr, filename); + + ret =ulwip_loop (); + } + +return ret; +} + +static int _do_lwip_dhcp (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]) +{ +return do_lwip_dhcp (); +} +#endif /* CONFIG_CMD_DHCP */ + +#if defined(CONFIG_CMD_DNS ) +int do_lwip_dns (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]) +{ +int ret; +char *name; +char *varname; +int LWIP_ERR_INPROGRESS =-5 ;/* lwip/err.h */ + +if (argc ==1 ) +return CMD_RET_USAGE ; + + name = argv[1 ]; + +if (argc ==3 ) + varname = argv[2 ]; +else + varname =NULL ; + + ret =ulwip_init (); +if (ret) { +log_err ("ulwip_init err %d\n" , ret); +return CMD_RET_FAILURE ; + } + + ret =ulwip_dns (name, varname); +if (ret ==0 ) +return CMD_RET_SUCCESS ; +if (ret !=LWIP_ERR_INPROGRESS ) +return CMD_RET_FAILURE ; + +net_set_timeout_handler (1000UL , ulwip_timeout_handler); + +return ulwip_loop (); +} +#endif /* CONFIG_CMD_DNS */ + +static struct cmd_tbl cmds[] = { +U_BOOT_CMD_MKENT (init,1 ,0 , do_lwip_init, +"initialize lwip stack" ,"" ), +#if defined(CONFIG_CMD_PING) +U_BOOT_CMD_MKENT (ping,2 ,0 , do_lwip_ping, +"send ICMP ECHO_REQUEST to network host" , +"pingAddress" ), +#endif +#if defined(CONFIG_CMD_WGET) +U_BOOT_CMD_MKENT (wget,2 ,0 , do_lwip_wget,"" ,"" ), +#endif +#if defined(CONFIG_CMD_TFTPBOOT) +U_BOOT_CMD_MKENT (tftp,3 ,0 , do_lwip_tftp, +"boot image via network using TFTP protocol\n" , +"[loadAddress] [[hostIPaddr:]bootfilename]" ), +#endif +#if defined(CONFIG_CMD_DHCP) +U_BOOT_CMD_MKENT (dhcp,1 ,0 , _do_lwip_dhcp, +"boot image via network using DHCP/TFTP protocol" , +"" ), +#endif +#if defined(CONFIG_CMD_DNS) +U_BOOT_CMD_MKENT (dns,3 ,0 , do_lwip_dns, +"lookup dns name [and store address at variable]" , +"" ), +#endif +}; + +static int do_ops (struct cmd_tbl *cmdtp,int flag,int argc, +char *const argv[]) +{ +struct cmd_tbl *cp; + + cp =find_cmd_tbl (argv[1 ], cmds,ARRAY_SIZE (cmds)); + + argc--; + argv++; + +if (cp ==NULL || argc > cp->maxargs) +return CMD_RET_USAGE ; +if (flag ==CMD_FLAG_REPEAT && !cmd_is_repeatable (cp)) +return CMD_RET_SUCCESS ; + +return cp->cmd (cmdtp, flag, argc, argv); +} + +U_BOOT_CMD ( + lwip,4 ,1 , do_ops, +"LWIP sub system" , +"init - init LWIP\n" +"ping addr - pingAddress\n" +"wget http://IPadress/url/\n" +"tftp [loadAddress] [[hostIPaddr:]bootfilename]\n" +"dhcp - boot image via network using DHCP/TFTP protocol\n" + );Signature · 1 line
2.30.2
Thanks
/Ilias
PATCH v6 12/14 net/lwip: replace original net commands with lwip
In reply to Maxim UvarovReplace original commands: ping, tftp, dhcp and wget.
--- boot/bootmeth_efi.c | 18 +++++++--- boot/bootmeth_pxe.c | 21 ++++++----- cmd/net.c | 86 +++++---------------------------------------- cmd/pxe.c | 19 +++++----- include/net.h | 8 +++-- include/net/ulwip.h | 68 +++++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 103 deletions(-) create mode 100644 include/net/ulwip.h
boot/bootmeth_efi.c +13 -5
@@ -20,6 +20,8 @@#include <mapmem.h> #include <mmc.h> #include <net.h> +#include <net/lwip.h> +#include <net/ulwip.h> #include <pxe_utils.h> #include <linux/sizes.h>
@@ -319,9 +321,7 @@ static int distro_efi_try_bootflow_files(struct udevice *dev,static int distro_efi_read_bootflow_net (struct bootflow *bflow) { -char file_addr[17 ], fname[256 ]; -char *tftp_argv[] = {"tftp" , file_addr, fname,NULL }; -struct cmd_tbl cmdtp = {};/* dummy */ +char fname[256 ];const char *addr_str, *fdt_addr_str;int ret, arch, size;ulong addr, fdt_addr;
@@ -368,7 +368,6 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)if (!fdt_addr_str)return log_msg_ret ("fdt" , -EINVAL ); fdt_addr =hextoul (fdt_addr_str,NULL ); -sprintf (file_addr,"%lx" , fdt_addr);/* We only allow the first prefix with PXE */ ret =distro_efi_get_fdt_name (fname,sizeof (fname),0 );
@@ -379,7 +378,16 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)if (!bflow->fdt_fname)return log_msg_ret ("fil" , -ENOMEM ); -if (!do_tftpb (&cmdtp,0 ,3 , tftp_argv)) { + ret =ulwip_init (); +if (ret) +return log_msg_ret ("ulwip_init" , ret); + + ret =ulwip_tftp (fdt_addr, fname); +if (ret) +return log_msg_ret ("ulwip_tftp" , ret); + + ret =ulwip_loop (); +if (!ret) { bflow->fdt_size =env_get_hex ("filesize" ,0 ); bflow->fdt_addr = fdt_addr; }else {
boot/bootmeth_pxe.c +13 -8
@@ -21,6 +21,8 @@#include <mapmem.h> #include <mmc.h> #include <net.h> +#include <net/ulwip.h> +#include <net/lwip.h> #include <pxe_utils.h> static int extlinux_pxe_getfile(struct pxe_context *ctx, const char *file_path,
@@ -116,18 +118,21 @@ static int extlinux_pxe_read_file(struct udevice *dev, struct bootflow *bflow, const char *file_path, ulong addr, ulong *sizep) { - char *tftp_argv[] = {"tftp", NULL, NULL, NULL}; -struct pxe_context *ctx =dev_get_priv (dev); -char file_addr[17 ]; ulong size;int ret; -sprintf (file_addr,"%lx" , addr); - tftp_argv[1 ] = file_addr; - tftp_argv[2 ] = (void *)file_path; + ret =ulwip_init (); +if (ret) +return log_msg_ret ("ulwip_init" , ret); + + ret =ulwip_tftp (addr, file_path); +if (ret) +return log_msg_ret ("ulwip_tftp" , ret); + + ret =ulwip_loop (); +if (ret) +return log_msg_ret ("ulwip_loop" , ret); -if (do_tftpb (ctx->cmdtp,0 ,3 , tftp_argv)) -return -ENOENT ; ret =pxe_get_file_size (&size);if (ret)return log_msg_ret ("tftp" , ret);
cmd/net.c +9 -77
134 lines not on this page · raw message
cmd/pxe.c +9 -10
@@ -8,6 +8,7 @@#include <command.h> #include <fs.h> #include <net.h> +#include <net/lwip.h> #include <net6.h> #include <malloc.h>
@@ -29,21 +30,19 @@ const char *pxe_default_paths[] = {static int do_get_tftp (struct pxe_context *ctx,const char *file_path,char *file_addr,ulong *sizep) { -char *tftp_argv[] = {"tftp" ,NULL ,NULL ,NULL }; +ulong addr; +char *end;int ret; -int num_args; - tftp_argv[1 ] = file_addr; - tftp_argv[2 ] = (void *)file_path; + addr =hextoul (file_addr, &end); +if (ctx->use_ipv6) { - tftp_argv[3 ] =USE_IP6_CMD_PARAM ; - num_args =4 ; - }else { - num_args =3 ; +/* @todo: check and fix me, here */ } -if (do_tftpb (ctx->cmdtp,0 , num_args, tftp_argv)) -return -ENOENT ; + ret =ulwip_tftp (addr, file_path); +if (ret) +return log_msg_ret ("tftp" , ret); ret =pxe_get_file_size (sizep);if (ret)
include/net.h +5 -3
@@ -54,8 +54,10 @@ struct in_addr {__be32 s_addr; }; +int do_lwip_dhcp (void ); +/** -* do_tftpb - Run the tftpboot command +* do_lwip_tftp - Run the tftpboot command * * @cmdtp: Command information for tftpboot * @flag: Command flags (CMD_FLAG_...)
@@ -63,7 +65,7 @@ struct in_addr {* @argv: List of arguments * Return: result (see enum command_ret_t) */ -int do_tftpb (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]); +int do_lwip_tftp (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]);/** * dhcp_run() - Run DHCP on the current ethernet device
@@ -514,7 +516,7 @@ extern int net_restart_wrap; /* Tried all network devices */enum proto_t {BOOTP ,RARP ,ARP ,TFTPGET ,DHCP ,DHCP6 ,PING ,PING6 ,DNS ,NFS ,CDP ,NETCONS ,SNTP ,TFTPSRV ,TFTPPUT ,LINKLOCAL ,FASTBOOT_UDP ,FASTBOOT_TCP , -WOL ,UDP ,NCSI ,WGET ,RS +WOL ,UDP ,NCSI ,WGET ,RS ,LWIP };extern char net_boot_file_name[1024 ];/* Boot File name */
include/net/ulwip.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v6 13/14 net/lwip: split net.h to net.h, arp.h and eth.h
In reply to Maxim Uvarovcurrent net.h has ethernet and protocol definitions. Protocol definitions overlap with lwIP protocol definitions and net.h can not be included from lwIP code. Splitting on logical blocks makes that work.
--- include/net.h | 189 +-------------------------------------------- include/net/arp.h | 7 ++ include/net/eth.h | 190 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 185 deletions(-) create mode 100644 include/net/arp.h create mode 100644 include/net/eth.h
include/net.h +4 -185
@@ -20,6 +20,7 @@#include <time.h> #include <linux/if_ether.h> #include <rand.h> +#include <net/arp.h> struct bd_info ;struct cmd_tbl ;
@@ -30,25 +31,6 @@ struct udevice;#define DEBUG_NET_PKT 0/* Packets on info on the network at large */ #define DEBUG_INT_STATE 0/* Internal network state changes */ -/* -* The number of receive packet buffers, and the required packet buffer -* alignment in memory. -* -*/ -#define PKTBUFSRX CONFIG_SYS_RX_ETH_BUFFER -#define PKTALIGN ARCH_DMA_MINALIGN - -/* Number of packets processed together */ -#define ETH_PACKETS_BATCH_RECV 32 - -/* ARP hardware address length */ -#define ARP_HLEN 6 -/* -* The size of a MAC address in string form, each digit requires two chars -* and five separator characters to form '00:00:00:00:00:00'. -*/ -#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1) -/* IPv4 addresses are always 32 bits in size */ struct in_addr {__be32 s_addr;
@@ -112,150 +94,7 @@ typedef void rxhand_icmp_f(unsigned type, unsigned code, unsigned dport,*/ typedef void thand_f (void ); -enum eth_state_t { -ETH_STATE_INIT , -ETH_STATE_PASSIVE , -ETH_STATE_ACTIVE -}; - -/** -* struct eth_pdata - Platform data for Ethernet MAC controllers -* -* @iobase: The base address of the hardware registers -* @enetaddr: The Ethernet MAC address that is loaded from EEPROM or env -* @phy_interface: PHY interface to use - see PHY_INTERFACE_MODE_... -* @max_speed: Maximum speed of Ethernet connection supported by MAC -* @priv_pdata: device specific plat -*/ -struct eth_pdata { -phys_addr_t iobase; -unsigned char enetaddr[ARP_HLEN ]; -int phy_interface; -int max_speed; -void *priv_pdata; -}; - -enum eth_recv_flags { -/* -* Check hardware device for new packets (otherwise only return those -* which are already in the memory buffer ready to process) -*/ -ETH_RECV_CHECK_DEVICE =1 <<0 , -}; - -/** -* struct eth_ops - functions of Ethernet MAC controllers -* -* start: Prepare the hardware to send and receive packets -* send: Send the bytes passed in "packet" as a packet on the wire -* recv: Check if the hardware received a packet. If so, set the pointer to the -* packet buffer in the packetp parameter. If not, return an error or 0 to -* indicate that the hardware receive FIFO is empty. If 0 is returned, the -* network stack will not process the empty packet, but free_pkt() will be -* called if supplied -* free_pkt: Give the driver an opportunity to manage its packet buffer memory -* when the network stack is finished processing it. This will only be -* called when no error was returned from recv - optional -* stop: Stop the hardware from looking for packets - may be called even if -* state == PASSIVE -* mcast: Join or leave a multicast group (for TFTP) - optional -* write_hwaddr: Write a MAC address to the hardware (used to pass it to Linux -* on some platforms like ARM). This function expects the -* eth_pdata::enetaddr field to be populated. The method can -* return -ENOSYS to indicate that this is not implemented for -this hardware - optional. -* read_rom_hwaddr: Some devices have a backup of the MAC address stored in a -* ROM on the board. This is how the driver should expose it -* to the network stack. This function should fill in the -* eth_pdata::enetaddr field - optional -* set_promisc: Enable or Disable promiscuous mode -* get_sset_count: Number of statistics counters -* get_string: Names of the statistic counters -* get_stats: The values of the statistic counters -*/ -struct eth_ops { -int (*start)(struct udevice *dev); -int (*send)(struct udevice *dev,void *packet,int length); -int (*recv)(struct udevice *dev,int flags,uchar **packetp); -int (*free_pkt)(struct udevice *dev,uchar *packet,int length); -void (*stop)(struct udevice *dev); -int (*mcast)(struct udevice *dev,const u8 *enetaddr,int join); -int (*write_hwaddr)(struct udevice *dev); -int (*read_rom_hwaddr)(struct udevice *dev); -int (*set_promisc)(struct udevice *dev,bool enable); -int (*get_sset_count)(struct udevice *dev); -void (*get_strings)(struct udevice *dev,u8 *data); -void (*get_stats)(struct udevice *dev,u64 *data); -}; - -#define eth_get_ops (dev) ((struct eth_ops *)(dev)->driver->ops) - -struct udevice *eth_get_dev (void );/* get the current device */ -/* -* The devname can be either an exact name given by the driver or device tree -* or it can be an alias of the form "eth%d" -*/ -struct udevice *eth_get_dev_by_name (const char *devname); -unsigned char *eth_get_ethaddr (void );/* get the current device MAC */ - -/* Used only when NetConsole is enabled */ -int eth_is_active (struct udevice *dev);/* Test device for active state */ -int eth_init_state_only (void );/* Set active state */ -void eth_halt_state_only (void );/* Set passive state */ - -int eth_initialize (void );/* Initialize network subsystem */ -void eth_try_another (int first_restart);/* Change the device */ -void eth_set_current (void );/* set nterface to ethcur var */ - -int eth_get_dev_index (void );/* get the device index */ - -/** -* eth_env_set_enetaddr_by_index() - set the MAC address environment variable -* -* This sets up an environment variable with the given MAC address (@enetaddr). -* The environment variable to be set is defined by <@base_name><@index>addr. -* If @index is 0 it is omitted. For common Ethernet this means ethaddr, -* eth1addr, etc. -* -* @base_name: Base name for variable, typically "eth" -* @index: Index of interface being updated (>=0) -* @enetaddr: Pointer to MAC address to put into the variable -* Return: 0 if OK, other value on error -*/ -int eth_env_set_enetaddr_by_index (const char *base_name,int index, -uchar *enetaddr); - - -/* -* Initialize USB ethernet device with CONFIG_DM_ETH -* Returns: -* 0 is success, non-zero is error status. -*/ -int usb_ether_init (void ); - -/* -* Get the hardware address for an ethernet interface . -* Args: -* base_name - base name for device (normally "eth") -* index - device index number (0 for first) -* enetaddr - returns 6 byte hardware address -* Returns: -* Return true if the address is valid. -*/ -int eth_env_get_enetaddr_by_index (const char *base_name,int index, -uchar *enetaddr); - -int eth_init (void );/* Initialize the device */ -int eth_send (void *packet,int length);/* Send a packet */ - -#if defined(CONFIG_API ) || defined(CONFIG_EFI_LOADER ) -int eth_receive (void *packet,int length);/* Receive a packet*/ -extern void (*push_packet)(void *packet,int length); -#endif -int eth_rx (void );/* Check for received packets */ -void eth_halt (void );/* stop SCC */ -const char *eth_get_name (void );/* get name of current device */ -int eth_mcast_join (struct in_addr mcast_addr,int join); +#include <net/eth.h> /**********************************************************************/ /*
@@ -495,16 +334,6 @@ extern char net_root_path[CONFIG_BOOTP_MAX_ROOT_PATH_LEN]; /* Our root path *//* Indicates whether the pxe path prefix / config file was specified in dhcp option */ extern char *pxelinux_configfile;/** END OF BOOTP EXTENTIONS **/ -extern u8 net_ethaddr[ARP_HLEN ];/* Our ethernet address */ -extern u8 net_server_ethaddr[ARP_HLEN ];/* Boot server enet address */ -extern struct in_addr net_ip;/* Our IP addr (0 = unknown) */ -extern struct in_addr net_server_ip;/* Server IP addr (0 = unknown) */ -extern uchar *net_tx_packet;/* THE transmit packet */ -extern uchar *net_rx_packets[PKTBUFSRX ];/* Receive packets */ -extern uchar *net_rx_packet;/* Current receive packet */ -extern int net_rx_packet_len;/* Current rx packet length */ -extern const u8 net_bcast_ethaddr[ARP_HLEN ];/* Ethernet broadcast address */ -extern const u8 net_null_ethaddr[ARP_HLEN ];#define VLAN_NONE 4095/* untagged */ #define VLAN_IDMASK 0x0fff/* mask of valid vlan id */
@@ -557,6 +386,8 @@ extern struct in_addr net_ntp_server; /* the ip address to NTP */extern int net_ntp_time_offset;/* offset time from UTC */ #endif +int eth_mcast_join (struct in_addr mcast_addr,int join); +/* Initialize the network adapter */ int net_init (void );int net_loop (enum proto_t );
@@ -827,18 +658,6 @@ static inline void net_random_ethaddr(uchar *addr) addr[0 ] |=0x02 ;/* set local assignment bit (IEEE802) */ } -/** -* string_to_enetaddr() - Parse a MAC address -* -* Convert a string MAC address -* -* Implemented in lib/net_utils.c (built unconditionally) -* -* @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit -* hex value -* @enetaddr: Place to put MAC address (6 bytes) -*/ -void string_to_enetaddr (const char *addr,uint8_t *enetaddr);/* Convert an IP address to a string */ void ip_to_string (struct in_addr x,char *s);
include/net/arp.h new file +7 -0
@@ -0,0 +1,7 @@ +/* ARP hardware address length */ +#define ARP_HLEN 6 +/* +* The size of a MAC address in string form, each digit requires two chars +* and five separator characters to form '00:00:00:00:00:00'. +*/ +#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1)
include/net/eth.h new file +190 -0
190 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v6 14/14 net/lwip: drop old net/wget
In reply to Maxim UvarovAfter which to lwip variants of working apps we need to drop old code with all dependencies. This commit drop old wget command files.
--- include/net/wget.h | 22 --- net/Makefile | 1 - net/net.c | 6 - net/wget.c | 440 --------------------------------------------- 4 files changed, 469 deletions(-) delete mode 100644 include/net/wget.h delete mode 100644 net/wget.c
include/net/wget.h deleted +0 -22
@@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Duncan Hare Copyright 2017 -*/ - -/** -* wget_start() - begin wget -*/ -void wget_start (void ); - -enum wget_state { -WGET_CLOSED , -WGET_CONNECTING , -WGET_CONNECTED , -WGET_TRANSFERRING , -WGET_TRANSFERRED -}; - -#define DEBUG_WGET 0/* Set to 1 for debug messages */ -#define SERVER_PORT 80 -#define WGET_RETRY_COUNT 30 -#define WGET_TIMEOUT 2000UL
net/Makefile +0 -1
@@ -32,7 +32,6 @@ obj-$(CONFIG_TCP_FUNCTION_FASTBOOT) += fastboot_tcp.o obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_PROT_UDP) += udp.o obj-$(CONFIG_PROT_TCP) += tcp.o -obj-$(CONFIG_CMD_WGET) += wget.o obj-$(CONFIG_LWIP) += lwip/ # Disable this warning as it is triggered by:
net/net.c +0 -6
@@ -109,7 +109,6 @@#include <linux/compiler.h> #include <test/test.h> #include <net/tcp.h> -#include <net/wget.h> #include "arp.h" #include "bootp.h" #include "cdp.h"
@@ -566,11 +565,6 @@ restart:nfs_start ();break ;#endif -#if defined(CONFIG_CMD_WGET ) -case WGET : -wget_start (); -break ; -#endif #if defined(CONFIG_CMD_CDP )case CDP :cdp_start ();
net/wget.c deleted +0 -440
440 lines not on this page · raw message
Signature · 1 line
2.30.2