Blame view

cmd/mem.c 27.6 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
3863585bb   wdenk   Initial revision
2
3
4
  /*
   * (C) Copyright 2000
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
3863585bb   wdenk   Initial revision
5
6
7
8
9
10
11
12
13
   */
  
  /*
   * Memory Functions
   *
   * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
   */
  
  #include <common.h>
24b852a7a   Simon Glass   Move console defi...
14
  #include <console.h>
0098e179e   Simon Glass   Move bootretry co...
15
  #include <bootretry.h>
18d66533a   Simon Glass   move CLI prototyp...
16
  #include <cli.h>
3863585bb   wdenk   Initial revision
17
  #include <command.h>
24b852a7a   Simon Glass   Move console defi...
18
  #include <console.h>
0ee48252b   Simon Glass   common: Move flas...
19
  #include <flash.h>
d20a40de9   Simon Glass   Roll crc32 into h...
20
  #include <hash.h>
0eb25b619   Joe Hershberger   common: Make sure...
21
  #include <mapmem.h>
a6e6fc610   Sergei Poselenov   Added watchdog tr...
22
  #include <watchdog.h>
0628ab8ec   Simon Glass   sandbox: Change m...
23
  #include <asm/io.h>
15a33e49d   Simon Glass   Add option to dis...
24
25
26
  #include <linux/compiler.h>
  
  DECLARE_GLOBAL_DATA_PTR;
3863585bb   wdenk   Initial revision
27

8e169cc94   Simon Glass   Move CONFIG_SYS_M...
28
29
30
  #ifndef CONFIG_SYS_MEMTEST_SCRATCH
  #define CONFIG_SYS_MEMTEST_SCRATCH 0
  #endif
54841ab50   Wolfgang Denk   Make sure that ar...
31
  static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
3863585bb   wdenk   Initial revision
32
33
34
35
  
  /* Display values from last command.
   * Memory modify remembered values are different from display memory.
   */
581508bdf   Scott Wood   cmd_mem: Store la...
36
37
38
  static ulong	dp_last_addr, dp_last_size;
  static ulong	dp_last_length = 0x40;
  static ulong	mm_last_addr, mm_last_size;
3863585bb   wdenk   Initial revision
39
40
41
42
43
44
  
  static	ulong	base_address = 0;
  
  /* Memory Display
   *
   * Syntax:
4d1fd7f1a   York Sun   Add 64-bit data s...
45
   *	md{.b, .w, .l, .q} {addr} {len}
3863585bb   wdenk   Initial revision
46
47
   */
  #define DISP_LINE_LEN	16
088f1b199   Kim Phillips   common/cmd_*.c: s...
48
  static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
49
  {
c68c03f52   Tuomas Tynkkynen   Drop CONFIG_HAS_D...
50
51
  	ulong	addr, length, bytes;
  	const void *buf;
27b207fd0   wdenk   * Implement new m...
52
  	int	size;
3863585bb   wdenk   Initial revision
53
54
55
56
57
58
59
60
  	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;
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
61
  	if (argc < 2)
4c12eeb8b   Simon Glass   Convert cmd_usage...
62
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
63
64
65
66
67
  
  	if ((flag & CMD_FLAG_REPEAT) == 0) {
  		/* New command specified.  Check for a size specification.
  		 * Defaults to long if no or incorrect specification.
  		 */
27b207fd0   wdenk   * Implement new m...
68
69
  		if ((size = cmd_get_data_size(argv[0], 4)) < 0)
  			return 1;
3863585bb   wdenk   Initial revision
70
71
72
73
74
75
76
77
78
79
80
81
  
  		/* 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);
  	}
c68c03f52   Tuomas Tynkkynen   Drop CONFIG_HAS_D...
82
83
  	bytes = size * length;
  	buf = map_sysmem(addr, bytes);
0628ab8ec   Simon Glass   sandbox: Change m...
84

c68c03f52   Tuomas Tynkkynen   Drop CONFIG_HAS_D...
85
86
87
88
  	/* Print the lines. */
  	print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
  	addr += bytes;
  	unmap_sysmem(buf);
3863585bb   wdenk   Initial revision
89
90
91
92
93
94
  
  	dp_last_addr = addr;
  	dp_last_length = length;
  	dp_last_size = size;
  	return (rc);
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
95
  static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
96
97
98
  {
  	return mod_mem (cmdtp, 1, flag, argc, argv);
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
99
  static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
100
101
102
  {
  	return mod_mem (cmdtp, 0, flag, argc, argv);
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
103
  static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
104
  {
4d979bfdb   Simon Glass   common: Move and ...
105
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
106
107
108
109
110
  	u64 writeval;
  #else
  	ulong writeval;
  #endif
  	ulong	addr, count;
27b207fd0   wdenk   * Implement new m...
111
  	int	size;
cc5e196e0   Simon Glass   Correct map_sysme...
112
  	void *buf, *start;
0628ab8ec   Simon Glass   sandbox: Change m...
113
  	ulong bytes;
3863585bb   wdenk   Initial revision
114

47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
115
  	if ((argc < 3) || (argc > 4))
4c12eeb8b   Simon Glass   Convert cmd_usage...
116
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
117
118
119
  
  	/* Check for size specification.
  	*/
27b207fd0   wdenk   * Implement new m...
120
121
  	if ((size = cmd_get_data_size(argv[0], 4)) < 1)
  		return 1;
3863585bb   wdenk   Initial revision
122
123
124
125
126
127
128
129
  
  	/* Address is specified since argc > 1
  	*/
  	addr = simple_strtoul(argv[1], NULL, 16);
  	addr += base_address;
  
  	/* Get the value to write.
  	*/
4d979bfdb   Simon Glass   common: Move and ...
130
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
131
132
  	writeval = simple_strtoull(argv[2], NULL, 16);
  #else
3863585bb   wdenk   Initial revision
133
  	writeval = simple_strtoul(argv[2], NULL, 16);
4d1fd7f1a   York Sun   Add 64-bit data s...
134
  #endif
3863585bb   wdenk   Initial revision
135
136
137
138
139
140
141
  
  	/* Count ? */
  	if (argc == 4) {
  		count = simple_strtoul(argv[3], NULL, 16);
  	} else {
  		count = 1;
  	}
0628ab8ec   Simon Glass   sandbox: Change m...
142
  	bytes = size * count;
cc5e196e0   Simon Glass   Correct map_sysme...
143
144
  	start = map_sysmem(addr, bytes);
  	buf = start;
3863585bb   wdenk   Initial revision
145
146
  	while (count-- > 0) {
  		if (size == 4)
76698b4e6   York Sun   Fix memory comman...
147
  			*((u32 *)buf) = (u32)writeval;
4d979bfdb   Simon Glass   common: Move and ...
148
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
149
150
151
  		else if (size == 8)
  			*((u64 *)buf) = (u64)writeval;
  #endif
3863585bb   wdenk   Initial revision
152
  		else if (size == 2)
76698b4e6   York Sun   Fix memory comman...
153
  			*((u16 *)buf) = (u16)writeval;
3863585bb   wdenk   Initial revision
154
  		else
76698b4e6   York Sun   Fix memory comman...
155
  			*((u8 *)buf) = (u8)writeval;
0628ab8ec   Simon Glass   sandbox: Change m...
156
  		buf += size;
3863585bb   wdenk   Initial revision
157
  	}
cc5e196e0   Simon Glass   Correct map_sysme...
158
  	unmap_sysmem(start);
3863585bb   wdenk   Initial revision
159
160
  	return 0;
  }
72732318a   Joel Johnson   cmd: mdc/mwc: nor...
161
  #ifdef CONFIG_CMD_MX_CYCLIC
5a8608e58   Masahiro Yamada   cmd_mem: add stat...
162
  static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
4aaf29b2f   stroese   memory commands "...
163
164
165
  {
  	int i;
  	ulong count;
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
166
  	if (argc < 4)
4c12eeb8b   Simon Glass   Convert cmd_usage...
167
  		return CMD_RET_USAGE;
4aaf29b2f   stroese   memory commands "...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
  
  	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
  ");
  			return 0;
  		}
  	}
  
  	return 0;
  }
5a8608e58   Masahiro Yamada   cmd_mem: add stat...
188
  static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
4aaf29b2f   stroese   memory commands "...
189
190
191
  {
  	int i;
  	ulong count;
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
192
  	if (argc < 4)
4c12eeb8b   Simon Glass   Convert cmd_usage...
193
  		return CMD_RET_USAGE;
4aaf29b2f   stroese   memory commands "...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  
  	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
  ");
  			return 0;
  		}
  	}
  
  	return 0;
  }
72732318a   Joel Johnson   cmd: mdc/mwc: nor...
214
  #endif /* CONFIG_CMD_MX_CYCLIC */
4aaf29b2f   stroese   memory commands "...
215

088f1b199   Kim Phillips   common/cmd_*.c: s...
216
  static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
217
  {
0628ab8ec   Simon Glass   sandbox: Change m...
218
  	ulong	addr1, addr2, count, ngood, bytes;
27b207fd0   wdenk   * Implement new m...
219
  	int	size;
3863585bb   wdenk   Initial revision
220
  	int     rcode = 0;
054ea170f   Mike Frysinger   cmd_mem: cmp: uni...
221
  	const char *type;
0628ab8ec   Simon Glass   sandbox: Change m...
222
  	const void *buf1, *buf2, *base;
4d979bfdb   Simon Glass   common: Move and ...
223
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
224
225
226
227
  	u64 word1, word2;
  #else
  	ulong word1, word2;
  #endif
3863585bb   wdenk   Initial revision
228

47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
229
  	if (argc != 4)
4c12eeb8b   Simon Glass   Convert cmd_usage...
230
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
231
232
233
  
  	/* Check for size specification.
  	*/
27b207fd0   wdenk   * Implement new m...
234
235
  	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
  		return 1;
4d1fd7f1a   York Sun   Add 64-bit data s...
236
237
238
  	type = size == 8 ? "double word" :
  	       size == 4 ? "word" :
  	       size == 2 ? "halfword" : "byte";
3863585bb   wdenk   Initial revision
239
240
241
242
243
244
245
246
  
  	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);
0628ab8ec   Simon Glass   sandbox: Change m...
247
248
249
  	bytes = size * count;
  	base = buf1 = map_sysmem(addr1, bytes);
  	buf2 = map_sysmem(addr2, bytes);
feb12a1f6   Mike Frysinger   cmd_mem: cmp: con...
250
  	for (ngood = 0; ngood < count; ++ngood) {
3863585bb   wdenk   Initial revision
251
  		if (size == 4) {
76698b4e6   York Sun   Fix memory comman...
252
253
  			word1 = *(u32 *)buf1;
  			word2 = *(u32 *)buf2;
4d979bfdb   Simon Glass   common: Move and ...
254
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
255
256
257
258
  		} else if (size == 8) {
  			word1 = *(u64 *)buf1;
  			word2 = *(u64 *)buf2;
  #endif
054ea170f   Mike Frysinger   cmd_mem: cmp: uni...
259
  		} else if (size == 2) {
76698b4e6   York Sun   Fix memory comman...
260
261
  			word1 = *(u16 *)buf1;
  			word2 = *(u16 *)buf2;
054ea170f   Mike Frysinger   cmd_mem: cmp: uni...
262
  		} else {
76698b4e6   York Sun   Fix memory comman...
263
264
  			word1 = *(u8 *)buf1;
  			word2 = *(u8 *)buf2;
3863585bb   wdenk   Initial revision
265
  		}
054ea170f   Mike Frysinger   cmd_mem: cmp: uni...
266
  		if (word1 != word2) {
0628ab8ec   Simon Glass   sandbox: Change m...
267
  			ulong offset = buf1 - base;
4d979bfdb   Simon Glass   common: Move and ...
268
  #ifdef MEM_SUPPORT_64BIT_DATA
dee37fc99   Masahiro Yamada   Remove <inttypes....
269
270
  			printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)
  ",
4d1fd7f1a   York Sun   Add 64-bit data s...
271
272
273
  			       type, (void *)(addr1 + offset), size, word1,
  			       type, (void *)(addr2 + offset), size, word2);
  #else
054ea170f   Mike Frysinger   cmd_mem: cmp: uni...
274
275
  			printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)
  ",
0628ab8ec   Simon Glass   sandbox: Change m...
276
277
  				type, (ulong)(addr1 + offset), size, word1,
  				type, (ulong)(addr2 + offset), size, word2);
4d1fd7f1a   York Sun   Add 64-bit data s...
278
  #endif
054ea170f   Mike Frysinger   cmd_mem: cmp: uni...
279
280
  			rcode = 1;
  			break;
3863585bb   wdenk   Initial revision
281
  		}
054ea170f   Mike Frysinger   cmd_mem: cmp: uni...
282

0628ab8ec   Simon Glass   sandbox: Change m...
283
284
  		buf1 += size;
  		buf2 += size;
eaadb44ed   Stefan Roese   cp/cmp: Add WATCH...
285
286
  
  		/* reset watchdog from time to time */
feb12a1f6   Mike Frysinger   cmd_mem: cmp: con...
287
  		if ((ngood % (64 << 10)) == 0)
eaadb44ed   Stefan Roese   cp/cmp: Add WATCH...
288
  			WATCHDOG_RESET();
3863585bb   wdenk   Initial revision
289
  	}
0628ab8ec   Simon Glass   sandbox: Change m...
290
291
  	unmap_sysmem(buf1);
  	unmap_sysmem(buf2);
3863585bb   wdenk   Initial revision
292

054ea170f   Mike Frysinger   cmd_mem: cmp: uni...
293
294
  	printf("Total of %ld %s(s) were the same
  ", ngood, type);
3863585bb   wdenk   Initial revision
295
296
  	return rcode;
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
297
  static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
298
  {
c2538421b   Fabio Estevam   cmd: mem: Use mem...
299
  	ulong	addr, dest, count;
787f10a9d   Philippe Reynes   cmd: cp: add miss...
300
  	void	*src, *dst;
27b207fd0   wdenk   * Implement new m...
301
  	int	size;
3863585bb   wdenk   Initial revision
302

47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
303
  	if (argc != 4)
4c12eeb8b   Simon Glass   Convert cmd_usage...
304
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
305
306
307
  
  	/* Check for size specification.
  	*/
27b207fd0   wdenk   * Implement new m...
308
309
  	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
  		return 1;
3863585bb   wdenk   Initial revision
310
311
312
313
314
315
316
317
318
319
320
321
322
323
  
  	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 ???
  ");
  		return 1;
  	}
787f10a9d   Philippe Reynes   cmd: cp: add miss...
324
325
  	src = map_sysmem(addr, count * size);
  	dst = map_sysmem(dest, count * size);
e856bdcfb   Masahiro Yamada   flash: complete C...
326
  #ifdef CONFIG_MTD_NOR_FLASH
3863585bb   wdenk   Initial revision
327
  	/* check if we are copying to Flash */
787f10a9d   Philippe Reynes   cmd: cp: add miss...
328
  	if (addr2info((ulong)dst)) {
3863585bb   wdenk   Initial revision
329
  		int rc;
4b9206ed5   wdenk   * Patches by Thom...
330
  		puts ("Copy to Flash... ");
3863585bb   wdenk   Initial revision
331

787f10a9d   Philippe Reynes   cmd: cp: add miss...
332
  		rc = flash_write((char *)src, (ulong)dst, count * size);
3863585bb   wdenk   Initial revision
333
  		if (rc != 0) {
0ee48252b   Simon Glass   common: Move flas...
334
  			flash_perror(rc);
787f10a9d   Philippe Reynes   cmd: cp: add miss...
335
336
  			unmap_sysmem(src);
  			unmap_sysmem(dst);
3863585bb   wdenk   Initial revision
337
338
339
340
  			return (1);
  		}
  		puts ("done
  ");
787f10a9d   Philippe Reynes   cmd: cp: add miss...
341
342
  		unmap_sysmem(src);
  		unmap_sysmem(dst);
3863585bb   wdenk   Initial revision
343
344
345
  		return 0;
  	}
  #endif
787f10a9d   Philippe Reynes   cmd: cp: add miss...
346
  	memcpy(dst, src, count * size);
a3a4749df   Masahiro Yamada   cmd_mem: call unm...
347

787f10a9d   Philippe Reynes   cmd: cp: add miss...
348
349
  	unmap_sysmem(src);
  	unmap_sysmem(dst);
3863585bb   wdenk   Initial revision
350
351
  	return 0;
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
352
353
  static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
  		       char * const argv[])
3863585bb   wdenk   Initial revision
354
355
356
357
358
359
360
361
362
363
364
365
  {
  	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
  ", base_address);
  	return 0;
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
366
367
  static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
  		       char * const argv[])
3863585bb   wdenk   Initial revision
368
  {
0628ab8ec   Simon Glass   sandbox: Change m...
369
  	ulong	addr, length, i, bytes;
27b207fd0   wdenk   * Implement new m...
370
  	int	size;
4d979bfdb   Simon Glass   common: Move and ...
371
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
372
373
  	volatile u64 *llp;
  #endif
76698b4e6   York Sun   Fix memory comman...
374
375
376
  	volatile u32 *longp;
  	volatile u16 *shortp;
  	volatile u8 *cp;
0628ab8ec   Simon Glass   sandbox: Change m...
377
  	const void *buf;
3863585bb   wdenk   Initial revision
378

47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
379
  	if (argc < 3)
4c12eeb8b   Simon Glass   Convert cmd_usage...
380
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
381

85de63e2e   Robert P. J. Day   cmd_mem.c: Fix so...
382
383
  	/*
  	 * Check for a size specification.
3863585bb   wdenk   Initial revision
384
385
  	 * Defaults to long if no or incorrect specification.
  	 */
27b207fd0   wdenk   * Implement new m...
386
387
  	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
  		return 1;
3863585bb   wdenk   Initial revision
388
389
390
391
392
393
394
395
  
  	/* 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);
0628ab8ec   Simon Glass   sandbox: Change m...
396
397
  	bytes = size * length;
  	buf = map_sysmem(addr, bytes);
3863585bb   wdenk   Initial revision
398
399
400
401
  	/* 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) {
4d979bfdb   Simon Glass   common: Move and ...
402
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
403
404
405
406
407
408
  		if (size == 8) {
  			llp = (u64 *)buf;
  			for (;;)
  				i = *llp;
  		}
  #endif
3863585bb   wdenk   Initial revision
409
  		if (size == 4) {
76698b4e6   York Sun   Fix memory comman...
410
  			longp = (u32 *)buf;
3863585bb   wdenk   Initial revision
411
412
413
414
  			for (;;)
  				i = *longp;
  		}
  		if (size == 2) {
76698b4e6   York Sun   Fix memory comman...
415
  			shortp = (u16 *)buf;
3863585bb   wdenk   Initial revision
416
417
418
  			for (;;)
  				i = *shortp;
  		}
76698b4e6   York Sun   Fix memory comman...
419
  		cp = (u8 *)buf;
3863585bb   wdenk   Initial revision
420
421
422
  		for (;;)
  			i = *cp;
  	}
4d979bfdb   Simon Glass   common: Move and ...
423
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
424
425
426
427
428
429
430
431
432
  	if (size == 8) {
  		for (;;) {
  			llp = (u64 *)buf;
  			i = length;
  			while (i-- > 0)
  				*llp++;
  		}
  	}
  #endif
3863585bb   wdenk   Initial revision
433
434
  	if (size == 4) {
  		for (;;) {
76698b4e6   York Sun   Fix memory comman...
435
  			longp = (u32 *)buf;
3863585bb   wdenk   Initial revision
436
437
  			i = length;
  			while (i-- > 0)
f3b3c3df1   Marek Vasut   GCC4.6: Squash wa...
438
  				*longp++;
3863585bb   wdenk   Initial revision
439
440
441
442
  		}
  	}
  	if (size == 2) {
  		for (;;) {
76698b4e6   York Sun   Fix memory comman...
443
  			shortp = (u16 *)buf;
3863585bb   wdenk   Initial revision
444
445
  			i = length;
  			while (i-- > 0)
f3b3c3df1   Marek Vasut   GCC4.6: Squash wa...
446
  				*shortp++;
3863585bb   wdenk   Initial revision
447
448
449
  		}
  	}
  	for (;;) {
76698b4e6   York Sun   Fix memory comman...
450
  		cp = (u8 *)buf;
3863585bb   wdenk   Initial revision
451
452
  		i = length;
  		while (i-- > 0)
f3b3c3df1   Marek Vasut   GCC4.6: Squash wa...
453
  			*cp++;
3863585bb   wdenk   Initial revision
454
  	}
0628ab8ec   Simon Glass   sandbox: Change m...
455
  	unmap_sysmem(buf);
92765f420   Simon Glass   Fix missing retur...
456
457
  
  	return 0;
3863585bb   wdenk   Initial revision
458
  }
56523f128   wdenk   * Patch by Martin...
459
  #ifdef CONFIG_LOOPW
5a8608e58   Masahiro Yamada   cmd_mem: add stat...
460
461
  static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
  			char * const argv[])
56523f128   wdenk   * Patch by Martin...
462
  {
4d1fd7f1a   York Sun   Add 64-bit data s...
463
  	ulong	addr, length, i, bytes;
56523f128   wdenk   * Patch by Martin...
464
  	int	size;
4d979bfdb   Simon Glass   common: Move and ...
465
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
466
467
468
469
470
  	volatile u64 *llp;
  	u64 data;
  #else
  	ulong	data;
  #endif
76698b4e6   York Sun   Fix memory comman...
471
472
473
  	volatile u32 *longp;
  	volatile u16 *shortp;
  	volatile u8 *cp;
0628ab8ec   Simon Glass   sandbox: Change m...
474
  	void *buf;
810509266   wdenk   * Cleanup
475

47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
476
  	if (argc < 4)
4c12eeb8b   Simon Glass   Convert cmd_usage...
477
  		return CMD_RET_USAGE;
56523f128   wdenk   * Patch by Martin...
478

85de63e2e   Robert P. J. Day   cmd_mem.c: Fix so...
479
480
  	/*
  	 * Check for a size specification.
56523f128   wdenk   * Patch by Martin...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
  	 * 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 */
4d979bfdb   Simon Glass   common: Move and ...
495
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
496
497
  	data = simple_strtoull(argv[3], NULL, 16);
  #else
56523f128   wdenk   * Patch by Martin...
498
  	data = simple_strtoul(argv[3], NULL, 16);
4d1fd7f1a   York Sun   Add 64-bit data s...
499
  #endif
810509266   wdenk   * Cleanup
500

0628ab8ec   Simon Glass   sandbox: Change m...
501
502
  	bytes = size * length;
  	buf = map_sysmem(addr, bytes);
56523f128   wdenk   * Patch by Martin...
503
504
505
506
  	/* 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) {
4d979bfdb   Simon Glass   common: Move and ...
507
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
508
509
510
511
512
513
  		if (size == 8) {
  			llp = (u64 *)buf;
  			for (;;)
  				*llp = data;
  		}
  #endif
56523f128   wdenk   * Patch by Martin...
514
  		if (size == 4) {
76698b4e6   York Sun   Fix memory comman...
515
  			longp = (u32 *)buf;
56523f128   wdenk   * Patch by Martin...
516
517
  			for (;;)
  				*longp = data;
4d1fd7f1a   York Sun   Add 64-bit data s...
518
  		}
56523f128   wdenk   * Patch by Martin...
519
  		if (size == 2) {
76698b4e6   York Sun   Fix memory comman...
520
  			shortp = (u16 *)buf;
56523f128   wdenk   * Patch by Martin...
521
522
523
  			for (;;)
  				*shortp = data;
  		}
76698b4e6   York Sun   Fix memory comman...
524
  		cp = (u8 *)buf;
56523f128   wdenk   * Patch by Martin...
525
526
527
  		for (;;)
  			*cp = data;
  	}
4d979bfdb   Simon Glass   common: Move and ...
528
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
529
530
531
532
533
534
535
536
537
  	if (size == 8) {
  		for (;;) {
  			llp = (u64 *)buf;
  			i = length;
  			while (i-- > 0)
  				*llp++ = data;
  		}
  	}
  #endif
56523f128   wdenk   * Patch by Martin...
538
539
  	if (size == 4) {
  		for (;;) {
76698b4e6   York Sun   Fix memory comman...
540
  			longp = (u32 *)buf;
56523f128   wdenk   * Patch by Martin...
541
542
543
544
545
546
547
  			i = length;
  			while (i-- > 0)
  				*longp++ = data;
  		}
  	}
  	if (size == 2) {
  		for (;;) {
76698b4e6   York Sun   Fix memory comman...
548
  			shortp = (u16 *)buf;
56523f128   wdenk   * Patch by Martin...
549
550
551
552
553
554
  			i = length;
  			while (i-- > 0)
  				*shortp++ = data;
  		}
  	}
  	for (;;) {
76698b4e6   York Sun   Fix memory comman...
555
  		cp = (u8 *)buf;
56523f128   wdenk   * Patch by Martin...
556
557
558
559
560
561
  		i = length;
  		while (i-- > 0)
  			*cp++ = data;
  	}
  }
  #endif /* CONFIG_LOOPW */
68149e940   Tom Rini   cmd_mem.c: Fix wa...
562
  #ifdef CONFIG_CMD_MEMTEST
5512d5b03   Simon Glass   sandbox: Update m...
563
564
  static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr,
  			  vu_long *dummy)
3863585bb   wdenk   Initial revision
565
  {
c9638f50f   Simon Glass   Split out the mem...
566
  	vu_long *addr;
c9638f50f   Simon Glass   Split out the mem...
567
568
569
  	ulong errs = 0;
  	ulong val, readback;
  	int j;
c9638f50f   Simon Glass   Split out the mem...
570
571
572
573
574
575
  	vu_long offset;
  	vu_long test_offset;
  	vu_long pattern;
  	vu_long temp;
  	vu_long anti_pattern;
  	vu_long num_words;
3863585bb   wdenk   Initial revision
576
577
578
579
580
581
582
583
584
585
  	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 */
  	};
3863585bb   wdenk   Initial revision
586

5512d5b03   Simon Glass   sandbox: Update m...
587
  	num_words = (end_addr - start_addr) / sizeof(vu_long);
8c86bbe00   Simon Glass   Reduce casting in...
588

7ecbd4d70   Simon Glass   Fix mtest indenting
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
  	/*
  	 * 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).
  	 */
5512d5b03   Simon Glass   sandbox: Update m...
606
  	addr = buf;
7ecbd4d70   Simon Glass   Fix mtest indenting
607
608
609
  	for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
  		val = bitpattern[j];
  		for (; val != 0; val <<= 1) {
5512d5b03   Simon Glass   sandbox: Update m...
610
  			*addr = val;
c9638f50f   Simon Glass   Split out the mem...
611
  			*dummy  = ~val; /* clear the test data off the bus */
3863585bb   wdenk   Initial revision
612
  			readback = *addr;
7ecbd4d70   Simon Glass   Fix mtest indenting
613
  			if (readback != val) {
c9638f50f   Simon Glass   Split out the mem...
614
615
616
617
618
  				printf("FAILURE (data line): "
  					"expected %08lx, actual %08lx
  ",
  						val, readback);
  				errs++;
c44d4386e   Simon Glass   Bring mtest putc(...
619
  				if (ctrlc())
51209b1f4   Simon Glass   Use common mtest ...
620
  					return -1;
3863585bb   wdenk   Initial revision
621
622
623
624
  			}
  			*addr  = ~val;
  			*dummy  = val;
  			readback = *addr;
c9638f50f   Simon Glass   Split out the mem...
625
626
627
628
629
630
  			if (readback != ~val) {
  				printf("FAILURE (data line): "
  					"Is %08lx, should be %08lx
  ",
  						readback, ~val);
  				errs++;
c44d4386e   Simon Glass   Bring mtest putc(...
631
  				if (ctrlc())
51209b1f4   Simon Glass   Use common mtest ...
632
  					return -1;
3863585bb   wdenk   Initial revision
633
  			}
3863585bb   wdenk   Initial revision
634
  		}
7ecbd4d70   Simon Glass   Fix mtest indenting
635
  	}
3863585bb   wdenk   Initial revision
636

7ecbd4d70   Simon Glass   Fix mtest indenting
637
638
639
640
641
642
643
644
645
  	/*
  	 * 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.
  	 */
3863585bb   wdenk   Initial revision
646

7ecbd4d70   Simon Glass   Fix mtest indenting
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
  	/*
  	* 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.
  	 */
7ecbd4d70   Simon Glass   Fix mtest indenting
671
672
  	pattern = (vu_long) 0xaaaaaaaa;
  	anti_pattern = (vu_long) 0x55555555;
3863585bb   wdenk   Initial revision
673

5512d5b03   Simon Glass   sandbox: Update m...
674
675
  	debug("%s:%d: length = 0x%.8lx
  ", __func__, __LINE__, num_words);
7ecbd4d70   Simon Glass   Fix mtest indenting
676
677
678
679
  	/*
  	 * Write the default pattern at each of the
  	 * power-of-two offsets.
  	 */
5512d5b03   Simon Glass   sandbox: Update m...
680
681
  	for (offset = 1; offset < num_words; offset <<= 1)
  		addr[offset] = pattern;
3863585bb   wdenk   Initial revision
682

7ecbd4d70   Simon Glass   Fix mtest indenting
683
684
685
686
  	/*
  	 * Check for address bits stuck high.
  	 */
  	test_offset = 0;
5512d5b03   Simon Glass   sandbox: Update m...
687
  	addr[test_offset] = anti_pattern;
3863585bb   wdenk   Initial revision
688

5512d5b03   Simon Glass   sandbox: Update m...
689
690
  	for (offset = 1; offset < num_words; offset <<= 1) {
  		temp = addr[offset];
7ecbd4d70   Simon Glass   Fix mtest indenting
691
  		if (temp != pattern) {
c9638f50f   Simon Glass   Split out the mem...
692
693
  			printf("
  FAILURE: Address bit stuck high @ 0x%.8lx:"
3863585bb   wdenk   Initial revision
694
695
  				" expected 0x%.8lx, actual 0x%.8lx
  ",
102c051fc   David Feng   fix address of er...
696
697
  				start_addr + offset*sizeof(vu_long),
  				pattern, temp);
87b22b778   Paul Gortmaker   mem_mtest: fix er...
698
  			errs++;
c44d4386e   Simon Glass   Bring mtest putc(...
699
  			if (ctrlc())
7ecbd4d70   Simon Glass   Fix mtest indenting
700
  				return -1;
3863585bb   wdenk   Initial revision
701
  		}
7ecbd4d70   Simon Glass   Fix mtest indenting
702
  	}
5512d5b03   Simon Glass   sandbox: Update m...
703
  	addr[test_offset] = pattern;
7ecbd4d70   Simon Glass   Fix mtest indenting
704
  	WATCHDOG_RESET();
3863585bb   wdenk   Initial revision
705

7ecbd4d70   Simon Glass   Fix mtest indenting
706
707
708
  	/*
  	 * Check for addr bits stuck low or shorted.
  	 */
5512d5b03   Simon Glass   sandbox: Update m...
709
710
  	for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
  		addr[test_offset] = anti_pattern;
3863585bb   wdenk   Initial revision
711

5512d5b03   Simon Glass   sandbox: Update m...
712
713
  		for (offset = 1; offset < num_words; offset <<= 1) {
  			temp = addr[offset];
3863585bb   wdenk   Initial revision
714
  			if ((temp != pattern) && (offset != test_offset)) {
7ecbd4d70   Simon Glass   Fix mtest indenting
715
716
717
718
719
  				printf("
  FAILURE: Address bit stuck low or"
  					" shorted @ 0x%.8lx: expected 0x%.8lx,"
  					" actual 0x%.8lx
  ",
102c051fc   David Feng   fix address of er...
720
721
  					start_addr + offset*sizeof(vu_long),
  					pattern, temp);
7ecbd4d70   Simon Glass   Fix mtest indenting
722
  				errs++;
c44d4386e   Simon Glass   Bring mtest putc(...
723
  				if (ctrlc())
7ecbd4d70   Simon Glass   Fix mtest indenting
724
  					return -1;
3863585bb   wdenk   Initial revision
725
  			}
3863585bb   wdenk   Initial revision
726
  		}
5512d5b03   Simon Glass   sandbox: Update m...
727
  		addr[test_offset] = pattern;
7ecbd4d70   Simon Glass   Fix mtest indenting
728
  	}
3863585bb   wdenk   Initial revision
729

7ecbd4d70   Simon Glass   Fix mtest indenting
730
731
732
733
734
735
736
737
738
739
740
741
  	/*
  	 * 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.
  	 */
5512d5b03   Simon Glass   sandbox: Update m...
742
  	num_words++;
3863585bb   wdenk   Initial revision
743

7ecbd4d70   Simon Glass   Fix mtest indenting
744
745
746
747
748
  	/*
  	 * Fill memory with a known pattern.
  	 */
  	for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
  		WATCHDOG_RESET();
5512d5b03   Simon Glass   sandbox: Update m...
749
  		addr[offset] = pattern;
7ecbd4d70   Simon Glass   Fix mtest indenting
750
  	}
3863585bb   wdenk   Initial revision
751

7ecbd4d70   Simon Glass   Fix mtest indenting
752
753
754
755
756
  	/*
  	 * Check each location and invert it for the second pass.
  	 */
  	for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
  		WATCHDOG_RESET();
5512d5b03   Simon Glass   sandbox: Update m...
757
  		temp = addr[offset];
7ecbd4d70   Simon Glass   Fix mtest indenting
758
  		if (temp != pattern) {
c9638f50f   Simon Glass   Split out the mem...
759
760
  			printf("
  FAILURE (read/write) @ 0x%.8lx:"
3863585bb   wdenk   Initial revision
761
762
  				" expected 0x%.8lx, actual 0x%.8lx)
  ",
102c051fc   David Feng   fix address of er...
763
764
  				start_addr + offset*sizeof(vu_long),
  				pattern, temp);
87b22b778   Paul Gortmaker   mem_mtest: fix er...
765
  			errs++;
c44d4386e   Simon Glass   Bring mtest putc(...
766
  			if (ctrlc())
51209b1f4   Simon Glass   Use common mtest ...
767
  				return -1;
3863585bb   wdenk   Initial revision
768
  		}
7ecbd4d70   Simon Glass   Fix mtest indenting
769
  		anti_pattern = ~pattern;
5512d5b03   Simon Glass   sandbox: Update m...
770
  		addr[offset] = anti_pattern;
7ecbd4d70   Simon Glass   Fix mtest indenting
771
772
773
774
775
776
777
778
  	}
  
  	/*
  	 * 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;
5512d5b03   Simon Glass   sandbox: Update m...
779
  		temp = addr[offset];
7ecbd4d70   Simon Glass   Fix mtest indenting
780
  		if (temp != anti_pattern) {
c9638f50f   Simon Glass   Split out the mem...
781
782
  			printf("
  FAILURE (read/write): @ 0x%.8lx:"
3863585bb   wdenk   Initial revision
783
784
  				" expected 0x%.8lx, actual 0x%.8lx)
  ",
102c051fc   David Feng   fix address of er...
785
786
  				start_addr + offset*sizeof(vu_long),
  				anti_pattern, temp);
87b22b778   Paul Gortmaker   mem_mtest: fix er...
787
  			errs++;
c44d4386e   Simon Glass   Bring mtest putc(...
788
  			if (ctrlc())
51209b1f4   Simon Glass   Use common mtest ...
789
  				return -1;
3863585bb   wdenk   Initial revision
790
  		}
5512d5b03   Simon Glass   sandbox: Update m...
791
  		addr[offset] = 0;
7ecbd4d70   Simon Glass   Fix mtest indenting
792
  	}
51209b1f4   Simon Glass   Use common mtest ...
793

fea6730e1   Rasmus Villemoes   fix always succes...
794
  	return errs;
c9638f50f   Simon Glass   Split out the mem...
795
  }
5512d5b03   Simon Glass   sandbox: Update m...
796
797
  static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
  			    vu_long pattern, int iteration)
c9638f50f   Simon Glass   Split out the mem...
798
  {
5512d5b03   Simon Glass   sandbox: Update m...
799
  	vu_long *end;
c9638f50f   Simon Glass   Split out the mem...
800
  	vu_long *addr;
c9638f50f   Simon Glass   Split out the mem...
801
  	ulong errs = 0;
5512d5b03   Simon Glass   sandbox: Update m...
802
  	ulong incr, length;
c9638f50f   Simon Glass   Split out the mem...
803
  	ulong val, readback;
3863585bb   wdenk   Initial revision
804

51209b1f4   Simon Glass   Use common mtest ...
805
  	/* Alternate the pattern */
3863585bb   wdenk   Initial revision
806
  	incr = 1;
51209b1f4   Simon Glass   Use common mtest ...
807
808
809
810
811
812
813
814
815
816
817
818
819
  	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;
  	}
5512d5b03   Simon Glass   sandbox: Update m...
820
821
  	length = (end_addr - start_addr) / sizeof(ulong);
  	end = buf + length;
7ecbd4d70   Simon Glass   Fix mtest indenting
822
823
824
825
  	printf("\rPattern %08lX  Writing..."
  		"%12s"
  		"\b\b\b\b\b\b\b\b\b\b",
  		pattern, "");
3863585bb   wdenk   Initial revision
826

5512d5b03   Simon Glass   sandbox: Update m...
827
  	for (addr = buf, val = pattern; addr < end; addr++) {
7ecbd4d70   Simon Glass   Fix mtest indenting
828
829
830
831
  		WATCHDOG_RESET();
  		*addr = val;
  		val += incr;
  	}
3863585bb   wdenk   Initial revision
832

7ecbd4d70   Simon Glass   Fix mtest indenting
833
  	puts("Reading...");
3863585bb   wdenk   Initial revision
834

5512d5b03   Simon Glass   sandbox: Update m...
835
  	for (addr = buf, val = pattern; addr < end; addr++) {
7ecbd4d70   Simon Glass   Fix mtest indenting
836
837
838
  		WATCHDOG_RESET();
  		readback = *addr;
  		if (readback != val) {
5512d5b03   Simon Glass   sandbox: Update m...
839
  			ulong offset = addr - buf;
7ecbd4d70   Simon Glass   Fix mtest indenting
840
841
842
843
  			printf("
  Mem error @ 0x%08X: "
  				"found %08lX, expected %08lX
  ",
102c051fc   David Feng   fix address of er...
844
  				(uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
5512d5b03   Simon Glass   sandbox: Update m...
845
  				readback, val);
7ecbd4d70   Simon Glass   Fix mtest indenting
846
  			errs++;
c44d4386e   Simon Glass   Bring mtest putc(...
847
  			if (ctrlc())
7ecbd4d70   Simon Glass   Fix mtest indenting
848
  				return -1;
3863585bb   wdenk   Initial revision
849
  		}
7ecbd4d70   Simon Glass   Fix mtest indenting
850
851
  		val += incr;
  	}
3863585bb   wdenk   Initial revision
852

fea6730e1   Rasmus Villemoes   fix always succes...
853
  	return errs;
c9638f50f   Simon Glass   Split out the mem...
854
855
856
857
858
859
860
861
862
863
  }
  
  /*
   * 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[])
  {
8c86bbe00   Simon Glass   Reduce casting in...
864
  	ulong start, end;
5512d5b03   Simon Glass   sandbox: Update m...
865
  	vu_long *buf, *dummy;
adcc57059   Tom Rini   cmd_mem.c: Update...
866
  	ulong iteration_limit = 0;
c9638f50f   Simon Glass   Split out the mem...
867
  	int ret;
51209b1f4   Simon Glass   Use common mtest ...
868
  	ulong errs = 0;	/* number of errors, or -1 if interrupted */
e37f1eb45   Pavel Machek   cmd_mem: cleanups...
869
  	ulong pattern = 0;
51209b1f4   Simon Glass   Use common mtest ...
870
  	int iteration;
c9638f50f   Simon Glass   Split out the mem...
871
872
873
874
  #if defined(CONFIG_SYS_ALT_MEMTEST)
  	const int alt_test = 1;
  #else
  	const int alt_test = 0;
3863585bb   wdenk   Initial revision
875
  #endif
c9638f50f   Simon Glass   Split out the mem...
876

e37f1eb45   Pavel Machek   cmd_mem: cleanups...
877
878
  	start = CONFIG_SYS_MEMTEST_START;
  	end = CONFIG_SYS_MEMTEST_END;
c9638f50f   Simon Glass   Split out the mem...
879
  	if (argc > 1)
e37f1eb45   Pavel Machek   cmd_mem: cleanups...
880
881
  		if (strict_strtoul(argv[1], 16, &start) < 0)
  			return CMD_RET_USAGE;
c9638f50f   Simon Glass   Split out the mem...
882
883
  
  	if (argc > 2)
e37f1eb45   Pavel Machek   cmd_mem: cleanups...
884
885
  		if (strict_strtoul(argv[2], 16, &end) < 0)
  			return CMD_RET_USAGE;
c9638f50f   Simon Glass   Split out the mem...
886
887
  
  	if (argc > 3)
e37f1eb45   Pavel Machek   cmd_mem: cleanups...
888
889
  		if (strict_strtoul(argv[3], 16, &pattern) < 0)
  			return CMD_RET_USAGE;
c9638f50f   Simon Glass   Split out the mem...
890
891
  
  	if (argc > 4)
e37f1eb45   Pavel Machek   cmd_mem: cleanups...
892
893
894
895
896
897
898
899
  		if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
  			return CMD_RET_USAGE;
  
  	if (end < start) {
  		printf("Refusing to do empty test
  ");
  		return -1;
  	}
c9638f50f   Simon Glass   Split out the mem...
900

dfe461d6b   Michal Simek   cmd: mem: Show 64...
901
902
  	printf("Testing %08lx ... %08lx:
  ", start, end);
8c86bbe00   Simon Glass   Reduce casting in...
903
904
905
  	debug("%s:%d: start %#08lx end %#08lx
  ", __func__, __LINE__,
  	      start, end);
51209b1f4   Simon Glass   Use common mtest ...
906

5512d5b03   Simon Glass   sandbox: Update m...
907
908
  	buf = map_sysmem(start, end - start);
  	dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long));
51209b1f4   Simon Glass   Use common mtest ...
909
910
911
912
  	for (iteration = 0;
  			!iteration_limit || iteration < iteration_limit;
  			iteration++) {
  		if (ctrlc()) {
51209b1f4   Simon Glass   Use common mtest ...
913
914
915
916
917
918
919
  			errs = -1UL;
  			break;
  		}
  
  		printf("Iteration: %6d\r", iteration + 1);
  		debug("
  ");
5512d5b03   Simon Glass   sandbox: Update m...
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
  		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);
51209b1f4   Simon Glass   Use common mtest ...
941
942
943
  	}
  
  	if (errs == -1UL) {
c44d4386e   Simon Glass   Bring mtest putc(...
944
945
946
  		/* Memory test was aborted - write a newline to finish off */
  		putc('
  ');
51209b1f4   Simon Glass   Use common mtest ...
947
948
949
950
951
952
953
  		ret = 1;
  	} else {
  		printf("Tested %d iteration(s) with %lu errors.
  ",
  			iteration, errs);
  		ret = errs != 0;
  	}
c9638f50f   Simon Glass   Split out the mem...
954

e37f1eb45   Pavel Machek   cmd_mem: cleanups...
955
  	return ret;
3863585bb   wdenk   Initial revision
956
  }
a2681707b   Wolfgang Denk   Feature Removal: ...
957
  #endif	/* CONFIG_CMD_MEMTEST */
3863585bb   wdenk   Initial revision
958
959
960
961
  
  /* Modify memory.
   *
   * Syntax:
4d1fd7f1a   York Sun   Add 64-bit data s...
962
963
   *	mm{.b, .w, .l, .q} {addr}
   *	nm{.b, .w, .l, .q} {addr}
3863585bb   wdenk   Initial revision
964
965
   */
  static int
54841ab50   Wolfgang Denk   Make sure that ar...
966
  mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
967
  {
4d1fd7f1a   York Sun   Add 64-bit data s...
968
  	ulong	addr;
4d979bfdb   Simon Glass   common: Move and ...
969
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
970
971
972
973
  	u64 i;
  #else
  	ulong i;
  #endif
27b207fd0   wdenk   * Implement new m...
974
  	int	nbytes, size;
0628ab8ec   Simon Glass   sandbox: Change m...
975
  	void *ptr = NULL;
3863585bb   wdenk   Initial revision
976

47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
977
  	if (argc != 2)
4c12eeb8b   Simon Glass   Convert cmd_usage...
978
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
979

b26440f1f   Simon Glass   Rename bootretry ...
980
  	bootretry_reset_cmd_timeout();	/* got a good command to get here */
3863585bb   wdenk   Initial revision
981
982
983
984
985
986
987
988
989
990
  	/* 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.
  		 */
27b207fd0   wdenk   * Implement new m...
991
992
  		if ((size = cmd_get_data_size(argv[0], 4)) < 0)
  			return 1;
3863585bb   wdenk   Initial revision
993
994
995
996
997
998
999
1000
1001
1002
1003
  
  		/* Address is specified since argc > 1
  		*/
  		addr = simple_strtoul(argv[1], NULL, 16);
  		addr += base_address;
  	}
  
  	/* Print the address, followed by value.  Then accept input for
  	 * the next value.  A non-converted value exits.
  	 */
  	do {
0628ab8ec   Simon Glass   sandbox: Change m...
1004
  		ptr = map_sysmem(addr, size);
3863585bb   wdenk   Initial revision
1005
1006
  		printf("%08lx:", addr);
  		if (size == 4)
76698b4e6   York Sun   Fix memory comman...
1007
  			printf(" %08x", *((u32 *)ptr));
4d979bfdb   Simon Glass   common: Move and ...
1008
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1009
  		else if (size == 8)
dee37fc99   Masahiro Yamada   Remove <inttypes....
1010
  			printf(" %016llx", *((u64 *)ptr));
4d1fd7f1a   York Sun   Add 64-bit data s...
1011
  #endif
3863585bb   wdenk   Initial revision
1012
  		else if (size == 2)
76698b4e6   York Sun   Fix memory comman...
1013
  			printf(" %04x", *((u16 *)ptr));
3863585bb   wdenk   Initial revision
1014
  		else
76698b4e6   York Sun   Fix memory comman...
1015
  			printf(" %02x", *((u8 *)ptr));
3863585bb   wdenk   Initial revision
1016

e1bf824df   Simon Glass   Add cli_ prefix t...
1017
  		nbytes = cli_readline(" ? ");
3863585bb   wdenk   Initial revision
1018
1019
1020
1021
1022
1023
1024
  		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;
b26440f1f   Simon Glass   Rename bootretry ...
1025
1026
  			/* good enough to not time out */
  			bootretry_reset_cmd_timeout();
3863585bb   wdenk   Initial revision
1027
1028
1029
1030
1031
1032
1033
1034
  		}
  #ifdef CONFIG_BOOT_RETRY_TIME
  		else if (nbytes == -2) {
  			break;	/* timed out, exit the command	*/
  		}
  #endif
  		else {
  			char *endp;
4d979bfdb   Simon Glass   common: Move and ...
1035
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1036
1037
  			i = simple_strtoull(console_buffer, &endp, 16);
  #else
3863585bb   wdenk   Initial revision
1038
  			i = simple_strtoul(console_buffer, &endp, 16);
4d1fd7f1a   York Sun   Add 64-bit data s...
1039
  #endif
3863585bb   wdenk   Initial revision
1040
1041
  			nbytes = endp - console_buffer;
  			if (nbytes) {
3863585bb   wdenk   Initial revision
1042
1043
  				/* good enough to not time out
  				 */
b26440f1f   Simon Glass   Rename bootretry ...
1044
  				bootretry_reset_cmd_timeout();
3863585bb   wdenk   Initial revision
1045
  				if (size == 4)
76698b4e6   York Sun   Fix memory comman...
1046
  					*((u32 *)ptr) = i;
4d979bfdb   Simon Glass   common: Move and ...
1047
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1048
1049
1050
  				else if (size == 8)
  					*((u64 *)ptr) = i;
  #endif
3863585bb   wdenk   Initial revision
1051
  				else if (size == 2)
76698b4e6   York Sun   Fix memory comman...
1052
  					*((u16 *)ptr) = i;
3863585bb   wdenk   Initial revision
1053
  				else
76698b4e6   York Sun   Fix memory comman...
1054
  					*((u8 *)ptr) = i;
3863585bb   wdenk   Initial revision
1055
1056
1057
1058
1059
  				if (incrflag)
  					addr += size;
  			}
  		}
  	} while (nbytes);
0628ab8ec   Simon Glass   sandbox: Change m...
1060
1061
  	if (ptr)
  		unmap_sysmem(ptr);
3863585bb   wdenk   Initial revision
1062
1063
1064
1065
1066
  
  	mm_last_addr = addr;
  	mm_last_size = size;
  	return 0;
  }
710b99385   Mike Frysinger   crc32: make comma...
1067
  #ifdef CONFIG_CMD_CRC32
088f1b199   Kim Phillips   common/cmd_*.c: s...
1068
  static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
1069
  {
d20a40de9   Simon Glass   Roll crc32 into h...
1070
  	int flags = 0;
c26e454df   wdenk   Patches by Pantel...
1071
  	int ac;
54841ab50   Wolfgang Denk   Make sure that ar...
1072
  	char * const *av;
c26e454df   wdenk   Patches by Pantel...
1073

d20a40de9   Simon Glass   Roll crc32 into h...
1074
  	if (argc < 3)
4c12eeb8b   Simon Glass   Convert cmd_usage...
1075
  		return CMD_RET_USAGE;
c26e454df   wdenk   Patches by Pantel...
1076
1077
1078
  
  	av = argv + 1;
  	ac = argc - 1;
221a949eb   Daniel Thompson   Kconfig: Finish m...
1079
  #ifdef CONFIG_CRC32_VERIFY
c26e454df   wdenk   Patches by Pantel...
1080
  	if (strcmp(*av, "-v") == 0) {
a69bdba9c   Joe Hershberger   Fix broken verify...
1081
  		flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
c26e454df   wdenk   Patches by Pantel...
1082
1083
  		av++;
  		ac--;
c26e454df   wdenk   Patches by Pantel...
1084
  	}
d20a40de9   Simon Glass   Roll crc32 into h...
1085
  #endif
c26e454df   wdenk   Patches by Pantel...
1086

d20a40de9   Simon Glass   Roll crc32 into h...
1087
  	return hash_command("crc32", flags, cmdtp, flag, ac, av);
c26e454df   wdenk   Patches by Pantel...
1088
  }
c26e454df   wdenk   Patches by Pantel...
1089

710b99385   Mike Frysinger   crc32: make comma...
1090
  #endif
803e1a3d3   Jean-Jacques Hiblot   cmd: mem: Add a c...
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
  #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>]
  ", 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.
  ");
  			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
  ", len);
  	return 1;
  }
  #endif
8bde7f776   wdenk   * Code cleanup:
1136
  /**************************************************/
0d4983930   wdenk   Patch by Kenneth ...
1137
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1138
  	md,	3,	1,	do_mem_md,
2fb2604d5   Peter Tyser   Command usage cle...
1139
  	"memory display",
4d979bfdb   Simon Glass   common: Move and ...
1140
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1141
1142
  	"[.b, .w, .l, .q] address [# of objects]"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1143
  	"[.b, .w, .l] address [# of objects]"
4d1fd7f1a   York Sun   Add 64-bit data s...
1144
  #endif
8bde7f776   wdenk   * Code cleanup:
1145
  );
0d4983930   wdenk   Patch by Kenneth ...
1146
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1147
  	mm,	2,	1,	do_mem_mm,
a89c33db9   Wolfgang Denk   General help mess...
1148
  	"memory modify (auto-incrementing address)",
4d979bfdb   Simon Glass   common: Move and ...
1149
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1150
1151
  	"[.b, .w, .l, .q] address"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1152
  	"[.b, .w, .l] address"
4d1fd7f1a   York Sun   Add 64-bit data s...
1153
  #endif
8bde7f776   wdenk   * Code cleanup:
1154
  );
0d4983930   wdenk   Patch by Kenneth ...
1155
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1156
  	nm,	2,	1,	do_mem_nm,
2fb2604d5   Peter Tyser   Command usage cle...
1157
  	"memory modify (constant address)",
4d979bfdb   Simon Glass   common: Move and ...
1158
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1159
1160
  	"[.b, .w, .l, .q] address"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1161
  	"[.b, .w, .l] address"
4d1fd7f1a   York Sun   Add 64-bit data s...
1162
  #endif
8bde7f776   wdenk   * Code cleanup:
1163
  );
0d4983930   wdenk   Patch by Kenneth ...
1164
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1165
  	mw,	4,	1,	do_mem_mw,
2fb2604d5   Peter Tyser   Command usage cle...
1166
  	"memory write (fill)",
4d979bfdb   Simon Glass   common: Move and ...
1167
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1168
1169
  	"[.b, .w, .l, .q] address value [count]"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1170
  	"[.b, .w, .l] address value [count]"
4d1fd7f1a   York Sun   Add 64-bit data s...
1171
  #endif
8bde7f776   wdenk   * Code cleanup:
1172
  );
0d4983930   wdenk   Patch by Kenneth ...
1173
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1174
  	cp,	4,	1,	do_mem_cp,
2fb2604d5   Peter Tyser   Command usage cle...
1175
  	"memory copy",
4d979bfdb   Simon Glass   common: Move and ...
1176
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1177
1178
  	"[.b, .w, .l, .q] source target count"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1179
  	"[.b, .w, .l] source target count"
4d1fd7f1a   York Sun   Add 64-bit data s...
1180
  #endif
8bde7f776   wdenk   * Code cleanup:
1181
  );
0d4983930   wdenk   Patch by Kenneth ...
1182
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1183
  	cmp,	4,	1,	do_mem_cmp,
2fb2604d5   Peter Tyser   Command usage cle...
1184
  	"memory compare",
4d979bfdb   Simon Glass   common: Move and ...
1185
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1186
1187
  	"[.b, .w, .l, .q] addr1 addr2 count"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1188
  	"[.b, .w, .l] addr1 addr2 count"
4d1fd7f1a   York Sun   Add 64-bit data s...
1189
  #endif
8bde7f776   wdenk   * Code cleanup:
1190
  );
710b99385   Mike Frysinger   crc32: make comma...
1191
  #ifdef CONFIG_CMD_CRC32
221a949eb   Daniel Thompson   Kconfig: Finish m...
1192
  #ifndef CONFIG_CRC32_VERIFY
c26e454df   wdenk   Patches by Pantel...
1193

0d4983930   wdenk   Patch by Kenneth ...
1194
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1195
  	crc32,	4,	1,	do_mem_crc,
2fb2604d5   Peter Tyser   Command usage cle...
1196
  	"checksum calculation",
a89c33db9   Wolfgang Denk   General help mess...
1197
1198
  	"address count [addr]
      - compute CRC32 checksum [save at addr]"
8bde7f776   wdenk   * Code cleanup:
1199
  );
221a949eb   Daniel Thompson   Kconfig: Finish m...
1200
  #else	/* CONFIG_CRC32_VERIFY */
c26e454df   wdenk   Patches by Pantel...
1201
1202
  
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1203
  	crc32,	5,	1,	do_mem_crc,
2fb2604d5   Peter Tyser   Command usage cle...
1204
  	"checksum calculation",
c26e454df   wdenk   Patches by Pantel...
1205
1206
1207
  	"address count [addr]
      - compute CRC32 checksum [save at addr]
  "
a89c33db9   Wolfgang Denk   General help mess...
1208
1209
  	"-v address count crc
      - verify crc of memory area"
c26e454df   wdenk   Patches by Pantel...
1210
  );
221a949eb   Daniel Thompson   Kconfig: Finish m...
1211
  #endif	/* CONFIG_CRC32_VERIFY */
c26e454df   wdenk   Patches by Pantel...
1212

710b99385   Mike Frysinger   crc32: make comma...
1213
  #endif
15a33e49d   Simon Glass   Add option to dis...
1214
  #ifdef CONFIG_CMD_MEMINFO
15a33e49d   Simon Glass   Add option to dis...
1215
1216
1217
  static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc,
  		       char * const argv[])
  {
428a6a18f   Simon Glass   common: Drop boar...
1218
1219
1220
  	puts("DRAM:  ");
  	print_size(gd->ram_size, "
  ");
15a33e49d   Simon Glass   Add option to dis...
1221
1222
1223
1224
  
  	return 0;
  }
  #endif
0d4983930   wdenk   Patch by Kenneth ...
1225
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1226
  	base,	2,	1,	do_mem_base,
2fb2604d5   Peter Tyser   Command usage cle...
1227
  	"print or set address offset",
8bde7f776   wdenk   * Code cleanup:
1228
1229
1230
  	"
      - print address offset for memory commands
  "
a89c33db9   Wolfgang Denk   General help mess...
1231
1232
  	"base off
      - set address offset for memory commands to 'off'"
8bde7f776   wdenk   * Code cleanup:
1233
  );
0d4983930   wdenk   Patch by Kenneth ...
1234
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1235
  	loop,	3,	1,	do_mem_loop,
2fb2604d5   Peter Tyser   Command usage cle...
1236
  	"infinite loop on address range",
4d979bfdb   Simon Glass   common: Move and ...
1237
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1238
1239
  	"[.b, .w, .l, .q] address number_of_objects"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1240
  	"[.b, .w, .l] address number_of_objects"
4d1fd7f1a   York Sun   Add 64-bit data s...
1241
  #endif
8bde7f776   wdenk   * Code cleanup:
1242
  );
56523f128   wdenk   * Patch by Martin...
1243
1244
  #ifdef CONFIG_LOOPW
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1245
  	loopw,	4,	1,	do_mem_loopw,
2fb2604d5   Peter Tyser   Command usage cle...
1246
  	"infinite write loop on address range",
4d979bfdb   Simon Glass   common: Move and ...
1247
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1248
1249
  	"[.b, .w, .l, .q] address number_of_objects data_to_write"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1250
  	"[.b, .w, .l] address number_of_objects data_to_write"
4d1fd7f1a   York Sun   Add 64-bit data s...
1251
  #endif
56523f128   wdenk   * Patch by Martin...
1252
1253
  );
  #endif /* CONFIG_LOOPW */
a2681707b   Wolfgang Denk   Feature Removal: ...
1254
  #ifdef CONFIG_CMD_MEMTEST
0d4983930   wdenk   Patch by Kenneth ...
1255
  U_BOOT_CMD(
b6fc6fd49   Dirk Eibach   common: Iteration...
1256
  	mtest,	5,	1,	do_mem_mtest,
a89c33db9   Wolfgang Denk   General help mess...
1257
1258
  	"simple RAM read/write test",
  	"[start [end [pattern [iterations]]]]"
8bde7f776   wdenk   * Code cleanup:
1259
  );
a2681707b   Wolfgang Denk   Feature Removal: ...
1260
  #endif	/* CONFIG_CMD_MEMTEST */
8bde7f776   wdenk   * Code cleanup:
1261

72732318a   Joel Johnson   cmd: mdc/mwc: nor...
1262
  #ifdef CONFIG_CMD_MX_CYCLIC
4aaf29b2f   stroese   memory commands "...
1263
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1264
  	mdc,	4,	1,	do_mem_mdc,
2fb2604d5   Peter Tyser   Command usage cle...
1265
  	"memory display cyclic",
4d979bfdb   Simon Glass   common: Move and ...
1266
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1267
1268
  	"[.b, .w, .l, .q] address count delay(ms)"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1269
  	"[.b, .w, .l] address count delay(ms)"
4d1fd7f1a   York Sun   Add 64-bit data s...
1270
  #endif
4aaf29b2f   stroese   memory commands "...
1271
1272
1273
  );
  
  U_BOOT_CMD(
53677ef18   Wolfgang Denk   Big white-space c...
1274
  	mwc,	4,	1,	do_mem_mwc,
2fb2604d5   Peter Tyser   Command usage cle...
1275
  	"memory write cyclic",
4d979bfdb   Simon Glass   common: Move and ...
1276
  #ifdef MEM_SUPPORT_64BIT_DATA
4d1fd7f1a   York Sun   Add 64-bit data s...
1277
1278
  	"[.b, .w, .l, .q] address value delay(ms)"
  #else
a89c33db9   Wolfgang Denk   General help mess...
1279
  	"[.b, .w, .l] address value delay(ms)"
4d1fd7f1a   York Sun   Add 64-bit data s...
1280
  #endif
4aaf29b2f   stroese   memory commands "...
1281
  );
72732318a   Joel Johnson   cmd: mdc/mwc: nor...
1282
  #endif /* CONFIG_CMD_MX_CYCLIC */
15a33e49d   Simon Glass   Add option to dis...
1283
1284
1285
1286
1287
1288
1289
1290
  
  #ifdef CONFIG_CMD_MEMINFO
  U_BOOT_CMD(
  	meminfo,	3,	1,	do_mem_info,
  	"display memory information",
  	""
  );
  #endif
803e1a3d3   Jean-Jacques Hiblot   cmd: mem: Add a c...
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
  
  #ifdef CONFIG_CMD_RANDOM
  U_BOOT_CMD(
  	random,	4,	0,	do_random,
  	"fill memory with random pattern",
  	"<addr> <len> [<seed>]
  "
  	"   - Fill 'len' bytes of memory starting at 'addr' with random data
  "
  );
  #endif