From patchwork Wed Nov 8 11:06:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742223 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227477wrw; Wed, 8 Nov 2023 03:08:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJKPfMwFLVWVdEjvRbgg7IuT07RvNWIS6FRJjmbIHcN4EGPPxm70oSOs5Q0iiW4H94Wwir X-Received: by 2002:a17:906:c142:b0:9d2:20ee:b1d0 with SMTP id dp2-20020a170906c14200b009d220eeb1d0mr1014321ejc.53.1699441690927; Wed, 08 Nov 2023 03:08:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441690; cv=none; d=google.com; s=arc-20160816; b=sMyHcCqDuk2964YmiGx/3NDm2gdPf7gJmOQvBta5B+2+MCLhGPHmazBjYV8WS7i6nH QwvE3nZC0ZOVq+gvrMXIZSShrZRTM+N1rfyJdBZhJp8w8S4BZ6qcMcS9dblvjsI7gPu9 Jp5LfAkUl4J4bp0ssevPtjxOaqUX3EPFhN4740LU8W15wIhv2eGamxm44hwAoUNoRm/g vMlRYDSBypQsYs6hClumjOx2+++YHzIQ7gpZ0n8VEhie8eZPVWTLGYwLYKitdVZCheBC dR8h0Y3KWh9HmAqiWbyXH2csDZMYVpct8Rt80gx6Gq8yh9fYm1hI+GT4ALDQqcbzScoJ Uh8g== 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=S+AWbgL/HUQZQnqFDt9ybn/w6PgW+fMI1r188M4/139SElNxWKKaaUKJISW2snvavV 4bXWeC4HCsuu2hoMza4YkzcuwESSw8XItBLPh1wFiRsOU7Nzk9TqZgENBEvxDHhAjVVu 7xCodY5nLVc+JR9z1a1GN9UWpxS5YPiUKbkJVx1uYBNJNo/Jrwp2TwG6QYSNKC3w2iM+ AQ7thdxGgn/Od6NvdlQ+qq0qm3LMdOp6PQyN6F0aFh3oc91y1dHd/Q8gQvHQmu2aHdcS nwDqw/GywIKa+y/tY2if/BB3LjHMLYFR5QfnK0AZIZp5YfaTNv8LccDJRU2JZoCG+5NL dY1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XdrcCPJe; 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 17-20020a508751000000b005360a551c4csi6674431edv.74.2023.11.08.03.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:10 -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=XdrcCPJe; 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 9372187703; Wed, 8 Nov 2023 12:08:04 +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="XdrcCPJe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A8968754B; Wed, 8 Nov 2023 12:08:04 +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-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) (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 EDB18875DB for ; Wed, 8 Nov 2023 12:07:50 +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-oi1-x230.google.com with SMTP id 5614622812f47-3b52360cdf0so3223063b6e.2 for ; Wed, 08 Nov 2023 03:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441669; x=1700046469; 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=XdrcCPJeUA9V2Ggn6UqA591AXAwvtYnO5IzNZ96EYTJPUBu8xy+mo0lPp+N7MN5psf aE2tRBgPyRTnn7Re2SlDeXSazAOPTskcqFLvKjUC8fAWu8ynmLSs8Q4SEDzSzJAmJ+jR mC7X1+cgnyR2oAccQ+n+UCU90KtO8hEwGpqsjUrjKGZoWJnpRGRrbwXI8vJ38R475t5k TBdlV3zyEi51VQBl+t8b4u/iVfjWPhvWyoHkVMrxuXMda5ZWo3XjDhm10FUei9PJWfOV XRo6JLRvCjuw/lJIPqkA/kVPvYtJ5/6JEky8XvwAUgLYQOuexPAcMzUgHFhRqE4hjNnn 95cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441669; x=1700046469; 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=RPSVaYrsao5mMkTDshE+b8ddi9NWd1Ts6TUsGYs/N4QzAD9IO08CTRH3iAMkZ3Q9mx TcsLbdmtLjcALj5UXHf8KDiym8cEQYFGZjgPXJw/edLIQTOotE/ls7u+frW/alHPR7fC 0usvM/mSSJeLLhI7q11olOAZ65ZJC0lm8Zh318c4OLTBy3+TyoHsVLe0V8vw3gGnAKkH 4vXdnH7M2Km0gah0D8lhRRIlQK1B04V46HbBbv/CoxBRk1sRTRlvJ4lNp49tSwXQSyRW V7K+FplBW1qe0wWtH2hUTEIJvQBCniGJvWMK0mkYGeuIHWK2hHU+R54Xgv20YF9Z4xFE HYUw== X-Gm-Message-State: AOJu0YwvNfeMrI6pxwWpUf3DliOH9t6Z3LjvwoP41FhKLOOhqGZqMeL4 2uTpgaK6mJJL429ptkbKg0ULqSQXfi4nqzvC5Is= X-Received: by 2002:a05:6808:1154:b0:3ac:b73a:757f with SMTP id u20-20020a056808115400b003acb73a757fmr1974618oiu.39.1699441668851; Wed, 08 Nov 2023 03:07:48 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id m29-20020a634c5d000000b005bd2b3a03eesm2916497pgl.6.2023.11.08.03.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:07:47 -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 v11 2/9] net: wget: add wget with dns utility function Date: Wed, 8 Nov 2023 20:06:29 +0900 Message-Id: <20231108110637.3691441-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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