From patchwork Fri Sep 22 07:11:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725217 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp875909wrm; Fri, 22 Sep 2023 00:12:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYAcRTuF2md/qjFTVuOoy0P+0EDk0bbH39EQ+FNQIU95ZD6kWlxPBGcVoAodxHRMDp+Fxt X-Received: by 2002:adf:e710:0:b0:31f:e19e:a2c with SMTP id c16-20020adfe710000000b0031fe19e0a2cmr6615952wrm.32.1695366735183; Fri, 22 Sep 2023 00:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366735; cv=none; d=google.com; s=arc-20160816; b=z2In8q7wfC6hilYKV3rUi7igGyEKB0XK6LHWQF9078RQqnSGcZzM6iasMYo+vEKHRO bn48yeraU8we/DPRCaCAoZpt3MUb2O9OyB+A9JY1eBNET0FlQf5d+TdKz1HY37lnhZyk JzuRe/s9pJXg3WJE1z2IhYapU7WzrAH6ul3Ivs2x5LgDwg5jmZ+9awM/q4UcFYr+eSks FQTb79fhrurt6VCv234jhPpZ/CJq2uxU8zhARsS6rkKe7MKjWysUNECWKNY3momB4bC5 mlTYM/eB16M5atbjNR13vWR5PIX5GlgziohOCMhqfuscKB3BlMIro4esbjsTIOgPOJA3 1Jsg== 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=KGdSB+1Sc+3rE1pD5ZrEOwcyiOX7+KHT5RdxLZLHyek=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=ontwmu1bQVmRNHAh9MZs2APgZVMpvSF6k0yf2AYHqWHmNVSlhpyFim99XpSL431Acm yoHrbX4CNsa+vZHGOu+xpHaLHwQFyGTSaS0nvQ1bI5hQasdDJmEk+KjUNf5nFL9RPBom Qpe7ALAEG3wiiQTlwWTqI5X8O3nwNonaCkYKK8S/OUROk/obXQ6PfUk5pyjqapAqfmU4 gtH5l3iwVolPOkoIBpAmij2fMeBLhSFR83S5T18JP5YizDU4PFBNucHf0KIR3vlfnCwa Or+2gZN2bE0pt3vYtH2RNDeQagg+OxoAlDMgdXC9N9Ywq0LjyZhHJyuqlvNLAbNDwqA0 qHNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VeX6Gd4s; 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 h10-20020adff18a000000b0031c80449ca5si1526232wro.895.2023.09.22.00.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:15 -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=VeX6Gd4s; 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 D17198667B; Fri, 22 Sep 2023 09:12: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=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="VeX6Gd4s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6BCE686290; Fri, 22 Sep 2023 09:12:04 +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-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (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 3BFA68667B for ; Fri, 22 Sep 2023 09:12:02 +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=masahisa.kojima@linaro.org Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-27499bb759cso1265185a91.3 for ; Fri, 22 Sep 2023 00:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366720; x=1695971520; 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=KGdSB+1Sc+3rE1pD5ZrEOwcyiOX7+KHT5RdxLZLHyek=; b=VeX6Gd4sOBuZWt1hkrIcL+9apfO/B6Dq9PEp17bKw6yh444y/SeYIdzTTR1NSO8fby WcDBsrlQhto8U5evDcJ5adygr/9YWne3Y8soPHOjOg7NbXxilQ5V++uGjji1tzPkikJ+ StKdtI4zhE8f3wTt+9jTX0X6ptjMzCRS463QulGc+wTK6F8HGenmax7HcvthrHU4A+wS J/KF5sHblE/DvM5KfIapSxfIeOGndX/vNqRZ6ieyFrhcRjGX/YGHfjPtPldNGIjNHfBo FRztdingdtt1FJ0DNPyq0KQYG/t2igfVTtx5L4j5B+zt6I/s7nIWcUQwD7CgzPv/PrJ5 DNCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366720; x=1695971520; 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=KGdSB+1Sc+3rE1pD5ZrEOwcyiOX7+KHT5RdxLZLHyek=; b=t69MqgVgJm9q4lNQsSrCEogS/Z8s9Y9t4lggUL/INsr6uQlk2R4XRHWH1vQtEoqNW4 XPfu57uaWGAz4iWq3bKnNaOpaJtOr6m0yAox9s4zKqhGLYwPWJQGtOXhn/CJB/4vP2/T MPa1byOxi3jasxOY31AOg2TS9D2fo0yPNxXQCgw9j1f7dlDQQV/i8J+Iff8GpxWinXp7 99C3mGNQkUF3Aj6gmDlUbeliRqQMTajry0/BEJksb8Y69iJ9uqa0tBc185yzhhzb8jzz gTAzES0Ml6sxmcn4qttj9Hpg1cG+q+SFdctK0Jg7A7q3bQG7ibfWTqLXAHwPEr7BLbFh SDDg== X-Gm-Message-State: AOJu0YyFLKu9t3T0vZRuuEurs2gO9lBVffMRTTyHaKfWRngRNNb/+Uof 1OY9nVWBnv+6iRjVz7JrObES9q/hwFAUWwP/qME= X-Received: by 2002:a17:90a:b78e:b0:26d:3d86:9a8e with SMTP id m14-20020a17090ab78e00b0026d3d869a8emr8032816pjr.25.1695366720408; Fri, 22 Sep 2023 00:12:00 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id 6-20020a17090a194600b002684b837d88sm2812464pjh.14.2023.09.22.00.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:11:59 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Joe Hershberger , Ramon Fried Subject: [PATCH v4 2/8] net: wget: add wget with dns utility function Date: Fri, 22 Sep 2023 16:11:13 +0900 Message-Id: <20230922071119.1439482-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-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 --- 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 a48a8cb624..4801e28eb9 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -504,3 +505,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