The iteration limit is passed to mtest as a fourth parameter: [start [end [pattern [iterations]]]] If no fourth parameter is supplied, there is no iteration limit and the test will loop forever.
Signed-off-by: Dirk Eibach <eib...@gdsys.de> --- - Beautified commit message - Whitespace cleanup - Linelength cleanup common/cmd_mem.c | 225 +++++++++++++++++++++++++++++------------------------ 1 files changed, 123 insertions(+), 102 deletions(-) diff --git a/common/cmd_mem.c b/common/cmd_mem.c index d7666c2..405d45f 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -38,9 +38,9 @@ #include <watchdog.h> #ifdef CMD_MEM_DEBUG -#define PRINTF(fmt,args...) printf (fmt ,##args) +#define PRINTF(fmt, args...) printf(fmt, ##args) #else -#define PRINTF(fmt,args...) +#define PRINTF(fmt, args...) #endif static int mod_mem(cmd_tbl_t *, int, int, int, char *[]); @@ -60,7 +60,7 @@ static ulong base_address = 0; * md{.b, .w, .l} {addr} {len} */ #define DISP_LINE_LEN 16 -int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, length; #if defined(CONFIG_HAS_DATAFLASH) @@ -77,7 +77,7 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) length = dp_last_length; if (argc < 2) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -155,25 +155,25 @@ int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) dp_last_addr = addr; dp_last_length = length; dp_last_size = size; - return (rc); + return rc; } -int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - return mod_mem (cmdtp, 1, flag, argc, argv); + return mod_mem(cmdtp, 1, flag, argc, argv); } -int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - return mod_mem (cmdtp, 0, flag, argc, argv); + return mod_mem(cmdtp, 0, flag, argc, argv); } -int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, writeval, count; int size; if ((argc < 3) || (argc > 4)) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -211,24 +211,24 @@ int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #ifdef CONFIG_MX_CYCLIC -int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int i; ulong count; if (argc < 4) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } count = simple_strtoul(argv[3], NULL, 10); for (;;) { - do_mem_md (NULL, 0, 3, argv); + do_mem_md(NULL, 0, 3, argv); /* delay for <count> ms... */ for (i=0; i<count; i++) - udelay (1000); + udelay(1000); /* check for ctrl-c to abort... */ if (ctrlc()) { @@ -240,24 +240,24 @@ int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 0; } -int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int i; ulong count; if (argc < 4) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } count = simple_strtoul(argv[3], NULL, 10); for (;;) { - do_mem_mw (NULL, 0, 3, argv); + do_mem_mw(NULL, 0, 3, argv); /* delay for <count> ms... */ for (i=0; i<count; i++) - udelay (1000); + udelay(1000); /* check for ctrl-c to abort... */ if (ctrlc()) { @@ -270,14 +270,14 @@ int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #endif /* CONFIG_MX_CYCLIC */ -int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr1, addr2, count, ngood; int size; int rcode = 0; if (argc != 4) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -296,14 +296,15 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #ifdef CONFIG_HAS_DATAFLASH if (addr_dataflash(addr1) | addr_dataflash(addr2)){ - puts ("Comparison with DataFlash space not supported.\n\r"); + puts("Comparison with DataFlash space not supported.\n\r"); return 0; } #endif #ifdef CONFIG_BLACKFIN if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) { - puts ("Comparison with L1 instruction memory not supported.\n\r"); + puts("Comparison with L1 instruction memory not " + "supported.\n\r"); return 0; } #endif @@ -355,13 +356,13 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return rcode; } -int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, dest, count; int size; if (argc != 4) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -379,7 +380,7 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) count = simple_strtoul(argv[3], NULL, 16); if (count == 0) { - puts ("Zero length ???\n"); + puts("Zero length ???\n"); return 1; } @@ -392,14 +393,14 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) ) { int rc; - puts ("Copy to Flash... "); + puts("Copy to Flash... "); - rc = flash_write ((char *)addr, dest, count*size); + rc = flash_write((char *)addr, dest, count*size); if (rc != 0) { - flash_perror (rc); - return (1); + flash_perror(rc); + return 1; } - puts ("done\n"); + puts("done\n"); return 0; } #endif @@ -408,38 +409,38 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if (mmc2info(dest)) { int rc; - puts ("Copy to MMC... "); - switch (rc = mmc_write ((uchar *)addr, dest, count*size)) { + puts("Copy to MMC... "); + switch (rc = mmc_write((uchar *)addr, dest, count*size)) { case 0: - putc ('\n'); + putc('\n'); return 1; case -1: - puts ("failed\n"); + puts("failed\n"); return 1; default: - printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc); + printf("%s[%d] FIXME: rc=%d\n", __FILE__, __LINE__, rc); return 1; } - puts ("done\n"); + puts("done\n"); return 0; } if (mmc2info(addr)) { int rc; - puts ("Copy from MMC... "); - switch (rc = mmc_read (addr, (uchar *)dest, count*size)) { + puts("Copy from MMC... "); + switch (rc = mmc_read(addr, (uchar *)dest, count*size)) { case 0: - putc ('\n'); + putc('\n'); return 1; case -1: - puts ("failed\n"); + puts("failed\n"); return 1; default: - printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc); + printf("%s[%d] FIXME: rc=%d\n", __FILE__, __LINE__, rc); return 1; } - puts ("done\n"); + puts("done\n"); return 0; } #endif @@ -449,15 +450,15 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if (addr_dataflash(dest) && !addr_dataflash(addr)){ int rc; - puts ("Copy to DataFlash... "); + puts("Copy to DataFlash... "); - rc = write_dataflash (dest, addr, count*size); + rc = write_dataflash(dest, addr, count*size); if (rc != 1) { - dataflash_perror (rc); - return (1); + dataflash_perror(rc); + return 1; } - puts ("done\n"); + puts("done\n"); return 0; } @@ -470,14 +471,14 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) int rc; rc = read_dataflash(addr, count * size, (char *) dest); if (rc != 1) { - dataflash_perror (rc); - return (1); + dataflash_perror(rc); + return 1; } return 0; } if (addr_dataflash(addr) && addr_dataflash(dest)){ - puts ("Unsupported combination of source/destination.\n\r"); + puts("Unsupported combination of source/destination.\n\r"); return 1; } #endif @@ -503,7 +504,7 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 0; } -int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { if (argc > 1) { /* Set new base address. @@ -516,7 +517,7 @@ int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 0; } -int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, length, i, junk; int size; @@ -525,7 +526,7 @@ int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) volatile u_char *cp; if (argc < 3) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -587,7 +588,7 @@ int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #ifdef CONFIG_LOOPW -int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, length, i, data; int size; @@ -596,7 +597,7 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) volatile u_char *cp; if (argc < 4) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -666,12 +667,14 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until * interrupted by ctrl-c or by a failure of one of the sub-tests. */ -int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { vu_long *addr, *start, *end; ulong val; ulong readback; int rcode = 0; + int iterations = 1; + int iteration_limit; #if defined(CONFIG_SYS_ALT_MEMTEST) vu_long len; @@ -687,7 +690,6 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */ #endif int j; - int iterations = 1; static const ulong bitpattern[] = { 0x00000001, /* single bit */ @@ -704,37 +706,46 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) ulong pattern; #endif - if (argc > 1) { + if (argc > 1) start = (ulong *)simple_strtoul(argv[1], NULL, 16); - } else { + else start = (ulong *)CONFIG_SYS_MEMTEST_START; - } - if (argc > 2) { + if (argc > 2) end = (ulong *)simple_strtoul(argv[2], NULL, 16); - } else { + else end = (ulong *)(CONFIG_SYS_MEMTEST_END); - } - if (argc > 3) { + if (argc > 3) pattern = (ulong)simple_strtoul(argv[3], NULL, 16); - } else { + else pattern = 0; - } + + if (argc > 4) + iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16); + else + iteration_limit = 0; #if defined(CONFIG_SYS_ALT_MEMTEST) - printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end); + printf("Testing %08x ... %08x:\n", (uint)start, (uint)end); PRINTF("%s:%d: start 0x%p end 0x%p\n", __FUNCTION__, __LINE__, start, end); for (;;) { if (ctrlc()) { - putc ('\n'); + putc('\n'); return 1; } + + if (iteration_limit && iterations > iteration_limit) { + printf("Tested %d iteration(s) without errors.\n", + iterations-1); + return 0; + } + printf("Iteration: %6d\r", iterations); - PRINTF("Iteration: %6d\n", iterations); + PRINTF("\n"); iterations++; /* @@ -762,7 +773,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) *dummy = ~val; /* clear the test data off of the bus */ readback = *addr; if(readback != val) { - printf ("FAILURE (data line): " + printf("FAILURE (data line): " "expected %08lx, actual %08lx\n", val, readback); } @@ -770,7 +781,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) *dummy = val; readback = *addr; if(readback != ~val) { - printf ("FAILURE (data line): " + printf("FAILURE (data line): " "Is %08lx, should be %08lx\n", readback, ~val); } @@ -835,7 +846,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) for (offset = 1; offset < len; offset <<= 1) { temp = start[offset]; if (temp != pattern) { - printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:" + printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx\n", (ulong)&start[offset], pattern, temp); return 1; @@ -853,8 +864,9 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) for (offset = 1; offset < len; offset <<= 1) { temp = start[offset]; if ((temp != pattern) && (offset != test_offset)) { - printf ("\nFAILURE: Address bit stuck low or shorted @" - " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n", + printf("\nFAILURE: Address bit stuck low or shorted" + " @ 0x%.8lx: expected 0x%.8lx," + " actual 0x%.8lx\n", (ulong)&start[offset], pattern, temp); return 1; } @@ -891,7 +903,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) WATCHDOG_RESET(); temp = start[offset]; if (temp != pattern) { - printf ("\nFAILURE (read/write) @ 0x%.8lx:" + printf("\nFAILURE (read/write) @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", (ulong)&start[offset], pattern, temp); return 1; @@ -909,7 +921,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) anti_pattern = ~pattern; temp = start[offset]; if (temp != anti_pattern) { - printf ("\nFAILURE (read/write): @ 0x%.8lx:" + printf("\nFAILURE (read/write): @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", (ulong)&start[offset], anti_pattern, temp); return 1; @@ -922,11 +934,18 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) incr = 1; for (;;) { if (ctrlc()) { - putc ('\n'); + putc('\n'); return 1; } - printf ("\rPattern %08lX Writing..." + if (iteration_limit && iterations > iteration_limit) { + printf("Tested %d iteration(s) without errors.\n", + iterations-1); + return 0; + } + ++iterations; + + printf("\rPattern %08lX Writing..." "%12s" "\b\b\b\b\b\b\b\b\b\b", pattern, ""); @@ -937,13 +956,13 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) val += incr; } - puts ("Reading..."); + puts("Reading..."); for (addr=start,val=pattern; addr<end; addr++) { WATCHDOG_RESET(); readback = *addr; if (readback != val) { - printf ("\nMem error @ 0x%08X: " + printf("\nMem error @ 0x%08X: " "found %08lX, expected %08lX\n", (uint)addr, readback, val); rcode = 1; @@ -984,7 +1003,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]) extern char console_buffer[]; if (argc != 2) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -1012,14 +1031,15 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]) #ifdef CONFIG_HAS_DATAFLASH if (addr_dataflash(addr)){ - puts ("Can't modify DataFlash in place. Use cp instead.\n\r"); + puts("Can't modify DataFlash in place. Use cp instead.\n\r"); return 0; } #endif #ifdef CONFIG_BLACKFIN if (addr_bfin_on_chip_mem(addr)) { - puts ("Can't modify L1 instruction in place. Use cp instead.\n\r"); + puts("Can't modify L1 instruction in place. " + "Use cp instead.\n\r"); return 0; } #endif @@ -1036,7 +1056,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]) else printf(" %02x", *((u_char *)addr)); - nbytes = readline (" ? "); + nbytes = readline(" ? "); if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { /* <CR> pressed as only input, don't modify current * location and move to next. "-" pressed will go back. @@ -1082,25 +1102,25 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]) #ifndef CONFIG_CRC32_VERIFY -int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, length; ulong crc; ulong *ptr; if (argc < 3) { - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } - addr = simple_strtoul (argv[1], NULL, 16); + addr = simple_strtoul(argv[1], NULL, 16); addr += base_address; - length = simple_strtoul (argv[2], NULL, 16); + length = simple_strtoul(argv[2], NULL, 16); - crc = crc32 (0, (const uchar *) addr, length); + crc = crc32(0, (const uchar *) addr, length); - printf ("CRC32 for %08lx ... %08lx ==> %08lx\n", + printf("CRC32 for %08lx ... %08lx ==> %08lx\n", addr, addr + length - 1, crc); if (argc > 3) { @@ -1113,7 +1133,7 @@ int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #else /* CONFIG_CRC32_VERIFY */ -int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, length; ulong crc; @@ -1125,7 +1145,7 @@ int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if (argc < 3) { usage: - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -1147,16 +1167,17 @@ int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) crc = crc32(0, (const uchar *) addr, length); if (!verify) { - printf ("CRC32 for %08lx ... %08lx ==> %08lx\n", + printf("CRC32 for %08lx ... %08lx ==> %08lx\n", addr, addr + length - 1, crc); if (ac > 2) { - ptr = (ulong *) simple_strtoul (*av++, NULL, 16); + ptr = (ulong *) simple_strtoul(*av++, NULL, 16); *ptr = crc; } } else { vcrc = simple_strtoul(*av++, NULL, 16); if (vcrc != crc) { - printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n", + printf("CRC32 for %08lx ... %08lx ==> %08lx != %08lx " + "** ERROR **\n", addr, addr + length - 1, crc, vcrc); return 1; } @@ -1169,9 +1190,9 @@ int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #ifdef CONFIG_CMD_UNZIP -int gunzip (void *, int, unsigned char *, unsigned long *); +int gunzip(void *, int, unsigned char *, unsigned long *); -int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { unsigned long src, dst; unsigned long src_len = ~0UL, dst_len = ~0UL; @@ -1186,7 +1207,7 @@ int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) dst = simple_strtoul(argv[2], NULL, 16); break; default: - printf ("Usage:\n%s\n", cmdtp->usage); + printf("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -1277,9 +1298,9 @@ U_BOOT_CMD( #endif /* CONFIG_LOOPW */ U_BOOT_CMD( - mtest, 4, 1, do_mem_mtest, - "mtest - simple RAM test\n", - "[start [end [pattern]]]\n" + mtest, 5, 1, do_mem_mtest, + "mtest - simple RAM test\n", + "[start [end [pattern [iterations]]]]\n" " - simple RAM read/write test\n" ); -- 1.5.6.5 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot