]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bootstd: make it possible to use tftp for netboot with standardboot
authorBenjamin Hahn <B.Hahn@phytec.de>
Tue, 21 Oct 2025 14:34:17 +0000 (16:34 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 24 Oct 2025 19:47:50 +0000 (13:47 -0600)
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.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Benjamin Hahn <B.Hahn@phytec.de>
boot/bootmeth_script.c
doc/develop/bootstd/overview.rst
doc/develop/bootstd/script.rst
include/net-common.h
net/net-common.c

index 020cb8a7aec0aad131e32c32d7acd332a4663015..cd50977cc40439f32694c88b2b13a79c948610b5 100644 (file)
@@ -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);
 
index e36cde4d3604f3ee2ec00b16527973a19fa70fea..abb616adc77eb6690424ba5d5fab43588ed97cb1 100644 (file)
@@ -262,6 +262,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
 
index 47f3684b86b9b1ee7a6e8f5a1af743a3cc262e25..3b19c22726ff29dca1ccc7de147b876e630ea194 100644 (file)
@@ -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
index 78d98e5bba07038a248bacbe1436ad3c94a90536..f5cff3e7c0c5d25f154e7730fad52cf03f71b875 100644 (file)
@@ -490,6 +490,15 @@ int dhcp_run(ulong addr, const char *fname, bool autoload);
  */
 int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 
+/**
+ * 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
  *
index 442b05975581b911f0db2ab36594364101783c78..c68e19fc03e64a740d05b998ef0efb9fce311543 100644 (file)
@@ -83,3 +83,24 @@ int dhcp_run(ulong addr, const char *fname, bool autoload)
        return 0;
 }
 #endif
+
+#if defined(CONFIG_CMD_TFTPBOOT)
+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;
+}
+
+#endif