[U-Boot] [RFC PATCH 2/2] sandbox: Read contents of SPI flash from file
Simon Glass
sjg at chromium.org
Tue Oct 25 15:30:39 CEST 2011
TODO: Rename to sandbox_flash
TODO: Discuss the CONFIG_NO_SPI option
Signed-off-by: Simon Glass <sjg at chromium.org>
---
drivers/mtd/spi/test_flash.c | 19 +++++++++++++++++++
include/spi_flash.h | 2 ++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/spi/test_flash.c b/drivers/mtd/spi/test_flash.c
index e0027ee..38d2731 100644
--- a/drivers/mtd/spi/test_flash.c
+++ b/drivers/mtd/spi/test_flash.c
@@ -22,6 +22,7 @@
#include <common.h>
#include <malloc.h>
#include <spi_flash.h>
+#include <os.h>
struct test_flash_info {
unsigned page_size; /* Page size of the test flash */
@@ -86,3 +87,21 @@ struct test_flash_info *spi_flash_test_setup(unsigned page_size, ulong size)
info->buf = malloc(size);
return info;
}
+
+int spi_flash_test_loadfile(struct test_flash_info *info, const char *filename)
+{
+ int fd, len;
+
+ fd = os_open(filename, 0);
+ if (fd < 0) {
+ printf("Cannot open file '%s'\n", filename);
+ return -1;
+ }
+ len = os_read(fd, info->buf, info->size);
+ if (len != info->size) {
+ printf("Read %d bytes, expected %ld\n", len, info->size);
+ return -1;
+ }
+ os_close(fd);
+ return 0;
+}
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 5611222..357de30 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -74,4 +74,6 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
struct test_flash_info;
struct spi_flash *spi_flash_probe_test(struct test_flash_info *info);
struct test_flash_info *spi_flash_test_setup(unsigned page_size, ulong size);
+int spi_flash_test_loadfile(struct test_flash_info *info,
+ const char *filename);
#endif /* _SPI_FLASH_H_ */
--
1.7.3.1
More information about the U-Boot
mailing list