From patchwork Fri Nov 10 04:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742838 Delivered-To: patch@linaro.org Received: by 2002:a5d:67cf:0:b0:32d:baff:b0ca with SMTP id n15csp12431wrw; Thu, 9 Nov 2023 20:28:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHguzrseRA4wuSIDY0b6eSJtpZeGZeHtYLKGUOq94/MDtj1Kz290q+syF2kiP89VGW6YQsF X-Received: by 2002:a17:906:fd85:b0:9bd:c336:21e5 with SMTP id xa5-20020a170906fd8500b009bdc33621e5mr5723180ejb.56.1699590488225; Thu, 09 Nov 2023 20:28:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699590488; cv=none; d=google.com; s=arc-20160816; b=IS7z+OTI+18nqBa7By+icvo6xGaXw0eY+3S3LTOQHe1ynIz2Nu3B+F9WiUNqS+XtkQ epxHbaUh4gn+88vQdaennd7LXTpF++bro2eNsWh0ffFiceae/40zAyDmULWJbctdqXE+ QUM7x0xx6UPrU45Xz3rpmppp0eSPei71oKqzXfbE/aHe51WMjl3R6f05atj9Kq5wg7yT ZEHf2CopzbDcUmxsSCQhWzKcHodtmIDsmIpgMqGbHSE/ItCljxzuC/u6GVzYXZXfZoyt hLqzFsp6nYlT/+Of31agTr56OdyH/ahcQA/TXJ7rnN53zLxtfxm/8WlB0/dzxhNIjwKr wU2Q== 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=zGZQU+HctrKKVXmy2gttea3yHpOHmqPE2LoEebzQakY=; fh=eBItVz4B+jX5FuRNHVjUaldxTsf8xOQKLrDTtjpPbrk=; b=RV3oQ9RY7TB4mO+r0FsNH6v3RhbRN41EHQQOxsaFmS8R32WxkiVbJJxRF8JyuBH6NO GuGjCAhb3xPclu5Zec8f+xa9hywDMKkRijrZT7KSJ5i+jINATSIgCTHvZ4A/uqicTfe5 VDVBWePaMIvJfcZH+4BCG6jXWFbtw67N5+G3Al/ORu25pWXnqwC8kox1XtE5p41w4FBH QgVt9EkxNWlAm6YiR5X6pdWZ5emT1XyiTU7s58tfAQUZe1pqSwpAlh3hkJRG4eekWm+h cMvynLuzqRC+KTWxMvBf4NSenrZs8VJgRE3+1G00x3D/WeVioIbPiTEZX4OrBtGA62MW Lo6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YiETNyz7; 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 qa13-20020a170907868d00b009bf3d83ba85si4012931ejc.148.2023.11.09.20.28.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 20:28:08 -0800 (PST) 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=YiETNyz7; 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 CA4C287792; Fri, 10 Nov 2023 05:27:22 +0100 (CET) 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="YiETNyz7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 66BFF87783; Fri, 10 Nov 2023 05:27:17 +0100 (CET) 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-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (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 70ECA87787 for ; Fri, 10 Nov 2023 05:27:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5bdc185c449so1268890a12.0 for ; Thu, 09 Nov 2023 20:27:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699590431; x=1700195231; 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=zGZQU+HctrKKVXmy2gttea3yHpOHmqPE2LoEebzQakY=; b=YiETNyz7Bc80OKS5Sg6l0WGhoDF7mPpD73TSR20FprorxQS38VyMIGRv4s5ia+5AP8 6yB+X2gCuY+PSyDwxQ7iTja8CGx4VGX43V+AsT/9ZUtGHwpGiuvULQxmRXEhrBAR0F0+ wXJg+1EIbzBWiU7PSCUHa45gcghRGZRy54jypCNBWUxt3N33bSvsczenQrQrAvQE4E8P jRWcfx2qkOcklBXIBfh8LKK9d2CTaR1mo3GRFqk4cF/HkQnvmAFJh2gCqTypm+OnJWFR /E1kL31LkwQk+wm+xEGCuH8cd9eHF+V7r16t+qZy4Kvtghkn+lKyNn8ePGEHR6T5NB4u os3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699590431; x=1700195231; 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=zGZQU+HctrKKVXmy2gttea3yHpOHmqPE2LoEebzQakY=; b=niSkusljml7RGyncjYvccpv3C0uQpUZnYaJ3AMVfp53ZJSuKOXUGU82kN6jgjs3Enn 12NqutRV6iSTi5yEP01fcCqCvE0ZcA2wVRhHq8NK9HGPE6NB6I1D+mOW8J6ZRat/Swuk FV23Z6JZ7E01KEzwy5bnbFplopux+cUzn6IuZ8IkQPTWdVqv4WTAasJPsbMpm1iam7ya 1yfM0MJ7L+PA/tWI0NmP+SJn4lmmrHW7qZK6a2LdLWvXFf9pWSxOPFVyhgxt1KvJ/9Zy m/yVYjdJr06DUttAFgJyTO2WyZ5B6DmOwNGZ2wsqmNbJxsar5DB+bgVJUBvjZzqPYUYS tX3Q== X-Gm-Message-State: AOJu0YxcEIz6cunRlfyxKJGiXjNjOn/bDOtvt+XCBc3HSTI4NpDJNHXr vG7v5axcyJBbyJG0KWZ9HHxR22KPnwOhewW8W+w= X-Received: by 2002:a17:902:8488:b0:1cc:8b4c:9ba1 with SMTP id c8-20020a170902848800b001cc8b4c9ba1mr6218726plo.50.1699590431228; Thu, 09 Nov 2023 20:27:11 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id ix22-20020a170902f81600b001cc32261bdfsm4332568plb.38.2023.11.09.20.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 20:27:10 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [PATCH v12 2/9] net: wget: add wget with dns utility function Date: Fri, 10 Nov 2023 13:25:35 +0900 Message-Id: <20231110042542.3797301-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231110042542.3797301-1-masahisa.kojima@linaro.org> References: <20231110042542.3797301-1-masahisa.kojima@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 Current wget takes the target uri in this format: ":" e.g.) 192.168.1.1:/bar The http server ip address must be resolved before calling wget. This commit adds the utility function runs wget with dhs. User can call wget with the uri like "http://foo/bar". Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- include/net.h | 9 +++++++++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..57889d8b7a 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,13 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ +int wget_with_dns(ulong dst_addr, char *uri); + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index 6f97eb1d12..2087146b37 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -512,3 +513,56 @@ void wget_start(void) wget_send(TCP_SYN, 0, 0, 0); } + +#if (IS_ENABLED(CONFIG_CMD_DNS)) +int wget_with_dns(ulong dst_addr, char *uri) +{ + int ret; + char *s, *host_name, *file_name, *str_copy; + + /* + * Download file using wget. + * + * U-Boot wget takes the target uri in this format. + * ":" e.g.) 192.168.1.1:/sample/test.iso + * Need to resolve the http server ip address before starting wget. + */ + str_copy = strdup(uri); + if (!str_copy) + return -ENOMEM; + + s = str_copy + strlen("http://"); + host_name = strsep(&s, "/"); + if (!s) { + log_err("Error: invalied uri, no file path\n"); + ret = -EINVAL; + goto out; + } + file_name = s; + + /* TODO: If the given uri has ip address for the http server, skip dns */ + net_dns_resolve = host_name; + net_dns_env_var = "httpserverip"; + if (net_loop(DNS) < 0) { + log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve); + ret = -EINVAL; + goto out; + } + s = env_get("httpserverip"); + if (!s) { + ret = -EINVAL; + goto out; + } + + strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name)); + strlcat(net_boot_file_name, ":/", sizeof(net_boot_file_name)); /* append '/' which is removed by strsep() */ + strlcat(net_boot_file_name, file_name, sizeof(net_boot_file_name)); + image_load_addr = dst_addr; + ret = net_loop(WGET); + +out: + free(str_copy); + + return ret; +} +#endif