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>
This commit is contained in:
Simon Glass
2025-03-05 17:25:23 -07:00
committed by Tom Rini
parent f278f0cb49
commit 0f094b8b14
3 changed files with 75 additions and 39 deletions

View File

@@ -382,44 +382,6 @@ static int parse_args(enum proto_t proto, int argc, char *const argv[],
return 0;
}
static 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;
}
static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
char *const argv[])
{
@@ -475,7 +437,7 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
}
size = netboot_run_(proto, addr, fname, save_size, fname_explicit,
use_ip6);
IS_ENABLED(CONFIG_IPV6) && use_ip6);
if (size < 0)
return CMD_RET_FAILURE;