From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
Simon Glass <sjg@chromium.org>,
Takahiro Akashi <takahiro.akashi@linaro.org>,
Joe Hershberger <joe.hershberger@ni.com>,
Ramon Fried <rfried.dev@gmail.com>
Subject: Re: [PATCH v4 2/8] net: wget: add wget with dns utility function
Date: Mon, 25 Sep 2023 13:52:03 +0300 [thread overview]
Message-ID: <ZRFmU32r473EsOpH@hera> (raw)
In-Reply-To: <20230922071119.1439482-3-masahisa.kojima@linaro.org>
On Fri, Sep 22, 2023 at 04:11:13PM +0900, Masahisa Kojima wrote:
> Current wget takes the target uri in this format:
> "<http server ip>:<file path>" 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 <masahisa.kojima@linaro.org>
> ---
> 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 a48a8cb624..4801e28eb9 100644
> --- a/net/wget.c
> +++ b/net/wget.c
> @@ -15,6 +15,7 @@
> #include <net.h>
> #include <net/tcp.h>
> #include <net/wget.h>
> +#include <stdlib.h>
>
> DECLARE_GLOBAL_DATA_PTR;
>
> @@ -504,3 +505,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.
> + * "<http server ip>:<file path>" 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
> --
> 2.34.1
>
This can be done better when we integrate LWIP but for now
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
next prev parent reply other threads:[~2023-09-25 10:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-22 7:11 [PATCH v4 0/8] Add EFI HTTP boot support Masahisa Kojima
2023-09-22 7:11 ` [PATCH v4 1/8] net: wget: prevent overwriting reserved memory Masahisa Kojima
2023-09-25 10:50 ` Ilias Apalodimas
2023-09-22 7:11 ` [PATCH v4 2/8] net: wget: add wget with dns utility function Masahisa Kojima
2023-09-25 10:52 ` Ilias Apalodimas [this message]
2023-09-22 7:11 ` [PATCH v4 3/8] blk: blkmap: add ramdisk creation " Masahisa Kojima
2023-09-25 12:09 ` Ilias Apalodimas
2023-09-22 7:11 ` [PATCH v4 4/8] efi_loader: support boot from URI device path Masahisa Kojima
2023-09-25 12:37 ` Ilias Apalodimas
2023-09-26 3:01 ` Masahisa Kojima
2023-09-28 11:35 ` Maxim Uvarov
2023-09-29 2:13 ` Masahisa Kojima
2023-09-29 6:24 ` Maxim Uvarov
2023-09-29 7:00 ` Masahisa Kojima
2023-09-29 7:43 ` Maxim Uvarov
2023-09-22 7:11 ` [PATCH v4 5/8] efi_loader: set EFI HTTP Boot download buffer as reserved Masahisa Kojima
2023-09-25 12:46 ` Ilias Apalodimas
2023-09-26 3:11 ` Masahisa Kojima
2023-09-22 7:11 ` [PATCH v4 6/8] cmd: efidebug: add uri device path Masahisa Kojima
2023-09-22 7:11 ` [PATCH v4 7/8] doc: uefi: add HTTP Boot support Masahisa Kojima
2023-09-25 12:12 ` Ilias Apalodimas
2023-09-26 3:02 ` Masahisa Kojima
2023-09-22 7:11 ` [PATCH v4 8/8] efi_loader: create BlockIo device boot option Masahisa Kojima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZRFmU32r473EsOpH@hera \
--to=ilias.apalodimas@linaro.org \
--cc=joe.hershberger@ni.com \
--cc=masahisa.kojima@linaro.org \
--cc=rfried.dev@gmail.com \
--cc=sjg@chromium.org \
--cc=takahiro.akashi@linaro.org \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox