From patchwork Mon Oct 16 04:23:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734007 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp33960wrx; Sun, 15 Oct 2023 21:25:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWLxCYNVUVk6xuPgvNWBE8oy8ygOPOFjZ64b4W38hQl6mAkk6t/2NE4BaOx5EeVf8EEpSi X-Received: by 2002:a05:600c:2189:b0:405:315f:e681 with SMTP id e9-20020a05600c218900b00405315fe681mr28400090wme.40.1697430326511; Sun, 15 Oct 2023 21:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430326; cv=none; d=google.com; s=arc-20160816; b=y3tfm52pZOxHsashlaxy6jtYNp0+k6vQAgNREg5CmGWIEObxiL+9DQoxMoxBPYWsPG sjs9Dtgu9rzCU61u56fkBAb2zPZbZYIK4oaHC1CzA4mY/iSDgTxZRNhzM2Y1WeNg0cbF 1WfDTN1tpOfZQyr3uOzl9LtftC98tvbHMbaMbhaQdamrJ0q0VfRQdv5f0kZNUexDbfK8 9/QAkHY6m+dOqVx23D7KVrAIu775SsFJHqPn3Vv8cgkP4AEDXTWxVK/djm7ACWsfWHDW WNrdGKz16AXB4jj6/9+LFz4uRvVCCHPfZD3OIQkbT4s5YMbsizQsejtTCkYsMBbjO0ZO fn3Q== 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=AxQfk1AQMYeRDW5jVbxxua6uHdqN+0OHX6QmDQqNybu/ddozvk4mw4oDwdCnL0cE2t cKaz1WZ/vRFmRXCRD4CijgNRR9wJq++sV6y6GhBa8R4E9dr9T8vpxoU7NHbFnViCoqb8 Z2UjCEFdXMM30Sf1u29VpiFkx8gyfah1YypEIIS6J31zenFSi/iDin3VKYsDytLprpNX Q3pjTu/wffl1P+PmSzzm9WpUOAnQRhHqxqMPyTB8Ku7+SS71TqmN196n54jW5lDo/6Qb Y5dsSAHLFr8kGtubGSNczx+UMtf3KbzxWVo8dSmdjRIkxwb7qoyzkm3BFenTMxloWYlP BV5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="g/HmHsnZ"; 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 o8-20020a05600c510800b0040745fefdf6si2215169wms.131.2023.10.15.21.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:25:26 -0700 (PDT) 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="g/HmHsnZ"; 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 B118586C3F; Mon, 16 Oct 2023 06:24:50 +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="g/HmHsnZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A0B6185423; Mon, 16 Oct 2023 06:24:45 +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-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (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 1009086940 for ; Mon, 16 Oct 2023 06:24:25 +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-x436.google.com with SMTP id d2e1a72fcca58-6ba172c5f3dso968187b3a.0 for ; Sun, 15 Oct 2023 21:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430261; x=1698035061; 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=g/HmHsnZuaeQd/8VbXQdJFJuRpg37dw66ubWleKVPdK8ms6DxiWIOqalVyVwbmTcmZ iszy9aUpC8mdL0pJTQgZz25iyJm9VS0DOGNO4l/wZ/PbAB58ZJjGGkctjqzjC23SHYV6 Y/i8TEzxoLvyfF8HKK3Z5oGVnCgpnRgvIfIvMX5RBCM+0SBe5+TZxaFP4558Yna4J6mJ XNftIjj5oruSUD86BPUoOUvYtqEpplse4fsOUv0/amgJw6Xj/OGOK4ZNxxp+7ruI1gdc MRLQH+WHfPeNxg3DIc7SaqSdsatOjGz3/qyISrN95xXLDUxa5TSskEcDNC5TUqq80p0v ILrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430261; x=1698035061; 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=NcyXyRUk87HvpjXwSuz8NtZGbUFzOrTo4jr3u3wc3pu2pYpP4OBXYHPZWR/bENwPsd xfPvJuNbEaReY0ssP3n6i8c6go81sKW2l1NNJ4baUvj7CwJNDgeorsP2XL5/rLMMYKrU zATke/ZAUxUSagFvxyCheY2IWtG6yPLUwateZ0gihpjE7BViyia8SzkQyixmPuQS4R+V FV1SJmBRo5Ozsu4pKvQPMeVByEMdtuYt5Q3civn5it61wDHQGwjleGdo0xd/irWtxMaW VQsnVfx8X/aXN3f7+OPSvOR3dQfRj+DH88o+M3kvz0+0vg+Jb4NCED2JHkVf0kAnaX+c Fktw== X-Gm-Message-State: AOJu0Yzs12k08ScTmfew2Nh7LGLMYc7HSjdjwLA2FvquBnEXiJH1OLV4 ldQWKZeqZANM1mu47HAAWTneuz6O9mjKam2CMtk= X-Received: by 2002:a05:6a00:21c5:b0:692:af9c:d96a with SMTP id t5-20020a056a0021c500b00692af9cd96amr31095618pfj.5.1697430261579; Sun, 15 Oct 2023 21:24:21 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id f6-20020a637546000000b0057c29fec795sm6993559pgn.37.2023.10.15.21.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:21 -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: [RESEND PATCH v6 2/9] net: wget: add wget with dns utility function Date: Mon, 16 Oct 2023 13:23:01 +0900 Message-Id: <20231016042309.2386387-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-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