It's not possible to differentiate a flattened device tree from a FIT image without parsing it for top-level /images and /configurations node.
We thus have some checks that check for filetype_oftree instead of filetype_fit, which is confusing. Let's introduce filetype_fit and handle it at the boot layer to allow for slightly more readable code. This will pay off some more when we start making use of it in a later commit. Signed-off-by: Ahmad Fatoum <[email protected]> --- common/bootm.c | 7 +++---- common/filetype.c | 1 + common/image-fit.c | 11 ++++++++++- include/filetype.h | 7 +++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/common/bootm.c b/common/bootm.c index f1beac52ec15..1554a8f7f3f9 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -571,7 +571,7 @@ int bootm_boot(struct bootm_data *bootm_data) if (size < PAGE_SIZE) goto err_out; - os_type = data->os_type = file_detect_type(data->os_header, PAGE_SIZE); + os_type = data->os_type = file_detect_boot_image_type(data->os_header, PAGE_SIZE); if (!data->force && os_type == filetype_unknown) { pr_err("Unknown OS filetype (try -f)\n"); @@ -589,7 +589,7 @@ int bootm_boot(struct bootm_data *bootm_data) data->oftree_file = NULL; data->initrd_file = NULL; data->tee_file = NULL; - if (os_type != filetype_oftree) { + if (os_type != filetype_fit) { pr_err("Signed boot and image is no FIT image, aborting\n"); ret = -EINVAL; goto err_out; @@ -599,10 +599,9 @@ int bootm_boot(struct bootm_data *bootm_data) os_type_str = file_type_to_short_string(os_type); switch (os_type) { - case filetype_oftree: + case filetype_fit: ret = bootm_open_fit(data); os_type = file_detect_type(data->fit_kernel, data->fit_kernel_size); - os_type_str = "FIT"; break; case filetype_uimage: ret = bootm_open_uimage(data); diff --git a/common/filetype.c b/common/filetype.c index 9b348377f222..80b7e1d98ce0 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -42,6 +42,7 @@ static const struct filetype_str filetype_str[] = { [filetype_gzip] = { "GZIP compressed", "gzip" }, [filetype_bzip2] = { "BZIP2 compressed", "bzip2" }, [filetype_oftree] = { "open firmware Device Tree flattened Binary", "dtb" }, + [filetype_fit] = { "Flattened Image Tree", "FIT" }, [filetype_aimage] = { "android boot image", "android" }, [filetype_sh] = { "bourne SHell", "sh" }, [filetype_mips_barebox] = { "MIPS barebox image", "mips-barebox" }, diff --git a/common/image-fit.c b/common/image-fit.c index 5c3a3e8f230f..d8fa5a4c8a8b 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1081,10 +1081,19 @@ static int do_bootm_fit(struct image_data *data) return -EINVAL; } +static bool fitimage_check(struct image_handler *handler, + struct image_data *data, + enum filetype detected_filetype) +{ + return detected_filetype == filetype_oftree || + detected_filetype == filetype_fit; +} + static struct image_handler fit_handler = { .name = "FIT image", .bootm = do_bootm_fit, - .filetype = filetype_oftree, + .filetype = filetype_fit, + .check_image = fitimage_check, }; static int bootm_fit_register(void) diff --git a/include/filetype.h b/include/filetype.h index 0e19e46c513d..d404e0cf3c6a 100644 --- a/include/filetype.h +++ b/include/filetype.h @@ -24,6 +24,7 @@ enum filetype { filetype_gzip, filetype_bzip2, filetype_oftree, + filetype_fit, filetype_aimage, filetype_sh, filetype_mips_barebox, @@ -108,6 +109,12 @@ static inline bool file_is_compressed_file(enum filetype ft) } } +static inline enum filetype file_detect_boot_image_type(const void *_buf, size_t bufsize) +{ + enum filetype ft = file_detect_type(_buf, bufsize); + return ft == filetype_oftree ? filetype_fit : ft; +} + #define ARM_HEAD_SIZE 0x30 #define ARM_HEAD_MAGICWORD_OFFSET 0x20 #define ARM_HEAD_SIZE_OFFSET 0x2C -- 2.47.3
