mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/10] bootm: refactor to prepare multiple initrd support
@ 2026-01-05  8:03 Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 01/10] bootm: set image_data::initrd_res at a single place Ahmad Fatoum
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox

Linux can transparently handle concatenated individually compressed CPIOs
just fine, but so far, the concantenation needed to happen before bootm
is called.

This series prepares for supporting initrd concatenation by refactoring
the bootm code to make it easier to extend in a follow-up series.

No functional change intended.

Ahmad Fatoum (10):
  bootm: set image_data::initrd_res at a single place
  bootm: fit: split support into dedicated file
  bootm: uimage: split support into dedicated file
  filetype: introduce filetype_fit
  bootm: refactor for readability and extensibility
  memory: move release_sdram_region into header
  resource: make NULL in release_[sdram_]region a no-op
  common: elf: use release_region unconditionally
  memory: always print errors on request_sdram_region failure
  memory: drop now duplicate request_sdram_region error messages

 arch/arm/cpu/armv7r-mpu.c |   6 +-
 arch/arm/cpu/bootm-fip.c  |  11 +-
 arch/arm/cpu/mmu_32.c     |   4 +-
 arch/arm/lib32/bootm.c    |  13 +-
 arch/arm/lib32/bootz.c    |   7 +-
 common/Makefile           |   2 +
 common/bootm-fit.c        | 176 ++++++++++++++++++
 common/bootm-uimage.c     | 176 ++++++++++++++++++
 common/bootm.c            | 376 ++++++--------------------------------
 common/elf.c              |  11 +-
 common/filetype.c         |   1 +
 common/image-fit.c        |  11 +-
 common/memory.c           |  25 +--
 common/resource.c         |   2 +
 common/uimage.c           |  12 +-
 fs/pstore/ram_core.c      |   7 +-
 include/bootm-fit.h       |  70 +++++++
 include/bootm-uimage.h    |  57 ++++++
 include/filetype.h        |   7 +
 include/memory.h          |  45 ++++-
 lib/libfile.c             |   5 +-
 21 files changed, 625 insertions(+), 399 deletions(-)
 create mode 100644 common/bootm-fit.c
 create mode 100644 common/bootm-uimage.c
 create mode 100644 include/bootm-fit.h
 create mode 100644 include/bootm-uimage.h

-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 01/10] bootm: set image_data::initrd_res at a single place
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
@ 2026-01-05  8:03 ` Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 02/10] bootm: fit: split support into dedicated file Ahmad Fatoum
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We are going to substantially rework this function, so make it easier to
reason about by setting the externally visible image_data->initrd_res
only at the end.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/bootm.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 4e4d940d9198..e60c81a9021e 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -339,6 +339,7 @@ static int bootm_open_initrd_uimage(struct image_data *data)
 const struct resource *
 bootm_load_initrd(struct image_data *data, unsigned long load_address)
 {
+	struct resource *res;
 	enum filetype type;
 	int ret;
 
@@ -362,10 +363,9 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)
 					ERR_PTR(ret));
 			return ERR_PTR(ret);
 		}
-		data->initrd_res = request_sdram_region("initrd",
-				load_address, initrd_size,
-				MEMTYPE_LOADER_DATA, MEMATTRS_RW);
-		if (!data->initrd_res) {
+		res = request_sdram_region("initrd", load_address, initrd_size,
+					   MEMTYPE_LOADER_DATA, MEMATTRS_RW);
+		if (!res) {
 			pr_err("unable to request SDRAM region for initrd at"
 					" 0x%08llx-0x%08llx\n",
 				(unsigned long long)load_address,
@@ -397,16 +397,15 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)
 
 		num = uimage_part_num(data->initrd_part);
 
-		data->initrd_res = uimage_load_to_sdram(data->initrd,
-			num, load_address);
-		if (!data->initrd_res)
+		res = uimage_load_to_sdram(data->initrd, num, load_address);
+		if (!res)
 			return ERR_PTR(-ENOMEM);
 
 		goto done;
 	}
 
-	data->initrd_res = file_to_sdram(data->initrd_file, load_address, MEMTYPE_LOADER_DATA);
-	if (!data->initrd_res)
+	res = file_to_sdram(data->initrd_file, load_address, MEMTYPE_LOADER_DATA);
+	if (!res)
 		return ERR_PTR(-ENOMEM);
 
 done:
@@ -417,10 +416,9 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)
 		pr_info(", multifile image %s", data->initrd_part);
 	pr_info("\n");
 done1:
-	pr_info("initrd is at %pa-%pa\n",
-		&data->initrd_res->start,
-		&data->initrd_res->end);
+	pr_info("initrd is at %pa-%pa\n", &res->start, &res->end);
 
+	data->initrd_res = res;
 	return data->initrd_res;
 }
 
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 02/10] bootm: fit: split support into dedicated file
  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 ` Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 03/10] bootm: uimage: " Ahmad Fatoum
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Interleaving the FIT handling with the generic bootm code makes the
generic code harder to follow. Let's factor it out into a dedicated
file.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/Makefile     |   1 +
 common/bootm-fit.c  | 185 ++++++++++++++++++++++++++++++++++++++++++++
 common/bootm.c      | 156 ++++---------------------------------
 include/bootm-fit.h |  70 +++++++++++++++++
 4 files changed, 271 insertions(+), 141 deletions(-)
 create mode 100644 common/bootm-fit.c
 create mode 100644 include/bootm-fit.h

diff --git a/common/Makefile b/common/Makefile
index 36dee5f7a98a..45bd00758e4a 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_RATP)		+= ratp/
 obj-$(CONFIG_BOOTCHOOSER)	+= bootchooser.o
 obj-$(CONFIG_UIMAGE)		+= uimage_types.o uimage.o
 obj-$(CONFIG_FITIMAGE)		+= image-fit.o
+obj-$(CONFIG_BOOTM_FITIMAGE)	+= bootm-fit.o
 obj-$(CONFIG_MENUTREE)		+= menutree.o
 lwl-$(CONFIG_IMD)		+= imd-barebox.o
 obj-$(CONFIG_IMD)		+= imd.o
diff --git a/common/bootm-fit.c b/common/bootm-fit.c
new file mode 100644
index 000000000000..f9c8bff43912
--- /dev/null
+++ b/common/bootm-fit.c
@@ -0,0 +1,185 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <bootm.h>
+#include <image-fit.h>
+#include <bootm-fit.h>
+#include <memory.h>
+#include <zero_page.h>
+
+/*
+ * bootm_load_fit_os() - load OS from FIT to RAM
+ *
+ * @data:		image data context
+ * @load_address:	The address where the OS should be loaded to
+ *
+ * This loads the OS to a RAM location. load_address must be a valid
+ * address. If the image_data doesn't have a OS specified it's considered
+ * an error.
+ *
+ * Return: 0 on success, negative error code otherwise
+ */
+int bootm_load_fit_os(struct image_data *data, unsigned long load_address)
+{
+	const void *kernel = data->fit_kernel;
+	unsigned long kernel_size = data->fit_kernel_size;
+
+	data->os_res = request_sdram_region("kernel",
+			load_address, kernel_size,
+			MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
+	if (!data->os_res) {
+		pr_err("unable to request SDRAM region for kernel at"
+				" 0x%08llx-0x%08llx\n",
+			(unsigned long long)load_address,
+			(unsigned long long)load_address + kernel_size - 1);
+		return -ENOMEM;
+	}
+	zero_page_memcpy((void *)load_address, kernel, kernel_size);
+	return 0;
+}
+
+static bool fitconfig_has_ramdisk(struct image_data *data)
+{
+	return fit_has_image(data->os_fit, data->fit_config, "ramdisk");
+}
+
+/*
+ * bootm_load_fit_initrd() - load initrd from FIT to RAM
+ *
+ * @data:		image data context
+ * @load_address:	The address where the initrd should be loaded to
+ *
+ * This loads the initrd to a RAM location. load_address must be a valid
+ * address. If the image_data doesn't have a initrd specified this function
+ * still returns successful as an initrd is optional.
+ *
+ * Return: initrd resource on success, NULL if no initrd is present or
+ *         an error pointer if an error occurred.
+ */
+struct resource *bootm_load_fit_initrd(struct image_data *data, unsigned long load_address)
+{
+	struct resource *res;
+	const void *initrd;
+	unsigned long initrd_size;
+	int ret;
+
+	if (!fitconfig_has_ramdisk(data))
+		return NULL;
+
+	ret = fit_open_image(data->os_fit, data->fit_config, "ramdisk",
+			     &initrd, &initrd_size);
+	if (ret) {
+		pr_err("Cannot open ramdisk image in FIT image: %pe\n",
+				ERR_PTR(ret));
+		return ERR_PTR(ret);
+	}
+	res = request_sdram_region("initrd",
+				   load_address, initrd_size,
+				   MEMTYPE_LOADER_DATA, MEMATTRS_RW);
+	if (!res) {
+		pr_err("unable to request SDRAM region for initrd at"
+				" 0x%08llx-0x%08llx\n",
+			(unsigned long long)load_address,
+			(unsigned long long)load_address + initrd_size - 1);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	memcpy((void *)load_address, initrd, initrd_size);
+	return res;
+}
+
+/*
+ * bootm_get_fit_devicetree() - get devicetree
+ *
+ * @data:		image data context
+ *
+ * This gets the fixed devicetree from the various image sources or the internal
+ * devicetree. It returns a pointer to the allocated devicetree which must be
+ * freed after use.
+ *
+ * Return: pointer to the fixed devicetree, NULL if image_data has an empty DT
+ *         or a ERR_PTR() on failure.
+ */
+void *bootm_get_fit_devicetree(struct image_data *data)
+{
+	int ret;
+	const void *of_tree;
+	unsigned long of_size;
+
+	ret = fit_open_image(data->os_fit, data->fit_config, "fdt",
+			     &of_tree, &of_size);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return of_unflatten_dtb(of_tree, of_size);
+}
+
+static bool bootm_fit_config_valid(struct fit_handle *fit,
+				   struct device_node *config)
+{
+	/*
+	 * Consider only FIT configurations which do provide a loadable kernel
+	 * image.
+	 */
+	return !!fit_has_image(fit, config, "kernel");
+}
+
+int bootm_open_fit(struct image_data *data)
+{
+	struct fit_handle *fit;
+	struct fdt_header *header;
+	static const char *kernel_img = "kernel";
+	size_t flen, hlen;
+	int ret;
+
+	header = (struct fdt_header *)data->os_header;
+	flen = bootm_get_os_size(data);
+	hlen = fdt32_to_cpu(header->totalsize);
+
+	fit = fit_open(data->os_file, data->verbose, data->verify,
+		       min(flen, hlen));
+	if (IS_ERR(fit)) {
+		pr_err("Loading FIT image %s failed with: %pe\n", data->os_file, fit);
+		return PTR_ERR(fit);
+	}
+
+	data->os_fit = fit;
+
+	data->fit_config = fit_open_configuration(data->os_fit,
+						  data->os_part,
+						  bootm_fit_config_valid);
+	if (IS_ERR(data->fit_config)) {
+		pr_err("Cannot open FIT image configuration '%s'\n",
+		       data->os_part ? data->os_part : "default");
+		return PTR_ERR(data->fit_config);
+	}
+
+	ret = fit_open_image(data->os_fit, data->fit_config, kernel_img,
+			     &data->fit_kernel, &data->fit_kernel_size);
+	if (ret)
+		return ret;
+	if (data->os_address == UIMAGE_SOME_ADDRESS) {
+		ret = fit_get_image_address(data->os_fit,
+					    data->fit_config,
+					    kernel_img,
+					    "load", &data->os_address);
+		if (!ret)
+			pr_info("Load address from FIT '%s': 0x%lx\n",
+				kernel_img, data->os_address);
+		/* Note: Error case uses default value. */
+	}
+	if (data->os_entry == UIMAGE_SOME_ADDRESS) {
+		unsigned long entry;
+		ret = fit_get_image_address(data->os_fit,
+					    data->fit_config,
+					    kernel_img,
+					    "entry", &entry);
+		if (!ret) {
+			data->os_entry = entry - data->os_address;
+			pr_info("Entry address from FIT '%s': 0x%lx\n",
+				kernel_img, entry);
+		}
+		/* Note: Error case uses default value. */
+	}
+
+	return 0;
+}
diff --git a/common/bootm.c b/common/bootm.c
index e60c81a9021e..dced46f3e067 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -11,6 +11,7 @@
 #include <memory.h>
 #include <block.h>
 #include <libfile.h>
+#include <bootm-fit.h>
 #include <image-fit.h>
 #include <globalvar.h>
 #include <init.h>
@@ -246,23 +247,8 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
 	if (load_address == UIMAGE_INVALID_ADDRESS)
 		return -EINVAL;
 
-	if (data->os_fit) {
-		const void *kernel = data->fit_kernel;
-		unsigned long kernel_size = data->fit_kernel_size;
-
-		data->os_res = request_sdram_region("kernel",
-				load_address, kernel_size,
-				MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
-		if (!data->os_res) {
-			pr_err("unable to request SDRAM region for kernel at"
-					" 0x%08llx-0x%08llx\n",
-				(unsigned long long)load_address,
-				(unsigned long long)load_address + kernel_size - 1);
-			return -ENOMEM;
-		}
-		zero_page_memcpy((void *)load_address, kernel, kernel_size);
-		return 0;
-	}
+	if (data->os_fit)
+		return bootm_load_fit_os(data, load_address);
 
 	if (image_is_uimage(data)) {
 		int num;
@@ -287,14 +273,6 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
 	return 0;
 }
 
-static bool fitconfig_has_ramdisk(struct image_data *data)
-{
-	if (!IS_ENABLED(CONFIG_FITIMAGE) || !data->os_fit)
-		return false;
-
-	return fit_has_image(data->os_fit, data->fit_config, "ramdisk");
-}
-
 static int bootm_open_initrd_uimage(struct image_data *data)
 {
 	int ret;
@@ -352,28 +330,13 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)
 	if (data->initrd_res)
 		return data->initrd_res;
 
-	if (fitconfig_has_ramdisk(data)) {
-		const void *initrd;
-		unsigned long initrd_size;
+	if (data->os_fit) {
+		res = bootm_load_fit_initrd(data, load_address);
+		if (IS_ERR(res))
+			return res;
+		if (res)
+			pr_info("Loaded initrd from FIT image\n");
 
-		ret = fit_open_image(data->os_fit, data->fit_config, "ramdisk",
-				     &initrd, &initrd_size);
-		if (ret) {
-			pr_err("Cannot open ramdisk image in FIT image: %pe\n",
-					ERR_PTR(ret));
-			return ERR_PTR(ret);
-		}
-		res = request_sdram_region("initrd", load_address, initrd_size,
-					   MEMTYPE_LOADER_DATA, MEMATTRS_RW);
-		if (!res) {
-			pr_err("unable to request SDRAM region for initrd at"
-					" 0x%08llx-0x%08llx\n",
-				(unsigned long long)load_address,
-				(unsigned long long)load_address + initrd_size - 1);
-			return ERR_PTR(-ENOMEM);
-		}
-		memcpy((void *)load_address, initrd, initrd_size);
-		pr_info("Loaded initrd from FIT image\n");
 		goto done1;
 	}
 
@@ -416,7 +379,8 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)
 		pr_info(", multifile image %s", data->initrd_part);
 	pr_info("\n");
 done1:
-	pr_info("initrd is at %pa-%pa\n", &res->start, &res->end);
+	if (res)
+		pr_info("initrd is at %pa-%pa\n", &res->start, &res->end);
 
 	data->initrd_res = res;
 	return data->initrd_res;
@@ -464,14 +428,6 @@ static int bootm_open_oftree_uimage(struct image_data *data, size_t *size,
 	return 0;
 }
 
-static bool fitconfig_has_fdt(struct image_data *data)
-{
-	if (!IS_ENABLED(CONFIG_FITIMAGE) || !data->os_fit)
-		return false;
-
-	return fit_has_image(data->os_fit, data->fit_config, "fdt");
-}
-
 /*
  * bootm_get_devicetree() - get devicetree
  *
@@ -494,20 +450,12 @@ void *bootm_get_devicetree(struct image_data *data)
 	if (!IS_ENABLED(CONFIG_OFTREE))
 		return ERR_PTR(-ENOSYS);
 
-	from_fit = fitconfig_has_fdt(data);
+	from_fit = bootm_fit_has_fdt(data);
 	if (bootm_get_override(&data->oftree_file, bootm_overrides.oftree_file))
 		from_fit = false;
 
 	if (from_fit) {
-		const void *of_tree;
-		unsigned long of_size;
-
-		ret = fit_open_image(data->os_fit, data->fit_config, "fdt",
-				     &of_tree, &of_size);
-		if (ret)
-			return ERR_PTR(ret);
-
-		data->of_root_node = of_unflatten_dtb(of_tree, of_size);
+		data->of_root_node = bootm_get_fit_devicetree(data);
 	} else if (data->oftree_file) {
 		size_t size;
 
@@ -671,80 +619,6 @@ static int bootm_open_os_uimage(struct image_data *data)
 	return 0;
 }
 
-static bool bootm_fit_config_valid(struct fit_handle *fit,
-				   struct device_node *config)
-{
-	/*
-	 * Consider only FIT configurations which do provide a loadable kernel
-	 * image.
-	 */
-	return !!fit_has_image(fit, config, "kernel");
-}
-
-static int bootm_open_fit(struct image_data *data)
-{
-	struct fit_handle *fit;
-	struct fdt_header *header;
-	static const char *kernel_img = "kernel";
-	size_t flen, hlen;
-	int ret;
-
-	if (!IS_ENABLED(CONFIG_FITIMAGE))
-		return -ENOSYS;
-
-	header = (struct fdt_header *)data->os_header;
-	flen = bootm_get_os_size(data);
-	hlen = fdt32_to_cpu(header->totalsize);
-
-	fit = fit_open(data->os_file, data->verbose, data->verify,
-		       min(flen, hlen));
-	if (IS_ERR(fit)) {
-		pr_err("Loading FIT image %s failed with: %pe\n", data->os_file, fit);
-		return PTR_ERR(fit);
-	}
-
-	data->os_fit = fit;
-
-	data->fit_config = fit_open_configuration(data->os_fit,
-						  data->os_part,
-						  bootm_fit_config_valid);
-	if (IS_ERR(data->fit_config)) {
-		pr_err("Cannot open FIT image configuration '%s'\n",
-		       data->os_part ? data->os_part : "default");
-		return PTR_ERR(data->fit_config);
-	}
-
-	ret = fit_open_image(data->os_fit, data->fit_config, kernel_img,
-			     &data->fit_kernel, &data->fit_kernel_size);
-	if (ret)
-		return ret;
-	if (data->os_address == UIMAGE_SOME_ADDRESS) {
-		ret = fit_get_image_address(data->os_fit,
-					    data->fit_config,
-					    kernel_img,
-					    "load", &data->os_address);
-		if (!ret)
-			pr_info("Load address from FIT '%s': 0x%lx\n",
-				kernel_img, data->os_address);
-		/* Note: Error case uses default value. */
-	}
-	if (data->os_entry == UIMAGE_SOME_ADDRESS) {
-		unsigned long entry;
-		ret = fit_get_image_address(data->os_fit,
-					    data->fit_config,
-					    kernel_img,
-					    "entry", &entry);
-		if (!ret) {
-			data->os_entry = entry - data->os_address;
-			pr_info("Entry address from FIT '%s': 0x%lx\n",
-				kernel_img, entry);
-		}
-		/* Note: Error case uses default value. */
-	}
-
-	return 0;
-}
-
 static void bootm_print_info(struct image_data *data)
 {
 	if (data->os_res)
@@ -1028,8 +902,8 @@ int bootm_boot(struct bootm_data *bootm_data)
 			uimage_close(data->initrd);
 		uimage_close(data->os);
 	}
-	if (IS_ENABLED(CONFIG_FITIMAGE) && data->os_fit)
-		fit_close(data->os_fit);
+	if (data->os_fit)
+		bootm_close_fit(data);
 	if (data->of_root_node)
 		of_delete_node(data->of_root_node);
 
diff --git a/include/bootm-fit.h b/include/bootm-fit.h
new file mode 100644
index 000000000000..8deddd62e328
--- /dev/null
+++ b/include/bootm-fit.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __BOOTM_FIT_H
+#define __BOOTM_FIT_H
+
+#include <linux/types.h>
+#include <image-fit.h>
+#include <bootm.h>
+
+struct resource;
+
+#ifdef CONFIG_BOOTM_FITIMAGE
+
+int bootm_load_fit_os(struct image_data *data, unsigned long load_address);
+
+struct resource *bootm_load_fit_initrd(struct image_data *data,
+				       unsigned long load_address);
+
+void *bootm_get_fit_devicetree(struct image_data *data);
+
+int bootm_open_fit(struct image_data *data);
+
+static inline void bootm_close_fit(struct image_data *data)
+{
+	fit_close(data->os_fit);
+}
+
+static inline bool bootm_fit_has_fdt(struct image_data *data)
+{
+	if (!data->os_fit)
+		return false;
+
+	return fit_has_image(data->os_fit, data->fit_config, "fdt");
+}
+
+#else
+
+static inline int bootm_load_fit_os(struct image_data *data,
+				    unsigned long load_address)
+{
+	return -ENOSYS;
+}
+
+static inline struct resource *bootm_load_fit_initrd(struct image_data *data,
+						     unsigned long load_address)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
+static inline void *bootm_get_fit_devicetree(struct image_data *data)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
+static inline int bootm_open_fit(struct image_data *data)
+{
+	return -ENOSYS;
+}
+
+static inline void bootm_close_fit(struct image_data *data)
+{
+}
+
+static inline bool bootm_fit_has_fdt(struct image_data *data)
+{
+	return false;
+}
+
+#endif
+
+#endif
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 03/10] bootm: uimage: split support into dedicated file
  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 ` Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 04/10] filetype: introduce filetype_fit Ahmad Fatoum
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Interleaving the uImage handling with the generic bootm code makes the
generic code harder to follow. Let's factor it out into a dedicated
file.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/Makefile        |   1 +
 common/bootm-uimage.c  | 176 +++++++++++++++++++++++++++++++++++++++++
 common/bootm.c         | 143 +++------------------------------
 include/bootm-uimage.h |  57 +++++++++++++
 4 files changed, 243 insertions(+), 134 deletions(-)
 create mode 100644 common/bootm-uimage.c
 create mode 100644 include/bootm-uimage.h

diff --git a/common/Makefile b/common/Makefile
index 45bd00758e4a..751f3ba20293 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_TLV)		+= tlv/
 obj-$(CONFIG_RATP)		+= ratp/
 obj-$(CONFIG_BOOTCHOOSER)	+= bootchooser.o
 obj-$(CONFIG_UIMAGE)		+= uimage_types.o uimage.o
+obj-$(CONFIG_BOOTM_UIMAGE)	+= bootm-uimage.o
 obj-$(CONFIG_FITIMAGE)		+= image-fit.o
 obj-$(CONFIG_BOOTM_FITIMAGE)	+= bootm-fit.o
 obj-$(CONFIG_MENUTREE)		+= menutree.o
diff --git a/common/bootm-uimage.c b/common/bootm-uimage.c
new file mode 100644
index 000000000000..609b678e1d4a
--- /dev/null
+++ b/common/bootm-uimage.c
@@ -0,0 +1,176 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <bootm.h>
+#include <bootm-uimage.h>
+#include <linux/kstrtox.h>
+
+static int uimage_part_num(const char *partname)
+{
+	if (!partname)
+		return 0;
+	return simple_strtoul(partname, NULL, 0);
+}
+
+/*
+ * bootm_load_uimage_os() - load uImage OS to RAM
+ *
+ * @data:		image data context
+ * @load_address:	The address where the OS should be loaded to
+ *
+ * This loads the OS to a RAM location. load_address must be a valid
+ * address. If the image_data doesn't have a OS specified it's considered
+ * an error.
+ *
+ * Return: 0 on success, negative error code otherwise
+ */
+int bootm_load_uimage_os(struct image_data *data, unsigned long load_address)
+{
+	int num;
+
+	num = uimage_part_num(data->os_part);
+
+	data->os_res = uimage_load_to_sdram(data->os,
+		num, load_address);
+	if (!data->os_res)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static int bootm_open_initrd_uimage(struct image_data *data)
+{
+	int ret;
+
+	if (strcmp(data->os_file, data->initrd_file)) {
+		data->initrd = uimage_open(data->initrd_file);
+		if (!data->initrd)
+			return -EINVAL;
+
+		if (bootm_get_verify_mode() > BOOTM_VERIFY_NONE) {
+			ret = uimage_verify(data->initrd);
+			if (ret) {
+				pr_err("Checking data crc failed with %pe\n",
+					ERR_PTR(ret));
+				return ret;
+			}
+		}
+		uimage_print_contents(data->initrd);
+	} else {
+		data->initrd = data->os;
+	}
+
+	return 0;
+}
+
+/*
+ * bootm_load_uimage_initrd() - load initrd from uimage to RAM
+ *
+ * @data:		image data context
+ * @load_address:	The address where the initrd should be loaded to
+ *
+ * This loads the initrd to a RAM location. load_address must be a valid
+ * address. If the image_data doesn't have a initrd specified this function
+ * still returns successful as an initrd is optional.
+ *
+ * Return: initrd resource on success, NULL if no initrd is present or
+ *         an error pointer if an error occurred.
+ */
+struct resource *
+bootm_load_uimage_initrd(struct image_data *data, unsigned long load_address)
+{
+	struct resource *res;
+	int ret;
+
+	int num;
+	ret = bootm_open_initrd_uimage(data);
+	if (ret) {
+		pr_err("loading initrd failed with %pe\n", ERR_PTR(ret));
+		return ERR_PTR(ret);
+	}
+
+	num = uimage_part_num(data->initrd_part);
+
+	res = uimage_load_to_sdram(data->initrd,
+		num, load_address);
+	if (!res)
+		return ERR_PTR(-ENOMEM);
+
+	return res;
+}
+
+int bootm_open_oftree_uimage(struct image_data *data, size_t *size,
+			     struct fdt_header **fdt)
+{
+	enum filetype ft;
+	const char *oftree = data->oftree_file;
+	int num = uimage_part_num(data->oftree_part);
+	struct uimage_handle *of_handle;
+	int release = 0;
+
+	pr_info("Loading devicetree from '%s'@%d\n", oftree, num);
+
+	if (!strcmp(data->os_file, oftree)) {
+		of_handle = data->os;
+	} else if (!strcmp(data->initrd_file, oftree)) {
+		of_handle = data->initrd;
+	} else {
+		of_handle = uimage_open(oftree);
+		if (!of_handle)
+			return -ENODEV;
+		uimage_print_contents(of_handle);
+		release = 1;
+	}
+
+	*fdt = uimage_load_to_buf(of_handle, num, size);
+
+	if (release)
+		uimage_close(of_handle);
+
+	ft = file_detect_type(*fdt, *size);
+	if (ft != filetype_oftree) {
+		pr_err("%s is not an oftree but %s\n",
+			data->oftree_file, file_type_to_string(ft));
+		free(*fdt);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int bootm_open_uimage(struct image_data *data)
+{
+	int ret;
+
+	data->os = uimage_open(data->os_file);
+	if (!data->os)
+		return -EINVAL;
+
+	if (bootm_get_verify_mode() > BOOTM_VERIFY_NONE) {
+		ret = uimage_verify(data->os);
+		if (ret) {
+			pr_err("Checking data crc failed with %pe\n",
+					ERR_PTR(ret));
+			return ret;
+		}
+	}
+
+	uimage_print_contents(data->os);
+
+	if (IH_ARCH == IH_ARCH_INVALID || data->os->header.ih_arch != IH_ARCH) {
+		pr_err("Unsupported Architecture 0x%x\n",
+		       data->os->header.ih_arch);
+		return -EINVAL;
+	}
+
+	if (data->os_address == UIMAGE_SOME_ADDRESS)
+		data->os_address = data->os->header.ih_load;
+
+	return 0;
+}
+
+void bootm_close_uimage(struct image_data *data)
+{
+	if (data->initrd && data->initrd != data->os)
+		uimage_close(data->initrd);
+	uimage_close(data->os);
+}
diff --git a/common/bootm.c b/common/bootm.c
index dced46f3e067..f1beac52ec15 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -13,6 +13,7 @@
 #include <libfile.h>
 #include <bootm-fit.h>
 #include <image-fit.h>
+#include <bootm-uimage.h>
 #include <globalvar.h>
 #include <init.h>
 #include <environment.h>
@@ -250,18 +251,8 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
 	if (data->os_fit)
 		return bootm_load_fit_os(data, load_address);
 
-	if (image_is_uimage(data)) {
-		int num;
-
-		num = uimage_part_num(data->os_part);
-
-		data->os_res = uimage_load_to_sdram(data->os,
-			num, load_address);
-		if (!data->os_res)
-			return -ENOMEM;
-
-		return 0;
-	}
+	if (image_is_uimage(data))
+		return bootm_load_uimage_os(data, load_address);
 
 	if (!data->os_file)
 		return -EINVAL;
@@ -273,34 +264,6 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
 	return 0;
 }
 
-static int bootm_open_initrd_uimage(struct image_data *data)
-{
-	int ret;
-
-	if (!IS_ENABLED(CONFIG_BOOTM_UIMAGE))
-		return -ENOSYS;
-
-	if (strcmp(data->os_file, data->initrd_file)) {
-		data->initrd = uimage_open(data->initrd_file);
-		if (!data->initrd)
-			return -EINVAL;
-
-		if (bootm_get_verify_mode() > BOOTM_VERIFY_NONE) {
-			ret = uimage_verify(data->initrd);
-			if (ret) {
-				pr_err("Checking data crc failed with %pe\n",
-					ERR_PTR(ret));
-				return ret;
-			}
-		}
-		uimage_print_contents(data->initrd);
-	} else {
-		data->initrd = data->os;
-	}
-
-	return 0;
-}
-
 /*
  * bootm_load_initrd() - load initrd to RAM
  *
@@ -351,18 +314,9 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)
 	}
 
 	if (type == filetype_uimage) {
-		int num;
-		ret = bootm_open_initrd_uimage(data);
-		if (ret) {
-			pr_err("loading initrd failed with %pe\n", ERR_PTR(ret));
-			return ERR_PTR(ret);
-		}
-
-		num = uimage_part_num(data->initrd_part);
-
-		res = uimage_load_to_sdram(data->initrd, num, load_address);
-		if (!res)
-			return ERR_PTR(-ENOMEM);
+		res = bootm_load_uimage_initrd(data, load_address);
+		if (IS_ERR(res))
+			return res;
 
 		goto done;
 	}
@@ -386,48 +340,6 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)
 	return data->initrd_res;
 }
 
-static int bootm_open_oftree_uimage(struct image_data *data, size_t *size,
-				    struct fdt_header **fdt)
-{
-	enum filetype ft;
-	const char *oftree = data->oftree_file;
-	int num = uimage_part_num(data->oftree_part);
-	struct uimage_handle *of_handle;
-	int release = 0;
-
-	pr_info("Loading devicetree from '%s'@%d\n", oftree, num);
-
-	if (!IS_ENABLED(CONFIG_BOOTM_OFTREE_UIMAGE))
-		return -EINVAL;
-
-	if (!strcmp(data->os_file, oftree)) {
-		of_handle = data->os;
-	} else if (!strcmp(data->initrd_file, oftree)) {
-		of_handle = data->initrd;
-	} else {
-		of_handle = uimage_open(oftree);
-		if (!of_handle)
-			return -ENODEV;
-		uimage_print_contents(of_handle);
-		release = 1;
-	}
-
-	*fdt = uimage_load_to_buf(of_handle, num, size);
-
-	if (release)
-		uimage_close(of_handle);
-
-	ft = file_detect_type(*fdt, *size);
-	if (ft != filetype_oftree) {
-		pr_err("%s is not an oftree but %s\n",
-			data->oftree_file, file_type_to_string(ft));
-		free(*fdt);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 /*
  * bootm_get_devicetree() - get devicetree
  *
@@ -585,40 +497,6 @@ int bootm_get_os_size(struct image_data *data)
 	return s.st_size;
 }
 
-static int bootm_open_os_uimage(struct image_data *data)
-{
-	int ret;
-
-	if (!IS_ENABLED(CONFIG_BOOTM_UIMAGE))
-		return -ENOSYS;
-
-	data->os = uimage_open(data->os_file);
-	if (!data->os)
-		return -EINVAL;
-
-	if (bootm_get_verify_mode() > BOOTM_VERIFY_NONE) {
-		ret = uimage_verify(data->os);
-		if (ret) {
-			pr_err("Checking data crc failed with %pe\n",
-					ERR_PTR(ret));
-			return ret;
-		}
-	}
-
-	uimage_print_contents(data->os);
-
-	if (IH_ARCH == IH_ARCH_INVALID || data->os->header.ih_arch != IH_ARCH) {
-		pr_err("Unsupported Architecture 0x%x\n",
-		       data->os->header.ih_arch);
-		return -EINVAL;
-	}
-
-	if (data->os_address == UIMAGE_SOME_ADDRESS)
-		data->os_address = data->os->header.ih_load;
-
-	return 0;
-}
-
 static void bootm_print_info(struct image_data *data)
 {
 	if (data->os_res)
@@ -727,7 +605,7 @@ int bootm_boot(struct bootm_data *bootm_data)
 		os_type_str = "FIT";
 		break;
 	case filetype_uimage:
-		ret = bootm_open_os_uimage(data);
+		ret = bootm_open_uimage(data);
 		break;
 	default:
 		ret = 0;
@@ -897,11 +775,8 @@ int bootm_boot(struct bootm_data *bootm_data)
 		release_sdram_region(data->oftree_res);
 	if (data->tee_res)
 		release_sdram_region(data->tee_res);
-	if (image_is_uimage(data)) {
-		if (data->initrd && data->initrd != data->os)
-			uimage_close(data->initrd);
-		uimage_close(data->os);
-	}
+	if (image_is_uimage(data))
+		bootm_close_uimage(data);
 	if (data->os_fit)
 		bootm_close_fit(data);
 	if (data->of_root_node)
diff --git a/include/bootm-uimage.h b/include/bootm-uimage.h
new file mode 100644
index 000000000000..aac2beb35e2a
--- /dev/null
+++ b/include/bootm-uimage.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __BOOTM_UIMAGE_H
+#define __BOOTM_UIMAGE_H
+
+#include <linux/types.h>
+#include <linux/err.h>
+
+struct image_data;
+struct fdt_header;
+struct resource;
+
+#ifdef CONFIG_BOOTM_UIMAGE
+
+int bootm_load_uimage_os(struct image_data *data, unsigned long load_address);
+
+struct resource *bootm_load_uimage_initrd(struct image_data *data,
+					  unsigned long load_address);
+
+int bootm_open_oftree_uimage(struct image_data *data, size_t *size,
+			     struct fdt_header **fdt);
+int bootm_open_uimage(struct image_data *data);
+
+void bootm_close_uimage(struct image_data *data);
+
+#else
+
+static inline int bootm_load_uimage_os(struct image_data *data,
+				       unsigned long load_address)
+{
+	return -ENOSYS;
+}
+
+static inline struct resource *
+bootm_load_uimage_initrd(struct image_data *data, unsigned long load_address)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
+static inline int bootm_open_oftree_uimage(struct image_data *data,
+					   size_t *size,
+					   struct fdt_header **fdt)
+{
+	return -ENOSYS;
+}
+
+static inline int bootm_open_uimage(struct image_data *data)
+{
+	return -ENOSYS;
+}
+
+static inline void bootm_close_uimage(struct image_data *data)
+{
+}
+
+#endif
+
+#endif
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 04/10] filetype: introduce filetype_fit
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2026-01-05  8:03 ` [PATCH 03/10] bootm: uimage: " Ahmad Fatoum
@ 2026-01-05  8:03 ` Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 05/10] bootm: refactor for readability and extensibility Ahmad Fatoum
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 05/10] bootm: refactor for readability and extensibility
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2026-01-05  8:03 ` [PATCH 04/10] filetype: introduce filetype_fit Ahmad Fatoum
@ 2026-01-05  8:03 ` Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 06/10] memory: move release_sdram_region into header Ahmad Fatoum
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The code is hard to follow with the gotos and the organically grown
ordering. Let's refactor it, so we can start putting a loop around it.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/bootm.c | 71 +++++++++++++++++++++++---------------------------
 1 file changed, 32 insertions(+), 39 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 1554a8f7f3f9..26fd8227f01f 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -280,61 +280,54 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
 const struct resource *
 bootm_load_initrd(struct image_data *data, unsigned long load_address)
 {
-	struct resource *res;
-	enum filetype type;
+	struct resource *res = NULL;
+	const char *initrd, *initrd_part = NULL;
+	enum filetype type = filetype_unknown;
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_BOOTM_INITRD))
 		return NULL;
 
-	if (bootm_get_override(&data->initrd_file, bootm_overrides.initrd_file))
-		goto initrd_file;
-
-	if (data->initrd_res)
+	/* TODO: This should not be set anywhere, but in case it is, let's print
+	 * a warning to find out if we need this
+	 */
+	if (WARN_ON(data->initrd_res))
 		return data->initrd_res;
 
-	if (data->os_fit) {
-		res = bootm_load_fit_initrd(data, load_address);
-		if (IS_ERR(res))
-			return res;
-		if (res)
-			pr_info("Loaded initrd from FIT image\n");
+	bootm_get_override(&data->initrd_file, bootm_overrides.initrd_file);
 
-		goto done1;
-	}
-
-initrd_file:
-	if (!data->initrd_file)
-		return NULL;
-
-	ret = file_name_detect_type(data->initrd_file, &type);
-	if (ret) {
-		pr_err("could not open initrd \"%s\": %pe\n", data->initrd_file, ERR_PTR(ret));
-		return ERR_PTR(ret);
+	initrd = data->initrd_file;
+	if (initrd) {
+		ret = file_name_detect_type(initrd, &type);
+		if (ret) {
+			pr_err("could not open initrd \"%s\": %pe\n",
+			       initrd, ERR_PTR(ret));
+			return ERR_PTR(ret);
+		}
 	}
 
 	if (type == filetype_uimage) {
 		res = bootm_load_uimage_initrd(data, load_address);
-		if (IS_ERR(res))
-			return res;
+		if (data->initrd->header.ih_type == IH_TYPE_MULTI)
+			initrd_part = data->initrd_part;
+
+	} else if (initrd) {
+		res = file_to_sdram(initrd, load_address, MEMTYPE_LOADER_DATA)
+			?: ERR_PTR(-ENOMEM);
+
+	} else if (data->os_fit) {
+		res = bootm_load_fit_initrd(data, load_address);
+		type = filetype_fit;
 
-		goto done;
 	}
 
-	res = file_to_sdram(data->initrd_file, load_address, MEMTYPE_LOADER_DATA);
-	if (!res)
-		return ERR_PTR(-ENOMEM);
+	if (IS_ERR_OR_NULL(res))
+		return res;
 
-done:
-
-	pr_info("Loaded initrd %s '%s'", file_type_to_string(type),
-	       data->initrd_file);
-	if (type == filetype_uimage && data->initrd->header.ih_type == IH_TYPE_MULTI)
-		pr_info(", multifile image %s", data->initrd_part);
-	pr_info("\n");
-done1:
-	if (res)
-		pr_info("initrd is at %pa-%pa\n", &res->start, &res->end);
+	pr_info("Loaded initrd from %s %s%s%s to %pa-%pa\n",
+		file_type_to_string(type), initrd,
+		initrd_part ? "@" : "", initrd_part ?: "",
+		&res->start, &res->end);
 
 	data->initrd_res = res;
 	return data->initrd_res;
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 06/10] memory: move release_sdram_region into header
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2026-01-05  8:03 ` [PATCH 05/10] bootm: refactor for readability and extensibility Ahmad Fatoum
@ 2026-01-05  8:03 ` Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 07/10] resource: make NULL in release_[sdram_]region a no-op Ahmad Fatoum
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

To make it clear that release_sdram_region and release_region are the
same, move it into a header and give it a comment saying as much.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/memory.c  | 5 -----
 include/memory.h | 6 +++++-
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index 2cd6d29a8f2b..7dc7f40db7fc 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -352,11 +352,6 @@ struct resource *reserve_sdram_region(const char *name, resource_size_t start,
 	return res;
 }
 
-int release_sdram_region(struct resource *res)
-{
-	return release_region(res);
-}
-
 void memory_bank_find_space(struct memory_bank *bank, resource_size_t *retstart,
 			   resource_size_t *retend)
 {
diff --git a/include/memory.h b/include/memory.h
index 6189a0f65c50..3475e9211b0c 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -63,7 +63,11 @@ static inline struct resource *request_sdram_region(const char *name,
 struct resource *reserve_sdram_region(const char *name, resource_size_t start,
 				      resource_size_t size);
 
-int release_sdram_region(struct resource *res);
+/* It's always fine to call release_region directly as well */
+static inline int release_sdram_region(struct resource *res)
+{
+	return release_region(res);
+}
 
 void memory_bank_find_space(struct memory_bank *bank, resource_size_t *retstart,
 			    resource_size_t *retend);
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 07/10] resource: make NULL in release_[sdram_]region a no-op
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
                   ` (5 preceding siblings ...)
  2026-01-05  8:03 ` [PATCH 06/10] memory: move release_sdram_region into header Ahmad Fatoum
@ 2026-01-05  8:03 ` Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 08/10] common: elf: use release_region unconditionally Ahmad Fatoum
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

By handling the NULL inside release_region, we can remove some
clutter in caller error handling for release_sdram_region.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/arm/cpu/bootm-fip.c |  5 ++---
 arch/arm/lib32/bootz.c   |  3 +--
 common/bootm.c           | 18 ++++++------------
 common/resource.c        |  2 ++
 fs/pstore/ram_core.c     |  7 +++----
 5 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/arch/arm/cpu/bootm-fip.c b/arch/arm/cpu/bootm-fip.c
index a50b3f4431d0..8d1ea3f109d1 100644
--- a/arch/arm/cpu/bootm-fip.c
+++ b/arch/arm/cpu/bootm-fip.c
@@ -52,9 +52,8 @@ static int desc_to_sdram(struct fip_image_desc *loadable, ulong load_address)
 
 static void desc_release_sdram(struct fip_image_desc *loadable)
 {
-	struct resource *res = loadable ? desc_get_res(loadable) : NULL;
-	if (res)
-		release_sdram_region(res);
+	if (loadable)
+		release_sdram_region(desc_get_res(loadable));
 }
 
 enum { IMAGE_BL33, IMAGE_HW_CONFIG, IMAGE_COUNT };
diff --git a/arch/arm/lib32/bootz.c b/arch/arm/lib32/bootz.c
index 6ed6af1d19e3..0ace36271026 100644
--- a/arch/arm/lib32/bootz.c
+++ b/arch/arm/lib32/bootz.c
@@ -127,8 +127,7 @@ static int do_bootz(int argc, char *argv[])
 	return 0;
 
 err_out2:
-	if (res)
-		release_sdram_region(res);
+	release_sdram_region(res);
 err_out1:
 	free(zimage);
 err_out:
diff --git a/common/bootm.c b/common/bootm.c
index 26fd8227f01f..933e9dfc69fe 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -748,10 +748,8 @@ int bootm_boot(struct bootm_data *bootm_data)
 	bootm_get_override(&data->oftree_file, bootm_overrides.oftree_file);
 
 	if (bootm_get_override(&data->initrd_file, bootm_overrides.initrd_file)) {
-		if (data->initrd_res) {
-			release_sdram_region(data->initrd_res);
-			data->initrd_res = NULL;
-		}
+		release_sdram_region(data->initrd_res);
+		data->initrd_res = NULL;
 	}
 
 	ret = handler->bootm(data);
@@ -759,14 +757,10 @@ int bootm_boot(struct bootm_data *bootm_data)
 		pr_info("Dryrun. Aborted\n");
 
 err_out:
-	if (data->os_res)
-		release_sdram_region(data->os_res);
-	if (data->initrd_res)
-		release_sdram_region(data->initrd_res);
-	if (data->oftree_res)
-		release_sdram_region(data->oftree_res);
-	if (data->tee_res)
-		release_sdram_region(data->tee_res);
+	release_sdram_region(data->os_res);
+	release_sdram_region(data->initrd_res);
+	release_sdram_region(data->oftree_res);
+	release_sdram_region(data->tee_res);
 	if (image_is_uimage(data))
 		bootm_close_uimage(data);
 	if (data->os_fit)
diff --git a/common/resource.c b/common/resource.c
index 078dc9f2ff2d..33eb122f4668 100644
--- a/common/resource.c
+++ b/common/resource.c
@@ -97,6 +97,8 @@ struct resource *__request_region(struct resource *parent,
  */
 int release_region(struct resource *res)
 {
+	if (!res)
+		return 0;
 	if (!list_empty(&res->children))
 		return -EBUSY;
 
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index 621987f1bade..6cf99fc4b284 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -397,10 +397,9 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
 	if (!prz)
 		return;
 
-	if (prz->res) {
-		release_sdram_region(prz->res);
-		prz->res = NULL;
-	}
+	release_sdram_region(prz->res);
+	prz->res = NULL;
+
 	if (prz->rs_decoder) {
 		free_rs(prz->rs_decoder);
 		prz->rs_decoder = NULL;
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 08/10] common: elf: use release_region unconditionally
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
                   ` (6 preceding siblings ...)
  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 ` Ahmad Fatoum
  2026-01-05  8:03 ` [PATCH 09/10] memory: always print errors on request_sdram_region failure Ahmad Fatoum
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Given that release_region and release_sdram_region are the same, just
use release_region regardless of whether SDRAM or I/O memory region was
requested.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/elf.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/common/elf.c b/common/elf.c
index c68ea0be3fa6..4f4151f722d7 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -18,7 +18,6 @@ struct elf_segment {
 	struct list_head list;
 	struct resource *r;
 	void *phdr;
-	bool is_iomem_region;
 };
 
 static int elf_request_region(struct elf_image *elf, resource_size_t start,
@@ -40,7 +39,6 @@ static int elf_request_region(struct elf_image *elf, resource_size_t start,
 			pr_err("Failed to request region: %pa %pa\n", &start, &size);
 			return -EINVAL;
 		}
-		r->is_iomem_region = true;
 	}
 
 	r->r = r_new;
@@ -56,10 +54,7 @@ static void elf_release_regions(struct elf_image *elf)
 	struct elf_segment *r, *r_tmp;
 
 	list_for_each_entry_safe(r, r_tmp, list, list) {
-		if (r->is_iomem_region)
-			release_region(r->r);
-		else
-			release_sdram_region(r->r);
+		release_region(r->r);
 		list_del(&r->list);
 		free(r);
 	}
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 09/10] memory: always print errors on request_sdram_region failure
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
                   ` (7 preceding siblings ...)
  2026-01-05  8:03 ` [PATCH 08/10] common: elf: use release_region unconditionally Ahmad Fatoum
@ 2026-01-05  8:03 ` 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
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

A failed request_sdram_region is nearly always a problem and warrants a
print out.

Introduce request_sdram_region_silent() for the few cases, where an
error is tolerated and print an error message in the general case.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/arm/cpu/armv7r-mpu.c |  6 +++---
 arch/arm/cpu/bootm-fip.c  |  6 +++---
 arch/arm/cpu/mmu_32.c     |  4 ++--
 common/elf.c              |  4 ++--
 common/memory.c           | 20 +++++++++++++-------
 include/memory.h          | 39 +++++++++++++++++++++++++++++++--------
 6 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/arch/arm/cpu/armv7r-mpu.c b/arch/arm/cpu/armv7r-mpu.c
index 4fb867c50a42..d96411a61632 100644
--- a/arch/arm/cpu/armv7r-mpu.c
+++ b/arch/arm/cpu/armv7r-mpu.c
@@ -206,9 +206,9 @@ int armv7r_mpu_init_coherent(unsigned long start, enum size reg_size)
 static int armv7r_request_pool(void)
 {
 	if (dma_coherent_start && dma_coherent_size)
-		request_sdram_region("DMA coherent pool",
-				     dma_coherent_start, dma_coherent_size,
-				     MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_RW);
+		request_sdram_region_silent("DMA coherent pool",
+					    dma_coherent_start, dma_coherent_size,
+					    MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_RW);
 	return 0;
 }
 postmem_initcall(armv7r_request_pool);
diff --git a/arch/arm/cpu/bootm-fip.c b/arch/arm/cpu/bootm-fip.c
index 8d1ea3f109d1..a4da4c538abe 100644
--- a/arch/arm/cpu/bootm-fip.c
+++ b/arch/arm/cpu/bootm-fip.c
@@ -36,9 +36,9 @@ static int desc_to_sdram(struct fip_image_desc *loadable, ulong load_address)
 	if (desc_get_res(loadable))
 		return 0;
 
-	res = request_sdram_region("fip", load_address,
-				   loadable->image->toc_e.size,
-				   MEMTYPE_LOADER_CODE, MEMATTRS_RW);
+	res = request_sdram_region_silent("fip", load_address,
+					  loadable->image->toc_e.size,
+					  MEMTYPE_LOADER_CODE, MEMATTRS_RW);
 	if (!res)
 		return -EBUSY;
 
diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index 912d14e8cf82..caa41e1beb3a 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -540,8 +540,8 @@ static void create_zero_page(void)
 	 * In case the zero page is in SDRAM request it to prevent others
 	 * from using it
 	 */
-	request_sdram_region("zero page", 0x0, PAGE_SIZE,
-			     MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_FAULT);
+	request_sdram_region_silent("zero page", 0x0, PAGE_SIZE,
+				    MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_FAULT);
 
 	zero_page_faulting();
 	pr_debug("Created zero page\n");
diff --git a/common/elf.c b/common/elf.c
index 4f4151f722d7..330505e9a2bf 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -31,8 +31,8 @@ static int elf_request_region(struct elf_image *elf, resource_size_t start,
 	if (!r)
 		return -ENOMEM;
 
-	r_new = request_sdram_region("elf_segment", start, size,
-				     MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
+	r_new = request_sdram_region_silent("elf_segment", start, size,
+					    MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
 	if (!r_new) {
 		r_new = request_iomem_region("elf_segment", start, size);
 		if (!r_new) {
diff --git a/common/memory.c b/common/memory.c
index 7dc7f40db7fc..49ff0ef619d5 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -67,7 +67,7 @@ void register_barebox_area(resource_size_t start,
 static int mem_register_barebox(void)
 {
 	if (barebox_start && barebox_size)
-		barebox_res = request_sdram_region("barebox", barebox_start,
+		barebox_res = request_sdram_region_silent("barebox", barebox_start,
 						   barebox_size,
 						   MEMTYPE_BOOT_SERVICES_CODE,
 						   MEMATTRS_RWX); // FIXME
@@ -108,7 +108,7 @@ struct resource *request_barebox_region(const char *name,
 		return iores;
 	}
 
-	return request_sdram_region(name, start, size, memtype, memattrs);
+	return request_sdram_region_silent(name, start, size, memtype, memattrs);
 }
 
 static int mem_malloc_resource(void)
@@ -122,7 +122,7 @@ static int mem_malloc_resource(void)
 	 * regions are outside of sdram in which case
 	 * the following fails.
 	 */
-	request_sdram_region("malloc space",
+	request_sdram_region_silent("malloc space",
 			malloc_start,
 			malloc_end - malloc_start + 1,
 			MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_RW);
@@ -179,7 +179,7 @@ static int mem_malloc_resource(void)
 			MEMATTRS_RW);
 #endif
 #ifdef STACK_BASE
-	request_sdram_region("stack", STACK_BASE, STACK_SIZE,
+	request_sdram_region_silent("stack", STACK_BASE, STACK_SIZE,
 			     MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_RW);
 #endif
 
@@ -302,19 +302,25 @@ postmem_initcall(add_mem_devices);
  * Request a region from the registered sdram
  */
 struct resource *__request_sdram_region(const char *name,
-					resource_size_t start, resource_size_t size)
+					resource_size_t start, resource_size_t size,
+					bool verbose)
 {
 	struct memory_bank *bank;
+	resource_size_t end = start + size - 1;
 
 	for_each_memory_bank(bank) {
 		struct resource *res;
 
-		res = __request_region(bank->res, start, start + size - 1,
+		res = __request_region(bank->res, start, end,
 				       name, IORESOURCE_MEM);
 		if (!IS_ERR(res))
 			return res;
 	}
 
+	if (verbose)
+		pr_err("unable to request SDRAM region for %s at %pa-%pa\n",
+		       name, &start, &end);
+
 	return NULL;
 }
 
@@ -339,7 +345,7 @@ struct resource *reserve_sdram_region(const char *name, resource_size_t start,
 	 * want to set the reserved flag independently of whether
 	 * CONFIG_MEMORY_ATTRIBUTES is enabled or not
 	 */
-	res = __request_sdram_region(name, start, size);
+	res = __request_sdram_region(name, start, size, true);
 	if (!res)
 		return NULL;
 
diff --git a/include/memory.h b/include/memory.h
index 3475e9211b0c..6b7ada641c9d 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -39,7 +39,21 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
 	for_each_resource_region_reverse((bank)->res, region)
 
 struct resource *__request_sdram_region(const char *name,
-					resource_size_t start, resource_size_t size);
+					resource_size_t start, resource_size_t size,
+					bool verbose);
+
+static inline struct resource *sdram_region_with_attrs(struct resource *res,
+						       enum resource_memtype memtype,
+						       unsigned memattrs)
+{
+	if (IS_ENABLED(CONFIG_MEMORY_ATTRIBUTES) && res) {
+		res->type = memtype;
+		res->attrs = memattrs;
+		res->flags |= IORESOURCE_TYPE_VALID;
+	}
+
+	return res;
+}
 
 static inline struct resource *request_sdram_region(const char *name,
 						    resource_size_t start,
@@ -50,14 +64,23 @@ static inline struct resource *request_sdram_region(const char *name,
 	struct resource *res;
 
 	/* IORESOURCE_MEM is implicit for all SDRAM regions */
-	res = __request_sdram_region(name, start, size);
-	if (IS_ENABLED(CONFIG_MEMORY_ATTRIBUTES) && res) {
-		res->type = memtype;
-		res->attrs = memattrs;
-		res->flags |= IORESOURCE_TYPE_VALID;
-	}
+	res = __request_sdram_region(name, start, size, true);
 
-	return res;
+	return sdram_region_with_attrs(res, memtype, memattrs);
+}
+
+static inline struct resource *request_sdram_region_silent(const char *name,
+							   resource_size_t start,
+							   resource_size_t size,
+							   enum resource_memtype memtype,
+							   unsigned memattrs)
+{
+	struct resource *res;
+
+	/* IORESOURCE_MEM is implicit for all SDRAM regions */
+	res = __request_sdram_region(name, start, size, false);
+
+	return sdram_region_with_attrs(res, memtype, memattrs);
 }
 
 struct resource *reserve_sdram_region(const char *name, resource_size_t start,
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 10/10] memory: drop now duplicate request_sdram_region error messages
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
                   ` (8 preceding siblings ...)
  2026-01-05  8:03 ` [PATCH 09/10] memory: always print errors on request_sdram_region failure Ahmad Fatoum
@ 2026-01-05  8:03 ` Ahmad Fatoum
  2026-01-09  8:20 ` [PATCH 00/10] bootm: refactor to prepare multiple initrd support Sascha Hauer
  10 siblings, 0 replies; 12+ messages in thread
From: Ahmad Fatoum @ 2026-01-05  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Now that we have a general printout inside request_sdram_region, let's
drop the now unneeded duplicate prints.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/arm/lib32/bootm.c | 13 ++-----------
 arch/arm/lib32/bootz.c |  4 +---
 common/bootm-fit.c     | 15 +++------------
 common/bootm.c         |  7 +------
 common/uimage.c        | 12 ++----------
 lib/libfile.c          |  5 +----
 6 files changed, 10 insertions(+), 46 deletions(-)

diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c
index dca4fec0204c..c641310147ec 100644
--- a/arch/arm/lib32/bootm.c
+++ b/arch/arm/lib32/bootm.c
@@ -162,12 +162,8 @@ static int optee_verify_header_request_region(struct image_data *data, struct op
 
 	data->tee_res = request_sdram_region("TEE", hdr->init_load_addr_lo, hdr->init_size,
 					     MEMTYPE_RESERVED, MEMATTRS_RW_DEVICE);
-	if (!data->tee_res) {
-		pr_err("Cannot request SDRAM region 0x%08x-0x%08x: %pe\n",
-		       hdr->init_load_addr_lo, hdr->init_load_addr_lo + hdr->init_size - 1,
-		       ERR_PTR(-EINVAL));
+	if (!data->tee_res)
 		return -EINVAL;
-	}
 
 	return 0;
 }
@@ -509,8 +505,6 @@ static int do_bootz_linux(struct image_data *data)
 	data->os_res = request_sdram_region("zimage", load_address, image_size,
 					    MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
 	if (!data->os_res) {
-		pr_err("bootm/zImage: failed to request memory at 0x%lx to 0x%lx (%zu).\n",
-		       load_address, load_address + image_size, image_size);
 		ret = -ENOMEM;
 		goto err_out;
 	}
@@ -634,15 +628,12 @@ static int do_bootm_aimage(struct image_data *data)
 	data->os_res = request_sdram_region("akernel", cmp->load_addr, cmp->size,
 					    MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
 	if (!data->os_res) {
-		pr_err("Cannot request region 0x%08x - 0x%08x, using default load address\n",
-				cmp->load_addr, cmp->size);
+		pr_err("using default load address\n");
 
 		data->os_address = mem_start + PAGE_ALIGN(cmp->size * 4);
 		data->os_res = request_sdram_region("akernel", data->os_address, cmp->size,
 						    MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
 		if (!data->os_res) {
-			pr_err("Cannot request region 0x%08x - 0x%08x\n",
-					cmp->load_addr, cmp->size);
 			ret = -ENOMEM;
 			goto err_out;
 		}
diff --git a/arch/arm/lib32/bootz.c b/arch/arm/lib32/bootz.c
index 0ace36271026..5aa762b4912d 100644
--- a/arch/arm/lib32/bootz.c
+++ b/arch/arm/lib32/bootz.c
@@ -90,10 +90,8 @@ static int do_bootz(int argc, char *argv[])
 					bank->res->start + SZ_8M, end,
 					MEMTYPE_LOADER_CODE,
 					MEMATTRS_RWX);
-			if (!res) {
-				printf("can't request region for kernel\n");
+			if (!res)
 				goto err_out1;
-			}
 		}
 
 		memcpy(zimage, header, sizeof(*header));
diff --git a/common/bootm-fit.c b/common/bootm-fit.c
index f9c8bff43912..3b2252ca8810 100644
--- a/common/bootm-fit.c
+++ b/common/bootm-fit.c
@@ -26,13 +26,9 @@ int bootm_load_fit_os(struct image_data *data, unsigned long load_address)
 	data->os_res = request_sdram_region("kernel",
 			load_address, kernel_size,
 			MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
-	if (!data->os_res) {
-		pr_err("unable to request SDRAM region for kernel at"
-				" 0x%08llx-0x%08llx\n",
-			(unsigned long long)load_address,
-			(unsigned long long)load_address + kernel_size - 1);
+	if (!data->os_res)
 		return -ENOMEM;
-	}
+
 	zero_page_memcpy((void *)load_address, kernel, kernel_size);
 	return 0;
 }
@@ -75,13 +71,8 @@ struct resource *bootm_load_fit_initrd(struct image_data *data, unsigned long lo
 	res = request_sdram_region("initrd",
 				   load_address, initrd_size,
 				   MEMTYPE_LOADER_DATA, MEMATTRS_RW);
-	if (!res) {
-		pr_err("unable to request SDRAM region for initrd at"
-				" 0x%08llx-0x%08llx\n",
-			(unsigned long long)load_address,
-			(unsigned long long)load_address + initrd_size - 1);
+	if (!res)
 		return ERR_PTR(-ENOMEM);
-	}
 
 	memcpy((void *)load_address, initrd, initrd_size);
 	return res;
diff --git a/common/bootm.c b/common/bootm.c
index 933e9dfc69fe..3998443e1aff 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -450,13 +450,8 @@ int bootm_load_devicetree(struct image_data *data, void *fdt,
 
 	data->oftree_res = request_sdram_region("oftree", load_address,
 			fdt_size, MEMTYPE_LOADER_DATA, MEMATTRS_RW);
-	if (!data->oftree_res) {
-		pr_err("unable to request SDRAM region for device tree at"
-				" 0x%08llx-0x%08llx\n",
-			(unsigned long long)load_address,
-			(unsigned long long)load_address + fdt_size - 1);
+	if (!data->oftree_res)
 		return -ENOMEM;
-	}
 
 	memcpy((void *)data->oftree_res->start, fdt, fdt_size);
 
diff --git a/common/uimage.c b/common/uimage.c
index 3e456e9c58ab..5f7087475709 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -349,12 +349,8 @@ static long uimage_sdram_flush(void *buf, unsigned long len)
 		uimage_resource = request_sdram_region("uimage",
 				start, size, MEMTYPE_LOADER_CODE,
 				MEMATTRS_RWX);
-		if (!uimage_resource) {
-			resource_size_t prsize = start + size - 1;
-			printf("unable to request SDRAM %pa - %pa\n",
-				&start, &prsize);
+		if (!uimage_resource)
 			return -ENOMEM;
-		}
 	}
 
 	if (zero_page_contains((unsigned long)uimage_buf + uimage_size))
@@ -388,12 +384,8 @@ struct resource *uimage_load_to_sdram(struct uimage_handle *handle,
 	uimage_resource = request_sdram_region("uimage",
 				start, size, MEMTYPE_LOADER_CODE,
 				MEMATTRS_RWX);
-	if (!uimage_resource) {
-		printf("unable to request SDRAM 0x%08llx-0x%08llx\n",
-			(unsigned long long)start,
-			(unsigned long long)start + size - 1);
+	if (!uimage_resource)
 		return NULL;
-	}
 
 	ret = uimage_load(handle, image_no, uimage_sdram_flush);
 	if (ret) {
diff --git a/lib/libfile.c b/lib/libfile.c
index 01189773b7e3..6b4adc90a0b5 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -789,11 +789,8 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr,
 
 		res = request_sdram_region("image", adr, size,
 					   memtype, memattrs);
-		if (!res) {
-			printf("unable to request SDRAM 0x%08lx-0x%08lx\n",
-				adr, adr + size - 1);
+		if (!res)
 			goto out;
-		}
 
 		if (zero_page_contains(res->start + ofs)) {
 			void *tmp = malloc(BUFSIZ);
-- 
2.47.3




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 00/10] bootm: refactor to prepare multiple initrd support
  2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
                   ` (9 preceding siblings ...)
  2026-01-05  8:03 ` [PATCH 10/10] memory: drop now duplicate request_sdram_region error messages Ahmad Fatoum
@ 2026-01-09  8:20 ` Sascha Hauer
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2026-01-09  8:20 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 05 Jan 2026 09:03:32 +0100, Ahmad Fatoum wrote:
> Linux can transparently handle concatenated individually compressed CPIOs
> just fine, but so far, the concantenation needed to happen before bootm
> is called.
> 
> This series prepares for supporting initrd concatenation by refactoring
> the bootm code to make it easier to extend in a follow-up series.
> 
> [...]

Applied, thanks!

[01/10] bootm: set image_data::initrd_res at a single place
        https://git.pengutronix.de/cgit/barebox/commit/?id=dca8fcca2830 (link may not be stable)
[02/10] bootm: fit: split support into dedicated file
        https://git.pengutronix.de/cgit/barebox/commit/?id=2b3cf02c037b (link may not be stable)
[03/10] bootm: uimage: split support into dedicated file
        https://git.pengutronix.de/cgit/barebox/commit/?id=e3085717c879 (link may not be stable)
[04/10] filetype: introduce filetype_fit
        https://git.pengutronix.de/cgit/barebox/commit/?id=bc0d99bc40bc (link may not be stable)
[05/10] bootm: refactor for readability and extensibility
        https://git.pengutronix.de/cgit/barebox/commit/?id=b62b21eddf30 (link may not be stable)
[06/10] memory: move release_sdram_region into header
        https://git.pengutronix.de/cgit/barebox/commit/?id=3900e7f40b9f (link may not be stable)
[07/10] resource: make NULL in release_[sdram_]region a no-op
        https://git.pengutronix.de/cgit/barebox/commit/?id=1918ba4da8b8 (link may not be stable)
[08/10] common: elf: use release_region unconditionally
        https://git.pengutronix.de/cgit/barebox/commit/?id=62761aaa41c2 (link may not be stable)
[09/10] memory: always print errors on request_sdram_region failure
        https://git.pengutronix.de/cgit/barebox/commit/?id=e453a1b33322 (link may not be stable)
[10/10] memory: drop now duplicate request_sdram_region error messages
        https://git.pengutronix.de/cgit/barebox/commit/?id=6a47e5b084d0 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-01-09  8:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 04/10] filetype: introduce filetype_fit Ahmad Fatoum
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox