mem.c 31 KB

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