diff mbox series

[PATHv11,07/43] net/lwip: implement wget cmd

Message ID 20231127125726.3735-8-maxim.uvarov@linaro.org
State New
Headers show
Series net/lwip: add lwip library for the network stack | expand

Commit Message

Maxim Uvarov Nov. 27, 2023, 12:56 p.m. UTC
U-Boot recently got support for an alternative network stack using LWIP.
Replace wget command with the LWIP variant while keeping the output and
error messages identical.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 include/net/lwip.h             |  14 +++++
 net/lwip/Makefile              |   1 +
 net/lwip/apps/http/Makefile    |   6 ++
 net/lwip/apps/http/lwip-wget.c | 105 +++++++++++++++++++++++++++++++++
 4 files changed, 126 insertions(+)
 create mode 100644 net/lwip/apps/http/Makefile
 create mode 100644 net/lwip/apps/http/lwip-wget.c

Comments

Fabio Estevam Nov. 28, 2023, 11:32 a.m. UTC | #1
Hi Maxim,

On Mon, Nov 27, 2023 at 5:46 PM Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>
> U-Boot recently got support for an alternative network stack using LWIP.
> Replace wget command with the LWIP variant while keeping the output and
> error messages identical.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

Do you know whether this wget issue also happens when LWIP is used?

https://lore.kernel.org/u-boot/CAJ+vNU2U9W2NRT6hf1CAEQ_56SDQviUEzuDD1iYOpdf1CNaZBw@mail.gmail.com/
Maxim Uvarov Nov. 28, 2023, 7:07 p.m. UTC | #2
On Tue, 28 Nov 2023 at 17:32, Fabio Estevam <festevam@gmail.com> wrote:

> Hi Maxim,
>
> On Mon, Nov 27, 2023 at 5:46 PM Maxim Uvarov <maxim.uvarov@linaro.org>
> wrote:
> >
> > U-Boot recently got support for an alternative network stack using LWIP.
> > Replace wget command with the LWIP variant while keeping the output and
> > error messages identical.
> >
> > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>
> Do you know whether this wget issue also happens when LWIP is used?
>
>
> https://lore.kernel.org/u-boot/CAJ+vNU2U9W2NRT6hf1CAEQ_56SDQviUEzuDD1iYOpdf1CNaZBw@mail.gmail.com/



From this log it's a little bit different wget output. My version prints
"#"  for status. So I guess it's original wget. You can spend time on
debugging it but this code will be replaced.
With my code I tried big iso download and check crc. I did not see any
issues.

BR,
Maxim.
Fabio Estevam Nov. 28, 2023, 7:12 p.m. UTC | #3
Hi Maxim,

On Tue, Nov 28, 2023 at 4:07 PM Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> From this log it's a little bit different wget output. My version prints "#"  for status. So I guess it's original wget. You can spend time on debugging it but this code will be replaced.
> With my code I tried big iso download and check crc. I did not see any issues.

Thanks for your feedback.

I will test wget again after your series gets merged.

Cheers
Tim Harvey Nov. 28, 2023, 8:41 p.m. UTC | #4
On Tue, Nov 28, 2023 at 11:12 AM Fabio Estevam <festevam@gmail.com> wrote:
>
> Hi Maxim,
>
> On Tue, Nov 28, 2023 at 4:07 PM Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>
> > From this log it's a little bit different wget output. My version prints "#"  for status. So I guess it's original wget. You can spend time on debugging it but this code will be replaced.
> > With my code I tried big iso download and check crc. I did not see any issues.
>
> Thanks for your feedback.
>
> I will test wget again after your series gets merged.
>

Hi Maxim,

Do you have a git repo that we can pull from to test for the wget failure?

Best regards,

Tim
Tom Rini Nov. 28, 2023, 8:43 p.m. UTC | #5
On Tue, Nov 28, 2023 at 12:41:44PM -0800, Tim Harvey wrote:
> On Tue, Nov 28, 2023 at 11:12 AM Fabio Estevam <festevam@gmail.com> wrote:
> >
> > Hi Maxim,
> >
> > On Tue, Nov 28, 2023 at 4:07 PM Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> >
> > > From this log it's a little bit different wget output. My version prints "#"  for status. So I guess it's original wget. You can spend time on debugging it but this code will be replaced.
> > > With my code I tried big iso download and check crc. I did not see any issues.
> >
> > Thanks for your feedback.
> >
> > I will test wget again after your series gets merged.
> >
> 
> Hi Maxim,
> 
> Do you have a git repo that we can pull from to test for the wget failure?

Note that "b4 am" for this series works currently on top of master, and
getting more general testing on real hardware would be very nice.
Maxim Uvarov Nov. 29, 2023, 7:18 a.m. UTC | #6
Tim,

https://github.com/muvarov/u-boot/tree/master_lwip_test_v10
(branch master_lwip_test_v10)

Commit 8617b290e79e526119ccef0b0090cb220c78dd34
All later commits are experimental and I'm testing them in the CI.

And yes, this series has to apply to the current master without rejects.

BR,
Maxim.


On Wed, 29 Nov 2023 at 02:43, Tom Rini <trini@konsulko.com> wrote:

> On Tue, Nov 28, 2023 at 12:41:44PM -0800, Tim Harvey wrote:
> > On Tue, Nov 28, 2023 at 11:12 AM Fabio Estevam <festevam@gmail.com>
> wrote:
> > >
> > > Hi Maxim,
> > >
> > > On Tue, Nov 28, 2023 at 4:07 PM Maxim Uvarov <maxim.uvarov@linaro.org>
> wrote:
> > >
> > > > From this log it's a little bit different wget output. My version
> prints "#"  for status. So I guess it's original wget. You can spend time
> on debugging it but this code will be replaced.
> > > > With my code I tried big iso download and check crc. I did not see
> any issues.
> > >
> > > Thanks for your feedback.
> > >
> > > I will test wget again after your series gets merged.
> > >
> >
> > Hi Maxim,
> >
> > Do you have a git repo that we can pull from to test for the wget
> failure?
>
> Note that "b4 am" for this series works currently on top of master, and
> getting more general testing on real hardware would be very nice.
>
> --
> Tom
>
diff mbox series

Patch

diff --git a/include/net/lwip.h b/include/net/lwip.h
index f025384c26..04ffbec006 100644
--- a/include/net/lwip.h
+++ b/include/net/lwip.h
@@ -42,3 +42,17 @@  int ulwip_dhcp(void);
  * Returns:  0 if success, !0 if error
  */
 int ulwip_tftp(ulong addr, const char *filename);
+
+/**
+ * ulwip_wget() - creates the HTTP request to download file
+ *
+ * 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/url
+ * Returns: 0 for success, !0 if error
+ */
+int ulwip_wget(ulong addr, char *url);
diff --git a/net/lwip/Makefile b/net/lwip/Makefile
index b348e5ca31..61042862e1 100644
--- a/net/lwip/Makefile
+++ b/net/lwip/Makefile
@@ -66,3 +66,4 @@  obj-$(CONFIG_NET) += port/sys-arch.o
 obj-y += apps/dhcp/lwip-dhcp.o
 obj-y += apps/dns/lwip-dns.o
 obj-y += apps/tftp/
+obj-y += apps/http/
diff --git a/net/lwip/apps/http/Makefile b/net/lwip/apps/http/Makefile
new file mode 100644
index 0000000000..ac0b3ede0d
--- /dev/null
+++ b/net/lwip/apps/http/Makefile
@@ -0,0 +1,6 @@ 
+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$(srctree)/net/lwip/lwip-external/src/include/lwip/apps
+
+obj-$(CONFIG_CMD_WGET) += ../../lwip-external/src/apps/http/http_client.o
+obj-$(CONFIG_CMD_WGET) += lwip-wget.o
diff --git a/net/lwip/apps/http/lwip-wget.c b/net/lwip/apps/http/lwip-wget.c
new file mode 100644
index 0000000000..7a7cc3273d
--- /dev/null
+++ b/net/lwip/apps/http/lwip-wget.c
@@ -0,0 +1,105 @@ 
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. <maxim.uvarov@linaro.org>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <console.h>
+#include <vsprintf.h>
+
+#include "http_client.h"
+#include <net/ulwip.h>
+
+static ulong daddr;
+static httpc_connection_t settings;
+
+#define SERVER_NAME_SIZE 200
+#define HTTP_PORT_DEFAULT 80
+
+static err_t httpc_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf,
+			err_t unused_err)
+{
+	struct pbuf *buf;
+
+	if (!pbuf)
+		return ERR_BUF;
+
+	for (buf = pbuf; buf != NULL; buf = buf->next) {
+		memcpy((void *)daddr, buf->payload, buf->len);
+		log_debug("downloaded chunk size %d, to addr 0x%lx\n",
+			  buf->len, daddr);
+		daddr += buf->len;
+	}
+
+	altcp_recved(pcb, pbuf->tot_len);
+	pbuf_free(pbuf);
+	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);
+		env_set_hex("filesize", rx_content_len);
+		ulwip_exit(0);
+	} else {
+		log_err("\nhttp eroror: %d\n", httpc_result);
+		ulwip_exit(-1);
+	}
+}
+
+/* http://hostname/url */
+static int parse_url(char *url, char *host, u16 *port)
+{
+	char *p, *pp;
+
+	p = strstr(url, "http://");
+	if (!p)
+		return -ENOENT;
+
+	p += strlen("http://");
+
+	/* parse hostname */
+	pp = strchr(p, '/');
+	if (!pp)
+		return -ENOENT;
+
+	if (p + SERVER_NAME_SIZE <= pp)
+		return -ENOENT;
+
+	memcpy(host, p, pp - p);
+	host[pp - p + 1] = '\0';
+	*port = HTTP_PORT_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)
+		return -ENOENT;
+
+	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)
+		return -EPERM;
+
+	if (env_set_hex("fileaddr", addr))
+		return -EACCES;
+
+	return 0;
+}