[U-Boot] [PATCH 8/8] powerpc/85xx: Add memory test feature for mpc85xx.

York Sun yorksun at freescale.com
Wed Jul 28 23:06:19 CEST 2010


Wolfgang,

On Thu, 2010-07-15 at 11:07 +0200, Wolfgang Denk wrote: 
> Dear Timur Tabi,
> 
> In message <AANLkTim6yjF6ORogtqE0vqiVqZqxu-EkkUhDTmJMgPqu at mail.gmail.com> you wrote:
> > 
> > > NAK.
> > >
> > > Please do not reinvent the wheel and add yet another meory test. Use
> > > one of the existing memory tests we already have -
> > > post/drivers/memory.c comes to mind.
> > 
> > That code is not capable of testing more than 2GB of RAM.  It assumes
> > that memory has already been initialized, but on PowerPC parts, we
> > only ever map 2GB of DDR.  We need a memory test that covers all of
> > DDR, but that requries PowerPC-specific code to create sliding TLB
> > windows during the memory test.
> 
> Then please extend the existing code and add the missing features.
> 
> We already have too many different implementations of a memory test in
> U-Boot, and I will not accept adding yet another one.
> 
I can reuse your testing code but have to move the desired code out of
memory.c file to avoid the need for CONFIG_POST and
CONFIG_SYS_POST_MEMORY. I also add a progress indicator. My testing
target is 2GB at a time, up to physically memory size which is easily
over 8GB. Without progress indicator, it feels hung when it is actually
running.

Please take a look at the patch below.

Regards,

York


>From 58002b8f549ca114583b72f541032fb106b6bf66 Mon Sep 17 00:00:00 2001
From: York Sun <yorksun at freescale.com>
Date: Wed, 23 Jun 2010 11:18:48 -0500
Subject: [PATCH] Add memory test feature for mpc85xx.

Reuse memory test code for POST. Move the actually pattern generator
and testing out of POST.

If enabled in config file and hwconfig, the memory test is performed
after DDR initialization when U-boot stills runs in flash and cache.
Whole memory is testable. However, only the low 2GB space is mapped
for DDR. The testing is conducted in the 2GB window and uses TLBs to
map the higher physical address into the 2GB window if the total
memory is more than 2GB. After the testing, DDR is remapped with up
to 2GB memory from the lowest address.

If memory test fails, DDR DIMM SPD and DDR controller registers are
dumped. All zero values are omitted for better viewing.

A worker function __setup_ddr_tlbs() is introduced to implemente more
control on physical address mapping.

Signed-off-by: York Sun <yorksun at freescale.com>
---

This patch is for discussion where to put the memory test code.


 arch/powerpc/cpu/mpc85xx/Makefile            |    2 +
 arch/powerpc/cpu/mpc85xx/memtest.c           |  220 +++++++++++++
 arch/powerpc/cpu/mpc85xx/tlb.c               |   16 +-
 doc/README.fsl-ddr                           |   13 +-
 post/drivers/Makefile                        |    2 +-
 post/drivers/memory.c                        |  426 +-------------------------
 post/drivers/{memory.c => memtest_pattern.c} |  147 ++++++---
 7 files changed, 346 insertions(+), 480 deletions(-)
 create mode 100644 arch/powerpc/cpu/mpc85xx/memtest.c
 copy post/drivers/{memory.c => memtest_pattern.c} (79%)

diff --git a/arch/powerpc/cpu/mpc85xx/Makefile b/arch/powerpc/cpu/mpc85xx/Makefile
index 2c12ef2..383de6a 100644
--- a/arch/powerpc/cpu/mpc85xx/Makefile
+++ b/arch/powerpc/cpu/mpc85xx/Makefile
@@ -62,6 +62,8 @@ COBJS-$(CONFIG_PPC_P3041)	+= ddr-gen3.o
 COBJS-$(CONFIG_PPC_P4080)	+= ddr-gen3.o
 COBJS-$(CONFIG_PPC_P5020)	+= ddr-gen3.o
 
+COBJS-${CONFIG_SYS_DRAM_TEST}	+= memtest.o $(TOPDIR)/post/drivers/memtest_pattern.o
+
 COBJS-$(CONFIG_CPM2)	+= ether_fcc.o
 COBJS-$(CONFIG_OF_LIBFDT) += fdt.o
 COBJS-$(CONFIG_FSL_CORENET) += liodn.o liodn_r1.o
diff --git a/arch/powerpc/cpu/mpc85xx/memtest.c b/arch/powerpc/cpu/mpc85xx/memtest.c
new file mode 100644
index 0000000..b873136
--- /dev/null
+++ b/arch/powerpc/cpu/mpc85xx/memtest.c
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2010 Freescale Semiconductor, Inc.
+ * York Sun <yorksun at freescale.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <hwconfig.h>
+#include <asm/processor.h>
+#include <asm/mmu.h>
+#include <asm/fsl_ddr_sdram.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Board-specific functions defined in each board's ddr.c */
+void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
+	unsigned int ctrl_num);
+void read_tlbcam_entry(int idx, u32 *valid, u32 *tsize, unsigned long *epn,
+		       phys_addr_t *rpn);
+unsigned int __setup_ddr_tlbs(phys_addr_t p_addr, unsigned int memsize_in_meg);
+
+int memory_post_tests (unsigned long start, unsigned long size);
+
+#if defined(CONFIG_SYS_DRAM_TEST)
+void dump_spd_ddr_reg(void)
+{
+	int i, j, k, m;
+	u8 *p_8;
+	u32 *p_32;
+	ccsr_ddr_t *ddr[CONFIG_NUM_DDR_CONTROLLERS];
+	generic_spd_eeprom_t
+	   spd[CONFIG_NUM_DDR_CONTROLLERS][CONFIG_DIMM_SLOTS_PER_CTLR];
+
+	for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
+		fsl_ddr_get_spd(spd[i], i);
+
+	puts("SPD data of all dimms (zero vaule is omitted)...\n");
+	puts("Byte (hex)  ");
+	k = 1;
+	for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
+		for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++)
+			printf("Dimm%d ", k++);
+	puts("\n");
+	for (k = 0; k < sizeof(generic_spd_eeprom_t); k++) {
+		m = 0;
+		printf("%3d (0x%02x)  ", k, k);
+		for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
+			for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
+				p_8 = (u8 *) &spd[i][j];
+				if (p_8[k]) {
+					printf("0x%02x  ", p_8[k]);
+					m++;
+				} else
+					puts("      ");
+			}
+		}
+		if (m)
+			puts("\n");
+		else
+			puts("\r");
+	}
+
+	for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
+		switch (i) {
+		case 0:
+			ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR;
+			break;
+#ifdef CONFIG_SYS_MPC85xx_DDR2_ADDR
+		case 1:
+			ddr[i] = (void *)CONFIG_SYS_MPC85xx_DDR2_ADDR;
+			break;
+#endif
+		default:
+			printf("%s unexpected controller number = %u\n",
+				__func__, i);
+			return;
+		}
+	}
+	printf("DDR registers dump for all controllers "
+		"(zero vaule is omitted)...\n");
+	puts("Offset (hex)   ");
+	for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
+		printf("     Base + 0x%04x", (u32)ddr[i] & 0xFFFF);
+	puts("\n");
+	for (k = 0; k < sizeof(ccsr_ddr_t)/4; k++) {
+		m = 0;
+		printf("%6d (0x%04x)", k * 4, k * 4);
+		for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
+			p_32 = (u32 *) ddr[i];
+			if (p_32[k]) {
+				printf("        0x%08x", p_32[k]);
+				m++;
+			} else
+				puts("                  ");
+		}
+		if (m)
+			puts("\n");
+		else
+			puts("\r");
+	}
+	puts("\n");
+}
+
+/*
+ * This funciton is called before U-boot relocates itself to RAM
+ * The L1 cache should be locked and L2 cache is not enabled yet
+ */
+int __testdram(phys_addr_t p_addr, u32 size)
+{
+
+	u32 vstart = CONFIG_SYS_DDR_SDRAM_BASE;
+	u32 vend = vstart + size;
+	int failed = 0;
+	unsigned long epn;
+	u32 tsize, valid, ptr;
+	phys_addr_t rpn = 0;
+	int ddr_esel;
+
+	puts("DDR memory testing...\n");
+	size = min(size, CONFIG_MAX_MEM_MAPPED);
+	ptr = vstart;
+	while (ptr < vend) {
+		ddr_esel = find_tlb_idx((void *)ptr, 1);
+		if (ddr_esel != -1) {
+			read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn);
+			disable_tlb(ddr_esel);
+		}
+		ptr += TSIZE_TO_BYTES(tsize);
+	}
+	/* Setup new tlb to cover the physical address */
+	__setup_ddr_tlbs(p_addr, size>>20);
+
+	ptr = vstart;
+	ddr_esel = find_tlb_idx((void *)ptr, 1);
+	if (ddr_esel != -1) {
+		read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn);
+	} else {
+		printf("TLB error in function %s\n", __func__);
+		return -1;
+	}
+
+	printf("Testing 0x%08llx - 0x%08llx\n",
+		(u64)vstart + rpn, (u64)vstart + rpn + size - 1);
+
+	failed = memory_post_tests(vstart, size);
+	if (failed != 0)
+		dump_spd_ddr_reg();
+
+	/* disable the TLBs for this testing */
+	ptr = vstart;
+	while (ptr < vend) {
+		ddr_esel = find_tlb_idx((void *)ptr, 1);
+		if (ddr_esel != -1) {
+			read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn);
+			disable_tlb(ddr_esel);
+		}
+		ptr += TSIZE_TO_BYTES(tsize);
+	}
+
+	return failed;
+}
+
+int testdram(void)
+{
+	int failed = 0;
+	phys_addr_t test_cap, p_addr = CONFIG_SYS_DDR_SDRAM_BASE;
+	phys_size_t p_size;
+	if (hwconfig("memtest")) {
+		if (hwconfig_arg_cmp("memtest", "null") || \
+			(!hwconfig_arg_cmp("memtest", "true"))) {
+			puts("memtest is not enabled in hwconfig, skipped.\n");
+			return 0;
+		}
+		p_size = min(gd->ram_size, CONFIG_MAX_MEM_MAPPED);
+#if !defined(CONFIG_PHYS_64BIT) || \
+    !defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS) || \
+	(CONFIG_SYS_INIT_RAM_ADDR_PHYS < 0x100000000ull)
+		if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
+			puts("Cannot test more than ");
+			print_size(CONFIG_MAX_MEM_MAPPED,
+				" without proper 36BIT support.\n");
+		}
+		test_cap = p_size;
+#else
+		test_cap = gd->ram_size;
+#endif
+		while (p_addr < test_cap - 1) {
+			if (__testdram(p_addr, (u32)p_size) != 0)
+				failed++;
+			p_addr += p_size;
+			p_size = min(test_cap - p_addr, CONFIG_MAX_MEM_MAPPED);
+		}
+		if (failed)
+			printf("\nWarning: Memory test failed."
+				" Software may not run as expected.\n");
+		puts("Remap DDR ");
+		setup_ddr_tlbs(gd->ram_size>>20);
+		puts("\n");
+	} else
+		puts("memtest is not set in hwconfig, skipped.\n");
+	return 0;
+}
+#endif
diff --git a/arch/powerpc/cpu/mpc85xx/tlb.c b/arch/powerpc/cpu/mpc85xx/tlb.c
index f2833a5..019fab7 100644
--- a/arch/powerpc/cpu/mpc85xx/tlb.c
+++ b/arch/powerpc/cpu/mpc85xx/tlb.c
@@ -245,7 +245,8 @@ void init_addr_map(void)
 }
 #endif
 
-unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg)
+unsigned int
+__setup_ddr_tlbs(phys_addr_t p_addr, unsigned int memsize_in_meg)
 {
 	int i;
 	unsigned int tlb_size;
@@ -275,21 +276,24 @@ unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg)
 
 		tlb_size = (camsize - 10) / 2;
 
-		set_tlb(1, ram_tlb_address, ram_tlb_address,
+		set_tlb(1, ram_tlb_address, p_addr,
 			MAS3_SX|MAS3_SW|MAS3_SR, 0,
 			0, ram_tlb_index, tlb_size, 1);
 
 		size -= 1ULL << camsize;
 		memsize -= 1ULL << camsize;
 		ram_tlb_address += 1UL << camsize;
+		p_addr += 1UL << camsize;
 	}
 
 	if (memsize)
 		print_size(memsize, " left unmapped\n");
-
-	/*
-	 * Confirm that the requested amount of memory was mapped.
-	 */
 	return memsize_in_meg;
 }
+
+unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg)
+{
+	return
+		__setup_ddr_tlbs(CONFIG_SYS_DDR_SDRAM_BASE, memsize_in_meg);
+}
 #endif /* !CONFIG_NAND_SPL */
diff --git a/doc/README.fsl-ddr b/doc/README.fsl-ddr
index e108a0d..4c528ac 100644
--- a/doc/README.fsl-ddr
+++ b/doc/README.fsl-ddr
@@ -78,9 +78,20 @@ If the DDR controller supports address hashing, it can be enabled by hwconfig.
 Syntax is:
 hwconfig=fsl_ddr:addr_hash=true
 
+
+Memory testing options for mpc85xx
+==================================
+1. Memory test can be done one U-boot prompt comes up using mtest, or
+2. Memory test can be done with a built-in function, activated at compile time
+   and by hwconfig.
+   In order to enable the built-in memory test, CONFIG_SYS_DRAM_TEST needs to be
+   defined in board configuraiton header file. Hwconfig is also required. To test
+   memory bigger than 2GB, 36BIT support is needed. Memory is tested within a 2GB
+
 Combination of hwconfig
 =======================
 Hwconfig can be combined with multiple parameters, for example, on a supported
 platform
 
-hwconfig=fsl_ddr:addr_hash=true,ctlr_intlv=cacheline,bank_intlv=cs0_cs1_cs2_cs3
+hwconfig=fsl_ddr:addr_hash=true,ctlr_intlv=cacheline,bank_intlv=cs0_cs1_cs2_cs3,;memtest=true
+
diff --git a/post/drivers/Makefile b/post/drivers/Makefile
index 0b6cdf5..6f67b9c 100644
--- a/post/drivers/Makefile
+++ b/post/drivers/Makefile
@@ -24,6 +24,6 @@ include $(TOPDIR)/config.mk
 
 LIB	= libpostdrivers.a
 
-COBJS-$(CONFIG_HAS_POST)	+= i2c.o memory.o rtc.o
+COBJS-$(CONFIG_HAS_POST)	+= i2c.o memtest_pattern.o memory.o rtc.o
 
 include $(TOPDIR)/post/rules.mk
diff --git a/post/drivers/memory.c b/post/drivers/memory.c
index 0062360..ee11e4b 100644
--- a/post/drivers/memory.c
+++ b/post/drivers/memory.c
@@ -22,436 +22,12 @@
  */
 
 #include <common.h>
-
-/* Memory test
- *
- * General observations:
- * o The recommended test sequence is to test the data lines: if they are
- *   broken, nothing else will work properly.  Then test the address
- *   lines.  Finally, test the cells in the memory now that the test
- *   program knows that the address and data lines work properly.
- *   This sequence also helps isolate and identify what is faulty.
- *
- * o For the address line test, it is a good idea to use the base
- *   address of the lowest memory location, which causes a '1' bit to
- *   walk through a field of zeros on the address lines and the highest
- *   memory location, which causes a '0' bit to walk through a field of
- *   '1's on the address line.
- *
- * o Floating buses can fool memory tests if the test routine writes
- *   a value and then reads it back immediately.  The problem is, the
- *   write will charge the residual capacitance on the data bus so the
- *   bus retains its state briefely.  When the test program reads the
- *   value back immediately, the capacitance of the bus can allow it
- *   to read back what was written, even though the memory circuitry
- *   is broken.  To avoid this, the test program should write a test
- *   pattern to the target location, write a different pattern elsewhere
- *   to charge the residual capacitance in a differnt manner, then read
- *   the target location back.
- *
- * o Always read the target location EXACTLY ONCE and save it in a local
- *   variable.  The problem with reading the target location more than
- *   once is that the second and subsequent reads may work properly,
- *   resulting in a failed test that tells the poor technician that
- *   "Memory error at 00000000, wrote aaaaaaaa, read aaaaaaaa" which
- *   doesn't help him one bit and causes puzzled phone calls.  Been there,
- *   done that.
- *
- * Data line test:
- * ---------------
- * This tests data lines for shorts and opens by forcing adjacent data
- * to opposite states. Because the data lines could be routed in an
- * arbitrary manner the must ensure test patterns ensure that every case
- * is tested. By using the following series of binary patterns every
- * combination of adjacent bits is test regardless of routing.
- *
- *     ...101010101010101010101010
- *     ...110011001100110011001100
- *     ...111100001111000011110000
- *     ...111111110000000011111111
- *
- * Carrying this out, gives us six hex patterns as follows:
- *
- *     0xaaaaaaaaaaaaaaaa
- *     0xcccccccccccccccc
- *     0xf0f0f0f0f0f0f0f0
- *     0xff00ff00ff00ff00
- *     0xffff0000ffff0000
- *     0xffffffff00000000
- *
- * To test for short and opens to other signals on our boards, we
- * simply test with the 1's complemnt of the paterns as well, resulting
- * in twelve patterns total.
- *
- * After writing a test pattern. a special pattern 0x0123456789ABCDEF is
- * written to a different address in case the data lines are floating.
- * Thus, if a byte lane fails, you will see part of the special
- * pattern in that byte lane when the test runs.  For example, if the
- * xx__xxxxxxxxxxxx byte line fails, you will see aa23aaaaaaaaaaaa
- * (for the 'a' test pattern).
- *
- * Address line test:
- * ------------------
- *  This function performs a test to verify that all the address lines
- *  hooked up to the RAM work properly.  If there is an address line
- *  fault, it usually shows up as two different locations in the address
- *  map (related by the faulty address line) mapping to one physical
- *  memory storage location.  The artifact that shows up is writing to
- *  the first location "changes" the second location.
- *
- * To test all address lines, we start with the given base address and
- * xor the address with a '1' bit to flip one address line.  For each
- * test, we shift the '1' bit left to test the next address line.
- *
- * In the actual code, we start with address sizeof(ulong) since our
- * test pattern we use is a ulong and thus, if we tried to test lower
- * order address bits, it wouldn't work because our pattern would
- * overwrite itself.
- *
- * Example for a 4 bit address space with the base at 0000:
- *   0000 <- base
- *   0001 <- test 1
- *   0010 <- test 2
- *   0100 <- test 3
- *   1000 <- test 4
- * Example for a 4 bit address space with the base at 0010:
- *   0010 <- base
- *   0011 <- test 1
- *   0000 <- (below the base address, skipped)
- *   0110 <- test 2
- *   1010 <- test 3
- *
- * The test locations are successively tested to make sure that they are
- * not "mirrored" onto the base address due to a faulty address line.
- * Note that the base and each test location are related by one address
- * line flipped.  Note that the base address need not be all zeros.
- *
- * Memory tests 1-4:
- * -----------------
- * These tests verify RAM using sequential writes and reads
- * to/from RAM. There are several test cases that use different patterns to
- * verify RAM. Each test case fills a region of RAM with one pattern and
- * then reads the region back and compares its contents with the pattern.
- * The following patterns are used:
- *
- *  1a) zero pattern (0x00000000)
- *  1b) negative pattern (0xffffffff)
- *  1c) checkerboard pattern (0x55555555)
- *  1d) checkerboard pattern (0xaaaaaaaa)
- *  2)  bit-flip pattern ((1 << (offset % 32))
- *  3)  address pattern (offset)
- *  4)  address pattern (~offset)
- *
- * Being run in normal mode, the test verifies only small 4Kb
- * regions of RAM around each 1Mb boundary. For example, for 64Mb
- * RAM the following areas are verified: 0x00000000-0x00000800,
- * 0x000ff800-0x00100800, 0x001ff800-0x00200800, ..., 0x03fff800-
- * 0x04000000. If the test is run in slow-test mode, it verifies
- * the whole RAM.
- */
-
 #include <post.h>
-#include <watchdog.h>
 
-#if CONFIG_POST & CONFIG_SYS_POST_MEMORY
+#if (CONFIG_POST & CONFIG_SYS_POST_MEMORY)
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/*
- * Define INJECT_*_ERRORS for testing error detection in the presence of
- * _good_ hardware.
- */
-#undef  INJECT_DATA_ERRORS
-#undef  INJECT_ADDRESS_ERRORS
-
-#ifdef INJECT_DATA_ERRORS
-#warning "Injecting data line errors for testing purposes"
-#endif
-
-#ifdef INJECT_ADDRESS_ERRORS
-#warning "Injecting address line errors for testing purposes"
-#endif
-
-
-/*
- * This function performs a double word move from the data at
- * the source pointer to the location at the destination pointer.
- * This is helpful for testing memory on processors which have a 64 bit
- * wide data bus.
- *
- * On those PowerPC with FPU, use assembly and a floating point move:
- * this does a 64 bit move.
- *
- * For other processors, let the compiler generate the best code it can.
- */
-static void move64(const unsigned long long *src, unsigned long long *dest)
-{
-#if defined(CONFIG_MPC8260) || defined(CONFIG_MPC824X)
-	asm ("lfd  0, 0(3)\n\t" /* fpr0	  =  *scr	*/
-	 "stfd 0, 0(4)"		/* *dest  =  fpr0	*/
-	 : : : "fr0" );		/* Clobbers fr0		*/
-    return;
-#else
-	*dest = *src;
-#endif
-}
-
-/*
- * This is 64 bit wide test patterns.  Note that they reside in ROM
- * (which presumably works) and the tests write them to RAM which may
- * not work.
- *
- * The "otherpattern" is written to drive the data bus to values other
- * than the test pattern.  This is for detecting floating bus lines.
- *
- */
-const static unsigned long long pattern[] = {
-	0xaaaaaaaaaaaaaaaaULL,
-	0xccccccccccccccccULL,
-	0xf0f0f0f0f0f0f0f0ULL,
-	0xff00ff00ff00ff00ULL,
-	0xffff0000ffff0000ULL,
-	0xffffffff00000000ULL,
-	0x00000000ffffffffULL,
-	0x0000ffff0000ffffULL,
-	0x00ff00ff00ff00ffULL,
-	0x0f0f0f0f0f0f0f0fULL,
-	0x3333333333333333ULL,
-	0x5555555555555555ULL
-};
-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 i;
-	unsigned int hi, lo, pathi, patlo;
-	int ret = 0;
-
-	for ( i = 0; i < num_patterns; i++) {
-		move64(&(pattern[i]), pmem++);
-		/*
-		 * Put a different pattern on the data lines: otherwise they
-		 * may float long enough to read back what we wrote.
-		 */
-		move64(&otherpattern, pmem--);
-		move64(pmem, &temp64);
-
-#ifdef INJECT_DATA_ERRORS
-		temp64 ^= 0x00008000;
-#endif
-
-		if (temp64 != pattern[i]){
-			pathi = (pattern[i]>>32) & 0xffffffff;
-			patlo = pattern[i] & 0xffffffff;
-
-			hi = (temp64>>32) & 0xffffffff;
-			lo = temp64 & 0xffffffff;
-
-			post_log ("Memory (date line) error at %08x, "
-				  "wrote %08x%08x, read %08x%08x !\n",
-					  pmem, pathi, patlo, hi, lo);
-			ret = -1;
-		}
-	}
-	return ret;
-}
-
-static int memory_post_addrline(ulong *testaddr, ulong *base, ulong size)
-{
-	ulong *target;
-	ulong *end;
-	ulong readback;
-	ulong xor;
-	int   ret = 0;
-
-	end = (ulong *)((ulong)base + size);	/* pointer arith! */
-	xor = 0;
-	for(xor = sizeof(ulong); xor > 0; xor <<= 1) {
-		target = (ulong *)((ulong)testaddr ^ xor);
-		if((target >= base) && (target < end)) {
-			*testaddr = ~*target;
-			readback  = *target;
-
-#ifdef INJECT_ADDRESS_ERRORS
-			if(xor == 0x00008000) {
-				readback = *testaddr;
-			}
-#endif
-			if(readback == *testaddr) {
-				post_log ("Memory (address line) error at %08x<->%08x, "
-					"XOR value %08x !\n",
-					testaddr, target, xor);
-				ret = -1;
-			}
-		}
-	}
-	return ret;
-}
-
-static int memory_post_test1 (unsigned long start,
-			      unsigned long size,
-			      unsigned long val)
-{
-	unsigned long i;
-	ulong *mem = (ulong *) start;
-	ulong readback;
-	int ret = 0;
-
-	for (i = 0; i < size / sizeof (ulong); i++) {
-		mem[i] = val;
-		if (i % 1024 == 0)
-			WATCHDOG_RESET ();
-	}
-
-	for (i = 0; i < size / sizeof (ulong) && ret == 0; i++) {
-		readback = mem[i];
-		if (readback != val) {
-			post_log ("Memory error at %08x, "
-				  "wrote %08x, read %08x !\n",
-					  mem + i, val, readback);
-
-			ret = -1;
-			break;
-		}
-		if (i % 1024 == 0)
-			WATCHDOG_RESET ();
-	}
-
-	return ret;
-}
-
-static int memory_post_test2 (unsigned long start, unsigned long size)
-{
-	unsigned long i;
-	ulong *mem = (ulong *) start;
-	ulong readback;
-	int ret = 0;
-
-	for (i = 0; i < size / sizeof (ulong); i++) {
-		mem[i] = 1 << (i % 32);
-		if (i % 1024 == 0)
-			WATCHDOG_RESET ();
-	}
-
-	for (i = 0; i < size / sizeof (ulong) && ret == 0; i++) {
-		readback = mem[i];
-		if (readback != (1 << (i % 32))) {
-			post_log ("Memory error at %08x, "
-				  "wrote %08x, read %08x !\n",
-					  mem + i, 1 << (i % 32), readback);
-
-			ret = -1;
-			break;
-		}
-		if (i % 1024 == 0)
-			WATCHDOG_RESET ();
-	}
-
-	return ret;
-}
-
-static int memory_post_test3 (unsigned long start, unsigned long size)
-{
-	unsigned long i;
-	ulong *mem = (ulong *) start;
-	ulong readback;
-	int ret = 0;
-
-	for (i = 0; i < size / sizeof (ulong); i++) {
-		mem[i] = i;
-		if (i % 1024 == 0)
-			WATCHDOG_RESET ();
-	}
-
-	for (i = 0; i < size / sizeof (ulong) && ret == 0; i++) {
-		readback = mem[i];
-		if (readback != i) {
-			post_log ("Memory error at %08x, "
-				  "wrote %08x, read %08x !\n",
-					  mem + i, i, readback);
-
-			ret = -1;
-			break;
-		}
-		if (i % 1024 == 0)
-			WATCHDOG_RESET ();
-	}
-
-	return ret;
-}
-
-static int memory_post_test4 (unsigned long start, unsigned long size)
-{
-	unsigned long i;
-	ulong *mem = (ulong *) start;
-	ulong readback;
-	int ret = 0;
-
-	for (i = 0; i < size / sizeof (ulong); i++) {
-		mem[i] = ~i;
-		if (i % 1024 == 0)
-			WATCHDOG_RESET ();
-	}
-
-	for (i = 0; i < size / sizeof (ulong) && ret == 0; i++) {
-		readback = mem[i];
-		if (readback != ~i) {
-			post_log ("Memory error at %08x, "
-				  "wrote %08x, read %08x !\n",
-					  mem + i, ~i, readback);
-
-			ret = -1;
-			break;
-		}
-		if (i % 1024 == 0)
-			WATCHDOG_RESET ();
-	}
-
-	return ret;
-}
-
-static int memory_post_tests (unsigned long start, unsigned long size)
-{
-	int ret = 0;
-
-	if (ret == 0)
-		ret = memory_post_dataline ((unsigned long long *)start);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_addrline ((ulong *)start, (ulong *)start, size);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_addrline ((ulong *)(start + size - 8),
-					    (ulong *)start, size);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_test1 (start, size, 0x00000000);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_test1 (start, size, 0xffffffff);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_test1 (start, size, 0x55555555);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_test1 (start, size, 0xaaaaaaaa);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_test2 (start, size);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_test3 (start, size);
-	WATCHDOG_RESET ();
-	if (ret == 0)
-		ret = memory_post_test4 (start, size);
-	WATCHDOG_RESET ();
-
-	return ret;
-}
-
 int memory_post_test (int flags)
 {
 	int ret = 0;
diff --git a/post/drivers/memory.c b/post/drivers/memtest_pattern.c
similarity index 79%
copy from post/drivers/memory.c
copy to post/drivers/memtest_pattern.c
index 0062360..713de29 100644
--- a/post/drivers/memory.c
+++ b/post/drivers/memtest_pattern.c
@@ -22,7 +22,6 @@
  */
 
 #include <common.h>
-
 /* Memory test
  *
  * General observations:
@@ -150,12 +149,31 @@
  * the whole RAM.
  */
 
-#include <post.h>
 #include <watchdog.h>
 
-#if CONFIG_POST & CONFIG_SYS_POST_MEMORY
+#if (CONFIG_POST & CONFIG_SYS_POST_MEMORY) | defined(CONFIG_SYS_DRAM_TEST)
+#ifdef CONFIG_POST
+#define test_log(fmt, args...) test_log(fmt, ##args)
+#else
+#define test_log(fmt, args...) printf(fmt, ##args)
+#endif
 
-DECLARE_GLOBAL_DATA_PTR;
+/* The follow is progress indicator, borrowed from flash programming code */
+#define TOTAL_PROGRESS_DOTS 45
+#define TOTAL_PROGRESS_NUMBERS 9
+#define PROGRESS_DOTS_PER_NUMBER (TOTAL_PROGRESS_DOTS/TOTAL_PROGRESS_NUMBERS)
+#define TEST_SHOW_PROGRESS(scale, dots, digit, dots_sub) \
+{ \
+	dots -= (dots_sub); \
+	if ((scale > 0) && (dots <= 0)) { \
+		if ((digit % PROGRESS_DOTS_PER_NUMBER) == 0) \
+			printf("%d", digit / PROGRESS_DOTS_PER_NUMBER); \
+		else \
+			putc('.'); \
+		digit--; \
+		dots += (scale); \
+	} \
+}
 
 /*
  * Define INJECT_*_ERRORS for testing error detection in the presence of
@@ -230,6 +248,7 @@ static int memory_post_dataline(unsigned long long * pmem)
 	unsigned int hi, lo, pathi, patlo;
 	int ret = 0;
 
+	test_log("Data line test ");
 	for ( i = 0; i < num_patterns; i++) {
 		move64(&(pattern[i]), pmem++);
 		/*
@@ -250,12 +269,16 @@ static int memory_post_dataline(unsigned long long * pmem)
 			hi = (temp64>>32) & 0xffffffff;
 			lo = temp64 & 0xffffffff;
 
-			post_log ("Memory (date line) error at %08x, "
+			test_log("Memory (date line) error at %p, "
 				  "wrote %08x%08x, read %08x%08x !\n",
 					  pmem, pathi, patlo, hi, lo);
 			ret = -1;
 		}
 	}
+	if (ret)
+		test_log("failed\n");
+	else
+		test_log("passed\n");
 	return ret;
 }
 
@@ -267,6 +290,7 @@ static int memory_post_addrline(ulong *testaddr, ulong *base, ulong size)
 	ulong xor;
 	int   ret = 0;
 
+	test_log("Address line test ");
 	end = (ulong *)((ulong)base + size);	/* pointer arith! */
 	xor = 0;
 	for(xor = sizeof(ulong); xor > 0; xor <<= 1) {
@@ -281,13 +305,17 @@ static int memory_post_addrline(ulong *testaddr, ulong *base, ulong size)
 			}
 #endif
 			if(readback == *testaddr) {
-				post_log ("Memory (address line) error at %08x<->%08x, "
-					"XOR value %08x !\n",
+				test_log("Memory (address line) error at %p<->%p, "
+					"XOR value %08lx !\n",
 					testaddr, target, xor);
 				ret = -1;
 			}
 		}
 	}
+	if (ret)
+		test_log("failed\n");
+	else
+		test_log("passed\n");
 	return ret;
 }
 
@@ -299,18 +327,27 @@ static int memory_post_test1 (unsigned long start,
 	ulong *mem = (ulong *) start;
 	ulong readback;
 	int ret = 0;
+	int digit = TOTAL_PROGRESS_DOTS;
+	int dots = 0;
+	int scale = (int)(((size >> 20) / sizeof(ulong) + TOTAL_PROGRESS_DOTS - 1) / TOTAL_PROGRESS_DOTS);
 
+	test_log("Pattern test %08lx\n", val);
 	for (i = 0; i < size / sizeof (ulong); i++) {
 		mem[i] = val;
 		if (i % 1024 == 0)
 			WATCHDOG_RESET ();
+		if ((i % (1 << 20)) == 0)
+			TEST_SHOW_PROGRESS(scale, dots, digit, 1);
 	}
+	test_log("Filled with pattern\n");
+	digit = TOTAL_PROGRESS_DOTS;
+	dots  = 0;
 
 	for (i = 0; i < size / sizeof (ulong) && ret == 0; i++) {
 		readback = mem[i];
 		if (readback != val) {
-			post_log ("Memory error at %08x, "
-				  "wrote %08x, read %08x !\n",
+			test_log("Memory error at %p, "
+				  "wrote %08lx, read %08lx !\n",
 					  mem + i, val, readback);
 
 			ret = -1;
@@ -318,7 +355,11 @@ static int memory_post_test1 (unsigned long start,
 		}
 		if (i % 1024 == 0)
 			WATCHDOG_RESET ();
+		if ((i % (1 << 20)) == 0)
+			TEST_SHOW_PROGRESS(scale, dots, digit, 1);
 	}
+	if (!ret)
+		test_log("Verifed\n");
 
 	return ret;
 }
@@ -329,18 +370,28 @@ static int memory_post_test2 (unsigned long start, unsigned long size)
 	ulong *mem = (ulong *) start;
 	ulong readback;
 	int ret = 0;
+	int digit = TOTAL_PROGRESS_DOTS;
+	int dots = 0;
+	int scale = (int)(((size >> 20) / sizeof(ulong) + TOTAL_PROGRESS_DOTS - 1) / TOTAL_PROGRESS_DOTS);
+
+	test_log("Bit flip pattern test\n");
 
 	for (i = 0; i < size / sizeof (ulong); i++) {
 		mem[i] = 1 << (i % 32);
 		if (i % 1024 == 0)
 			WATCHDOG_RESET ();
+		if ((i % (1 << 20)) == 0)
+			TEST_SHOW_PROGRESS(scale, dots, digit, 1);
 	}
+	test_log("Filled with pattern\n");
+	digit = TOTAL_PROGRESS_DOTS;
+	dots  = 0;
 
 	for (i = 0; i < size / sizeof (ulong) && ret == 0; i++) {
 		readback = mem[i];
 		if (readback != (1 << (i % 32))) {
-			post_log ("Memory error at %08x, "
-				  "wrote %08x, read %08x !\n",
+			test_log("Memory error at %p, "
+				  "wrote %08x, read %08lx !\n",
 					  mem + i, 1 << (i % 32), readback);
 
 			ret = -1;
@@ -348,7 +399,11 @@ static int memory_post_test2 (unsigned long start, unsigned long size)
 		}
 		if (i % 1024 == 0)
 			WATCHDOG_RESET ();
+		if ((i % (1 << 20)) == 0)
+			TEST_SHOW_PROGRESS(scale, dots, digit, 1);
 	}
+	if (!ret)
+		test_log("Verifed\n");
 
 	return ret;
 }
@@ -359,18 +414,28 @@ static int memory_post_test3 (unsigned long start, unsigned long size)
 	ulong *mem = (ulong *) start;
 	ulong readback;
 	int ret = 0;
+	int digit = TOTAL_PROGRESS_DOTS;
+	int dots = 0;
+	int scale = (int)(((size >> 20) / sizeof(ulong) + TOTAL_PROGRESS_DOTS - 1) / TOTAL_PROGRESS_DOTS);
+
+	test_log("Address pattern (offset)\n");
 
 	for (i = 0; i < size / sizeof (ulong); i++) {
 		mem[i] = i;
 		if (i % 1024 == 0)
 			WATCHDOG_RESET ();
+		if ((i % (1 << 20)) == 0)
+			TEST_SHOW_PROGRESS(scale, dots, digit, 1);
 	}
+	test_log("Filled with pattern\n");
+	digit = TOTAL_PROGRESS_DOTS;
+	dots  = 0;
 
 	for (i = 0; i < size / sizeof (ulong) && ret == 0; i++) {
 		readback = mem[i];
 		if (readback != i) {
-			post_log ("Memory error at %08x, "
-				  "wrote %08x, read %08x !\n",
+			test_log("Memory error at %p, "
+				  "wrote %08lx, read %08lx !\n",
 					  mem + i, i, readback);
 
 			ret = -1;
@@ -378,8 +443,11 @@ static int memory_post_test3 (unsigned long start, unsigned long size)
 		}
 		if (i % 1024 == 0)
 			WATCHDOG_RESET ();
+		if ((i % (1 << 20)) == 0)
+			TEST_SHOW_PROGRESS(scale, dots, digit, 1);
 	}
-
+	if (!ret)
+		test_log("Verifed\n");
 	return ret;
 }
 
@@ -389,18 +457,28 @@ static int memory_post_test4 (unsigned long start, unsigned long size)
 	ulong *mem = (ulong *) start;
 	ulong readback;
 	int ret = 0;
+	int digit = TOTAL_PROGRESS_DOTS;
+	int dots = 0;
+	int scale = (int)(((size >> 20) / sizeof(ulong) + TOTAL_PROGRESS_DOTS - 1) / TOTAL_PROGRESS_DOTS);
+
+	test_log("Address pattern (!offset)\n");
 
 	for (i = 0; i < size / sizeof (ulong); i++) {
 		mem[i] = ~i;
 		if (i % 1024 == 0)
 			WATCHDOG_RESET ();
+		if ((i % (1 << 20)) == 0)
+			TEST_SHOW_PROGRESS(scale, dots, digit, 1);
 	}
+	test_log("Filled with pattern\n");
+	digit = TOTAL_PROGRESS_DOTS;
+	dots  = 0;
 
 	for (i = 0; i < size / sizeof (ulong) && ret == 0; i++) {
 		readback = mem[i];
 		if (readback != ~i) {
-			post_log ("Memory error at %08x, "
-				  "wrote %08x, read %08x !\n",
+			test_log("Memory error at %p, "
+				  "wrote %08lx, read %08lx !\n",
 					  mem + i, ~i, readback);
 
 			ret = -1;
@@ -408,12 +486,16 @@ static int memory_post_test4 (unsigned long start, unsigned long size)
 		}
 		if (i % 1024 == 0)
 			WATCHDOG_RESET ();
+		if ((i % (1 << 20)) == 0)
+			TEST_SHOW_PROGRESS(scale, dots, digit, 1);
 	}
+	if (!ret)
+		test_log("Verifed\n");
 
 	return ret;
 }
 
-static int memory_post_tests (unsigned long start, unsigned long size)
+int memory_post_tests(unsigned long start, unsigned long size)
 {
 	int ret = 0;
 
@@ -451,33 +533,4 @@ static int memory_post_tests (unsigned long start, unsigned long size)
 
 	return ret;
 }
-
-int memory_post_test (int flags)
-{
-	int ret = 0;
-	bd_t *bd = gd->bd;
-	unsigned long memsize = (bd->bi_memsize >= 256 << 20 ?
-				 256 << 20 : bd->bi_memsize) - (1 << 20);
-
-	/* Limit area to be tested with the board info struct */
-	if (CONFIG_SYS_SDRAM_BASE + memsize > (ulong)bd)
-		memsize = (ulong)bd - CONFIG_SYS_SDRAM_BASE;
-
-	if (flags & POST_SLOWTEST) {
-		ret = memory_post_tests (CONFIG_SYS_SDRAM_BASE, memsize);
-	} else {			/* POST_NORMAL */
-
-		unsigned long i;
-
-		for (i = 0; i < (memsize >> 20) && ret == 0; i++) {
-			if (ret == 0)
-				ret = memory_post_tests (i << 20, 0x800);
-			if (ret == 0)
-				ret = memory_post_tests ((i << 20) + 0xff800, 0x800);
-		}
-	}
-
-	return ret;
-}
-
-#endif /* CONFIG_POST & CONFIG_SYS_POST_MEMORY */
+#endif /* (CONFIG_POST & CONFIG_SYS_POST_MEMORY) | defined(CONFIG_SYS_DRAM_TEST) */
-- 
1.7.0.4






More information about the U-Boot mailing list