[PATCH] net: lwip: wget: rework the '#' printing
Jerome Forissier
jerome.forissier at arm.com
Thu Jan 29 11:18:57 CET 2026
Hi Marek,
On 29/01/2026 01:23, Marek Vasut wrote:
> Currently, the LWIP wget command prints excessive amount of progress
> indicator '#' for very long file downloads,
So true! ;-)
> limit this to one line
> that scales according to transfer size.
>
> The HTTP server does report the size of the entire file in protocol
> headers, which are received before the actual data transfer. Cache
> this information and use it to adaptively print progress indicator
> '#' until it fills one entire line worth of '#', which indicates the
> transfer has completed. This way, long transfers don't print pages of
> '#', but every transfer will print exactly one line worth of '#'. The
> algorithm for '#' printing is the same as TFTP tsize one.
That's not one line strictly speaking, it is 50 characters.
Like I suggested re. your TFTP patch, perhaps a percent-based format
would be better?
0%....10%....20%... etc.
In any case:
Acked-by: Jerome Forissier <jerome.forissier at rm.com>
Thanks,
--
Jerome
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
> ---
> Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> Cc: Jerome Forissier <jerome at forissier.org>
> Cc: Joe Hershberger <joe.hershberger at ni.com>
> Cc: Ramon Fried <rfried.dev at gmail.com>
> Cc: Sughosh Ganu <sughosh.ganu at linaro.org>
> Cc: Tim Harvey <tharvey at gateworks.com>
> Cc: Tom Rini <trini at konsulko.com>
> Cc: u-boot at lists.denx.de
> ---
> net/lwip/wget.c | 27 +++++++++++++++++++++++----
> 1 file changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/net/lwip/wget.c b/net/lwip/wget.c
> index 55bd2b72e26..008f3b395e7 100644
> --- a/net/lwip/wget.c
> +++ b/net/lwip/wget.c
> @@ -37,6 +37,8 @@ struct wget_ctx {
> ulong size;
> ulong prevsize;
> ulong start_time;
> + ulong content_len;
> + ulong hash_count;
> enum done_state done;
> };
>
> @@ -152,6 +154,7 @@ static int store_block(struct wget_ctx *ctx, void *src, u16_t len)
> {
> ulong store_addr = ctx->daddr;
> uchar *ptr;
> + ulong pos;
>
> /* Avoid overflow */
> if (wget_info->buffer_size && wget_info->buffer_size < ctx->size + len)
> @@ -174,10 +177,12 @@ static int store_block(struct wget_ctx *ctx, void *src, u16_t len)
>
> ctx->daddr += len;
> ctx->size += len;
> - if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) {
> - if (!wget_info->silent)
> - printf("#");
> - ctx->prevsize = ctx->size;
> +
> + pos = clamp(ctx->size, 0UL, ctx->content_len);
> +
> + while (ctx->hash_count < pos * 50 / ctx->content_len) {
> + putc('#');
> + ctx->hash_count++;
> }
>
> return 0;
> @@ -234,6 +239,14 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
> return;
> }
>
> + /* Print hash marks for the last packet received */
> + while (ctx->hash_count < 49) {
> + putc('#');
> + ctx->hash_count++;
> + }
> + puts(" ");
> + print_size(ctx->content_len, "");
> +
> elapsed = get_timer(ctx->start_time);
> if (!elapsed)
> elapsed = 1;
> @@ -263,11 +276,15 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
> static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct pbuf *hdr,
> u16_t hdr_len, u32_t content_len)
> {
> + struct wget_ctx *ctx = arg;
> +
> wget_lwip_fill_info(hdr, hdr_len, content_len);
>
> if (wget_info->check_buffer_size && (ulong)content_len > wget_info->buffer_size)
> return ERR_BUF;
>
> + ctx->content_len = content_len;
> +
> return ERR_OK;
> }
>
> @@ -294,6 +311,8 @@ int wget_do_request(ulong dst_addr, char *uri)
> ctx.size = 0;
> ctx.prevsize = 0;
> ctx.start_time = 0;
> + ctx.content_len = 0;
> + ctx.hash_count = 0;
>
> if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https))
> return CMD_RET_USAGE;
More information about the U-Boot
mailing list