[U-Boot,05/15] spl: fit: implement fdt_record_loadable

Message ID 1505330989-25602-6-git-send-email-philipp.tomsich@theobroma-systems.com
State Accepted
Delegated to: Philipp Tomsich
Headers show
Series
  • [U-Boot,01/15] image: add IH_OS_ARM_TRUSTED_FIRMWARE for ARM Trusted Firmware
Related show

Commit Message

Philipp Tomsich Sept. 13, 2017, 7:29 p.m.
During the loading of more complex FIT images (e.g. when the invoked
next stage needs to find additional firmware for a power-management
core... or if there are multiple images for different privilege levels
started in parallel), it is helpful to create a record of what images
are loaded where: if a FDT is loaded for one of the next stages, it
can be used to convey the status and location of loadables.

This adds a fdt_record_loadable() function that can be invoked to
record the status of each loadable below the /fit-images path.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
---

 common/fdt_support.c  | 39 +++++++++++++++++++++++++++++++++++++++
 include/fdt_support.h | 20 ++++++++++++++++++++
 2 files changed, 59 insertions(+)

Comments

Simon Glass Sept. 17, 2017, 5:53 p.m. | #1
On 13 September 2017 at 13:29, Philipp Tomsich
<philipp.tomsich@theobroma-systems.com> wrote:
> During the loading of more complex FIT images (e.g. when the invoked
> next stage needs to find additional firmware for a power-management
> core... or if there are multiple images for different privilege levels
> started in parallel), it is helpful to create a record of what images
> are loaded where: if a FDT is loaded for one of the next stages, it
> can be used to convey the status and location of loadables.
>
> This adds a fdt_record_loadable() function that can be invoked to
> record the status of each loadable below the /fit-images path.
>
> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> ---
>
>  common/fdt_support.c  | 39 +++++++++++++++++++++++++++++++++++++++
>  include/fdt_support.h | 20 ++++++++++++++++++++
>  2 files changed, 59 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Philipp Tomsich Nov. 23, 2017, 2:51 p.m. | #2
> During the loading of more complex FIT images (e.g. when the invoked
> next stage needs to find additional firmware for a power-management
> core... or if there are multiple images for different privilege levels
> started in parallel), it is helpful to create a record of what images
> are loaded where: if a FDT is loaded for one of the next stages, it
> can be used to convey the status and location of loadables.
> 
> This adds a fdt_record_loadable() function that can be invoked to
> record the status of each loadable below the /fit-images path.
> 
> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  common/fdt_support.c  | 39 +++++++++++++++++++++++++++++++++++++++
>  include/fdt_support.h | 20 ++++++++++++++++++++
>  2 files changed, 59 insertions(+)
> 

Applied to u-boot-rockchip, thanks!

Patch

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 916a448..c936c33 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -410,6 +410,45 @@  static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size,
 	return p - (char *)buf;
 }
 
+int fdt_record_loadable(void *blob, u32 index, const char *name,
+			uintptr_t load_addr, u32 size, uintptr_t entry_point,
+			const char *type, const char *os)
+{
+	int err, node;
+
+	err = fdt_check_header(blob);
+	if (err < 0) {
+		printf("%s: %s\n", __func__, fdt_strerror(err));
+		return err;
+	}
+
+	/* find or create "/fit-images" node */
+	node = fdt_find_or_add_subnode(blob, 0, "fit-images");
+	if (node < 0)
+			return node;
+
+	/* find or create "/fit-images/<name>" node */
+	node = fdt_find_or_add_subnode(blob, node, name);
+	if (node < 0)
+		return node;
+
+	/*
+	 * We record these as 32bit entities, possibly truncating addresses.
+	 * However, spl_fit.c is not 64bit safe either: i.e. we should not
+	 * have an issue here.
+	 */
+	fdt_setprop_u32(blob, node, "load-addr", load_addr);
+	if (entry_point != -1)
+		fdt_setprop_u32(blob, node, "entry-point", entry_point);
+	fdt_setprop_u32(blob, node, "size", size);
+	if (type)
+		fdt_setprop_string(blob, node, "type", type);
+	if (os)
+		fdt_setprop_string(blob, node, "os", os);
+
+	return node;
+}
+
 #ifdef CONFIG_NR_DRAM_BANKS
 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS
 #else
diff --git a/include/fdt_support.h b/include/fdt_support.h
index 5ef78cc..4297bde 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -133,6 +133,26 @@  void fdt_fixup_crypto_node(void *blob, int sec_rev);
 static inline void fdt_fixup_crypto_node(void *blob, int sec_rev) {}
 #endif
 
+#if CONFIG_IS_ENABLED(LOAD_FIT)
+/**
+ * Record information about a processed loadable in /fit-images (creating
+ * /fit-images if necessary).
+ *
+ * @param blob		FDT blob to update
+ * @param index	        index of this loadable
+ * @param name          name of the loadable
+ * @param load_addr     address the loadable was loaded to
+ * @param size          number of bytes loaded
+ * @param entry_point   entry point (if specified, otherwise pass -1)
+ * @param type          type (if specified, otherwise pass NULL)
+ * @param os            os-type (if specified, otherwise pass NULL)
+ * @return 0 if ok, or -1 or -FDT_ERR_... on error
+ */
+int fdt_record_loadable(void *blob, u32 index, const char *name,
+			uintptr_t load_addr, u32 size, uintptr_t entry_point,
+			const char *type, const char *os);
+#endif
+
 #ifdef CONFIG_PCI
 #include <pci.h>
 int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose);