[PATCH 16/16] libfile: remove file_to_sdram

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Mar 12 07:44:59 PDT 2026


All users of file_to_sdram have now been switched to use
loadable_extract_into_sdram_all() or other loadable API, so it's now ok
to remove this function.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/libfile.h |  3 ---
 lib/libfile.c     | 66 -----------------------------------------------
 2 files changed, 69 deletions(-)

diff --git a/include/libfile.h b/include/libfile.h
index c1e51a77b169..3f5ea5255af7 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -55,9 +55,6 @@ 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,
-			       enum resource_memtype memtype);
-
 int fixup_path_case(int dirfd, const char **path);
 
 int open_fdt(const char *filename, size_t *size);
diff --git a/lib/libfile.c b/lib/libfile.c
index 0670ef0584cb..cf78c70354d9 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -830,72 +830,6 @@ int __read_full_anywhere(int fd, void *buf, size_t size)
 	return now < 0 ? now : now + nbytes;
 }
 
-#define BUFSIZ	(PAGE_SIZE * 32)
-
-struct resource *file_to_sdram(const char *filename, unsigned long adr,
-			       enum resource_memtype memtype)
-{
-	struct resource *res;
-	unsigned memattrs;
-	size_t size = BUFSIZ;
-	size_t ofs = 0;
-	ssize_t now;
-	int fd;
-
-	fd = open(filename, O_RDONLY);
-	if (fd < 0)
-		return NULL;
-
-	/* FIXME: EFI payloads are started with MMU enabled, so for now
-	 * we keep attributes as RWX instead of remapping later on
-	 */
-	memattrs = IS_ENABLED(CONFIG_EFI_LOADER) ? MEMATTRS_RWX : MEMATTRS_RW;
-
-	while (1) {
-
-		res = request_sdram_region("image", adr, size,
-					   memtype, memattrs);
-		if (!res)
-			goto out;
-
-		if (zero_page_contains(res->start + ofs)) {
-			void *tmp = malloc(BUFSIZ);
-			if (!tmp)
-				now = -ENOMEM;
-			else
-				now = read_full(fd, tmp, BUFSIZ);
-
-			if (now > 0)
-				zero_page_memcpy((void *)(res->start + ofs), tmp, now);
-			free(tmp);
-		} else {
-			now = read_full(fd, (void *)(res->start + ofs), BUFSIZ);
-		}
-
-		if (now < 0) {
-			release_sdram_region(res);
-			res = NULL;
-			goto out;
-		}
-
-		if (now < BUFSIZ) {
-			release_sdram_region(res);
-			res = request_sdram_region("image", adr, ofs + now,
-						   memtype, memattrs);
-			goto out;
-		}
-
-		release_sdram_region(res);
-
-		ofs += BUFSIZ;
-		size += BUFSIZ;
-	}
-out:
-	close(fd);
-
-	return res;
-}
-
 int fixup_path_case(int fd, const char **path)
 {
 	DIR *dir;
-- 
2.47.3




More information about the barebox mailing list