[PATCH 07/13] uimage: improve transfer speed

Vicente vicencb at gmail.com
Sun Oct 7 18:01:21 EDT 2012


Signed-off-by: Vicente <vicencb at gmail.com>
---
 common/uimage.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/common/uimage.c b/common/uimage.c
index c72db41..18c5b01 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -28,6 +28,8 @@
 #include <rtc.h>
 #include <filetype.h>
 #include <memory.h>
+#include <linux/stat.h>
+#include <sizes.h>
 
 #ifdef CONFIG_UIMAGE_MULTI
 static inline int uimage_is_multi_image(struct uimage_handle *handle)
@@ -380,15 +382,35 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr)
 	struct resource *res;
 	size_t size = BUFSIZ;
 	size_t ofs = 0;
+	size_t now;
 	int fd;
+	struct stat s;
 
 	fd = open(filename, O_RDONLY);
 	if (fd < 0)
 		return NULL;
 
-	while (1) {
-		size_t now;
+	/* TODO: use fstat(fd, &s) when implemented and avoid reopening file */
+	if (stat(filename, &s) == 0 && s.st_size <= SZ_1G) {
+		/*
+		 * As the file size is known we can read it at once and improve
+		 * transfer speed.
+		 */
+		res = request_sdram_region("image", adr, s.st_size);
+		if (!res) {
+			printf("unable to request SDRAM 0x%08lx-0x%08lx\n",
+				adr, adr + s.st_size - 1);
+			goto out;
+		}
 
+		now = read_full(fd, (void *)(res->start), s.st_size);
+		if (now < s.st_size) {
+			release_sdram_region(res);
+			res = NULL;
+		}
+		goto out;
+	}
+	while (1) {
 		res = request_sdram_region("image", adr, size);
 		if (!res) {
 			printf("unable to request SDRAM 0x%08lx-0x%08lx\n",
-- 
1.7.12.2




More information about the barebox mailing list