]>
Commit | Line | Data |
---|---|---|
3863585b WD |
1 | /* |
2 | * (C) Copyright 2000 | |
3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
3863585b WD |
6 | */ |
7 | ||
8 | /* | |
9 | * Memory Functions | |
10 | * | |
11 | * Copied from FADS ROM, Dan Malek (dmalek@jlc.net) | |
12 | */ | |
13 | ||
14 | #include <common.h> | |
0098e179 | 15 | #include <bootretry.h> |
18d66533 | 16 | #include <cli.h> |
3863585b | 17 | #include <command.h> |
2abbe075 WD |
18 | #ifdef CONFIG_HAS_DATAFLASH |
19 | #include <dataflash.h> | |
20 | #endif | |
d20a40de | 21 | #include <hash.h> |
e48f3741 | 22 | #include <inttypes.h> |
a6e6fc61 | 23 | #include <watchdog.h> |
0628ab8e | 24 | #include <asm/io.h> |
15a33e49 SG |
25 | #include <linux/compiler.h> |
26 | ||
27 | DECLARE_GLOBAL_DATA_PTR; | |
3863585b | 28 | |
8e169cc9 SG |
29 | #ifndef CONFIG_SYS_MEMTEST_SCRATCH |
30 | #define CONFIG_SYS_MEMTEST_SCRATCH 0 | |
31 | #endif | |
32 | ||
54841ab5 | 33 | static int mod_mem(cmd_tbl_t *, int, int, int, char * const []); |
3863585b WD |
34 | |
35 | /* Display values from last command. | |
36 | * Memory modify remembered values are different from display memory. | |
37 | */ | |
d6efe244 MF |
38 | static uint dp_last_addr, dp_last_size; |
39 | static uint dp_last_length = 0x40; | |
40 | static uint mm_last_addr, mm_last_size; | |
3863585b WD |
41 | |
42 | static ulong base_address = 0; | |
43 | ||
44 | /* Memory Display | |
45 | * | |
46 | * Syntax: | |
4d1fd7f1 | 47 | * md{.b, .w, .l, .q} {addr} {len} |
3863585b WD |
48 | */ |
49 | #define DISP_LINE_LEN 16 | |
088f1b19 | 50 | static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b | 51 | { |
27b207fd | 52 | ulong addr, length; |
c95c4280 GL |
53 | #if defined(CONFIG_HAS_DATAFLASH) |
54 | ulong nbytes, linebytes; | |
55 | #endif | |
27b207fd | 56 | int size; |
3863585b WD |
57 | int rc = 0; |
58 | ||
59 | /* We use the last specified parameters, unless new ones are | |
60 | * entered. | |
61 | */ | |
62 | addr = dp_last_addr; | |
63 | size = dp_last_size; | |
64 | length = dp_last_length; | |
65 | ||
47e26b1b | 66 | if (argc < 2) |
4c12eeb8 | 67 | return CMD_RET_USAGE; |
3863585b WD |
68 | |
69 | if ((flag & CMD_FLAG_REPEAT) == 0) { | |
70 | /* New command specified. Check for a size specification. | |
71 | * Defaults to long if no or incorrect specification. | |
72 | */ | |
27b207fd WD |
73 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
74 | return 1; | |
3863585b WD |
75 | |
76 | /* Address is specified since argc > 1 | |
77 | */ | |
78 | addr = simple_strtoul(argv[1], NULL, 16); | |
79 | addr += base_address; | |
80 | ||
81 | /* If another parameter, it is the length to display. | |
82 | * Length is the number of objects, not number of bytes. | |
83 | */ | |
84 | if (argc > 2) | |
85 | length = simple_strtoul(argv[2], NULL, 16); | |
86 | } | |
87 | ||
c95c4280 | 88 | #if defined(CONFIG_HAS_DATAFLASH) |
3863585b WD |
89 | /* Print the lines. |
90 | * | |
91 | * We buffer all read data, so we can make sure data is read only | |
92 | * once, and all accesses are with the specified bus width. | |
93 | */ | |
94 | nbytes = length * size; | |
95 | do { | |
96 | char linebuf[DISP_LINE_LEN]; | |
c95c4280 | 97 | void* p; |
3863585b | 98 | linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes; |
2abbe075 | 99 | |
c95c4280 GL |
100 | rc = read_dataflash(addr, (linebytes/size)*size, linebuf); |
101 | p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr; | |
102 | print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size); | |
103 | ||
3863585b | 104 | nbytes -= linebytes; |
c95c4280 | 105 | addr += linebytes; |
3863585b WD |
106 | if (ctrlc()) { |
107 | rc = 1; | |
108 | break; | |
109 | } | |
110 | } while (nbytes > 0); | |
c95c4280 | 111 | #else |
4c727c77 MF |
112 | |
113 | # if defined(CONFIG_BLACKFIN) | |
114 | /* See if we're trying to display L1 inst */ | |
115 | if (addr_bfin_on_chip_mem(addr)) { | |
116 | char linebuf[DISP_LINE_LEN]; | |
117 | ulong linebytes, nbytes = length * size; | |
118 | do { | |
119 | linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes; | |
120 | memcpy(linebuf, (void *)addr, linebytes); | |
121 | print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size); | |
122 | ||
123 | nbytes -= linebytes; | |
124 | addr += linebytes; | |
125 | if (ctrlc()) { | |
126 | rc = 1; | |
127 | break; | |
128 | } | |
129 | } while (nbytes > 0); | |
130 | } else | |
131 | # endif | |
132 | ||
133 | { | |
0628ab8e SG |
134 | ulong bytes = size * length; |
135 | const void *buf = map_sysmem(addr, bytes); | |
136 | ||
4c727c77 | 137 | /* Print the lines. */ |
0628ab8e SG |
138 | print_buffer(addr, buf, size, length, DISP_LINE_LEN / size); |
139 | addr += bytes; | |
140 | unmap_sysmem(buf); | |
4c727c77 | 141 | } |
c95c4280 | 142 | #endif |
3863585b WD |
143 | |
144 | dp_last_addr = addr; | |
145 | dp_last_length = length; | |
146 | dp_last_size = size; | |
147 | return (rc); | |
148 | } | |
149 | ||
088f1b19 | 150 | static int do_mem_mm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b WD |
151 | { |
152 | return mod_mem (cmdtp, 1, flag, argc, argv); | |
153 | } | |
088f1b19 | 154 | static int do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b WD |
155 | { |
156 | return mod_mem (cmdtp, 0, flag, argc, argv); | |
157 | } | |
158 | ||
088f1b19 | 159 | static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b | 160 | { |
4d1fd7f1 YS |
161 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
162 | u64 writeval; | |
163 | #else | |
164 | ulong writeval; | |
165 | #endif | |
166 | ulong addr, count; | |
27b207fd | 167 | int size; |
cc5e196e | 168 | void *buf, *start; |
0628ab8e | 169 | ulong bytes; |
3863585b | 170 | |
47e26b1b | 171 | if ((argc < 3) || (argc > 4)) |
4c12eeb8 | 172 | return CMD_RET_USAGE; |
3863585b WD |
173 | |
174 | /* Check for size specification. | |
175 | */ | |
27b207fd WD |
176 | if ((size = cmd_get_data_size(argv[0], 4)) < 1) |
177 | return 1; | |
3863585b WD |
178 | |
179 | /* Address is specified since argc > 1 | |
180 | */ | |
181 | addr = simple_strtoul(argv[1], NULL, 16); | |
182 | addr += base_address; | |
183 | ||
184 | /* Get the value to write. | |
185 | */ | |
4d1fd7f1 YS |
186 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
187 | writeval = simple_strtoull(argv[2], NULL, 16); | |
188 | #else | |
3863585b | 189 | writeval = simple_strtoul(argv[2], NULL, 16); |
4d1fd7f1 | 190 | #endif |
3863585b WD |
191 | |
192 | /* Count ? */ | |
193 | if (argc == 4) { | |
194 | count = simple_strtoul(argv[3], NULL, 16); | |
195 | } else { | |
196 | count = 1; | |
197 | } | |
198 | ||
0628ab8e | 199 | bytes = size * count; |
cc5e196e SG |
200 | start = map_sysmem(addr, bytes); |
201 | buf = start; | |
3863585b WD |
202 | while (count-- > 0) { |
203 | if (size == 4) | |
76698b4e | 204 | *((u32 *)buf) = (u32)writeval; |
4d1fd7f1 YS |
205 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
206 | else if (size == 8) | |
207 | *((u64 *)buf) = (u64)writeval; | |
208 | #endif | |
3863585b | 209 | else if (size == 2) |
76698b4e | 210 | *((u16 *)buf) = (u16)writeval; |
3863585b | 211 | else |
76698b4e | 212 | *((u8 *)buf) = (u8)writeval; |
0628ab8e | 213 | buf += size; |
3863585b | 214 | } |
cc5e196e | 215 | unmap_sysmem(start); |
3863585b WD |
216 | return 0; |
217 | } | |
218 | ||
4aaf29b2 | 219 | #ifdef CONFIG_MX_CYCLIC |
5a8608e5 | 220 | static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
4aaf29b2 SR |
221 | { |
222 | int i; | |
223 | ulong count; | |
224 | ||
47e26b1b | 225 | if (argc < 4) |
4c12eeb8 | 226 | return CMD_RET_USAGE; |
4aaf29b2 SR |
227 | |
228 | count = simple_strtoul(argv[3], NULL, 10); | |
229 | ||
230 | for (;;) { | |
231 | do_mem_md (NULL, 0, 3, argv); | |
232 | ||
233 | /* delay for <count> ms... */ | |
234 | for (i=0; i<count; i++) | |
235 | udelay (1000); | |
236 | ||
237 | /* check for ctrl-c to abort... */ | |
238 | if (ctrlc()) { | |
239 | puts("Abort\n"); | |
240 | return 0; | |
241 | } | |
242 | } | |
243 | ||
244 | return 0; | |
245 | } | |
246 | ||
5a8608e5 | 247 | static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
4aaf29b2 SR |
248 | { |
249 | int i; | |
250 | ulong count; | |
251 | ||
47e26b1b | 252 | if (argc < 4) |
4c12eeb8 | 253 | return CMD_RET_USAGE; |
4aaf29b2 SR |
254 | |
255 | count = simple_strtoul(argv[3], NULL, 10); | |
256 | ||
257 | for (;;) { | |
258 | do_mem_mw (NULL, 0, 3, argv); | |
259 | ||
260 | /* delay for <count> ms... */ | |
261 | for (i=0; i<count; i++) | |
262 | udelay (1000); | |
263 | ||
264 | /* check for ctrl-c to abort... */ | |
265 | if (ctrlc()) { | |
266 | puts("Abort\n"); | |
267 | return 0; | |
268 | } | |
269 | } | |
270 | ||
271 | return 0; | |
272 | } | |
273 | #endif /* CONFIG_MX_CYCLIC */ | |
274 | ||
088f1b19 | 275 | static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b | 276 | { |
0628ab8e | 277 | ulong addr1, addr2, count, ngood, bytes; |
27b207fd | 278 | int size; |
3863585b | 279 | int rcode = 0; |
054ea170 | 280 | const char *type; |
0628ab8e | 281 | const void *buf1, *buf2, *base; |
4d1fd7f1 YS |
282 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
283 | u64 word1, word2; | |
284 | #else | |
285 | ulong word1, word2; | |
286 | #endif | |
3863585b | 287 | |
47e26b1b | 288 | if (argc != 4) |
4c12eeb8 | 289 | return CMD_RET_USAGE; |
3863585b WD |
290 | |
291 | /* Check for size specification. | |
292 | */ | |
27b207fd WD |
293 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
294 | return 1; | |
4d1fd7f1 YS |
295 | type = size == 8 ? "double word" : |
296 | size == 4 ? "word" : | |
297 | size == 2 ? "halfword" : "byte"; | |
3863585b WD |
298 | |
299 | addr1 = simple_strtoul(argv[1], NULL, 16); | |
300 | addr1 += base_address; | |
301 | ||
302 | addr2 = simple_strtoul(argv[2], NULL, 16); | |
303 | addr2 += base_address; | |
304 | ||
305 | count = simple_strtoul(argv[3], NULL, 16); | |
306 | ||
2abbe075 WD |
307 | #ifdef CONFIG_HAS_DATAFLASH |
308 | if (addr_dataflash(addr1) | addr_dataflash(addr2)){ | |
4b9206ed | 309 | puts ("Comparison with DataFlash space not supported.\n\r"); |
2abbe075 WD |
310 | return 0; |
311 | } | |
312 | #endif | |
313 | ||
4c727c77 MF |
314 | #ifdef CONFIG_BLACKFIN |
315 | if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) { | |
316 | puts ("Comparison with L1 instruction memory not supported.\n\r"); | |
317 | return 0; | |
318 | } | |
319 | #endif | |
320 | ||
0628ab8e SG |
321 | bytes = size * count; |
322 | base = buf1 = map_sysmem(addr1, bytes); | |
323 | buf2 = map_sysmem(addr2, bytes); | |
feb12a1f | 324 | for (ngood = 0; ngood < count; ++ngood) { |
3863585b | 325 | if (size == 4) { |
76698b4e YS |
326 | word1 = *(u32 *)buf1; |
327 | word2 = *(u32 *)buf2; | |
4d1fd7f1 YS |
328 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
329 | } else if (size == 8) { | |
330 | word1 = *(u64 *)buf1; | |
331 | word2 = *(u64 *)buf2; | |
332 | #endif | |
054ea170 | 333 | } else if (size == 2) { |
76698b4e YS |
334 | word1 = *(u16 *)buf1; |
335 | word2 = *(u16 *)buf2; | |
054ea170 | 336 | } else { |
76698b4e YS |
337 | word1 = *(u8 *)buf1; |
338 | word2 = *(u8 *)buf2; | |
3863585b | 339 | } |
054ea170 | 340 | if (word1 != word2) { |
0628ab8e | 341 | ulong offset = buf1 - base; |
4d1fd7f1 | 342 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
e48f3741 SG |
343 | printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*" |
344 | PRIx64 ")\n", | |
4d1fd7f1 YS |
345 | type, (void *)(addr1 + offset), size, word1, |
346 | type, (void *)(addr2 + offset), size, word2); | |
347 | #else | |
054ea170 | 348 | printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n", |
0628ab8e SG |
349 | type, (ulong)(addr1 + offset), size, word1, |
350 | type, (ulong)(addr2 + offset), size, word2); | |
4d1fd7f1 | 351 | #endif |
054ea170 MF |
352 | rcode = 1; |
353 | break; | |
3863585b | 354 | } |
054ea170 | 355 | |
0628ab8e SG |
356 | buf1 += size; |
357 | buf2 += size; | |
eaadb44e SR |
358 | |
359 | /* reset watchdog from time to time */ | |
feb12a1f | 360 | if ((ngood % (64 << 10)) == 0) |
eaadb44e | 361 | WATCHDOG_RESET(); |
3863585b | 362 | } |
0628ab8e SG |
363 | unmap_sysmem(buf1); |
364 | unmap_sysmem(buf2); | |
3863585b | 365 | |
054ea170 | 366 | printf("Total of %ld %s(s) were the same\n", ngood, type); |
3863585b WD |
367 | return rcode; |
368 | } | |
369 | ||
088f1b19 | 370 | static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b | 371 | { |
0628ab8e | 372 | ulong addr, dest, count, bytes; |
27b207fd | 373 | int size; |
0628ab8e SG |
374 | const void *src; |
375 | void *buf; | |
3863585b | 376 | |
47e26b1b | 377 | if (argc != 4) |
4c12eeb8 | 378 | return CMD_RET_USAGE; |
3863585b WD |
379 | |
380 | /* Check for size specification. | |
381 | */ | |
27b207fd WD |
382 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
383 | return 1; | |
3863585b WD |
384 | |
385 | addr = simple_strtoul(argv[1], NULL, 16); | |
386 | addr += base_address; | |
387 | ||
388 | dest = simple_strtoul(argv[2], NULL, 16); | |
389 | dest += base_address; | |
390 | ||
391 | count = simple_strtoul(argv[3], NULL, 16); | |
392 | ||
393 | if (count == 0) { | |
394 | puts ("Zero length ???\n"); | |
395 | return 1; | |
396 | } | |
397 | ||
6d0f6bcf | 398 | #ifndef CONFIG_SYS_NO_FLASH |
3863585b | 399 | /* check if we are copying to Flash */ |
2abbe075 WD |
400 | if ( (addr2info(dest) != NULL) |
401 | #ifdef CONFIG_HAS_DATAFLASH | |
84d0c2f1 | 402 | && (!addr_dataflash(dest)) |
2abbe075 WD |
403 | #endif |
404 | ) { | |
3863585b WD |
405 | int rc; |
406 | ||
4b9206ed | 407 | puts ("Copy to Flash... "); |
3863585b | 408 | |
77ddac94 | 409 | rc = flash_write ((char *)addr, dest, count*size); |
3863585b WD |
410 | if (rc != 0) { |
411 | flash_perror (rc); | |
412 | return (1); | |
413 | } | |
414 | puts ("done\n"); | |
415 | return 0; | |
416 | } | |
417 | #endif | |
418 | ||
2abbe075 WD |
419 | #ifdef CONFIG_HAS_DATAFLASH |
420 | /* Check if we are copying from RAM or Flash to DataFlash */ | |
421 | if (addr_dataflash(dest) && !addr_dataflash(addr)){ | |
422 | int rc; | |
423 | ||
4b9206ed | 424 | puts ("Copy to DataFlash... "); |
2abbe075 WD |
425 | |
426 | rc = write_dataflash (dest, addr, count*size); | |
427 | ||
428 | if (rc != 1) { | |
429 | dataflash_perror (rc); | |
430 | return (1); | |
431 | } | |
432 | puts ("done\n"); | |
433 | return 0; | |
434 | } | |
8bde7f77 | 435 | |
2abbe075 | 436 | /* Check if we are copying from DataFlash to RAM */ |
880cc438 | 437 | if (addr_dataflash(addr) && !addr_dataflash(dest) |
6d0f6bcf | 438 | #ifndef CONFIG_SYS_NO_FLASH |
880cc438 SP |
439 | && (addr2info(dest) == NULL) |
440 | #endif | |
441 | ){ | |
5779d8d9 WD |
442 | int rc; |
443 | rc = read_dataflash(addr, count * size, (char *) dest); | |
444 | if (rc != 1) { | |
d4ca31c4 WD |
445 | dataflash_perror (rc); |
446 | return (1); | |
447 | } | |
2abbe075 WD |
448 | return 0; |
449 | } | |
450 | ||
451 | if (addr_dataflash(addr) && addr_dataflash(dest)){ | |
4b9206ed | 452 | puts ("Unsupported combination of source/destination.\n\r"); |
2abbe075 WD |
453 | return 1; |
454 | } | |
455 | #endif | |
456 | ||
4c727c77 MF |
457 | #ifdef CONFIG_BLACKFIN |
458 | /* See if we're copying to/from L1 inst */ | |
459 | if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) { | |
460 | memcpy((void *)dest, (void *)addr, count * size); | |
461 | return 0; | |
462 | } | |
463 | #endif | |
464 | ||
0628ab8e | 465 | bytes = size * count; |
53237afe | 466 | buf = map_sysmem(dest, bytes); |
0628ab8e | 467 | src = map_sysmem(addr, bytes); |
3863585b WD |
468 | while (count-- > 0) { |
469 | if (size == 4) | |
76698b4e | 470 | *((u32 *)buf) = *((u32 *)src); |
4d1fd7f1 YS |
471 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
472 | else if (size == 8) | |
473 | *((u64 *)buf) = *((u64 *)src); | |
474 | #endif | |
3863585b | 475 | else if (size == 2) |
76698b4e | 476 | *((u16 *)buf) = *((u16 *)src); |
3863585b | 477 | else |
76698b4e | 478 | *((u8 *)buf) = *((u8 *)src); |
0628ab8e SG |
479 | src += size; |
480 | buf += size; | |
eaadb44e SR |
481 | |
482 | /* reset watchdog from time to time */ | |
483 | if ((count % (64 << 10)) == 0) | |
484 | WATCHDOG_RESET(); | |
3863585b | 485 | } |
a3a4749d MY |
486 | unmap_sysmem(buf); |
487 | unmap_sysmem(src); | |
488 | ||
3863585b WD |
489 | return 0; |
490 | } | |
491 | ||
088f1b19 KP |
492 | static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc, |
493 | char * const argv[]) | |
3863585b WD |
494 | { |
495 | if (argc > 1) { | |
496 | /* Set new base address. | |
497 | */ | |
498 | base_address = simple_strtoul(argv[1], NULL, 16); | |
499 | } | |
500 | /* Print the current base address. | |
501 | */ | |
502 | printf("Base Address: 0x%08lx\n", base_address); | |
503 | return 0; | |
504 | } | |
505 | ||
088f1b19 KP |
506 | static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, |
507 | char * const argv[]) | |
3863585b | 508 | { |
0628ab8e | 509 | ulong addr, length, i, bytes; |
27b207fd | 510 | int size; |
4d1fd7f1 YS |
511 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
512 | volatile u64 *llp; | |
513 | #endif | |
76698b4e YS |
514 | volatile u32 *longp; |
515 | volatile u16 *shortp; | |
516 | volatile u8 *cp; | |
0628ab8e | 517 | const void *buf; |
3863585b | 518 | |
47e26b1b | 519 | if (argc < 3) |
4c12eeb8 | 520 | return CMD_RET_USAGE; |
3863585b | 521 | |
85de63e2 RD |
522 | /* |
523 | * Check for a size specification. | |
3863585b WD |
524 | * Defaults to long if no or incorrect specification. |
525 | */ | |
27b207fd WD |
526 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
527 | return 1; | |
3863585b WD |
528 | |
529 | /* Address is always specified. | |
530 | */ | |
531 | addr = simple_strtoul(argv[1], NULL, 16); | |
532 | ||
533 | /* Length is the number of objects, not number of bytes. | |
534 | */ | |
535 | length = simple_strtoul(argv[2], NULL, 16); | |
536 | ||
0628ab8e SG |
537 | bytes = size * length; |
538 | buf = map_sysmem(addr, bytes); | |
539 | ||
3863585b WD |
540 | /* We want to optimize the loops to run as fast as possible. |
541 | * If we have only one object, just run infinite loops. | |
542 | */ | |
543 | if (length == 1) { | |
4d1fd7f1 YS |
544 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
545 | if (size == 8) { | |
546 | llp = (u64 *)buf; | |
547 | for (;;) | |
548 | i = *llp; | |
549 | } | |
550 | #endif | |
3863585b | 551 | if (size == 4) { |
76698b4e | 552 | longp = (u32 *)buf; |
3863585b WD |
553 | for (;;) |
554 | i = *longp; | |
555 | } | |
556 | if (size == 2) { | |
76698b4e | 557 | shortp = (u16 *)buf; |
3863585b WD |
558 | for (;;) |
559 | i = *shortp; | |
560 | } | |
76698b4e | 561 | cp = (u8 *)buf; |
3863585b WD |
562 | for (;;) |
563 | i = *cp; | |
564 | } | |
565 | ||
4d1fd7f1 YS |
566 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
567 | if (size == 8) { | |
568 | for (;;) { | |
569 | llp = (u64 *)buf; | |
570 | i = length; | |
571 | while (i-- > 0) | |
572 | *llp++; | |
573 | } | |
574 | } | |
575 | #endif | |
3863585b WD |
576 | if (size == 4) { |
577 | for (;;) { | |
76698b4e | 578 | longp = (u32 *)buf; |
3863585b WD |
579 | i = length; |
580 | while (i-- > 0) | |
f3b3c3df | 581 | *longp++; |
3863585b WD |
582 | } |
583 | } | |
584 | if (size == 2) { | |
585 | for (;;) { | |
76698b4e | 586 | shortp = (u16 *)buf; |
3863585b WD |
587 | i = length; |
588 | while (i-- > 0) | |
f3b3c3df | 589 | *shortp++; |
3863585b WD |
590 | } |
591 | } | |
592 | for (;;) { | |
76698b4e | 593 | cp = (u8 *)buf; |
3863585b WD |
594 | i = length; |
595 | while (i-- > 0) | |
f3b3c3df | 596 | *cp++; |
3863585b | 597 | } |
0628ab8e | 598 | unmap_sysmem(buf); |
92765f42 SG |
599 | |
600 | return 0; | |
3863585b WD |
601 | } |
602 | ||
56523f12 | 603 | #ifdef CONFIG_LOOPW |
5a8608e5 MY |
604 | static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc, |
605 | char * const argv[]) | |
56523f12 | 606 | { |
4d1fd7f1 | 607 | ulong addr, length, i, bytes; |
56523f12 | 608 | int size; |
4d1fd7f1 YS |
609 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
610 | volatile u64 *llp; | |
611 | u64 data; | |
612 | #else | |
613 | ulong data; | |
614 | #endif | |
76698b4e YS |
615 | volatile u32 *longp; |
616 | volatile u16 *shortp; | |
617 | volatile u8 *cp; | |
0628ab8e | 618 | void *buf; |
81050926 | 619 | |
47e26b1b | 620 | if (argc < 4) |
4c12eeb8 | 621 | return CMD_RET_USAGE; |
56523f12 | 622 | |
85de63e2 RD |
623 | /* |
624 | * Check for a size specification. | |
56523f12 WD |
625 | * Defaults to long if no or incorrect specification. |
626 | */ | |
627 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) | |
628 | return 1; | |
629 | ||
630 | /* Address is always specified. | |
631 | */ | |
632 | addr = simple_strtoul(argv[1], NULL, 16); | |
633 | ||
634 | /* Length is the number of objects, not number of bytes. | |
635 | */ | |
636 | length = simple_strtoul(argv[2], NULL, 16); | |
637 | ||
638 | /* data to write */ | |
4d1fd7f1 YS |
639 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
640 | data = simple_strtoull(argv[3], NULL, 16); | |
641 | #else | |
56523f12 | 642 | data = simple_strtoul(argv[3], NULL, 16); |
4d1fd7f1 | 643 | #endif |
81050926 | 644 | |
0628ab8e SG |
645 | bytes = size * length; |
646 | buf = map_sysmem(addr, bytes); | |
647 | ||
56523f12 WD |
648 | /* We want to optimize the loops to run as fast as possible. |
649 | * If we have only one object, just run infinite loops. | |
650 | */ | |
651 | if (length == 1) { | |
4d1fd7f1 YS |
652 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
653 | if (size == 8) { | |
654 | llp = (u64 *)buf; | |
655 | for (;;) | |
656 | *llp = data; | |
657 | } | |
658 | #endif | |
56523f12 | 659 | if (size == 4) { |
76698b4e | 660 | longp = (u32 *)buf; |
56523f12 WD |
661 | for (;;) |
662 | *longp = data; | |
4d1fd7f1 | 663 | } |
56523f12 | 664 | if (size == 2) { |
76698b4e | 665 | shortp = (u16 *)buf; |
56523f12 WD |
666 | for (;;) |
667 | *shortp = data; | |
668 | } | |
76698b4e | 669 | cp = (u8 *)buf; |
56523f12 WD |
670 | for (;;) |
671 | *cp = data; | |
672 | } | |
673 | ||
4d1fd7f1 YS |
674 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
675 | if (size == 8) { | |
676 | for (;;) { | |
677 | llp = (u64 *)buf; | |
678 | i = length; | |
679 | while (i-- > 0) | |
680 | *llp++ = data; | |
681 | } | |
682 | } | |
683 | #endif | |
56523f12 WD |
684 | if (size == 4) { |
685 | for (;;) { | |
76698b4e | 686 | longp = (u32 *)buf; |
56523f12 WD |
687 | i = length; |
688 | while (i-- > 0) | |
689 | *longp++ = data; | |
690 | } | |
691 | } | |
692 | if (size == 2) { | |
693 | for (;;) { | |
76698b4e | 694 | shortp = (u16 *)buf; |
56523f12 WD |
695 | i = length; |
696 | while (i-- > 0) | |
697 | *shortp++ = data; | |
698 | } | |
699 | } | |
700 | for (;;) { | |
76698b4e | 701 | cp = (u8 *)buf; |
56523f12 WD |
702 | i = length; |
703 | while (i-- > 0) | |
704 | *cp++ = data; | |
705 | } | |
706 | } | |
707 | #endif /* CONFIG_LOOPW */ | |
708 | ||
68149e94 | 709 | #ifdef CONFIG_CMD_MEMTEST |
5512d5b0 SG |
710 | static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, |
711 | vu_long *dummy) | |
3863585b | 712 | { |
c9638f50 | 713 | vu_long *addr; |
c9638f50 SG |
714 | ulong errs = 0; |
715 | ulong val, readback; | |
716 | int j; | |
c9638f50 SG |
717 | vu_long offset; |
718 | vu_long test_offset; | |
719 | vu_long pattern; | |
720 | vu_long temp; | |
721 | vu_long anti_pattern; | |
722 | vu_long num_words; | |
3863585b WD |
723 | static const ulong bitpattern[] = { |
724 | 0x00000001, /* single bit */ | |
725 | 0x00000003, /* two adjacent bits */ | |
726 | 0x00000007, /* three adjacent bits */ | |
727 | 0x0000000F, /* four adjacent bits */ | |
728 | 0x00000005, /* two non-adjacent bits */ | |
729 | 0x00000015, /* three non-adjacent bits */ | |
730 | 0x00000055, /* four non-adjacent bits */ | |
731 | 0xaaaaaaaa, /* alternating 1/0 */ | |
732 | }; | |
3863585b | 733 | |
5512d5b0 | 734 | num_words = (end_addr - start_addr) / sizeof(vu_long); |
8c86bbe0 | 735 | |
7ecbd4d7 SG |
736 | /* |
737 | * Data line test: write a pattern to the first | |
738 | * location, write the 1's complement to a 'parking' | |
739 | * address (changes the state of the data bus so a | |
740 | * floating bus doesn't give a false OK), and then | |
741 | * read the value back. Note that we read it back | |
742 | * into a variable because the next time we read it, | |
743 | * it might be right (been there, tough to explain to | |
744 | * the quality guys why it prints a failure when the | |
745 | * "is" and "should be" are obviously the same in the | |
746 | * error message). | |
747 | * | |
748 | * Rather than exhaustively testing, we test some | |
749 | * patterns by shifting '1' bits through a field of | |
750 | * '0's and '0' bits through a field of '1's (i.e. | |
751 | * pattern and ~pattern). | |
752 | */ | |
5512d5b0 | 753 | addr = buf; |
7ecbd4d7 SG |
754 | for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) { |
755 | val = bitpattern[j]; | |
756 | for (; val != 0; val <<= 1) { | |
5512d5b0 | 757 | *addr = val; |
c9638f50 | 758 | *dummy = ~val; /* clear the test data off the bus */ |
3863585b | 759 | readback = *addr; |
7ecbd4d7 | 760 | if (readback != val) { |
c9638f50 SG |
761 | printf("FAILURE (data line): " |
762 | "expected %08lx, actual %08lx\n", | |
763 | val, readback); | |
764 | errs++; | |
c44d4386 | 765 | if (ctrlc()) |
51209b1f | 766 | return -1; |
3863585b WD |
767 | } |
768 | *addr = ~val; | |
769 | *dummy = val; | |
770 | readback = *addr; | |
c9638f50 SG |
771 | if (readback != ~val) { |
772 | printf("FAILURE (data line): " | |
773 | "Is %08lx, should be %08lx\n", | |
774 | readback, ~val); | |
775 | errs++; | |
c44d4386 | 776 | if (ctrlc()) |
51209b1f | 777 | return -1; |
3863585b | 778 | } |
3863585b | 779 | } |
7ecbd4d7 | 780 | } |
3863585b | 781 | |
7ecbd4d7 SG |
782 | /* |
783 | * Based on code whose Original Author and Copyright | |
784 | * information follows: Copyright (c) 1998 by Michael | |
785 | * Barr. This software is placed into the public | |
786 | * domain and may be used for any purpose. However, | |
787 | * this notice must not be changed or removed and no | |
788 | * warranty is either expressed or implied by its | |
789 | * publication or distribution. | |
790 | */ | |
3863585b | 791 | |
7ecbd4d7 SG |
792 | /* |
793 | * Address line test | |
794 | ||
795 | * Description: Test the address bus wiring in a | |
796 | * memory region by performing a walking | |
797 | * 1's test on the relevant bits of the | |
798 | * address and checking for aliasing. | |
799 | * This test will find single-bit | |
800 | * address failures such as stuck-high, | |
801 | * stuck-low, and shorted pins. The base | |
802 | * address and size of the region are | |
803 | * selected by the caller. | |
804 | ||
805 | * Notes: For best results, the selected base | |
806 | * address should have enough LSB 0's to | |
807 | * guarantee single address bit changes. | |
808 | * For example, to test a 64-Kbyte | |
809 | * region, select a base address on a | |
810 | * 64-Kbyte boundary. Also, select the | |
811 | * region size as a power-of-two if at | |
812 | * all possible. | |
813 | * | |
814 | * Returns: 0 if the test succeeds, 1 if the test fails. | |
815 | */ | |
7ecbd4d7 SG |
816 | pattern = (vu_long) 0xaaaaaaaa; |
817 | anti_pattern = (vu_long) 0x55555555; | |
3863585b | 818 | |
5512d5b0 | 819 | debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words); |
7ecbd4d7 SG |
820 | /* |
821 | * Write the default pattern at each of the | |
822 | * power-of-two offsets. | |
823 | */ | |
5512d5b0 SG |
824 | for (offset = 1; offset < num_words; offset <<= 1) |
825 | addr[offset] = pattern; | |
3863585b | 826 | |
7ecbd4d7 SG |
827 | /* |
828 | * Check for address bits stuck high. | |
829 | */ | |
830 | test_offset = 0; | |
5512d5b0 | 831 | addr[test_offset] = anti_pattern; |
3863585b | 832 | |
5512d5b0 SG |
833 | for (offset = 1; offset < num_words; offset <<= 1) { |
834 | temp = addr[offset]; | |
7ecbd4d7 | 835 | if (temp != pattern) { |
c9638f50 | 836 | printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:" |
3863585b | 837 | " expected 0x%.8lx, actual 0x%.8lx\n", |
102c051f DF |
838 | start_addr + offset*sizeof(vu_long), |
839 | pattern, temp); | |
87b22b77 | 840 | errs++; |
c44d4386 | 841 | if (ctrlc()) |
7ecbd4d7 | 842 | return -1; |
3863585b | 843 | } |
7ecbd4d7 | 844 | } |
5512d5b0 | 845 | addr[test_offset] = pattern; |
7ecbd4d7 | 846 | WATCHDOG_RESET(); |
3863585b | 847 | |
7ecbd4d7 SG |
848 | /* |
849 | * Check for addr bits stuck low or shorted. | |
850 | */ | |
5512d5b0 SG |
851 | for (test_offset = 1; test_offset < num_words; test_offset <<= 1) { |
852 | addr[test_offset] = anti_pattern; | |
3863585b | 853 | |
5512d5b0 SG |
854 | for (offset = 1; offset < num_words; offset <<= 1) { |
855 | temp = addr[offset]; | |
3863585b | 856 | if ((temp != pattern) && (offset != test_offset)) { |
7ecbd4d7 SG |
857 | printf("\nFAILURE: Address bit stuck low or" |
858 | " shorted @ 0x%.8lx: expected 0x%.8lx," | |
859 | " actual 0x%.8lx\n", | |
102c051f DF |
860 | start_addr + offset*sizeof(vu_long), |
861 | pattern, temp); | |
7ecbd4d7 | 862 | errs++; |
c44d4386 | 863 | if (ctrlc()) |
7ecbd4d7 | 864 | return -1; |
3863585b | 865 | } |
3863585b | 866 | } |
5512d5b0 | 867 | addr[test_offset] = pattern; |
7ecbd4d7 | 868 | } |
3863585b | 869 | |
7ecbd4d7 SG |
870 | /* |
871 | * Description: Test the integrity of a physical | |
872 | * memory device by performing an | |
873 | * increment/decrement test over the | |
874 | * entire region. In the process every | |
875 | * storage bit in the device is tested | |
876 | * as a zero and a one. The base address | |
877 | * and the size of the region are | |
878 | * selected by the caller. | |
879 | * | |
880 | * Returns: 0 if the test succeeds, 1 if the test fails. | |
881 | */ | |
5512d5b0 | 882 | num_words++; |
3863585b | 883 | |
7ecbd4d7 SG |
884 | /* |
885 | * Fill memory with a known pattern. | |
886 | */ | |
887 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { | |
888 | WATCHDOG_RESET(); | |
5512d5b0 | 889 | addr[offset] = pattern; |
7ecbd4d7 | 890 | } |
3863585b | 891 | |
7ecbd4d7 SG |
892 | /* |
893 | * Check each location and invert it for the second pass. | |
894 | */ | |
895 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { | |
896 | WATCHDOG_RESET(); | |
5512d5b0 | 897 | temp = addr[offset]; |
7ecbd4d7 | 898 | if (temp != pattern) { |
c9638f50 | 899 | printf("\nFAILURE (read/write) @ 0x%.8lx:" |
3863585b | 900 | " expected 0x%.8lx, actual 0x%.8lx)\n", |
102c051f DF |
901 | start_addr + offset*sizeof(vu_long), |
902 | pattern, temp); | |
87b22b77 | 903 | errs++; |
c44d4386 | 904 | if (ctrlc()) |
51209b1f | 905 | return -1; |
3863585b WD |
906 | } |
907 | ||
7ecbd4d7 | 908 | anti_pattern = ~pattern; |
5512d5b0 | 909 | addr[offset] = anti_pattern; |
7ecbd4d7 SG |
910 | } |
911 | ||
912 | /* | |
913 | * Check each location for the inverted pattern and zero it. | |
914 | */ | |
915 | for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { | |
916 | WATCHDOG_RESET(); | |
917 | anti_pattern = ~pattern; | |
5512d5b0 | 918 | temp = addr[offset]; |
7ecbd4d7 | 919 | if (temp != anti_pattern) { |
c9638f50 | 920 | printf("\nFAILURE (read/write): @ 0x%.8lx:" |
3863585b | 921 | " expected 0x%.8lx, actual 0x%.8lx)\n", |
102c051f DF |
922 | start_addr + offset*sizeof(vu_long), |
923 | anti_pattern, temp); | |
87b22b77 | 924 | errs++; |
c44d4386 | 925 | if (ctrlc()) |
51209b1f | 926 | return -1; |
3863585b | 927 | } |
5512d5b0 | 928 | addr[offset] = 0; |
7ecbd4d7 | 929 | } |
51209b1f SG |
930 | |
931 | return 0; | |
c9638f50 SG |
932 | } |
933 | ||
5512d5b0 SG |
934 | static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, |
935 | vu_long pattern, int iteration) | |
c9638f50 | 936 | { |
5512d5b0 | 937 | vu_long *end; |
c9638f50 | 938 | vu_long *addr; |
c9638f50 | 939 | ulong errs = 0; |
5512d5b0 | 940 | ulong incr, length; |
c9638f50 | 941 | ulong val, readback; |
3863585b | 942 | |
51209b1f | 943 | /* Alternate the pattern */ |
3863585b | 944 | incr = 1; |
51209b1f SG |
945 | if (iteration & 1) { |
946 | incr = -incr; | |
947 | /* | |
948 | * Flip the pattern each time to make lots of zeros and | |
949 | * then, the next time, lots of ones. We decrement | |
950 | * the "negative" patterns and increment the "positive" | |
951 | * patterns to preserve this feature. | |
952 | */ | |
953 | if (pattern & 0x80000000) | |
954 | pattern = -pattern; /* complement & increment */ | |
955 | else | |
956 | pattern = ~pattern; | |
957 | } | |
5512d5b0 SG |
958 | length = (end_addr - start_addr) / sizeof(ulong); |
959 | end = buf + length; | |
7ecbd4d7 SG |
960 | printf("\rPattern %08lX Writing..." |
961 | "%12s" | |
962 | "\b\b\b\b\b\b\b\b\b\b", | |
963 | pattern, ""); | |
3863585b | 964 | |
5512d5b0 | 965 | for (addr = buf, val = pattern; addr < end; addr++) { |
7ecbd4d7 SG |
966 | WATCHDOG_RESET(); |
967 | *addr = val; | |
968 | val += incr; | |
969 | } | |
3863585b | 970 | |
7ecbd4d7 | 971 | puts("Reading..."); |
3863585b | 972 | |
5512d5b0 | 973 | for (addr = buf, val = pattern; addr < end; addr++) { |
7ecbd4d7 SG |
974 | WATCHDOG_RESET(); |
975 | readback = *addr; | |
976 | if (readback != val) { | |
5512d5b0 SG |
977 | ulong offset = addr - buf; |
978 | ||
7ecbd4d7 SG |
979 | printf("\nMem error @ 0x%08X: " |
980 | "found %08lX, expected %08lX\n", | |
102c051f | 981 | (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)), |
5512d5b0 | 982 | readback, val); |
7ecbd4d7 | 983 | errs++; |
c44d4386 | 984 | if (ctrlc()) |
7ecbd4d7 | 985 | return -1; |
3863585b | 986 | } |
7ecbd4d7 SG |
987 | val += incr; |
988 | } | |
3863585b | 989 | |
51209b1f | 990 | return 0; |
c9638f50 SG |
991 | } |
992 | ||
993 | /* | |
994 | * Perform a memory test. A more complete alternative test can be | |
995 | * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until | |
996 | * interrupted by ctrl-c or by a failure of one of the sub-tests. | |
997 | */ | |
998 | static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, | |
999 | char * const argv[]) | |
1000 | { | |
8c86bbe0 | 1001 | ulong start, end; |
5512d5b0 | 1002 | vu_long *buf, *dummy; |
adcc5705 | 1003 | ulong iteration_limit = 0; |
c9638f50 | 1004 | int ret; |
51209b1f | 1005 | ulong errs = 0; /* number of errors, or -1 if interrupted */ |
e37f1eb4 | 1006 | ulong pattern = 0; |
51209b1f | 1007 | int iteration; |
c9638f50 SG |
1008 | #if defined(CONFIG_SYS_ALT_MEMTEST) |
1009 | const int alt_test = 1; | |
1010 | #else | |
1011 | const int alt_test = 0; | |
3863585b | 1012 | #endif |
c9638f50 | 1013 | |
e37f1eb4 PM |
1014 | start = CONFIG_SYS_MEMTEST_START; |
1015 | end = CONFIG_SYS_MEMTEST_END; | |
1016 | ||
c9638f50 | 1017 | if (argc > 1) |
e37f1eb4 PM |
1018 | if (strict_strtoul(argv[1], 16, &start) < 0) |
1019 | return CMD_RET_USAGE; | |
c9638f50 SG |
1020 | |
1021 | if (argc > 2) | |
e37f1eb4 PM |
1022 | if (strict_strtoul(argv[2], 16, &end) < 0) |
1023 | return CMD_RET_USAGE; | |
c9638f50 SG |
1024 | |
1025 | if (argc > 3) | |
e37f1eb4 PM |
1026 | if (strict_strtoul(argv[3], 16, &pattern) < 0) |
1027 | return CMD_RET_USAGE; | |
c9638f50 SG |
1028 | |
1029 | if (argc > 4) | |
e37f1eb4 PM |
1030 | if (strict_strtoul(argv[4], 16, &iteration_limit) < 0) |
1031 | return CMD_RET_USAGE; | |
1032 | ||
1033 | if (end < start) { | |
1034 | printf("Refusing to do empty test\n"); | |
1035 | return -1; | |
1036 | } | |
c9638f50 | 1037 | |
8c86bbe0 SG |
1038 | printf("Testing %08x ... %08x:\n", (uint)start, (uint)end); |
1039 | debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, | |
1040 | start, end); | |
51209b1f | 1041 | |
5512d5b0 SG |
1042 | buf = map_sysmem(start, end - start); |
1043 | dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long)); | |
51209b1f SG |
1044 | for (iteration = 0; |
1045 | !iteration_limit || iteration < iteration_limit; | |
1046 | iteration++) { | |
1047 | if (ctrlc()) { | |
51209b1f SG |
1048 | errs = -1UL; |
1049 | break; | |
1050 | } | |
1051 | ||
1052 | printf("Iteration: %6d\r", iteration + 1); | |
1053 | debug("\n"); | |
5512d5b0 SG |
1054 | if (alt_test) { |
1055 | errs = mem_test_alt(buf, start, end, dummy); | |
1056 | } else { | |
1057 | errs = mem_test_quick(buf, start, end, pattern, | |
1058 | iteration); | |
1059 | } | |
1060 | if (errs == -1UL) | |
1061 | break; | |
1062 | } | |
1063 | ||
1064 | /* | |
1065 | * Work-around for eldk-4.2 which gives this warning if we try to | |
1066 | * case in the unmap_sysmem() call: | |
1067 | * warning: initialization discards qualifiers from pointer target type | |
1068 | */ | |
1069 | { | |
1070 | void *vbuf = (void *)buf; | |
1071 | void *vdummy = (void *)dummy; | |
1072 | ||
1073 | unmap_sysmem(vbuf); | |
1074 | unmap_sysmem(vdummy); | |
51209b1f SG |
1075 | } |
1076 | ||
1077 | if (errs == -1UL) { | |
c44d4386 SG |
1078 | /* Memory test was aborted - write a newline to finish off */ |
1079 | putc('\n'); | |
51209b1f SG |
1080 | ret = 1; |
1081 | } else { | |
1082 | printf("Tested %d iteration(s) with %lu errors.\n", | |
1083 | iteration, errs); | |
1084 | ret = errs != 0; | |
1085 | } | |
c9638f50 | 1086 | |
e37f1eb4 | 1087 | return ret; |
3863585b | 1088 | } |
a2681707 | 1089 | #endif /* CONFIG_CMD_MEMTEST */ |
3863585b WD |
1090 | |
1091 | /* Modify memory. | |
1092 | * | |
1093 | * Syntax: | |
4d1fd7f1 YS |
1094 | * mm{.b, .w, .l, .q} {addr} |
1095 | * nm{.b, .w, .l, .q} {addr} | |
3863585b WD |
1096 | */ |
1097 | static int | |
54841ab5 | 1098 | mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) |
3863585b | 1099 | { |
4d1fd7f1 YS |
1100 | ulong addr; |
1101 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA | |
1102 | u64 i; | |
1103 | #else | |
1104 | ulong i; | |
1105 | #endif | |
27b207fd | 1106 | int nbytes, size; |
0628ab8e | 1107 | void *ptr = NULL; |
3863585b | 1108 | |
47e26b1b | 1109 | if (argc != 2) |
4c12eeb8 | 1110 | return CMD_RET_USAGE; |
3863585b | 1111 | |
b26440f1 | 1112 | bootretry_reset_cmd_timeout(); /* got a good command to get here */ |
3863585b WD |
1113 | /* We use the last specified parameters, unless new ones are |
1114 | * entered. | |
1115 | */ | |
1116 | addr = mm_last_addr; | |
1117 | size = mm_last_size; | |
1118 | ||
1119 | if ((flag & CMD_FLAG_REPEAT) == 0) { | |
1120 | /* New command specified. Check for a size specification. | |
1121 | * Defaults to long if no or incorrect specification. | |
1122 | */ | |
27b207fd WD |
1123 | if ((size = cmd_get_data_size(argv[0], 4)) < 0) |
1124 | return 1; | |
3863585b WD |
1125 | |
1126 | /* Address is specified since argc > 1 | |
1127 | */ | |
1128 | addr = simple_strtoul(argv[1], NULL, 16); | |
1129 | addr += base_address; | |
1130 | } | |
1131 | ||
2abbe075 WD |
1132 | #ifdef CONFIG_HAS_DATAFLASH |
1133 | if (addr_dataflash(addr)){ | |
4b9206ed | 1134 | puts ("Can't modify DataFlash in place. Use cp instead.\n\r"); |
2abbe075 WD |
1135 | return 0; |
1136 | } | |
1137 | #endif | |
1138 | ||
4c727c77 MF |
1139 | #ifdef CONFIG_BLACKFIN |
1140 | if (addr_bfin_on_chip_mem(addr)) { | |
1141 | puts ("Can't modify L1 instruction in place. Use cp instead.\n\r"); | |
1142 | return 0; | |
1143 | } | |
1144 | #endif | |
1145 | ||
3863585b WD |
1146 | /* Print the address, followed by value. Then accept input for |
1147 | * the next value. A non-converted value exits. | |
1148 | */ | |
1149 | do { | |
0628ab8e | 1150 | ptr = map_sysmem(addr, size); |
3863585b WD |
1151 | printf("%08lx:", addr); |
1152 | if (size == 4) | |
76698b4e | 1153 | printf(" %08x", *((u32 *)ptr)); |
4d1fd7f1 YS |
1154 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1155 | else if (size == 8) | |
e48f3741 | 1156 | printf(" %016" PRIx64, *((u64 *)ptr)); |
4d1fd7f1 | 1157 | #endif |
3863585b | 1158 | else if (size == 2) |
76698b4e | 1159 | printf(" %04x", *((u16 *)ptr)); |
3863585b | 1160 | else |
76698b4e | 1161 | printf(" %02x", *((u8 *)ptr)); |
3863585b | 1162 | |
e1bf824d | 1163 | nbytes = cli_readline(" ? "); |
3863585b WD |
1164 | if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { |
1165 | /* <CR> pressed as only input, don't modify current | |
1166 | * location and move to next. "-" pressed will go back. | |
1167 | */ | |
1168 | if (incrflag) | |
1169 | addr += nbytes ? -size : size; | |
1170 | nbytes = 1; | |
b26440f1 SG |
1171 | /* good enough to not time out */ |
1172 | bootretry_reset_cmd_timeout(); | |
3863585b WD |
1173 | } |
1174 | #ifdef CONFIG_BOOT_RETRY_TIME | |
1175 | else if (nbytes == -2) { | |
1176 | break; /* timed out, exit the command */ | |
1177 | } | |
1178 | #endif | |
1179 | else { | |
1180 | char *endp; | |
4d1fd7f1 YS |
1181 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1182 | i = simple_strtoull(console_buffer, &endp, 16); | |
1183 | #else | |
3863585b | 1184 | i = simple_strtoul(console_buffer, &endp, 16); |
4d1fd7f1 | 1185 | #endif |
3863585b WD |
1186 | nbytes = endp - console_buffer; |
1187 | if (nbytes) { | |
3863585b WD |
1188 | /* good enough to not time out |
1189 | */ | |
b26440f1 | 1190 | bootretry_reset_cmd_timeout(); |
3863585b | 1191 | if (size == 4) |
76698b4e | 1192 | *((u32 *)ptr) = i; |
4d1fd7f1 YS |
1193 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1194 | else if (size == 8) | |
1195 | *((u64 *)ptr) = i; | |
1196 | #endif | |
3863585b | 1197 | else if (size == 2) |
76698b4e | 1198 | *((u16 *)ptr) = i; |
3863585b | 1199 | else |
76698b4e | 1200 | *((u8 *)ptr) = i; |
3863585b WD |
1201 | if (incrflag) |
1202 | addr += size; | |
1203 | } | |
1204 | } | |
1205 | } while (nbytes); | |
0628ab8e SG |
1206 | if (ptr) |
1207 | unmap_sysmem(ptr); | |
3863585b WD |
1208 | |
1209 | mm_last_addr = addr; | |
1210 | mm_last_size = size; | |
1211 | return 0; | |
1212 | } | |
1213 | ||
710b9938 MF |
1214 | #ifdef CONFIG_CMD_CRC32 |
1215 | ||
088f1b19 | 1216 | static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b | 1217 | { |
d20a40de | 1218 | int flags = 0; |
c26e454d | 1219 | int ac; |
54841ab5 | 1220 | char * const *av; |
c26e454d | 1221 | |
d20a40de | 1222 | if (argc < 3) |
4c12eeb8 | 1223 | return CMD_RET_USAGE; |
c26e454d WD |
1224 | |
1225 | av = argv + 1; | |
1226 | ac = argc - 1; | |
d20a40de | 1227 | #ifdef CONFIG_HASH_VERIFY |
c26e454d | 1228 | if (strcmp(*av, "-v") == 0) { |
d20a40de | 1229 | flags |= HASH_FLAG_VERIFY; |
c26e454d WD |
1230 | av++; |
1231 | ac--; | |
c26e454d | 1232 | } |
d20a40de | 1233 | #endif |
c26e454d | 1234 | |
d20a40de | 1235 | return hash_command("crc32", flags, cmdtp, flag, ac, av); |
c26e454d | 1236 | } |
c26e454d | 1237 | |
710b9938 MF |
1238 | #endif |
1239 | ||
8bde7f77 | 1240 | /**************************************************/ |
0d498393 | 1241 | U_BOOT_CMD( |
53677ef1 | 1242 | md, 3, 1, do_mem_md, |
2fb2604d | 1243 | "memory display", |
4d1fd7f1 YS |
1244 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1245 | "[.b, .w, .l, .q] address [# of objects]" | |
1246 | #else | |
a89c33db | 1247 | "[.b, .w, .l] address [# of objects]" |
4d1fd7f1 | 1248 | #endif |
8bde7f77 WD |
1249 | ); |
1250 | ||
1251 | ||
0d498393 | 1252 | U_BOOT_CMD( |
53677ef1 | 1253 | mm, 2, 1, do_mem_mm, |
a89c33db | 1254 | "memory modify (auto-incrementing address)", |
4d1fd7f1 YS |
1255 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1256 | "[.b, .w, .l, .q] address" | |
1257 | #else | |
a89c33db | 1258 | "[.b, .w, .l] address" |
4d1fd7f1 | 1259 | #endif |
8bde7f77 WD |
1260 | ); |
1261 | ||
1262 | ||
0d498393 | 1263 | U_BOOT_CMD( |
53677ef1 | 1264 | nm, 2, 1, do_mem_nm, |
2fb2604d | 1265 | "memory modify (constant address)", |
4d1fd7f1 YS |
1266 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1267 | "[.b, .w, .l, .q] address" | |
1268 | #else | |
a89c33db | 1269 | "[.b, .w, .l] address" |
4d1fd7f1 | 1270 | #endif |
8bde7f77 WD |
1271 | ); |
1272 | ||
0d498393 | 1273 | U_BOOT_CMD( |
53677ef1 | 1274 | mw, 4, 1, do_mem_mw, |
2fb2604d | 1275 | "memory write (fill)", |
4d1fd7f1 YS |
1276 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1277 | "[.b, .w, .l, .q] address value [count]" | |
1278 | #else | |
a89c33db | 1279 | "[.b, .w, .l] address value [count]" |
4d1fd7f1 | 1280 | #endif |
8bde7f77 WD |
1281 | ); |
1282 | ||
0d498393 | 1283 | U_BOOT_CMD( |
53677ef1 | 1284 | cp, 4, 1, do_mem_cp, |
2fb2604d | 1285 | "memory copy", |
4d1fd7f1 YS |
1286 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1287 | "[.b, .w, .l, .q] source target count" | |
1288 | #else | |
a89c33db | 1289 | "[.b, .w, .l] source target count" |
4d1fd7f1 | 1290 | #endif |
8bde7f77 WD |
1291 | ); |
1292 | ||
0d498393 | 1293 | U_BOOT_CMD( |
53677ef1 | 1294 | cmp, 4, 1, do_mem_cmp, |
2fb2604d | 1295 | "memory compare", |
4d1fd7f1 YS |
1296 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1297 | "[.b, .w, .l, .q] addr1 addr2 count" | |
1298 | #else | |
a89c33db | 1299 | "[.b, .w, .l] addr1 addr2 count" |
4d1fd7f1 | 1300 | #endif |
8bde7f77 WD |
1301 | ); |
1302 | ||
710b9938 MF |
1303 | #ifdef CONFIG_CMD_CRC32 |
1304 | ||
c26e454d WD |
1305 | #ifndef CONFIG_CRC32_VERIFY |
1306 | ||
0d498393 | 1307 | U_BOOT_CMD( |
53677ef1 | 1308 | crc32, 4, 1, do_mem_crc, |
2fb2604d | 1309 | "checksum calculation", |
a89c33db | 1310 | "address count [addr]\n - compute CRC32 checksum [save at addr]" |
8bde7f77 WD |
1311 | ); |
1312 | ||
c26e454d WD |
1313 | #else /* CONFIG_CRC32_VERIFY */ |
1314 | ||
1315 | U_BOOT_CMD( | |
53677ef1 | 1316 | crc32, 5, 1, do_mem_crc, |
2fb2604d | 1317 | "checksum calculation", |
c26e454d | 1318 | "address count [addr]\n - compute CRC32 checksum [save at addr]\n" |
a89c33db | 1319 | "-v address count crc\n - verify crc of memory area" |
c26e454d WD |
1320 | ); |
1321 | ||
1322 | #endif /* CONFIG_CRC32_VERIFY */ | |
1323 | ||
710b9938 MF |
1324 | #endif |
1325 | ||
15a33e49 SG |
1326 | #ifdef CONFIG_CMD_MEMINFO |
1327 | __weak void board_show_dram(ulong size) | |
1328 | { | |
1329 | puts("DRAM: "); | |
1330 | print_size(size, "\n"); | |
1331 | } | |
1332 | ||
1333 | static int do_mem_info(cmd_tbl_t *cmdtp, int flag, int argc, | |
1334 | char * const argv[]) | |
1335 | { | |
1336 | board_show_dram(gd->ram_size); | |
1337 | ||
1338 | return 0; | |
1339 | } | |
1340 | #endif | |
1341 | ||
0d498393 | 1342 | U_BOOT_CMD( |
53677ef1 | 1343 | base, 2, 1, do_mem_base, |
2fb2604d | 1344 | "print or set address offset", |
8bde7f77 | 1345 | "\n - print address offset for memory commands\n" |
a89c33db | 1346 | "base off\n - set address offset for memory commands to 'off'" |
8bde7f77 WD |
1347 | ); |
1348 | ||
0d498393 | 1349 | U_BOOT_CMD( |
53677ef1 | 1350 | loop, 3, 1, do_mem_loop, |
2fb2604d | 1351 | "infinite loop on address range", |
4d1fd7f1 YS |
1352 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1353 | "[.b, .w, .l, .q] address number_of_objects" | |
1354 | #else | |
a89c33db | 1355 | "[.b, .w, .l] address number_of_objects" |
4d1fd7f1 | 1356 | #endif |
8bde7f77 WD |
1357 | ); |
1358 | ||
56523f12 WD |
1359 | #ifdef CONFIG_LOOPW |
1360 | U_BOOT_CMD( | |
53677ef1 | 1361 | loopw, 4, 1, do_mem_loopw, |
2fb2604d | 1362 | "infinite write loop on address range", |
4d1fd7f1 YS |
1363 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1364 | "[.b, .w, .l, .q] address number_of_objects data_to_write" | |
1365 | #else | |
a89c33db | 1366 | "[.b, .w, .l] address number_of_objects data_to_write" |
4d1fd7f1 | 1367 | #endif |
56523f12 WD |
1368 | ); |
1369 | #endif /* CONFIG_LOOPW */ | |
1370 | ||
a2681707 | 1371 | #ifdef CONFIG_CMD_MEMTEST |
0d498393 | 1372 | U_BOOT_CMD( |
b6fc6fd4 | 1373 | mtest, 5, 1, do_mem_mtest, |
a89c33db WD |
1374 | "simple RAM read/write test", |
1375 | "[start [end [pattern [iterations]]]]" | |
8bde7f77 | 1376 | ); |
a2681707 | 1377 | #endif /* CONFIG_CMD_MEMTEST */ |
8bde7f77 | 1378 | |
4aaf29b2 SR |
1379 | #ifdef CONFIG_MX_CYCLIC |
1380 | U_BOOT_CMD( | |
53677ef1 | 1381 | mdc, 4, 1, do_mem_mdc, |
2fb2604d | 1382 | "memory display cyclic", |
4d1fd7f1 YS |
1383 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1384 | "[.b, .w, .l, .q] address count delay(ms)" | |
1385 | #else | |
a89c33db | 1386 | "[.b, .w, .l] address count delay(ms)" |
4d1fd7f1 | 1387 | #endif |
4aaf29b2 SR |
1388 | ); |
1389 | ||
1390 | U_BOOT_CMD( | |
53677ef1 | 1391 | mwc, 4, 1, do_mem_mwc, |
2fb2604d | 1392 | "memory write cyclic", |
4d1fd7f1 YS |
1393 | #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA |
1394 | "[.b, .w, .l, .q] address value delay(ms)" | |
1395 | #else | |
a89c33db | 1396 | "[.b, .w, .l] address value delay(ms)" |
4d1fd7f1 | 1397 | #endif |
4aaf29b2 SR |
1398 | ); |
1399 | #endif /* CONFIG_MX_CYCLIC */ | |
15a33e49 SG |
1400 | |
1401 | #ifdef CONFIG_CMD_MEMINFO | |
1402 | U_BOOT_CMD( | |
1403 | meminfo, 3, 1, do_mem_info, | |
1404 | "display memory information", | |
1405 | "" | |
1406 | ); | |
1407 | #endif |