summaryrefslogtreecommitdiff
path: root/post/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'post/drivers')
-rw-r--r--post/drivers/Makefile2
-rw-r--r--post/drivers/flash.c107
-rw-r--r--post/drivers/memory.c15
3 files changed, 118 insertions, 6 deletions
diff --git a/post/drivers/Makefile b/post/drivers/Makefile
index 0d87ae0..85d6c03 100644
--- a/post/drivers/Makefile
+++ b/post/drivers/Makefile
@@ -24,6 +24,6 @@ include $(TOPDIR)/config.mk
LIB = libpostdrivers.o
-COBJS-$(CONFIG_HAS_POST) += i2c.o memory.o rtc.o
+COBJS-$(CONFIG_HAS_POST) += flash.o i2c.o memory.o rtc.o
include $(TOPDIR)/post/rules.mk
diff --git a/post/drivers/flash.c b/post/drivers/flash.c
new file mode 100644
index 0000000..07eab33
--- /dev/null
+++ b/post/drivers/flash.c
@@ -0,0 +1,107 @@
+/*
+ * Parallel NOR Flash tests
+ *
+ * Copyright (c) 2005-2011 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <post.h>
+#include <flash.h>
+
+#if CONFIG_POST & CONFIG_SYS_POST_FLASH
+
+/*
+ * This code will walk over the declared sectors erasing them,
+ * then programming them, then verifying the written contents.
+ * Possible future work:
+ * - verify sectors before/after are not erased/written
+ * - verify partial writes (e.g. programming only middle of sector)
+ * - verify the contents of the erased sector
+ * - better seed pattern than 0x00..0xff
+ */
+
+#ifndef CONFIG_SYS_POST_FLASH_NUM
+# define CONFIG_SYS_POST_FLASH_NUM 0
+#endif
+#if CONFIG_SYS_POST_FLASH_START >= CONFIG_SYS_POST_FLASH_END
+# error "invalid flash block start/end"
+#endif
+
+extern flash_info_t flash_info[];
+
+static void *seed_src_data(void *ptr, ulong *old_len, ulong new_len)
+{
+ unsigned char *p;
+ ulong i;
+
+ p = ptr = realloc(ptr, new_len);
+ if (!ptr)
+ return ptr;
+
+ for (i = *old_len; i < new_len; ++i)
+ p[i] = i;
+
+ *old_len = new_len;
+
+ return ptr;
+}
+
+int flash_post_test(int flags)
+{
+ ulong len;
+ void *src;
+ int ret, n, n_start, n_end;
+ flash_info_t *info;
+
+ /* the output from the common flash layers needs help */
+ puts("\n");
+
+ len = 0;
+ src = NULL;
+ info = &flash_info[CONFIG_SYS_POST_FLASH_NUM];
+ n_start = CONFIG_SYS_POST_FLASH_START;
+ n_end = CONFIG_SYS_POST_FLASH_END;
+
+ for (n = n_start; n < n_end; ++n) {
+ ulong s_start, s_len, s_off;
+
+ s_start = info->start[n];
+ s_len = flash_sector_size(info, n);
+ s_off = s_start - info->start[0];
+
+ src = seed_src_data(src, &len, s_len);
+ if (!src) {
+ printf("malloc(%#lx) failed\n", s_len);
+ return 1;
+ }
+
+ printf("\tsector %i: %#lx +%#lx", n, s_start, s_len);
+
+ ret = flash_erase(info, n, n + 1);
+ if (ret) {
+ flash_perror(ret);
+ break;
+ }
+
+ ret = write_buff(info, src, s_start, s_len);
+ if (ret) {
+ flash_perror(ret);
+ break;
+ }
+
+ ret = memcmp(src, (void *)s_start, s_len);
+ if (ret) {
+ printf(" verify failed with %i\n", ret);
+ break;
+ }
+ }
+
+ free(src);
+
+ return ret;
+}
+
+#endif
diff --git a/post/drivers/memory.c b/post/drivers/memory.c
index 3f47449..c2b711e 100644
--- a/post/drivers/memory.c
+++ b/post/drivers/memory.c
@@ -225,7 +225,7 @@ const unsigned long long otherpattern = 0x0123456789abcdefULL;
static int memory_post_dataline(unsigned long long * pmem)
{
unsigned long long temp64 = 0;
- int num_patterns = sizeof(pattern)/ sizeof(pattern[0]);
+ int num_patterns = ARRAY_SIZE(pattern);
int i;
unsigned int hi, lo, pathi, patlo;
int ret = 0;
@@ -452,13 +452,17 @@ static int memory_post_tests (unsigned long start, unsigned long size)
return ret;
}
+/*
+ * !! this is only valid, if you have contiguous memory banks !!
+ */
__attribute__((weak))
int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
{
bd_t *bd = gd->bd;
+
*vstart = CONFIG_SYS_SDRAM_BASE;
- *size = (bd->bi_memsize >= 256 << 20 ?
- 256 << 20 : bd->bi_memsize) - (1 << 20);
+ *size = (gd->ram_size >= 256 << 20 ?
+ 256 << 20 : gd->ram_size) - (1 << 20);
/* Limit area to be tested with the board info struct */
if ((*vstart) + (*size) > (ulong)bd)
@@ -500,9 +504,10 @@ int memory_post_test(int flags)
unsigned long i;
for (i = 0; i < (memsize >> 20) && ret == 0; i++) {
if (ret == 0)
- ret = memory_post_tests(i << 20, 0x800);
+ ret = memory_post_tests(vstart +
+ (i << 20), 0x800);
if (ret == 0)
- ret = memory_post_tests(
+ ret = memory_post_tests(vstart +
(i << 20) + 0xff800, 0x800);
}
}