Skip to contentSkip to conversation

bootstd: make it possible to use tftp for netboot with standardboot

PATCH Superseded Benjamin Hahn 4 participants 5 messages Sep 24, 2025 – Oct 8, 2025

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 bootstd: make it possible to use tftp for netboot with standardboot

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.

---
Changes in v3:
- code styling update
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- fix build error when CONFIG_CMD_TFTPBOOT is not activated
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 boot/bootmeth_script.c           |  6 +++++-
 cmd/net.c                        | 18 ++++++++++++++++++
 doc/develop/bootstd/overview.rst |  4 ++++
 doc/develop/bootstd/script.rst   |  6 ++++--
 include/net-common.h             |  8 ++++++++
 5 files changed, 39 insertions(+), 3 deletions(-)
boot/bootmeth_script.c +5 -1
index 020cb8a7aec0..cd50977cc404 100644
@@ -129,7 +129,11 @@ static int script_read_bootflow_net(struct bootflow *bflow)
 	if (!fname)
 		return log_msg_ret("dhc", -EINVAL);
 
-	ret = dhcp_run(addr, fname, true);
+	if (IS_ENABLED(CONFIG_CMD_TFTPBOOT) && env_get_yesno("ip_dyn") == 0)
+		ret = tftpb_run(addr, fname);
+	else
+		ret = dhcp_run(addr, fname, true);
+
 	if (ret)
 		return log_msg_ret("dhc", ret);
 
cmd/net.c +18 -0
index 886735ea14f6..5992b9c5d734 100644
@@ -49,6 +49,24 @@ int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	return ret;
 }
 
+int tftpb_run(ulong addr, const char *fname)
+{
+	char *tftp_argv[] = {"tftpboot", NULL, (char *)fname, NULL};
+	struct cmd_tbl cmdtp = {};      /* dummy */
+	char file_addr[17] = {0};
+
+	log_debug("addr=%lx, fname=%s\n", addr, fname);
+	sprintf(file_addr, "%lx", addr);
+	tftp_argv[1] = file_addr;
+
+	int result = do_tftpb(&cmdtp, 0, fname ? 3 : 2, tftp_argv);
+
+	if (result)
+		return log_msg_ret("res", -ENOENT);
+
+	return 0;
+}
+
 #if IS_ENABLED(CONFIG_IPV6)
 U_BOOT_CMD(
 	tftpboot,	4,	1,	do_tftpb,
doc/develop/bootstd/overview.rst +4 -0
index 0a2373595755..f94b73ad4d2c 100644
@@ -261,6 +261,10 @@ fdt_addr_r
 fdtoverlay_addr_r (needed if overlays are used)
     Address at which to load the overlay for the FDT, e.g. 0x02000000
 
+ip_dyn
+    Use dynamic IP (dhcp) or static IP (tftp) for loading the bootscript over
+    ethernet. Default is dhcp. e.g. no
+
 kernel_addr_r
     Address at which to load the kernel, e.g. 0x02080000
 
doc/develop/bootstd/script.rst +4 -2
index 47f3684b86b9..3b19c22726ff 100644
@@ -12,8 +12,10 @@ list of prefixes (``{"/", "/boot"}`` by default) and can be adjust with the
 `filename-prefixes` property in the bootstd device.
 
 For a network device, the filename is obtained from the `boot_script_dhcp`
-environment variable and the file is read using tftp. It must be in the
-top-level directory of the tftp server.
+environment variable. By setting the `ip_dyn` environment variable it can be
+decided if dynamic ip (dhcp command) or static ip (tftp command) is used for
+reading the file. By default dhcp is used. The file must be in the top-level
+directory of the tftp server.
 
 In either case (file or network), the bootmeth searches for the file and creates
 a bootflow if found. The bootmeth searches for "boot.scr.uimg" first, then
include/net-common.h +8 -0
index 1112af381a98..a2776fe71fad 100644
@@ -479,6 +479,14 @@ int net_loop(enum proto_t protocol);
  */
 int dhcp_run(ulong addr, const char *fname, bool autoload);
 
+/**
+ * tftpb_run() - Run TFTP on the current ethernet device
+ *
+ * @addr: Address to load the file into
+ * @fname: Filename of file to load (NULL to use the default filename)
+ * @return 0 if OK, -ENOENT if ant file was not found
+ */
+int tftpb_run(ulong addr, const char *fname);
 
 /**
  * do_ping - Run the ping command

---
base-commit: 1a7882de8c859467ce931ed23761db1e391aeaff
change-id: 20250911-ip_dyn_bootstd-dbc38bc3694f

Best regards,

Signature · 1 line
Benjamin Hahn <[email protected]>
Reviewed-by on v3 1/1
#1 lore raw

Hi Benjamin,

Quoted 18 lines · Benjamin Hahn

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.

---
Changes in v3:
- code styling update
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- fix build error when CONFIG_CMD_TFTPBOOT is not activated
- Link to v1: https://lore.kernel.org/r/[email protected]

Quoted 7 lines
---
 boot/bootmeth_script.c           |  6 +++++-
 cmd/net.c                        | 18 ++++++++++++++++++
 doc/develop/bootstd/overview.rst |  4 ++++
 doc/develop/bootstd/script.rst   |  6 ++++--
 include/net-common.h             |  8 ++++++++
 5 files changed, 39 insertions(+), 3 deletions(-)

It would be great if we could have some network tests, with fake packets perhaps, like we have disk-based tests. The disk tests are lightning fast. I've been trying to nudge things towards booting without CONFIG_CMDLINE, but networking is a bit behind for now.

Regards,
Simon

#2 lore raw
In reply to Benjamin Hahn
Quoted 9 lines · Benjamin Hahn

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.

OK, so this fails to build on qemu_arm64_lwip (and a few other lwip targets) because tftpb_run was defined just for the legacy stack and not lwIP too. But, and this is a question for Jerome too, why isn't dhcp_run already in the common network file and instead written again in net/lwip/dhcp.c? And for both of you, can we perhaps have a common function or functions? The lwIP one does handle tftp it looks like. Thanks!

Signature · 1 line
Tom
#3 lore raw

Hi Tom & all,

Quoted 10 lines · Tom Rini
Quoted 8 lines · Benjamin Hahn

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.

Quoted 7 lines
Quoted 1 line

OK, so this fails to build on qemu_arm64_lwip (and a few other lwip targets) because tftpb_run was defined just for the legacy stack and not lwIP too. But, and this is a question for Jerome too, why isn't dhcp_run already in the common network file and instead written again in net/lwip/dhcp.c?

No particular reason. This must have been an oversight when I introduced lwIP.

Quoted 3 lines

And for both of you, can we perhaps have a common function or functions? The lwIP one does handle tftp it looks like. Thanks!

Yeah. IMO, dhcp_run() should be common, but I'm not sure the NET_LWIP one is correct TBH. The comment "Assume DHCP was already performed" is suspicious and I'd rather use the NET one. That is, move dhcp_run() from cmd/net.c into net/net-common.c, discard dhcp_run() from net/lwip/dhcp.c, and see if that works as expected.

Thanks,

Signature · 1 line
Jerome
#4 lore raw
Quoted 28 lines · Jerome Forissier

Hi Tom & all,

Quoted 10 lines · Tom Rini
Quoted 8 lines · Benjamin Hahn

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.

Quoted 7 lines
Quoted 1 line

OK, so this fails to build on qemu_arm64_lwip (and a few other lwip targets) because tftpb_run was defined just for the legacy stack and not lwIP too. But, and this is a question for Jerome too, why isn't dhcp_run already in the common network file and instead written again in net/lwip/dhcp.c?

No particular reason. This must have been an oversight when I introduced lwIP.

Quoted 3 lines

And for both of you, can we perhaps have a common function or functions? The lwIP one does handle tftp it looks like. Thanks!

Quoted 5 lines

Yeah. IMO, dhcp_run() should be common, but I'm not sure the NET_LWIP one is correct TBH. The comment "Assume DHCP was already performed" is suspicious and I'd rather use the NET one. That is, move dhcp_run() from cmd/net.c into net/net-common.c, discard dhcp_run() from net/lwip/dhcp.c, and see if that works as expected.

Sounds like a good plan, thanks!

Signature · 1 line
Tom