From patchwork Mon Nov 6 11:39: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: 741371 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1035991wrr; Mon, 6 Nov 2023 03:41:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IECZ8rm8wc8/d3kkLdfUZcbXeoP1Du7/giMWN5Lhz44gL2t8wBXpLxN/LsQArPaGLoHGVwp X-Received: by 2002:a17:906:6d0c:b0:9df:254d:3e45 with SMTP id m12-20020a1709066d0c00b009df254d3e45mr3090446ejr.24.1699270898388; Mon, 06 Nov 2023 03:41:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270898; cv=none; d=google.com; s=arc-20160816; b=G39vTHASiDIJYxk/6IWYsGA7eNrJwzyPGUKI6L8tlOuJPz6RPYYo85twDgep6ruKKn pAWBFC+NNW6FYdCmqybE6wA1W1wZtQsh5TYBTe8YOzg+ZC1WMvTSbA88bqM6CK1zISUY FkHIPr1xEeDQo47siDtBXQVqAjn2OOsaDIXt9W+rDu09jmfDNHyLL+yd//zSCggKrqFP IX7y/5HarvcOgHQUrmjPpBi0Ly44iD3E+9YphMikENH8RDgNSfu61zrRnmt8WQLyIkdI Fh6VzACnYN8di8vGbmBHrhm4JBo3iBrGe4h1l7n9lOazuEIhWX+n1JD2yw/wB1BnPRlv e7rQ== 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=LpkU9wk3gj829EVx8p2lHMNKkbubof1kR3KeYVvX1vo=; fh=eBItVz4B+jX5FuRNHVjUaldxTsf8xOQKLrDTtjpPbrk=; b=LnR1lmEWLbIPMBrPMcn771ZhaSViLrQUp2Qr0ElRaz46WOZT820WBtZ3nk3OPRbZh+ Sf8dkxKUdqwd2+RUOqzyEIecIeuTYwU/Caf9XcMgVxbZ5I+X71lXk8K3K1v0L0CX87RS sea2R7qTwXXledZps9bN4CNC5gDjEJGL6Y3b2yE872m0Ky54PAnAlfIVsiUAwKM/R33n n6kjmb9SAZW01rRhxvdio7lckkyo9voP0Sa6jXnxNgM+e2Y9IQC6Nn/WjVMdaj6Fzagn xsYQEThv8QbHzo+Yc/ZuynAnVW+4+JwgKq9DfKJBxnNyZtVFarV80Q+hc7sX2NM0/+WR vYhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZM4fmkxa; 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 e25-20020a170906749900b009922cdfaf62si4087027ejl.42.2023.11.06.03.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:41:38 -0800 (PST) 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=ZM4fmkxa; 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 63F4086FF7; Mon, 6 Nov 2023 12:40:37 +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="ZM4fmkxa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B6AE38653E; Mon, 6 Nov 2023 12:40:35 +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-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 69C1786BA9 for ; Mon, 6 Nov 2023 12:40:33 +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-pl1-x62d.google.com with SMTP id d9443c01a7336-1cc29f39e7aso27453935ad.0 for ; Mon, 06 Nov 2023 03:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270831; x=1699875631; 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=LpkU9wk3gj829EVx8p2lHMNKkbubof1kR3KeYVvX1vo=; b=ZM4fmkxat6q5m3uZNmDecL6N31sTNVUG+Hoax2bC9Plhx6o2+f3hb0/GcxsFAqAixG 1V+SxNpPhYrSgDf72Hl2/Dum75NivHAODdJQSsDFhJSvuKqNGTzFdnD13rEPz5XTluj+ Jq+olNoF7xGHUaV97nI4LkIFptHZUlwKholXv61yKNiP5IWc0wU2cy1+e6EbgN6R13Jv +HRgX/ryjQbB7DL744VjEYoAgC4UwvMYhuNoEV5LzkTzZUHmBta+mXMn5SnO6+hvi+41 TC1R1NNhQ6GRQqyfR4CJxwBUXBEoxv+jXf0lKSWJuX5MzXcZCDTkLaK1R4kKg5bC70Yr Mx9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270831; x=1699875631; 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=LpkU9wk3gj829EVx8p2lHMNKkbubof1kR3KeYVvX1vo=; b=sdS4nTSG+F1im16v3vS8hTctYhOeOfYqX/3WIY2m5jPll25+XvggV/6CipqTXeXUO7 o4D/cLnvJBGsIBMN1BUbSXVSFJJP/BsYtXRKzW94nYOqxC8HsDlD+ipLR934k0O4esGM xGeNkGOxZRZlbfowqxVrHAwaXTqjpTeo4iRrCXi4KxkgEFXD7ygNAZEMboP6+VbgiWAW Jgvcu9bHpW4TnpAQBpdNnybkvHKWLZb3j1ar+AF5XIX5sU9Ul43evXBPzyjDgbX6Y+WZ jhnPVLvF7fbIe6q7jUiDncGwZXX7mVkpJgejXHdfAVhhjApod/2JmTKEIUy5gDs0BMQ7 KmMw== X-Gm-Message-State: AOJu0YxmA3wTwKd6M2v80IjCWa+DWCGJM4nL3BDqJbX55Lj4U7tl3aTD uagzA2R6kYSLSi3zewohh+uzLohWnoFs18muCDk= X-Received: by 2002:a17:902:db0f:b0:1cc:5ef7:e3dd with SMTP id m15-20020a170902db0f00b001cc5ef7e3ddmr18197030plx.47.1699270831326; Mon, 06 Nov 2023 03:40:31 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id e19-20020a170902f1d300b001b9da42cd7dsm5745534plc.279.2023.11.06.03.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:30 -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: [RESEND PATCH v10 2/9] net: wget: add wget with dns utility function Date: Mon, 6 Nov 2023 20:39:13 +0900 Message-Id: <20231106113920.3631591-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-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 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