]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
image: Add FIT image loadable section custom processing
authorAndrew F. Davis <afd@ti.com>
Tue, 29 Nov 2016 22:33:20 +0000 (16:33 -0600)
committerTom Rini <trini@konsulko.com>
Sat, 3 Dec 2016 18:21:19 +0000 (13:21 -0500)
To help automate the loading of custom image types we add the ability
to define custom handlers for the loadable section types. When we find
a compatible type while loading a "loadable" image from a FIT image we
run its associated handlers to perform any additional steps needed for
loading this image.

Signed-off-by: Andrew F. Davis <afd@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
common/image.c
doc/uImage.FIT/source_file_format.txt
include/image.h

index 7604494a567ed9cf9af14c2b58a2bc6d1fb3805d..2aac90d81826d4fbb0f56bf6b36667f87efbb8a4 100644 (file)
@@ -1389,6 +1389,23 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
 }
 #endif
 
+static void fit_loadable_process(uint8_t img_type,
+                                ulong img_data,
+                                ulong img_len)
+{
+       int i;
+       const unsigned int count =
+                       ll_entry_count(struct fit_loadable_tbl, fit_loadable);
+       struct fit_loadable_tbl *fit_loadable_handler =
+                       ll_entry_start(struct fit_loadable_tbl, fit_loadable);
+       /* For each loadable handler */
+       for (i = 0; i < count; i++, fit_loadable_handler++)
+               /* matching this type */
+               if (fit_loadable_handler->type == img_type)
+                       /* call that handler with this image data */
+                       fit_loadable_handler->handler(img_data, img_len);
+}
+
 int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
                uint8_t arch, const ulong *ld_start, ulong * const ld_len)
 {
@@ -1407,6 +1424,7 @@ int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
        int conf_noffset;
        int fit_img_result;
        const char *uname;
+       uint8_t img_type;
 
        /* Check to see if the images struct has a FIT configuration */
        if (!genimg_has_config(images)) {
@@ -1447,6 +1465,21 @@ int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
                                /* Something went wrong! */
                                return fit_img_result;
                        }
+
+                       fit_img_result = fit_image_get_node(buf, uname);
+                       if (fit_img_result < 0) {
+                               /* Something went wrong! */
+                               return fit_img_result;
+                       }
+                       fit_img_result = fit_image_get_type(buf,
+                                                           fit_img_result,
+                                                           &img_type);
+                       if (fit_img_result < 0) {
+                               /* Something went wrong! */
+                               return fit_img_result;
+                       }
+
+                       fit_loadable_process(img_type, img_data, img_len);
                }
                break;
        default:
index 91aa89a77ecb9f4e284021023404b5cfcbc59a9e..afff301c88593d5318d99f2283c9a7495619da29 100644 (file)
@@ -256,7 +256,9 @@ o config@1
     (component image node of a "fpga type").
   - loadables : Unit name containing a list of additional binaries to be
     loaded at their given locations.  "loadables" is a comma-separated list
-    of strings. U-Boot will load each binary at its given start-address.
+    of strings. U-Boot will load each binary at its given start-address and
+    may optionaly invoke additional post-processing steps on this binary based
+    on its component image node type.
 
 The FDT blob is required to properly boot FDT based kernel, so the minimal
 configuration for 2.6 FDT kernel is (kernel, fdt) pair.
index 81315959fe2a539a52ed113f6d5eef32d2f815c6..b96b8ebfe81daadee3a5eee1e937b9034bcf510c 100644 (file)
@@ -1271,4 +1271,34 @@ 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 */
 
+/**
+ * Mapping of image types to function handlers to be invoked on the associated
+ * loaded images
+ *
+ * @type: Type of image, I.E. IH_TYPE_*
+ * @handler: Function to call on loaded image
+ */
+struct fit_loadable_tbl {
+       int type;
+       /**
+        * handler() - Process a loaded image
+        *
+        * @data: Pointer to start of loaded image data
+        * @size: Size of loaded image data
+        */
+       void (*handler)(ulong data, size_t size);
+};
+
+/*
+ * Define a FIT loadable image type handler
+ *
+ * _type is a valid uimage_type ID as defined in the "Image Type" enum above
+ * _handler is the handler function to call after this image type is loaded
+ */
+#define U_BOOT_FIT_LOADABLE_HANDLER(_type, _handler) \
+       ll_entry_declare(struct fit_loadable_tbl, _function, fit_loadable) = { \
+               .type = _type, \
+               .handler = _handler, \
+       }
+
 #endif /* __IMAGE_H__ */