summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-01-17 20:47:39 +0300
committerTom Rini <trini@konsulko.com>2023-01-24 02:11:40 +0300
commitc8c3fd24cc0dd9512237dc13528e90eb46e704a7 (patch)
tree0e4a7e820d9048c144e950b4faf48f7d209aec5e /cmd
parent843160fa7afc682651c5eea7d8e15f0767b66497 (diff)
downloadu-boot-c8c3fd24cc0dd9512237dc13528e90eb46e704a7.tar.xz
net: Add a function to run dhcp
At present this must be done by executing the command. Also it involves fiddling with the environment to determine the correct autoload behaviour. Ideally it should be possible to run network operations without even having the command line present (CONFIG_CMDLINE). For now, add a function to handle DHCP, so it can be called from a bootdev more easily. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/net.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/cmd/net.c b/cmd/net.c
index dd50930a36..4227321871 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -4,6 +4,8 @@
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*/
+#define LOG_CATEGORY UCLASS_ETH
+
/*
* Boot support
*/
@@ -13,6 +15,7 @@
#include <dm.h>
#include <env.h>
#include <image.h>
+#include <log.h>
#include <net.h>
#include <net6.h>
#include <net/udp.h>
@@ -120,6 +123,38 @@ U_BOOT_CMD(
"boot image via network using DHCP/TFTP protocol",
"[loadAddress] [[hostIPaddr:]bootfilename]"
);
+
+int dhcp_run(ulong addr, const char *fname, bool autoload)
+{
+ char *dhcp_argv[] = {"dhcp", NULL, (char *)fname, NULL};
+ struct cmd_tbl cmdtp = {}; /* dummy */
+ char file_addr[17];
+ int old_autoload;
+ int ret, result;
+
+ log_debug("addr=%lx, fname=%s, autoload=%d\n", addr, fname, autoload);
+ old_autoload = env_get_yesno("autoload");
+ ret = env_set("autoload", autoload ? "y" : "n");
+ if (ret)
+ return log_msg_ret("en1", -EINVAL);
+
+ if (autoload) {
+ sprintf(file_addr, "%lx", addr);
+ dhcp_argv[1] = file_addr;
+ }
+
+ result = do_dhcp(&cmdtp, 0, !autoload ? 1 : fname ? 3 : 2, dhcp_argv);
+
+ ret = env_set("autoload", old_autoload == -1 ? NULL :
+ old_autoload ? "y" : "n");
+ if (ret)
+ return log_msg_ret("en2", -EINVAL);
+
+ if (result)
+ return log_msg_ret("res", -ENOENT);
+
+ return 0;
+}
#endif
#if defined(CONFIG_CMD_NFS)