summaryrefslogtreecommitdiff
path: root/common/boot_fit.c
diff options
context:
space:
mode:
authorCooper Jr., Franklin <fcooper@ti.com>2017-06-16 22:25:06 (GMT)
committerTom Rini <trini@konsulko.com>2017-07-10 18:25:50 (GMT)
commit92926bc80c5330d7ee71d0e56926264bce9dea3b (patch)
treeccde9f6763d2ea61dce3775ec3328730949eeed7 /common/boot_fit.c
parent3863f840fa03f6b93672a5afff74f15d460cb911 (diff)
downloadu-boot-fsl-qoriq-92926bc80c5330d7ee71d0e56926264bce9dea3b.tar.xz
boot_fit: Create helper functions that can be used to select DTB out of FIT
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>
Diffstat (limited to 'common/boot_fit.c')
-rw-r--r--common/boot_fit.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/common/boot_fit.c b/common/boot_fit.c
new file mode 100644
index 0000000..51440a6
--- /dev/null
+++ b/common/boot_fit.c
@@ -0,0 +1,80 @@
+/*
+ * (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 images, node, fdt_len, fdt_node, fdt_offset;
+ const char *fdt_name;
+
+ node = fit_find_config_node(fit);
+ if (node < 0)
+ return node;
+
+ images = fdt_path_offset(fit, FIT_IMAGES_PATH);
+ if (images < 0) {
+ debug("%s: Cannot find /images node: %d\n", __func__, images);
+ return FDT_ERROR;
+ }
+
+ fdt_name = fdt_getprop(fit, node, FIT_FDT_PROP, &fdt_len);
+ if (!fdt_name) {
+ debug("%s: Cannot find fdt name property: %d\n",
+ __func__, fdt_len);
+ return -EINVAL;
+ }
+
+ fdt_node = fdt_subnode_offset(fit, images, fdt_name);
+ if (fdt_node < 0) {
+ debug("%s: Cannot find fdt node '%s': %d\n",
+ __func__, fdt_name, fdt_node);
+ return -EINVAL;
+ }
+
+ fdt_offset = fdt_getprop_u32(fit, fdt_node, "data-offset");
+
+ if (fdt_offset == FDT_ERROR)
+ return -ENOENT;
+
+ fdt_len = fdt_getprop_u32(fit, fdt_node, "data-size");
+
+ 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;
+}