Patchwork [U-Boot,v3,4/6] fdt: ARM: Implement embedded and separate device tree

login
register
mail settings
Submitter Simon Glass
Date Oct. 11, 2011, 10:26 p.m.
Message ID <1318371971-4457-5-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/119079/
State New, archived
Headers show

Comments

Simon Glass - Oct. 11, 2011, 10:26 p.m.
This locates the device tree either embedded within U-Boot or attached to the
end as a separate binary.

When CONFIG_OF_CONTROL is defined, U-Boot requires a valid fdt. A check is
provided for this early in initialisation.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3:
- Add note about CONFIG_ARCH_DEVICE_TREE

 arch/arm/lib/board.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
Stephen Warren - Oct. 13, 2011, 9:39 p.m.
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
> This locates the device tree either embedded within U-Boot or attached to the
> end as a separate binary.
> 
> When CONFIG_OF_CONTROL is defined, U-Boot requires a valid fdt. A check is
> provided for this early in initialisation.

The subject of this patch seems a little misleading; something more like
"fdt: ARM: Check that a control fdt is present" would be more accurate.

Sorry for the trivial comments!
Simon Glass - Oct. 15, 2011, 3:15 p.m.
Hi Stephen,

On Thu, Oct 13, 2011 at 2:39 PM, Stephen Warren <swarren@nvidia.com> wrote:
> Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
>> This locates the device tree either embedded within U-Boot or attached to the
>> end as a separate binary.
>>
>> When CONFIG_OF_CONTROL is defined, U-Boot requires a valid fdt. A check is
>> provided for this early in initialisation.
>
> The subject of this patch seems a little misleading; something more like
> "fdt: ARM: Check that a control fdt is present" would be more accurate.

It does also implement it. Before this, there is no code to find the
device tree on ARM. But yes it also checks that it gets something
valid. I will change the name to something like 'fdt: ARM: Implement
and verify embedded and separate device tree'

>
> Sorry for the trivial comments!

Thanks for looking at it.

Regards,
Simon

>
> --
> nvpublic
>
>

Patch

diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 1fe3751..b0f3162 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -48,6 +48,7 @@ 
 #include <nand.h>
 #include <onenand_uboot.h>
 #include <mmc.h>
+#include <libfdt.h>
 #include <post.h>
 #include <logbuff.h>
 
@@ -197,6 +198,17 @@  static int arm_pci_init(void)
 }
 #endif /* CONFIG_CMD_PCI || CONFIG_PCI */
 
+#ifdef CONFIG_OF_CONTROL
+static int check_fdt(void)
+{
+	/* We must have an fdt */
+	if (fdt_check_header(gd->fdt_blob))
+		panic("No valid fdt found - please append one to U-Boot\n"
+			"binary or define CONFIG_OF_EMBED\n");
+	return 0;
+}
+#endif
+
 /*
  * Breathe some life into the board...
  *
@@ -239,6 +251,9 @@  init_fnc_t *init_sequence[] = {
 #if defined(CONFIG_BOARD_EARLY_INIT_F)
 	board_early_init_f,
 #endif
+#ifdef CONFIG_OF_CONTROL
+	check_fdt,
+#endif
 	timer_init,		/* initialize timer */
 #ifdef CONFIG_FSL_ESDHC
 	get_clocks,
@@ -276,6 +291,13 @@  void board_init_f(ulong bootflag)
 	memset((void *)gd, 0, sizeof(gd_t));
 
 	gd->mon_len = _bss_end_ofs;
+#ifdef CONFIG_OF_EMBED
+	/* Get a pointer to the FDT */
+	gd->fdt_blob = _binary_dt_dtb_start;
+#elif defined CONFIG_OF_SEPARATE
+	/* FDT is at end of image */
+	gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE);
+#endif
 
 	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
 		if ((*init_fnc_ptr)() != 0) {