aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-10-14 12:48:04 -0600
committerTom Rini <trini@konsulko.com>2021-11-11 19:02:28 -0500
commit12df842ee324a7e188a643bfee6fe08f28127b26 (patch)
treecb34fdc5fbc3f5941141fcc3a8e830369aa35e60 /cmd
parent9e62e7ca543ea94a46f30053262f67202e2435f4 (diff)
downloadu-boot-12df842ee324a7e188a643bfee6fe08f28127b26.zip
u-boot-12df842ee324a7e188a643bfee6fe08f28127b26.tar.gz
u-boot-12df842ee324a7e188a643bfee6fe08f28127b26.tar.bz2
pxe: Clean up the use of bootfile
The 'bootfile' environment variable is read in the bowels of pxe_util to provide a directory to which all loaded files are relative. This is not obvious from the API to PXE and it is strange to make the caller set an environment variable rather than pass this as a parameter. The code is also convoluted, which this feature implemented by get_bootfile_path(). Update the API to improve this. Unfortunately this means that pxe_setup_ctx() can fail, so add error checking. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Artem Lapkin <email2tema@gmail.com> Tested-by: Artem Lapkin <email2tema@gmail.com> Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/pxe.c18
-rw-r--r--cmd/sysboot.c15
2 files changed, 25 insertions, 8 deletions
diff --git a/cmd/pxe.c b/cmd/pxe.c
index 4fa51d2..e319db5 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -121,8 +121,6 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
struct pxe_context ctx;
int err, i = 0;
- pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false);
-
if (argc != 1)
return CMD_RET_USAGE;
@@ -136,6 +134,11 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
if (err < 0)
return 1;
+ if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false,
+ env_get("bootfile"))) {
+ printf("Out of memory\n");
+ return CMD_RET_FAILURE;
+ }
/*
* Keep trying paths until we successfully get a file we're looking
* for.
@@ -144,6 +147,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
pxe_mac_path(&ctx, pxefile_addr_r) > 0 ||
pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) {
printf("Config file found\n");
+ pxe_destroy_ctx(&ctx);
return 0;
}
@@ -152,12 +156,14 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
if (get_pxelinux_path(&ctx, pxe_default_paths[i],
pxefile_addr_r) > 0) {
printf("Config file found\n");
+ pxe_destroy_ctx(&ctx);
return 0;
}
i++;
}
printf("Config file not found\n");
+ pxe_destroy_ctx(&ctx);
return 1;
}
@@ -175,8 +181,6 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
struct pxe_context ctx;
int ret;
- pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false);
-
if (argc == 1) {
pxefile_addr_str = from_env("pxefile_addr_r");
if (!pxefile_addr_str)
@@ -193,7 +197,13 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
return 1;
}
+ if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false,
+ env_get("bootfile"))) {
+ printf("Out of memory\n");
+ return CMD_RET_FAILURE;
+ }
ret = pxe_process(&ctx, pxefile_addr_r, false);
+ pxe_destroy_ctx(&ctx);
if (ret)
return CMD_RET_FAILURE;
diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index 7ee14df..c45fed7 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -59,6 +59,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
unsigned long pxefile_addr_r;
+ pxe_getfile_func getfile;
struct pxe_context ctx;
char *pxefile_addr_str;
char *filename;
@@ -89,13 +90,12 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
env_set("bootfile", filename);
}
- pxe_setup_ctx(&ctx, cmdtp, NULL, NULL, true);
if (strstr(argv[3], "ext2")) {
- ctx.getfile = do_get_ext2;
+ getfile = do_get_ext2;
} else if (strstr(argv[3], "fat")) {
- ctx.getfile = do_get_fat;
+ getfile = do_get_fat;
} else if (strstr(argv[3], "any")) {
- ctx.getfile = do_get_any;
+ getfile = do_get_any;
} else {
printf("Invalid filesystem: %s\n", argv[3]);
return 1;
@@ -108,12 +108,19 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
return 1;
}
+ if (pxe_setup_ctx(&ctx, cmdtp, getfile, NULL, true, filename)) {
+ printf("Out of memory\n");
+ return CMD_RET_FAILURE;
+ }
+
if (get_pxe_file(&ctx, filename, pxefile_addr_r) < 0) {
printf("Error reading config file\n");
+ pxe_destroy_ctx(&ctx);
return 1;
}
ret = pxe_process(&ctx, pxefile_addr_r, prompt);
+ pxe_destroy_ctx(&ctx);
if (ret)
return CMD_RET_FAILURE;