mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 04/10] filetype: introduce filetype_fit
Date: Mon,  5 Jan 2026 09:03:36 +0100	[thread overview]
Message-ID: <20260105080653.3240497-5-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260105080653.3240497-1-a.fatoum@barebox.org>

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 <a.fatoum@barebox.org>
---
 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




  parent reply	other threads:[~2026-01-05  8:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 01/10] bootm: set image_data::initrd_res at a single place Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 02/10] bootm: fit: split support into dedicated file Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 03/10] bootm: uimage: " Ahmad Fatoum
2026-01-05  8:03 ` Ahmad Fatoum [this message]
2026-01-05  8:03 ` [PATCH 05/10] bootm: refactor for readability and extensibility Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 06/10] memory: move release_sdram_region into header Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 07/10] resource: make NULL in release_[sdram_]region a no-op Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 08/10] common: elf: use release_region unconditionally Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 09/10] memory: always print errors on request_sdram_region failure Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 10/10] memory: drop now duplicate request_sdram_region error messages Ahmad Fatoum
2026-01-09  8:20 ` [PATCH 00/10] bootm: refactor to prepare multiple initrd support Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260105080653.3240497-5-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox