From patchwork Wed Aug 2 14:06:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 709170 Delivered-To: patch@linaro.org Received: by 2002:a5d:55c5:0:b0:317:2194:b2bc with SMTP id i5csp931086wrw; Wed, 2 Aug 2023 07:10:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFMWF3FbAtd6bDE2FmXpzvCHzoIRKUTsNXTEbSXu0RUQ/d06fcAnzJwAlju5toHrcQQXUan X-Received: by 2002:a05:6000:8:b0:315:96ca:dcab with SMTP id h8-20020a056000000800b0031596cadcabmr4906032wrx.35.1690985431602; Wed, 02 Aug 2023 07:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690985431; cv=none; d=google.com; s=arc-20160816; b=GIilhhUwdciV9jLWMkV6BGrqcLN2Fl6jH0Gi1D6NbtFpaSgDdZmYZMIcQ2H+SPEQUv xCpR8MGPTwQr8m67wtihp0Nj+GnLF2d6T/kzc7JJ0woJV0DPmVVpwCwQh7pMrKeWBgdA WihfiA2gjbIij+llkWUhkryxrkFHsgxmQ7P0Orn0CxqIXSMXxiYV0RB2qbeIMVS3i22M EJaYTimgYwwCpnx3j+N3Vuo2qaVeSz2xQQcDGKjBrVQv04IVNv2oZ5b4ekeyN4oGnm5A +Jx6WQEJ6lvu7hAkWxD3+m/faQCKgvrZ9HwWnF0iD5ci2dyP4wLImjYNb87C7RyuJCPN yhGg== 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=kk3H8YW4H1Lr5BVyJkt4LyxRRYYXEZYXETh11fPCJXI=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=QJW2BXMV8QVgXJOhuh2Jr7YAsfbzbLWHJTLBhNRBVwnJT+VcaxbVtx8dSD7XdOH2x8 2b/n6SzLGcgUgG0eKzrDkYIwkAI/eegChiXk2Vcuk5Kfd622a7eQ2Qzf1dee7fAT2qgW RcUEHyuqgU1W2TkFtHbzS3iWuNCtAgJHCxmTVz3ufVKcGOPaxKLhxHnuQ2x45IIycfSV 4EvV62VwnZKj5c4tGPsCK6uKS1hSefYD93RJTKjyS/Wl9sWAGhcYVoLZH58DPL+U7zOP X1C9zvKlqUWjF6h+g1OF4QaOod5LU2HtscRMnm3HaE9hJ1fF6rIvDqbBFB5nQLotPUNV eOwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lt67M6yK; 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 k1-20020adfe3c1000000b0031435c43c5asi767049wrm.713.2023.08.02.07.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:10:31 -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=lt67M6yK; 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 6745286C0A; Wed, 2 Aug 2023 16:09:43 +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="lt67M6yK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 66DFB86898; Wed, 2 Aug 2023 16:09:41 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) (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 DEECD868AD for ; Wed, 2 Aug 2023 16:09:38 +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-x22f.google.com with SMTP id 38308e7fff4ca-2b9a2033978so107113001fa.0 for ; Wed, 02 Aug 2023 07:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690985378; x=1691590178; 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=kk3H8YW4H1Lr5BVyJkt4LyxRRYYXEZYXETh11fPCJXI=; b=lt67M6yK1L5cSjHXPAE/oO9oQ4D6Ibfm5er/qFklMiTaWzv3AricG0U8QW+tDz8RGW u07zPrKep9e6FTkPFNEPm3rcEVlUvgob0VACGNweGPzzUZfG8afbrurIr4aaxxFlcEVI Uimp6apPmzhAdv7VoUzUXLSG4UP7dtqPU12uqRnXLzRf/dSqDcV1ZNr8613MRU34mKCE HLmKRs3ibQ9VfYTDs94fUI6IvgaxH1DiOTH3Dozrz8xyA70qd4QzrOLXiF9xJhS19LNq AUhLkYb1i2d8MApSscQFI2d+IYqK5/BTPII1y5o1Kv6qTZ2A1LEg0pfSrRnmRTTSO4gz D/kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690985378; x=1691590178; 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=kk3H8YW4H1Lr5BVyJkt4LyxRRYYXEZYXETh11fPCJXI=; b=eEkRilK9QnfXepJVfNmVUKFO0fb4HMW5sCmrC1gKIeC4SfipsYZWERmWQXgaBrpQk5 wpHlYVM4px3Y3SXLv09PyxgUsbfc5kWzj069dLjOyAlI+qi0vUd48wiwziMbPHhZjqEK 1nS2Nd6rhFiW18qdhOuepU4uZysy9+yex2oPiS0SM5VLruDiwGpDsWCmES1s6gMk81qm 1ZIj3rEb6Sd16Rjvq1SwjUEnTTW+oOtYUJm/ANBhK3eoSEFKAn4kVh4obgIYNDcXyaWB fyvJYmfswthlWIiCO5ZzaOrK8drjR+HzsHQe8oONuogjEj2bJEoeO0QUju8oO80ZJeIP njyg== X-Gm-Message-State: ABy/qLYTZ8APAbhNcVcZJfWPXv8V+IR5oFVx5FgeJ1yBfLGCFEbi0uQp LcsYcZrqwl+GyB+BTRlHmBJw1a6DBYFVuzoH8G2yCw== X-Received: by 2002:a05:6512:754:b0:4f6:1b45:e8aa with SMTP id c20-20020a056512075400b004f61b45e8aamr3873698lfs.50.1690985377911; Wed, 02 Aug 2023 07:09:37 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id a12-20020a056512020c00b004fbbef8d4dbsm2982026lfo.121.2023.08.02.07.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:09:37 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@redhat.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, lwip-devel@nongnu.org, Maxim Uvarov Subject: [PATCHv5 06/13] net/lwip: implement wget cmd Date: Wed, 2 Aug 2023 20:06:51 +0600 Message-Id: <20230802140658.10319-7-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230802140658.10319-1-maxim.uvarov@linaro.org> References: <20230802140658.10319-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 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); + + 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); + 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 + 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; +}