#include <dataflash.h>
#endif
#include <watchdog.h>
+#include <linux/compiler.h>
-#ifdef CMD_MEM_DEBUG
-#define PRINTF(fmt,args...) printf (fmt ,##args)
-#else
-#define PRINTF(fmt,args...)
-#endif
+DECLARE_GLOBAL_DATA_PTR;
static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
* md{.b, .w, .l} {addr} {len}
*/
#define DISP_LINE_LEN 16
-int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
ulong addr, length;
#if defined(CONFIG_HAS_DATAFLASH)
length = dp_last_length;
if (argc < 2)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
if ((flag & CMD_FLAG_REPEAT) == 0) {
/* New command specified. Check for a size specification.
return (rc);
}
-int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
return mod_mem (cmdtp, 1, flag, argc, argv);
}
-int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
return mod_mem (cmdtp, 0, flag, argc, argv);
}
-int do_mem_mw ( 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[])
{
ulong addr, writeval, count;
int size;
if ((argc < 3) || (argc > 4))
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
/* Check for size specification.
*/
ulong count;
if (argc < 4)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
count = simple_strtoul(argv[3], NULL, 10);
ulong count;
if (argc < 4)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
count = simple_strtoul(argv[3], NULL, 10);
}
#endif /* CONFIG_MX_CYCLIC */
-int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
ulong addr1, addr2, count, ngood;
int size;
int rcode = 0;
+ const char *type;
if (argc != 4)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
/* Check for size specification.
*/
if ((size = cmd_get_data_size(argv[0], 4)) < 0)
return 1;
+ type = size == 4 ? "word" : size == 2 ? "halfword" : "byte";
addr1 = simple_strtoul(argv[1], NULL, 16);
addr1 += base_address;
}
#endif
- ngood = 0;
-
- while (count-- > 0) {
+ for (ngood = 0; ngood < count; ++ngood) {
+ ulong word1, word2;
if (size == 4) {
- ulong word1 = *(ulong *)addr1;
- ulong word2 = *(ulong *)addr2;
- if (word1 != word2) {
- printf("word at 0x%08lx (0x%08lx) "
- "!= word at 0x%08lx (0x%08lx)\n",
- addr1, word1, addr2, word2);
- rcode = 1;
- break;
- }
+ word1 = *(ulong *)addr1;
+ word2 = *(ulong *)addr2;
+ } else if (size == 2) {
+ word1 = *(ushort *)addr1;
+ word2 = *(ushort *)addr2;
+ } else {
+ word1 = *(u_char *)addr1;
+ word2 = *(u_char *)addr2;
}
- else if (size == 2) {
- ushort hword1 = *(ushort *)addr1;
- ushort hword2 = *(ushort *)addr2;
- if (hword1 != hword2) {
- printf("halfword at 0x%08lx (0x%04x) "
- "!= halfword at 0x%08lx (0x%04x)\n",
- addr1, hword1, addr2, hword2);
- rcode = 1;
- break;
- }
- }
- else {
- u_char byte1 = *(u_char *)addr1;
- u_char byte2 = *(u_char *)addr2;
- if (byte1 != byte2) {
- printf("byte at 0x%08lx (0x%02x) "
- "!= byte at 0x%08lx (0x%02x)\n",
- addr1, byte1, addr2, byte2);
- rcode = 1;
- break;
- }
+ if (word1 != word2) {
+ printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
+ type, addr1, size, word1,
+ type, addr2, size, word2);
+ rcode = 1;
+ break;
}
- ngood++;
+
addr1 += size;
addr2 += size;
/* reset watchdog from time to time */
- if ((count % (64 << 10)) == 0)
+ if ((ngood % (64 << 10)) == 0)
WATCHDOG_RESET();
}
- printf("Total of %ld %s%s were the same\n",
- ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte",
- ngood == 1 ? "" : "s");
+ printf("Total of %ld %s(s) were the same\n", ngood, type);
return rcode;
}
-int do_mem_cp ( 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;
int size;
if (argc != 4)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
/* Check for size specification.
*/
return 0;
}
-int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
{
if (argc > 1) {
/* Set new base address.
return 0;
}
-int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
{
ulong addr, length, i;
int size;
volatile u_char *cp;
if (argc < 3)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
- /* Check for a size spefication.
+ /*
+ * Check for a size specification.
* Defaults to long if no or incorrect specification.
*/
if ((size = cmd_get_data_size(argv[0], 4)) < 0)
volatile u_char *cp;
if (argc < 4)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
- /* Check for a size spefication.
+ /*
+ * Check for a size specification.
* Defaults to long if no or incorrect specification.
*/
if ((size = cmd_get_data_size(argv[0], 4)) < 0)
* 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 * const argv[])
+static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
{
vu_long *addr, *start, *end;
ulong val;
#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
#else
- vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
+ vu_long *dummy = NULL; /* yes, this is address 0x0, not NULL */
#endif
int j;
#if defined(CONFIG_SYS_ALT_MEMTEST)
printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
- PRINTF("%s:%d: start 0x%p end 0x%p\n",
+ debug("%s:%d: start 0x%p end 0x%p\n",
__FUNCTION__, __LINE__, start, end);
for (;;) {
}
printf("Iteration: %6d\r", iterations);
- PRINTF("\n");
+ debug("\n");
iterations++;
/*
* Data line test: write a pattern to the first
* location, write the 1's complement to a 'parking'
* address (changes the state of the data bus so a
- * floating bus doen't give a false OK), and then
+ * floating bus doesn't give a false OK), and then
* read the value back. Note that we read it back
* into a variable because the next time we read it,
* it might be right (been there, tough to explain to
* 1's test on the relevant bits of the
* address and checking for aliasing.
* This test will find single-bit
- * address failures such as stuck -high,
+ * address failures such as stuck-high,
* stuck-low, and shorted pins. The base
* address and size of the region are
* selected by the caller.
pattern = (vu_long) 0xaaaaaaaa;
anti_pattern = (vu_long) 0x55555555;
- PRINTF("%s:%d: length = 0x%.8lx\n",
+ debug("%s:%d: length = 0x%.8lx\n",
__FUNCTION__, __LINE__,
len);
/*
if (readback != val) {
printf ("\nMem error @ 0x%08X: "
"found %08lX, expected %08lX\n",
- (uint)addr, readback, val);
+ (uint)(uintptr_t)addr, readback, val);
errs++;
if (ctrlc()) {
putc ('\n');
{
ulong addr, i;
int nbytes, size;
- extern char console_buffer[];
if (argc != 2)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
#ifdef CONFIG_BOOT_RETRY_TIME
reset_cmd_timeout(); /* got a good command to get here */
#ifndef CONFIG_CRC32_VERIFY
-int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
ulong addr, length;
ulong crc;
ulong *ptr;
if (argc < 3)
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
addr = simple_strtoul (argv[1], NULL, 16);
addr += base_address;
if (argc < 3) {
usage:
- return cmd_usage(cmdtp);
+ return CMD_RET_USAGE;
}
av = argv + 1;
#endif
+#ifdef CONFIG_CMD_MEMINFO
+__weak void board_show_dram(ulong 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);
+
+ return 0;
+}
+#endif
+
U_BOOT_CMD(
base, 2, 1, do_mem_base,
"print or set address offset",
"[.b, .w, .l] address value delay(ms)"
);
#endif /* CONFIG_MX_CYCLIC */
+
+#ifdef CONFIG_CMD_MEMINFO
+U_BOOT_CMD(
+ meminfo, 3, 1, do_mem_info,
+ "display memory information",
+ ""
+);
+#endif