summaryrefslogtreecommitdiffstats
path: root/common/uimage.c
diff options
context:
space:
mode:
authorVicente <vicencb@gmail.com>2012-10-09 00:55:18 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-11-16 15:32:27 +0100
commit7b8a200154be38bd54ce4fc291a5a7904e5d33f2 (patch)
treeff4b34064e7f27eb94f10f0b06112a2d70a3621c /common/uimage.c
parentbeff13a41c1811bed8b1319c5551b0aa15653b1f (diff)
downloadbarebox-7b8a200154be38bd54ce4fc291a5a7904e5d33f2.tar.gz
uimage: improve transfer speed
Signed-off-by: Vicente <vicencb@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/uimage.c')
-rw-r--r--common/uimage.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/common/uimage.c b/common/uimage.c
index 344bd61..3f5a3d5 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,36 @@ 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.
+ */
+ size = s.st_size;
+ res = request_sdram_region("image", adr, size);
+ if (!res) {
+ printf("unable to request SDRAM 0x%08lx-0x%08lx\n",
+ adr, adr + size - 1);
+ goto out;
+ }
+ now = read_full(fd, (void *)(res->start), size);
+ if (now < 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",