Skip to contentSkip to conversation

bootstd: efi: Handle prior-stage FDT in network path

PATCH Superseded Simon Glass 2 participants 2 messages Mar 22 – Mar 25

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bootstd: efi: Handle prior-stage FDT in network path

When CONFIG_OF_HAS_PRIOR_STAGE is enabled and fdtfile is not set, efi_get_distro_fdt_name() returns -EALREADY to indicate the prior-stage FDT should be used. The block-device EFI path handles this by setting BOOTFLOWF_USE_PRIOR_FDT, but the network path treats it as an error, causing the bootflow to stay in 'base' state with a -EALREADY error.

This also means fdt_addr_r is required even when no FDT download is needed, giving a spurious -EINVAL error.

Fix this by calling efi_get_distro_fdt_name() before checking fdt_addr_r, and handling -EALREADY by setting BOOTFLOWF_USE_PRIOR_FDT to skip the FDT download, matching the block-device behaviour.

THere is no test for this at present, since sandbox does not enable CONFIG_OF_HAS_PRIOR_STAGE and lacks infra for network-based EFI boot.

---

 boot/bootmeth_efi.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
boot/bootmeth_efi.c +19 -17
index f592fec07f6..cbb392e1636 100644
@@ -269,27 +269,29 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
 		return log_msg_ret("fi0", -ENOMEM);
 
 	/* read the DT file also */
-	fdt_addr_str = env_get("fdt_addr_r");
-	if (!fdt_addr_str)
-		return log_msg_ret("fdt", -EINVAL);
-	fdt_addr = hextoul(fdt_addr_str, NULL);
-	sprintf(file_addr, "%lx", fdt_addr);
-
-	/* We only allow the first prefix with PXE */
 	ret = efi_get_distro_fdt_name(fname, sizeof(fname), 0);
-	if (ret)
+	if (ret == -EALREADY) {
+		bflow->flags |= BOOTFLOWF_USE_PRIOR_FDT;
+	} else if (ret) {
 		return log_msg_ret("nam", ret);
+	} else {
+		fdt_addr_str = env_get("fdt_addr_r");
+		if (!fdt_addr_str)
+			return log_msg_ret("fdt", -EINVAL);
+		fdt_addr = hextoul(fdt_addr_str, NULL);
+		sprintf(file_addr, "%lx", fdt_addr);
 
-	bflow->fdt_fname = strdup(fname);
-	if (!bflow->fdt_fname)
-		return log_msg_ret("fil", -ENOMEM);
+		bflow->fdt_fname = strdup(fname);
+		if (!bflow->fdt_fname)
+			return log_msg_ret("fil", -ENOMEM);
 
-	if (!do_tftpb(&cmdtp, 0, 3, tftp_argv)) {
-		bflow->fdt_size = env_get_hex("filesize", 0);
-		bflow->fdt_addr = fdt_addr;
-	} else {
-		log_debug("No device tree available\n");
-		bflow->flags |= BOOTFLOWF_USE_BUILTIN_FDT;
+		if (!do_tftpb(&cmdtp, 0, 3, tftp_argv)) {
+			bflow->fdt_size = env_get_hex("filesize", 0);
+			bflow->fdt_addr = fdt_addr;
+		} else {
+			log_debug("No device tree available\n");
+			bflow->flags |= BOOTFLOWF_USE_BUILTIN_FDT;
+		}
 	}
 
 	bflow->state = BOOTFLOWST_READY;
Signature · 4 lines
2.43.0

base-commit: eb00c710508d09b2a3b9aca75dd18280f1304703
branch: bootstd-fix-us
#1 lore raw
Quoted 34 lines · On Sun, 22 Mar 2026 14:08:50 -0600 Simon Glass <[email protected]> wrote:

When CONFIG_OF_HAS_PRIOR_STAGE is enabled and fdtfile is not set, efi_get_distro_fdt_name() returns -EALREADY to indicate the prior-stage FDT should be used. The block-device EFI path handles this by setting BOOTFLOWF_USE_PRIOR_FDT, but the network path treats it as an error, causing the bootflow to stay in 'base' state with a -EALREADY error.

This also means fdt_addr_r is required even when no FDT download is needed, giving a spurious -EINVAL error.

Fix this by calling efi_get_distro_fdt_name() before checking fdt_addr_r, and handling -EALREADY by setting BOOTFLOWF_USE_PRIOR_FDT to skip the FDT download, matching the block-device behaviour.

THere is no test for this at present, since sandbox does not enable CONFIG_OF_HAS_PRIOR_STAGE and lacks infra for network-based EFI boot.

---

 boot/bootmeth_efi.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
boot/bootmeth_efi.c +0 -4
index f592fec07f6..cbb392e1636 100644
@@ -269,27 +269,29 @@ static int distro_efi_read_bootflow_net(struct bootflow
 *bflow) return log_msg_ret("fi0", -ENOMEM);
 
 	/* read the DT file also */
-	fdt_addr_str = env_get("fdt_addr_r");
-	if (!fdt_addr_str)
-		return log_msg_ret("fdt", -EINVAL);
-	fdt_addr = hextoul(fdt_addr_str, NULL);

boot/bootmeth_efi.c static int distro_efi_read_bootflow_net(struct bootflow · line 277

Quoted 10 lines
boot/bootmeth_efi.c +4 -4
-	sprintf(file_addr, "%lx", fdt_addr);
-
-	/* We only allow the first prefix with PXE */
 	ret = efi_get_distro_fdt_name(fname, sizeof(fname), 0);
-	if (ret)
+	if (ret == -EALREADY) {
+		bflow->flags |= BOOTFLOWF_USE_PRIOR_FDT;
+	} else if (ret) {
 		return log_msg_ret("nam", ret);
+	} else {

Instead of this big else maybe you can return directly in the EALREADY case alongside with a comment, like this:

if (ret == -EALREADY) {
	/* Prior stage fdt is used */
	bflow->flags |= BOOTFLOWF_USE_PRIOR_FDT;
	bflow->state = BOOTFLOWST_READY;
	return 0;
} else if (ret) {
	return log_msg_ret("nam", ret);
}
Quoted 29 lines
boot/bootmeth_efi.c +15 -9
+		fdt_addr_str = env_get("fdt_addr_r");
+		if (!fdt_addr_str)
+			return log_msg_ret("fdt", -EINVAL);
+		fdt_addr = hextoul(fdt_addr_str, NULL);
+		sprintf(file_addr, "%lx", fdt_addr);
 
-	bflow->fdt_fname = strdup(fname);
-	if (!bflow->fdt_fname)
-		return log_msg_ret("fil", -ENOMEM);
+		bflow->fdt_fname = strdup(fname);
+		if (!bflow->fdt_fname)
+			return log_msg_ret("fil", -ENOMEM);
 
-	if (!do_tftpb(&cmdtp, 0, 3, tftp_argv)) {
-		bflow->fdt_size = env_get_hex("filesize", 0);
-		bflow->fdt_addr = fdt_addr;
-	} else {
-		log_debug("No device tree available\n");
-		bflow->flags |= BOOTFLOWF_USE_BUILTIN_FDT;
+		if (!do_tftpb(&cmdtp, 0, 3, tftp_argv)) {
+			bflow->fdt_size = env_get_hex("filesize", 0);
+			bflow->fdt_addr = fdt_addr;
+		} else {
+			log_debug("No device tree available\n");
+			bflow->flags |= BOOTFLOWF_USE_BUILTIN_FDT;
+		}
 	}
 
 	bflow->state = BOOTFLOWST_READY;
Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com