From: Franklin S Cooper Jr <fcooper@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 03/30] boot_fit: Create helper functions that can be used to select DTB out of FIT
Date: Tue, 23 May 2017 12:42:32 -0500 [thread overview]
Message-ID: <20170523174259.14797-4-fcooper@ti.com> (raw)
In-Reply-To: <20170523174259.14797-1-fcooper@ti.com>
Some platforms may append a FIT image to the U-boot image. This function
aids in parsing the FIT image and selecting the correct DTB at runtime.
Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
common/Kconfig | 8 ++++++++
common/Makefile | 1 +
common/boot_fit.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/boot_fit.h | 9 +++++++++
include/image.h | 8 ++++++++
5 files changed, 84 insertions(+)
create mode 100644 common/boot_fit.c
create mode 100644 include/boot_fit.h
diff --git a/common/Kconfig b/common/Kconfig
index 1879aef..2429953 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -421,6 +421,14 @@ config SYS_STDIO_DEREGISTER
endmenu
+config FIT_EMBED
+ bool "Support a FIT image embedded in the U-boot image"
+ default n
+ help
+ This option provides hooks to allow U-boot to parse an
+ appended FIT image and enable board specific code to then select
+ the correct DTB to be used.
+
config DEFAULT_FDT_FILE
string "Default fdt file"
help
diff --git a/common/Makefile b/common/Makefile
index ccd8bbc..0c6209b 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -151,6 +151,7 @@ obj-y += image.o
obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o
obj-$(CONFIG_$(SPL_)OF_LIBFDT) += image-fdt.o
obj-$(CONFIG_$(SPL_)FIT) += image-fit.o
+obj-$(CONFIG_FIT_EMBED) += boot_fit.o common_fit.o
obj-$(CONFIG_$(SPL_)FIT_SIGNATURE) += image-sig.o
obj-$(CONFIG_IO_TRACE) += iotrace.o
obj-y += memsize.o
diff --git a/common/boot_fit.c b/common/boot_fit.c
new file mode 100644
index 0000000..ff26cf7
--- /dev/null
+++ b/common/boot_fit.c
@@ -0,0 +1,58 @@
+/*
+ * (C) Copyright 2017
+ * Texas Instruments, <www.ti.com>
+ *
+ * Franklin S Cooper Jr. <fcooper@ti.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <boot_fit.h>
+#include <common.h>
+#include <errno.h>
+#include <image.h>
+#include <libfdt.h>
+
+int fdt_offset(void *fit)
+{
+ int fdt_offset, fdt_len;
+ int images;
+
+ images = fdt_path_offset(fit, FIT_IMAGES_PATH);
+ if (images < 0) {
+ debug("%s: Cannot find /images node: %d\n", __func__, images);
+ return -1;
+ }
+
+ /* Figure out which device tree the board wants to use */
+ fdt_len = fit_select_fdt(fit, images, &fdt_offset);
+
+ if (fdt_len < 0)
+ return fdt_len;
+
+ return fdt_offset;
+}
+
+void *locate_dtb_in_fit(void *fit)
+{
+ struct image_header *header;
+ int size;
+ int ret;
+
+ size = fdt_totalsize(fit);
+ size = (size + 3) & ~3;
+
+ header = (struct image_header *)fit;
+
+ if (image_get_magic(header) != FDT_MAGIC) {
+ debug("No FIT image appended to U-boot\n");
+ return NULL;
+ }
+
+ ret = fdt_offset(fit);
+
+ if (ret <= 0)
+ return NULL;
+ else
+ return (void *)fit+size+ret;
+}
diff --git a/include/boot_fit.h b/include/boot_fit.h
new file mode 100644
index 0000000..b7d2462
--- /dev/null
+++ b/include/boot_fit.h
@@ -0,0 +1,9 @@
+/*
+ * Copyright (C) 2017 Texas Instruments
+ * Written by Franklin Cooper Jr. <fcooper@ti.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+int fdt_offset(void *fit);
+void *locate_dtb_in_fit(void *fit);
diff --git a/include/image.h b/include/image.h
index 3f26f9b..1083578 100644
--- a/include/image.h
+++ b/include/image.h
@@ -18,6 +18,7 @@
#include "compiler.h"
#include <asm/byteorder.h>
+#include <linux/kconfig.h>
/* Define this to avoid #ifdefs later on */
struct lmb;
@@ -1274,6 +1275,13 @@ int board_fit_config_name_match(const char *name);
void board_fit_image_post_process(void **p_image, size_t *p_size);
#endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */
+#if IS_ENABLED(CONFIG_SPL_LOAD_FIT) || IS_ENABLED(CONFIG_FIT_EMBED)
+
+ulong fdt_getprop_u32(const void *fdt, int node, const char *prop);
+int fit_select_fdt(const void *fdt, int images, int *fdt_offsetp);
+
+#endif
+
/**
* Mapping of image types to function handlers to be invoked on the associated
* loaded images
--
2.10.0
next prev parent reply other threads:[~2017-05-23 17:42 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-23 17:42 [U-Boot] [PATCH v2 00/30] ARM: k2g: Add support for new K2G ICE EVM Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 01/30] ti: common: board_detect: Allow settings board detection variables manually Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 02/30] spl: fit: Break out some functions into a common file Franklin S Cooper Jr
2017-05-23 17:42 ` Franklin S Cooper Jr [this message]
2017-05-23 17:42 ` [U-Boot] [PATCH v2 04/30] fdt: Enable selecting correct DTB from appended FIT Image Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 05/30] ti: common: board_detect: Add function to determine if EEPROM was read Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 06/30] dts: Allow OF_LIST to depend on FIT_EMBED Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 07/30] ARM: dts: k2g: Introduce U-boot specific dtsi file Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 08/30] arm: dts: Add new "generic" 66AK2Gx device tree file Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 09/30] board_f: Add new function to allow runtime DTB selection Franklin S Cooper Jr
2017-05-24 15:38 ` Franklin S Cooper Jr
2017-05-26 8:08 ` Lothar Waßmann
2017-05-26 18:24 ` Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 10/30] Makefile: Build additional binaries for dtb FIT blobs appended to U-boot Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 11/30] ARM: keystone2: Allow to build with all image formats Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 12/30] ARM: k2g: Define embedded_dtb_select for runtime DTB selection in U-boot Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 13/30] ARM: keystone2: Define board_fit_config_name_match for Keystone 2 boards Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 14/30] ks2_evm: Add EEPROM based board detection Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 15/30] defconfig: keystone2: Enable U-boot runtime DTB detection Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 16/30] ARM: keystone2: Add additional fields used for DDR3 configuration Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 17/30] ARM: k2g: Program DDR PHY MR2 register with the default value Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 18/30] ARM: k2g: Program DDRPHY_DATX8 registers via mask and value variables Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 19/30] ks2_evm: Add EEPROM based board detection helper functions Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 20/30] ARM: k2g: Add pinmux support for K2G ICE evm Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 21/30] ARM: k2g: Add DDR3 configuration " Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 22/30] board: ks2: Use board detection to wrap code not specific to " Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 23/30] ARM: k2g: Use board detection to wrap K2G GP specific calls Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 24/30] ARM: k2g: Update board_name u-boot env variable at runtime Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 25/30] ARM: dts: keystone-k2g: Remove skeleton.dtsi Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 26/30] ARM: dts: keystone-k2g-evm: Add unit address to memory node Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 27/30] ARM: dts: k2g: Disable netcp by default Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 28/30] ARM: dts: k2g: Add DT support for K2G Industrial Communication Engine evm Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 29/30] ARM: k2g: Add K2G ICE DTB to the list of possible DTBs Franklin S Cooper Jr
2017-05-23 17:42 ` [U-Boot] [PATCH v2 30/30] defconfig: k2g_evm_defconfig: Add K2G ICE to OF_LIST Franklin S Cooper Jr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170523174259.14797-4-fcooper@ti.com \
--to=fcooper@ti.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox