Skip to contentSkip to conversation

bootflow: bootmeth_efi: Fix network eif boot.

PATCH Superseded Shantur Rathore 3 participants 15 messages Nov 17, 2023 – Nov 19, 2023

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover bootflow: bootmeth_efi: Fix network eif 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: Don't set bootdev again
bootflow: bootmeth_efi: Handle fdt not available.
bootflow: bootmeth_efi: don't free buffer

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

PATCH v2 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
Reviewed-by on v2 1/4
#2 lore raw

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

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(-)

Now the question is how to add test coverage for this.

#3 lore raw

PATCH v2 2/4 bootflow: bootmeth_efi: Don't set bootdev again

In reply to Shantur Rathore

efi_set_bootdev is already called as part of tftp while doing dhcp_run() Doing this again crashes U-boot and we don't need to call again.

---
 boot/bootmeth_efi.c | 3 ---
 1 file changed, 3 deletions(-)
boot/bootmeth_efi.c +0 -3
index 682cf5b23b..5917458dc5 100644
@@ -360,9 +360,6 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
 		return log_msg_ret("sz", -EINVAL);
 	bflow->size = size;
 
-	/* do the hideous EFI hack */
-	efi_set_bootdev("Net", "", bflow->fname, map_sysmem(addr, 0),
-			bflow->size);
 
 	/* read the DT file also */
 	fdt_addr_str = env_get("fdt_addr_r");
Signature · 1 line
2.40.1
#4 lore raw

Re: [PATCH v2 2/4] bootflow: bootmeth_efi: Don't set bootdev again

+Ilias too as this involves a design decision

Hi Shantur,

Quoted 2 lines · Shantur Rathore

efi_set_bootdev is already called as part of tftp while doing dhcp_run()

Is that in tftp_complete() ?

Quoted 1 line

Doing this again crashes U-boot and we don't need to call again.

U-Boot

The problem is that we might scan for 4 bootflows, then later decide which one to boot. So we cannot know which one it will be until that point.

The hack is needed so that it actually tells EFI about the right one.

The addition of EFI hacks when reading files (i.e. the code in tftp_complete()) is a real problem, unfortunately. I understand that it was a convenient hack, but with standard boot we really don't want it to do that. We end up calling it multiple times for bootflows that won't be used.

So I believe the fix is to be able to disable those calls, leaving it to bootstd.

I'm not sure of the best way to do that. Perhaps we should have a function like bootstd_scanning() which returns a bool indicating that bootstd is scanning? If that is true then no efi_set_bootdev() calls are made? We could have a flag in 'struct bootstd_priv' which is set before bootflow_check() is called and cleared afterwards.

As to how this should be done with standard boot, we should create a function like efi_start_app() and pass it the information we need. That function should do the equivalent of the 'bootefi' command, except programmatically, with no prior state hanging around.

As to when we might be able to do that, we need more refactoring of the bootm code. There is a start on this [1] but it likely needs 2-3 more series before it might be possible.

So for now, I think bootstd_scanning() is the best approach. If you are not sure about that, I can send a patch.

Quoted 21 lines
---
 boot/bootmeth_efi.c | 3 ---
 1 file changed, 3 deletions(-)
boot/bootmeth_efi.c +0 -4
index 682cf5b23b..5917458dc5 100644
@@ -360,9 +360,6 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
                return log_msg_ret("sz", -EINVAL);
        bflow->size = size;
 
-       /* do the hideous EFI hack */
-       efi_set_bootdev("Net", "", bflow->fname, map_sysmem(addr, 0),
-                       bflow->size);
 
        /* read the DT file also */
        fdt_addr_str = env_get("fdt_addr_r");
--
Quoted 2 lines

2.40.1

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=382423

#5 lore raw

Re: [PATCH v2 2/4] bootflow: bootmeth_efi: Don't set bootdev again

Hi Simon,

Quoted 41 lines · Simon Glass

+Ilias too as this involves a design decision

Hi Shantur,

Quoted 2 lines · Shantur Rathore

efi_set_bootdev is already called as part of tftp while doing dhcp_run()

Is that in tftp_complete() ?

Quoted 1 line

Doing this again crashes U-boot and we don't need to call again.

U-Boot

The problem is that we might scan for 4 bootflows, then later decide which one to boot. So we cannot know which one it will be until that point.

The hack is needed so that it actually tells EFI about the right one.

The addition of EFI hacks when reading files (i.e. the code in tftp_complete()) is a real problem, unfortunately. I understand that it was a convenient hack, but with standard boot we really don't want it to do that. We end up calling it multiple times for bootflows that won't be used.

So I believe the fix is to be able to disable those calls, leaving it to bootstd.

I'm not sure of the best way to do that. Perhaps we should have a function like bootstd_scanning() which returns a bool indicating that bootstd is scanning? If that is true then no efi_set_bootdev() calls are made? We could have a flag in 'struct bootstd_priv' which is set before bootflow_check() is called and cleared afterwards.

As to how this should be done with standard boot, we should create a function like efi_start_app() and pass it the information we need. That function should do the equivalent of the 'bootefi' command, except programmatically, with no prior state hanging around.

Quoted 7 lines

As to when we might be able to do that, we need more refactoring of the bootm code. There is a start on this [1] but it likely needs 2-3 more series before it might be possible.

So for now, I think bootstd_scanning() is the best approach. If you are not sure about that, I can send a patch.

My apologies, the fix I submitted is incorrect.
After reading your explanation, I started thinking on why dhcp can call this multiple times but bootmethod can't.

There it was clear that the issue bflow->fname is null when we call this function.
The correct fix should be below

+       /* bootfile should be setup by dhcp by now*/
+       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);

I have a patch ready for this which I will send but I have some queries regarding that.
As I sent this a series of patches out of which 2 were reviewed, should I send a new version for the whole series even though 2 are not going to be changed?
Another thing, should I send them as a reply to the original email or a new thread?

Kind regards,
Shantur

#6 lore raw

Re: [PATCH v2 2/4] bootflow: bootmeth_efi: Don't set bootdev again

Hi Shantur,

Quoted 71 lines · Shantur Rathore

Hi Simon,

Quoted 41 lines · Simon Glass

+Ilias too as this involves a design decision

Hi Shantur,

Quoted 2 lines · Shantur Rathore

efi_set_bootdev is already called as part of tftp while doing dhcp_run()

Is that in tftp_complete() ?

Quoted 1 line

Doing this again crashes U-boot and we don't need to call again.

U-Boot

The problem is that we might scan for 4 bootflows, then later decide which one to boot. So we cannot know which one it will be until that point.

The hack is needed so that it actually tells EFI about the right one.

The addition of EFI hacks when reading files (i.e. the code in tftp_complete()) is a real problem, unfortunately. I understand that it was a convenient hack, but with standard boot we really don't want it to do that. We end up calling it multiple times for bootflows that won't be used.

So I believe the fix is to be able to disable those calls, leaving it to bootstd.

I'm not sure of the best way to do that. Perhaps we should have a function like bootstd_scanning() which returns a bool indicating that bootstd is scanning? If that is true then no efi_set_bootdev() calls are made? We could have a flag in 'struct bootstd_priv' which is set before bootflow_check() is called and cleared afterwards.

As to how this should be done with standard boot, we should create a function like efi_start_app() and pass it the information we need. That function should do the equivalent of the 'bootefi' command, except programmatically, with no prior state hanging around.

Quoted 7 lines

As to when we might be able to do that, we need more refactoring of the bootm code. There is a start on this [1] but it likely needs 2-3 more series before it might be possible.

So for now, I think bootstd_scanning() is the best approach. If you are not sure about that, I can send a patch.

My apologies, the fix I submitted is incorrect.
After reading your explanation, I started thinking on why dhcp can call this multiple times but bootmethod can't.

There it was clear that the issue bflow->fname is null when we call this function.
The correct fix should be below

(quoted diff) +6 -0
+       /* bootfile should be setup by dhcp by now*/
+       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);
Quoted 5 lines

I have a patch ready for this which I will send but I have some queries regarding that.
As I sent this a series of patches out of which 2 were reviewed, should I send a new version for the whole series even though 2 are not going to be changed?

Yes you normally send the whole series but include any review/tested tags that you received for each patch ('patman status' can help).

Quoted 2 lines

Another thing, should I send them as a reply to the original email or a new thread?

A new thread is fine.

Regards,
Simon

#7 lore raw

Re: [PATCH v2 2/4] bootflow: bootmeth_efi: Don't set bootdev again

Hi Simon,

Quoted 75 lines · Simon Glass

Hi Shantur,

Quoted 71 lines · Shantur Rathore

Hi Simon,

Quoted 41 lines · Simon Glass

+Ilias too as this involves a design decision

Hi Shantur,

Quoted 2 lines · Shantur Rathore

efi_set_bootdev is already called as part of tftp while doing dhcp_run()

Is that in tftp_complete() ?

Quoted 1 line

Doing this again crashes U-boot and we don't need to call again.

U-Boot

The problem is that we might scan for 4 bootflows, then later decide which one to boot. So we cannot know which one it will be until that point.

The hack is needed so that it actually tells EFI about the right one.

The addition of EFI hacks when reading files (i.e. the code in tftp_complete()) is a real problem, unfortunately. I understand that it was a convenient hack, but with standard boot we really don't want it to do that. We end up calling it multiple times for bootflows that won't be used.

So I believe the fix is to be able to disable those calls, leaving it to bootstd.

I'm not sure of the best way to do that. Perhaps we should have a function like bootstd_scanning() which returns a bool indicating that bootstd is scanning? If that is true then no efi_set_bootdev() calls are made? We could have a flag in 'struct bootstd_priv' which is set before bootflow_check() is called and cleared afterwards.

As to how this should be done with standard boot, we should create a function like efi_start_app() and pass it the information we need. That function should do the equivalent of the 'bootefi' command, except programmatically, with no prior state hanging around.

Quoted 7 lines

As to when we might be able to do that, we need more refactoring of the bootm code. There is a start on this [1] but it likely needs 2-3 more series before it might be possible.

So for now, I think bootstd_scanning() is the best approach. If you are not sure about that, I can send a patch.

My apologies, the fix I submitted is incorrect.
After reading your explanation, I started thinking on why dhcp can call this multiple times but bootmethod can't.

There it was clear that the issue bflow->fname is null when we call this function.
The correct fix should be below

(quoted diff) +6 -0
+       /* bootfile should be setup by dhcp by now*/
+       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);
Quoted 9 lines
Quoted 5 lines

I have a patch ready for this which I will send but I have some queries regarding that.
As I sent this a series of patches out of which 2 were reviewed, should I send a new version for the whole series even though 2 are not going to be changed?

Yes you normally send the whole series but include any review/tested tags that you received for each patch ('patman status' can help).

patman... that's the missing piece in the puzzle. I was trying to find out how everyone is managing their commits.

Thanks for pointing it out to me.

Kind regards,
Shantur

#8 lore raw

Re: [PATCH v2 2/4] bootflow: bootmeth_efi: Don't set bootdev again

Hi Shantur,

Quoted 85 lines · Shantur Rathore

Hi Simon,

Quoted 81 lines · Simon Glass

Hi Shantur,

Quoted 76 lines · Shantur Rathore

Hi Simon,

Quoted 41 lines · Simon Glass

+Ilias too as this involves a design decision

Hi Shantur,

Quoted 2 lines · Shantur Rathore

efi_set_bootdev is already called as part of tftp while doing dhcp_run()

Is that in tftp_complete() ?

Quoted 1 line

Doing this again crashes U-boot and we don't need to call again.

U-Boot

The problem is that we might scan for 4 bootflows, then later decide which one to boot. So we cannot know which one it will be until that point.

The hack is needed so that it actually tells EFI about the right one.

The addition of EFI hacks when reading files (i.e. the code in tftp_complete()) is a real problem, unfortunately. I understand that it was a convenient hack, but with standard boot we really don't want it to do that. We end up calling it multiple times for bootflows that won't be used.

So I believe the fix is to be able to disable those calls, leaving it to bootstd.

I'm not sure of the best way to do that. Perhaps we should have a function like bootstd_scanning() which returns a bool indicating that bootstd is scanning? If that is true then no efi_set_bootdev() calls are made? We could have a flag in 'struct bootstd_priv' which is set before bootflow_check() is called and cleared afterwards.

As to how this should be done with standard boot, we should create a function like efi_start_app() and pass it the information we need. That function should do the equivalent of the 'bootefi' command, except programmatically, with no prior state hanging around.

Quoted 7 lines

As to when we might be able to do that, we need more refactoring of the bootm code. There is a start on this [1] but it likely needs 2-3 more series before it might be possible.

So for now, I think bootstd_scanning() is the best approach. If you are not sure about that, I can send a patch.

My apologies, the fix I submitted is incorrect.
After reading your explanation, I started thinking on why dhcp can call this multiple times but bootmethod can't.

There it was clear that the issue bflow->fname is null when we call this function.
The correct fix should be below

(quoted diff) +6 -0
+       /* bootfile should be setup by dhcp by now*/
+       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);

I have a patch ready for this which I will send but I have some queries regarding that.
As I sent this a series of patches out of which 2 were reviewed, should I send a new version for the whole series even though 2 are not going to be changed?

Quoted 8 lines
Quoted 3 lines

Yes you normally send the whole series but include any review/tested tags that you received for each patch ('patman status' can help).

patman... that's the missing piece in the puzzle. I was trying to find out how everyone is managing their commits.

Thanks for pointing it out to me.

:-) If you have ideas to improve it, please send patches.

- Simon

#9 lore raw

Re: [PATCH v2 2/4] bootflow: bootmeth_efi: Don't set bootdev again

In reply to Simon Glass

Hi Simon,

Thanks for looping me in

Quoted 12 lines · Simon Glass

+Ilias too as this involves a design decision

Hi Shantur,

Quoted 2 lines · Shantur Rathore

efi_set_bootdev is already called as part of tftp while doing dhcp_run()

Is that in tftp_complete() ?

Quoted 1 line

Doing this again crashes U-boot and we don't need to call again.

Yes, we should fine the root cause here instead of papering over the problem

Quoted 29 lines

U-Boot

The problem is that we might scan for 4 bootflows, then later decide which one to boot. So we cannot know which one it will be until that point.

The hack is needed so that it actually tells EFI about the right one.

The addition of EFI hacks when reading files (i.e. the code in tftp_complete()) is a real problem, unfortunately. I understand that it was a convenient hack, but with standard boot we really don't want it to do that. We end up calling it multiple times for bootflows that won't be used.

So I believe the fix is to be able to disable those calls, leaving it to bootstd.

I'm not sure of the best way to do that. Perhaps we should have a function like bootstd_scanning() which returns a bool indicating that bootstd is scanning? If that is true then no efi_set_bootdev() calls are made? We could have a flag in 'struct bootstd_priv' which is set before bootflow_check() is called and cleared afterwards.

As to how this should be done with standard boot, we should create a function like efi_start_app() and pass it the information we need. That function should do the equivalent of the 'bootefi' command, except programmatically, with no prior state hanging around.

Quoted 6 lines

As to when we might be able to do that, we need more refactoring of the bootm code. There is a start on this [1] but it likely needs 2-3 more series before it might be possible.

So for now, I think bootstd_scanning() is the best approach. If you are not sure about that, I can send a patch.

I'll have a closer look at the efi bootmeth as well and come back with suggestions

Thanks
/Ilias

Quoted 29 lines
Quoted 22 lines
---
 boot/bootmeth_efi.c | 3 ---
 1 file changed, 3 deletions(-)
boot/bootmeth_efi.c +0 -4
index 682cf5b23b..5917458dc5 100644
@@ -360,9 +360,6 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow)
                return log_msg_ret("sz", -EINVAL);
        bflow->size = size;
 
-       /* do the hideous EFI hack */
-       efi_set_bootdev("Net", "", bflow->fname, map_sysmem(addr, 0),
-                       bflow->size);
 
        /* read the DT file also */
        fdt_addr_str = env_get("fdt_addr_r");
--
Quoted 2 lines

2.40.1

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=382423

#10 lore raw

Re: [PATCH v2 2/4] bootflow: bootmeth_efi: Don't set bootdev again

Hi Ilias,

Quoted 13 lines · Ilias Apalodimas

Hi Simon,

Thanks for looping me in

Quoted 7 lines · Simon Glass

+Ilias too as this involves a design decision

Hi Shantur,

Quoted 1 line · Shantur Rathore
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

efi_set_bootdev is already called as part of tftp while doing dhcp_run()

Is that in tftp_complete() ?

Quoted 1 line

Doing this again crashes U-boot and we don't need to call again.

Yes, we should fine the root cause here instead of papering over the problem

The root cause has been identified and fixed here -
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Kind regards,
Shantur

#11 lore raw

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

In reply to Shantur Rathore

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

---
 boot/bootmeth_efi.c | 10 +++++++++-
 include/bootflow.h  |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)
boot/bootmeth_efi.c +9 -1
index 5917458dc5..5e67afed88 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;
@@ -382,6 +383,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;
@@ -443,7 +445,13 @@ 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 {
+		snprintf(cmd, sizeof(cmd), "bootefi %lx %lx", kernel, fdt);
+	}
+
 	if (run_command(cmd, 0))
 		return log_msg_ret("run", -EINVAL);
 
include/bootflow.h +1 -0
index fede8f22a2..3890cd4bc2 100644
@@ -49,6 +49,7 @@ enum bootflow_state_t {
 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
#12 lore raw

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

Hi Shantur,

Quoted 32 lines · Shantur Rathore

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

---
 boot/bootmeth_efi.c | 10 +++++++++-
 include/bootflow.h  |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)
boot/bootmeth_efi.c +2 -0
index 5917458dc5..5e67afed88 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;
@@ -382,6 +383,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;
@@ -443,7 +445,13 @@ 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

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

Quoted 10 lines
boot/bootmeth_efi.c +7 -1
         * 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 {
+               snprintf(cmd, sizeof(cmd), "bootefi %lx %lx", kernel, fdt);
+       }
+

There is some code (not shown) in this function:

/*
* use the provided device tree if available, else fall back to
* the control FDT
*/
if (bflow->fdt_fname)

I believe that should use your flag as well. So instead of using fdt_fname to indicate whether there is an fdt, we should use your new flag.

include/bootflow.h enum bootflow_state_t { · line 52

Quoted 12 lines
boot/bootmeth_efi.c +0 -0
        if (run_command(cmd, 0))
                return log_msg_ret("run", -EINVAL);
 
include/bootflow.h +1 -0
index fede8f22a2..3890cd4bc2 100644
@@ -49,6 +49,7 @@ enum bootflow_state_t {
 enum bootflow_flags_t {
        BOOTFLOWF_USE_PRIOR_FDT = 1 << 0,
        BOOTFLOWF_STATIC_BUF    = 1 << 1,
+       BOOTFLOWF_USE_BUILTIN_FDT       = 1 << 2,

Please update the comment for the enum to fully explain what it does

Quoted 6 lines
include/bootflow.h +0 -1
 };
 
 /**
--

2.40.1

Regards,
Simon

#13 lore raw

PATCH v2 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 5e67afed88..045e9ac543 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);
 
@@ -395,6 +394,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 v2 4/4
#14 lore raw

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

Quoted 9 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(-)