blob: 91af7995b47400d83bb868b356a584052867356a [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * Memory Functions
26 *
27 * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
28 */
29
30#include <common.h>
31#include <command.h>
wdenk2abbe072003-06-16 23:50:08 +000032#ifdef CONFIG_HAS_DATAFLASH
33#include <dataflash.h>
34#endif
Sergei Poselenova6e6fc62008-04-09 16:09:41 +020035#include <watchdog.h>
wdenk38635852002-08-27 05:55:31 +000036
Wolfgang Denk54841ab2010-06-28 22:00:46 +020037static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000038
39/* Display values from last command.
40 * Memory modify remembered values are different from display memory.
41 */
Mike Frysingerd6efe242010-12-22 09:40:29 -050042static uint dp_last_addr, dp_last_size;
43static uint dp_last_length = 0x40;
44static uint mm_last_addr, mm_last_size;
wdenk38635852002-08-27 05:55:31 +000045
46static ulong base_address = 0;
47
48/* Memory Display
49 *
50 * Syntax:
51 * md{.b, .w, .l} {addr} {len}
52 */
53#define DISP_LINE_LEN 16
Wolfgang Denk54841ab2010-06-28 22:00:46 +020054int do_mem_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000055{
wdenk27b207f2003-07-24 23:38:38 +000056 ulong addr, length;
Grant Likelyc95c4282007-02-20 09:05:00 +010057#if defined(CONFIG_HAS_DATAFLASH)
58 ulong nbytes, linebytes;
59#endif
wdenk27b207f2003-07-24 23:38:38 +000060 int size;
wdenk38635852002-08-27 05:55:31 +000061 int rc = 0;
62
63 /* We use the last specified parameters, unless new ones are
64 * entered.
65 */
66 addr = dp_last_addr;
67 size = dp_last_size;
68 length = dp_last_length;
69
Wolfgang Denk47e26b12010-07-17 01:06:04 +020070 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000071 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000072
73 if ((flag & CMD_FLAG_REPEAT) == 0) {
74 /* New command specified. Check for a size specification.
75 * Defaults to long if no or incorrect specification.
76 */
wdenk27b207f2003-07-24 23:38:38 +000077 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
78 return 1;
wdenk38635852002-08-27 05:55:31 +000079
80 /* Address is specified since argc > 1
81 */
82 addr = simple_strtoul(argv[1], NULL, 16);
83 addr += base_address;
84
85 /* If another parameter, it is the length to display.
86 * Length is the number of objects, not number of bytes.
87 */
88 if (argc > 2)
89 length = simple_strtoul(argv[2], NULL, 16);
90 }
91
Grant Likelyc95c4282007-02-20 09:05:00 +010092#if defined(CONFIG_HAS_DATAFLASH)
wdenk38635852002-08-27 05:55:31 +000093 /* Print the lines.
94 *
95 * We buffer all read data, so we can make sure data is read only
96 * once, and all accesses are with the specified bus width.
97 */
98 nbytes = length * size;
99 do {
100 char linebuf[DISP_LINE_LEN];
Grant Likelyc95c4282007-02-20 09:05:00 +0100101 void* p;
wdenk38635852002-08-27 05:55:31 +0000102 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
wdenk2abbe072003-06-16 23:50:08 +0000103
Grant Likelyc95c4282007-02-20 09:05:00 +0100104 rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
105 p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
106 print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
wdenk8bde7f72003-06-27 21:31:46 +0000107
wdenk38635852002-08-27 05:55:31 +0000108 nbytes -= linebytes;
Grant Likelyc95c4282007-02-20 09:05:00 +0100109 addr += linebytes;
wdenk38635852002-08-27 05:55:31 +0000110 if (ctrlc()) {
111 rc = 1;
112 break;
113 }
114 } while (nbytes > 0);
Grant Likelyc95c4282007-02-20 09:05:00 +0100115#else
Mike Frysinger4c727c72008-02-04 19:26:56 -0500116
117# if defined(CONFIG_BLACKFIN)
118 /* See if we're trying to display L1 inst */
119 if (addr_bfin_on_chip_mem(addr)) {
120 char linebuf[DISP_LINE_LEN];
121 ulong linebytes, nbytes = length * size;
122 do {
123 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
124 memcpy(linebuf, (void *)addr, linebytes);
125 print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
126
127 nbytes -= linebytes;
128 addr += linebytes;
129 if (ctrlc()) {
130 rc = 1;
131 break;
132 }
133 } while (nbytes > 0);
134 } else
135# endif
136
137 {
138 /* Print the lines. */
Kumar Gala94c50f12011-11-12 08:02:12 +0000139 print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
140 addr += size*length;
Mike Frysinger4c727c72008-02-04 19:26:56 -0500141 }
Grant Likelyc95c4282007-02-20 09:05:00 +0100142#endif
wdenk38635852002-08-27 05:55:31 +0000143
144 dp_last_addr = addr;
145 dp_last_length = length;
146 dp_last_size = size;
147 return (rc);
148}
149
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200150int do_mem_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000151{
152 return mod_mem (cmdtp, 1, flag, argc, argv);
153}
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200154int do_mem_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000155{
156 return mod_mem (cmdtp, 0, flag, argc, argv);
157}
158
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200159int do_mem_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000160{
wdenk27b207f2003-07-24 23:38:38 +0000161 ulong addr, writeval, count;
162 int size;
wdenk38635852002-08-27 05:55:31 +0000163
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200164 if ((argc < 3) || (argc > 4))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000165 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000166
167 /* Check for size specification.
168 */
wdenk27b207f2003-07-24 23:38:38 +0000169 if ((size = cmd_get_data_size(argv[0], 4)) < 1)
170 return 1;
wdenk38635852002-08-27 05:55:31 +0000171
172 /* Address is specified since argc > 1
173 */
174 addr = simple_strtoul(argv[1], NULL, 16);
175 addr += base_address;
176
177 /* Get the value to write.
178 */
179 writeval = simple_strtoul(argv[2], NULL, 16);
180
181 /* Count ? */
182 if (argc == 4) {
183 count = simple_strtoul(argv[3], NULL, 16);
184 } else {
185 count = 1;
186 }
187
188 while (count-- > 0) {
189 if (size == 4)
190 *((ulong *)addr) = (ulong )writeval;
191 else if (size == 2)
192 *((ushort *)addr) = (ushort)writeval;
193 else
194 *((u_char *)addr) = (u_char)writeval;
195 addr += size;
196 }
197 return 0;
198}
199
stroese4aaf29b2004-12-16 17:42:39 +0000200#ifdef CONFIG_MX_CYCLIC
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200201int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000202{
203 int i;
204 ulong count;
205
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200206 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000207 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000208
209 count = simple_strtoul(argv[3], NULL, 10);
210
211 for (;;) {
212 do_mem_md (NULL, 0, 3, argv);
213
214 /* delay for <count> ms... */
215 for (i=0; i<count; i++)
216 udelay (1000);
217
218 /* check for ctrl-c to abort... */
219 if (ctrlc()) {
220 puts("Abort\n");
221 return 0;
222 }
223 }
224
225 return 0;
226}
227
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200228int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese4aaf29b2004-12-16 17:42:39 +0000229{
230 int i;
231 ulong count;
232
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200233 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000234 return CMD_RET_USAGE;
stroese4aaf29b2004-12-16 17:42:39 +0000235
236 count = simple_strtoul(argv[3], NULL, 10);
237
238 for (;;) {
239 do_mem_mw (NULL, 0, 3, argv);
240
241 /* delay for <count> ms... */
242 for (i=0; i<count; i++)
243 udelay (1000);
244
245 /* check for ctrl-c to abort... */
246 if (ctrlc()) {
247 puts("Abort\n");
248 return 0;
249 }
250 }
251
252 return 0;
253}
254#endif /* CONFIG_MX_CYCLIC */
255
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200256int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000257{
wdenk27b207f2003-07-24 23:38:38 +0000258 ulong addr1, addr2, count, ngood;
259 int size;
wdenk38635852002-08-27 05:55:31 +0000260 int rcode = 0;
261
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200262 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000263 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000264
265 /* Check for size specification.
266 */
wdenk27b207f2003-07-24 23:38:38 +0000267 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
268 return 1;
wdenk38635852002-08-27 05:55:31 +0000269
270 addr1 = simple_strtoul(argv[1], NULL, 16);
271 addr1 += base_address;
272
273 addr2 = simple_strtoul(argv[2], NULL, 16);
274 addr2 += base_address;
275
276 count = simple_strtoul(argv[3], NULL, 16);
277
wdenk2abbe072003-06-16 23:50:08 +0000278#ifdef CONFIG_HAS_DATAFLASH
279 if (addr_dataflash(addr1) | addr_dataflash(addr2)){
wdenk4b9206e2004-03-23 22:14:11 +0000280 puts ("Comparison with DataFlash space not supported.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000281 return 0;
282 }
283#endif
284
Mike Frysinger4c727c72008-02-04 19:26:56 -0500285#ifdef CONFIG_BLACKFIN
286 if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) {
287 puts ("Comparison with L1 instruction memory not supported.\n\r");
288 return 0;
289 }
290#endif
291
wdenk38635852002-08-27 05:55:31 +0000292 ngood = 0;
293
294 while (count-- > 0) {
295 if (size == 4) {
296 ulong word1 = *(ulong *)addr1;
297 ulong word2 = *(ulong *)addr2;
298 if (word1 != word2) {
299 printf("word at 0x%08lx (0x%08lx) "
300 "!= word at 0x%08lx (0x%08lx)\n",
301 addr1, word1, addr2, word2);
302 rcode = 1;
303 break;
304 }
305 }
306 else if (size == 2) {
307 ushort hword1 = *(ushort *)addr1;
308 ushort hword2 = *(ushort *)addr2;
309 if (hword1 != hword2) {
310 printf("halfword at 0x%08lx (0x%04x) "
311 "!= halfword at 0x%08lx (0x%04x)\n",
312 addr1, hword1, addr2, hword2);
313 rcode = 1;
314 break;
315 }
316 }
317 else {
318 u_char byte1 = *(u_char *)addr1;
319 u_char byte2 = *(u_char *)addr2;
320 if (byte1 != byte2) {
321 printf("byte at 0x%08lx (0x%02x) "
322 "!= byte at 0x%08lx (0x%02x)\n",
323 addr1, byte1, addr2, byte2);
324 rcode = 1;
325 break;
326 }
327 }
328 ngood++;
329 addr1 += size;
330 addr2 += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200331
332 /* reset watchdog from time to time */
333 if ((count % (64 << 10)) == 0)
334 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000335 }
336
337 printf("Total of %ld %s%s were the same\n",
338 ngood, size == 4 ? "word" : size == 2 ? "halfword" : "byte",
339 ngood == 1 ? "" : "s");
340 return rcode;
341}
342
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200343int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000344{
wdenk27b207f2003-07-24 23:38:38 +0000345 ulong addr, dest, count;
346 int size;
wdenk38635852002-08-27 05:55:31 +0000347
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200348 if (argc != 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000349 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000350
351 /* Check for size specification.
352 */
wdenk27b207f2003-07-24 23:38:38 +0000353 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
354 return 1;
wdenk38635852002-08-27 05:55:31 +0000355
356 addr = simple_strtoul(argv[1], NULL, 16);
357 addr += base_address;
358
359 dest = simple_strtoul(argv[2], NULL, 16);
360 dest += base_address;
361
362 count = simple_strtoul(argv[3], NULL, 16);
363
364 if (count == 0) {
365 puts ("Zero length ???\n");
366 return 1;
367 }
368
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200369#ifndef CONFIG_SYS_NO_FLASH
wdenk38635852002-08-27 05:55:31 +0000370 /* check if we are copying to Flash */
wdenk2abbe072003-06-16 23:50:08 +0000371 if ( (addr2info(dest) != NULL)
372#ifdef CONFIG_HAS_DATAFLASH
Kim B. Heino84d0c2f2008-03-03 10:39:13 +0200373 && (!addr_dataflash(dest))
wdenk2abbe072003-06-16 23:50:08 +0000374#endif
375 ) {
wdenk38635852002-08-27 05:55:31 +0000376 int rc;
377
wdenk4b9206e2004-03-23 22:14:11 +0000378 puts ("Copy to Flash... ");
wdenk38635852002-08-27 05:55:31 +0000379
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200380 rc = flash_write ((char *)addr, dest, count*size);
wdenk38635852002-08-27 05:55:31 +0000381 if (rc != 0) {
382 flash_perror (rc);
383 return (1);
384 }
385 puts ("done\n");
386 return 0;
387 }
388#endif
389
wdenk2abbe072003-06-16 23:50:08 +0000390#ifdef CONFIG_HAS_DATAFLASH
391 /* Check if we are copying from RAM or Flash to DataFlash */
392 if (addr_dataflash(dest) && !addr_dataflash(addr)){
393 int rc;
394
wdenk4b9206e2004-03-23 22:14:11 +0000395 puts ("Copy to DataFlash... ");
wdenk2abbe072003-06-16 23:50:08 +0000396
397 rc = write_dataflash (dest, addr, count*size);
398
399 if (rc != 1) {
400 dataflash_perror (rc);
401 return (1);
402 }
403 puts ("done\n");
404 return 0;
405 }
wdenk8bde7f72003-06-27 21:31:46 +0000406
wdenk2abbe072003-06-16 23:50:08 +0000407 /* Check if we are copying from DataFlash to RAM */
Stelian Pop880cc432008-03-26 22:52:35 +0100408 if (addr_dataflash(addr) && !addr_dataflash(dest)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200409#ifndef CONFIG_SYS_NO_FLASH
Stelian Pop880cc432008-03-26 22:52:35 +0100410 && (addr2info(dest) == NULL)
411#endif
412 ){
wdenk5779d8d2003-12-06 23:55:10 +0000413 int rc;
414 rc = read_dataflash(addr, count * size, (char *) dest);
415 if (rc != 1) {
wdenkd4ca31c2004-01-02 14:00:00 +0000416 dataflash_perror (rc);
417 return (1);
418 }
wdenk2abbe072003-06-16 23:50:08 +0000419 return 0;
420 }
421
422 if (addr_dataflash(addr) && addr_dataflash(dest)){
wdenk4b9206e2004-03-23 22:14:11 +0000423 puts ("Unsupported combination of source/destination.\n\r");
wdenk2abbe072003-06-16 23:50:08 +0000424 return 1;
425 }
426#endif
427
Mike Frysinger4c727c72008-02-04 19:26:56 -0500428#ifdef CONFIG_BLACKFIN
429 /* See if we're copying to/from L1 inst */
430 if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
431 memcpy((void *)dest, (void *)addr, count * size);
432 return 0;
433 }
434#endif
435
wdenk38635852002-08-27 05:55:31 +0000436 while (count-- > 0) {
437 if (size == 4)
438 *((ulong *)dest) = *((ulong *)addr);
439 else if (size == 2)
440 *((ushort *)dest) = *((ushort *)addr);
441 else
442 *((u_char *)dest) = *((u_char *)addr);
443 addr += size;
444 dest += size;
Stefan Roeseeaadb442010-09-13 11:10:34 +0200445
446 /* reset watchdog from time to time */
447 if ((count % (64 << 10)) == 0)
448 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000449 }
450 return 0;
451}
452
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200453int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000454{
455 if (argc > 1) {
456 /* Set new base address.
457 */
458 base_address = simple_strtoul(argv[1], NULL, 16);
459 }
460 /* Print the current base address.
461 */
462 printf("Base Address: 0x%08lx\n", base_address);
463 return 0;
464}
465
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200466int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000467{
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200468 ulong addr, length, i;
wdenk27b207f2003-07-24 23:38:38 +0000469 int size;
wdenk38635852002-08-27 05:55:31 +0000470 volatile uint *longp;
471 volatile ushort *shortp;
472 volatile u_char *cp;
473
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200474 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000475 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000476
477 /* Check for a size spefication.
478 * Defaults to long if no or incorrect specification.
479 */
wdenk27b207f2003-07-24 23:38:38 +0000480 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
481 return 1;
wdenk38635852002-08-27 05:55:31 +0000482
483 /* Address is always specified.
484 */
485 addr = simple_strtoul(argv[1], NULL, 16);
486
487 /* Length is the number of objects, not number of bytes.
488 */
489 length = simple_strtoul(argv[2], NULL, 16);
490
491 /* We want to optimize the loops to run as fast as possible.
492 * If we have only one object, just run infinite loops.
493 */
494 if (length == 1) {
495 if (size == 4) {
496 longp = (uint *)addr;
497 for (;;)
498 i = *longp;
499 }
500 if (size == 2) {
501 shortp = (ushort *)addr;
502 for (;;)
503 i = *shortp;
504 }
505 cp = (u_char *)addr;
506 for (;;)
507 i = *cp;
508 }
509
510 if (size == 4) {
511 for (;;) {
512 longp = (uint *)addr;
513 i = length;
514 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200515 *longp++;
wdenk38635852002-08-27 05:55:31 +0000516 }
517 }
518 if (size == 2) {
519 for (;;) {
520 shortp = (ushort *)addr;
521 i = length;
522 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200523 *shortp++;
wdenk38635852002-08-27 05:55:31 +0000524 }
525 }
526 for (;;) {
527 cp = (u_char *)addr;
528 i = length;
529 while (i-- > 0)
Marek Vasutf3b3c3d2011-09-26 02:26:06 +0200530 *cp++;
wdenk38635852002-08-27 05:55:31 +0000531 }
532}
533
wdenk56523f12004-07-11 17:40:54 +0000534#ifdef CONFIG_LOOPW
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200535int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk56523f12004-07-11 17:40:54 +0000536{
537 ulong addr, length, i, data;
538 int size;
539 volatile uint *longp;
540 volatile ushort *shortp;
541 volatile u_char *cp;
wdenk81050922004-07-11 20:04:51 +0000542
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200543 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000544 return CMD_RET_USAGE;
wdenk56523f12004-07-11 17:40:54 +0000545
546 /* Check for a size spefication.
547 * Defaults to long if no or incorrect specification.
548 */
549 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
550 return 1;
551
552 /* Address is always specified.
553 */
554 addr = simple_strtoul(argv[1], NULL, 16);
555
556 /* Length is the number of objects, not number of bytes.
557 */
558 length = simple_strtoul(argv[2], NULL, 16);
559
560 /* data to write */
561 data = simple_strtoul(argv[3], NULL, 16);
wdenk81050922004-07-11 20:04:51 +0000562
wdenk56523f12004-07-11 17:40:54 +0000563 /* We want to optimize the loops to run as fast as possible.
564 * If we have only one object, just run infinite loops.
565 */
566 if (length == 1) {
567 if (size == 4) {
568 longp = (uint *)addr;
569 for (;;)
570 *longp = data;
571 }
572 if (size == 2) {
573 shortp = (ushort *)addr;
574 for (;;)
575 *shortp = data;
576 }
577 cp = (u_char *)addr;
578 for (;;)
579 *cp = data;
580 }
581
582 if (size == 4) {
583 for (;;) {
584 longp = (uint *)addr;
585 i = length;
586 while (i-- > 0)
587 *longp++ = data;
588 }
589 }
590 if (size == 2) {
591 for (;;) {
592 shortp = (ushort *)addr;
593 i = length;
594 while (i-- > 0)
595 *shortp++ = data;
596 }
597 }
598 for (;;) {
599 cp = (u_char *)addr;
600 i = length;
601 while (i-- > 0)
602 *cp++ = data;
603 }
604}
605#endif /* CONFIG_LOOPW */
606
wdenk38635852002-08-27 05:55:31 +0000607/*
608 * Perform a memory test. A more complete alternative test can be
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200609 * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
wdenk38635852002-08-27 05:55:31 +0000610 * interrupted by ctrl-c or by a failure of one of the sub-tests.
611 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200612int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000613{
614 vu_long *addr, *start, *end;
615 ulong val;
616 ulong readback;
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400617 ulong errs = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100618 int iterations = 1;
619 int iteration_limit;
wdenk38635852002-08-27 05:55:31 +0000620
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200621#if defined(CONFIG_SYS_ALT_MEMTEST)
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100622 vu_long len;
wdenk38635852002-08-27 05:55:31 +0000623 vu_long offset;
624 vu_long test_offset;
625 vu_long pattern;
626 vu_long temp;
627 vu_long anti_pattern;
628 vu_long num_words;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200629#if defined(CONFIG_SYS_MEMTEST_SCRATCH)
630 vu_long *dummy = (vu_long*)CONFIG_SYS_MEMTEST_SCRATCH;
wdenk5f535fe2003-09-18 09:21:33 +0000631#else
Wolfgang Denk029b6dc2006-07-21 11:37:40 +0200632 vu_long *dummy = 0; /* yes, this is address 0x0, not NULL */
wdenk5f535fe2003-09-18 09:21:33 +0000633#endif
wdenk38635852002-08-27 05:55:31 +0000634 int j;
wdenk38635852002-08-27 05:55:31 +0000635
636 static const ulong bitpattern[] = {
637 0x00000001, /* single bit */
638 0x00000003, /* two adjacent bits */
639 0x00000007, /* three adjacent bits */
640 0x0000000F, /* four adjacent bits */
641 0x00000005, /* two non-adjacent bits */
642 0x00000015, /* three non-adjacent bits */
643 0x00000055, /* four non-adjacent bits */
644 0xaaaaaaaa, /* alternating 1/0 */
645 };
646#else
647 ulong incr;
648 ulong pattern;
wdenk38635852002-08-27 05:55:31 +0000649#endif
650
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100651 if (argc > 1)
wdenk38635852002-08-27 05:55:31 +0000652 start = (ulong *)simple_strtoul(argv[1], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100653 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200654 start = (ulong *)CONFIG_SYS_MEMTEST_START;
wdenk38635852002-08-27 05:55:31 +0000655
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100656 if (argc > 2)
wdenk38635852002-08-27 05:55:31 +0000657 end = (ulong *)simple_strtoul(argv[2], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100658 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200659 end = (ulong *)(CONFIG_SYS_MEMTEST_END);
wdenk38635852002-08-27 05:55:31 +0000660
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100661 if (argc > 3)
wdenk38635852002-08-27 05:55:31 +0000662 pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100663 else
wdenk38635852002-08-27 05:55:31 +0000664 pattern = 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100665
666 if (argc > 4)
667 iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
668 else
669 iteration_limit = 0;
wdenk38635852002-08-27 05:55:31 +0000670
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200671#if defined(CONFIG_SYS_ALT_MEMTEST)
wdenk38635852002-08-27 05:55:31 +0000672 printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
Mike Frysinger9504a552012-01-20 09:07:20 +0000673 debug("%s:%d: start 0x%p end 0x%p\n",
wdenk38635852002-08-27 05:55:31 +0000674 __FUNCTION__, __LINE__, start, end);
675
676 for (;;) {
677 if (ctrlc()) {
678 putc ('\n');
679 return 1;
680 }
681
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100682
683 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400684 printf("Tested %d iteration(s) with %lu errors.\n",
685 iterations-1, errs);
686 return errs != 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100687 }
688
wdenk38635852002-08-27 05:55:31 +0000689 printf("Iteration: %6d\r", iterations);
Mike Frysinger9504a552012-01-20 09:07:20 +0000690 debug("\n");
wdenk38635852002-08-27 05:55:31 +0000691 iterations++;
692
693 /*
694 * Data line test: write a pattern to the first
695 * location, write the 1's complement to a 'parking'
696 * address (changes the state of the data bus so a
697 * floating bus doen't give a false OK), and then
698 * read the value back. Note that we read it back
699 * into a variable because the next time we read it,
700 * it might be right (been there, tough to explain to
701 * the quality guys why it prints a failure when the
702 * "is" and "should be" are obviously the same in the
703 * error message).
704 *
705 * Rather than exhaustively testing, we test some
706 * patterns by shifting '1' bits through a field of
707 * '0's and '0' bits through a field of '1's (i.e.
708 * pattern and ~pattern).
709 */
710 addr = start;
711 for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
712 val = bitpattern[j];
713 for(; val != 0; val <<= 1) {
714 *addr = val;
715 *dummy = ~val; /* clear the test data off of the bus */
716 readback = *addr;
717 if(readback != val) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400718 printf ("FAILURE (data line): "
wdenk38635852002-08-27 05:55:31 +0000719 "expected %08lx, actual %08lx\n",
720 val, readback);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400721 errs++;
722 if (ctrlc()) {
723 putc ('\n');
724 return 1;
725 }
wdenk38635852002-08-27 05:55:31 +0000726 }
727 *addr = ~val;
728 *dummy = val;
729 readback = *addr;
730 if(readback != ~val) {
731 printf ("FAILURE (data line): "
732 "Is %08lx, should be %08lx\n",
wdenke1599e82004-10-10 23:27:33 +0000733 readback, ~val);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400734 errs++;
735 if (ctrlc()) {
736 putc ('\n');
737 return 1;
738 }
wdenk38635852002-08-27 05:55:31 +0000739 }
740 }
741 }
742
743 /*
744 * Based on code whose Original Author and Copyright
745 * information follows: Copyright (c) 1998 by Michael
746 * Barr. This software is placed into the public
747 * domain and may be used for any purpose. However,
748 * this notice must not be changed or removed and no
749 * warranty is either expressed or implied by its
750 * publication or distribution.
751 */
752
753 /*
754 * Address line test
755 *
756 * Description: Test the address bus wiring in a
757 * memory region by performing a walking
758 * 1's test on the relevant bits of the
759 * address and checking for aliasing.
760 * This test will find single-bit
761 * address failures such as stuck -high,
762 * stuck-low, and shorted pins. The base
763 * address and size of the region are
764 * selected by the caller.
765 *
766 * Notes: For best results, the selected base
767 * address should have enough LSB 0's to
768 * guarantee single address bit changes.
769 * For example, to test a 64-Kbyte
770 * region, select a base address on a
771 * 64-Kbyte boundary. Also, select the
772 * region size as a power-of-two if at
773 * all possible.
774 *
775 * Returns: 0 if the test succeeds, 1 if the test fails.
wdenk38635852002-08-27 05:55:31 +0000776 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100777 len = ((ulong)end - (ulong)start)/sizeof(vu_long);
wdenk38635852002-08-27 05:55:31 +0000778 pattern = (vu_long) 0xaaaaaaaa;
779 anti_pattern = (vu_long) 0x55555555;
780
Mike Frysinger9504a552012-01-20 09:07:20 +0000781 debug("%s:%d: length = 0x%.8lx\n",
wdenk38635852002-08-27 05:55:31 +0000782 __FUNCTION__, __LINE__,
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100783 len);
wdenk38635852002-08-27 05:55:31 +0000784 /*
785 * Write the default pattern at each of the
786 * power-of-two offsets.
787 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100788 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000789 start[offset] = pattern;
790 }
791
792 /*
793 * Check for address bits stuck high.
794 */
795 test_offset = 0;
796 start[test_offset] = anti_pattern;
797
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100798 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000799 temp = start[offset];
800 if (temp != pattern) {
801 printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
802 " expected 0x%.8lx, actual 0x%.8lx\n",
803 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400804 errs++;
805 if (ctrlc()) {
806 putc ('\n');
807 return 1;
808 }
wdenk38635852002-08-27 05:55:31 +0000809 }
810 }
811 start[test_offset] = pattern;
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200812 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000813
814 /*
815 * Check for addr bits stuck low or shorted.
816 */
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100817 for (test_offset = 1; test_offset < len; test_offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000818 start[test_offset] = anti_pattern;
819
Guennadi Liakhovetski6f4abee2008-02-08 21:25:58 +0100820 for (offset = 1; offset < len; offset <<= 1) {
wdenk38635852002-08-27 05:55:31 +0000821 temp = start[offset];
822 if ((temp != pattern) && (offset != test_offset)) {
823 printf ("\nFAILURE: Address bit stuck low or shorted @"
824 " 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
825 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400826 errs++;
827 if (ctrlc()) {
828 putc ('\n');
829 return 1;
830 }
wdenk38635852002-08-27 05:55:31 +0000831 }
832 }
833 start[test_offset] = pattern;
834 }
835
836 /*
837 * Description: Test the integrity of a physical
838 * memory device by performing an
839 * increment/decrement test over the
840 * entire region. In the process every
841 * storage bit in the device is tested
842 * as a zero and a one. The base address
843 * and the size of the region are
844 * selected by the caller.
845 *
846 * Returns: 0 if the test succeeds, 1 if the test fails.
847 */
848 num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
849
850 /*
851 * Fill memory with a known pattern.
852 */
853 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200854 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000855 start[offset] = pattern;
856 }
857
858 /*
859 * Check each location and invert it for the second pass.
860 */
861 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200862 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000863 temp = start[offset];
864 if (temp != pattern) {
865 printf ("\nFAILURE (read/write) @ 0x%.8lx:"
866 " expected 0x%.8lx, actual 0x%.8lx)\n",
867 (ulong)&start[offset], pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400868 errs++;
869 if (ctrlc()) {
870 putc ('\n');
871 return 1;
872 }
wdenk38635852002-08-27 05:55:31 +0000873 }
874
875 anti_pattern = ~pattern;
876 start[offset] = anti_pattern;
877 }
878
879 /*
880 * Check each location for the inverted pattern and zero it.
881 */
882 for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200883 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000884 anti_pattern = ~pattern;
885 temp = start[offset];
886 if (temp != anti_pattern) {
887 printf ("\nFAILURE (read/write): @ 0x%.8lx:"
888 " expected 0x%.8lx, actual 0x%.8lx)\n",
889 (ulong)&start[offset], anti_pattern, temp);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400890 errs++;
891 if (ctrlc()) {
892 putc ('\n');
893 return 1;
894 }
wdenk38635852002-08-27 05:55:31 +0000895 }
896 start[offset] = 0;
897 }
898 }
899
900#else /* The original, quickie test */
901 incr = 1;
902 for (;;) {
903 if (ctrlc()) {
904 putc ('\n');
905 return 1;
906 }
907
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100908 if (iteration_limit && iterations > iteration_limit) {
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400909 printf("Tested %d iteration(s) with %lu errors.\n",
910 iterations-1, errs);
911 return errs != 0;
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +0100912 }
913 ++iterations;
914
wdenk38635852002-08-27 05:55:31 +0000915 printf ("\rPattern %08lX Writing..."
916 "%12s"
917 "\b\b\b\b\b\b\b\b\b\b",
918 pattern, "");
919
920 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200921 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000922 *addr = val;
923 val += incr;
924 }
925
wdenk4b9206e2004-03-23 22:14:11 +0000926 puts ("Reading...");
wdenk38635852002-08-27 05:55:31 +0000927
928 for (addr=start,val=pattern; addr<end; addr++) {
Sergei Poselenova6e6fc62008-04-09 16:09:41 +0200929 WATCHDOG_RESET();
wdenk38635852002-08-27 05:55:31 +0000930 readback = *addr;
931 if (readback != val) {
932 printf ("\nMem error @ 0x%08X: "
933 "found %08lX, expected %08lX\n",
Simon Glass92549352011-09-17 06:48:58 +0000934 (uint)(uintptr_t)addr, readback, val);
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400935 errs++;
936 if (ctrlc()) {
937 putc ('\n');
938 return 1;
939 }
wdenk38635852002-08-27 05:55:31 +0000940 }
941 val += incr;
942 }
943
944 /*
945 * Flip the pattern each time to make lots of zeros and
946 * then, the next time, lots of ones. We decrement
947 * the "negative" patterns and increment the "positive"
948 * patterns to preserve this feature.
949 */
950 if(pattern & 0x80000000) {
951 pattern = -pattern; /* complement & increment */
952 }
953 else {
954 pattern = ~pattern;
955 }
956 incr = -incr;
957 }
wdenk38635852002-08-27 05:55:31 +0000958#endif
Paul Gortmaker87b22b72009-10-02 18:18:33 -0400959 return 0; /* not reached */
wdenk38635852002-08-27 05:55:31 +0000960}
961
962
963/* Modify memory.
964 *
965 * Syntax:
966 * mm{.b, .w, .l} {addr}
967 * nm{.b, .w, .l} {addr}
968 */
969static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200970mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000971{
wdenk27b207f2003-07-24 23:38:38 +0000972 ulong addr, i;
973 int nbytes, size;
wdenk38635852002-08-27 05:55:31 +0000974
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200975 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000976 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000977
978#ifdef CONFIG_BOOT_RETRY_TIME
979 reset_cmd_timeout(); /* got a good command to get here */
980#endif
981 /* We use the last specified parameters, unless new ones are
982 * entered.
983 */
984 addr = mm_last_addr;
985 size = mm_last_size;
986
987 if ((flag & CMD_FLAG_REPEAT) == 0) {
988 /* New command specified. Check for a size specification.
989 * Defaults to long if no or incorrect specification.
990 */
wdenk27b207f2003-07-24 23:38:38 +0000991 if ((size = cmd_get_data_size(argv[0], 4)) < 0)
992 return 1;
wdenk38635852002-08-27 05:55:31 +0000993
994 /* Address is specified since argc > 1
995 */
996 addr = simple_strtoul(argv[1], NULL, 16);
997 addr += base_address;
998 }
999
wdenk2abbe072003-06-16 23:50:08 +00001000#ifdef CONFIG_HAS_DATAFLASH
1001 if (addr_dataflash(addr)){
wdenk4b9206e2004-03-23 22:14:11 +00001002 puts ("Can't modify DataFlash in place. Use cp instead.\n\r");
wdenk2abbe072003-06-16 23:50:08 +00001003 return 0;
1004 }
1005#endif
1006
Mike Frysinger4c727c72008-02-04 19:26:56 -05001007#ifdef CONFIG_BLACKFIN
1008 if (addr_bfin_on_chip_mem(addr)) {
1009 puts ("Can't modify L1 instruction in place. Use cp instead.\n\r");
1010 return 0;
1011 }
1012#endif
1013
wdenk38635852002-08-27 05:55:31 +00001014 /* Print the address, followed by value. Then accept input for
1015 * the next value. A non-converted value exits.
1016 */
1017 do {
1018 printf("%08lx:", addr);
1019 if (size == 4)
1020 printf(" %08x", *((uint *)addr));
1021 else if (size == 2)
1022 printf(" %04x", *((ushort *)addr));
1023 else
1024 printf(" %02x", *((u_char *)addr));
1025
1026 nbytes = readline (" ? ");
1027 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
1028 /* <CR> pressed as only input, don't modify current
1029 * location and move to next. "-" pressed will go back.
1030 */
1031 if (incrflag)
1032 addr += nbytes ? -size : size;
1033 nbytes = 1;
1034#ifdef CONFIG_BOOT_RETRY_TIME
1035 reset_cmd_timeout(); /* good enough to not time out */
1036#endif
1037 }
1038#ifdef CONFIG_BOOT_RETRY_TIME
1039 else if (nbytes == -2) {
1040 break; /* timed out, exit the command */
1041 }
1042#endif
1043 else {
1044 char *endp;
1045 i = simple_strtoul(console_buffer, &endp, 16);
1046 nbytes = endp - console_buffer;
1047 if (nbytes) {
1048#ifdef CONFIG_BOOT_RETRY_TIME
1049 /* good enough to not time out
1050 */
1051 reset_cmd_timeout();
1052#endif
1053 if (size == 4)
1054 *((uint *)addr) = i;
1055 else if (size == 2)
1056 *((ushort *)addr) = i;
1057 else
1058 *((u_char *)addr) = i;
1059 if (incrflag)
1060 addr += size;
1061 }
1062 }
1063 } while (nbytes);
1064
1065 mm_last_addr = addr;
1066 mm_last_size = size;
1067 return 0;
1068}
1069
Mike Frysinger710b9932010-12-21 14:19:51 -05001070#ifdef CONFIG_CMD_CRC32
1071
wdenkc26e4542004-04-18 10:13:26 +00001072#ifndef CONFIG_CRC32_VERIFY
1073
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001074int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +00001075{
wdenk71f95112003-06-15 22:40:42 +00001076 ulong addr, length;
1077 ulong crc;
1078 ulong *ptr;
wdenk38635852002-08-27 05:55:31 +00001079
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001080 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001081 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +00001082
wdenk71f95112003-06-15 22:40:42 +00001083 addr = simple_strtoul (argv[1], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001084 addr += base_address;
1085
wdenk71f95112003-06-15 22:40:42 +00001086 length = simple_strtoul (argv[2], NULL, 16);
wdenk38635852002-08-27 05:55:31 +00001087
Jens Scharsig39c6e032011-07-18 08:46:26 +02001088 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
wdenk38635852002-08-27 05:55:31 +00001089
1090 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
wdenk71f95112003-06-15 22:40:42 +00001091 addr, addr + length - 1, crc);
wdenk38635852002-08-27 05:55:31 +00001092
wdenk71f95112003-06-15 22:40:42 +00001093 if (argc > 3) {
1094 ptr = (ulong *) simple_strtoul (argv[3], NULL, 16);
1095 *ptr = crc;
1096 }
wdenk38635852002-08-27 05:55:31 +00001097
1098 return 0;
1099}
1100
wdenkc26e4542004-04-18 10:13:26 +00001101#else /* CONFIG_CRC32_VERIFY */
1102
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001103int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc26e4542004-04-18 10:13:26 +00001104{
1105 ulong addr, length;
1106 ulong crc;
1107 ulong *ptr;
wdenk6e592382004-04-18 17:39:38 +00001108 ulong vcrc;
wdenkc26e4542004-04-18 10:13:26 +00001109 int verify;
1110 int ac;
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001111 char * const *av;
wdenkc26e4542004-04-18 10:13:26 +00001112
1113 if (argc < 3) {
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001114usage:
Simon Glass4c12eeb2011-12-10 08:44:01 +00001115 return CMD_RET_USAGE;
wdenkc26e4542004-04-18 10:13:26 +00001116 }
1117
1118 av = argv + 1;
1119 ac = argc - 1;
1120 if (strcmp(*av, "-v") == 0) {
1121 verify = 1;
1122 av++;
1123 ac--;
1124 if (ac < 3)
1125 goto usage;
1126 } else
1127 verify = 0;
1128
1129 addr = simple_strtoul(*av++, NULL, 16);
1130 addr += base_address;
1131 length = simple_strtoul(*av++, NULL, 16);
1132
Jens Scharsig39c6e032011-07-18 08:46:26 +02001133 crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
wdenkc26e4542004-04-18 10:13:26 +00001134
1135 if (!verify) {
1136 printf ("CRC32 for %08lx ... %08lx ==> %08lx\n",
1137 addr, addr + length - 1, crc);
1138 if (ac > 2) {
1139 ptr = (ulong *) simple_strtoul (*av++, NULL, 16);
1140 *ptr = crc;
1141 }
1142 } else {
1143 vcrc = simple_strtoul(*av++, NULL, 16);
1144 if (vcrc != crc) {
1145 printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n",
1146 addr, addr + length - 1, crc, vcrc);
1147 return 1;
1148 }
1149 }
1150
1151 return 0;
1152
1153}
1154#endif /* CONFIG_CRC32_VERIFY */
1155
Mike Frysinger710b9932010-12-21 14:19:51 -05001156#endif
1157
wdenk8bde7f72003-06-27 21:31:46 +00001158/**************************************************/
wdenk0d498392003-07-01 21:06:45 +00001159U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001160 md, 3, 1, do_mem_md,
Peter Tyser2fb26042009-01-27 18:03:12 -06001161 "memory display",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001162 "[.b, .w, .l] address [# of objects]"
wdenk8bde7f72003-06-27 21:31:46 +00001163);
1164
1165
wdenk0d498392003-07-01 21:06:45 +00001166U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001167 mm, 2, 1, do_mem_mm,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001168 "memory modify (auto-incrementing address)",
1169 "[.b, .w, .l] address"
wdenk8bde7f72003-06-27 21:31:46 +00001170);
1171
1172
wdenk0d498392003-07-01 21:06:45 +00001173U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001174 nm, 2, 1, do_mem_nm,
Peter Tyser2fb26042009-01-27 18:03:12 -06001175 "memory modify (constant address)",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001176 "[.b, .w, .l] address"
wdenk8bde7f72003-06-27 21:31:46 +00001177);
1178
wdenk0d498392003-07-01 21:06:45 +00001179U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001180 mw, 4, 1, do_mem_mw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001181 "memory write (fill)",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001182 "[.b, .w, .l] address value [count]"
wdenk8bde7f72003-06-27 21:31:46 +00001183);
1184
wdenk0d498392003-07-01 21:06:45 +00001185U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001186 cp, 4, 1, do_mem_cp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001187 "memory copy",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001188 "[.b, .w, .l] source target count"
wdenk8bde7f72003-06-27 21:31:46 +00001189);
1190
wdenk0d498392003-07-01 21:06:45 +00001191U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001192 cmp, 4, 1, do_mem_cmp,
Peter Tyser2fb26042009-01-27 18:03:12 -06001193 "memory compare",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001194 "[.b, .w, .l] addr1 addr2 count"
wdenk8bde7f72003-06-27 21:31:46 +00001195);
1196
Mike Frysinger710b9932010-12-21 14:19:51 -05001197#ifdef CONFIG_CMD_CRC32
1198
wdenkc26e4542004-04-18 10:13:26 +00001199#ifndef CONFIG_CRC32_VERIFY
1200
wdenk0d498392003-07-01 21:06:45 +00001201U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001202 crc32, 4, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001203 "checksum calculation",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001204 "address count [addr]\n - compute CRC32 checksum [save at addr]"
wdenk8bde7f72003-06-27 21:31:46 +00001205);
1206
wdenkc26e4542004-04-18 10:13:26 +00001207#else /* CONFIG_CRC32_VERIFY */
1208
1209U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001210 crc32, 5, 1, do_mem_crc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001211 "checksum calculation",
wdenkc26e4542004-04-18 10:13:26 +00001212 "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001213 "-v address count crc\n - verify crc of memory area"
wdenkc26e4542004-04-18 10:13:26 +00001214);
1215
1216#endif /* CONFIG_CRC32_VERIFY */
1217
Mike Frysinger710b9932010-12-21 14:19:51 -05001218#endif
1219
wdenk0d498392003-07-01 21:06:45 +00001220U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001221 base, 2, 1, do_mem_base,
Peter Tyser2fb26042009-01-27 18:03:12 -06001222 "print or set address offset",
wdenk8bde7f72003-06-27 21:31:46 +00001223 "\n - print address offset for memory commands\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001224 "base off\n - set address offset for memory commands to 'off'"
wdenk8bde7f72003-06-27 21:31:46 +00001225);
1226
wdenk0d498392003-07-01 21:06:45 +00001227U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001228 loop, 3, 1, do_mem_loop,
Peter Tyser2fb26042009-01-27 18:03:12 -06001229 "infinite loop on address range",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001230 "[.b, .w, .l] address number_of_objects"
wdenk8bde7f72003-06-27 21:31:46 +00001231);
1232
wdenk56523f12004-07-11 17:40:54 +00001233#ifdef CONFIG_LOOPW
1234U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001235 loopw, 4, 1, do_mem_loopw,
Peter Tyser2fb26042009-01-27 18:03:12 -06001236 "infinite write loop on address range",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001237 "[.b, .w, .l] address number_of_objects data_to_write"
wdenk56523f12004-07-11 17:40:54 +00001238);
1239#endif /* CONFIG_LOOPW */
1240
wdenk0d498392003-07-01 21:06:45 +00001241U_BOOT_CMD(
Dirk Eibachb6fc6fd2008-12-16 14:51:56 +01001242 mtest, 5, 1, do_mem_mtest,
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001243 "simple RAM read/write test",
1244 "[start [end [pattern [iterations]]]]"
wdenk8bde7f72003-06-27 21:31:46 +00001245);
1246
stroese4aaf29b2004-12-16 17:42:39 +00001247#ifdef CONFIG_MX_CYCLIC
1248U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001249 mdc, 4, 1, do_mem_mdc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001250 "memory display cyclic",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001251 "[.b, .w, .l] address count delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001252);
1253
1254U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +02001255 mwc, 4, 1, do_mem_mwc,
Peter Tyser2fb26042009-01-27 18:03:12 -06001256 "memory write cyclic",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001257 "[.b, .w, .l] address value delay(ms)"
stroese4aaf29b2004-12-16 17:42:39 +00001258);
1259#endif /* CONFIG_MX_CYCLIC */