net: Refactor part of netboot_common() into a function
Move the core code for starting an netboot operation into a separate function, so that we can (with additional work) move towards calling it from outside the file. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
62
cmd/net.c
62
cmd/net.c
@@ -382,11 +382,50 @@ static int parse_args(enum proto_t proto, int argc, char *const argv[],
|
|||||||
return 0;
|
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,
|
static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
|
||||||
char *const argv[])
|
char *const argv[])
|
||||||
{
|
{
|
||||||
|
ulong addr, save_size;
|
||||||
|
bool fname_explicit;
|
||||||
const char *fname;
|
const char *fname;
|
||||||
ulong addr;
|
|
||||||
char *s;
|
char *s;
|
||||||
int rcode = 0;
|
int rcode = 0;
|
||||||
int size;
|
int size;
|
||||||
@@ -410,22 +449,17 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_args(proto, argc, argv, &fname, &addr, &image_save_size)) {
|
if (parse_args(proto, argc, argv, &fname, &addr, &save_size)) {
|
||||||
bootstage_error(BOOTSTAGE_ID_NET_START);
|
bootstage_error(BOOTSTAGE_ID_NET_START);
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
}
|
}
|
||||||
if (IS_ENABLED(CONFIG_CMD_TFTPPUT) && proto == TFTPPUT)
|
|
||||||
image_save_addr = addr;
|
|
||||||
else
|
|
||||||
image_load_addr = addr;
|
|
||||||
|
|
||||||
if (fname) {
|
if (fname) {
|
||||||
net_boot_file_name_explicit = true;
|
fname_explicit = true;
|
||||||
} else {
|
} else {
|
||||||
net_boot_file_name_explicit = false;
|
fname_explicit = false;
|
||||||
fname = env_get("bootfile");
|
fname = env_get("bootfile");
|
||||||
}
|
}
|
||||||
copy_filename(net_boot_file_name, fname, sizeof(net_boot_file_name));
|
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_IPV6) && !use_ip6) {
|
if (IS_ENABLED(CONFIG_IPV6) && !use_ip6) {
|
||||||
char *s, *e;
|
char *s, *e;
|
||||||
@@ -440,14 +474,10 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstage_mark(BOOTSTAGE_ID_NET_START);
|
size = netboot_run_(proto, addr, fname, save_size, fname_explicit,
|
||||||
|
use_ip6);
|
||||||
size = net_loop(proto);
|
if (size < 0)
|
||||||
if (size < 0) {
|
|
||||||
bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
|
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
}
|
|
||||||
bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK);
|
|
||||||
|
|
||||||
/* net_loop ok, update environment */
|
/* net_loop ok, update environment */
|
||||||
netboot_update_env();
|
netboot_update_env();
|
||||||
|
Reference in New Issue
Block a user