boot: Update pxe_getfile_func() to support reservation

In some cases we don't have a particular address to read into so would
like one reserved. Adjust this function to support that.

For now, sysbot_read_file() fails if the address is not provided. This
will be resolved in a later patch.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-08-07 04:30:23 -06:00
parent c545f0762b
commit 5ead77edd5
7 changed files with 29 additions and 35 deletions

View File

@@ -36,19 +36,16 @@ static int extlinux_get_state_desc(struct udevice *dev, char *buf, int maxsize)
}
static int extlinux_getfile(struct pxe_context *ctx, const char *file_path,
char *file_addr, enum bootflow_img_t type,
ulong *addrp, ulong align, enum bootflow_img_t type,
ulong *sizep)
{
struct extlinux_info *info = ctx->userdata;
ulong addr;
int ret;
addr = simple_strtoul(file_addr, NULL, 16);
/* Allow up to 1GB */
*sizep = 1 << 30;
ret = bootmeth_read_file(info->dev, info->bflow, file_path, &addr, 0,
type, sizep);
ret = bootmeth_read_file(info->dev, info->bflow, file_path, addrp,
align, type, sizep);
if (ret)
return log_msg_ret("read", ret);

View File

@@ -23,19 +23,16 @@
#include <pxe_utils.h>
static int extlinux_pxe_getfile(struct pxe_context *ctx, const char *file_path,
char *file_addr, enum bootflow_img_t type,
ulong *sizep)
ulong *addrp, ulong align,
enum bootflow_img_t type, ulong *sizep)
{
struct extlinux_info *info = ctx->userdata;
ulong addr;
int ret;
addr = simple_strtoul(file_addr, NULL, 16);
/* Allow up to 1GB */
*sizep = 1 << 30;
ret = bootmeth_read_file(info->dev, info->bflow, file_path, &addr, 0,
type, sizep);
ret = bootmeth_read_file(info->dev, info->bflow, file_path, addrp,
align, type, sizep);
if (ret)
return log_msg_ret("read", ret);

View File

@@ -94,7 +94,7 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)
*
* @ctx: PXE context
* @file_path: File path to read (relative to the PXE file)
* @file_addr: Address to load file to
* @addr: Address to load file to
* @filesizep: If not NULL, returns the file size in bytes
* Returns 1 for success, or < 0 on error
*/
@@ -104,7 +104,6 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
{
size_t path_len;
char relfile[MAX_TFTP_PATH_LEN + 1];
char addr_buf[18];
ulong size;
int ret;
@@ -125,9 +124,7 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path,
printf("Retrieving file: %s\n", relfile);
sprintf(addr_buf, "%lx", file_addr);
ret = ctx->getfile(ctx, relfile, addr_buf, type, &size);
ret = ctx->getfile(ctx, relfile, &file_addr, 0, type, &size);
if (ret < 0)
return log_msg_ret("get", ret);
if (filesizep)

View File

@@ -43,19 +43,16 @@ static enum vbe_pick_t find_pick(const char *name)
}
static int vbe_abrec_getfile(struct pxe_context *ctx, const char *file_path,
char *file_addr, enum bootflow_img_t type,
ulong *sizep)
ulong *addrp, ulong align,
enum bootflow_img_t type, ulong *sizep)
{
struct extlinux_info *info = ctx->userdata;
ulong addr;
int ret;
addr = simple_strtoul(file_addr, NULL, 16);
/* Allow up to 1GB */
*sizep = 1 << 30;
ret = bootmeth_read_file(info->dev, info->bflow, file_path, &addr, 0,
type, sizep);
ret = bootmeth_read_file(info->dev, info->bflow, file_path, addrp,
align, type, sizep);
if (ret)
return log_msg_ret("read", ret);

View File

@@ -26,13 +26,16 @@ const char *pxe_default_paths[] = {
};
static int do_get_tftp(struct pxe_context *ctx, const char *file_path,
char *file_addr, enum bootflow_img_t type, ulong *sizep)
ulong *addrp, ulong align, enum bootflow_img_t type,
ulong *sizep)
{
int ret;
if (IS_ENABLED(CONFIG_NET_LWIP))
return -ENOTSUPP;
ret = netboot_run(TFTPGET, hextoul(file_addr, NULL), file_path, 0,
if (!*addrp)
return -ENOTSUPP;
ret = netboot_run(TFTPGET, *addrp, file_path, 0,
ctx->use_ipv6);
if (ret)
return log_msg_ret("tfp", ret);

View File

@@ -23,19 +23,20 @@ struct sysboot_info {
};
static int sysboot_read_file(struct pxe_context *ctx, const char *file_path,
char *file_addr, enum bootflow_img_t type,
ulong *sizep)
ulong *addrp, ulong align,
enum bootflow_img_t type, ulong *sizep)
{
struct sysboot_info *info = ctx->userdata;
loff_t len_read;
ulong addr;
int ret;
addr = simple_strtoul(file_addr, NULL, 16);
if (!*addrp)
return -ENOTSUPP;
ret = fs_set_blk_dev(info->ifname, info->dev_part_str, info->fstype);
if (ret)
return ret;
ret = fs_legacy_read(file_path, addr, 0, 0, &len_read);
ret = fs_legacy_read(file_path, *addrp, 0, 0, &len_read);
if (ret)
return ret;
*sizep = len_read;

View File

@@ -97,13 +97,15 @@ struct pxe_context;
*
* @ctx: PXE context
* @file_path: Full path to filename to read
* @file_addr: String containing the to which to read the file
* @addrp: On entry, address to load file or 0 to reserve an address with lmb;
* on exit, address to which the file was loaded
* @align: Reservation alignment, if using lmb
* @type: File type
* @fileszeip: Returns file size
*/
typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
char *file_addr, enum bootflow_img_t type,
ulong *filesizep);
ulong *addrp, ulong align,
enum bootflow_img_t type, ulong *filesizep);
/**
* struct pxe_context - context information for PXE parsing