summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorJerome Forissier <[email protected]>2025-10-09 14:30:14 +0200
committerJerome Forissier <[email protected]>2025-10-22 14:28:33 +0200
commit4b8e78585171787794611205d661b97bc5f4dd83 (patch)
tree4b7b7e6cfbd66ee7c393da745e3600e201d152be /net
parentb24268d151a0c28772785e14703491364becda5b (diff)
net: make dhcp_run() common for NET and NET_LWIP
There are currently two implementations of dhcp_run(): one in cmd/net.c for NET and one in net/lwip/dhcp.c for NET_LWIP. There is no justification for that. Therefore, move the NET version into net/net-common.c to be used by both stacks, and drop the NET_LWIP version which by the way does not look totally correct. Signed-off-by: Jerome Forissier <[email protected]> Suggested-by: Tom Rini <[email protected]> Acked-by: Benjamin Hahn <[email protected]>
Diffstat (limited to 'net')
-rw-r--r--net/lwip/dhcp.c22
-rw-r--r--net/net-common.c35
2 files changed, 35 insertions, 22 deletions
diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c
index 531bf2c6705..b798014ebcb 100644
--- a/net/lwip/dhcp.c
+++ b/net/lwip/dhcp.c
@@ -150,25 +150,3 @@ int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
return CMD_RET_SUCCESS;
}
-
-int dhcp_run(ulong addr, const char *fname, bool autoload)
-{
- char *dhcp_argv[] = {"dhcp", NULL, };
-#ifdef CONFIG_CMD_TFTPBOOT
- char *tftp_argv[] = {"tftpboot", boot_file_name, NULL, };
-#endif
- struct cmd_tbl cmdtp = {}; /* dummy */
-
- if (autoload) {
-#ifdef CONFIG_CMD_TFTPBOOT
- /* Assume DHCP was already performed */
- if (boot_file_name[0])
- return do_tftpb(&cmdtp, 0, 2, tftp_argv);
- return 0;
-#else
- return -EOPNOTSUPP;
-#endif
- }
-
- return do_dhcp(&cmdtp, 0, 1, dhcp_argv);
-}
diff --git a/net/net-common.c b/net/net-common.c
index b064557d524..442b0597558 100644
--- a/net/net-common.c
+++ b/net/net-common.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <dm/uclass.h>
+#include <env.h>
#include <net-common.h>
#include <linux/time.h>
#include <rtc.h>
@@ -48,3 +49,37 @@ void net_sntp_set_rtc(u32 seconds)
tm.tm_year, tm.tm_mon, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
+
+#if defined(CONFIG_CMD_DHCP)
+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