mem.c 31 KB

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