All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/5] post: new nor flash test
Date: Tue, 28 Jun 2011 15:26:42 -0400	[thread overview]
Message-ID: <1309289203-5758-4-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <1309289203-5758-1-git-send-email-vapier@gentoo.org>

This adds a simple flash test to automatically verify erasing,
writing, and reading of sectors.  The code is based on existing
Blackfin tests but generalized for everyone to use.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 include/post.h        |    1 +
 post/drivers/Makefile |    2 +-
 post/drivers/flash.c  |  107 +++++++++++++++++++++++++++++++++++++++++++++++++
 post/tests.c          |   15 ++++++-
 4 files changed, 123 insertions(+), 2 deletions(-)
 create mode 100644 post/drivers/flash.c

diff --git a/include/post.h b/include/post.h
index c9ec2f4..19991de 100644
--- a/include/post.h
+++ b/include/post.h
@@ -186,6 +186,7 @@ extern int post_hotkeys_pressed(void);
 #define CONFIG_SYS_POST_BSPEC5		0x00100000
 #define CONFIG_SYS_POST_CODEC		0x00200000
 #define CONFIG_SYS_POST_COPROC		0x00400000
+#define CONFIG_SYS_POST_FLASH		0x00800000
 
 #endif /* CONFIG_POST */
 
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/tests.c b/post/tests.c
index 71437b6..bfb9cb5 100644
--- a/post/tests.c
+++ b/post/tests.c
@@ -46,6 +46,7 @@ extern int sysmon_post_test (int flags);
 extern int dsp_post_test (int flags);
 extern int codec_post_test (int flags);
 extern int ecc_post_test (int flags);
+extern int flash_post_test(int flags);
 
 extern int dspic_init_post_test (int flags);
 extern int dspic_post_test (int flags);
@@ -301,7 +302,19 @@ struct post_test post_list[] =
 	NULL,
 	NULL,
 	CONFIG_SYS_POST_COPROC
-    }
+    },
+#endif
+#if CONFIG_POST & CONFIG_SYS_POST_FLASH
+    {
+	"Parallel NOR flash test",
+	"flash",
+	"This test verifies parallel flash operations.",
+	POST_RAM | POST_SLOWTEST | POST_MANUAL,
+	&flash_post_test,
+	NULL,
+	NULL,
+	CONFIG_SYS_POST_FLASH
+    },
 #endif
 };
 
-- 
1.7.5.3

  parent reply	other threads:[~2011-06-28 19:26 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-28 19:26 [U-Boot] Pull request u-boot-blackfin.git (post branch) Mike Frysinger
2011-06-28 19:26 ` [U-Boot] [PATCH 1/5] post: fix up I/O helper usage Mike Frysinger
2011-06-28 19:26   ` [U-Boot] [PATCH 2/5] post: add gpio hotkey support Mike Frysinger
2011-06-28 19:26   ` [U-Boot] [PATCH 3/5] post: use ARRAY_SIZE Mike Frysinger
2011-06-28 19:26   ` Mike Frysinger [this message]
2011-06-28 19:26   ` [U-Boot] [PATCH 5/5] serial: implement common uart post test Mike Frysinger
2011-06-29 21:21 ` [U-Boot] Pull request u-boot-blackfin.git (post branch) Wolfgang Denk
2011-06-29 23:30   ` Mike Frysinger
2011-06-30 10:29     ` Wolfgang Denk
2011-06-30 15:26       ` Mike Frysinger
2011-06-30 15:38         ` Wolfgang Denk
2011-06-30 15:42           ` Mike Frysinger
2011-06-30 15:49             ` Wolfgang Denk
2011-06-30 16:04               ` Mike Frysinger
2011-06-30 21:10                 ` Wolfgang Denk
2011-06-30 21:12                   ` Mike Frysinger
2011-06-30 22:57                     ` Wolfgang Denk
2011-06-30 23:06                       ` Mike Frysinger
2011-07-01  4:36                         ` Wolfgang Denk
2011-07-01 23:27                           ` Mike Frysinger
2011-07-03 22:30                             ` Wolfgang Denk
2011-07-05  1:25                               ` Mike Frysinger
2011-07-05  4:42                                 ` Wolfgang Denk
2011-07-05  6:14                                   ` Mike Frysinger
2011-07-05  9:59                                     ` Wolfgang Denk
2011-07-05 17:32                                       ` Mike Frysinger
2011-07-05 21:54                                         ` Wolfgang Denk
2011-07-05 22:12                                           ` Mike Frysinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1309289203-5758-4-git-send-email-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.