From patchwork Sun Oct 15 23:49:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733895 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2466430wrv; Sun, 15 Oct 2023 16:55:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELFMiukJFD7rRlMCsx7mokESJaj2F7QV+XNZLoMvWzU412Y648hepZEELQ9jJjVaP1aeNJ X-Received: by 2002:adf:ed52:0:b0:32d:9a17:2a72 with SMTP id u18-20020adfed52000000b0032d9a172a72mr6257365wro.55.1697414122891; Sun, 15 Oct 2023 16:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697414122; cv=none; d=google.com; s=arc-20160816; b=IT091MbynxVgI4iVAUdHvKE8IMSTit4c5oqvlrd/pS58aw+zJR0AWYqJ5w5/PcWjjS i5zw8QroBU7IhodZS2h6hONrPDUQ46LZX3TPAQlJoIC6h5xPI+kbU32VTWNQeumHY8yw qu0WCeIwNq1tqSx12GwCzyDfflKW9VTrYAC/m7ur3yruv/1eSfCo4jygj2FLbnpvy5Wm g4gxcdYVO8XjPOZLf0WLjX/k2NGyIiisxGDAZYisHsSy3Z8kq2kBph2/luJgqyVl9yp+ iBshUd4RdNhgOdsr0rQP5sHULm6nZtTmnU7WwgFI2bakEiMjjENADskGXCSMEAr5Kj2B 9F3g== 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=LsFL2XfoUIFU6f0RR/RdbWmwhM/OKW8DMTl2JBiDp7OEdSiUPmyuwc1ydIjJUZiIo4 gxHGHsP9UHVldrD/ecqmc2B5OLiIKq9WVNRVv4SFgDCeB20y8lzNseMFvU4efCRFygXf uHZdiwi/COh1wTrv9bkhqpAVFaymogKwkS2oVDzyksgZ4eWRV1u0G11dIsercWtvfuaC MHbi/6zwkDJWjZ1T2Mm3tu/jfr+BtcnmoRFpeU54gWPkyQksLzS6Z0BzUr/dq39tzo7y gf47qYj/hZzhgTm2E8UBnTztUa7vDDO3F9dTFy7LkqVt81usAPH85k98Dl48NehlK5Rq 536w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dqYxhg9B; 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 d14-20020a5d6dce000000b003216a203a0bsi10057149wrz.139.2023.10.15.16.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:55:22 -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=dqYxhg9B; 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 4D2AF869D1; Mon, 16 Oct 2023 01:52:53 +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="dqYxhg9B"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2BD04864A9; Mon, 16 Oct 2023 01:50:42 +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-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (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 B954786AE9 for ; Mon, 16 Oct 2023 01:50:30 +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-x42f.google.com with SMTP id d2e1a72fcca58-694ed84c981so2930724b3a.3 for ; Sun, 15 Oct 2023 16:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413829; x=1698018629; 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=dqYxhg9BOIH80XS97PCcAehRYUyiELEAzvAKUZvJrSnun3TnB2wis8il1fPDQDxy5A /TxHwRgVnWIV6OoRBodx+E51Ur0lpeJGoM3AHtL8z3JatuINct8FUSFfTohWqdhLsd3p v8HoleekWCsEGsAtcPJukmwkOUtcsGbzJSXABuKG9HpuBvbJl4yvi6eBG4xnjKtK4YrZ uyVvI0A/QBIaP+Uqc39TcAoqCgSrVn9XzXmmMdSEwBzynyxVoe849KtM4BSrTwOqngZv pijWmxiuhry1UrmlJnAr01W6OU3ObT4uEHGRe0QH5NGG9DX6DzALl3WsCWy12OACmnZw ShUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413829; x=1698018629; 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=qQSL66JPlWGDiZf5qDf81g+uZkSF/EM6WI2TvWxNs/C+2HWmACIo6IlPIv+XK2C4xu jjDjkevP6XkZmgTPmyntsVffF663IcXhqfQ1cUuCoBNW0dthBi28RUL1Vr4dLsM1fnJk WXJjQH+8H+dDwccRehSutqRwthGa1DkOAkdFvDPCXTFiGCJ9QgNpoOUhRdiM39t6cmg6 jiKY8KnBX0sB3egOxjhN3ofGZ3D6h68+ourTtDD5dQVhIqcSCPPjG+IwRcBFbCWGqG1c kxs60am2dlDXx9eGWJaNUfUorMevEmgd9GDzt7EqaFieBmBKjI603PYHgErMmA2YXqEm 5Cug== X-Gm-Message-State: AOJu0YzLNmgP396w/50aItr7SKAoaxz6pjKW4rVU8qt4yckq5VXbZjiT Sllk86vqUUSO2hciPTyDyzabPNHKEa//y1zUoE4= X-Received: by 2002:a05:6a00:885:b0:68f:e810:e86f with SMTP id q5-20020a056a00088500b0068fe810e86fmr33717470pfj.28.1697413828915; Sun, 15 Oct 2023 16:50:28 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id r13-20020aa7962d000000b006be1dc1537csm651926pfg.59.2023.10.15.16.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:28 -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 v6 2/9] net: wget: add wget with dns utility function Date: Mon, 16 Oct 2023 08:49:00 +0900 Message-Id: <20231015234907.2362717-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-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