[PATCH 1/3] bootstrap_read_devfs(): optionally inform the caller of the buffer size

Sascha Hauer s.hauer at pengutronix.de
Thu Nov 5 06:56:12 EST 2020


From: Ulrich Ölmann <u.oelmann at pengutronix.de>

The size of the buffer allocated in the function is needed if it shall be
inspected more closely later. Therefore optionally return it via a new pointer
argument.

Signed-off-by: Ulrich Ölmann <u.oelmann at pengutronix.de>
---
 arch/arm/boards/tny-a926x/tny_a9263_bootstrap.c |  2 +-
 arch/arm/boards/usb-a926x/usb_a9263_bootstrap.c |  2 +-
 arch/arm/mach-at91/bootstrap.c                  |  2 +-
 arch/arm/mach-socfpga/xload.c                   |  2 +-
 include/bootstrap.h                             |  8 ++++----
 lib/bootstrap/devfs.c                           | 11 +++++++----
 6 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/arch/arm/boards/tny-a926x/tny_a9263_bootstrap.c b/arch/arm/boards/tny-a926x/tny_a9263_bootstrap.c
index 368c67744f..f26f1eaecb 100644
--- a/arch/arm/boards/tny-a926x/tny_a9263_bootstrap.c
+++ b/arch/arm/boards/tny-a926x/tny_a9263_bootstrap.c
@@ -11,6 +11,6 @@
 #ifdef CONFIG_MTD_DATAFLASH
 void * bootstrap_board_read_dataflash(void)
 {
-	return bootstrap_read_devfs("dataflash0", false, 0xffc0, 204864, 204864);
+	return bootstrap_read_devfs("dataflash0", false, 0xffc0, 204864, 204864, NULL);
 }
 #endif
diff --git a/arch/arm/boards/usb-a926x/usb_a9263_bootstrap.c b/arch/arm/boards/usb-a926x/usb_a9263_bootstrap.c
index 368c67744f..f26f1eaecb 100644
--- a/arch/arm/boards/usb-a926x/usb_a9263_bootstrap.c
+++ b/arch/arm/boards/usb-a926x/usb_a9263_bootstrap.c
@@ -11,6 +11,6 @@
 #ifdef CONFIG_MTD_DATAFLASH
 void * bootstrap_board_read_dataflash(void)
 {
-	return bootstrap_read_devfs("dataflash0", false, 0xffc0, 204864, 204864);
+	return bootstrap_read_devfs("dataflash0", false, 0xffc0, 204864, 204864, NULL);
 }
 #endif
diff --git a/arch/arm/mach-at91/bootstrap.c b/arch/arm/mach-at91/bootstrap.c
index 5d21b2d021..90b7b33fc9 100644
--- a/arch/arm/mach-at91/bootstrap.c
+++ b/arch/arm/mach-at91/bootstrap.c
@@ -78,7 +78,7 @@ static void at91bootstrap_boot_nand(bool is_barebox)
 	kernel_entry_func func = NULL;
 
 	printf("Boot %s from nand\n", name);
-	func = bootstrap_read_devfs("nand0", true, SZ_128K, SZ_256K, SZ_1M);
+	func = bootstrap_read_devfs("nand0", true, SZ_128K, SZ_256K, SZ_1M, NULL);
 	bootstrap_boot(func, is_barebox);
 	bootstrap_err("... failed\n");
 	free(func);
diff --git a/arch/arm/mach-socfpga/xload.c b/arch/arm/mach-socfpga/xload.c
index ee7d194427..8be2827e62 100644
--- a/arch/arm/mach-socfpga/xload.c
+++ b/arch/arm/mach-socfpga/xload.c
@@ -53,7 +53,7 @@ static __noreturn int socfpga_xload(void)
 		socfpga_cyclone5_qspi_init();
 		for (part = barebox_parts; part->nor_size; part++) {
 			buf = bootstrap_read_devfs("mtd0", false,
-					part->nor_offset, part->nor_size, SZ_1M);
+					part->nor_offset, part->nor_size, SZ_1M, NULL);
 			if (!buf) {
 				pr_info("failed to load barebox from QSPI NOR flash at offset %#x\n",
 					part->nor_offset);
diff --git a/include/bootstrap.h b/include/bootstrap.h
index 05734a920c..8b3bb34a03 100644
--- a/include/bootstrap.h
+++ b/include/bootstrap.h
@@ -14,11 +14,11 @@ typedef void (*kernel_entry_func)(int zero, int arch, void *params);
 void bootstrap_boot(kernel_entry_func func, bool barebox);
 
 #ifdef CONFIG_BOOTSTRAP_DEVFS
-void* bootstrap_read_devfs(const char *devname, bool use_bb, int offset,
-			   int default_size, int max_size);
+void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
+			   int default_size, int max_size, size_t *bufsize);
 #else
-static inline void* bootstrap_read_devfs(const char *devname, bool use_bb, int offset,
-			   int default_size, int max_size)
+static inline void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
+			   int default_size, int max_size, size_t *bufsize)
 {
 	return NULL;
 }
diff --git a/lib/bootstrap/devfs.c b/lib/bootstrap/devfs.c
index 6a3dd76cdd..6d28b1cb4d 100644
--- a/lib/bootstrap/devfs.c
+++ b/lib/bootstrap/devfs.c
@@ -80,8 +80,8 @@ static unsigned int get_image_size(void *head)
 }
 #endif
 
-void* bootstrap_read_devfs(const char *devname, bool use_bb, int offset,
-			   int default_size, int max_size)
+void* bootstrap_read_devfs(char *devname, bool use_bb, int offset,
+			   int default_size, int max_size, size_t *bufsize)
 {
 	int ret;
 	int size = 0;
@@ -133,10 +133,13 @@ void* bootstrap_read_devfs(const char *devname, bool use_bb, int offset,
 	ret = cdev_read(cdev, to, size, 0, 0);
 	cdev_close(cdev);
 
-	if (ret != size)
+	if (ret != size) {
 		bootstrap_err("%s: failed to read from %s\n", devname, partname);
-	else
+	} else {
 		result = to;
+		if (bufsize)
+			*bufsize = size;
+	}
 
 free_memory:
 	free(header);
-- 
2.20.1




More information about the barebox mailing list