[U-Boot] [PATCH PATCH v3 01/12] spl: fit: Add support for applying DT overlay

Jean-Jacques Hiblot jjhiblot at ti.com
Thu May 23 10:39:01 UTC 2019


From: Michal Simek <michal.simek at xilinx.com>

doc/uImage.FIT/overlay-fdt-boot.txt is describing how to create FIT
image with DT overlays in it.
Add support for this feature to SPL.

Here is the ZynqMP fragment where dtb points to full DT and dtbo is
overlay which should be applied on the top of dtb.
config {
        description = "ATF with full u-boot overlay";
        firmware = "atf";
        loadables = "uboot";
        fdt = "dtb", "dtbo";
};

The whole feature depends on OF_LIBFDT_OVERLAY which is adding +4kB code
and 0 for platforms which are not enabling this feature.

Signed-off-by: Michal Simek <michal.simek at xilinx.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>

---

Changes in v3:
- Add a new config option: SPL_LOAD_FIT_APPLY_OVERLAY. By default, it is
not selected.

Changes in v2: None

 Kconfig              | 10 ++++++++++
 common/spl/spl_fit.c | 27 +++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/Kconfig b/Kconfig
index 5f5c5ccfd6..8197c9066a 100644
--- a/Kconfig
+++ b/Kconfig
@@ -398,6 +398,16 @@ config SPL_LOAD_FIT
 	  particular it can handle selecting from multiple device tree
 	  and passing the correct one to U-Boot.
 
+config SPL_LOAD_FIT_APPLY_OVERLAY
+	bool "Enable SPL applying DT overlays from FIT"
+	depends on SPL_LOAD_FIT
+	select OF_LIBFDT_OVERLAY
+	default n
+	help
+	  The device tree is loaded from the FIT image. Allow the SPL is to
+	  also load device-tree overlays from the FIT image an apply them
+	  over the device tree.
+
 config SPL_LOAD_FIT_FULL
 	bool "Enable SPL loading U-Boot as a FIT"
 	select SPL_FIT
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 87ecf0bb9e..3fbcb969f8 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -278,10 +278,10 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 			      void *fit, int images, ulong base_offset)
 {
 	struct spl_image_info image_info;
-	int node, ret;
+	int node, ret, index = 0;
 
 	/* Figure out which device tree the board wants to use */
-	node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, 0);
+	node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, index++);
 	if (node < 0) {
 		debug("%s: cannot find FDT node\n", __func__);
 		return node;
@@ -303,8 +303,31 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 #if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
 	/* Try to make space, so we can inject details on the loadables */
 	ret = fdt_shrink_to_minimum(spl_image->fdt_addr, 8192);
+	if (ret < 0)
+		return ret;
 #endif
+#if defined(CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY)
+	for (; ; index++) {
+		node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, index);
+		if (node < 0) {
+			debug("%s: No additional FDT node\n", __func__);
+			return 0;
+		}
 
+		ret = spl_load_fit_image(info, sector, fit, base_offset, node,
+					 &image_info);
+		if (ret < 0)
+			return ret;
+
+		ret = fdt_overlay_apply_verbose(spl_image->fdt_addr,
+						(void *)image_info.load_addr);
+		if (ret)
+			return ret;
+
+		debug("%s: DT overlay %s applied\n", __func__,
+		      fit_get_name(fit, node, NULL));
+	}
+#endif
 	return ret;
 }
 
-- 
2.17.1



More information about the U-Boot mailing list