#include <common.h>
#include <command.h>
-#if (CONFIG_COMMANDS & CFG_CMD_MMC)
+#if defined(CONFIG_CMD_MMC)
#include <mmc.h>
#endif
#ifdef CONFIG_HAS_DATAFLASH
#include <dataflash.h>
#endif
-#if (CONFIG_COMMANDS & (CFG_CMD_MEMORY | \
- CFG_CMD_I2C | \
- CFG_CMD_PCI | \
- CMD_CMD_PORTIO ) )
+#if defined(CONFIG_CMD_MEMORY) \
+ || defined(CONFIG_CMD_I2C) \
+ || defined(CONFIG_CMD_ITEST) \
+ || defined(CONFIG_CMD_PCI) \
+ || defined(CONFIG_CMD_PORTIO)
+
int cmd_get_data_size(char* arg, int default_size)
{
/* Check for a size specification .b, .w or .l.
return 2;
case 'l':
return 4;
+ case 's':
+ return -2;
default:
return -1;
}
}
#endif
-#if (CONFIG_COMMANDS & CFG_CMD_MEMORY)
+#if defined(CONFIG_CMD_MEMORY)
#ifdef CMD_MEM_DEBUG
#define PRINTF(fmt,args...) printf (fmt ,##args)
int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
ulong addr, length;
- ulong i, nbytes, linebytes;
- u_char *cp;
+#if defined(CONFIG_HAS_DATAFLASH)
+ ulong nbytes, linebytes;
+#endif
int size;
int rc = 0;
length = simple_strtoul(argv[2], NULL, 16);
}
+#if defined(CONFIG_HAS_DATAFLASH)
/* Print the lines.
*
* We buffer all read data, so we can make sure data is read only
nbytes = length * size;
do {
char linebuf[DISP_LINE_LEN];
- uint *uip = (uint *)linebuf;
- ushort *usp = (ushort *)linebuf;
- u_char *ucp = (u_char *)linebuf;
-
- printf("%08lx:", addr);
+ void* p;
linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
-#ifdef CONFIG_HAS_DATAFLASH
- if (read_dataflash(addr, (linebytes/size)*size, linebuf) != -1){
-
- for (i=0; i<linebytes; i+= size) {
- if (size == 4) {
- printf(" %08x", *uip++);
- } else if (size == 2) {
- printf(" %04x", *usp++);
- } else {
- printf(" %02x", *ucp++);
- }
- addr += size;
- }
+ rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
+ p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
+ print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
- } else { /* addr does not correspond to DataFlash */
-#endif
- for (i=0; i<linebytes; i+= size) {
- if (size == 4) {
- printf(" %08x", (*uip++ = *((uint *)addr)));
- } else if (size == 2) {
- printf(" %04x", (*usp++ = *((ushort *)addr)));
- } else {
- printf(" %02x", (*ucp++ = *((u_char *)addr)));
- }
- addr += size;
- }
-#ifdef CONFIG_HAS_DATAFLASH
- }
-#endif
- printf(" ");
- cp = linebuf;
- for (i=0; i<linebytes; i++) {
- if ((*cp < 0x20) || (*cp > 0x7e))
- printf(".");
- else
- printf("%c", *cp);
- cp++;
- }
- printf("\n");
nbytes -= linebytes;
+ addr += linebytes;
if (ctrlc()) {
rc = 1;
break;
}
} while (nbytes > 0);
+#else
+
+# if defined(CONFIG_BLACKFIN)
+ /* See if we're trying to display L1 inst */
+ if (addr_bfin_on_chip_mem(addr)) {
+ char linebuf[DISP_LINE_LEN];
+ ulong linebytes, nbytes = length * size;
+ do {
+ linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
+ memcpy(linebuf, (void *)addr, linebytes);
+ print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
+
+ nbytes -= linebytes;
+ addr += linebytes;
+ if (ctrlc()) {
+ rc = 1;
+ break;
+ }
+ } while (nbytes > 0);
+ } else
+# endif
+
+ {
+ /* Print the lines. */
+ print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
+ addr += size*length;
+ }
+#endif
dp_last_addr = addr;
dp_last_length = length;
return 0;
}
+#ifdef CONFIG_MX_CYCLIC
+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);
+ return 1;
+ }
+
+ count = simple_strtoul(argv[3], NULL, 10);
+
+ for (;;) {
+ do_mem_md (NULL, 0, 3, argv);
+
+ /* delay for <count> ms... */
+ for (i=0; i<count; i++)
+ udelay (1000);
+
+ /* check for ctrl-c to abort... */
+ if (ctrlc()) {
+ puts("Abort\n");
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
+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);
+ return 1;
+ }
+
+ count = simple_strtoul(argv[3], NULL, 10);
+
+ for (;;) {
+ do_mem_mw (NULL, 0, 3, argv);
+
+ /* delay for <count> ms... */
+ for (i=0; i<count; i++)
+ udelay (1000);
+
+ /* check for ctrl-c to abort... */
+ if (ctrlc()) {
+ puts("Abort\n");
+ return 0;
+ }
+ }
+
+ return 0;
+}
+#endif /* CONFIG_MX_CYCLIC */
+
int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
ulong addr1, addr2, count, ngood;
#ifdef CONFIG_HAS_DATAFLASH
if (addr_dataflash(addr1) | addr_dataflash(addr2)){
- printf("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");
return 0;
}
#endif
/* check if we are copying to Flash */
if ( (addr2info(dest) != NULL)
#ifdef CONFIG_HAS_DATAFLASH
- && (!addr_dataflash(addr))
+ && (!addr_dataflash(dest))
#endif
) {
int rc;
- printf ("Copy to Flash... ");
+ puts ("Copy to Flash... ");
- rc = flash_write ((uchar *)addr, dest, count*size);
+ rc = flash_write ((char *)addr, dest, count*size);
if (rc != 0) {
flash_perror (rc);
return (1);
}
#endif
-#if (CONFIG_COMMANDS & CFG_CMD_MMC)
+#if defined(CONFIG_CMD_MMC)
if (mmc2info(dest)) {
int rc;
- printf ("Copy to MMC... ");
+ puts ("Copy to MMC... ");
switch (rc = mmc_write ((uchar *)addr, dest, count*size)) {
case 0:
- printf ("\n");
+ putc ('\n');
return 1;
case -1:
- printf("failed\n");
+ puts ("failed\n");
return 1;
default:
printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
if (mmc2info(addr)) {
int rc;
- printf ("Copy from MMC... ");
+ puts ("Copy from MMC... ");
switch (rc = mmc_read (addr, (uchar *)dest, count*size)) {
case 0:
- printf ("\n");
+ putc ('\n');
return 1;
case -1:
- printf("failed\n");
+ puts ("failed\n");
return 1;
default:
printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
if (addr_dataflash(dest) && !addr_dataflash(addr)){
int rc;
- printf ("Copy to DataFlash... ");
+ puts ("Copy to DataFlash... ");
rc = write_dataflash (dest, addr, count*size);
/* Check if we are copying from DataFlash to RAM */
if (addr_dataflash(addr) && !addr_dataflash(dest) && (addr2info(dest)==NULL) ){
- read_dataflash(addr, count * size, (char *) dest);
+ int rc;
+ rc = read_dataflash(addr, count * size, (char *) dest);
+ if (rc != 1) {
+ dataflash_perror (rc);
+ return (1);
+ }
return 0;
}
if (addr_dataflash(addr) && addr_dataflash(dest)){
- printf("Unsupported combination of source/destination.\n\r");
+ puts ("Unsupported combination of source/destination.\n\r");
return 1;
}
#endif
+#ifdef CONFIG_BLACKFIN
+ /* See if we're copying to/from L1 inst */
+ if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
+ memcpy((void *)dest, (void *)addr, count * size);
+ return 0;
+ }
+#endif
+
while (count-- > 0) {
if (size == 4)
*((ulong *)dest) = *((ulong *)addr);
}
}
+#ifdef CONFIG_LOOPW
+int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ ulong addr, length, i, data;
+ int size;
+ volatile uint *longp;
+ volatile ushort *shortp;
+ volatile u_char *cp;
+
+ if (argc < 4) {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ /* Check for a size spefication.
+ * Defaults to long if no or incorrect specification.
+ */
+ if ((size = cmd_get_data_size(argv[0], 4)) < 0)
+ return 1;
+
+ /* Address is always specified.
+ */
+ addr = simple_strtoul(argv[1], NULL, 16);
+
+ /* Length is the number of objects, not number of bytes.
+ */
+ length = simple_strtoul(argv[2], NULL, 16);
+
+ /* data to write */
+ data = simple_strtoul(argv[3], NULL, 16);
+
+ /* We want to optimize the loops to run as fast as possible.
+ * If we have only one object, just run infinite loops.
+ */
+ if (length == 1) {
+ if (size == 4) {
+ longp = (uint *)addr;
+ for (;;)
+ *longp = data;
+ }
+ if (size == 2) {
+ shortp = (ushort *)addr;
+ for (;;)
+ *shortp = data;
+ }
+ cp = (u_char *)addr;
+ for (;;)
+ *cp = data;
+ }
+
+ if (size == 4) {
+ for (;;) {
+ longp = (uint *)addr;
+ i = length;
+ while (i-- > 0)
+ *longp++ = data;
+ }
+ }
+ if (size == 2) {
+ for (;;) {
+ shortp = (ushort *)addr;
+ i = length;
+ while (i-- > 0)
+ *shortp++ = data;
+ }
+ }
+ for (;;) {
+ cp = (u_char *)addr;
+ i = length;
+ while (i-- > 0)
+ *cp++ = data;
+ }
+}
+#endif /* CONFIG_LOOPW */
+
/*
* Perform a memory test. A more complete alternative test can be
* configured using CFG_ALT_MEMTEST. The complete test loops until
vu_long *addr, *start, *end;
ulong val;
ulong readback;
+ int rcode = 0;
#if defined(CFG_ALT_MEMTEST)
- vu_long addr_mask;
+ vu_long len;
vu_long offset;
vu_long test_offset;
vu_long pattern;
#if defined(CFG_MEMTEST_SCRATCH)
vu_long *dummy = (vu_long*)CFG_MEMTEST_SCRATCH;
#else
- vu_long *dummy = NULL;
+ vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
#endif
int j;
int iterations = 1;
#else
ulong incr;
ulong pattern;
- int rcode = 0;
#endif
if (argc > 1) {
if(readback != ~val) {
printf ("FAILURE (data line): "
"Is %08lx, should be %08lx\n",
- val, readback);
+ readback, ~val);
}
}
}
* all possible.
*
* Returns: 0 if the test succeeds, 1 if the test fails.
- *
- * ## NOTE ## Be sure to specify start and end
- * addresses such that addr_mask has
- * lots of bits set. For example an
- * address range of 01000000 02000000 is
- * bad while a range of 01000000
- * 01ffffff is perfect.
*/
- addr_mask = ((ulong)end - (ulong)start)/sizeof(vu_long);
+ len = ((ulong)end - (ulong)start)/sizeof(vu_long);
pattern = (vu_long) 0xaaaaaaaa;
anti_pattern = (vu_long) 0x55555555;
- PRINTF("%s:%d: addr mask = 0x%.8lx\n",
+ PRINTF("%s:%d: length = 0x%.8lx\n",
__FUNCTION__, __LINE__,
- addr_mask);
+ len);
/*
* Write the default pattern at each of the
* power-of-two offsets.
*/
- for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) {
+ for (offset = 1; offset < len; offset <<= 1) {
start[offset] = pattern;
}
test_offset = 0;
start[test_offset] = anti_pattern;
- for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) {
+ for (offset = 1; offset < len; offset <<= 1) {
temp = start[offset];
if (temp != pattern) {
printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
/*
* Check for addr bits stuck low or shorted.
*/
- for (test_offset = 1; (test_offset & addr_mask) != 0; test_offset <<= 1) {
+ for (test_offset = 1; test_offset < len; test_offset <<= 1) {
start[test_offset] = anti_pattern;
- for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) {
+ for (offset = 1; offset < len; offset <<= 1) {
temp = start[offset];
if ((temp != pattern) && (offset != test_offset)) {
printf ("\nFAILURE: Address bit stuck low or shorted @"
val += incr;
}
- printf("Reading...");
+ puts ("Reading...");
for (addr=start,val=pattern; addr<end; addr++) {
readback = *addr;
}
incr = -incr;
}
- return rcode;
#endif
+ return rcode;
}
#ifdef CONFIG_HAS_DATAFLASH
if (addr_dataflash(addr)){
- printf("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");
return 0;
}
#endif
return 0;
}
+#ifndef CONFIG_CRC32_VERIFY
+
int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
ulong addr, length;
return 0;
}
+#else /* CONFIG_CRC32_VERIFY */
+
+int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ ulong addr, length;
+ ulong crc;
+ ulong *ptr;
+ ulong vcrc;
+ int verify;
+ int ac;
+ char **av;
+
+ if (argc < 3) {
+ usage:
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ av = argv + 1;
+ ac = argc - 1;
+ if (strcmp(*av, "-v") == 0) {
+ verify = 1;
+ av++;
+ ac--;
+ if (ac < 3)
+ goto usage;
+ } else
+ verify = 0;
+
+ addr = simple_strtoul(*av++, NULL, 16);
+ addr += base_address;
+ length = simple_strtoul(*av++, NULL, 16);
+
+ crc = crc32(0, (const uchar *) addr, length);
+
+ if (!verify) {
+ printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
+ addr, addr + length - 1, crc);
+ if (ac > 2) {
+ 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",
+ addr, addr + length - 1, crc, vcrc);
+ return 1;
+ }
+ }
+
+ return 0;
+
+}
+#endif /* CONFIG_CRC32_VERIFY */
+
/**************************************************/
-#if (CONFIG_COMMANDS & CFG_CMD_MEMORY)
+#if defined(CONFIG_CMD_MEMORY)
U_BOOT_CMD(
md, 3, 1, do_mem_md,
"md - memory display\n",
"[.b, .w, .l] addr1 addr2 count\n - compare memory\n"
);
+#ifndef CONFIG_CRC32_VERIFY
+
U_BOOT_CMD(
crc32, 4, 1, do_mem_crc,
"crc32 - checksum calculation\n",
"address count [addr]\n - compute CRC32 checksum [save at addr]\n"
);
+#else /* CONFIG_CRC32_VERIFY */
+
+U_BOOT_CMD(
+ crc32, 5, 1, do_mem_crc,
+ "crc32 - checksum calculation\n",
+ "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
+ "-v address count crc\n - verify crc of memory area\n"
+);
+
+#endif /* CONFIG_CRC32_VERIFY */
+
U_BOOT_CMD(
base, 2, 1, do_mem_base,
"base - print or set address offset\n",
" - loop on a set of addresses\n"
);
+#ifdef CONFIG_LOOPW
+U_BOOT_CMD(
+ loopw, 4, 1, do_mem_loopw,
+ "loopw - infinite write loop on address range\n",
+ "[.b, .w, .l] address number_of_objects data_to_write\n"
+ " - loop on a set of addresses\n"
+);
+#endif /* CONFIG_LOOPW */
+
U_BOOT_CMD(
mtest, 4, 1, do_mem_mtest,
"mtest - simple RAM test\n",
" - simple RAM read/write test\n"
);
+#ifdef CONFIG_MX_CYCLIC
+U_BOOT_CMD(
+ mdc, 4, 1, do_mem_mdc,
+ "mdc - memory display cyclic\n",
+ "[.b, .w, .l] address count delay(ms)\n - memory display cyclic\n"
+);
+
+U_BOOT_CMD(
+ mwc, 4, 1, do_mem_mwc,
+ "mwc - memory write cyclic\n",
+ "[.b, .w, .l] address value delay(ms)\n - memory write cyclic\n"
+);
+#endif /* CONFIG_MX_CYCLIC */
+
+#endif
#endif
-#endif /* CFG_CMD_MEMORY */