From 4d79e884adf6842beb94566bf5249c07a84a5b51 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:08 -0600 Subject: pxe: Return the file size from the getfile() function It is pretty strange that the pxe code uses the 'filesize' environment variable find the size of a file it has just read. Partly this is because it uses the command-line interpreter to parse its request to load the file. As a first step towards unwinding this, return it directly from the getfile() function. This makes the code a bit longer, for now, but will be cleaned up in future patches. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin Reviewed-by: Ramon Fried --- include/pxe_utils.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include/pxe_utils.h') diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 8b50f2e6861..194a5ed8cc7 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -77,7 +77,7 @@ struct pxe_menu { struct pxe_context; typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path, - char *file_addr); + char *file_addr, ulong *filesizep); /** * struct pxe_context - context information for PXE parsing @@ -88,6 +88,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path, * @allow_abs_path: true to allow absolute paths * @bootdir: Directory that files are loaded from ("" if no directory). This is * allocated + * @pxe_file_size: Size of the PXE file */ struct pxe_context { struct cmd_tbl *cmdtp; @@ -98,6 +99,7 @@ struct pxe_context { * @file_path: Path to the file * @file_addr: String containing the hex address to put the file in * memory + * @filesizep: Returns the file size in bytes * Return 0 if OK, -ve on error */ pxe_getfile_func getfile; @@ -105,6 +107,7 @@ struct pxe_context { void *userdata; bool allow_abs_path; char *bootdir; + ulong pxe_file_size; }; /** @@ -225,4 +228,12 @@ void pxe_destroy_ctx(struct pxe_context *ctx); */ int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt); +/** + * pxe_get_file_size() - Read the value of the 'filesize' environment variable + * + * @sizep: Place to put the value + * @return 0 if OK, -ENOENT if no such variable, -EINVAL if format is invalid + */ +int pxe_get_file_size(ulong *sizep); + #endif /* __PXE_UTILS_H */ -- cgit v1.2.3