Skip to contentSkip to conversation

Add support for applications of overlays in SPL

PATCH Superseded Jean-Jacques Hiblot 4 participants 22 messages Sep 20, 2019 – Oct 11, 2019

Subsystems (6)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add support for applications of overlays in SPL

The purpose of this series is to provide the SPL with ability to apply overlays for u-boot.

Our use-case is the support of the daughter boards of the AM65x EVM. In Linux, each board is supported by a unique overlay. The presence of the boards is detected at runtime, and some useful features (like USB) are implemented on those daughter boards. Instead of providing multiple dtbs and fall in a combinatorial pit, we propose to use DT overlays.

Patch #2 "spl: fit: Add support for applying DT overlay" has been posted a few weeks ago by Michal Simek.
Patch #3 to #6 amend Michal's patch.
Patch #7 to #9 are simple fixes for the Makefile
Patch #10 is used to reduce the complexity of the Makefile by having FIT generator scripts provide their dependencies
Patch #12-#13 allow to use the board driver in SPL
Patch #14-#15 adds a way to dynamically select the DT overlays. That is were we would use HW detection to select the required overlays. In that case, the board driver code tells what overlay it needs (it gives the name of the node).

On arm, if overlay are supported, this series increases the size of the SPL by 3.2 kB.

Travis build : https://travis-ci.org/jjhiblot/u-boot/builds/567779404

Changes in v5:
- Do not allocate the buffer if not needed (no overlay).
- Add a Kconfig option for the buffer size
- board_get_fit_loadable() returns an error code instead of a NULL string in case of failure
- reword some commit logs

Changes in v4:
- use CONFIG_IS_ENABLED() instead of #idef
- make sure that the temp buffer is freed in all cases
- Use the board driver infrastructure to get the image names from the board code.
- Remove a patch that passed the board name to the FIT generator. If needed the generator can get it from elsewhere
- Add a fix to not load the firmware twice (once as a firmware and once as a loadable)

Changes in v3:
- Add a new config option: SPL_LOAD_FIT_APPLY_OVERLAY. By default, it is not selected.
- removed the RFC prefix. This work will be needed soon by TI's AM65x platform. and can probably benefit other modular platforms
- removed the last patch that provided an example of how to use this with on a DRA76.
- removed the patch that made u-boot.img a symlink to u-boot.itb because it breaks the build of many platforms (because files required to build the ITB are missing)
- removed the patch to reduce the footprint of the am335x SPL. (already merged)
- Made the boot flow more permissive (don't fail immediately if an overlay is not present) and more verbose when an error occures
- handle the dependencies of the FIT generation in a more generic way
- use a dedicated kconfig option to enable the application of the overlays by the SPL.

Changes in v2:
- depend on SPL_DM
- update the commit log
- reworked board_fit_get_additionnal_images() and how it used in spl_fit.c
- removed dtbo generation from dtso files and use .dts extension for the overlays
- add dynamic allocation usage in a separate patch
- defconfig change for the am335x_evm

Jean-Jacques Hiblot (14):
spl: fit: don't load the firmware twice
spl: fit: Make room in the FDT before applying overlays
spl: fit: allocate a temporary buffer to load the overlays
spl: fit: Do not fail immediately if an overlay is not available
spl: fit: be more verbose when an error occurs when applying the
overlays
Makefile.lib: include /__symbols__ in dtb if
SPL_LOAD_FIT_APPLY_OVERLAY is enabled
Makefile: Fix tests for CONFIG_SPL_LOAD_FIT and
CONFIG_SPL_FIT_GENERATOR
Makefile: Fix u-boot.itb generation when building outside the source
tree
Makefile: Query the SPL Fit Generator for its dependencies
spl: fit: constify the output parameter of spl_fit_get_image_name()
drivers: board: Make the board drivers available in SPL
drivers: board: Add get_fit_loadable()
include: board: provide empty stubs when the BOARD option is not
selected
spl: fit: Allow the board to tell if more images must be loaded from
FIT

Michal Simek (1):
spl: fit: Add support for applying DT overlay

 Kconfig                                       |  18 +++
 Makefile                                      |  23 ++--
 arch/arm/mach-imx/mkimage_fit_atf.sh          |   5 +
 arch/arm/mach-rockchip/make_fit_atf.py        |   7 ++
 board/sunxi/mksunxi_fit_atf.sh                |   4 +
 .../lion_rk3368/fit_spl_atf.its               |   6 +-
 .../puma_rk3399/fit_spl_atf.sh                |   6 +
 common/spl/spl_fit.c                          | 113 ++++++++++++++++--
 drivers/Makefile                              |   2 +-
 drivers/board/Kconfig                         |   3 +
 drivers/board/Makefile                        |   2 +-
 drivers/board/board-uclass.c                  |  11 ++
 include/board.h                               |  74 ++++++++++++
 scripts/Makefile.lib                          |   4 +
 14 files changed, 251 insertions(+), 27 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v5 1/15 spl: fit: don't load the firmware twice

When u-boot.img is a FIT image generated automatically by mkimage, the configuration node has the following structure:
conf-1 {
description = "k3-am654-base-board";
firmware = "firmware-1";
loadables = "firmware-1";
fdt = "fdt-1";
};

The firmware is referenced twice. Once by the 'firmware' property and once by the 'loadables' property. Currently this result in the firmware being loaded twice. This is not a big problem but has an impact on the boot time.
Fixing it by not loading a loadable image if it is also the firmware image.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/spl/spl_fit.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
common/spl/spl_fit.c +10 -0
index b3e3ccd5a2..ee037134a8 100644
@@ -373,6 +373,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 	int images, ret;
 	int base_offset, hsize, align_len = ARCH_DMA_MINALIGN - 1;
 	int index = 0;
+	int firmware_node;
 
 	/*
 	 * For FIT with external data, figure out where the external images
@@ -502,6 +503,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 		spl_fit_append_fdt(spl_image, info, sector, fit,
 				   images, base_offset);
 
+	firmware_node = node;
 	/* Now check if there are more images for us to load */
 	for (; ; index++) {
 		uint8_t os_type = IH_OS_INVALID;
@@ -510,6 +512,14 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 		if (node < 0)
 			break;
 
+		/*
+		 * if the firmware is also a loadable, skip it because
+		 * it already has been loaded. This is typically the case with
+		 * u-boot.img generated by mkimage.
+		 */
+		if (firmware_node == node)
+			continue;
+
 		ret = spl_load_fit_image(info, sector, fit, base_offset, node,
 					 &image_info);
 		if (ret < 0)
Signature · 1 line
2.17.1
#2 lore raw

PATCH v5 2/15 spl: fit: Add support for applying DT overlay

In reply to Jean-Jacques Hiblot

From: Michal Simek <[email protected]>

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.

---

Changes in v5: None
Changes in v4:
- use CONFIG_IS_ENABLED() instead of #idef

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

Changes in v2: None

 Kconfig              |  9 +++++++++
 common/spl/spl_fit.c | 30 +++++++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 3 deletions(-)
Kconfig +9 -0
index 1f0904f704..825f096807 100644
@@ -428,6 +428,15 @@ 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
+	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 (full fitImage features)"
 	select SPL_FIT
common/spl/spl_fit.c +27 -3
index ee037134a8..569110f3ac 100644
@@ -281,7 +281,7 @@ 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 = 0;
+	int node, ret = 0, index = 0;
 
 	/*
 	 * Use the address following the image as target address for the
@@ -290,7 +290,7 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 	image_info.load_addr = spl_image->load_addr + spl_image->size;
 
 	/* 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__);
 
@@ -315,8 +315,32 @@ 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 (CONFIG_IS_ENABLED(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));
+		}
+	}
 	return ret;
 }
 
Signature · 1 line
2.17.1
#3 lore raw

PATCH v5 3/15 spl: fit: Make room in the FDT before applying overlays

In reply to Jean-Jacques Hiblot

Make room in the FDT before applying the overlay, otherwise it may fail if the overlay is big. As the exact added size is not known in advance, just add the size of the overlay.
Move after the end of the application of the overlays, the resize of the FDT for the injection of the details on the loadables.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/spl/spl_fit.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
common/spl/spl_fit.c +12 -5
index 569110f3ac..95b45aafa2 100644
@@ -313,11 +313,6 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 	/* Make the load-address of the FDT available for the SPL framework */
 	spl_image->fdt_addr = (void *)image_info.load_addr;
 #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 (CONFIG_IS_ENABLED(LOAD_FIT_APPLY_OVERLAY)) {
 		for (; ; index++) {
 			node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP,
@@ -332,6 +327,12 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 			if (ret < 0)
 				return ret;
 
+			/* Make room in FDT for changes from the overlay */
+			ret = fdt_increase_size(spl_image->fdt_addr,
+						image_info.size);
+			if (ret < 0)
+				return ret;
+
 			ret = fdt_overlay_apply_verbose(spl_image->fdt_addr,
 							(void *)image_info.load_addr);
 			if (ret)
@@ -341,6 +342,12 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 			      fit_get_name(fit, node, NULL));
 		}
 	}
+	/* 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
+
 	return ret;
 }
 
Signature · 1 line
2.17.1
#4 lore raw

PATCH v5 4/15 spl: fit: allocate a temporary buffer to load the overlays

In reply to Jean-Jacques Hiblot

If the node describing an overlay does not specify a load address, it will be loaded at the address previously used.
Fixing it by allocating a temporary buffer that will be used as a default load address. By default, the size of the buffer is 64kB which should be plenty for most use cases.

---

Changes in v5:
- Do not allocate the buffer if not needed (no overlay).
- Add a Kconfig option for the buffer size

Changes in v4:
- make sure that the temp buffer is freed in all cases

Changes in v3: None
Changes in v2: None

 Kconfig              |  9 +++++++++
 common/spl/spl_fit.c | 34 +++++++++++++++++++++++++++++-----
 2 files changed, 38 insertions(+), 5 deletions(-)
Kconfig +9 -0
index 825f096807..a41d33de13 100644
@@ -437,6 +437,15 @@ config SPL_LOAD_FIT_APPLY_OVERLAY
 	  also load device-tree overlays from the FIT image an apply them
 	  over the device tree.
 
+config SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ
+	depends on SPL_LOAD_FIT_APPLY_OVERLAY
+	default 0x10000
+	hex "size of temporary buffer used to load the overlays"
+	help
+	  The size of the area where the overlays will be loaded and
+	  uncompress. Must be at least as large as biggest overlay
+	  (uncompressed)
+
 config SPL_LOAD_FIT_FULL
 	bool "Enable SPL loading U-Boot as a FIT (full fitImage features)"
 	select SPL_FIT
common/spl/spl_fit.c +29 -5
index 95b45aafa2..4fdc10c9e2 100644
@@ -9,11 +9,16 @@
 #include <fpga.h>
 #include <gzip.h>
 #include <image.h>
-#include <linux/libfdt.h>
+#include <malloc.h>
 #include <spl.h>
+#include <linux/libfdt.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#ifndef CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ
+#define CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ (64 * 1024)
+#endif
+
 #ifndef CONFIG_SYS_BOOTM_LEN
 #define CONFIG_SYS_BOOTM_LEN	(64 << 20)
 #endif
@@ -314,33 +319,52 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 	spl_image->fdt_addr = (void *)image_info.load_addr;
 #if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
 	if (CONFIG_IS_ENABLED(LOAD_FIT_APPLY_OVERLAY)) {
+		void *tmpbuffer = NULL;
+
 		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;
+				break;
 			}
 
+			if (!tmpbuffer) {
+				/*
+				 * allocate memory to store the DT overlay
+				 * before it is applied. It may not be used
+				 * depending on how the overlay is stored, so
+				 * don't fail yet if the allocation failed.
+				 */
+				tmpbuffer = malloc(CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ);
+				if (!tmpbuffer)
+					debug("%s: unable to allocate space for overlays\n",
+					      __func__);
+			}
+			image_info.load_addr = (ulong)tmpbuffer;
 			ret = spl_load_fit_image(info, sector, fit, base_offset,
 						 node, &image_info);
 			if (ret < 0)
-				return ret;
+				break;
 
 			/* Make room in FDT for changes from the overlay */
 			ret = fdt_increase_size(spl_image->fdt_addr,
 						image_info.size);
 			if (ret < 0)
-				return ret;
+				break;
 
 			ret = fdt_overlay_apply_verbose(spl_image->fdt_addr,
 							(void *)image_info.load_addr);
 			if (ret)
-				return ret;
+				break;
 
 			debug("%s: DT overlay %s applied\n", __func__,
 			      fit_get_name(fit, node, NULL));
 		}
+		if (tmpbuffer)
+			free(tmpbuffer);
+		if (ret)
+			return ret;
 	}
 	/* Try to make space, so we can inject details on the loadables */
 	ret = fdt_shrink_to_minimum(spl_image->fdt_addr, 8192);
Signature · 1 line
2.17.1
#5 lore raw

PATCH v5 5/15 spl: fit: Do not fail immediately if an overlay is not available

In reply to Jean-Jacques Hiblot

If one overlay that must be applied cannot be found in the FIT, the current implementation stops applying the overlays. Let's make it skip only the failing overlay instead.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/spl/spl_fit.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
common/spl/spl_fit.c +5 -1
index 4fdc10c9e2..187dd5ab3f 100644
@@ -324,9 +324,13 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 		for (; ; index++) {
 			node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP,
 						      index);
-			if (node < 0) {
+			if (node == -E2BIG) {
 				debug("%s: No additional FDT node\n", __func__);
 				break;
+			} else if (node < 0) {
+				debug("%s: unable to find FDT node %d\n",
+				      __func__, index);
+				continue;
 			}
 
 			if (!tmpbuffer) {
Signature · 1 line
2.17.1
#6 lore raw

PATCH v5 6/15 spl: fit: be more verbose when an error occurs when applying the overlays

In reply to Jean-Jacques Hiblot

There are many ways the overlay application can fail.
2 of them are probably the most common:
- the application itself failed. Usually this is comes from an unresolved reference
- DTBO not available in FIT (could be because of a typo)

In both case it is good to be more explicit about the error and at least show which overlay is failing.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/spl/spl_fit.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
common/spl/spl_fit.c +5 -2
index 187dd5ab3f..cdbba3705d 100644
@@ -113,7 +113,7 @@ static int spl_fit_get_image_node(const void *fit, int images,
 
 	node = fdt_subnode_offset(fit, images, str);
 	if (node < 0) {
-		debug("cannot find image node '%s': %d\n", str, node);
+		pr_err("cannot find image node '%s': %d\n", str, node);
 		return -EINVAL;
 	}
 
@@ -359,8 +359,11 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 
 			ret = fdt_overlay_apply_verbose(spl_image->fdt_addr,
 							(void *)image_info.load_addr);
-			if (ret)
+			if (ret) {
+				pr_err("failed to apply DT overlay %s\n",
+				       fit_get_name(fit, node, NULL));
 				break;
+			}
 
 			debug("%s: DT overlay %s applied\n", __func__,
 			      fit_get_name(fit, node, NULL));
Signature · 1 line
2.17.1
#7 lore raw

PATCH v5 7/15 Makefile.lib: include /__symbols__ in dtb if SPL_LOAD_FIT_APPLY_OVERLAY is enabled

In reply to Jean-Jacques Hiblot

In order to apply an overlay to a DTB. The DTB must have been generated with the option '-@'.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 scripts/Makefile.lib | 4 ++++
 1 file changed, 4 insertions(+)
scripts/Makefile.lib +4 -0
index ef116e0e0a..6946da6aa4 100644
@@ -292,6 +292,10 @@ cmd_dt_S_dtb=						\
 $(obj)/%.dtb.S: $(obj)/%.dtb
 	$(call cmd,dt_S_dtb)
 
+ifeq ($(CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY),y)
+DTC_FLAGS += -@
+endif
+
 quiet_cmd_dtc = DTC     $@
 # Modified for U-Boot
 # Bring in any U-Boot-specific include at the end of the file
Signature · 1 line
2.17.1
#8 lore raw

PATCH v5 8/15 Makefile: Fix tests for CONFIG_SPL_LOAD_FIT and CONFIG_SPL_FIT_GENERATOR

In reply to Jean-Jacques Hiblot

The current tests do to handle well the cases where those variables are not defined. When CONFIG_SPL_LOAD_FIT is not defined, U_BOOT_ITS gets defined as an empty string.
Fixing it by using intermediate variables with the quotes removed

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 Makefile | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Makefile +7 -4
index 57d0700227..2f118affe9 100644
@@ -1224,12 +1224,15 @@ ifndef CONFIG_SYS_UBOOT_START
 CONFIG_SYS_UBOOT_START := 0
 endif
 
+
 # Boards with more complex image requirments can provide an .its source file
 # or a generator script
-ifneq ($(CONFIG_SPL_FIT_SOURCE),"")
-U_BOOT_ITS = $(subst ",,$(CONFIG_SPL_FIT_SOURCE))
+SPL_FIT_SOURCE := $(subst ",,$(CONFIG_SPL_FIT_SOURCE))
+SPL_FIT_GENERATOR := $(subst ",,$(CONFIG_SPL_FIT_GENERATOR))
+ifneq ($(SPL_FIT_SOURCE),)
+U_BOOT_ITS = $(SPL_FIT_SOURCE)
 else
-ifneq ($(CONFIG_SPL_FIT_GENERATOR),"")
+ifneq ($(SPL_FIT_GENERATOR),)
 U_BOOT_ITS := u-boot.its
 ifeq ($(CONFIG_SPL_FIT_GENERATOR),"arch/arm/mach-imx/mkimage_fit_atf.sh")
 U_BOOT_ITS_DEPS += u-boot-nodtb.bin
@@ -1238,7 +1241,7 @@ ifeq ($(CONFIG_SPL_FIT_GENERATOR),"arch/arm/mach-rockchip/make_fit_atf.py")
 U_BOOT_ITS_DEPS += u-boot
 endif
 $(U_BOOT_ITS): $(U_BOOT_ITS_DEPS) FORCE
-	$(srctree)/$(CONFIG_SPL_FIT_GENERATOR) \
+	$(srctree)/$(SPL_FIT_GENERATOR) \
 	$(patsubst %,arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) > $@
 endif
 endif
Signature · 1 line
2.17.1
#9 lore raw

PATCH v5 9/15 Makefile: Fix u-boot.itb generation when building outside the source tree

In reply to Jean-Jacques Hiblot

Include the object tree and the source tree in the search path of the FIT compîler (dtc). This allows to use paths relative to the root of the source or object trees in the ITS instead of working backward from the actual location of the ITS.
It also allows to use a build directory different of the source directory.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 Makefile                                            | 5 +++--
 board/theobroma-systems/lion_rk3368/fit_spl_atf.its | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)
Makefile +3 -2
index 2f118affe9..8a28740b22 100644
@@ -914,7 +914,8 @@ cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
 	>$(MKIMAGEOUTPUT) $(if $(KBUILD_VERBOSE:0=), && cat $(MKIMAGEOUTPUT))
 
 quiet_cmd_mkfitimage = MKIMAGE $@
-cmd_mkfitimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -f $(U_BOOT_ITS) -p $(CONFIG_FIT_EXTERNAL_OFFSET) $@\
+cmd_mkfitimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -D "-i $(obj) -i $(src)"\
+	-f $(U_BOOT_ITS) $@ -p $(CONFIG_FIT_EXTERNAL_OFFSET)\
 	>$(MKIMAGEOUTPUT) $(if $(KBUILD_VERBOSE:0=), && cat $(MKIMAGEOUTPUT))
 
 quiet_cmd_cat = CAT     $@
@@ -1230,7 +1231,7 @@ endif
 SPL_FIT_SOURCE := $(subst ",,$(CONFIG_SPL_FIT_SOURCE))
 SPL_FIT_GENERATOR := $(subst ",,$(CONFIG_SPL_FIT_GENERATOR))
 ifneq ($(SPL_FIT_SOURCE),)
-U_BOOT_ITS = $(SPL_FIT_SOURCE)
+U_BOOT_ITS = $(src)/$(SPL_FIT_SOURCE)
 else
 ifneq ($(SPL_FIT_GENERATOR),)
 U_BOOT_ITS := u-boot.its
board/theobroma-systems/lion_rk3368/fit_spl_atf.its +3 -3
index 6b04fbc7da..69202a117b 100644
@@ -14,7 +14,7 @@
 	images {
 		uboot {
 			description = "U-Boot (64-bit)";
-			data = /incbin/("../../../u-boot-nodtb.bin");
+			data = /incbin/("u-boot-nodtb.bin");
 			type = "standalone";
 			os = "U-Boot";
 			arch = "arm64";
@@ -23,7 +23,7 @@
 		};
 		atf {
 			description = "ARM Trusted Firmware";
-			data = /incbin/("../../../bl31-rk3368.bin");
+			data = /incbin/("bl31-rk3368.bin");
 			type = "firmware";
 			os = "arm-trusted-firmware";
 			arch = "arm64";
@@ -34,7 +34,7 @@
 
 		fdt {
 			description = "RK3368-uQ7 (Lion) flat device-tree";
-			data = /incbin/("../../../u-boot.dtb");
+			data = /incbin/("u-boot.dtb");
 			type = "flat_dt";
 			compression = "none";
 		};
Signature · 1 line
2.17.1
#10 lore raw

PATCH v5 10/15 Makefile: Query the SPL Fit Generator for its dependencies

In reply to Jean-Jacques Hiblot

To reduce the complexity of the Makefile, let the generator tell what its dependencies are. For this purpose use the "--deps" option.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 Makefile                                           | 9 ++-------
 arch/arm/mach-imx/mkimage_fit_atf.sh               | 5 +++++
 arch/arm/mach-rockchip/make_fit_atf.py             | 7 +++++++
 board/sunxi/mksunxi_fit_atf.sh                     | 4 ++++
 board/theobroma-systems/puma_rk3399/fit_spl_atf.sh | 6 ++++++
 5 files changed, 24 insertions(+), 7 deletions(-)
Makefile +2 -7
index 8a28740b22..1fa63d2a6b 100644
@@ -1235,13 +1235,8 @@ U_BOOT_ITS = $(src)/$(SPL_FIT_SOURCE)
 else
 ifneq ($(SPL_FIT_GENERATOR),)
 U_BOOT_ITS := u-boot.its
-ifeq ($(CONFIG_SPL_FIT_GENERATOR),"arch/arm/mach-imx/mkimage_fit_atf.sh")
-U_BOOT_ITS_DEPS += u-boot-nodtb.bin
-endif
-ifeq ($(CONFIG_SPL_FIT_GENERATOR),"arch/arm/mach-rockchip/make_fit_atf.py")
-U_BOOT_ITS_DEPS += u-boot
-endif
-$(U_BOOT_ITS): $(U_BOOT_ITS_DEPS) FORCE
+U_BOOT_ITS_DEPS += $(shell $(srctree)/$(SPL_FIT_GENERATOR) --deps $(BOARD))
+$(U_BOOT_ITS): u-boot-nodtb.bin $(U_BOOT_ITS_DEPS) FORCE
 	$(srctree)/$(SPL_FIT_GENERATOR) \
 	$(patsubst %,arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) > $@
 endif
arch/arm/mach-imx/mkimage_fit_atf.sh +5 -0
index 38c9858e84..4da7531954 100755
@@ -11,6 +11,11 @@
 [ -z "$ATF_LOAD_ADDR" ] && ATF_LOAD_ADDR="0x00910000"
 [ -z "$BL33_LOAD_ADDR" ] && BL33_LOAD_ADDR="0x40200000"
 
+
+if [ x"$1" = x"--deps" ]; then
+	exit 0
+fi
+
 if [ ! -f $BL31 ]; then
 	echo "ERROR: BL31 file $BL31 NOT found" >&2
 	exit 0
arch/arm/mach-rockchip/make_fit_atf.py +7 -0
index b9a1988298..56fab4e330 100755
@@ -163,6 +163,10 @@ def unpack_elf(filename):
             segments.append((index, e_entry, p_paddr, p_data))
     return segments
 
+def show_deps_and_exit():
+	print("u-boot")
+	sys.exit(0)
+
 def main():
     uboot_elf = "./u-boot"
     fit_its = sys.stdout
@@ -178,6 +182,9 @@ def main():
         logging.warning(' BL31 file bl31.elf NOT found, resulting binary is non-functional')
         logging.warning(' Please read Building section in doc/README.rockchip')
 
+    if sys.argv[1] == "--deps":
+	    show_deps_and_exit()
+
     opts, args = getopt.getopt(sys.argv[1:], "o:u:b:h")
     for opt, val in opts:
         if opt == "-o":
board/sunxi/mksunxi_fit_atf.sh +4 -0
index 88ad719747..c0ce4394e2 100755
@@ -5,6 +5,10 @@
 #
 # usage: $0 <dt_name> [<dt_name> [<dt_name] ...]
 
+if [ x"$1" = x"--deps" ]; then
+	exit 0
+fi
+
 [ -z "$BL31" ] && BL31="bl31.bin"
 
 if [ ! -f $BL31 ]; then
board/theobroma-systems/puma_rk3399/fit_spl_atf.sh +6 -0
index 420e7daf4c..a7bada193a 100755
@@ -11,6 +11,12 @@
 #
 # usage: $0 <dt_name> [<dt_name> [<dt_name] ...]
 
+
+if [ x"$1" = x"--deps" ]; then
+	echo "u-boot.dtb"
+	exit 0
+fi
+
 [ -z "$BL31" ] && BL31="bl31.bin"
 
 if [ ! -f $BL31 ]; then
Signature · 1 line
2.17.1
#11 lore raw

PATCH v5 10/15 Makefile: Query the SPL Fit Generator for its dependencies

Hi Jean-Jacques,

Quoted 3 lines · Jean-Jacques Hiblot

To reduce the complexity of the Makefile, let the generator tell what its dependencies are. For this purpose use the "--deps" option.

We recently added a generic FIT generator script for RISC-V, located at arch/riscv/lib/mkimage_fit_opensbi.sh . Can you add the --deps option to that script as well? It does not have any dependencies, so it can be handled the same way as in the i.MX and sunxi FIT generator scripts.

Thanks,
Lukas

Quoted 109 lines

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 Makefile                                           | 9 ++-------
 arch/arm/mach-imx/mkimage_fit_atf.sh               | 5 +++++
 arch/arm/mach-rockchip/make_fit_atf.py             | 7 +++++++
 board/sunxi/mksunxi_fit_atf.sh                     | 4 ++++
 board/theobroma-systems/puma_rk3399/fit_spl_atf.sh | 6 ++++++
 5 files changed, 24 insertions(+), 7 deletions(-)
Makefile +2 -7
index 8a28740b22..1fa63d2a6b 100644
@@ -1235,13 +1235,8 @@ U_BOOT_ITS = $(src)/$(SPL_FIT_SOURCE)
 else
 ifneq ($(SPL_FIT_GENERATOR),)
 U_BOOT_ITS := u-boot.its
-ifeq ($(CONFIG_SPL_FIT_GENERATOR),"arch/arm/mach-imx/mkimage_fit_atf.sh")
-U_BOOT_ITS_DEPS += u-boot-nodtb.bin
-endif
-ifeq ($(CONFIG_SPL_FIT_GENERATOR),"arch/arm/mach-rockchip/make_fit_atf.py")
-U_BOOT_ITS_DEPS += u-boot
-endif
-$(U_BOOT_ITS): $(U_BOOT_ITS_DEPS) FORCE
+U_BOOT_ITS_DEPS += $(shell $(srctree)/$(SPL_FIT_GENERATOR) --deps $(BOARD))
+$(U_BOOT_ITS): u-boot-nodtb.bin $(U_BOOT_ITS_DEPS) FORCE
 	$(srctree)/$(SPL_FIT_GENERATOR) \
 	$(patsubst %,arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) > $@
 endif
arch/arm/mach-imx/mkimage_fit_atf.sh +5 -0
index 38c9858e84..4da7531954 100755
@@ -11,6 +11,11 @@
 [ -z "$ATF_LOAD_ADDR" ] && ATF_LOAD_ADDR="0x00910000"
 [ -z "$BL33_LOAD_ADDR" ] && BL33_LOAD_ADDR="0x40200000"
 
+
+if [ x"$1" = x"--deps" ]; then
+	exit 0
+fi
+
 if [ ! -f $BL31 ]; then
 	echo "ERROR: BL31 file $BL31 NOT found" >&2
 	exit 0
arch/arm/mach-rockchip/make_fit_atf.py +7 -0
index b9a1988298..56fab4e330 100755
@@ -163,6 +163,10 @@ def unpack_elf(filename):
             segments.append((index, e_entry, p_paddr, p_data))
     return segments
 
+def show_deps_and_exit():
+	print("u-boot")
+	sys.exit(0)
+
 def main():
     uboot_elf = "./u-boot"
     fit_its = sys.stdout
@@ -178,6 +182,9 @@ def main():
         logging.warning(' BL31 file bl31.elf NOT found, resulting binary is non-functional')
         logging.warning(' Please read Building section in doc/README.rockchip')
 
+    if sys.argv[1] == "--deps":
+	    show_deps_and_exit()
+
     opts, args = getopt.getopt(sys.argv[1:], "o:u:b:h")
     for opt, val in opts:
         if opt == "-o":
board/sunxi/mksunxi_fit_atf.sh +4 -0
index 88ad719747..c0ce4394e2 100755
@@ -5,6 +5,10 @@
 #
 # usage: $0 <dt_name> [<dt_name> [<dt_name] ...]
 
+if [ x"$1" = x"--deps" ]; then
+	exit 0
+fi
+
 [ -z "$BL31" ] && BL31="bl31.bin"
 
 if [ ! -f $BL31 ]; then
board/theobroma-systems/puma_rk3399/fit_spl_atf.sh +6 -0
index 420e7daf4c..a7bada193a 100755
@@ -11,6 +11,12 @@
 #
 # usage: $0 <dt_name> [<dt_name> [<dt_name] ...]
 
+
+if [ x"$1" = x"--deps" ]; then
+	echo "u-boot.dtb"
+	exit 0
+fi
+
 [ -z "$BL31" ] && BL31="bl31.bin"
 
 if [ ! -f $BL31 ]; then
#12 lore raw

PATCH v5 10/15 Makefile: Query the SPL Fit Generator for its dependencies

Quoted 11 lines · Lukas

Hi Jean-Jacques,

Quoted 3 lines · Jean-Jacques Hiblot

To reduce the complexity of the Makefile, let the generator tell what its dependencies are. For this purpose use the "--deps" option.

We recently added a generic FIT generator script for RISC-V, located at arch/riscv/lib/mkimage_fit_opensbi.sh . Can you add the --deps option to that script as well? It does not have any dependencies, so it can be handled the same way as in the i.MX and sunxi FIT generator scripts.

Can we please work on generalizing these scripts and either using binman, updating binman as needed or coming up with a POSIX SH tool that can do what needs doing? Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191006/7d51c29a/attachment.sig>
#13 lore raw

PATCH v5 10/15 Makefile: Query the SPL Fit Generator for its dependencies

Quoted 7 lines · Tom Rini
Quoted 6 lines · Lukas

Hi Jean-Jacques,

Quoted 3 lines · Jean-Jacques Hiblot

To reduce the complexity of the Makefile, let the generator tell what its dependencies are. For this purpose use the "--deps" option.

Quoted 7 lines
Quoted 4 lines

We recently added a generic FIT generator script for RISC-V, located at arch/riscv/lib/mkimage_fit_opensbi.sh . Can you add the --deps option to that script as well? It does not have any dependencies, so it can be handled the same way as in the i.MX and sunxi FIT generator scripts.

Can we please work on generalizing these scripts and either using binman, updating binman as needed or coming up with a POSIX SH tool that can do what needs doing? Thanks!

Maybe it can be done. But we would need to know first what the needs are.

In may case, all I need is to bundle at build time a set of DTB overlays with u-boot.bin and some DTBs.

For this binman is overkill, using dtc is enough, though I guess binman can be used instead.

JJ

Quoted 1 line
#14 lore raw

PATCH v5 10/15 Makefile: Query the SPL Fit Generator for its dependencies

Quoted 17 lines · Jean-Jacques Hiblot
Quoted 7 lines · Tom Rini
Quoted 6 lines · Lukas

Hi Jean-Jacques,

Quoted 3 lines · Jean-Jacques Hiblot

To reduce the complexity of the Makefile, let the generator tell what its dependencies are. For this purpose use the "--deps" option.

Quoted 7 lines
Quoted 4 lines

We recently added a generic FIT generator script for RISC-V, located at arch/riscv/lib/mkimage_fit_opensbi.sh . Can you add the --deps option to that script as well? It does not have any dependencies, so it can be handled the same way as in the i.MX and sunxi FIT generator scripts.

Can we please work on generalizing these scripts and either using binman, updating binman as needed or coming up with a POSIX SH tool that can do what needs doing? Thanks!

Quoted 7 lines

Maybe it can be done. But we would need to know first what the needs are.

In may case, all I need is to bundle at build time a set of DTB overlays with u-boot.bin and some DTBs.

For this binman is overkill, using dtc is enough, though I guess binman can be used instead.

OK, and in this case we're talking about tools/k3_fit_atf.sh which is based on board/sunxi/mksunxi_fit_atf.sh ? That's two similar but not quite just mergable POSIX SH tools. If we end up with an intermediate state of having tools/generators/ with a number of $(soc)_fit_atf.sh scripts that'll start to make it clearer what is/isn't the same. Maybe we won't have a single tool, but if it's at least make it clearer where things belong and we can get consistency. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191007/60ba5fd6/attachment.sig>
#15 lore raw

PATCH v5 10/15 Makefile: Query the SPL Fit Generator for its dependencies

Quoted 23 lines · Tom Rini
Quoted 15 lines · Jean-Jacques Hiblot
Quoted 7 lines · Tom Rini
Quoted 6 lines · Lukas

Hi Jean-Jacques,

Quoted 3 lines · Jean-Jacques Hiblot

To reduce the complexity of the Makefile, let the generator tell what its dependencies are. For this purpose use the "--deps" option.

Quoted 7 lines
Quoted 4 lines

We recently added a generic FIT generator script for RISC-V, located at arch/riscv/lib/mkimage_fit_opensbi.sh . Can you add the --deps option to that script as well? It does not have any dependencies, so it can be handled the same way as in the i.MX and sunxi FIT generator scripts.

Can we please work on generalizing these scripts and either using binman, updating binman as needed or coming up with a POSIX SH tool that can do what needs doing? Thanks!

Quoted 7 lines

Maybe it can be done. But we would need to know first what the needs are.

In may case, all I need is to bundle at build time a set of DTB overlays with u-boot.bin and some DTBs.

For this binman is overkill, using dtc is enough, though I guess binman can be used instead.

Quoted 7 lines

OK, and in this case we're talking about tools/k3_fit_atf.sh which is based on board/sunxi/mksunxi_fit_atf.sh ? That's two similar but not quite just mergable POSIX SH tools. If we end up with an intermediate state of having tools/generators/ with a number of $(soc)_fit_atf.sh scripts that'll start to make it clearer what is/isn't the same. Maybe we won't have a single tool, but if it's at least make it clearer where things belong and we can get consistency. Thanks!

I see your point. This patch is not essential for this series, so I'll drop this for the time being and try to come up with a better solution when adding SPL overlay support for AM6/J7.

JJ

Quoted 1 line
#16 lore raw

PATCH v5 11/15 spl: fit: constify the output parameter of spl_fit_get_image_name()

In reply to Jean-Jacques Hiblot

There is no need for it to be non-constant. Making it constant, allows to return constant string without warning.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/spl/spl_fit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/spl/spl_fit.c +3 -3
index cdbba3705d..d761cd821f 100644
@@ -46,7 +46,7 @@ __weak ulong board_spl_fit_size_align(ulong size)
  */
 static int spl_fit_get_image_name(const void *fit, int images,
 				  const char *type, int index,
-				  char **outname)
+				  const char **outname)
 {
 	const char *name, *str;
 	__maybe_unused int node;
@@ -101,7 +101,7 @@ static int spl_fit_get_image_name(const void *fit, int images,
 static int spl_fit_get_image_node(const void *fit, int images,
 				  const char *type, int index)
 {
-	char *str;
+	const char *str;
 	int err;
 	int node;
 
@@ -387,7 +387,7 @@ static int spl_fit_record_loadable(const void *fit, int images, int index,
 {
 	int ret = 0;
 #if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
-	char *name;
+	const char *name;
 	int node;
 
 	ret = spl_fit_get_image_name(fit, images, "loadables",
Signature · 1 line
2.17.1
#17 lore raw

PATCH v5 12/15 drivers: board: Make the board drivers available in SPL

In reply to Jean-Jacques Hiblot

Make the board driver available in the SPL too. The board driver is a way to provide useful information about the board and that can be useful in the SPL too.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
- depend on SPL_DM
- update the commit log

 drivers/Makefile       | 2 +-
 drivers/board/Kconfig  | 3 +++
 drivers/board/Makefile | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/Makefile +1 -1
index a4bb5e4975..6dd43d4949 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_$(SPL_TPL_)VIRTIO) += virtio/
 obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox/
 obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/
 obj-$(CONFIG_$(SPL_TPL_)TPM) += tpm/
+obj-$(CONFIG_$(SPL_)BOARD) += board/
 
 ifndef CONFIG_TPL_BUILD
 ifdef CONFIG_SPL_BUILD
@@ -77,7 +78,6 @@ obj-y += ata/
 obj-$(CONFIG_DM_DEMO) += demo/
 obj-$(CONFIG_BIOSEMU) += bios_emulator/
 obj-y += block/
-obj-y += board/
 obj-$(CONFIG_BOOTCOUNT_LIMIT) += bootcount/
 obj-y += cache/
 obj-$(CONFIG_CPU) += cpu/
drivers/board/Kconfig +3 -0
index 2a3fc9c049..254f657049 100644
@@ -8,6 +8,9 @@ menuconfig BOARD
 
 if BOARD
 
+config SPL_BOARD
+	depends on SPL_DM
+	bool "Enable board driver support in SPL"
 
 config BOARD_GAZERBEAM
 	bool "Enable board driver for the Gazerbeam board"
drivers/board/Makefile +1 -1
index c8dab4fa0b..cc16361755 100644
@@ -2,6 +2,6 @@
 #
 # (C) Copyright 2017
 # Mario Six,  Guntermann & Drunck GmbH, mario.six at gdsys.cc
-obj-$(CONFIG_BOARD) += board-uclass.o
+obj-y += board-uclass.o
 obj-$(CONFIG_BOARD_GAZERBEAM) += gazerbeam.o
 obj-$(CONFIG_BOARD_SANDBOX) += sandbox.o
Signature · 1 line
2.17.1
#18 lore raw

PATCH v5 12/15 drivers: board: Make the board drivers available in SPL

Quoted 16 lines · Jean-Jacques Hiblot

Make the board driver available in the SPL too. The board driver is a way to provide useful information about the board and that can be useful in the SPL too.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
- depend on SPL_DM
- update the commit log

Quoted 4 lines
 drivers/Makefile       | 2 +-
 drivers/board/Kconfig  | 3 +++
 drivers/board/Makefile | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)
#19 lore raw

PATCH v5 13/15 drivers: board: Add get_fit_loadable()

In reply to Jean-Jacques Hiblot

This function will be used by the SPL to get the names of images to load from the FIT. This allows to load different images based on runtime HW detection.

---

Changes in v5:
- board_get_fit_loadable() returns an error code instead of a NULL string in case of failure

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/board/board-uclass.c | 11 +++++++++++
 include/board.h              | 37 ++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
drivers/board/board-uclass.c +11 -0
index a516ba4962..b5485e9895 100644
@@ -23,6 +23,17 @@ int board_detect(struct udevice *dev)
 	return ops->detect(dev);
 }
 
+int board_get_fit_loadable(struct udevice *dev, int index,
+			   const char *type, const char **strp)
+{
+	struct board_ops *ops = board_get_ops(dev);
+
+	if (!ops->get_fit_loadable)
+		return -ENOSYS;
+
+	return ops->get_fit_loadable(dev, index, type, strp);
+}
+
 int board_get_bool(struct udevice *dev, int id, bool *val)
 {
 	struct board_ops *ops = board_get_ops(dev);
include/board.h +37 -0
index 9dc78684f8..fd6a486702 100644
@@ -79,6 +79,24 @@ struct board_ops {
 	 * Return: 0 if OK, -ve on error.
 	 */
 	int (*get_str)(struct udevice *dev, int id, size_t size, char *val);
+
+	/**
+	 * get_fit_loadable - Get the name of an image to load from FIT
+	 * This function can be used to provide the image names based on runtime
+	 * detection. A classic use-case would when DTBOs are used to describe
+	 * additionnal daughter cards.
+	 *
+	 * @dev:	The board instance to gather the data.
+	 * @index:	Index of the image. Starts at 0 and gets incremented
+	 *		after each call to this function.
+	 * @type:	The type of image. For example, "fdt" for DTBs
+	 * @strp:	A pointer to string. Untouched if the function fails
+	 *
+	 * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
+	 * error.
+	 */
+	int (*get_fit_loadable)(struct udevice *dev, int index,
+				const char *type, const char **strp);
 };
 
 #define board_get_ops(dev)	((struct board_ops *)(dev)->driver->ops)
@@ -137,3 +155,22 @@ int board_get_str(struct udevice *dev, int id, size_t size, char *val);
  * Return: 0 if OK, -ve on error.
  */
 int board_get(struct udevice **devp);
+
+/**
+ * board_get_fit_loadable - Get the name of an image to load from FIT
+ * This function can be used to provide the image names based on runtime
+ * detection. A classic use-case would when DTBOs are used to describe
+ * additionnal daughter cards.
+ *
+ * @dev:	The board instance to gather the data.
+ * @index:	Index of the image. Starts at 0 and gets incremented
+ *		after each call to this function.
+ * @type:	The type of image. For example, "fdt" for DTBs
+ * @strp:	A pointer to string. Untouched if the function fails
+ *
+ *
+ * Return: 0 if OK, -ENOENT if no loadable is available else -ve on
+ * error.
+ */
+int board_get_fit_loadable(struct udevice *dev, int index,
+			   const char *type, const char **strp);
Signature · 1 line
2.17.1
#20 lore raw

PATCH v5 14/15 include: board: provide empty stubs when the BOARD option is not selected

In reply to Jean-Jacques Hiblot

Useful to avoid #ifdef throughout the code that uses the board driver API.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/board.h | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
include/board.h +37 -0
index fd6a486702..678b652b0a 100644
@@ -31,6 +31,7 @@
  * to read the serial number.
  */
 
+#if CONFIG_IS_ENABLED(BOARD)
 struct board_ops {
 	/**
 	 * detect() - Run the hardware info detection procedure for this
@@ -174,3 +175,39 @@ int board_get(struct udevice **devp);
  */
 int board_get_fit_loadable(struct udevice *dev, int index,
 			   const char *type, const char **strp);
+
+#else
+
+static inline int board_detect(struct udevice *dev)
+{
+	return -ENOSYS;
+}
+
+static inline int board_get_bool(struct udevice *dev, int id, bool *val)
+{
+	return -ENOSYS;
+}
+
+static inline int board_get_int(struct udevice *dev, int id, int *val)
+{
+	return -ENOSYS;
+}
+
+static inline int board_get_str(struct udevice *dev, int id, size_t size,
+				char *val)
+{
+	return -ENOSYS;
+}
+
+static inline int board_get(struct udevice **devp)
+{
+	return -ENOSYS;
+}
+
+static inline int board_get_fit_loadable(struct udevice *dev, int index,
+					 const char *type, const char **strp)
+{
+	return -ENOSYS;
+}
+
+#endif
Signature · 1 line
2.17.1
#21 lore raw

PATCH v5 15/15 spl: fit: Allow the board to tell if more images must be loaded from FIT

In reply to Jean-Jacques Hiblot

spl_fit_get_image_name() is used to get the names of the images that the SPL must load from the FIT. It relies on the content of a property present in the FIT. The list of images is thus statically defined in the FIT. With this scheme, it quickly becomes hard to manage combinations of more than a handful of images.
To address this problem, give the board driver code the opportunity to add to the list of images. The images from the FIT property are loaded first, and then the board_get_fit_loadable() is called to get more image names.

---

Changes in v5:
- reword commit log

Changes in v4:
- Use the board driver infrastructure to get the image names from the board code.
- Remove a patch that passed the board name to the FIT generator. If needed the generator can get it from elsewhere
- Add a fix to not load the firmware twice (once as a firmware and once as a loadable)

Changes in v3:
- removed the RFC prefix. This work will be needed soon by TI's AM65x platform. and can probably benefit other modular platforms
- removed the last patch that provided an example of how to use this with on a DRA76.
- removed the patch that made u-boot.img a symlink to u-boot.itb because it breaks the build of many platforms (because files required to build the ITB are missing)
- removed the patch to reduce the footprint of the am335x SPL. (already merged)
- Made the boot flow more permissive (don't fail immediately if an overlay is not present) and more verbose when an error occures
- handle the dependencies of the FIT generation in a more generic way
- use a dedicated kconfig option to enable the application of the overlays by the SPL.

Changes in v2:
- reworked board_fit_get_additionnal_images() and how it used in spl_fit.c
- removed dtbo generation from dtso files and use .dts extension for the overlays
- add dynamic allocation usage in a separate patch
- defconfig change for the am335x_evm

 common/spl/spl_fit.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
common/spl/spl_fit.c +24 -3
index d761cd821f..af8096988f 100644
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <errno.h>
+#include <board.h>
 #include <fpga.h>
 #include <gzip.h>
 #include <image.h>
@@ -48,10 +49,12 @@ static int spl_fit_get_image_name(const void *fit, int images,
 				  const char *type, int index,
 				  const char **outname)
 {
+	struct udevice *board;
 	const char *name, *str;
 	__maybe_unused int node;
 	int conf_node;
 	int len, i;
+	bool found = true;
 
 	conf_node = fit_find_config_node(fit);
 	if (conf_node < 0) {
@@ -77,12 +80,30 @@ static int spl_fit_get_image_name(const void *fit, int images,
 	for (i = 0; i < index; i++) {
 		str = strchr(str, '\0') + 1;
 		if (!str || (str - name >= len)) {
-			debug("no string for index %d\n", index);
-			return -E2BIG;
+			found = false;
+			break;
 		}
 	}
 
-	*outname = (char *)str;
+	if (!found && !board_get(&board)) {
+		int rc;
+		/*
+		 * no string in the property for this index. Check if the board
+		 * level code can supply one.
+		 */
+		rc = board_get_fit_loadable(board, index - i - 1, type, &str);
+		if (rc && rc != -ENOENT)
+			return rc;
+		if (!rc)
+			found = true;
+	}
+
+	if (!found) {
+		debug("no string for index %d\n", index);
+		return -E2BIG;
+	}
+
+	*outname = str;
 	return 0;
 }
 
Signature · 1 line
2.17.1