]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
Allow boards to initialize the DT at runtime.
authorAlex Deymo <deymo@google.com>
Sun, 2 Apr 2017 08:25:20 +0000 (01:25 -0700)
committerTom Rini <trini@konsulko.com>
Wed, 10 May 2017 00:35:06 +0000 (20:35 -0400)
In some boards like the Raspberry Pi the initial bootloader will pass
a DT to the kernel. When using U-Boot as such kernel, the board code in
U-Boot should be able to provide U-Boot with this, already assembled
device tree blob.

This patch introduces a new config option CONFIG_OF_BOARD to use instead
of CONFIG_OF_EMBED or CONFIG_OF_SEPARATE which will initialize the DT
from a board-specific funtion instead of bundling one with U-Boot or as
a separated file. This allows boards like the Raspberry Pi to reuse the
device tree passed from the bootcode.bin and start.elf firmware
files, including the run-time selected device tree overlays.

Signed-off-by: Alex Deymo <deymo@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
README
board/raspberrypi/rpi/rpi.c
doc/README.fdt-control
dts/Kconfig
include/fdtdec.h
lib/fdtdec.c

diff --git a/README b/README
index 78173e2d867054bfeb02438550da166d000912fb..685a8222b0dd3a3304f087821d9a7db088d3be93 100644 (file)
--- a/README
+++ b/README
@@ -968,7 +968,7 @@ The following options need to be configured:
                tree is available in the global data as gd->fdt_blob.
 
                U-Boot needs to get its device tree from somewhere. This can
-               be done using one of the two options below:
+               be done using one of the three options below:
 
                CONFIG_OF_EMBED
                If this variable is defined, U-Boot will embed a device tree
@@ -989,6 +989,12 @@ The following options need to be configured:
                still use the individual files if you need something more
                exotic.
 
+               CONFIG_OF_BOARD
+               If this variable is defined, U-Boot will use the device tree
+               provided by the board at runtime instead of embedding one with
+               the image. Only boards defining board_fdt_blob_setup() support
+               this option (see include/fdtdec.h file).
+
 - Watchdog:
                CONFIG_WATCHDOG
                If this variable is defined, it enables watchdog
index 82da9e5a5a8e1c81cff20863369226bcca5f88af..d3c6ba580f5cadf7e1b387a2d580424c5dcde138 100644 (file)
@@ -470,6 +470,16 @@ int board_init(void)
        return bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
 }
 
+/*
+ * If the firmware passed a device tree use it for U-Boot.
+ */
+void *board_fdt_blob_setup(void)
+{
+       if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
+               return NULL;
+       return (void *)fw_dtb_pointer;
+}
+
 int ft_board_setup(void *blob, bd_t *bd)
 {
        /*
index c9656299053b4e21a0ae0cadb71b8249e322afb3..378b06b108d9e8bb7c834d585f0e1342eb7b0f46 100644 (file)
@@ -130,6 +130,10 @@ u-boot-dtb.bin which does the above step for you also. If you are using
 CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device
 tree binary.
 
+If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
+device tree at runtime, for example if an earlier bootloader stage creates
+it and passes it to U-Boot.
+
 If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
 startup. This is only useful for sandbox. Use the -d flag to U-Boot to
 specify the file to read.
index 6fe7a5bc08adf4caccbf3bccc9cb9ca4283b599f..9a0622154ad0befb28ba76509b6a310e7dfe089d 100644 (file)
@@ -51,6 +51,14 @@ config OF_EMBED
          and development only and is not recommended for production devices.
          Boards in the mainline U-Boot tree should not use it.
 
+config OF_BOARD
+       bool "Provided by the board at runtime"
+       depends on !SANDBOX
+       help
+         If this option is enabled, the device tree will be provided by
+         the board at runtime if the board supports it, instead of being
+         bundled with the image.
+
 config OF_HOSTFILE
        bool "Host filed DTB for DT control"
        depends on SANDBOX
index 2134701c547275e16d280923a0de7733997edbcf..b0e5b2767de3204b12e937263d60826f1b7d2a9a 100644 (file)
@@ -1023,4 +1023,10 @@ int fdtdec_setup_memory_banksize(void);
  */
 int fdtdec_setup(void);
 
+/**
+ * Board-specific FDT initialization. Returns the address to a device tree blob.
+ * Called when CONFIG_OF_BOARD is defined.
+ */
+void *board_fdt_blob_setup(void);
+
 #endif
index 94372cc6cd5a08023c46a2fb21ff46e2c2420847..c072e54cffa6f9c3ac1955d806bb809f45d024f8 100644 (file)
@@ -1255,6 +1255,9 @@ int fdtdec_setup(void)
        /* FDT is at end of image */
        gd->fdt_blob = (ulong *)&_end;
 #  endif
+# elif defined(CONFIG_OF_BOARD)
+       /* Allow the board to override the fdt address. */
+       gd->fdt_blob = board_fdt_blob_setup();
 # elif defined(CONFIG_OF_HOSTFILE)
        if (sandbox_read_fdt_from_file()) {
                puts("Failed to read control FDT\n");