mem.c 29.9 KB
Newer Older
wdenk's avatar
wdenk committed
1 2 3 4
/*
 * (C) Copyright 2000
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
5
 * SPDX-License-Identifier:	GPL-2.0+
wdenk's avatar
wdenk committed
6 7 8 9 10 11 12 13 14
 */

/*
 * Memory Functions
 *
 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
 */

#include <common.h>
15
#include <console.h>
16
#include <bootretry.h>
17
#include <cli.h>
wdenk's avatar
wdenk committed
18
#include <command.h>
19
#include <console.h>
20 21 22
#ifdef CONFIG_HAS_DATAFLASH
#include <dataflash.h>
#endif
23
#include <hash.h>
24
#include <inttypes.h>
25
#include <mapmem.h>
26
#include <watchdog.h>
27
#include <asm/io.h>
28 29 30
#include <linux/compiler.h>

DECLARE_GLOBAL_DATA_PTR;
wdenk's avatar
wdenk committed
31

32 33 34 35
#ifndef CONFIG_SYS_MEMTEST_SCRATCH
#define CONFIG_SYS_MEMTEST_SCRATCH 0
#endif

36
static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk's avatar
wdenk committed
37 38 39 40

/* Display values from last command.
 * Memory modify remembered values are different from display memory.
 */
41 42 43
static ulong	dp_last_addr, dp_last_size;
static ulong	dp_last_length = 0x40;
static ulong	mm_last_addr, mm_last_size;
wdenk's avatar
wdenk committed
44 45 46 47 48 49

static	ulong	base_address = 0;

/* Memory Display
 *
 * Syntax:
50
 *	md{.b, .w, .l, .q} {addr} {len}
wdenk's avatar
wdenk committed
51 52
 */
#define DISP_LINE_LEN	16
53
static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
54
{
55
	ulong	addr, length;
56 57 58
#if defined(CONFIG_HAS_DATAFLASH)
	ulong	nbytes, linebytes;
#endif
59
	int	size;
wdenk's avatar
wdenk committed
60 61 62 63 64 65 66 67 68
	int rc = 0;

	/* We use the last specified parameters, unless new ones are
	 * entered.
	 */
	addr = dp_last_addr;
	size = dp_last_size;
	length = dp_last_length;

69
	if (argc < 2)
70
		return CMD_RET_USAGE;
wdenk's avatar
wdenk committed
71 72 73 74 75

	if ((flag & CMD_FLAG_REPEAT) == 0) {
		/* New command specified.  Check for a size specification.
		 * Defaults to long if no or incorrect specification.
		 */
76 77
		if ((size = cmd_get_data_size(argv[0], 4)) < 0)
			return 1;
wdenk's avatar
wdenk committed
78 79 80 81 82 83 84 85 86 87 88 89 90

		/* Address is specified since argc > 1
		*/
		addr = simple_strtoul(argv[1], NULL, 16);
		addr += base_address;

		/* If another parameter, it is the length to display.
		 * Length is the number of objects, not number of bytes.
		 */
		if (argc > 2)
			length = simple_strtoul(argv[2], NULL, 16);
	}

91
#if defined(CONFIG_HAS_DATAFLASH)
wdenk's avatar
wdenk committed
92 93 94 95 96 97 98 99
	/* 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];
100
		void* p;
wdenk's avatar
wdenk committed
101
		linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
102

103 104 105 106
		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);

wdenk's avatar
wdenk committed
107
		nbytes -= linebytes;
108
		addr += linebytes;
wdenk's avatar
wdenk committed
109 110 111 112 113
		if (ctrlc()) {
			rc = 1;
			break;
		}
	} while (nbytes > 0);
114
#else
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

# 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

	{
137 138 139
		ulong bytes = size * length;
		const void *buf = map_sysmem(addr, bytes);

140
		/* Print the lines. */
141 142 143
		print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
		addr += bytes;
		unmap_sysmem(buf);
144
	}
145
#endif
wdenk's avatar
wdenk committed
146 147 148 149 150 151 152

	dp_last_addr = addr;
	dp_last_length = length;
	dp_last_size = size;
	return (rc);
}

153
static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
154 155 156
{
	return mod_mem (cmdtp, 1, flag, argc, argv);
}
157
static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
158 159 160 161
{
	return mod_mem (cmdtp, 0, flag, argc, argv);
}

162
static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
163
{
164 165 166 167 168 169
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	u64 writeval;
#else
	ulong writeval;
#endif
	ulong	addr, count;
170
	int	size;
171
	void *buf, *start;
172
	ulong bytes;
wdenk's avatar
wdenk committed
173

174
	if ((argc < 3) || (argc > 4))
175
		return CMD_RET_USAGE;
wdenk's avatar
wdenk committed
176 177 178

	/* Check for size specification.
	*/
179 180
	if ((size = cmd_get_data_size(argv[0], 4)) < 1)
		return 1;
wdenk's avatar
wdenk committed
181 182 183 184 185 186 187 188

	/* Address is specified since argc > 1
	*/
	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	/* Get the value to write.
	*/
189 190 191
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	writeval = simple_strtoull(argv[2], NULL, 16);
#else
wdenk's avatar
wdenk committed
192
	writeval = simple_strtoul(argv[2], NULL, 16);
193
#endif
wdenk's avatar
wdenk committed
194 195 196 197 198 199 200 201

	/* Count ? */
	if (argc == 4) {
		count = simple_strtoul(argv[3], NULL, 16);
	} else {
		count = 1;
	}

202
	bytes = size * count;
203 204
	start = map_sysmem(addr, bytes);
	buf = start;
wdenk's avatar
wdenk committed
205 206
	while (count-- > 0) {
		if (size == 4)
207
			*((u32 *)buf) = (u32)writeval;
208 209 210 211
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
		else if (size == 8)
			*((u64 *)buf) = (u64)writeval;
#endif
wdenk's avatar
wdenk committed
212
		else if (size == 2)
213
			*((u16 *)buf) = (u16)writeval;
wdenk's avatar
wdenk committed
214
		else
215
			*((u8 *)buf) = (u8)writeval;
216
		buf += size;
wdenk's avatar
wdenk committed
217
	}
218
	unmap_sysmem(start);
wdenk's avatar
wdenk committed
219 220 221
	return 0;
}

222
#ifdef CONFIG_MX_CYCLIC
223
static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
224 225 226 227
{
	int i;
	ulong count;

228
	if (argc < 4)
229
		return CMD_RET_USAGE;
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249

	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;
}

250
static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
251 252 253 254
{
	int i;
	ulong count;

255
	if (argc < 4)
256
		return CMD_RET_USAGE;
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277

	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 */

278
static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
279
{
280
	ulong	addr1, addr2, count, ngood, bytes;
281
	int	size;
wdenk's avatar
wdenk committed
282
	int     rcode = 0;
283
	const char *type;
284
	const void *buf1, *buf2, *base;
285 286 287 288 289
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	u64 word1, word2;
#else
	ulong word1, word2;
#endif
wdenk's avatar
wdenk committed
290

291
	if (argc != 4)
292
		return CMD_RET_USAGE;
wdenk's avatar
wdenk committed
293 294 295

	/* Check for size specification.
	*/
296 297
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;
298 299 300
	type = size == 8 ? "double word" :
	       size == 4 ? "word" :
	       size == 2 ? "halfword" : "byte";
wdenk's avatar
wdenk committed
301 302 303 304 305 306 307 308 309

	addr1 = simple_strtoul(argv[1], NULL, 16);
	addr1 += base_address;

	addr2 = simple_strtoul(argv[2], NULL, 16);
	addr2 += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

310 311
#ifdef CONFIG_HAS_DATAFLASH
	if (addr_dataflash(addr1) | addr_dataflash(addr2)){
312
		puts ("Comparison with DataFlash space not supported.\n\r");
313 314 315 316
		return 0;
	}
#endif

317 318 319 320 321 322 323
#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

324 325 326
	bytes = size * count;
	base = buf1 = map_sysmem(addr1, bytes);
	buf2 = map_sysmem(addr2, bytes);
327
	for (ngood = 0; ngood < count; ++ngood) {
wdenk's avatar
wdenk committed
328
		if (size == 4) {
329 330
			word1 = *(u32 *)buf1;
			word2 = *(u32 *)buf2;
331 332 333 334 335
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
		} else if (size == 8) {
			word1 = *(u64 *)buf1;
			word2 = *(u64 *)buf2;
#endif
336
		} else if (size == 2) {
337 338
			word1 = *(u16 *)buf1;
			word2 = *(u16 *)buf2;
339
		} else {
340 341
			word1 = *(u8 *)buf1;
			word2 = *(u8 *)buf2;
wdenk's avatar
wdenk committed
342
		}
343
		if (word1 != word2) {
344
			ulong offset = buf1 - base;
345
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
346 347
			printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
			       PRIx64 ")\n",
348 349 350
			       type, (void *)(addr1 + offset), size, word1,
			       type, (void *)(addr2 + offset), size, word2);
#else
351
			printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
352 353
				type, (ulong)(addr1 + offset), size, word1,
				type, (ulong)(addr2 + offset), size, word2);
354
#endif
355 356
			rcode = 1;
			break;
wdenk's avatar
wdenk committed
357
		}
358

359 360
		buf1 += size;
		buf2 += size;
361 362

		/* reset watchdog from time to time */
363
		if ((ngood % (64 << 10)) == 0)
364
			WATCHDOG_RESET();
wdenk's avatar
wdenk committed
365
	}
366 367
	unmap_sysmem(buf1);
	unmap_sysmem(buf2);
wdenk's avatar
wdenk committed
368

369
	printf("Total of %ld %s(s) were the same\n", ngood, type);
wdenk's avatar
wdenk committed
370 371 372
	return rcode;
}

373
static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
374
{
375
	ulong	addr, dest, count, bytes;
376
	int	size;
377 378
	const void *src;
	void *buf;
wdenk's avatar
wdenk committed
379

380
	if (argc != 4)
381
		return CMD_RET_USAGE;
wdenk's avatar
wdenk committed
382 383 384

	/* Check for size specification.
	*/
385 386
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;
wdenk's avatar
wdenk committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400

	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	dest = simple_strtoul(argv[2], NULL, 16);
	dest += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

	if (count == 0) {
		puts ("Zero length ???\n");
		return 1;
	}

401
#ifndef CONFIG_SYS_NO_FLASH
wdenk's avatar
wdenk committed
402
	/* check if we are copying to Flash */
403 404
	if ( (addr2info(dest) != NULL)
#ifdef CONFIG_HAS_DATAFLASH
405
	   && (!addr_dataflash(dest))
406 407
#endif
	   ) {
wdenk's avatar
wdenk committed
408 409
		int rc;

410
		puts ("Copy to Flash... ");
wdenk's avatar
wdenk committed
411

Wolfgang Denk's avatar
Wolfgang Denk committed
412
		rc = flash_write ((char *)addr, dest, count*size);
wdenk's avatar
wdenk committed
413 414 415 416 417 418 419 420 421
		if (rc != 0) {
			flash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}
#endif

422 423 424 425 426
#ifdef CONFIG_HAS_DATAFLASH
	/* Check if we are copying from RAM or Flash to DataFlash */
	if (addr_dataflash(dest) && !addr_dataflash(addr)){
		int rc;

427
		puts ("Copy to DataFlash... ");
428 429 430 431 432 433 434 435 436 437

		rc = write_dataflash (dest, addr, count*size);

		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}
wdenk's avatar
wdenk committed
438

439
	/* Check if we are copying from DataFlash to RAM */
440
	if (addr_dataflash(addr) && !addr_dataflash(dest)
441
#ifndef CONFIG_SYS_NO_FLASH
442 443 444
				 && (addr2info(dest) == NULL)
#endif
	   ){
445 446 447
		int rc;
		rc = read_dataflash(addr, count * size, (char *) dest);
		if (rc != 1) {
448 449 450
			dataflash_perror (rc);
			return (1);
		}
451 452 453 454
		return 0;
	}

	if (addr_dataflash(addr) && addr_dataflash(dest)){
455
		puts ("Unsupported combination of source/destination.\n\r");
456 457 458 459
		return 1;
	}
#endif

460 461 462 463 464 465 466 467
#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

468
	bytes = size * count;
469
	buf = map_sysmem(dest, bytes);
470
	src = map_sysmem(addr, bytes);
wdenk's avatar
wdenk committed
471 472
	while (count-- > 0) {
		if (size == 4)
473
			*((u32 *)buf) = *((u32  *)src);
474 475 476 477
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
		else if (size == 8)
			*((u64 *)buf) = *((u64 *)src);
#endif
wdenk's avatar
wdenk committed
478
		else if (size == 2)
479
			*((u16 *)buf) = *((u16 *)src);
wdenk's avatar
wdenk committed
480
		else
481
			*((u8 *)buf) = *((u8 *)src);
482 483
		src += size;
		buf += size;
484 485 486 487

		/* reset watchdog from time to time */
		if ((count % (64 << 10)) == 0)
			WATCHDOG_RESET();
wdenk's avatar
wdenk committed
488
	}
489 490 491
	unmap_sysmem(buf);
	unmap_sysmem(src);

wdenk's avatar
wdenk committed
492 493 494
	return 0;
}

495 496
static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
		       char * const argv[])
wdenk's avatar
wdenk committed
497 498 499 500 501 502 503 504 505 506 507 508
{
	if (argc > 1) {
		/* Set new base address.
		*/
		base_address = simple_strtoul(argv[1], NULL, 16);
	}
	/* Print the current base address.
	*/
	printf("Base Address: 0x%08lx\n", base_address);
	return 0;
}

509 510
static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
		       char * const argv[])
wdenk's avatar
wdenk committed
511
{
512
	ulong	addr, length, i, bytes;
513
	int	size;
514 515 516
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	volatile u64 *llp;
#endif
517 518 519
	volatile u32 *longp;
	volatile u16 *shortp;
	volatile u8 *cp;
520
	const void *buf;
wdenk's avatar
wdenk committed
521

522
	if (argc < 3)
523
		return CMD_RET_USAGE;
wdenk's avatar
wdenk committed
524

525 526
	/*
	 * Check for a size specification.
wdenk's avatar
wdenk committed
527 528
	 * Defaults to long if no or incorrect specification.
	 */
529 530
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;
wdenk's avatar
wdenk committed
531 532 533 534 535 536 537 538 539

	/* 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);

540 541 542
	bytes = size * length;
	buf = map_sysmem(addr, bytes);

wdenk's avatar
wdenk committed
543 544 545 546
	/* 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) {
547 548 549 550 551 552 553
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
		if (size == 8) {
			llp = (u64 *)buf;
			for (;;)
				i = *llp;
		}
#endif
wdenk's avatar
wdenk committed
554
		if (size == 4) {
555
			longp = (u32 *)buf;
wdenk's avatar
wdenk committed
556 557 558 559
			for (;;)
				i = *longp;
		}
		if (size == 2) {
560
			shortp = (u16 *)buf;
wdenk's avatar
wdenk committed
561 562 563
			for (;;)
				i = *shortp;
		}
564
		cp = (u8 *)buf;
wdenk's avatar
wdenk committed
565 566 567 568
		for (;;)
			i = *cp;
	}

569 570 571 572 573 574 575 576 577 578
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	if (size == 8) {
		for (;;) {
			llp = (u64 *)buf;
			i = length;
			while (i-- > 0)
				*llp++;
		}
	}
#endif
wdenk's avatar
wdenk committed
579 580
	if (size == 4) {
		for (;;) {
581
			longp = (u32 *)buf;
wdenk's avatar
wdenk committed
582 583
			i = length;
			while (i-- > 0)
584
				*longp++;
wdenk's avatar
wdenk committed
585 586 587 588
		}
	}
	if (size == 2) {
		for (;;) {
589
			shortp = (u16 *)buf;
wdenk's avatar
wdenk committed
590 591
			i = length;
			while (i-- > 0)
592
				*shortp++;
wdenk's avatar
wdenk committed
593 594 595
		}
	}
	for (;;) {
596
		cp = (u8 *)buf;
wdenk's avatar
wdenk committed
597 598
		i = length;
		while (i-- > 0)
599
			*cp++;
wdenk's avatar
wdenk committed
600
	}
601
	unmap_sysmem(buf);
602 603

	return 0;
wdenk's avatar
wdenk committed
604 605
}

606
#ifdef CONFIG_LOOPW
607 608
static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
			char * const argv[])
609
{
610
	ulong	addr, length, i, bytes;
611
	int	size;
612 613 614 615 616 617
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	volatile u64 *llp;
	u64 data;
#else
	ulong	data;
#endif
618 619 620
	volatile u32 *longp;
	volatile u16 *shortp;
	volatile u8 *cp;
621
	void *buf;
wdenk's avatar
wdenk committed
622

623
	if (argc < 4)
624
		return CMD_RET_USAGE;
625

626 627
	/*
	 * Check for a size specification.
628 629 630 631 632 633 634 635 636 637 638 639 640 641
	 * 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 */
642 643 644
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	data = simple_strtoull(argv[3], NULL, 16);
#else
645
	data = simple_strtoul(argv[3], NULL, 16);
646
#endif
wdenk's avatar
wdenk committed
647

648 649 650
	bytes = size * length;
	buf = map_sysmem(addr, bytes);

651 652 653 654
	/* 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) {
655 656 657 658 659 660 661
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
		if (size == 8) {
			llp = (u64 *)buf;
			for (;;)
				*llp = data;
		}
#endif
662
		if (size == 4) {
663
			longp = (u32 *)buf;
664 665
			for (;;)
				*longp = data;
666
		}
667
		if (size == 2) {
668
			shortp = (u16 *)buf;
669 670 671
			for (;;)
				*shortp = data;
		}
672
		cp = (u8 *)buf;
673 674 675 676
		for (;;)
			*cp = data;
	}

677 678 679 680 681 682 683 684 685 686
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	if (size == 8) {
		for (;;) {
			llp = (u64 *)buf;
			i = length;
			while (i-- > 0)
				*llp++ = data;
		}
	}
#endif
687 688
	if (size == 4) {
		for (;;) {
689
			longp = (u32 *)buf;
690 691 692 693 694 695 696
			i = length;
			while (i-- > 0)
				*longp++ = data;
		}
	}
	if (size == 2) {
		for (;;) {
697
			shortp = (u16 *)buf;
698 699 700 701 702 703
			i = length;
			while (i-- > 0)
				*shortp++ = data;
		}
	}
	for (;;) {
704
		cp = (u8 *)buf;
705 706 707 708 709 710 711
		i = length;
		while (i-- > 0)
			*cp++ = data;
	}
}
#endif /* CONFIG_LOOPW */

712
#ifdef CONFIG_CMD_MEMTEST
713 714
static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
			  vu_long *dummy)
wdenk's avatar
wdenk committed
715
{
716 717 718 719 720 721 722 723 724 725
	vu_long *addr;
	ulong errs = 0;
	ulong val, readback;
	int j;
	vu_long offset;
	vu_long test_offset;
	vu_long pattern;
	vu_long temp;
	vu_long anti_pattern;
	vu_long num_words;
wdenk's avatar
wdenk committed
726 727 728 729 730 731 732 733 734 735 736
	static const ulong bitpattern[] = {
		0x00000001,	/* single bit */
		0x00000003,	/* two adjacent bits */
		0x00000007,	/* three adjacent bits */
		0x0000000F,	/* four adjacent bits */
		0x00000005,	/* two non-adjacent bits */
		0x00000015,	/* three non-adjacent bits */
		0x00000055,	/* four non-adjacent bits */
		0xaaaaaaaa,	/* alternating 1/0 */
	};

737
	num_words = (end_addr - start_addr) / sizeof(vu_long);
Simon Glass's avatar
Simon Glass committed
738

Simon Glass's avatar
Simon Glass committed
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
	/*
	 * 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 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
	 * the quality guys why it prints a failure when the
	 * "is" and "should be" are obviously the same in the
	 * error message).
	 *
	 * Rather than exhaustively testing, we test some
	 * patterns by shifting '1' bits through a field of
	 * '0's and '0' bits through a field of '1's (i.e.
	 * pattern and ~pattern).
	 */
756
	addr = buf;
Simon Glass's avatar
Simon Glass committed
757 758 759
	for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
		val = bitpattern[j];
		for (; val != 0; val <<= 1) {
760
			*addr = val;
761
			*dummy  = ~val; /* clear the test data off the bus */
wdenk's avatar
wdenk committed
762
			readback = *addr;
Simon Glass's avatar
Simon Glass committed
763
			if (readback != val) {
764 765 766 767
				printf("FAILURE (data line): "
					"expected %08lx, actual %08lx\n",
						val, readback);
				errs++;
768
				if (ctrlc())
769
					return -1;
wdenk's avatar
wdenk committed
770 771 772 773
			}
			*addr  = ~val;
			*dummy  = val;
			readback = *addr;
774 775 776 777 778
			if (readback != ~val) {
				printf("FAILURE (data line): "
					"Is %08lx, should be %08lx\n",
						readback, ~val);
				errs++;
779
				if (ctrlc())
780
					return -1;
wdenk's avatar
wdenk committed
781 782
			}
		}
Simon Glass's avatar
Simon Glass committed
783
	}
wdenk's avatar
wdenk committed
784

Simon Glass's avatar
Simon Glass committed
785 786 787 788 789 790 791 792 793
	/*
	 * Based on code whose Original Author and Copyright
	 * information follows: Copyright (c) 1998 by Michael
	 * Barr. This software is placed into the public
	 * domain and may be used for any purpose. However,
	 * this notice must not be changed or removed and no
	 * warranty is either expressed or implied by its
	 * publication or distribution.
	 */
wdenk's avatar
wdenk committed
794

Simon Glass's avatar
Simon Glass committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
	/*
	* Address line test

	 * Description: Test the address bus wiring in a
	 *              memory region by performing a walking
	 *              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,
	 *              stuck-low, and shorted pins. The base
	 *              address and size of the region are
	 *              selected by the caller.

	 * Notes:	For best results, the selected base
	 *              address should have enough LSB 0's to
	 *              guarantee single address bit changes.
	 *              For example, to test a 64-Kbyte
	 *              region, select a base address on a
	 *              64-Kbyte boundary. Also, select the
	 *              region size as a power-of-two if at
	 *              all possible.
	 *
	 * Returns:     0 if the test succeeds, 1 if the test fails.
	 */
	pattern = (vu_long) 0xaaaaaaaa;
	anti_pattern = (vu_long) 0x55555555;
wdenk's avatar
wdenk committed
821

822
	debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
Simon Glass's avatar
Simon Glass committed
823 824 825 826
	/*
	 * Write the default pattern at each of the
	 * power-of-two offsets.
	 */
827 828
	for (offset = 1; offset < num_words; offset <<= 1)
		addr[offset] = pattern;
wdenk's avatar
wdenk committed
829

Simon Glass's avatar
Simon Glass committed
830 831 832 833
	/*
	 * Check for address bits stuck high.
	 */
	test_offset = 0;
834
	addr[test_offset] = anti_pattern;
wdenk's avatar
wdenk committed
835

836 837
	for (offset = 1; offset < num_words; offset <<= 1) {
		temp = addr[offset];
Simon Glass's avatar
Simon Glass committed
838
		if (temp != pattern) {
839
			printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
wdenk's avatar
wdenk committed
840
				" expected 0x%.8lx, actual 0x%.8lx\n",
841 842
				start_addr + offset*sizeof(vu_long),
				pattern, temp);
843
			errs++;
844
			if (ctrlc())
Simon Glass's avatar
Simon Glass committed
845
				return -1;
wdenk's avatar
wdenk committed
846
		}
Simon Glass's avatar
Simon Glass committed
847
	}
848
	addr[test_offset] = pattern;
Simon Glass's avatar
Simon Glass committed
849
	WATCHDOG_RESET();
wdenk's avatar
wdenk committed
850

Simon Glass's avatar
Simon Glass committed
851 852 853
	/*
	 * Check for addr bits stuck low or shorted.
	 */
854 855
	for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
		addr[test_offset] = anti_pattern;
wdenk's avatar
wdenk committed
856

857 858
		for (offset = 1; offset < num_words; offset <<= 1) {
			temp = addr[offset];
wdenk's avatar
wdenk committed
859
			if ((temp != pattern) && (offset != test_offset)) {
Simon Glass's avatar
Simon Glass committed
860 861 862
				printf("\nFAILURE: Address bit stuck low or"
					" shorted @ 0x%.8lx: expected 0x%.8lx,"
					" actual 0x%.8lx\n",
863 864
					start_addr + offset*sizeof(vu_long),
					pattern, temp);
Simon Glass's avatar
Simon Glass committed
865
				errs++;
866
				if (ctrlc())
Simon Glass's avatar
Simon Glass committed
867
					return -1;
wdenk's avatar
wdenk committed
868 869
			}
		}
870
		addr[test_offset] = pattern;
Simon Glass's avatar
Simon Glass committed
871
	}
wdenk's avatar
wdenk committed
872

Simon Glass's avatar
Simon Glass committed
873 874 875 876 877 878 879 880 881 882 883 884
	/*
	 * Description: Test the integrity of a physical
	 *		memory device by performing an
	 *		increment/decrement test over the
	 *		entire region. In the process every
	 *		storage bit in the device is tested
	 *		as a zero and a one. The base address
	 *		and the size of the region are
	 *		selected by the caller.
	 *
	 * Returns:     0 if the test succeeds, 1 if the test fails.
	 */
885
	num_words++;
wdenk's avatar
wdenk committed
886

Simon Glass's avatar
Simon Glass committed
887 888 889 890 891
	/*
	 * Fill memory with a known pattern.
	 */
	for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
		WATCHDOG_RESET();
892
		addr[offset] = pattern;
Simon Glass's avatar
Simon Glass committed
893
	}
wdenk's avatar
wdenk committed
894

Simon Glass's avatar
Simon Glass committed
895 896 897 898 899
	/*
	 * Check each location and invert it for the second pass.
	 */
	for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
		WATCHDOG_RESET();
900
		temp = addr[offset];
Simon Glass's avatar
Simon Glass committed
901
		if (temp != pattern) {
902
			printf("\nFAILURE (read/write) @ 0x%.8lx:"
wdenk's avatar
wdenk committed
903
				" expected 0x%.8lx, actual 0x%.8lx)\n",
904 905
				start_addr + offset*sizeof(vu_long),
				pattern, temp);
906
			errs++;
907
			if (ctrlc())
908
				return -1;
wdenk's avatar
wdenk committed
909 910
		}

Simon Glass's avatar
Simon Glass committed
911
		anti_pattern = ~pattern;
912
		addr[offset] = anti_pattern;
Simon Glass's avatar
Simon Glass committed
913 914 915 916 917 918 919 920
	}

	/*
	 * Check each location for the inverted pattern and zero it.
	 */
	for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
		WATCHDOG_RESET();
		anti_pattern = ~pattern;
921
		temp = addr[offset];
Simon Glass's avatar
Simon Glass committed
922
		if (temp != anti_pattern) {
923
			printf("\nFAILURE (read/write): @ 0x%.8lx:"
wdenk's avatar
wdenk committed
924
				" expected 0x%.8lx, actual 0x%.8lx)\n",
925 926
				start_addr + offset*sizeof(vu_long),
				anti_pattern, temp);
927
			errs++;
928
			if (ctrlc())
929
				return -1;
wdenk's avatar
wdenk committed
930
		}
931
		addr[offset] = 0;
Simon Glass's avatar
Simon Glass committed
932
	}
933

934
	return errs;
935 936
}

937 938
static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
			    vu_long pattern, int iteration)
939
{
940
	vu_long *end;
941 942
	vu_long *addr;
	ulong errs = 0;
943
	ulong incr, length;
944
	ulong val, readback;
wdenk's avatar
wdenk committed
945

946
	/* Alternate the pattern */
wdenk's avatar
wdenk committed
947
	incr = 1;
948 949 950 951 952 953 954 955 956 957 958 959 960
	if (iteration & 1) {
		incr = -incr;
		/*
		 * Flip the pattern each time to make lots of zeros and
		 * then, the next time, lots of ones.  We decrement
		 * the "negative" patterns and increment the "positive"
		 * patterns to preserve this feature.
		 */
		if (pattern & 0x80000000)
			pattern = -pattern;	/* complement & increment */
		else
			pattern = ~pattern;
	}
961 962
	length = (end_addr - start_addr) / sizeof(ulong);
	end = buf + length;
Simon Glass's avatar
Simon Glass committed
963 964 965 966
	printf("\rPattern %08lX  Writing..."
		"%12s"
		"\b\b\b\b\b\b\b\b\b\b",
		pattern, "");
wdenk's avatar
wdenk committed
967

968
	for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass's avatar
Simon Glass committed
969 970 971 972
		WATCHDOG_RESET();
		*addr = val;
		val += incr;
	}
wdenk's avatar
wdenk committed
973

Simon Glass's avatar
Simon Glass committed
974
	puts("Reading...");
wdenk's avatar
wdenk committed
975

976
	for (addr = buf, val = pattern; addr < end; addr++) {
Simon Glass's avatar
Simon Glass committed
977 978 979
		WATCHDOG_RESET();
		readback = *addr;
		if (readback != val) {
980 981
			ulong offset = addr - buf;

Simon Glass's avatar
Simon Glass committed
982 983
			printf("\nMem error @ 0x%08X: "
				"found %08lX, expected %08lX\n",
984
				(uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
985
				readback, val);
Simon Glass's avatar
Simon Glass committed
986
			errs++;
987
			if (ctrlc())
Simon Glass's avatar
Simon Glass committed
988
				return -1;
wdenk's avatar
wdenk committed
989
		}
Simon Glass's avatar
Simon Glass committed
990 991
		val += incr;
	}
wdenk's avatar
wdenk committed
992

993
	return errs;
994 995 996 997 998 999 1000 1001 1002 1003
}

/*
 * Perform a memory test. A more complete alternative test can be
 * 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.
 */
static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
			char * const argv[])
{
Simon Glass's avatar
Simon Glass committed
1004
	ulong start, end;
1005
	vu_long *buf, *dummy;
1006
	ulong iteration_limit = 0;
1007
	int ret;
1008
	ulong errs = 0;	/* number of errors, or -1 if interrupted */
1009
	ulong pattern = 0;
1010
	int iteration;
1011 1012 1013 1014
#if defined(CONFIG_SYS_ALT_MEMTEST)
	const int alt_test = 1;
#else
	const int alt_test = 0;
wdenk's avatar
wdenk committed
1015
#endif
1016

1017 1018 1019
	start = CONFIG_SYS_MEMTEST_START;
	end = CONFIG_SYS_MEMTEST_END;

1020
	if (argc > 1)
1021 1022
		if (strict_strtoul(argv[1], 16, &start) < 0)
			return CMD_RET_USAGE;
1023 1024

	if (argc > 2)
1025 1026
		if (strict_strtoul(argv[2], 16, &end) < 0)
			return CMD_RET_USAGE;
1027 1028

	if (argc > 3)
1029 1030
		if (strict_strtoul(argv[3], 16, &pattern) < 0)
			return CMD_RET_USAGE;
1031 1032

	if (argc > 4)
1033 1034 1035 1036 1037 1038 1039
		if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
			return CMD_RET_USAGE;

	if (end < start) {
		printf("Refusing to do empty test\n");
		return -1;
	}
1040

1041
	printf("Testing %08lx ... %08lx:\n", start, end);
Simon Glass's avatar
Simon Glass committed
1042 1043
	debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
	      start, end);
1044

1045 1046
	buf = map_sysmem(start, end - start);
	dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
	for (iteration = 0;
			!iteration_limit || iteration < iteration_limit;
			iteration++) {
		if (ctrlc()) {
			errs = -1UL;
			break;
		}

		printf("Iteration: %6d\r", iteration + 1);
		debug("\n");
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
		if (alt_test) {
			errs = mem_test_alt(buf, start, end, dummy);
		} else {
			errs = mem_test_quick(buf, start, end, pattern,
					      iteration);
		}
		if (errs == -1UL)
			break;
	}

	/*
	 * 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);
1078 1079 1080
	}

	if (errs == -1UL) {
1081 1082
		/* Memory test was aborted - write a newline to finish off */
		putc('\n');
1083 1084 1085 1086 1087 1088
		ret = 1;
	} else {
		printf("Tested %d iteration(s) with %lu errors.\n",
			iteration, errs);
		ret = errs != 0;
	}
1089

1090
	return ret;
wdenk's avatar
wdenk committed
1091
}
1092
#endif	/* CONFIG_CMD_MEMTEST */
wdenk's avatar
wdenk committed
1093 1094 1095 1096

/* Modify memory.
 *
 * Syntax:
1097 1098
 *	mm{.b, .w, .l, .q} {addr}
 *	nm{.b, .w, .l, .q} {addr}
wdenk's avatar
wdenk committed
1099 1100
 */
static int
1101
mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
1102
{
1103 1104 1105 1106 1107 1108
	ulong	addr;
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	u64 i;
#else
	ulong i;
#endif
1109
	int	nbytes, size;
1110
	void *ptr = NULL;
wdenk's avatar
wdenk committed
1111

1112
	if (argc != 2)
1113
		return CMD_RET_USAGE;
wdenk's avatar
wdenk committed
1114

1115
	bootretry_reset_cmd_timeout();	/* got a good command to get here */
wdenk's avatar
wdenk committed
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
	/* We use the last specified parameters, unless new ones are
	 * entered.
	 */
	addr = mm_last_addr;
	size = mm_last_size;

	if ((flag & CMD_FLAG_REPEAT) == 0) {
		/* New command specified.  Check for a size specification.
		 * Defaults to long if no or incorrect specification.
		 */
1126 1127
		if ((size = cmd_get_data_size(argv[0], 4)) < 0)
			return 1;
wdenk's avatar
wdenk committed
1128 1129 1130 1131 1132 1133 1134

		/* Address is specified since argc > 1
		*/
		addr = simple_strtoul(argv[1], NULL, 16);
		addr += base_address;
	}

1135 1136
#ifdef CONFIG_HAS_DATAFLASH
	if (addr_dataflash(addr)){
1137
		puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
1138 1139 1140 1141
		return 0;
	}
#endif

1142 1143 1144 1145 1146 1147 1148
#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

wdenk's avatar
wdenk committed
1149 1150 1151 1152
	/* Print the address, followed by value.  Then accept input for
	 * the next value.  A non-converted value exits.
	 */
	do {
1153
		ptr = map_sysmem(addr, size);
wdenk's avatar
wdenk committed
1154 1155
		printf("%08lx:", addr);
		if (size == 4)
1156
			printf(" %08x", *((u32 *)ptr));
1157 1158
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
		else if (size == 8)
1159
			printf(" %016" PRIx64, *((u64 *)ptr));
1160
#endif
wdenk's avatar
wdenk committed
1161
		else if (size == 2)
1162
			printf(" %04x", *((u16 *)ptr));
wdenk's avatar
wdenk committed
1163
		else
1164
			printf(" %02x", *((u8 *)ptr));
wdenk's avatar
wdenk committed
1165

1166
		nbytes = cli_readline(" ? ");
wdenk's avatar
wdenk committed
1167 1168 1169 1170 1171 1172 1173
		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.
			 */
			if (incrflag)
				addr += nbytes ? -size : size;
			nbytes = 1;
1174 1175
			/* good enough to not time out */
			bootretry_reset_cmd_timeout();
wdenk's avatar
wdenk committed
1176 1177 1178 1179 1180 1181 1182 1183
		}
#ifdef CONFIG_BOOT_RETRY_TIME
		else if (nbytes == -2) {
			break;	/* timed out, exit the command	*/
		}
#endif
		else {
			char *endp;
1184 1185 1186
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
			i = simple_strtoull(console_buffer, &endp, 16);
#else
wdenk's avatar
wdenk committed
1187
			i = simple_strtoul(console_buffer, &endp, 16);
1188
#endif
wdenk's avatar
wdenk committed
1189 1190 1191 1192
			nbytes = endp - console_buffer;
			if (nbytes) {
				/* good enough to not time out
				 */
1193
				bootretry_reset_cmd_timeout();
wdenk's avatar
wdenk committed
1194
				if (size == 4)
1195
					*((u32 *)ptr) = i;
1196 1197 1198 1199
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
				else if (size == 8)
					*((u64 *)ptr) = i;
#endif
wdenk's avatar
wdenk committed
1200
				else if (size == 2)
1201
					*((u16 *)ptr) = i;
wdenk's avatar
wdenk committed
1202
				else
1203
					*((u8 *)ptr) = i;
wdenk's avatar
wdenk committed
1204 1205 1206 1207 1208
				if (incrflag)
					addr += size;
			}
		}
	} while (nbytes);
1209 1210
	if (ptr)
		unmap_sysmem(ptr);
wdenk's avatar
wdenk committed
1211 1212 1213 1214 1215 1216

	mm_last_addr = addr;
	mm_last_size = size;
	return 0;
}

1217 1218
#ifdef CONFIG_CMD_CRC32

1219
static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk's avatar
wdenk committed
1220
{
1221
	int flags = 0;
1222
	int ac;
1223
	char * const *av;
1224

1225
	if (argc < 3)
1226
		return CMD_RET_USAGE;
1227 1228 1229

	av = argv + 1;
	ac = argc - 1;
1230
#ifdef CONFIG_HASH_VERIFY
1231
	if (strcmp(*av, "-v") == 0) {
1232
		flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
1233 1234 1235
		av++;
		ac--;
	}
1236
#endif
1237

1238
	return hash_command("crc32", flags, cmdtp, flag, ac, av);
1239 1240
}

1241 1242
#endif

wdenk's avatar
wdenk committed
1243
/**************************************************/
1244
U_BOOT_CMD(
Wolfgang Denk's avatar
Wolfgang Denk committed
1245
	md,	3,	1,	do_mem_md,
Peter Tyser's avatar
Peter Tyser committed
1246
	"memory display",
1247 1248 1249
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	"[.b, .w, .l, .q] address [# of objects]"
#else
1250
	"[.b, .w, .l] address [# of objects]"
1251
#endif
wdenk's avatar
wdenk committed
1252 1253 1254
);


1255
U_BOOT_CMD(
Wolfgang Denk's avatar
Wolfgang Denk committed
1256
	mm,	2,	1,	do_mem_mm,
1257
	"memory modify (auto-incrementing address)",
1258 1259 1260
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	"[.b, .w, .l, .q] address"
#else
1261
	"[.b, .w, .l] address"
1262
#endif
wdenk's avatar
wdenk committed
1263 1264 1265
);


1266
U_BOOT_CMD(
Wolfgang Denk's avatar
Wolfgang Denk committed
1267
	nm,	2,	1,	do_mem_nm,
Peter Tyser's avatar
Peter Tyser committed
1268
	"memory modify (constant address)",
1269 1270 1271
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	"[.b, .w, .l, .q] address"
#else
1272
	"[.b, .w, .l] address"
1273
#endif
wdenk's avatar
wdenk committed
1274 1275
);

1276
U_BOOT_CMD(
Wolfgang Denk's avatar
Wolfgang Denk committed
1277
	mw,	4,	1,	do_mem_mw,
Peter Tyser's avatar
Peter Tyser committed
1278
	"memory write (fill)",
1279 1280 1281
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	"[.b, .w, .l, .q] address value [count]"
#else
1282
	"[.b, .w, .l] address value [count]"
1283
#endif
wdenk's avatar
wdenk committed
1284 1285
);

1286
U_BOOT_CMD(
Wolfgang Denk's avatar
Wolfgang Denk committed
1287
	cp,	4,	1,	do_mem_cp,
Peter Tyser's avatar
Peter Tyser committed
1288
	"memory copy",
1289 1290 1291
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	"[.b, .w, .l, .q] source target count"
#else
1292
	"[.b, .w, .l] source target count"
1293
#endif
wdenk's avatar
wdenk committed
1294 1295
);

1296
U_BOOT_CMD(
Wolfgang Denk's avatar
Wolfgang Denk committed
1297
	cmp,	4,	1,	do_mem_cmp,
Peter Tyser's avatar
Peter Tyser committed
1298
	"memory compare",
1299 1300 1301
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
	"[.b, .w, .l, .q] addr1 addr2 count"
#else
1302
	"[.b, .w, .l] addr1 addr2 count"
1303
#endif
wdenk's avatar
wdenk committed
1304 1305
);

1306 1307
#ifdef CONFIG_CMD_CRC32

1308
#ifndef CONFIG_HASH_VERIFY
1309

1310
U_BOOT_CMD(
Wolfgang Denk's avatar
Wolfgang Denk committed
1311
	crc32,	4,	1,	do_mem_crc,
Peter Tyser's avatar
Peter Tyser committed
1312
	"checksum calculation",
1313
	"address count [addr]\n    - compute CRC32 checksum [save at addr]"