
From: Simon Glass <sjg@chromium.org> Since fit_image_load() is still too long, move the load-operation handling into a separate function. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/image-fit.c | 107 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 34 deletions(-) diff --git a/boot/image-fit.c b/boot/image-fit.c index e5123176001..77706ccf4b5 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -2215,6 +2215,75 @@ static int check_allowed(const void *fit, int noffset, return 0; } +/** + * handle_load_op() - Handle the load operation + * + * Process the load_op and figure out where the image should be loaded, now + * that it has been located + * + * @fit: FIT to check + * @noffset: Node offset of the image being loaded + * @prop_name: Property name (in the configuration node) indicating the image + * that was loaded + * @buf: Pointer to image (within the FIT) + * @size: Size of the image in bytes + * @image_type: Type of the image + * @load_op: Load operation to process + * @bootstage_id: ID of starting bootstage to use for progress updates + * @datap: Returns buf + * @loadp: Returns the address to which the data should be loaded + * @load_endp: Returns the end address of the data-loading location + * Return: 0 if OK, -ve on error + */ +static int handle_load_op(const void *fit, int noffset, const char *prop_name, + const void *buf, ulong size, + enum image_type_t image_type, + enum fit_load_op load_op, int bootstage_id, + ulong *datap, ulong *loadp, ulong *load_endp) +{ + ulong data, load; + + data = map_to_sysmem(buf); + load = data; + *load_endp = 0; + if (load_op == FIT_LOAD_IGNORED) { + log_debug("load_op: not loading\n"); + /* Don't load */ + } else if (fit_image_get_load(fit, noffset, &load)) { + if (load_op == FIT_LOAD_REQUIRED) { + printf("Can't get %s subimage load address!\n", + prop_name); + bootstage_error(bootstage_id + BOOTSTAGE_SUB_LOAD); + return -EBADF; + } + } else if (load_op != FIT_LOAD_OPTIONAL_NON_ZERO || load) { + ulong image_start, image_end; + + /* + * move image data to the load address, + * make sure we don't overwrite initial image + */ + image_start = map_to_sysmem(fit); + image_end = image_start + fit_get_size(fit); + + *load_endp = load + size; + if (image_type != IH_TYPE_KERNEL && + load < image_end && *load_endp > image_start) { + printf("Error: %s overwritten\n", prop_name); + return -EXDEV; + } + + printf(" Loading %s from 0x%08lx to 0x%08lx\n", + prop_name, data, load); + } else { + load = data; /* No load address specified */ + } + *datap = data; + *loadp = load; + + return 0; +} + int fit_image_load(struct bootm_headers *images, ulong addr, const char **fit_unamep, const char **fit_uname_configp, enum image_arch_t arch, int ph_type, int bootstage_id, @@ -2288,40 +2357,10 @@ int fit_image_load(struct bootm_headers *images, ulong addr, bootstage_mark(bootstage_id + BOOTSTAGE_SUB_GET_DATA_OK); - data = map_to_sysmem(buf); - load = data; - if (load_op == FIT_LOAD_IGNORED) { - log_debug("load_op: not loading\n"); - /* Don't load */ - } else if (fit_image_get_load(fit, noffset, &load)) { - if (load_op == FIT_LOAD_REQUIRED) { - printf("Can't get %s subimage load address!\n", - prop_name); - bootstage_error(bootstage_id + BOOTSTAGE_SUB_LOAD); - return -EBADF; - } - } else if (load_op != FIT_LOAD_OPTIONAL_NON_ZERO || load) { - ulong image_start, image_end; - - /* - * move image data to the load address, - * make sure we don't overwrite initial image - */ - image_start = addr; - image_end = addr + fit_get_size(fit); - - load_end = load + len; - if (image_type != IH_TYPE_KERNEL && - load < image_end && load_end > image_start) { - printf("Error: %s overwritten\n", prop_name); - return -EXDEV; - } - - printf(" Loading %s from 0x%08lx to 0x%08lx\n", - prop_name, data, load); - } else { - load = data; /* No load address specified */ - } + ret = handle_load_op(fit, noffset, prop_name, buf, len, image_type, + load_op, bootstage_id, &data, &load, &load_end); + if (ret) + return ret; comp = IH_COMP_NONE; loadbuf = buf; -- 2.43.0