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>
This commit is contained in:
Simon Glass 2021-10-14 12:48:04 -06:00 committed by Tom Rini
parent 9e62e7ca54
commit 12df842ee3
4 changed files with 79 additions and 33 deletions

View file

@ -86,6 +86,8 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
* @getfile: Function called by PXE to read a file
* @userdata: Data the caller requires for @getfile
* @allow_abs_path: true to allow absolute paths
* @bootdir: Directory that files are loaded from ("" if no directory). This is
* allocated
*/
struct pxe_context {
struct cmd_tbl *cmdtp;
@ -102,6 +104,7 @@ struct pxe_context {
void *userdata;
bool allow_abs_path;
char *bootdir;
};
/**
@ -197,10 +200,20 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
* @getfile: Function to call to read a file
* @userdata: Data the caller requires for @getfile - stored in ctx->userdata
* @allow_abs_path: true to allow absolute paths
* @bootfile: Bootfile whose directory loaded files are relative to, NULL if
* none
* @return 0 if OK, -ENOMEM if out of memory
*/
void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
pxe_getfile_func getfile, void *userdata,
bool allow_abs_path);
int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
pxe_getfile_func getfile, void *userdata,
bool allow_abs_path, const char *bootfile);
/**
* pxe_destroy_ctx() - Destroy a PXE context
*
* @ctx: Context to destroy
*/
void pxe_destroy_ctx(struct pxe_context *ctx);
/**
* pxe_process() - Process a PXE file through to boot