[PATCH 01/13] boot: Split out the first part of fit_image_load()
Simon Glass
sjg at chromium.org
Wed Mar 25 17:54:10 CET 2026
This function is over 250 lines long. Split out the image-selection
part into a new select_image() function which handles format checking,
configuration selection and image-node lookup.
Take care to only call fit_get_name() when a valid node is found, since
libfdt does not handle negative offsets gracefully.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
boot/image-fit.c | 101 ++++++++++++++++++++++++++++++++---------------
1 file changed, 70 insertions(+), 31 deletions(-)
diff --git a/boot/image-fit.c b/boot/image-fit.c
index e7c7212195f..a4402dcff63 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -2070,33 +2070,35 @@ static const char *fit_get_image_type_property(int ph_type)
return "unknown";
}
-int fit_image_load(struct bootm_headers *images, ulong addr,
- const char **fit_unamep, const char **fit_uname_configp,
- int arch, int ph_type, int bootstage_id,
- enum fit_load_op load_op, ulong *datap, ulong *lenp)
+/**
+ * select_image() - Select the image to load
+ *
+ * image->fit_uname_cfg is set if the image type is IH_TYPE_KERNEL
+ *
+ * @fit: Pointer to FIT
+ * @images: Boot images structure
+ * @fit_unamep: On entry, the requested image name (e.g. "kernel") or NULL to
+ * use the default. On exit, the selected image name
+ * @fit_uname_config: Requested configuration name (e.g. "conf-1") or NULL to
+ * use the default
+ * @prop_name: Property name (in the configuration node) indicating the image
+ * to load
+ * @ph_type: Required image type (IH_TYPE_...) and phase (IH_PHASE_...)
+ * @bootstage_id: ID of starting bootstage to use for progress updates
+ * @fit_base_uname_configp: Returns config name selected, or NULL if *fit_unamep
+ * was used to select an image node
+ * Return: node offset of image node, on success, else -ve error code
+ */
+static int select_image(const void *fit, struct bootm_headers *images,
+ const char **fit_unamep, const char *fit_uname_config,
+ const char *prop_name, int ph_type, int bootstage_id,
+ const char **fit_base_uname_configp)
{
- int image_type = image_ph_type(ph_type);
int cfg_noffset, noffset;
- const char *fit_uname;
- const char *fit_uname_config;
- const char *fit_base_uname_config;
- const void *fit;
- void *buf;
- void *loadbuf;
- size_t size;
- int type_ok, os_ok;
- ulong load, load_end, data, len;
- uint8_t os, comp;
- const char *prop_name;
int ret;
- fit = map_sysmem(addr, 0);
- fit_uname = fit_unamep ? *fit_unamep : NULL;
- fit_uname_config = fit_uname_configp ? *fit_uname_configp : NULL;
- fit_base_uname_config = NULL;
+ *fit_base_uname_configp = NULL;
prop_name = fit_get_image_type_property(ph_type);
- printf("## Loading %s (%s) from FIT Image at %08lx ...\n",
- prop_name, genimg_get_phase_name(image_ph_phase(ph_type)), addr);
bootstage_mark(bootstage_id + BOOTSTAGE_SUB_FORMAT);
ret = fit_check_format(fit, IMAGE_SIZE_INVAL);
@@ -2108,10 +2110,10 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
return ret;
}
bootstage_mark(bootstage_id + BOOTSTAGE_SUB_FORMAT_OK);
- if (fit_uname) {
+ if (*fit_unamep) {
/* get FIT component image node offset */
bootstage_mark(bootstage_id + BOOTSTAGE_SUB_UNIT_NAME);
- noffset = fit_image_get_node(fit, fit_uname);
+ noffset = fit_image_get_node(fit, *fit_unamep);
} else {
/*
* no image node unit name, try to get config
@@ -2133,11 +2135,12 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
}
cfg_noffset = ret;
- fit_base_uname_config = fdt_get_name(fit, cfg_noffset, NULL);
- printf(" Using '%s' configuration\n", fit_base_uname_config);
+ *fit_base_uname_configp = fdt_get_name(fit, cfg_noffset, NULL);
+ printf(" Using '%s' configuration\n",
+ *fit_base_uname_configp);
/* Remember this config */
- if (image_type == IH_TYPE_KERNEL)
- images->fit_uname_cfg = fit_base_uname_config;
+ if (image_ph_type(ph_type) == IH_TYPE_KERNEL)
+ images->fit_uname_cfg = *fit_base_uname_configp;
if (FIT_IMAGE_ENABLE_VERIFY && images->verify) {
puts(" Verifying Hash Integrity ... ");
@@ -2161,10 +2164,46 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
return -ENOENT;
}
- if (!fit_uname)
- fit_uname = fit_get_name(fit, noffset, NULL);
+ if (!*fit_unamep)
+ *fit_unamep = fit_get_name(fit, noffset, NULL);
+
+ printf(" Trying '%s' %s subimage\n", *fit_unamep, prop_name);
+
+ return noffset;
+}
+
+int fit_image_load(struct bootm_headers *images, ulong addr,
+ const char **fit_unamep, const char **fit_uname_configp,
+ int arch, int ph_type, int bootstage_id,
+ enum fit_load_op load_op, ulong *datap, ulong *lenp)
+{
+ int image_type = image_ph_type(ph_type);
+ int noffset;
+ const char *fit_uname;
+ const char *fit_uname_config;
+ const char *fit_base_uname_config;
+ const void *fit;
+ void *buf;
+ void *loadbuf;
+ size_t size;
+ int type_ok, os_ok;
+ ulong load, load_end, data, len;
+ uint8_t os, comp;
+ const char *prop_name;
+ int ret;
+
+ fit = map_sysmem(addr, 0);
+ prop_name = fit_get_image_type_property(ph_type);
+ printf("## Loading %s (%s) from FIT Image at %08lx ...\n",
+ prop_name, genimg_get_phase_name(image_ph_phase(ph_type)), addr);
- printf(" Trying '%s' %s subimage\n", fit_uname, prop_name);
+ fit_uname = fit_unamep ? *fit_unamep : NULL;
+ fit_uname_config = fit_uname_configp ? *fit_uname_configp : NULL;
+ noffset = select_image(fit, images, &fit_uname, fit_uname_config,
+ prop_name, ph_type, bootstage_id,
+ &fit_base_uname_config);
+ if (noffset < 0)
+ return noffset;
ret = fit_image_select(fit, noffset, images->verify);
if (ret) {
--
2.43.0
More information about the U-Boot
mailing list