From patchwork Wed Sep 27 09:36:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 726693 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp3430575wrm; Wed, 27 Sep 2023 02:37:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxipSUSQ3WsKZN6vV7bcnDkVenhQ1656Ok2ufj+gJLAePQNKRdpCcG/nM4IyaGmiKBsrDv X-Received: by 2002:adf:e791:0:b0:31f:fdcf:b2b6 with SMTP id n17-20020adfe791000000b0031ffdcfb2b6mr1284485wrm.55.1695807468230; Wed, 27 Sep 2023 02:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695807468; cv=none; d=google.com; s=arc-20160816; b=HS8MyW9eNaN8jbbfQXzIVtT0B834iCy0nSJX8W78NGUu11OwTEsY2WnNXxVmaVSM9H AiCW3MbRWAhJ8sYod648TEcpG5jAbC+Yi3hjx3tzURmk+JR3/HRmR79nXobvXAKZZekE BZgWQjeMT07xBZ8Fl3hPqvKy4LN+8WgaLZE7bx4zjaaU5G2TNCCBGq1ONWQbBr+0gL5I JbotkgOhuBsQd6rnrm4k0MG+PpcXAsBOROpkf3znKgTSTIxBF9xMfe+V15AqLk7TE/yN V6PXgAahGYN0sB/p5Q/HsFt2/t6ACP/olhcKTMlXL3PjrEozjtrSfmPOWtDcFymGjlm7 KjgA== 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=23L8aS493+zafOpjLr+4gUrZEYR4Ae5sZvaUqjD4Qh0=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=ITfXMW0fZwZ7CaL2ADfkNrX5rwSrEEISxf6LmoDLP9bgK+E+VE17YweCaqKxwZ548J zJyKEl6nqWVMJy0EZr/aR+Fpjek+Ao+rcO1sdous5Qcn/4prTahS9heRO9eWDKdfc7ZA Kfra3449uJpRWs5a0TKqgWDugAzSKQ/DCWFwOfzu5Y/WOMZXP2fm3u+7oZXiqAfySYwD W3OjmBRpOpvVeuwgmVz7q7Uwe66uG9STfQ5vi3xsQRZ31hU0jYX4aV65gLjZLI4KNuqp s3i4y6+UEn7HZKp5mx2Fv87oNW+kLo5cBNcJFJlb7CzS7OrbzXqCMGXC2nZby+Snsajz Wmcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bdRDwubt; 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 x18-20020adfdd92000000b0032160212b91si7226120wrl.206.2023.09.27.02.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:48 -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=bdRDwubt; 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 08AC686D4F; Wed, 27 Sep 2023 11:37:39 +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="bdRDwubt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 62CBE85C98; Wed, 27 Sep 2023 11:37:37 +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-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 338C586D4F for ; Wed, 27 Sep 2023 11:37:35 +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-pf1-x433.google.com with SMTP id d2e1a72fcca58-690ba63891dso8082444b3a.2 for ; Wed, 27 Sep 2023 02:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695807453; x=1696412253; 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=23L8aS493+zafOpjLr+4gUrZEYR4Ae5sZvaUqjD4Qh0=; b=bdRDwubtHafiTQnFAVL4LqNBBYX3i4YniOlNLgcuxI5oVVFYCks+9lP8Nw+elcysp7 TGRJpuq87AYT+BMb+F5IVFAdDK/ZSh7j8G3l04hu9+IEMs7AWkEJaUYB1CDQPrL3cIaM lzG/cF4oFM1iTqaHoin5cFCwsvPTWQCs2bBnb1Dbs+uCJ+fSN7Rpogxw719LpCYWh2rF +nTLQWLw7464lX+zP/ANS+mwdttDEFHuFx/3znwp67NBAMWeeuS5SbvIotOQMYtd+Rsg HqlE1fV/7TnXv36prkPtMBM7O6wTQRHhjQP6BVIu+94q4u6HCLrwvNehA1yGRxIUuljX 6CTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695807453; x=1696412253; 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=23L8aS493+zafOpjLr+4gUrZEYR4Ae5sZvaUqjD4Qh0=; b=tXnnfw8Wkej6xojaHv/rluHj63laaFnIsrWePb/YCX8krZGtISZKR2fGV+Pc33IecM lc0kO4gtJTkeLm5bdIYoKeVrIK37fUBTsKgtHXch3SRomegpYOdLUmE1tYZuMmd2LBBp uKWthA3DMpBMn9NXqdM+2quIbdTkf6Bf8XxY8bCsOUx2u4vXG4y24Z9h7Sy+kh0nF/Xn 7iNq88JCP+zkHHtUf50g06h4Arr36rnIrlTghUMJE8J4mX/2oxfMfY4zHS4PscnL+3mw HOc/YVfV4RohNLYBeLXpLYbUdTN5weu+2l3TdK6WDOh/5b1bviTj0Zx8b409456vQEKG A9Zg== X-Gm-Message-State: AOJu0YyWshjXV3zVS7xlUyFyFWWomTFptCNANIM2D8HzyLuY5nf5TpOK 9VI/MfhWVCs25ptMasloMSwSI//zYQ/X74GIEk0= X-Received: by 2002:a05:6a20:3d14:b0:15f:b5:bfee with SMTP id y20-20020a056a203d1400b0015f00b5bfeemr1535024pzi.5.1695807453112; Wed, 27 Sep 2023 02:37:33 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id jb19-20020a170903259300b001aaf2e8b1eesm6694183plb.248.2023.09.27.02.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:32 -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 v5 2/7] net: wget: add wget with dns utility function Date: Wed, 27 Sep 2023 18:36:26 +0900 Message-Id: <20230927093631.1595494-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230927093631.1595494-1-masahisa.kojima@linaro.org> References: <20230927093631.1595494-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 --- 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