diff mbox series

[v7,29/31] fdt: Add a Kconfig for boards with a prior stage

Message ID 20211207001209.3467163-29-sjg@chromium.org
State Changes Requested
Delegated to: Tom Rini
Headers show
Series fdt: Make OF_BOARD a boolean option | expand

Commit Message

Simon Glass Dec. 7, 2021, 12:12 a.m. UTC
When U-Boot is started from another firmware program, not just a prior
phase of U-Boot, special behaviour is typically used. In particular, the
device tree may come from that prior stage.

At present this is sort-of indicated by OF_BOARD, although the
correlation is not 1:1, since that option simply means that the board has
a custom mechanism for obtaining the device tree. For example, sandbox
defines OF_BOARD. Also the board_fdt_blob_setup() function can in fact
make use of the devicetree in U-Boot if it wishes, as used by
dragonboard410c until very recently.

Add an explicit Kconfig for this situation. Define it for boards which
use this feature. Update the OF_BOARD option to more-accurately reflect
what it is doing, e.g. for sandbox.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v7:
- Add new patch to add a Kconfig for boards with a prior stage

 arch/arm/Kconfig                   |  8 ++++++++
 arch/arm/mach-bcm283x/Kconfig      |  1 +
 board/emulation/qemu-riscv/Kconfig |  1 +
 dts/Kconfig                        | 31 ++++++++++++++++++++++++++----
 lib/fdtdec.c                       |  1 +
 5 files changed, 38 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index eed27af74e8..d26461029af 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -635,6 +635,7 @@  config ARCH_BCMSTB
 	select GPIO_EXTRA_HEADER
 	select OF_CONTROL
 	imply CMD_DM
+	imply OF_HAS_PRIOR_STAGE
 	help
 	  This enables support for Broadcom ARM-based set-top box
 	  chipsets, including the 7445 family of chips.
@@ -713,6 +714,7 @@  config ARCH_HIGHBANK
 	select AHCI
 	select DM_ETH
 	select PHYS_64BIT
+	imply OF_HAS_PRIOR_STAGE
 
 config ARCH_INTEGRATOR
 	bool "ARM Ltd. Integrator family"
@@ -966,6 +968,7 @@  config ARCH_QEMU
 	imply DM_RNG
 	imply DM_RTC
 	imply RTC_PL031
+	imply OF_HAS_PRIOR_STAGE
 
 config ARCH_RMOBILE
 	bool "Renesas ARM SoCs"
@@ -1251,6 +1254,7 @@  config TARGET_VEXPRESS64_JUNO
 	select DM_ETH
 	select BLK
 	select USB
+	imply OF_HAS_PRIOR_STAGE
 
 config TARGET_TOTAL_COMPUTE
 	bool "Support Total Compute Platform"
@@ -1907,6 +1911,7 @@  config ARCH_OCTEONTX
 	select OF_LIVE
 	select BOARD_LATE_INIT
 	select SYS_CACHE_SHIFT_7
+	imply OF_HAS_PRIOR_STAGE
 
 config ARCH_OCTEONTX2
 	bool "Support OcteonTX2 SoCs"
@@ -1918,6 +1923,7 @@  config ARCH_OCTEONTX2
 	select OF_LIVE
 	select BOARD_LATE_INIT
 	select SYS_CACHE_SHIFT_7
+	imply OF_HAS_PRIOR_STAGE
 
 config TARGET_THUNDERX_88XX
 	bool "Support ThunderX 88xx"
@@ -1954,6 +1960,8 @@  config TARGET_XENGUEST_ARM64
 	select LINUX_KERNEL_IMAGE_HEADER
 	select XEN_SERIAL
 	select SSCANF
+	imply OF_HAS_PRIOR_STAGE
+
 endchoice
 
 config SUPPORT_PASSING_ATAGS
diff --git a/arch/arm/mach-bcm283x/Kconfig b/arch/arm/mach-bcm283x/Kconfig
index b3287ce8bce..2eb3802d9ae 100644
--- a/arch/arm/mach-bcm283x/Kconfig
+++ b/arch/arm/mach-bcm283x/Kconfig
@@ -188,6 +188,7 @@  config TARGET_RPI_4
 
 	  This option creates a build targeting the ARMv8/AArch64 ISA.
 	select BCM2711_64B
+	imply OF_HAS_PRIOR_STAGE
 
 config TARGET_RPI_ARM64
 	bool "Raspberry Pi one binary 64-bit build"
diff --git a/board/emulation/qemu-riscv/Kconfig b/board/emulation/qemu-riscv/Kconfig
index 1bbf1bc84af..a380db61a0f 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -65,5 +65,6 @@  config BOARD_SPECIFIC_OPTIONS # dummy
 	imply VIRTIO_BLK
 	imply MTD_NOR_FLASH
 	imply CFI_FLASH
+	imply OF_HAS_PRIOR_STAGE
 
 endif
diff --git a/dts/Kconfig b/dts/Kconfig
index 5dcc79d5192..803d0899556 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -100,11 +100,34 @@  config OF_BOARD
 	bool "Provided by the board (e.g a previous loader) at runtime"
 	default y if SANDBOX
 	help
-	  If this option is enabled, the device tree will be provided by
-	  the board at runtime if the board supports it. The device tree bundled
-	  with the image (if any) will be overridden / ignored.
+	  If this option is enabled, the device tree is provided at runtime by
+	  a custom function called board_fdt_blob_setup(). The board must
+	  implement this function if it wishes to provide special behaviour.
 
-	  A device tree file must be provided in the tree.
+	  With this option, the device tree build by U-Boot may be overridden or
+	  ignored. See OF_HAS_PRIOR_STAGE.
+
+	  Note: Boards which use this to handle a device tree passed from an
+	  earlier stage should enable OF_HAS_PRIOR_STAGE.
+
+config OF_HAS_PRIOR_STAGE
+	bool
+	help
+	  Indicates that a prior stage of the firmware (before U-Boot proper)
+	  makes use of device tree and this board normally boots with that prior
+	  stage, that provides a devicetree to U-Boot.
+
+	  This means that the device tree built in U-Boot should not be packaged
+	  in the firmware image. Instead, the prior stage's device tree should
+	  be so packaged. At runtime, the prior stage reads this, does any
+	  necessary fix-ups, then passes it to U-Boot. See OF_BOARD.
+
+	  This option does not preclude using the U-Boot device tree, e.g. for
+	  development purposes, but it is not recommended, and likely will not
+	  even work, for production systems.
+
+	  Note: This option must be set in Kconfig and cannot be enabled or
+	  disabled in the board's defconfig file.
 
 config DEFAULT_DEVICE_TREE
 	string "Default Device Tree for DT control"
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 118c100b389..280cda61a72 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1595,6 +1595,7 @@  int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
 	return 0;
 }
 
+/* TODO(sjg@chromium.org): This function should not be weak */
 __weak int fdtdec_board_setup(const void *fdt_blob)
 {
 	return 0;