From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1EBEC001E0 for ; Thu, 3 Aug 2023 06:48:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2340986C19; Thu, 3 Aug 2023 08:48:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="i1vxUE1v"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 067F286C1D; Thu, 3 Aug 2023 08:48:08 +0200 (CEST) Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9DDE58680E for ; Thu, 3 Aug 2023 08:48:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4fe07f0636bso1017884e87.1 for ; Wed, 02 Aug 2023 23:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691045285; x=1691650085; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=CLPh6b4ibsiIBpjUWoCl3t7d5IHY3X+YY32qioFfZLY=; b=i1vxUE1vxKyEbPFcmoUY4gXSx8x5EjNpy+ksx75xMh0T9hia/fX4aKuoeQvrjy5YGd Th5QpTpRt42CWLnPZrjq5Ea0U8ZXfPv1ysiYHUtdcFYrS1Lt82voywfaYE2ibaAmAOUf hyxx2usTNb4NUxzBKcs9bGBbhMkrH9jeLA/HIwcCdckl6OO3jSvh8kzCKf8jz5u7faKI oCaNhE8JdgWZCMcGQGa+I6vjbn+FO8us0SBGFfSCVZhWywz7q9puruZgPlQu4UiV/o90 SB2MwcD++uscZWkLVGltHIxvWfKuc6t8e9fY5ZFIqkZG0em1oMC1xvw+WTcu65v+XGps jjvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691045285; x=1691650085; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=CLPh6b4ibsiIBpjUWoCl3t7d5IHY3X+YY32qioFfZLY=; b=QY5/ZjohLL9z5tLARM01SBXtENGiLBFQ56E6D+k8MaXCTfLWcKLfHkAwq1kJb+cOYl DbAoe3Le4x/hCjw84aBp89jXD3s9e9g8R0mYOqtp/InMFtVVMCEzsDZDEll0yoUWtE7d fR81RK5bNLwCFkxepu+mpvvyWGkDwuMoDxSqJQpZA1QzAHHiuHakc0q4ruZ428THS14e 2c0sTpomRde2w0GlG6p+YSfDHd2VgStCFWietkdNAFn0CqhVtjUaJT+EndJ19lHUHLHS 5L6cxyeJhYenPJ+quP4bKgPWaQGdMon2MSbQaLCYFjY9ri9xZ0tpqwf8ak0+aE8usu49 zLGQ== X-Gm-Message-State: ABy/qLZaUu2hWRii8F10cVfuAxrga7PPzuCXCB42WMSGJvQQL9R5wvnW rroe4TInq20OyzGs44ITCRTY3Q== X-Google-Smtp-Source: APBJJlFlGPpWb6qwfxSiRFViIVehvcAw00jicCUXIOV3v7c6qw9j9t0SMe4h0Z2xjiseP6QwbHqgJA== X-Received: by 2002:a19:6509:0:b0:4f9:cd02:4af1 with SMTP id z9-20020a196509000000b004f9cd024af1mr5482001lfb.34.1691045284808; Wed, 02 Aug 2023 23:48:04 -0700 (PDT) Received: from hades (ppp089210246083.access.hol.gr. [89.210.246.83]) by smtp.gmail.com with ESMTPSA id p4-20020a056402074400b00522828d438csm9730770edy.7.2023.08.02.23.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 23:48:04 -0700 (PDT) Date: Thu, 3 Aug 2023 09:48:02 +0300 From: Ilias Apalodimas To: Maxim Uvarov Cc: u-boot@lists.denx.de, pbrobinson@redhat.com, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, lwip-devel@nongnu.org Subject: Re: [PATCHv5 06/13] net/lwip: implement wget cmd Message-ID: References: <20230802140658.10319-1-maxim.uvarov@linaro.org> <20230802140658.10319-7-maxim.uvarov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230802140658.10319-7-maxim.uvarov@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On Wed, Aug 02, 2023 at 08:06:51PM +0600, Maxim Uvarov wrote: > Signed-off-by: Maxim Uvarov > --- > lib/lwip/Makefile | 1 + > lib/lwip/apps/http/Makefile | 13 ++++ > lib/lwip/apps/http/lwip-wget.c | 130 +++++++++++++++++++++++++++++++++ > 3 files changed, 144 insertions(+) > create mode 100644 lib/lwip/apps/http/Makefile > create mode 100644 lib/lwip/apps/http/lwip-wget.c > > diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile > index 1893162c1a..ec6b728c8e 100644 > --- a/lib/lwip/Makefile > +++ b/lib/lwip/Makefile > @@ -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/ > diff --git a/lib/lwip/apps/http/Makefile b/lib/lwip/apps/http/Makefile > new file mode 100644 > index 0000000000..7d22817e50 > --- /dev/null > +++ b/lib/lwip/apps/http/Makefile > @@ -0,0 +1,13 @@ > +ccflags-y += -I$(srctree)/lib/lwip/port/include > +ccflags-y += -I$(srctree)/lib/lwip/lwip-external/src/include -I$(srctree)/lib/lwip > +ccflags-y += -I$(obj) > + > +$(obj)/http_clinet.o: $(obj)/http_client.c > +.PHONY: $(obj)/http_client.c > +$(obj)/http_client.c: > + cp $(srctree)/lib/lwip/lwip-external/src/apps/http/http_client.c $(obj)/http_client.c > + cp $(srctree)/lib/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 > + > diff --git a/lib/lwip/apps/http/lwip-wget.c b/lib/lwip/apps/http/lwip-wget.c > new file mode 100644 > index 0000000000..47a77250c5 > --- /dev/null > +++ b/lib/lwip/apps/http/lwip-wget.c > @@ -0,0 +1,130 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +/* > + * (C) Copyright 2023 Linaro Ltd. > + */ > + > +#include > +#include > +#include > + > +#include "http_client.h" > +#include > + > +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 err) > +{ > + struct pbuf *q; > + LWIP_UNUSED_ARG(err); I think it's better to use standard C instead of LWIP defined macros for things like that > + > + if (!p) > + return ERR_BUF; > + > + for (q = p; q != NULL; q = q->next) { > + memcpy((void *)daddr, q->payload, q->len); > + printf("downloaded chunk size %d, to addr 0x%lx\n", q->len, daddr); > + daddr += q->len; > + } > + altcp_recved(pcb, p->tot_len); > + pbuf_free(p); > + 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) { > + printf("\n%d bytes successfully downloaded.\n", rx_content_len); Switch those to a log_XXXX that makes sense > + env_set_ulong("filesize", rx_content_len); > + ulwip_exit(0); > + } else { > + printf("\nhttp eroror: %d\n", httpc_result); > + ulwip_exit(-1); > + } > +} > + > +/* http://hostname:port/url */ > +static int parse_url(char *url, char *host, int *port) > +{ > + 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 https://lore.kernel.org/u-boot/ZMJqIxmXJD4S72Ig@hades/ Do we currently support a configurable port for wget? > + 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 = atoi(portstr); > + } 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 lwip_wget(ulong addr, char *url) > +{ > + err_t err; > + int port; > + char server_name[SERVER_NAME_SIZE]; > + httpc_state_t *connection; > + > + daddr = addr; > + > + err = parse_url(url, server_name, &port); > + if (err) { > + printf("error parse_url\n"); > + return -1; > + } > + > + printf("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) { > + printf("httpc_init_connection failed\n"); > + return err; > + } > + > + env_set_hex("fileaddr", addr); > + return 0; > +} > -- > 2.30.2 >