From patchwork Thu Sep 14 16:18:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722564 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp485789wro; Thu, 14 Sep 2023 09:21:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHAtifA2y+GrvgAO8Qgle9g89LlDm/gNps5YyOqpepQlcaPzevM012XE/JyM5A1sH+p6Mk X-Received: by 2002:a05:600c:24c:b0:3fe:1548:264f with SMTP id 12-20020a05600c024c00b003fe1548264fmr5148517wmj.22.1694708510560; Thu, 14 Sep 2023 09:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708510; cv=none; d=google.com; s=arc-20160816; b=GFhsf6foed6DUmGYt3aJYVTULMP1/Rbj5JP0UTaodX0SgjGRR9mxyWC8MfGm7ac7HC EjqrS6xry73yReSi7lVUXbkaAykN+brihhZLEXOPrKQw6T1rZ7Jz2xpGW0+eIxcKeZ1Q hmZW/9OsM656Rui0miL7V3DVZm/gSBsFLpDtMoGaB2cOzmtpoLF9fUVp5T8ZbPhDe4sE 9bbYdomu3C1d3iH17vA2KIV9Y6KS+McxqoJ44wOdLZy7R+9+Zo/wr3w8H42MlsQT/GPi 77HUaZMHL5QDpqxohit5b+cp3EWbdV1kdOo9Ye1TBP29oQk8yfGz5cN6bhCAhKfFs7cL zCgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PKZJ9HOZxIBTiLch9aEDpcZKIBMQWo/QAQDhGkXMw7E=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=eo5yPomS2clviv6IxrVANeSzAIwulsdWespyI3O76D9OSwCNH7vzJkyeoAdDU9we+S amkl0JbOZrBkN37kKHzifhPFce4soTxlRpiqlqs/f/ItdSxCAj1CZ8oF5oxt8hOqbAyQ KGQtVM2HP2FU+kTBg3yAq18if88V/RIgwsZNcG+axUFNNpvQ+KV05CD0L5LXLLVEEit4 3QV3I2CfMTzIHgc5kzqXHm70VLqybDWf/uFowJj+DswO7TMtFX6n+Z1nXeVAbirfJd3+ lPwHfMOjHEV4oSPf2SVFmIC3f5zjvTh/X2e2ob2uMrypBSZ+dZHiJA5NK+hOrOAKGgtt 3tJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOJTY1oy; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id b18-20020a5d6352000000b00318f7b655d7si798037wrw.700.2023.09.14.09.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:50 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOJTY1oy; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ADDC986AB5; Thu, 14 Sep 2023 18:20:56 +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="xOJTY1oy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2DC8F869BC; Thu, 14 Sep 2023 18:20:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) (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 2F36386AB5 for ; Thu, 14 Sep 2023 18:20:53 +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=maxim.uvarov@linaro.org Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bcbfb3705dso18084761fa.1 for ; Thu, 14 Sep 2023 09:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708452; x=1695313252; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PKZJ9HOZxIBTiLch9aEDpcZKIBMQWo/QAQDhGkXMw7E=; b=xOJTY1oyzb/z1gIN1S3U1+zEC67MGf0lrNFuopB++NZ4qVADYErZW1gpO5wxAKyYMh he9FK+y1gp3FCmJwUND8l/O7P4uIbFmtNWQv+FFzXGbAZ+iMhtKSQd0ugI5QZV3jv0pu lLr7N5wgXp1oqRdXVMRa+7sc8ovpqrsd93CsgqQJftZPgOcGf7Hs8yAl9bgDQNs7xpPP 8xCCEwCkzc/uZDg9kKqKExEAEXYhAOgtEW4LE61sNEFU5otIo2Q+Hmqd0qZKVujAg2JI xZVSOJYkYGm7mbYcMbkdxr9Rx7aVTz6ixtiitd7NyrzhPKHnCg0V5VpzaeDJUsK8mhQM UlDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708452; x=1695313252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PKZJ9HOZxIBTiLch9aEDpcZKIBMQWo/QAQDhGkXMw7E=; b=C1IghAvaJNqdDIhxczudlSrTsmuLnl3hpDbD63nLyEFxq7meLXWRNUY45hT2EgEBVq dyhogL2v0tAVPdW23W1uYnr8gORXjxChVKZx4yLcvKilCqbLZwIknmz8mOmn/vMX5P6H za5y5Bo9+Ud4EFJ/mx0J5qwFnjLzqtuW4XNmUHb5/beMxIvCCyuOprgrutdc/rCszqRF bgGO6VrqnE8kUypO6CzcRpOprkUDN267ECf5p+uhb+1gv5w+3tEMEBsmdDMMfMyoi5CV LpjE6sDSND5PrVLz0it7hwBYlvnilbRDzFAEzVMVmHGBy6qg8ae6QpA1LI8i7ZF0of15 8LaA== X-Gm-Message-State: AOJu0Yzl5+sADTCtJbzKVNCJ91twA4VKd8SxR9GK/21cFZ7dgwgliLJK OquR9yN7n0w+WrzhxdRMoH1/h3hrq5NJS4Mw/3rz0A== X-Received: by 2002:a2e:8ed3:0:b0:2b9:53bd:47a7 with SMTP id e19-20020a2e8ed3000000b002b953bd47a7mr5293350ljl.30.1694708451941; Thu, 14 Sep 2023 09:20:51 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:51 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv9 07/15] net/lwip: implement wget cmd Date: Thu, 14 Sep 2023 22:18:20 +0600 Message-Id: <20230914161828.3662-8-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 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 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 --- 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 diff --git a/include/net/lwip.h b/include/net/lwip.h index 11389bb038..85f08343fd 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..d82d450c0f --- /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. + */ + +#include +#include +#include +#include + +#include "http_client.h" +#include + +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; +}