[U-Boot] [PATCH 03/31] boot_fit: Create helper functions that can be used to select DTB out of FIT
Franklin S Cooper Jr
fcooper at ti.com
Thu Mar 2 19:04:07 UTC 2017
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 at ti.com>
Reviewed-by: Tom Rini <trini at konsulko.com>
---
common/Kconfig | 8 ++++++++
common/Makefile | 1 +
common/boot_fit.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/boot_fit.h | 9 +++++++++
include/image.h | 2 +-
5 files changed, 77 insertions(+), 1 deletion(-)
create mode 100644 common/boot_fit.c
create mode 100644 include/boot_fit.h
diff --git a/common/Kconfig b/common/Kconfig
index 8f73c8f..11495f3 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -352,6 +352,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 692ebc4..4dfebfc 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -150,6 +150,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 at 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 at 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 bb8d699..2674cef 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1275,7 +1275,7 @@ 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)
+#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);
--
2.10.0
More information about the U-Boot
mailing list