[PATCH v2 28/41] pxe: Record the bootflow in the PXE context

Simon Glass sjg at chromium.org
Wed Dec 4 00:45:46 CET 2024


At present the only option with PXE is to boot it and see what happens.

Provide a bootflow, when available, so that PXE will eventually be able
to add some useful information to it.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 boot/bootmeth_extlinux.c | 2 +-
 boot/bootmeth_pxe.c      | 2 +-
 boot/pxe_utils.c         | 3 ++-
 cmd/pxe.c                | 4 ++--
 cmd/sysboot.c            | 2 +-
 include/pxe_utils.h      | 5 ++++-
 6 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c
index 4adcaf5654a..569f9d760bf 100644
--- a/boot/bootmeth_extlinux.c
+++ b/boot/bootmeth_extlinux.c
@@ -188,7 +188,7 @@ static int extlinux_boot(struct udevice *dev, struct bootflow *bflow)
 	plat = dev_get_plat(dev);
 
 	ret = pxe_setup_ctx(&ctx, extlinux_getfile, &info, true, bflow->fname,
-			    false, plat->use_fallback);
+			    false, plat->use_fallback, bflow);
 	if (ret)
 		return log_msg_ret("ctx", -EINVAL);
 
diff --git a/boot/bootmeth_pxe.c b/boot/bootmeth_pxe.c
index 59ebf1be83a..f2b9ffaae89 100644
--- a/boot/bootmeth_pxe.c
+++ b/boot/bootmeth_pxe.c
@@ -148,7 +148,7 @@ static int extlinux_pxe_boot(struct udevice *dev, struct bootflow *bflow)
 	info.dev = dev;
 	info.bflow = bflow;
 	ret = pxe_setup_ctx(ctx, extlinux_pxe_getfile, &info, false,
-			    bflow->subdir, false, false);
+			    bflow->subdir, false, false, bflow);
 	if (ret)
 		return log_msg_ret("ctx", -EINVAL);
 
diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index b4aa284b1ee..f7bbc1527af 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -1632,7 +1632,7 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
 
 int pxe_setup_ctx(struct pxe_context *ctx, pxe_getfile_func getfile,
 		  void *userdata, bool allow_abs_path, const char *bootfile,
-		  bool use_ipv6, bool use_fallback)
+		  bool use_ipv6, bool use_fallback, struct bootflow *bflow)
 {
 	const char *last_slash;
 	size_t path_len = 0;
@@ -1643,6 +1643,7 @@ int pxe_setup_ctx(struct pxe_context *ctx, pxe_getfile_func getfile,
 	ctx->allow_abs_path = allow_abs_path;
 	ctx->use_ipv6 = use_ipv6;
 	ctx->use_fallback = use_fallback;
+	ctx->bflow = bflow;
 
 	/* figure out the boot directory, if there is one */
 	if (bootfile && strlen(bootfile) >= MAX_TFTP_PATH_LEN)
diff --git a/cmd/pxe.c b/cmd/pxe.c
index 530d5d9c35b..7728949d14b 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -130,7 +130,7 @@ int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep, bool use_ipv6)
 	int i;
 
 	if (pxe_setup_ctx(&ctx, do_get_tftp, NULL, false, env_get("bootfile"),
-			  use_ipv6, false))
+			  use_ipv6, false, NULL))
 		return -ENOMEM;
 
 	if (IS_ENABLED(CONFIG_BOOTP_PXE_DHCP_OPTION) &&
@@ -280,7 +280,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	}
 
 	if (pxe_setup_ctx(&ctx, do_get_tftp, NULL, false, env_get("bootfile"),
-			  use_ipv6, false)) {
+			  use_ipv6, false, NULL)) {
 		printf("Out of memory\n");
 		return CMD_RET_FAILURE;
 	}
diff --git a/cmd/sysboot.c b/cmd/sysboot.c
index 6e899f381ec..384d5e15e3d 100644
--- a/cmd/sysboot.c
+++ b/cmd/sysboot.c
@@ -106,7 +106,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
 	}
 
 	if (pxe_setup_ctx(&ctx, sysboot_read_file, &info, true, filename, false,
-			  false)) {
+			  false, NULL)) {
 		printf("Out of memory\n");
 		return CMD_RET_FAILURE;
 	}
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index fb057442d5d..e8e03430a81 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -109,6 +109,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
  * @use_ipv6: TRUE : use IPv6 addressing, FALSE : use IPv4 addressing
  * @use_fallback: TRUE : use "fallback" option as default, FALSE : use
  *	"default" option as default
+ * @bflow: Bootflow being booted, or NULL if none
  */
 struct pxe_context {
 	/**
@@ -129,6 +130,7 @@ struct pxe_context {
 	ulong pxe_file_size;
 	bool use_ipv6;
 	bool use_fallback;
+	struct bootflow *bflow;
 };
 
 /**
@@ -231,12 +233,13 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len);
  *                       other choice be selected
  *                FALSE : Use "default" option should no other choice be
  *                        selected
+ * @bflow: Bootflow to update, NULL if none
  * Return: 0 if OK, -ENOMEM if out of memory, -E2BIG if bootfile is larger than
  *	MAX_TFTP_PATH_LEN bytes
  */
 int pxe_setup_ctx(struct pxe_context *ctx, pxe_getfile_func getfile,
 		  void *userdata, bool allow_abs_path, const char *bootfile,
-		  bool use_ipv6, bool use_fallback);
+		  bool use_ipv6, bool use_fallback, struct bootflow *bflow);
 
 /**
  * pxe_destroy_ctx() - Destroy a PXE context
-- 
2.34.1



More information about the U-Boot mailing list