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 <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/include/pxe_utils.h b/include/pxe_utils.h
index 8b50f2e..194a5ed 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -77,7 +77,7 @@
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 @@
* @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 @@
* @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 @@
void *userdata;
bool allow_abs_path;
char *bootdir;
+ ulong pxe_file_size;
};
/**
@@ -225,4 +228,12 @@
*/
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 */