From patchwork Thu Nov 2 06:44:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740428 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672304wrv; Wed, 1 Nov 2023 23:46:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPUvq4rB003lbIRx+OK/zKCB65BoasAbgIxkDLPkuL0C0RAwPrxKMN9Yx0gqavQlQ83uAh X-Received: by 2002:a5d:64c5:0:b0:32f:952f:c524 with SMTP id f5-20020a5d64c5000000b0032f952fc524mr5700266wri.10.1698907610584; Wed, 01 Nov 2023 23:46:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907610; cv=none; d=google.com; s=arc-20160816; b=Qb3tyvr95h6SiYeIweplCHOQ+mxmQb11R26R9vr+GvsQ2qJ1pGPtMPdIwK4IJW53l4 Kq4n43wUSJYWEy45dLok/pYTAr2R++mFJjDBEEOqUgZZcG8nMPK1KOVze9auFpuEeLw1 EO+UkTwDP5cq6D+8tJG5+nwXFCnVHj4Q9t+faCJH7PMxe4mDmcnahOA5eeQ3TKi+Ezv6 I2PwSgsqruauq/GFO8mP3GmKjr8Hz7JTvwsAro5wu8kqSBJXimfy2O49rwKWgRqTQEJP +o1tzKGyONuqzql/lL2i5/rTc/qInfr1uYQRjaS8n3GXiNq4pSKDCwzWTh5uU5Y/D7Hi qvXw== 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=A4qEfI1sO1WejJzJQ+Itg7oNJsuGBM1eF79uFdT0LV4ADc+86iE/fYS1/aMvqLOmKh 9ucmtwYRFFhU7CY8YpU4HzRMd1FpxYQ46Dkb2pLV+fwtASn+AZSWxuthtj/IYh/xi/F/ jud9o8e5P7E5Uf5+nK8hjbMjGcwcloWupqr9Nh+1cWKltKwvEvjfUN9buP3NYNGVz0Ur 3mTO0YE8rKTSINtyopDVjuzlYe63bapyJvOHHMJa96ilB9dzFTsxssX7PKt1sPARb5OG 2iSE+en/zgeNjc+2s1UHNz4fBlaV7SM3grUOu3DzzUbfsFEzqCb00YNp54M8xAiIuK1x qZZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uBzK6W+9; 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 b4-20020adfd1c4000000b0032f982cc6dcsi968084wrd.85.2023.11.01.23.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:50 -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=uBzK6W+9; 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 281FC876E2; Thu, 2 Nov 2023 07:46:28 +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="uBzK6W+9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A7FDF870C9; Thu, 2 Nov 2023 07:46:26 +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-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (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 B8A4D87467 for ; Thu, 2 Nov 2023 07:46: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=masahisa.kojima@linaro.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6c3077984e8so613575b3a.0 for ; Wed, 01 Nov 2023 23:46:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907580; x=1699512380; 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=uBzK6W+9W8WYBjvUTOKgzthbcpbUx0Rz0NpJeNI1dd5r9OSCSnQN2alBWxfDu8GSoA 3tky37zNqQFNWfpbdr4FMvZIzqqvt2YKlikO4yNfdVBvDbFrINhmsrUKrZyFa7dHBDNv tvSrUaVN8C0wAFEptDlU8Zek9QwdZSm/P/i0apfUrDJHR/NfKuFx5nMdmpSdi7ckwBVb C/46zf7ddlL6n1haiEOlIigi6f7kbLGaguExbWkVnTp6vMEcxjlnItrCbq2vFL+ehi0t WPAvqVj9WtRL5J0WBCOyPM5vG2ZSVvsDiLnJxQ1hH0r4P0Y0/VStSue4mOS8skGMb/sJ oSgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907580; x=1699512380; 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=dTkcR+F9M6n/39/3P9X9Ey/W2RRScggKw1YsXQiHgPutVb8m/ItSimP58mspuJ3KL8 pgq0irNNXMC65ixNquQeKFjhFgaoXEIJST+peT9L6YjWsBj02jRwtAHZXqlFRGU6jKnm HycFmzzsuokR3xBEKNh0WT1eCsXYYLITUwTvajvW85PjHaezuAt4oSP/y18pS3XNyMxU iqLuBktJe2H1WiqjPlRKWIvx2Id8G3wdFl1+C4FFEEcR/TSTWK1inHLs7vY7UaW+27Ga fanbtBtwg2aFm3xddHSD05Mv2bPz6bHqK3+553Fy1wKGA04M0mcM5blSVn0PBMkMqXsX WMrg== X-Gm-Message-State: AOJu0YyCg/09Uv0CpZw4k+Qo/ZHUSCCu1ey9dT06fhRH56ZIcETEqq+g mX+MjM9zILGpBCJKs1Bh9Zz/Lu8MPUcL/H5Syfw= X-Received: by 2002:a05:6a00:cc8:b0:68f:dd50:aef8 with SMTP id b8-20020a056a000cc800b0068fdd50aef8mr19372182pfv.4.1698907580587; Wed, 01 Nov 2023 23:46:20 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h13-20020aa786cd000000b0069309cbc220sm2170329pfo.121.2023.11.01.23.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:20 -0700 (PDT) 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 v9 2/9] net: wget: add wget with dns utility function Date: Thu, 2 Nov 2023 15:44:52 +0900 Message-Id: <20231102064459.3466953-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-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