xilinx: Move bootmode detection to separate function
[oweals/u-boot.git] / cmd / mem.c
index 83d34faf2d8885147e54ec62a200ae5ad41b6e18..0bfb6081e7e13e99fd1a1632928e1221c6dd1d1c 100644 (file)
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2000
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
 #include <cli.h>
 #include <command.h>
 #include <console.h>
-#ifdef CONFIG_HAS_DATAFLASH
-#include <dataflash.h>
-#endif
+#include <flash.h>
 #include <hash.h>
-#include <inttypes.h>
 #include <mapmem.h>
 #include <watchdog.h>
 #include <asm/io.h>
@@ -52,10 +48,8 @@ static       ulong   base_address = 0;
 #define DISP_LINE_LEN  16
 static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       ulong   addr, length;
-#if defined(CONFIG_HAS_DATAFLASH)
-       ulong   nbytes, linebytes;
-#endif
+       ulong   addr, length, bytes;
+       const void *buf;
        int     size;
        int rc = 0;
 
@@ -88,61 +82,13 @@ static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        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
-        * once, and all accesses are with the specified bus width.
-        */
-       nbytes = length * size;
-       do {
-               char    linebuf[DISP_LINE_LEN];
-               void* p;
-               linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
-
-               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);
-
-               nbytes -= linebytes;
-               addr += linebytes;
-               if (ctrlc()) {
-                       rc = 1;
-                       break;
-               }
-       } while (nbytes > 0);
-#else
+       bytes = size * length;
+       buf = map_sysmem(addr, bytes);
 
-# 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
-
-       {
-               ulong bytes = size * length;
-               const void *buf = map_sysmem(addr, bytes);
-
-               /* Print the lines. */
-               print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
-               addr += bytes;
-               unmap_sysmem(buf);
-       }
-#endif
+       /* Print the lines. */
+       print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
+       addr += bytes;
+       unmap_sysmem(buf);
 
        dp_last_addr = addr;
        dp_last_length = length;
@@ -161,7 +107,7 @@ static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        u64 writeval;
 #else
        ulong writeval;
@@ -186,7 +132,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        /* Get the value to write.
        */
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        writeval = simple_strtoull(argv[2], NULL, 16);
 #else
        writeval = simple_strtoul(argv[2], NULL, 16);
@@ -205,7 +151,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        while (count-- > 0) {
                if (size == 4)
                        *((u32 *)buf) = (u32)writeval;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
                else if (size == 8)
                        *((u64 *)buf) = (u64)writeval;
 #endif
@@ -219,7 +165,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        return 0;
 }
 
-#ifdef CONFIG_MX_CYCLIC
+#ifdef CONFIG_CMD_MX_CYCLIC
 static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        int i;
@@ -273,7 +219,7 @@ static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        return 0;
 }
-#endif /* CONFIG_MX_CYCLIC */
+#endif /* CONFIG_CMD_MX_CYCLIC */
 
 static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
@@ -282,7 +228,7 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        int     rcode = 0;
        const char *type;
        const void *buf1, *buf2, *base;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        u64 word1, word2;
 #else
        ulong word1, word2;
@@ -307,20 +253,6 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        count = simple_strtoul(argv[3], NULL, 16);
 
-#ifdef CONFIG_HAS_DATAFLASH
-       if (addr_dataflash(addr1) | addr_dataflash(addr2)){
-               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
-
        bytes = size * count;
        base = buf1 = map_sysmem(addr1, bytes);
        buf2 = map_sysmem(addr2, bytes);
@@ -328,7 +260,7 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                if (size == 4) {
                        word1 = *(u32 *)buf1;
                        word2 = *(u32 *)buf2;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
                } else if (size == 8) {
                        word1 = *(u64 *)buf1;
                        word2 = *(u64 *)buf2;
@@ -342,9 +274,8 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                }
                if (word1 != word2) {
                        ulong offset = buf1 - base;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
-                       printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
-                              PRIx64 ")\n",
+#ifdef MEM_SUPPORT_64BIT_DATA
+                       printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n",
                               type, (void *)(addr1 + offset), size, word1,
                               type, (void *)(addr2 + offset), size, word2);
 #else
@@ -373,6 +304,7 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        ulong   addr, dest, count;
+       void    *src, *dst;
        int     size;
 
        if (argc != 4)
@@ -396,75 +328,34 @@ static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                return 1;
        }
 
+       src = map_sysmem(addr, count * size);
+       dst = map_sysmem(dest, count * size);
+
 #ifdef CONFIG_MTD_NOR_FLASH
        /* check if we are copying to Flash */
-       if ( (addr2info(dest) != NULL)
-#ifdef CONFIG_HAS_DATAFLASH
-          && (!addr_dataflash(dest))
-#endif
-          ) {
+       if (addr2info((ulong)dst)) {
                int rc;
 
                puts ("Copy to Flash... ");
 
-               rc = flash_write ((char *)addr, dest, count*size);
+               rc = flash_write((char *)src, (ulong)dst, count * size);
                if (rc != 0) {
-                       flash_perror (rc);
+                       flash_perror(rc);
+                       unmap_sysmem(src);
+                       unmap_sysmem(dst);
                        return (1);
                }
                puts ("done\n");
+               unmap_sysmem(src);
+               unmap_sysmem(dst);
                return 0;
        }
 #endif
 
-#ifdef CONFIG_HAS_DATAFLASH
-       /* Check if we are copying from RAM or Flash to DataFlash */
-       if (addr_dataflash(dest) && !addr_dataflash(addr)){
-               int rc;
-
-               puts ("Copy to DataFlash... ");
-
-               rc = write_dataflash (dest, addr, count*size);
-
-               if (rc != 1) {
-                       dataflash_perror (rc);
-                       return (1);
-               }
-               puts ("done\n");
-               return 0;
-       }
-
-       /* Check if we are copying from DataFlash to RAM */
-       if (addr_dataflash(addr) && !addr_dataflash(dest)
-#ifdef CONFIG_MTD_NOR_FLASH
-                                && (addr2info(dest) == NULL)
-#endif
-          ){
-               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)){
-               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
-
-       memcpy((void *)dest, (void *)addr, count * size);
+       memcpy(dst, src, count * size);
 
+       unmap_sysmem(src);
+       unmap_sysmem(dst);
        return 0;
 }
 
@@ -487,7 +378,7 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
 {
        ulong   addr, length, i, bytes;
        int     size;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        volatile u64 *llp;
 #endif
        volatile u32 *longp;
@@ -520,7 +411,7 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
         * If we have only one object, just run infinite loops.
         */
        if (length == 1) {
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
                if (size == 8) {
                        llp = (u64 *)buf;
                        for (;;)
@@ -542,7 +433,7 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
                        i = *cp;
        }
 
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        if (size == 8) {
                for (;;) {
                        llp = (u64 *)buf;
@@ -585,7 +476,7 @@ static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
 {
        ulong   addr, length, i, bytes;
        int     size;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        volatile u64 *llp;
        u64 data;
 #else
@@ -615,7 +506,7 @@ static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
        length = simple_strtoul(argv[2], NULL, 16);
 
        /* data to write */
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        data = simple_strtoull(argv[3], NULL, 16);
 #else
        data = simple_strtoul(argv[3], NULL, 16);
@@ -628,7 +519,7 @@ static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
         * If we have only one object, just run infinite loops.
         */
        if (length == 1) {
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
                if (size == 8) {
                        llp = (u64 *)buf;
                        for (;;)
@@ -650,7 +541,7 @@ static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
                        *cp = data;
        }
 
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        if (size == 8) {
                for (;;) {
                        llp = (u64 *)buf;
@@ -910,6 +801,59 @@ static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
        return errs;
 }
 
+static int compare_regions(volatile unsigned long *bufa,
+                          volatile unsigned long *bufb, size_t count)
+{
+       volatile unsigned long  *p1 = bufa;
+       volatile unsigned long  *p2 = bufb;
+       int errs = 0;
+       size_t i;
+
+       for (i = 0; i < count; i++, p1++, p2++) {
+               if (*p1 != *p2) {
+                       printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n",
+                              (unsigned long)*p1, (unsigned long)*p2,
+                              *p1 ^ *p2, __ffs(*p1 ^ *p2),
+                               (unsigned long)(i * sizeof(unsigned long)));
+                       errs++;
+               }
+       }
+
+       return errs;
+}
+
+static ulong test_bitflip_comparison(volatile unsigned long *bufa,
+                                    volatile unsigned long *bufb, size_t count)
+{
+       volatile unsigned long *p1 = bufa;
+       volatile unsigned long *p2 = bufb;
+       unsigned int j, k;
+       unsigned long q;
+       size_t i;
+       int max;
+       int errs = 0;
+
+       max = sizeof(unsigned long) * 8;
+       for (k = 0; k < max; k++) {
+               q = 0x00000001L << k;
+               for (j = 0; j < 8; j++) {
+                       WATCHDOG_RESET();
+                       q = ~q;
+                       p1 = (volatile unsigned long *)bufa;
+                       p2 = (volatile unsigned long *)bufb;
+                       for (i = 0; i < count; i++)
+                               *p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
+
+                       errs += compare_regions(bufa, bufb, count);
+               }
+
+               if (ctrlc())
+                       return -1UL;
+       }
+
+       return errs;
+}
+
 static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
                            vu_long pattern, int iteration)
 {
@@ -980,15 +924,10 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
        ulong start, end;
        vu_long *buf, *dummy;
        ulong iteration_limit = 0;
-       int ret;
+       ulong count = 0;
        ulong errs = 0; /* number of errors, or -1 if interrupted */
        ulong pattern = 0;
        int iteration;
-#if defined(CONFIG_SYS_ALT_MEMTEST)
-       const int alt_test = 1;
-#else
-       const int alt_test = 0;
-#endif
 
        start = CONFIG_SYS_MEMTEST_START;
        end = CONFIG_SYS_MEMTEST_END;
@@ -1030,40 +969,34 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
 
                printf("Iteration: %6d\r", iteration + 1);
                debug("\n");
-               if (alt_test) {
+               if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
                        errs = mem_test_alt(buf, start, end, dummy);
+                       if (errs == -1UL)
+                               break;
+                       count += errs;
+                       errs = test_bitflip_comparison(buf,
+                                                      buf + (end - start) / 2,
+                                                      (end - start) /
+                                                      sizeof(unsigned long));
                } else {
                        errs = mem_test_quick(buf, start, end, pattern,
                                              iteration);
                }
                if (errs == -1UL)
                        break;
+               count += errs;
        }
 
-       /*
-        * Work-around for eldk-4.2 which gives this warning if we try to
-        * case in the unmap_sysmem() call:
-        * warning: initialization discards qualifiers from pointer target type
-        */
-       {
-               void *vbuf = (void *)buf;
-               void *vdummy = (void *)dummy;
-
-               unmap_sysmem(vbuf);
-               unmap_sysmem(vdummy);
-       }
+       unmap_sysmem((void *)buf);
+       unmap_sysmem((void *)dummy);
 
        if (errs == -1UL) {
                /* Memory test was aborted - write a newline to finish off */
                putc('\n');
-               ret = 1;
-       } else {
-               printf("Tested %d iteration(s) with %lu errors.\n",
-                       iteration, errs);
-               ret = errs != 0;
        }
+       printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
 
-       return ret;
+       return errs != 0;
 }
 #endif /* CONFIG_CMD_MEMTEST */
 
@@ -1077,7 +1010,7 @@ static int
 mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
 {
        ulong   addr;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        u64 i;
 #else
        ulong i;
@@ -1108,20 +1041,6 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
                addr += base_address;
        }
 
-#ifdef CONFIG_HAS_DATAFLASH
-       if (addr_dataflash(addr)){
-               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
-
        /* Print the address, followed by value.  Then accept input for
         * the next value.  A non-converted value exits.
         */
@@ -1130,9 +1049,9 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
                printf("%08lx:", addr);
                if (size == 4)
                        printf(" %08x", *((u32 *)ptr));
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
                else if (size == 8)
-                       printf(" %016" PRIx64, *((u64 *)ptr));
+                       printf(" %016llx", *((u64 *)ptr));
 #endif
                else if (size == 2)
                        printf(" %04x", *((u16 *)ptr));
@@ -1157,7 +1076,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
 #endif
                else {
                        char *endp;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
                        i = simple_strtoull(console_buffer, &endp, 16);
 #else
                        i = simple_strtoul(console_buffer, &endp, 16);
@@ -1169,7 +1088,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
                                bootretry_reset_cmd_timeout();
                                if (size == 4)
                                        *((u32 *)ptr) = i;
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
                                else if (size == 8)
                                        *((u64 *)ptr) = i;
 #endif
@@ -1203,7 +1122,7 @@ static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        av = argv + 1;
        ac = argc - 1;
-#ifdef CONFIG_HASH_VERIFY
+#ifdef CONFIG_CRC32_VERIFY
        if (strcmp(*av, "-v") == 0) {
                flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
                av++;
@@ -1216,11 +1135,54 @@ static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 #endif
 
+#ifdef CONFIG_CMD_RANDOM
+static int do_random(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       unsigned long addr, len;
+       unsigned long seed; // NOT INITIALIZED ON PURPOSE
+       unsigned int *buf, *start;
+       unsigned char *buf8;
+       unsigned int i;
+
+       if (argc < 3 || argc > 4) {
+               printf("usage: %s <addr> <len> [<seed>]\n", argv[0]);
+               return 0;
+       }
+
+       len = simple_strtoul(argv[2], NULL, 16);
+       addr = simple_strtoul(argv[1], NULL, 16);
+
+       if (argc == 4) {
+               seed = simple_strtoul(argv[3], NULL, 16);
+               if (seed == 0) {
+                       printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
+                       seed = 0xDEADBEEF;
+               }
+       } else {
+               seed = get_timer(0) ^ rand();
+       }
+
+       srand(seed);
+       start = map_sysmem(addr, len);
+       buf = start;
+       for (i = 0; i < (len / 4); i++)
+               *buf++ = rand();
+
+       buf8 = (unsigned char *)buf;
+       for (i = 0; i < (len % 4); i++)
+               *buf8++ = rand() & 0xFF;
+
+       unmap_sysmem(start);
+       printf("%lu bytes filled with random data\n", len);
+       return 1;
+}
+#endif
+
 /**************************************************/
 U_BOOT_CMD(
        md,     3,      1,      do_mem_md,
        "memory display",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] address [# of objects]"
 #else
        "[.b, .w, .l] address [# of objects]"
@@ -1231,7 +1193,7 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        mm,     2,      1,      do_mem_mm,
        "memory modify (auto-incrementing address)",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] address"
 #else
        "[.b, .w, .l] address"
@@ -1242,7 +1204,7 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        nm,     2,      1,      do_mem_nm,
        "memory modify (constant address)",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] address"
 #else
        "[.b, .w, .l] address"
@@ -1252,7 +1214,7 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        mw,     4,      1,      do_mem_mw,
        "memory write (fill)",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] address value [count]"
 #else
        "[.b, .w, .l] address value [count]"
@@ -1262,7 +1224,7 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        cp,     4,      1,      do_mem_cp,
        "memory copy",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] source target count"
 #else
        "[.b, .w, .l] source target count"
@@ -1272,7 +1234,7 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        cmp,    4,      1,      do_mem_cmp,
        "memory compare",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] addr1 addr2 count"
 #else
        "[.b, .w, .l] addr1 addr2 count"
@@ -1281,7 +1243,7 @@ U_BOOT_CMD(
 
 #ifdef CONFIG_CMD_CRC32
 
-#ifndef CONFIG_HASH_VERIFY
+#ifndef CONFIG_CRC32_VERIFY
 
 U_BOOT_CMD(
        crc32,  4,      1,      do_mem_crc,
@@ -1289,7 +1251,7 @@ U_BOOT_CMD(
        "address count [addr]\n    - compute CRC32 checksum [save at addr]"
 );
 
-#else  /* CONFIG_HASH_VERIFY */
+#else  /* CONFIG_CRC32_VERIFY */
 
 U_BOOT_CMD(
        crc32,  5,      1,      do_mem_crc,
@@ -1298,21 +1260,16 @@ U_BOOT_CMD(
        "-v address count crc\n    - verify crc of memory area"
 );
 
-#endif /* CONFIG_HASH_VERIFY */
+#endif /* CONFIG_CRC32_VERIFY */
 
 #endif
 
 #ifdef CONFIG_CMD_MEMINFO
-__weak void board_show_dram(phys_size_t size)
-{
-       puts("DRAM:  ");
-       print_size(size, "\n");
-}
-
 static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
                       char * const argv[])
 {
-       board_show_dram(gd->ram_size);
+       puts("DRAM:  ");
+       print_size(gd->ram_size, "\n");
 
        return 0;
 }
@@ -1328,7 +1285,7 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        loop,   3,      1,      do_mem_loop,
        "infinite loop on address range",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] address number_of_objects"
 #else
        "[.b, .w, .l] address number_of_objects"
@@ -1339,7 +1296,7 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        loopw,  4,      1,      do_mem_loopw,
        "infinite write loop on address range",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] address number_of_objects data_to_write"
 #else
        "[.b, .w, .l] address number_of_objects data_to_write"
@@ -1355,11 +1312,11 @@ U_BOOT_CMD(
 );
 #endif /* CONFIG_CMD_MEMTEST */
 
-#ifdef CONFIG_MX_CYCLIC
+#ifdef CONFIG_CMD_MX_CYCLIC
 U_BOOT_CMD(
        mdc,    4,      1,      do_mem_mdc,
        "memory display cyclic",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] address count delay(ms)"
 #else
        "[.b, .w, .l] address count delay(ms)"
@@ -1369,13 +1326,13 @@ U_BOOT_CMD(
 U_BOOT_CMD(
        mwc,    4,      1,      do_mem_mwc,
        "memory write cyclic",
-#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+#ifdef MEM_SUPPORT_64BIT_DATA
        "[.b, .w, .l, .q] address value delay(ms)"
 #else
        "[.b, .w, .l] address value delay(ms)"
 #endif
 );
-#endif /* CONFIG_MX_CYCLIC */
+#endif /* CONFIG_CMD_MX_CYCLIC */
 
 #ifdef CONFIG_CMD_MEMINFO
 U_BOOT_CMD(
@@ -1384,3 +1341,12 @@ U_BOOT_CMD(
        ""
 );
 #endif
+
+#ifdef CONFIG_CMD_RANDOM
+U_BOOT_CMD(
+       random, 4,      0,      do_random,
+       "fill memory with random pattern",
+       "<addr> <len> [<seed>]\n"
+       "   - Fill 'len' bytes of memory starting at 'addr' with random data\n"
+);
+#endif