Skip to contentSkip to conversation

bootflow: bootmeth_efi: Fix network efi boot.

PATCH Superseded Shantur Rathore 2 participants 9 messages Nov 18, 2023 – Nov 19, 2023

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover bootflow: bootmeth_efi: Fix network efi boot.

Currently bootmeth_efi crashes while doing a network (dhcp) boot. This patch series fixes issues and both network and disk boot works.

Shantur Rathore (4):
bootflow: bootmeth_efi: Set bootp_arch as hex
bootflow: bootmeth_efi: set bflow->fname from bootfile name
bootflow: bootmeth_efi: Handle fdt not available.
bootflow: bootmeth_efi: don't free buffer

 boot/bootmeth_efi.c | 36 +++++++++++++++++++++++++++---------
 include/bootflow.h  |  2 ++
 2 files changed, 29 insertions(+), 9 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH v3 1/4 bootflow: bootmeth_efi: Set bootp_arch as hex

bootmeth_efi sets up bootp_arch which is read later in bootp.c Currently bootp_arch is being set as integer string and being read in bootp.c as hex, this sends incorrect arch value to dhcp server which in return sends wrong file for network boot.

For ARM64 UEFI Arch value is 0xb (11), here we set environment as 11 and later is read as 0x11 and 17 is sent to dhcp server.

Setting it as hex string fixes the problem.

---
 boot/bootmeth_efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
boot/bootmeth_efi.c +1 -1
index 9ba7734911..682cf5b23b 100644
@@ -339,7 +339,7 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
 	ret = env_set("bootp_vci", str);
 	if (ret)
 		return log_msg_ret("vcs", ret);
-	ret = env_set_ulong("bootp_arch", arch);
+	ret = env_set_hex("bootp_arch", arch);
 	if (ret)
 		return log_msg_ret("ars", ret);
 
Signature · 1 line
2.40.1
#2 lore raw

Re: [PATCH v3 1/4] bootflow: bootmeth_efi: Set bootp_arch as hex

Hi Shantur,

Quoted 9 lines · Shantur Rathore

bootmeth_efi sets up bootp_arch which is read later in bootp.c Currently bootp_arch is being set as integer string and being read in bootp.c as hex, this sends incorrect arch value to dhcp server which in return sends wrong file for network boot.

For ARM64 UEFI Arch value is 0xb (11), here we set environment as 11 and later is read as 0x11 and 17 is sent to dhcp server.

Quoted 6 lines

Setting it as hex string fixes the problem.

---
 boot/bootmeth_efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

I think you dropped my review tag on this version.

You can use 'patman status' to collect review tags automatically.

Regards,
Simon

#3 lore raw

PATCH v3 2/4 bootflow: bootmeth_efi: set bflow->fname from bootfile name

In reply to Shantur Rathore

We need to set boot->fname before calling efi_set_bootdev otherwise this crashes as bflow->fname is null.

---
 boot/bootmeth_efi.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
boot/bootmeth_efi.c +7 -1
index 682cf5b23b..183daad8f1 100644
@@ -323,7 +323,7 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
 	char file_addr[17], fname[256];
 	char *tftp_argv[] = {"tftp", file_addr, fname, NULL};
 	struct cmd_tbl cmdtp = {};	/* dummy */
-	const char *addr_str, *fdt_addr_str;
+	const char *addr_str, *fdt_addr_str, *bootfile_name;
 	int ret, arch, size;
 	ulong addr, fdt_addr;
 	char str[36];
@@ -360,6 +360,12 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
 		return log_msg_ret("sz", -EINVAL);
 	bflow->size = size;
 
+    /* bootfile should be setup by dhcp*/
+    bootfile_name = env_get("bootfile");
+    if (!bootfile_name)
+        return log_msg_ret("bootfile_name", ret);
+    bflow->fname = strdup(bootfile_name);
+
 	/* do the hideous EFI hack */
 	efi_set_bootdev("Net", "", bflow->fname, map_sysmem(addr, 0),
 			bflow->size);
Signature · 1 line
2.40.1
#4 lore raw

PATCH v3 3/4 bootflow: bootmeth_efi: Handle fdt not available.

While booting with efi, if fdt isn't available externally, just use the built-in one.

---
 boot/bootmeth_efi.c | 19 +++++++++++++------
 include/bootflow.h  |  2 ++
 2 files changed, 15 insertions(+), 6 deletions(-)
boot/bootmeth_efi.c +13 -6
index 183daad8f1..370d6fba9f 100644
@@ -313,6 +313,7 @@ static int distro_efi_try_bootflow_files(struct udevice *dev,
 		 */
 	} else {
 		log_debug("No device tree available\n");
+		bflow->flags |= BOOTFLOWF_USE_BUILTIN_FDT;
 	}
 
 	return 0;
@@ -391,6 +392,7 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
 		bflow->fdt_addr = fdt_addr;
 	} else {
 		log_debug("No device tree available\n");
+		bflow->flags |= BOOTFLOWF_USE_BUILTIN_FDT;
 	}
 
 	bflow->state = BOOTFLOWST_READY;
@@ -429,13 +431,11 @@ static int distro_efi_boot(struct udevice *dev, struct bootflow *bflow)
 			return log_msg_ret("read", ret);
 
 		/*
-		 * use the provided device tree if available, else fall back to
-		 * the control FDT
+		 * use the provided device tree if not using the built-in fdt
 		 */
-		if (bflow->fdt_fname)
+		if (bflow->flags & ~BOOTFLOWF_USE_BUILTIN_FDT)
 			fdt = bflow->fdt_addr;
-		else
-			fdt = (ulong)map_to_sysmem(gd->fdt_blob);
+
 	} else {
 		/*
 		 * This doesn't actually work for network devices:
@@ -452,7 +452,14 @@ static int distro_efi_boot(struct udevice *dev, struct bootflow *bflow)
 	 * At some point we can add a real interface to bootefi so we can call
 	 * this directly. For now, go through the CLI, like distro boot.
 	 */
-	snprintf(cmd, sizeof(cmd), "bootefi %lx %lx", kernel, fdt);
+	if (bflow->flags & BOOTFLOWF_USE_BUILTIN_FDT) {
+		log_debug("Booting with built-in fdt\n");
+		snprintf(cmd, sizeof(cmd), "bootefi %lx", kernel);
+	} else {
+		log_debug("Booting with external fdt\n");
+		snprintf(cmd, sizeof(cmd), "bootefi %lx %lx", kernel, fdt);
+	}
+
 	if (run_command(cmd, 0))
 		return log_msg_ret("run", -EINVAL);
 
include/bootflow.h +2 -0
index fede8f22a2..42112874f6 100644
@@ -45,10 +45,12 @@ enum bootflow_state_t {
  *	CONFIG_OF_HAS_PRIOR_STAGE is enabled
  * @BOOTFLOWF_STATIC_BUF: Indicates that @bflow->buf is statically set, rather
  *	than being allocated by malloc().
+ * @BOOTFLOWF_USE_BUILTIN_FDT : Indicates that current bootflow uses built-in FDT
  */
 enum bootflow_flags_t {
 	BOOTFLOWF_USE_PRIOR_FDT	= 1 << 0,
 	BOOTFLOWF_STATIC_BUF	= 1 << 1,
+	BOOTFLOWF_USE_BUILTIN_FDT	= 1 << 2,
 };
 
 /**
Signature · 1 line
2.40.1
Reviewed-by on v3 3/4
#5 lore raw

Re: [PATCH v3 3/4] bootflow: bootmeth_efi: Handle fdt not available.

Quoted 6 lines · Shantur Rathore

While booting with efi, if fdt isn't available externally, just use the built-in one.

---

Change log needed when you send a new version

Quoted 4 lines
 boot/bootmeth_efi.c | 19 +++++++++++++------
 include/bootflow.h  |  2 ++
 2 files changed, 15 insertions(+), 6 deletions(-)
#6 lore raw

PATCH v3 4/4 bootflow: bootmeth_efi: don't free buffer

In reply to Shantur Rathore

bootmeth_efi doesn't allocate any buffer to load efi in any case. enable static buffer flag for all cases.

---
 boot/bootmeth_efi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
boot/bootmeth_efi.c +6 -1
index 370d6fba9f..93f096896c 100644
@@ -160,7 +160,6 @@ static int efiload_read_file(struct bootflow *bflow, ulong addr)
 	if (ret)
 		return log_msg_ret("read", ret);
 	bflow->buf = map_sysmem(addr, bflow->size);
-	bflow->flags |= BOOTFLOWF_STATIC_BUF;
 
 	set_efi_bootdev(desc, bflow);
 
@@ -404,6 +403,12 @@ static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
 	int ret;
 
+	/* 
+	 * bootmeth_efi doesn't allocate any buffer neither for bulk nor net device
+	 * set flag to avoid freeing static buffer.
+	 */
+	bflow->flags |= BOOTFLOWF_STATIC_BUF;
+
 	if (bootmeth_uses_network(bflow)) {
 		/* we only support reading from one device, so ignore 'dev' */
 		ret = distro_efi_read_bootflow_net(bflow);
Signature · 1 line
2.40.1
Reviewed-by on v3 4/4
#7 lore raw

Re: [PATCH v3 4/4] bootflow: bootmeth_efi: don't free buffer

Hi Shantur,

Quoted 8 lines · Shantur Rathore

bootmeth_efi doesn't allocate any buffer to load efi in any case. enable static buffer flag for all cases.

---
 boot/bootmeth_efi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 14 lines
boot/bootmeth_efi.c +0 -1
index 370d6fba9f..93f096896c 100644
@@ -160,7 +160,6 @@ static int efiload_read_file(struct bootflow *bflow, ulong addr)
        if (ret)
                return log_msg_ret("read", ret);
        bflow->buf = map_sysmem(addr, bflow->size);
-       bflow->flags |= BOOTFLOWF_STATIC_BUF;
 
        set_efi_bootdev(desc, bflow);
 

boot/bootmeth_efi.c static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow) · line 407

Quoted 5 lines
boot/bootmeth_efi.c +2 -0
@@ -404,6 +403,12 @@ static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        int ret;
 
+       /*
+        * bootmeth_efi doesn't allocate any buffer neither for bulk nor net device

s/bulk/blk/ ?

Quoted 10 lines
boot/bootmeth_efi.c +4 -1
+        * set flag to avoid freeing static buffer.
+        */
+       bflow->flags |= BOOTFLOWF_STATIC_BUF;
+
        if (bootmeth_uses_network(bflow)) {
                /* we only support reading from one device, so ignore 'dev' */
                ret = distro_efi_read_bootflow_net(bflow);
--

2.40.1

Regards,
Simon

Reviewed-by on v3 2/4
#8 lore raw

Re: [PATCH v3 2/4] bootflow: bootmeth_efi: set bflow->fname from bootfile name

In reply to Shantur Rathore
Quoted 9 lines · Shantur Rathore

We need to set boot->fname before calling efi_set_bootdev otherwise this crashes as bflow->fname is null.

---
 boot/bootmeth_efi.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

We definitely need to figure out a way to get this code. The boostd tests don't go much into the bothmeths unfortunately

- Simon