]> git.sur5r.net Git - u-boot/commitdiff
boot_fit: Create helper functions that can be used to select DTB out of FIT
authorCooper Jr., Franklin <fcooper@ti.com>
Fri, 16 Jun 2017 22:25:06 +0000 (17:25 -0500)
committerTom Rini <trini@konsulko.com>
Mon, 10 Jul 2017 18:25:50 +0000 (14:25 -0400)
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
common/Makefile
common/boot_fit.c [new file with mode: 0644]
include/boot_fit.h [new file with mode: 0644]
include/image.h

index 27dde11b14c47431d2a6ad15b6c1bfd1973a6f69..a5e3a6b418a37439a898af6c6956eb15ac1602e7 100644 (file)
@@ -437,6 +437,13 @@ config SYS_STDIO_DEREGISTER
 
 endmenu
 
+config FIT_EMBED
+       bool "Support a FIT image embedded in the U-boot image"
+       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
index d6d0764e7a9c5d8c49bb477b01c86eb260924aef..8540fbc9fa6dc44dc0a7bc39d7fc6bdf05d99603 100644 (file)
@@ -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 (file)
index 0000000..51440a6
--- /dev/null
@@ -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;
+}
diff --git a/include/boot_fit.h b/include/boot_fit.h
new file mode 100644 (file)
index 0000000..b7d2462
--- /dev/null
@@ -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);
index 1d763b33b833af418492cf52cb2742e94ed564d1..c6f1513220a31d29a0bf68a2879afd97eb3a62ab 100644 (file)
@@ -1272,6 +1272,9 @@ void board_fit_image_post_process(void **p_image, size_t *p_size);
 
 #define FDT_ERROR      ((ulong)(-1))
 
+ulong fdt_getprop_u32(const void *fdt, int node, const char *prop);
+int fit_find_config_node(const void *fdt);
+
 /**
  * Mapping of image types to function handlers to be invoked on the associated
  * loaded images