U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Jerome Forissier <jerome.forissier@linaro.org>
Cc: u-boot@lists.denx.de, Javier Tia <javier.tia@linaro.org>,
	Maxim Uvarov <muvarov@gmail.com>, Tom Rini <trini@konsulko.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Simon Glass <sjg@chromium.org>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	AKASHI Takahiro <akashi.tkhro@gmail.com>,
	Michal Simek <michal.simek@amd.com>,
	Francis Laniel <francis.laniel@amarulasolutions.com>,
	Peter Robinson <pbrobinson@gmail.com>,
	Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>,
	Masahisa Kojima <kojima.masahisa@socionext.com>,
	Ramon Fried <rfried.dev@gmail.com>, Peng Fan <peng.fan@nxp.com>,
	Sean Edmond <seanedmond@microsoft.com>,
	Ioana Ciornei <ioana.ciornei@nxp.com>
Subject: Re: [PATCH v2 08/14] net-lwip: add wget command
Date: Thu, 6 Jun 2024 12:38:30 +0300	[thread overview]
Message-ID: <ZmGDliTx_DKVaU-V@hera> (raw)
In-Reply-To: <98a1de5f01dad1ad55b68ebadcbad1f6357246a6.1716566960.git.jerome.forissier@linaro.org>

Hi Jerome

>  	if (!label)
>  		return CMD_RET_FAILURE;
>
> -	if (!wget_validate_uri(argv[3])) {
> -		printf("ERROR: invalid URI\n");
> -		return CMD_RET_FAILURE;
> +	if (IS_ENABLED(CONFIG_CMD_WGET)) {

efi_boot_add_uri() is only called if CONFIG_EFI_HTTP_BOOT which selectes
WGET

> +		if (!wget_validate_uri(argv[3])) {
> +			printf("ERROR: invalid URI\n");
> +			return CMD_RET_FAILURE;
> +		}
>  	}
>
>  	efi_create_indexed_name(var_name16, var_name16_size, "Boot", id);
> diff --git a/cmd/net-common.c b/cmd/net-common.c
> new file mode 100644
> index 00000000000..b5dfd2c8866
> --- /dev/null
> +++ b/cmd/net-common.c
> @@ -0,0 +1,112 @@

[...]

> +
> +static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
> +			    u32_t rx_content_len, u32_t srv_res, err_t err)
> +{
> +	ulong elapsed;
> +
> +	if (httpc_result != HTTPC_RESULT_OK) {
> +		log_err("\nHTTP client error %d\n", httpc_result);
> +		done = FAILURE;
> +		return;
> +	}
> +
> +	elapsed = get_timer(start_time);
> +        log_info("\n%u bytes transferred in %lu ms (", rx_content_len,
> +                 get_timer(start_time));
> +        print_size(rx_content_len / elapsed * 1000, "/s)\n");
> +
> +	if (env_set_hex("filesize", rx_content_len) ||
> +	    env_set_hex("fileaddr", saved_daddr)) {
> +		log_err("Could not set filesize or fileaddr\n");
> +		done = FAILURE;
> +		return;
> +	}
> +
> +	done = SUCCESS;
> +}
> +
> +int wget_with_dns(ulong dst_addr, char *uri)
> +{
> +	char server_name[SERVER_NAME_SIZE];
> +	httpc_connection_t conn;
> +	httpc_state_t *state;
> +	char *path;
> +	u16 port;
> +
> +	daddr = dst_addr;
> +	saved_daddr = dst_addr;
> +	done = NOT_DONE;
> +	size = 0;
> +	prevsize = 0;
> +
> +	if (parse_url(uri, server_name, &port, &path))
> +		return CMD_RET_USAGE;
> +
> +	memset(&conn, 0, sizeof(conn));
> +	conn.result_fn = httpc_result_cb;
> +	start_time = get_timer(0);
> +	if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb,
> +			       NULL, &state))
> +		return CMD_RET_FAILURE;
> +
> +	while (!done) {
> +		eth_rx();
> +		sys_check_timeouts();
> +		if (ctrlc())
> +			break;
> +	}

You probably don't need the 'done' enum here. There's a state->rx_status,
which if I am reading tlwip correctly should be filled in with the results
of httpc_result_t

> +
> +	if (done == SUCCESS)
> +		return 0;
> +
> +	return -1;
> +}
> +
> +int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
> +{
> +	char *url;
> +	ulong dst_addr;
> +
> +	if (argc < 2 || argc > 3)
> +		return CMD_RET_USAGE;
> +
> +	dst_addr = image_load_addr;
> +
> +	if (!strncmp(argv[1], "0x", 2)) {
> +		if (argc < 3)
> +			return CMD_RET_USAGE;
> +		dst_addr = hextoul(argv[1], NULL);
> +		url = argv[2];
> +	} else {
> +		url = argv[1];
> +	}
> +
> +	if (wget_with_dns(dst_addr, url))
> +		return CMD_RET_FAILURE;
> +
> +	return CMD_RET_SUCCESS;
> +}
> --
> 2.40.1
>

Cheers
/Ilias

  parent reply	other threads:[~2024-06-06  9:38 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-24 16:19 [PATCH v2 00/14] Introduce the lwIP network stack Jerome Forissier
2024-05-24 16:19 ` [PATCH v2 01/14] net: introduce alternative implementation as net-lwip/ Jerome Forissier
2024-05-27 15:34   ` Tom Rini
2024-05-28 11:53     ` Ilias Apalodimas
2024-06-05 17:48     ` Jerome Forissier
2024-05-24 16:19 ` [PATCH v2 02/14] Squashed 'lib/lwip/lwip/' content from commit 0a0452b2c39 Jerome Forissier
2024-05-24 16:19 ` [PATCH v2 03/14] net-lwip: build lwIP Jerome Forissier
2024-05-24 16:19 ` [PATCH v2 04/14] net-lwip: add DHCP support and dhcp commmand Jerome Forissier
2024-05-24 16:19 ` [PATCH v2 05/14] net-lwip: add TFTP support and tftpboot command Jerome Forissier
2024-05-24 16:20 ` [PATCH v2 06/14] net-lwip: add ping command Jerome Forissier
2024-06-06  9:10   ` Ilias Apalodimas
2024-06-06 12:04     ` Jerome Forissier
2024-05-24 16:20 ` [PATCH v2 07/14] net-lwip: add dns command Jerome Forissier
2024-06-06  6:29   ` Ilias Apalodimas
2024-06-06  8:51     ` Maxim Uvarov
2024-06-06 12:19     ` Jerome Forissier
2024-05-24 16:20 ` [PATCH v2 08/14] net-lwip: add wget command Jerome Forissier
2024-05-28 13:39   ` Maxim Uvarov
2024-06-06  9:56     ` Jerome Forissier
2024-06-06 10:16       ` Maxim Uvarov
2024-06-06 12:14         ` Jerome Forissier
2024-06-06  9:38   ` Ilias Apalodimas [this message]
2024-05-24 16:20 ` [PATCH v2 09/14] test: dm: dsa, eth: disable tests when CONFIG_NET_LWIP=y Jerome Forissier
2024-05-24 16:20 ` [PATCH v2 10/14] cmd: bdinfo: enable -e when CONFIG_CMD_NET_LWIP=y Jerome Forissier
2024-05-24 16:20 ` [PATCH v2 11/14] configs: add qemu_arm64_lwip_defconfig Jerome Forissier
2024-05-24 16:20 ` [PATCH v2 12/14] test/py: net: add _lwip variants of dhcp, ping and tftpboot tests Jerome Forissier
2024-05-28  9:41   ` Love Kumar
2024-05-28  9:53   ` Maxim Uvarov
2024-05-30 14:11     ` Jerome Forissier
2024-05-30 14:22       ` Maxim Uvarov
2024-06-06  9:18         ` Jerome Forissier
2024-05-24 16:20 ` [PATCH v2 13/14] MAINTAINERS: net-lwip: add myself as a maintainer Jerome Forissier
2024-05-24 16:20 ` [PATCH v2 14/14] CI: add qemu_arm64_lwip to the test matrix Jerome Forissier
2024-05-27  9:23 ` [PATCH v2 00/14] Introduce the lwIP network stack Francesco Dolcini
2024-05-27  9:36   ` Jerome Forissier
2024-05-27  9:45     ` Martin Husemann
2024-05-27 12:45       ` Jerome Forissier
2024-05-27 12:47         ` Martin Husemann
2024-05-28 11:50           ` Ilias Apalodimas
2024-06-04 23:13   ` Peter Robinson
2024-05-27 15:34 ` Tom Rini
2024-06-06  9:15   ` Jerome Forissier
2024-06-06 14:25     ` Tom Rini

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=ZmGDliTx_DKVaU-V@hera \
    --to=ilias.apalodimas@linaro.org \
    --cc=abdellatif.elkhlifi@arm.com \
    --cc=akashi.tkhro@gmail.com \
    --cc=francis.laniel@amarulasolutions.com \
    --cc=ioana.ciornei@nxp.com \
    --cc=javier.tia@linaro.org \
    --cc=jerome.forissier@linaro.org \
    --cc=kojima.masahisa@socionext.com \
    --cc=michal.simek@amd.com \
    --cc=mkorpershoek@baylibre.com \
    --cc=muvarov@gmail.com \
    --cc=pbrobinson@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=rfried.dev@gmail.com \
    --cc=seanedmond@microsoft.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --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