summaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2025-03-05 17:25:23 -0700
committerTom Rini <trini@konsulko.com>2025-03-18 13:12:16 -0600
commit0f094b8b146679c3980cd2febde4e902bbc4405d (patch)
treec8ddca55cbabb720c0ef749a2432589e16fd9301 /net/net.c
parentf278f0cb4996398720328ce33e057678f6ea4109 (diff)
net: Provide a function to run network operations
Add a new netboot_run() function which can be used for simple network operations, such as loading a file. Put the implementation in an internal function, used by the existing code. Place this function into the net/ code, so that it does not need the command line to be available. Document which network operations are supported, i.e. a limited subset, for now. For the one board which uses lwip, it is not quite clear how to avoid using the cmdline interface. This will need some discussion. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/net/net.c b/net/net.c
index 1828f1cca36..ef97377cdec 100644
--- a/net/net.c
+++ b/net/net.c
@@ -775,6 +775,50 @@ done:
return ret;
}
+int netboot_run_(enum proto_t proto, ulong addr, const char *fname, ulong size,
+ bool fname_explicit, bool ipv6)
+{
+ int ret;
+
+ bootstage_mark(BOOTSTAGE_ID_NET_START);
+
+ /*
+ * For now we use the global variables as that is the only way to
+ * control the network stack. At some point, perhaps, the state could be
+ * in a struct
+ */
+ if (IS_ENABLED(CONFIG_CMD_TFTPPUT) && proto == TFTPPUT)
+ image_save_addr = addr;
+ else
+ image_load_addr = addr;
+
+ net_boot_file_name_explicit = fname_explicit;
+ copy_filename(net_boot_file_name, fname, sizeof(net_boot_file_name));
+ if (IS_ENABLED(CONFIG_IPV6))
+ use_ip6 = ipv6;
+ if (IS_ENABLED(CONFIG_CMD_TFTPPUT) && proto == TFTPPUT) {
+ image_save_addr = addr;
+ image_save_size = size;
+ } else {
+ image_load_addr = addr;
+ }
+
+ ret = net_loop(proto);
+ if (ret < 0) {
+ bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
+ return ret;
+ }
+ bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK);
+
+ return 0;
+}
+
+int netboot_run(enum proto_t proto, ulong addr, const char *fname, ulong size,
+ bool ipv6)
+{
+ return netboot_run_(proto, addr, fname, size, true, ipv6);
+}
+
/**********************************************************************/
static void start_again_timeout_handler(void)