[PATCH v2 08/14] net-lwip: add wget command

Ilias Apalodimas ilias.apalodimas at linaro.org
Thu Jun 6 11:38:30 CEST 2024


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


More information about the U-Boot mailing list