From patchwork Tue Sep 26 09:41:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 726409 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2834443wrm; Tue, 26 Sep 2023 02:45:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEp8ojpBeuI68WZmv6D7ZURpwkHf/ZKJFjameLnV9Q8FUtbuG1nEH5Ev04zyD+5rmNUs1dR X-Received: by 2002:a7b:c7ca:0:b0:405:3d04:5f52 with SMTP id z10-20020a7bc7ca000000b004053d045f52mr8608757wmk.24.1695721503892; Tue, 26 Sep 2023 02:45:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695721503; cv=none; d=google.com; s=arc-20160816; b=bWYqJCmE0ynM3NDQ5HmwNrGrvC++CC+ffNLkkRitTZ3z3amXhTFw2Bj8j7LhndSXld VibghUiDawrvtM4qRwbPOe7PvKR8URVb4iLwGI/H3dmGN5qqnSkezqjH9Cs9Pne9e4E1 OLl11fl2nAaIacEGLjlSghjXlcZqiGHbmWUJCGOoX3M3Vzqa6DuqrGB/HerGxGhP5yhK Tn48tdx+DccFN6eNHMVcuG96v4o2OlQ8mwBsAJj0RM7o2abCz4ewX7xowHN0OZQrg+o5 f+VmwhUyonzD8xOZtc+/QsmdZngr8+pAH7mYH/H37GDVRRbghX7Puwb0J8wiX8odBXiM TZtA== 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=V218Z5cIEqbBmV6mdyr4s9oHBggfZPoBshAZy5wwtmY=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=PkxdNlX1bbsC58grN6XARLUg21f9SmVDb6hsPr6X/EUFWowmRav+f0j2Y4S3pL21fp G2RzwTxf3U2sLSj1aeXkaLAvELy4WDNnaW7jphm8fq52Mt4VkJMLPjZXLFShpjO1mASd uc1gmMla/edPCcWPUeMXavizCjptwWJ8T5kv1PRD1OsAuZLrpdPrB+xttJo7Pr8MhI4i naE0Br/kJ1+vigE6DS15aHAx0xdByM7U/TITQcZZuhmX4unjBERsmZAiuWdAd5GGdcZM RZwJ6lg0srTe9LNuu1qGP8FTtKcbvfU18omDI18EpZR15Kq0K5q75BILj5ly4N0fc/iR 28wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vi2NYnhG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id i11-20020adff30b000000b0032316c446b6si3654694wro.994.2023.09.26.02.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 02:45:03 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vi2NYnhG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 9CF4E86DC5; Tue, 26 Sep 2023 11:44:03 +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="Vi2NYnhG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BFA2886DC9; Tue, 26 Sep 2023 11:44:01 +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-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) (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 BEB5E86AF7 for ; Tue, 26 Sep 2023 11:43:59 +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-lf1-x135.google.com with SMTP id 2adb3069b0e04-503f39d3236so13532828e87.0 for ; Tue, 26 Sep 2023 02:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695721439; x=1696326239; 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=V218Z5cIEqbBmV6mdyr4s9oHBggfZPoBshAZy5wwtmY=; b=Vi2NYnhG/8kCu3+C47/cyctUpnhXXG4c5DZWKlYcqzXGsn2GcClBMomZU2OEJdpj4K fyDuy5YQ+hGetDB9l/Mlb4J2U6GlftvUqGD4Y60C7CzW5Ub+G2H5lCjpE2+L1lNd1lLZ A9CIxJhV0iGrMuap5vZzK3qc0v4rJ73RvgHFdaEs1KnkvRZUKMCCwwyO94XyCbAEl6gh QuKgONtVULq8utWvwU+y2cpFMtG0uPRUsyuBRr6C+NDzpYUoE4RAxH0gkRlKkoNhJpTp jO30rHM7jMoqWpZoA8WOUpBL+KOkgrH9OMddzfn7OHE1XjECugRTDS3Rb0pCM3ddNa1n cTdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695721439; x=1696326239; 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=V218Z5cIEqbBmV6mdyr4s9oHBggfZPoBshAZy5wwtmY=; b=xJFjNLueWz0mC2QY669EVL1LjVvnf0NY8CD9NJizPtv0xUluOzz3W5xmybs2AUo4x2 +R9z3gch3qduncu+YlSk+QmlFngFWZ6zbvSirxd6oZCo1MEiYZNkfD8BStRSB9PkdDjB WAo5HVrqv3jD1SY4BlSpvY+UAz9rzyCy35x+rNrdhZgY+ehNWyEhBoaLBKLOtOoLN6at G8g2B6MOlGzyKPTGmjme9w2Z38VjTk7jKXDHW0ESnq4BCfBRG8LwaeGdvglg9bFfI139 h5KA91Cow8xzI3qZUP5bRfI1Arc7NUMAafd/DZEu7pdSIprMMWKlQtaWTdDI7Dx5eEMX 1SqQ== X-Gm-Message-State: AOJu0YwleMkN6ZHCsABrO2FYSfqV0e7TxYkdf7RJqFRW44mTpQOeVky7 bMOX9RxSisKmuMw55MTAK63LOpJcT9UjM2uADgdCcg== X-Received: by 2002:a19:4f56:0:b0:503:3278:3225 with SMTP id a22-20020a194f56000000b0050332783225mr7180584lfk.63.1695721438897; Tue, 26 Sep 2023 02:43:58 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id x6-20020ac25dc6000000b004fe09e6d1e7sm2131131lfq.110.2023.09.26.02.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 02:43:58 -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: [PATCHv10 08/15] net/lwip: implement wget cmd Date: Tue, 26 Sep 2023 15:41:17 +0600 Message-Id: <20230926094124.7024-9-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230926094124.7024-1-maxim.uvarov@linaro.org> References: <20230926094124.7024-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 Reviewed-by: Simon Glass --- 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..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. + */ + +#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; +}