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@barebox.org>
Subject: [PATCH] libfile: use different memory types for os and initrd
Date: Thu, 11 Dec 2025 21:43:23 +0100	[thread overview]
Message-ID: <20251211204324.2618644-1-a.fatoum@pengutronix.de> (raw)

From: Ahmad Fatoum <a.fatoum@barebox.org>

An initrd is not directly executable, so lets set the memory attributes
to reflect that.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/bootm.c    | 4 ++--
 include/libfile.h | 6 +++---
 lib/libfile.c     | 7 ++++---
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 1fafb2a5cd06..22796b3522ac 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -276,7 +276,7 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
 	if (!data->os_file)
 		return -EINVAL;
 
-	data->os_res = file_to_sdram(data->os_file, load_address);
+	data->os_res = file_to_sdram(data->os_file, load_address, MEMTYPE_LOADER_CODE);
 	if (!data->os_res)
 		return -ENOMEM;
 
@@ -401,7 +401,7 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)
 		goto done;
 	}
 
-	data->initrd_res = file_to_sdram(data->initrd_file, load_address);
+	data->initrd_res = file_to_sdram(data->initrd_file, load_address, MEMTYPE_LOADER_DATA);
 	if (!data->initrd_res)
 		return ERR_PTR(-ENOMEM);
 
diff --git a/include/libfile.h b/include/libfile.h
index 26571945f678..cdcad4b173d0 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -4,10 +4,9 @@
 
 #include <linux/types.h>
 #include <linux/compiler.h>
+#include <linux/ioport.h>
 #include <linux/bits.h>
 
-struct resource;
-
 int pread_full(int fd, void *buf, size_t size, loff_t offset);
 int pwrite_full(int fd, const void *buf, size_t size, loff_t offset);
 int write_full(int fd, const void *buf, size_t size);
@@ -55,6 +54,7 @@ char *make_temp(const char *template);
 
 int cache_file(const char *path, char **newpath);
 
-struct resource *file_to_sdram(const char *filename, unsigned long adr);
+struct resource *file_to_sdram(const char *filename, unsigned long adr,
+			       enum resource_memtype memtype);
 
 #endif /* __LIBFILE_H */
diff --git a/lib/libfile.c b/lib/libfile.c
index 7ca13a34b41d..a6690b0b904a 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -765,7 +765,8 @@ int cache_file(const char *path, char **newpath)
 
 #define BUFSIZ	(PAGE_SIZE * 32)
 
-struct resource *file_to_sdram(const char *filename, unsigned long adr)
+struct resource *file_to_sdram(const char *filename, unsigned long adr,
+			       enum resource_memtype memtype)
 {
 	struct resource *res;
 	unsigned memattrs;
@@ -786,7 +787,7 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr)
 	while (1) {
 
 		res = request_sdram_region("image", adr, size,
-					   MEMTYPE_LOADER_CODE, memattrs);
+					   memtype, memattrs);
 		if (!res) {
 			printf("unable to request SDRAM 0x%08lx-0x%08lx\n",
 				adr, adr + size - 1);
@@ -816,7 +817,7 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr)
 		if (now < BUFSIZ) {
 			release_sdram_region(res);
 			res = request_sdram_region("image", adr, ofs + now,
-						   MEMTYPE_LOADER_CODE, memattrs);
+						   memtype, memattrs);
 			goto out;
 		}
 
-- 
2.47.3




             reply	other threads:[~2025-12-11 20:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 20:43 Ahmad Fatoum [this message]
2025-12-15  7:13 ` 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=20251211204324.2618644-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=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