summaryrefslogtreecommitdiff
path: root/boot/image-fit.c
diff options
context:
space:
mode:
authorSean Anderson <sean.anderson@seco.com>2022-08-16 18:16:03 +0300
committerPeng Fan <peng.fan@nxp.com>2022-09-07 08:40:44 +0300
commit37feaf2f72788263b767136065794f80485bb5ff (patch)
treef0bd4bb1719af7594087e97511d023ff099e5924 /boot/image-fit.c
parent1b0e98221d826776adc8e3c5d939cfee1890398e (diff)
downloadu-boot-37feaf2f72788263b767136065794f80485bb5ff.tar.xz
image: fit: Add some helpers for getting data
Several different firmware users have repetitive code to extract the firmware data from a FIT. Add some helper functions to reduce the amount of repetition. fit_conf_get_prop_node (eventually) calls fdt_check_node_offset_, so we can avoid an explicit if. In general, this version avoids printing on error because the callers are typically library functions, and because the FIT code generally has (debug) prints of its own. One difference in these helpers is that they use fit_image_get_data_and_size instead of fit_image_get_data, as the former handles external data correctly. Signed-off-by: Sean Anderson <sean.anderson@seco.com> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Peng Fan <peng.fan@nxp.com>
Diffstat (limited to 'boot/image-fit.c')
-rw-r--r--boot/image-fit.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/boot/image-fit.c b/boot/image-fit.c
index 21dbd05118..f16eab9df3 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -1916,6 +1916,43 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
return fit_conf_get_prop_node_index(fit, noffset, prop_name, 0);
}
+static int fit_get_data_tail(const void *fit, int noffset,
+ const void **data, size_t *size)
+{
+ char *desc;
+
+ if (noffset < 0)
+ return noffset;
+
+ if (!fit_image_verify(fit, noffset))
+ return -EINVAL;
+
+ if (fit_image_get_data_and_size(fit, noffset, data, size))
+ return -ENOENT;
+
+ if (!fit_get_desc(fit, noffset, &desc))
+ printf("%s\n", desc);
+
+ return 0;
+}
+
+int fit_get_data_node(const void *fit, const char *image_uname,
+ const void **data, size_t *size)
+{
+ int noffset = fit_image_get_node(fit, image_uname);
+
+ return fit_get_data_tail(fit, noffset, data, size);
+}
+
+int fit_get_data_conf_prop(const void *fit, const char *prop_name,
+ const void **data, size_t *size)
+{
+ int noffset = fit_conf_get_node(fit, NULL);
+
+ noffset = fit_conf_get_prop_node(fit, noffset, prop_name);
+ return fit_get_data_tail(fit, noffset, data, size);
+}
+
static int fit_image_select(const void *fit, int rd_noffset, int verify)
{
fit_image_print(fit, rd_noffset, " ");