diff options
author | Simon Glass <sjg@chromium.org> | 2021-10-14 12:47:56 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-11-11 19:02:11 -0500 |
commit | fd3fa5c3941d4de0736d066f77d0158cf933e207 (patch) | |
tree | 3e8291c7ad555000c4c1852c82351cc6e9736542 /cmd/pxe_utils.h | |
parent | 3d24636e925f89841aac4482c8cc372a2b9d96a6 (diff) |
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>
Diffstat (limited to 'cmd/pxe_utils.h')
-rw-r--r-- | cmd/pxe_utils.h | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/cmd/pxe_utils.h b/cmd/pxe_utils.h index 441beefa2b..cd0d337176 100644 --- a/cmd/pxe_utils.h +++ b/cmd/pxe_utils.h @@ -79,6 +79,23 @@ extern bool is_pxe; extern int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path, char *file_addr); + +/** + * struct pxe_context - context information for PXE parsing + * + * @cmdtp: Pointer to command table to use when calling other commands + */ +struct pxe_context { + struct cmd_tbl *cmdtp; +}; + +/** + * destroy_pxe_menu() - Destroy an allocated pxe structure + * + * Free the memory used by a pxe_menu and its labels + * + * @cfg: Config to destroy, previous returned from parse_pxefile() + */ void destroy_pxe_menu(struct pxe_menu *cfg); /** @@ -88,12 +105,12 @@ void destroy_pxe_menu(struct pxe_menu *cfg); * 'bootfile' was specified in the environment, the path to bootfile will be * prepended to 'file_path' and the resulting path will be used. * - * @cmdtp: Pointer to command-table entry for the initiating command + * @ctx: PXE context * @file_path: Path to file * @file_addr: Address to place file * Returns 1 on success, or < 0 for error */ -int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path, +int get_pxe_file(struct pxe_context *ctx, const char *file_path, ulong file_addr); /** @@ -103,12 +120,12 @@ int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path, * to do the hard work, the location of the 'pxelinux.cfg' folder is generated * from the bootfile path, as described in get_pxe_file(). * - * @cmdtp: Pointer to command-table entry for the initiating command + * @ctx: PXE context * @file: Relative path to file * @pxefile_addr_r: Address to load file * Returns 1 on success or < 0 on error. */ -int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file, +int get_pxelinux_path(struct pxe_context *ctx, const char *file, ulong pxefile_addr_r); /** @@ -123,25 +140,23 @@ int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file, * If this function returns, there weren't any labels that successfully * booted, or the user interrupted the menu selection via ctrl+c. * - * @cmdtp: Pointer to command-table entry for the initiating command + * @ctx: PXE context * @cfg: PXE menu */ -void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg); +void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg); /** * parse_pxefile() - Parsing a pxe file * * This is only used for the top-level file. * - * @cmdtp: Pointer to command-table entry for the initiating command - * @menucfg: Address of PXE file - * + * @ctx: PXE context (provided by the caller) * Returns NULL if there is an error, otherwise, returns a pointer to a * pxe_menu struct populated with the results of parsing the pxe file (and any * files it includes). The resulting pxe_menu struct can be free()'d by using * the destroy_pxe_menu() function. */ -struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, ulong menucfg); +struct pxe_menu *parse_pxefile(struct pxe_context *ctx, ulong menucfg); /** * format_mac_pxe() - Convert a MAC address to PXE format @@ -159,4 +174,12 @@ struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, ulong menucfg); */ int format_mac_pxe(char *outbuf, size_t outbuf_len); +/** + * pxe_setup_ctx() - Setup a new PXE context + * + * @ctx: Context to set up + * @cmdtp: Command table entry which started this action + */ +void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp); + #endif /* __PXE_UTILS_H */ |