[PATCH v2] bootstd: make it possible to use tftp for netboot with standardboot

Tom Rini trini at konsulko.com
Tue Sep 23 18:55:46 CEST 2025


On Tue, Sep 23, 2025 at 03:43:09PM +0200, Benjamin Hahn wrote:

> Add the option to load the bootscript with the tftp command (static IP)
> instead of the dhcp command (dynamic IP). For this a new function
> tftpb_run similar to dhcp_run, is needed. The selection of which command
> to use can be done with the ip_dyn environment variable, which can be
> set to yes or no. The ip_dyn variable was chosen as it is already in use
> on the imx platforms.
> Also edit the bootstd doc.
> 
> Signed-off-by: Benjamin Hahn <B.Hahn at phytec.de>
> ---
> Changes in v2:
> - fix build error when CONFIG_CMD_TFTPBOOT is not activated
> - Link to v1: https://lore.kernel.org/r/20250911-ip_dyn_bootstd-v1-1-74f74507cc18@phytec.de
> ---
>  boot/bootmeth_script.c           |  8 ++++++++
>  cmd/net.c                        | 18 ++++++++++++++++++
>  doc/develop/bootstd/overview.rst |  4 ++++
>  doc/develop/bootstd/script.rst   |  6 ++++--
>  include/net-common.h             |  8 ++++++++
>  5 files changed, 42 insertions(+), 2 deletions(-)
> 
> diff --git a/boot/bootmeth_script.c b/boot/bootmeth_script.c
> index 020cb8a7aec0..fd15b1ac1a20 100644
> --- a/boot/bootmeth_script.c
> +++ b/boot/bootmeth_script.c
> @@ -129,7 +129,15 @@ static int script_read_bootflow_net(struct bootflow *bflow)
>  	if (!fname)
>  		return log_msg_ret("dhc", -EINVAL);
>  
> +#ifdef CONFIG_CMD_TFTPBOOT
> +	if (env_get_yesno("ip_dyn") == 0)
> +		ret = tftpb_run(addr, fname);
> +	else
> +		ret = dhcp_run(addr, fname, true);
> +#else
>  	ret = dhcp_run(addr, fname, true);
> +#endif /* CONFIG_CMD_TFTPBOOT */

This is a case where IS_ENABLED(CONFIG..) is helpful as we can do:
if (IS_ENABLED(CONFIG_CMD_TFTPBOOT) && env_get_yesno("ip_dyn") == 0)
	ret = tftpb_run(addr, fname);
else
	ret = dhcp_run(addr, fname, true);

And when CONFIG_CMD_TFTPBOOT isn't set the compiler optimizes this to
just the dhcp_run call.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20250923/833d3bfb/attachment.sig>


More information about the U-Boot mailing list