pxe: Use a context pointer
At present the PXE functions pass around a pointer to command-table entry
which is very strange. It is only needed in a few places and it is odd to
pass around a data structure from another module in this way.
For bootmethod we will need to provide some context information when
reading files.
Create a PXE context struct to hold the command-table-entry pointer and
pass that around instead. We can then add more things to the context as
needed.
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>
diff --git a/cmd/pxe.c b/cmd/pxe.c
index 46ac08f..17ce54f 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -43,7 +43,7 @@
*
* Returns 1 on success or < 0 on error.
*/
-static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
+static int pxe_uuid_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
{
char *uuid_str;
@@ -52,7 +52,7 @@
if (!uuid_str)
return -ENOENT;
- return get_pxelinux_path(cmdtp, uuid_str, pxefile_addr_r);
+ return get_pxelinux_path(ctx, uuid_str, pxefile_addr_r);
}
/*
@@ -61,7 +61,7 @@
*
* Returns 1 on success or < 0 on error.
*/
-static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
+static int pxe_mac_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
{
char mac_str[21];
int err;
@@ -71,7 +71,7 @@
if (err < 0)
return err;
- return get_pxelinux_path(cmdtp, mac_str, pxefile_addr_r);
+ return get_pxelinux_path(ctx, mac_str, pxefile_addr_r);
}
/*
@@ -81,7 +81,7 @@
*
* Returns 1 on success or < 0 on error.
*/
-static int pxe_ipaddr_paths(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
+static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long pxefile_addr_r)
{
char ip_addr[9];
int mask_pos, err;
@@ -89,7 +89,7 @@
sprintf(ip_addr, "%08X", ntohl(net_ip.s_addr));
for (mask_pos = 7; mask_pos >= 0; mask_pos--) {
- err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r);
+ err = get_pxelinux_path(ctx, ip_addr, pxefile_addr_r);
if (err > 0)
return err;
@@ -118,8 +118,10 @@
{
char *pxefile_addr_str;
unsigned long pxefile_addr_r;
+ struct pxe_context ctx;
int err, i = 0;
+ pxe_setup_ctx(&ctx, cmdtp);
do_getfile = do_get_tftp;
if (argc != 1)
@@ -139,16 +141,16 @@
* Keep trying paths until we successfully get a file we're looking
* for.
*/
- if (pxe_uuid_path(cmdtp, pxefile_addr_r) > 0 ||
- pxe_mac_path(cmdtp, pxefile_addr_r) > 0 ||
- pxe_ipaddr_paths(cmdtp, pxefile_addr_r) > 0) {
+ if (pxe_uuid_path(&ctx, pxefile_addr_r) > 0 ||
+ pxe_mac_path(&ctx, pxefile_addr_r) > 0 ||
+ pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) {
printf("Config file found\n");
return 0;
}
while (pxe_default_paths[i]) {
- if (get_pxelinux_path(cmdtp, pxe_default_paths[i],
+ if (get_pxelinux_path(&ctx, pxe_default_paths[i],
pxefile_addr_r) > 0) {
printf("Config file found\n");
return 0;
@@ -172,7 +174,9 @@
unsigned long pxefile_addr_r;
struct pxe_menu *cfg;
char *pxefile_addr_str;
+ struct pxe_context ctx;
+ pxe_setup_ctx(&ctx, cmdtp);
do_getfile = do_get_tftp;
if (argc == 1) {
@@ -191,14 +195,14 @@
return 1;
}
- cfg = parse_pxefile(cmdtp, pxefile_addr_r);
+ cfg = parse_pxefile(&ctx, pxefile_addr_r);
if (!cfg) {
printf("Error parsing config file\n");
return 1;
}
- handle_pxe_menu(cmdtp, cfg);
+ handle_pxe_menu(&ctx, cfg);
destroy_pxe_menu(cfg);