
From: Simon Glass <sjg@chromium.org> Move the code which checks whether the image can be loaded into a separate check_allowed() function. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/image-fit.c | 98 ++++++++++++++++++++++++++++++------------------ include/image.h | 4 +- 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/boot/image-fit.c b/boot/image-fit.c index 754b309b91b..e5123176001 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -2160,9 +2160,64 @@ static int select_image(const void *fit, struct bootm_headers *images, return noffset; } +/** + * check_allowed() - Check if an image is allowed to be loaded + * + * @fit: FIT to check + * @noffset: Node offset of the image being loaded + * @image_type: Type of the image + * @arch: Expected architecture for the image + * @bootstage_id: ID of starting bootstage to use for progress updates + * Return: 0 if OK, -EIO if not + */ +static int check_allowed(const void *fit, int noffset, + enum image_type_t image_type, enum image_arch_t arch, + int bootstage_id) +{ + bool type_ok, os_ok; + uint8_t os; + + bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); + type_ok = fit_image_check_type(fit, noffset, image_type) || + fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE) || + fit_image_check_type(fit, noffset, IH_TYPE_TEE) || + fit_image_check_type(fit, noffset, IH_TYPE_TFA_BL31) || + (image_type == IH_TYPE_KERNEL && + fit_image_check_type(fit, noffset, IH_TYPE_KERNEL_NOLOAD)); + + os_ok = image_type == IH_TYPE_FLATDT || + image_type == IH_TYPE_FPGA || + fit_image_check_os(fit, noffset, IH_OS_LINUX) || + fit_image_check_os(fit, noffset, IH_OS_U_BOOT) || + fit_image_check_os(fit, noffset, IH_OS_TEE) || + fit_image_check_os(fit, noffset, IH_OS_OPENRTOS) || + fit_image_check_os(fit, noffset, IH_OS_EFI) || + fit_image_check_os(fit, noffset, IH_OS_VXWORKS) || + fit_image_check_os(fit, noffset, IH_OS_ELF); + + /* + * If either of the checks fail, we should report an error, but + * if the image type is coming from the "loadables" field, we + * don't care what it is + */ + if ((!type_ok || !os_ok) && image_type != IH_TYPE_LOADABLE) { + fit_image_get_os(fit, noffset, &os); + printf("No %s %s %s Image\n", + genimg_get_os_name(os), + genimg_get_arch_name(arch), + genimg_get_type_name(image_type)); + bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); + return -EIO; + } + + bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL_OK); + + return 0; +} + 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 image_arch_t 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); @@ -2174,10 +2229,10 @@ int fit_image_load(struct bootm_headers *images, ulong addr, void *buf; void *loadbuf; size_t size; - int type_ok, os_ok; ulong load, load_end, data, len; - uint8_t os, comp, os_arch; + uint8_t comp, os_arch; const char *prop_name; + int ret; fit = map_sysmem(addr, 0); prop_name = fit_get_image_type_property(ph_type); @@ -2204,40 +2259,9 @@ int fit_image_load(struct bootm_headers *images, ulong addr, fit_image_get_arch(fit, noffset, &os_arch); images_set_arch(images, os_arch); - bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); - type_ok = fit_image_check_type(fit, noffset, image_type) || - fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE) || - fit_image_check_type(fit, noffset, IH_TYPE_TEE) || - fit_image_check_type(fit, noffset, IH_TYPE_TFA_BL31) || - (image_type == IH_TYPE_KERNEL && - fit_image_check_type(fit, noffset, IH_TYPE_KERNEL_NOLOAD)); - - os_ok = image_type == IH_TYPE_FLATDT || - image_type == IH_TYPE_FPGA || - fit_image_check_os(fit, noffset, IH_OS_LINUX) || - fit_image_check_os(fit, noffset, IH_OS_U_BOOT) || - fit_image_check_os(fit, noffset, IH_OS_TEE) || - fit_image_check_os(fit, noffset, IH_OS_OPENRTOS) || - fit_image_check_os(fit, noffset, IH_OS_EFI) || - fit_image_check_os(fit, noffset, IH_OS_VXWORKS) || - fit_image_check_os(fit, noffset, IH_OS_ELF); - - /* - * If either of the checks fail, we should report an error, but - * if the image type is coming from the "loadables" field, we - * don't care what it is - */ - if ((!type_ok || !os_ok) && image_type != IH_TYPE_LOADABLE) { - fit_image_get_os(fit, noffset, &os); - printf("No %s %s %s Image\n", - genimg_get_os_name(os), - genimg_get_arch_name(arch), - genimg_get_type_name(image_type)); - bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); - return -EIO; - } - - bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL_OK); + ret = check_allowed(fit, noffset, image_type, arch, bootstage_id); + if (ret) + return ret; /* get image data address and length */ if (fit_image_get_data(fit, noffset, (const void **)&buf, &size)) { diff --git a/include/image.h b/include/image.h index 3a6afb5d954..0402cf92219 100644 --- a/include/image.h +++ b/include/image.h @@ -113,7 +113,7 @@ enum { * New IDs *MUST* be appended at the end of the list and *NEVER* * inserted for backward compatibility. */ -enum { +enum image_arch_t { IH_ARCH_INVALID = 0, /* Invalid CPU */ IH_ARCH_ALPHA, /* Alpha */ IH_ARCH_ARM, /* ARM */ @@ -837,7 +837,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, */ int fit_image_load(struct bootm_headers *images, ulong addr, const char **fit_unamep, const char **fit_uname_configp, - int arch, int image_ph_type, int bootstage_id, + enum image_arch_t arch, int image_ph_type, int bootstage_id, enum fit_load_op load_op, ulong *datap, ulong *lenp); /** -- 2.43.0