mem.c 31 KB

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