[U-Boot] [PATCH v5 00/15] 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(-)

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org Tested-by: Andreas Dannenberg dannenberg@ti.com ---
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(+)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index b3e3ccd5a2..ee037134a8 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -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)

From: Michal Simek michal.simek@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@xilinx.com Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org
---
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(-)
diff --git a/Kconfig b/Kconfig index 1f0904f704..825f096807 100644 --- a/Kconfig +++ b/Kconfig @@ -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 diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index ee037134a8..569110f3ac 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -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; }

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 569110f3ac..95b45aafa2 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -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; }

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com
---
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(-)
diff --git a/Kconfig b/Kconfig index 825f096807..a41d33de13 100644 --- a/Kconfig +++ b/Kconfig @@ -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 diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 95b45aafa2..4fdc10c9e2 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -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);

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 4fdc10c9e2..187dd5ab3f 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -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) {

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 187dd5ab3f..cdbba3705d 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -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));

In order to apply an overlay to a DTB. The DTB must have been generated with the option '-@'.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(+)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index ef116e0e0a..6946da6aa4 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -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

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
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/Makefile b/Makefile index 57d0700227..2f118affe9 100644 --- a/Makefile +++ b/Makefile @@ -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

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/Makefile b/Makefile index 2f118affe9..8a28740b22 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/board/theobroma-systems/lion_rk3368/fit_spl_atf.its b/board/theobroma-systems/lion_rk3368/fit_spl_atf.its index 6b04fbc7da..69202a117b 100644 --- a/board/theobroma-systems/lion_rk3368/fit_spl_atf.its +++ b/board/theobroma-systems/lion_rk3368/fit_spl_atf.its @@ -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"; };

To reduce the complexity of the Makefile, let the generator tell what its dependencies are. For this purpose use the "--deps" option.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/Makefile b/Makefile index 8a28740b22..1fa63d2a6b 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/arch/arm/mach-imx/mkimage_fit_atf.sh b/arch/arm/mach-imx/mkimage_fit_atf.sh index 38c9858e84..4da7531954 100755 --- a/arch/arm/mach-imx/mkimage_fit_atf.sh +++ b/arch/arm/mach-imx/mkimage_fit_atf.sh @@ -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 diff --git a/arch/arm/mach-rockchip/make_fit_atf.py b/arch/arm/mach-rockchip/make_fit_atf.py index b9a1988298..56fab4e330 100755 --- a/arch/arm/mach-rockchip/make_fit_atf.py +++ b/arch/arm/mach-rockchip/make_fit_atf.py @@ -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": diff --git a/board/sunxi/mksunxi_fit_atf.sh b/board/sunxi/mksunxi_fit_atf.sh index 88ad719747..c0ce4394e2 100755 --- a/board/sunxi/mksunxi_fit_atf.sh +++ b/board/sunxi/mksunxi_fit_atf.sh @@ -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 diff --git a/board/theobroma-systems/puma_rk3399/fit_spl_atf.sh b/board/theobroma-systems/puma_rk3399/fit_spl_atf.sh index 420e7daf4c..a7bada193a 100755 --- a/board/theobroma-systems/puma_rk3399/fit_spl_atf.sh +++ b/board/theobroma-systems/puma_rk3399/fit_spl_atf.sh @@ -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

Hi Jean-Jacques,
On Fri, 2019-09-20 at 17:28 +0200, Jean-Jacques Hiblot wrote:
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
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org
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(-)
diff --git a/Makefile b/Makefile index 8a28740b22..1fa63d2a6b 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/arch/arm/mach-imx/mkimage_fit_atf.sh b/arch/arm/mach-imx/mkimage_fit_atf.sh index 38c9858e84..4da7531954 100755 --- a/arch/arm/mach-imx/mkimage_fit_atf.sh +++ b/arch/arm/mach-imx/mkimage_fit_atf.sh @@ -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 diff --git a/arch/arm/mach-rockchip/make_fit_atf.py b/arch/arm/mach-rockchip/make_fit_atf.py index b9a1988298..56fab4e330 100755 --- a/arch/arm/mach-rockchip/make_fit_atf.py +++ b/arch/arm/mach-rockchip/make_fit_atf.py @@ -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":
diff --git a/board/sunxi/mksunxi_fit_atf.sh b/board/sunxi/mksunxi_fit_atf.sh index 88ad719747..c0ce4394e2 100755 --- a/board/sunxi/mksunxi_fit_atf.sh +++ b/board/sunxi/mksunxi_fit_atf.sh @@ -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 diff --git a/board/theobroma-systems/puma_rk3399/fit_spl_atf.sh b/board/theobroma-systems/puma_rk3399/fit_spl_atf.sh index 420e7daf4c..a7bada193a 100755 --- a/board/theobroma-systems/puma_rk3399/fit_spl_atf.sh +++ b/board/theobroma-systems/puma_rk3399/fit_spl_atf.sh @@ -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

On Sun, Oct 06, 2019 at 04:57:29PM +0000, Auer, Lukas wrote:
Hi Jean-Jacques,
On Fri, 2019-09-20 at 17:28 +0200, Jean-Jacques Hiblot wrote:
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!

On 06/10/2019 19:12, Tom Rini wrote:
On Sun, Oct 06, 2019 at 04:57:29PM +0000, Auer, Lukas wrote:
Hi Jean-Jacques,
On Fri, 2019-09-20 at 17:28 +0200, Jean-Jacques Hiblot wrote:
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!
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

On Mon, Oct 07, 2019 at 11:43:07AM +0200, Jean-Jacques Hiblot wrote:
On 06/10/2019 19:12, Tom Rini wrote:
On Sun, Oct 06, 2019 at 04:57:29PM +0000, Auer, Lukas wrote:
Hi Jean-Jacques,
On Fri, 2019-09-20 at 17:28 +0200, Jean-Jacques Hiblot wrote:
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!
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!

On 07/10/2019 18:02, Tom Rini wrote:
On Mon, Oct 07, 2019 at 11:43:07AM +0200, Jean-Jacques Hiblot wrote:
On 06/10/2019 19:12, Tom Rini wrote:
On Sun, Oct 06, 2019 at 04:57:29PM +0000, Auer, Lukas wrote:
Hi Jean-Jacques,
On Fri, 2019-09-20 at 17:28 +0200, Jean-Jacques Hiblot wrote:
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!
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!
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

There is no need for it to be non-constant. Making it constant, allows to return constant string without warning.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index cdbba3705d..d761cd821f 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -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",

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com
---
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(-)
diff --git a/drivers/Makefile b/drivers/Makefile index a4bb5e4975..6dd43d4949 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -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/ diff --git a/drivers/board/Kconfig b/drivers/board/Kconfig index 2a3fc9c049..254f657049 100644 --- a/drivers/board/Kconfig +++ b/drivers/board/Kconfig @@ -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" diff --git a/drivers/board/Makefile b/drivers/board/Makefile index c8dab4fa0b..cc16361755 100644 --- a/drivers/board/Makefile +++ b/drivers/board/Makefile @@ -2,6 +2,6 @@ # # (C) Copyright 2017 # Mario Six, Guntermann & Drunck GmbH, mario.six@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

On Fri, 20 Sep 2019 at 09:28, Jean-Jacques Hiblot jjhiblot@ti.com wrote:
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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com
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(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com
---
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(+)
diff --git a/drivers/board/board-uclass.c b/drivers/board/board-uclass.c index a516ba4962..b5485e9895 100644 --- a/drivers/board/board-uclass.c +++ b/drivers/board/board-uclass.c @@ -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); diff --git a/include/board.h b/include/board.h index 9dc78684f8..fd6a486702 100644 --- a/include/board.h +++ b/include/board.h @@ -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);

Useful to avoid #ifdef throughout the code that uses the board driver API.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(+)
diff --git a/include/board.h b/include/board.h index fd6a486702..678b652b0a 100644 --- a/include/board.h +++ b/include/board.h @@ -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

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.
Signed-off-by: Jean-Jacques Hiblot jjhiblot@ti.com
---
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(-)
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index d761cd821f..af8096988f 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -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; }
participants (4)
-
Auer, Lukas
-
Jean-Jacques Hiblot
-
Simon Glass
-
Tom Rini