All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] efi_loader: Use system fdt as fallback
@ 2016-04-11 14:55 Alexander Graf
  2016-04-13 12:58 ` Andreas Färber
  2016-04-21 11:22 ` [U-Boot] " Tom Rini
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Graf @ 2016-04-11 14:55 UTC (permalink / raw)
  To: u-boot

When the user did not pass any device tree or the boot script
didn't find any, let's use the system device tree as last resort
to get something the payload (Linux) may understand.

This means that on systems that use the same device tree for U-Boot
and Linux we can just share it and there's no need to manually provide
a device tree in the target image.

While at it, also copy and pad the device tree by 64kb to give us
space for modifications.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 cmd/bootefi.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index f502996..9b8af65 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -12,6 +12,10 @@
 #include <errno.h>
 #include <libfdt.h>
 #include <libfdt_env.h>
+#include <malloc.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 /*
  * When booting using the "bootefi" command, we don't know which
@@ -97,6 +101,21 @@ static struct efi_object bootefi_device_obj = {
 	},
 };
 
+static void *copy_fdt(void *fdt)
+{
+	u64 fdt_size = fdt_totalsize(fdt);
+	void *new_fdt;
+
+	/* Give us 64kb breathing room */
+	fdt_size += 64 * 1024;
+
+	new_fdt = malloc(fdt_size);
+	memcpy(new_fdt, fdt, fdt_totalsize(fdt));
+	fdt_set_totalsize(new_fdt, fdt_size);
+
+	return new_fdt;
+}
+
 /*
  * Load an EFI payload into a newly allocated piece of memory, register all
  * EFI objects it would want to access and jump to it.
@@ -106,6 +125,7 @@ static unsigned long do_bootefi_exec(void *efi)
 	ulong (*entry)(void *image_handle, struct efi_system_table *st);
 	ulong fdt_pages, fdt_size, fdt_start, fdt_end;
 	bootm_headers_t img = { 0 };
+	void *fdt = working_fdt;
 
 	/*
 	 * gd lives in a fixed register which may get clobbered while we execute
@@ -115,28 +135,33 @@ static unsigned long do_bootefi_exec(void *efi)
 
 	/* Update system table to point to our currently loaded FDT */
 
-	if (working_fdt) {
+	/* Fall back to included fdt if none was manually loaded */
+	if (!fdt && gd->fdt_blob)
+		fdt = (void *)gd->fdt_blob;
+
+	if (fdt) {
 		/* Prepare fdt for payload */
-		if (image_setup_libfdt(&img, working_fdt, 0, NULL)) {
+		fdt = copy_fdt(fdt);
+
+		if (image_setup_libfdt(&img, fdt, 0, NULL)) {
 			printf("ERROR: Failed to process device tree\n");
 			return -EINVAL;
 		}
 
 		/* Link to it in the efi tables */
 		systab.tables[0].guid = EFI_FDT_GUID;
-		systab.tables[0].table = working_fdt;
+		systab.tables[0].table = fdt;
 		systab.nr_tables = 1;
 
 		/* And reserve the space in the memory map */
-		fdt_start = ((ulong)working_fdt) & ~EFI_PAGE_MASK;
-		fdt_end = ((ulong)working_fdt) + fdt_totalsize(working_fdt);
+		fdt_start = ((ulong)fdt) & ~EFI_PAGE_MASK;
+		fdt_end = ((ulong)fdt) + fdt_totalsize(fdt);
 		fdt_size = (fdt_end - fdt_start) + EFI_PAGE_MASK;
 		fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
 		/* Give a bootloader the chance to modify the device tree */
 		fdt_pages += 2;
 		efi_add_memory_map(fdt_start, fdt_pages,
 				   EFI_BOOT_SERVICES_DATA, true);
-
 	} else {
 		printf("WARNING: No device tree loaded, expect boot to fail\n");
 		systab.nr_tables = 0;
-- 
1.8.5.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH] efi_loader: Use system fdt as fallback
  2016-04-11 14:55 [U-Boot] [PATCH] efi_loader: Use system fdt as fallback Alexander Graf
@ 2016-04-13 12:58 ` Andreas Färber
  2016-04-13 13:15   ` Alexander Graf
  2016-04-21 11:22 ` [U-Boot] " Tom Rini
  1 sibling, 1 reply; 5+ messages in thread
From: Andreas Färber @ 2016-04-13 12:58 UTC (permalink / raw)
  To: u-boot

Am 11.04.2016 um 16:55 schrieb Alexander Graf:
> When the user did not pass any device tree or the boot script
> didn't find any, let's use the system device tree as last resort
> to get something the payload (Linux) may understand.
> 
> This means that on systems that use the same device tree for U-Boot
> and Linux we can just share it and there's no need to manually provide
> a device tree in the target image.
> 
> While at it, also copy and pad the device tree by 64kb to give us
> space for modifications.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>

Tested-by: Andreas F?rber <afaerber@suse.de>

It definitely avoids a warning message. However, it does not always
allow Linux to actually boot, e.g. on jetson-tk1 (patch sent).

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH] efi_loader: Use system fdt as fallback
  2016-04-13 12:58 ` Andreas Färber
@ 2016-04-13 13:15   ` Alexander Graf
  2016-04-13 13:17     ` Andreas Färber
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Graf @ 2016-04-13 13:15 UTC (permalink / raw)
  To: u-boot

On 04/13/2016 02:58 PM, Andreas F?rber wrote:
> Am 11.04.2016 um 16:55 schrieb Alexander Graf:
>> When the user did not pass any device tree or the boot script
>> didn't find any, let's use the system device tree as last resort
>> to get something the payload (Linux) may understand.
>>
>> This means that on systems that use the same device tree for U-Boot
>> and Linux we can just share it and there's no need to manually provide
>> a device tree in the target image.
>>
>> While at it, also copy and pad the device tree by 64kb to give us
>> space for modifications.
>>
>> Signed-off-by: Alexander Graf <agraf@suse.de>
> Tested-by: Andreas F?rber <afaerber@suse.de>
>
> It definitely avoids a warning message. However, it does not always
> allow Linux to actually boot, e.g. on jetson-tk1 (patch sent).

We could give the user a warning in the fallback case as well, but 
ideally I'd like to move to a model where all device trees really are 
interchangable and work with every component. So then we would warn the 
user about the preferred default case. I'm not sure that's a great idea.


Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH] efi_loader: Use system fdt as fallback
  2016-04-13 13:15   ` Alexander Graf
@ 2016-04-13 13:17     ` Andreas Färber
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Färber @ 2016-04-13 13:17 UTC (permalink / raw)
  To: u-boot

Am 13.04.2016 um 15:15 schrieb Alexander Graf:
> On 04/13/2016 02:58 PM, Andreas F?rber wrote:
>> Am 11.04.2016 um 16:55 schrieb Alexander Graf:
>>> When the user did not pass any device tree or the boot script
>>> didn't find any, let's use the system device tree as last resort
>>> to get something the payload (Linux) may understand.
>>>
>>> This means that on systems that use the same device tree for U-Boot
>>> and Linux we can just share it and there's no need to manually provide
>>> a device tree in the target image.
>>>
>>> While at it, also copy and pad the device tree by 64kb to give us
>>> space for modifications.
>>>
>>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> Tested-by: Andreas F?rber <afaerber@suse.de>
>>
>> It definitely avoids a warning message. However, it does not always
>> allow Linux to actually boot, e.g. on jetson-tk1 (patch sent).
> 
> We could give the user a warning in the fallback case as well, but
> ideally I'd like to move to a model where all device trees really are
> interchangable and work with every component. So then we would warn the
> user about the preferred default case. I'm not sure that's a great idea.

I'm not saying we need a warning here, just that this solution by itself
is not sufficient and other fixes (like supplying $fdtfile) are still
necessary today.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] efi_loader: Use system fdt as fallback
  2016-04-11 14:55 [U-Boot] [PATCH] efi_loader: Use system fdt as fallback Alexander Graf
  2016-04-13 12:58 ` Andreas Färber
@ 2016-04-21 11:22 ` Tom Rini
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Rini @ 2016-04-21 11:22 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 11, 2016 at 04:55:26PM +0200, Alexander Graf wrote:

> When the user did not pass any device tree or the boot script
> didn't find any, let's use the system device tree as last resort
> to get something the payload (Linux) may understand.
> 
> This means that on systems that use the same device tree for U-Boot
> and Linux we can just share it and there's no need to manually provide
> a device tree in the target image.
> 
> While at it, also copy and pad the device tree by 64kb to give us
> space for modifications.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> Tested-by: Andreas F?rber <afaerber@suse.de>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160421/4ce1d11e/attachment.sig>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-04-21 11:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-11 14:55 [U-Boot] [PATCH] efi_loader: Use system fdt as fallback Alexander Graf
2016-04-13 12:58 ` Andreas Färber
2016-04-13 13:15   ` Alexander Graf
2016-04-13 13:17     ` Andreas Färber
2016-04-21 11:22 ` [U-Boot] " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.