From patchwork Wed Oct 25 06:28:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 737806 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp131214wrq; Tue, 24 Oct 2023 23:30:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1RhbYEL7VUSlRpuqmKmYXreR1L1eOL2UczaF7eCJ0xha7XEvwYM15RJwBStLg/QvN5WBf X-Received: by 2002:a5d:62cd:0:b0:32d:9df1:6f6d with SMTP id o13-20020a5d62cd000000b0032d9df16f6dmr9562083wrv.17.1698215453048; Tue, 24 Oct 2023 23:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698215453; cv=none; d=google.com; s=arc-20160816; b=X/1KIeCkgGEnJ6ntNGKnyIcYlJSietvoLjTG/wP61BqIRkclItsJ6rNOzArSZU9Hde HPwV/qmiPrl+0dp9MLXU4XYp1vlQ5s31tV1W7YPE14Ifg821KuZmKoG2xdRqhX3gX989 ilIt2JDJiZIWwIQTGzx1+PeKFETDz6ezvpd71zQ/bPxsn7tgtziMTugN1DpEvDC8tSQD g2fm5W+gOta7zV4zlnqGxUc+ZQ/u+2OIWEp81RXZYGZNG4ZESKd8d5Zx/C1dberWu/hb yeKgKbIRuqYeUcVQruTSReEbFutVFzoqhK94zEieBHxYALN7WPjGf+iQLttMwwEz7Ke0 rHNw== 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=dB5AjyyilBE04s1KFsx3O+o3BC9z97K5PjnVRA/iL7LXsPAGwSSTbP951T9NBDVo+Z O0pb94edIM21B6ReHfrTlohkBPXABQVMEQdCFAyPI57DzbVS+88m7FwknHByEgeq0oy9 rl7fR/oHYn0vSkGW4mUVJHFPzAbtJF/MvrE0M1WpndSa78q/6ebix4hglIOkOmdILCGC 4GmUvJtDCaGNWuBZzOXo2yYcqKOCSPwn/Vj1vzThyS2tjLGK601AlQ5pZozMwp1Usv0A qp4jJ1mudEMcFwCqJrYH0nf2pyHWMNJTxd4368eJinDsusDNXUTo8BbS5tc9s0WVJJCF 4xYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k1RTOuO9; 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 l2-20020adfe9c2000000b0032dda7a59efsi7008046wrn.709.2023.10.24.23.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:53 -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=k1RTOuO9; 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 DC41A87A59; Wed, 25 Oct 2023 08:30:22 +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="k1RTOuO9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67785879E0; Wed, 25 Oct 2023 08:30:16 +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-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (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 69CEB87A2A for ; Wed, 25 Oct 2023 08:30:12 +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-pl1-x62e.google.com with SMTP id d9443c01a7336-1ca72f8ff3aso37805995ad.0 for ; Tue, 24 Oct 2023 23:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698215411; x=1698820211; 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=k1RTOuO9E9PZBvSk4c/KkXi2bA0hrMvYj1nyNxVxhbqZyWT3Rgj0VEzx3dhlNrY3e+ +RQCi5sH2puymCcD4T2Qw+mclZO/76IgrS1eZwTk1NBOOjxXIOxF43Ec24yR7bUj+Erj d4KpH6x7eMA7xR2Yd9enfNlMPGFlgupHIglDk5K29RQF5vVBTeiOipnfIMpECnn8oRr0 6kFyK/Udz4g74U2Vz1UOSOkwVfhCOHqiNmbox8cOe0ucKhRWqvAFjFLyWS1Cv7r0eoPr WzsFQjde8j/zRsVl5Y7XBnK8ai1b131ONU+ojFXnQOINOy7kwjHyXqipBT2Ceh1gvPsw FHeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698215411; x=1698820211; 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=d6zdm1XI/oSCTlBr4wttho/oTf762tXNbZltRihOjUrbjBJKiHKyGfbbvQXMNtopzv lpDNTWKyc36xJh+mAptaCklIrNP4ALpuh8RiHHNlTyR9cPdOm2nAX/S8g+BhfWYgDZBq UfZ/5wTEjOTDBE8RUYK1sSVysUYkpTi6it725GLQuT7vYMG4zj5ziF/2rbtScLXbFEzI UAuG7a6OBOi17Cv5Z4lLFAvxMZSDR4Y1WoqZT4shM9vqHAeS+viFkFg8V4+byaMsLgVi LdJJUiKZdaEmVsbXz+o65HDhV5oEoiu534ehudk1RnY9IRI3PvXsuUhiqOvge7SJuqm+ QDnQ== X-Gm-Message-State: AOJu0Yy4dzW6RhRfqcxe996wZ7ClAHDRQN1iq5E71OGtSxOTLtfwkdaW LvPwVG7TNQEgW5d3wvufQgOwUyag0HXYfsftl3A= X-Received: by 2002:a17:903:4052:b0:1ca:cc28:b4f with SMTP id n18-20020a170903405200b001cacc280b4fmr8677027pla.54.1698215410852; Tue, 24 Oct 2023 23:30:10 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id b15-20020a170902650f00b001c6187f2875sm8663888plk.225.2023.10.24.23.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:10 -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 v8 2/7] net: wget: add wget with dns utility function Date: Wed, 25 Oct 2023 15:28:40 +0900 Message-Id: <20231025062845.3100964-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025062845.3100964-1-masahisa.kojima@linaro.org> References: <20231025062845.3100964-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