mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 05/13] bootm: store separate image_type and kernel_type
Date: Mon,  9 Feb 2026 19:10:44 +0100	[thread overview]
Message-ID: <20260209181138.2023065-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260209181138.2023065-1-a.fatoum@pengutronix.de>

For FIT images, image_data::os_type is either the container file type or
the kernel file type, depending on when we are looking.

This makes the code harder to refactor, so let's split it into two
separate image_type and kernel_type members.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/booti.c     |  3 +--
 common/bootm-fit.c | 15 +++++++++++++++
 common/bootm.c     | 29 +++++++++++++++--------------
 efi/loader/bootm.c |  2 +-
 include/bootm.h    |  6 +++++-
 5 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/common/booti.c b/common/booti.c
index 67f31b793517..4f6ccf95f85c 100644
--- a/common/booti.c
+++ b/common/booti.c
@@ -32,8 +32,7 @@ static unsigned long get_kernel_address(unsigned long os_address,
 
 void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
 {
-	const void *kernel_header =
-			data->os_fit ? data->fit_kernel : data->os_header;
+	const void *kernel_header = data->os_header;
 	const struct resource *os_res;
 	unsigned long text_offset, image_size, kernel;
 	unsigned long image_end;
diff --git a/common/bootm-fit.c b/common/bootm-fit.c
index a0e808e31b40..5bfd8ac61d3f 100644
--- a/common/bootm-fit.c
+++ b/common/bootm-fit.c
@@ -5,6 +5,7 @@
 #include <bootm-fit.h>
 #include <memory.h>
 #include <zero_page.h>
+#include <filetype.h>
 
 /*
  * bootm_load_fit_os() - load OS from FIT to RAM
@@ -114,6 +115,17 @@ static bool bootm_fit_config_valid(struct fit_handle *fit,
 	return !!fit_has_image(fit, config, "kernel");
 }
 
+static enum filetype bootm_fit_update_os_header(struct image_data *data)
+{
+	if (data->fit_kernel_size < PAGE_SIZE)
+		return filetype_unknown;
+
+	free(data->os_header);
+	data->os_header = xmemdup(data->fit_kernel, PAGE_SIZE);
+
+	return file_detect_type(data->os_header, PAGE_SIZE);
+}
+
 int bootm_open_fit(struct image_data *data)
 {
 	struct fit_handle *fit;
@@ -148,6 +160,9 @@ int bootm_open_fit(struct image_data *data)
 			     &data->fit_kernel, &data->fit_kernel_size);
 	if (ret)
 		return ret;
+
+	data->kernel_type = bootm_fit_update_os_header(data);
+
 	if (data->os_address == UIMAGE_SOME_ADDRESS) {
 		ret = fit_get_image_address(data->os_fit,
 					    data->fit_config,
diff --git a/common/bootm.c b/common/bootm.c
index 505b670a4a5e..efb2f401ed9b 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -550,9 +550,8 @@ int bootm_boot(struct bootm_data *bootm_data)
 	struct image_data *data;
 	struct image_handler *handler;
 	int ret;
-	enum filetype os_type;
 	size_t size;
-	const char *os_type_str;
+	const char *image_type_str;
 
 	if (!bootm_data->os_file) {
 		pr_err("no image given\n");
@@ -583,9 +582,9 @@ int bootm_boot(struct bootm_data *bootm_data)
 	if (size < PAGE_SIZE)
 		goto err_out;
 
-	os_type = data->os_type = file_detect_boot_image_type(data->os_header, PAGE_SIZE);
+	data->image_type = file_detect_boot_image_type(data->os_header, PAGE_SIZE);
 
-	if (!data->force && os_type == filetype_unknown) {
+	if (!data->force && data->image_type == filetype_unknown) {
 		pr_err("Unknown OS filetype (try -f)\n");
 		ret = -EINVAL;
 		goto err_out;
@@ -601,19 +600,21 @@ int bootm_boot(struct bootm_data *bootm_data)
 		data->oftree_file = NULL;
 		data->initrd_file = NULL;
 		data->tee_file = NULL;
-		if (os_type != filetype_fit) {
+		if (data->image_type != filetype_fit) {
 			pr_err("Signed boot and image is no FIT image, aborting\n");
 			ret = -EINVAL;
 			goto err_out;
 		}
 	}
 
-	os_type_str = file_type_to_short_string(os_type);
+	image_type_str = file_type_to_short_string(data->image_type);
 
-	switch (os_type) {
+	/* May be updated by below container-specific handlers */
+	data->kernel_type = data->image_type;
+
+	switch (data->image_type) {
 	case filetype_fit:
 		ret = bootm_open_fit(data);
-		os_type = file_detect_type(data->fit_kernel, data->fit_kernel_size);
 		break;
 	case filetype_uimage:
 		ret = bootm_open_uimage(data);
@@ -624,7 +625,7 @@ int bootm_boot(struct bootm_data *bootm_data)
 	}
 
 	if (ret) {
-		pr_err("Loading %s image failed with: %pe\n", os_type_str, ERR_PTR(ret));
+		pr_err("Loading %s image failed with: %pe\n", image_type_str, ERR_PTR(ret));
 		goto err_out;
 	}
 
@@ -737,9 +738,9 @@ int bootm_boot(struct bootm_data *bootm_data)
 		free(hostname_bootarg);
 	}
 
-	pr_info("\nLoading %s '%s'", file_type_to_string(os_type),
+	pr_info("\nLoading %s '%s'", file_type_to_string(data->kernel_type),
 		data->os_file);
-	if (os_type == filetype_uimage &&
+	if (data->kernel_type == filetype_uimage &&
 			data->os->header.ih_type == IH_TYPE_MULTI)
 		pr_info(", multifile image %d", uimage_part_num(data->os_part));
 	pr_info("\n");
@@ -749,11 +750,11 @@ int bootm_boot(struct bootm_data *bootm_data)
 	if (data->os_entry == UIMAGE_SOME_ADDRESS)
 		data->os_entry = 0;
 
-	handler = bootm_find_handler(os_type, data);
+	handler = bootm_find_handler(data->kernel_type, data);
 	if (!handler) {
 		pr_err("no image handler found for image type %s\n",
-		       file_type_to_string(os_type));
-		if (os_type == filetype_uimage)
+		       file_type_to_string(data->kernel_type));
+		if (data->kernel_type == filetype_uimage)
 			pr_err("and OS type: %d\n", data->os->header.ih_os);
 		ret = -ENODEV;
 		goto err_out;
diff --git a/efi/loader/bootm.c b/efi/loader/bootm.c
index 498f4dce6b07..97621d8a05e5 100644
--- a/efi/loader/bootm.c
+++ b/efi/loader/bootm.c
@@ -215,7 +215,7 @@ static int efi_loader_bootm(struct image_data *data)
 	if (IS_ERR(os_res))
 		return PTR_ERR(os_res);
 
-	if (filetype_is_linux_efi_image(data->os_type)) {
+	if (filetype_is_linux_efi_image(data->kernel_type)) {
 		const char *options;
 
 		options = linux_bootargs_get();
diff --git a/include/bootm.h b/include/bootm.h
index 1c3bb8899b38..bdabba23f2b9 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -111,7 +111,11 @@ struct image_data {
 	char *tee_file;
 	struct resource *tee_res;
 
-	enum filetype os_type;
+	/* Type of OS image, e.g. filetype_fit or the same as kernel_type */
+	enum filetype image_type;
+	/* Type of kernel image that's going to be booted */
+	enum filetype kernel_type;
+
 	enum bootm_verify verify;
 	int verbose;
 	int force;
-- 
2.47.3




  parent reply	other threads:[~2026-02-09 18:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-09 18:10 [PATCH v2 00/13] bootm: prepare loadable abstraction rework Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 01/13] FIT: implement fit_count_images Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 02/13] FIT: add image index argument to fit_open_image Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 03/13] resource: implement gap-aware lookup_region Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 04/13] bootm: give bootm_load_ functions an end address Ahmad Fatoum
2026-02-09 18:10 ` Ahmad Fatoum [this message]
2026-02-09 18:10 ` [PATCH v2 06/13] bootm: fit: move length calculation into fit_open Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 07/13] libfile: factor out zero-page resistant read_file as __read_full_anywhere Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 08/13] resource: implement resize_region Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 09/13] bootm: rename image_data::os/initrd with _uimage suffix Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 10/13] uimage: record original file name in uimage_handle Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 11/13] bootm: factor out file detection into helper Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 12/13] efi: payload: bootm: add dry run support Ahmad Fatoum
2026-02-09 18:10 ` [PATCH v2 13/13] efi: initrd: make efi_initrd_register initrd pointer param const Ahmad Fatoum
2026-02-13 14:07 ` [PATCH v2 00/13] bootm: prepare loadable abstraction rework 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=20260209181138.2023065-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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