mem.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  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[1], 4)) < 0)
  76. return 1;
  77. /* Address is specified since argc > 1
  78. */
  79. addr = simple_strtoul(argv[2], 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 > 3)
  85. length = simple_strtoul(argv[3], 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 > 5))
  117. return CMD_RET_USAGE;
  118. /* Check for size specification.
  119. */
  120. if ((size = cmd_get_data_size(argv[1], 4)) < 1)
  121. return 1;
  122. /* Address is specified since argc > 1
  123. */
  124. addr = simple_strtoul(argv[2], NULL, 16);
  125. addr += base_address;
  126. /* Get the value to write.
  127. */
  128. if (SUPPORT_64BIT_DATA)
  129. writeval = simple_strtoull(argv[3], NULL, 16);
  130. else
  131. writeval = simple_strtoul(argv[3], NULL, 16);
  132. /* Count ? */
  133. if (argc == 4) {
  134. count = simple_strtoul(argv[4], 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 != 5)
  209. return CMD_RET_USAGE;
  210. /* Check for size specification.
  211. */
  212. if ((size = cmd_get_data_size(argv[1], 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[2], NULL, 16);
  218. addr1 += base_address;
  219. addr2 = simple_strtoul(argv[3], NULL, 16);
  220. addr2 += base_address;
  221. count = simple_strtoul(argv[4], 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 != 5)
  265. return CMD_RET_USAGE;
  266. /* Check for size specification.
  267. */
  268. if ((size = cmd_get_data_size(argv[1], 4)) < 0)
  269. return 1;
  270. addr = simple_strtoul(argv[2], NULL, 16);
  271. addr += base_address;
  272. dest = simple_strtoul(argv[3], NULL, 16);
  273. dest += base_address;
  274. count = simple_strtoul(argv[4], 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_bitflip(vu_long *buf, ulong start, ulong end)
  863. {
  864. /*
  865. * Split the specified range into two halves.
  866. * Note that mtest range is inclusive of start,end.
  867. * Bitflip test instead uses a count (of 32-bit words).
  868. */
  869. ulong half_size = (end - start + 1) / 2 / sizeof(unsigned long);
  870. return test_bitflip_comparison(buf, buf + half_size, half_size);
  871. }
  872. static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
  873. vu_long pattern, int iteration)
  874. {
  875. vu_long *end;
  876. vu_long *addr;
  877. ulong errs = 0;
  878. ulong incr, length;
  879. ulong val, readback;
  880. /* Alternate the pattern */
  881. incr = 1;
  882. if (iteration & 1) {
  883. incr = -incr;
  884. /*
  885. * Flip the pattern each time to make lots of zeros and
  886. * then, the next time, lots of ones. We decrement
  887. * the "negative" patterns and increment the "positive"
  888. * patterns to preserve this feature.
  889. */
  890. if (pattern & 0x80000000)
  891. pattern = -pattern; /* complement & increment */
  892. else
  893. pattern = ~pattern;
  894. }
  895. length = (end_addr - start_addr) / sizeof(ulong);
  896. end = buf + length;
  897. printf("\rPattern %08lX Writing..."
  898. "%12s"
  899. "\b\b\b\b\b\b\b\b\b\b",
  900. pattern, "");
  901. for (addr = buf, val = pattern; addr < end; addr++) {
  902. WATCHDOG_RESET();
  903. *addr = val;
  904. val += incr;
  905. }
  906. puts("Reading...");
  907. for (addr = buf, val = pattern; addr < end; addr++) {
  908. WATCHDOG_RESET();
  909. readback = *addr;
  910. if (readback != val) {
  911. ulong offset = addr - buf;
  912. printf("\nMem error @ 0x%08X: "
  913. "found %08lX, expected %08lX\n",
  914. (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)),
  915. readback, val);
  916. errs++;
  917. if (ctrlc())
  918. return -1;
  919. }
  920. val += incr;
  921. }
  922. return errs;
  923. }
  924. /*
  925. * Perform a memory test. A more complete alternative test can be
  926. * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
  927. * interrupted by ctrl-c or by a failure of one of the sub-tests.
  928. */
  929. static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
  930. char *const argv[])
  931. {
  932. ulong start, end;
  933. vu_long scratch_space;
  934. vu_long *buf, *dummy = &scratch_space;
  935. ulong iteration_limit = 0;
  936. ulong count = 0;
  937. ulong errs = 0; /* number of errors, or -1 if interrupted */
  938. ulong pattern = 0;
  939. int iteration;
  940. start = CONFIG_SYS_MEMTEST_START;
  941. end = CONFIG_SYS_MEMTEST_END;
  942. if (argc > 1)
  943. if (strict_strtoul(argv[1], 16, &start) < 0)
  944. return CMD_RET_USAGE;
  945. if (argc > 2)
  946. if (strict_strtoul(argv[2], 16, &end) < 0)
  947. return CMD_RET_USAGE;
  948. if (argc > 3)
  949. if (strict_strtoul(argv[3], 16, &pattern) < 0)
  950. return CMD_RET_USAGE;
  951. if (argc > 4)
  952. if (strict_strtoul(argv[4], 16, &iteration_limit) < 0)
  953. return CMD_RET_USAGE;
  954. if (end < start) {
  955. printf("Refusing to do empty test\n");
  956. return -1;
  957. }
  958. printf("Testing %08lx ... %08lx:\n", start, end);
  959. debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__,
  960. start, end);
  961. buf = map_sysmem(start, end - start);
  962. for (iteration = 0;
  963. !iteration_limit || iteration < iteration_limit;
  964. iteration++) {
  965. if (ctrlc()) {
  966. errs = -1UL;
  967. break;
  968. }
  969. printf("Iteration: %6d\r", iteration + 1);
  970. debug("\n");
  971. if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) {
  972. errs = mem_test_alt(buf, start, end, dummy);
  973. if (errs == -1UL)
  974. break;
  975. if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST_BITFLIP)) {
  976. count += errs;
  977. errs = mem_test_bitflip(buf, start, end);
  978. }
  979. } else {
  980. errs = mem_test_quick(buf, start, end, pattern,
  981. iteration);
  982. }
  983. if (errs == -1UL)
  984. break;
  985. count += errs;
  986. }
  987. unmap_sysmem((void *)buf);
  988. if (errs == -1UL) {
  989. /* Memory test was aborted - write a newline to finish off */
  990. putc('\n');
  991. }
  992. printf("Tested %d iteration(s) with %lu errors.\n", iteration, count);
  993. return errs != 0;
  994. }
  995. #endif /* CONFIG_CMD_MEMTEST */
  996. /* Modify memory.
  997. *
  998. * Syntax:
  999. * mm{.b, .w, .l, .q} {addr}
  1000. */
  1001. static int
  1002. mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
  1003. char *const argv[])
  1004. {
  1005. ulong addr;
  1006. ulong i; /* 64-bit if SUPPORT_64BIT_DATA */
  1007. int nbytes, size;
  1008. void *ptr = NULL;
  1009. if (argc != 3)
  1010. return CMD_RET_USAGE;
  1011. bootretry_reset_cmd_timeout(); /* got a good command to get here */
  1012. /* We use the last specified parameters, unless new ones are
  1013. * entered.
  1014. */
  1015. addr = mm_last_addr;
  1016. size = mm_last_size;
  1017. if ((flag & CMD_FLAG_REPEAT) == 0) {
  1018. /* New command specified. Check for a size specification.
  1019. * Defaults to long if no or incorrect specification.
  1020. */
  1021. if ((size = cmd_get_data_size(argv[1], 4)) < 0)
  1022. return 1;
  1023. /* Address is specified since argc > 1
  1024. */
  1025. addr = simple_strtoul(argv[2], NULL, 16);
  1026. addr += base_address;
  1027. }
  1028. /* Print the address, followed by value. Then accept input for
  1029. * the next value. A non-converted value exits.
  1030. */
  1031. do {
  1032. ptr = map_sysmem(addr, size);
  1033. printf("%08lx:", addr);
  1034. if (size == 4)
  1035. printf(" %08x", *((u32 *)ptr));
  1036. else if (SUPPORT_64BIT_DATA && size == 8)
  1037. printf(" %0lx", *((ulong *)ptr));
  1038. else if (size == 2)
  1039. printf(" %04x", *((u16 *)ptr));
  1040. else
  1041. printf(" %02x", *((u8 *)ptr));
  1042. nbytes = cli_readline(" ? ");
  1043. if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
  1044. /* <CR> pressed as only input, don't modify current
  1045. * location and move to next. "-" pressed will go back.
  1046. */
  1047. if (incrflag)
  1048. addr += nbytes ? -size : size;
  1049. nbytes = 1;
  1050. /* good enough to not time out */
  1051. bootretry_reset_cmd_timeout();
  1052. }
  1053. #ifdef CONFIG_BOOT_RETRY_TIME
  1054. else if (nbytes == -2) {
  1055. break; /* timed out, exit the command */
  1056. }
  1057. #endif
  1058. else {
  1059. char *endp;
  1060. if (SUPPORT_64BIT_DATA)
  1061. i = simple_strtoull(console_buffer, &endp, 16);
  1062. else
  1063. i = simple_strtoul(console_buffer, &endp, 16);
  1064. nbytes = endp - console_buffer;
  1065. if (nbytes) {
  1066. /* good enough to not time out
  1067. */
  1068. bootretry_reset_cmd_timeout();
  1069. if (size == 4)
  1070. *((u32 *)ptr) = i;
  1071. else if (SUPPORT_64BIT_DATA && size == 8)
  1072. *((ulong *)ptr) = i;
  1073. else if (size == 2)
  1074. *((u16 *)ptr) = i;
  1075. else
  1076. *((u8 *)ptr) = i;
  1077. if (incrflag)
  1078. addr += size;
  1079. }
  1080. }
  1081. } while (nbytes);
  1082. if (ptr)
  1083. unmap_sysmem(ptr);
  1084. mm_last_addr = addr;
  1085. mm_last_size = size;
  1086. return 0;
  1087. }
  1088. #ifdef CONFIG_CMD_CRC32
  1089. static int do_mem_crc(struct cmd_tbl *cmdtp, int flag, int argc,
  1090. char *const argv[])
  1091. {
  1092. int flags = 0;
  1093. int ac;
  1094. char * const *av;
  1095. if (argc < 3)
  1096. return CMD_RET_USAGE;
  1097. av = argv + 1;
  1098. ac = argc - 1;
  1099. #ifdef CONFIG_CRC32_VERIFY
  1100. if (strcmp(*av, "-v") == 0) {
  1101. flags |= HASH_FLAG_VERIFY | HASH_FLAG_ENV;
  1102. av++;
  1103. ac--;
  1104. }
  1105. #endif
  1106. return hash_command("crc32", flags, cmdtp, flag, ac, av);
  1107. }
  1108. #endif
  1109. #ifdef CONFIG_CMD_RANDOM
  1110. static int do_random(struct cmd_tbl *cmdtp, int flag, int argc,
  1111. char *const argv[])
  1112. {
  1113. unsigned long addr, len;
  1114. unsigned long seed; // NOT INITIALIZED ON PURPOSE
  1115. unsigned int *buf, *start;
  1116. unsigned char *buf8;
  1117. unsigned int i;
  1118. if (argc < 3 || argc > 4)
  1119. return CMD_RET_USAGE;
  1120. len = simple_strtoul(argv[2], NULL, 16);
  1121. addr = simple_strtoul(argv[1], NULL, 16);
  1122. if (argc == 4) {
  1123. seed = simple_strtoul(argv[3], NULL, 16);
  1124. if (seed == 0) {
  1125. printf("The seed cannot be 0. Using 0xDEADBEEF.\n");
  1126. seed = 0xDEADBEEF;
  1127. }
  1128. } else {
  1129. seed = get_timer(0) ^ rand();
  1130. }
  1131. srand(seed);
  1132. start = map_sysmem(addr, len);
  1133. buf = start;
  1134. for (i = 0; i < (len / 4); i++)
  1135. *buf++ = rand();
  1136. buf8 = (unsigned char *)buf;
  1137. for (i = 0; i < (len % 4); i++)
  1138. *buf8++ = rand() & 0xFF;
  1139. unmap_sysmem(start);
  1140. printf("%lu bytes filled with random data\n", len);
  1141. return CMD_RET_SUCCESS;
  1142. }
  1143. #endif
  1144. /**************************************************/
  1145. U_BOOT_CMD(
  1146. md, 4, 1, do_mem_md,
  1147. "memory display",
  1148. "[.b, .w, .l" HELP_Q "] address [# of objects]"
  1149. );
  1150. U_BOOT_CMD(
  1151. mm, 3, 1, do_mem_mm,
  1152. "memory modify (auto-incrementing address)",
  1153. "[.b, .w, .l" HELP_Q "] address"
  1154. );
  1155. U_BOOT_CMD(
  1156. nm, 3, 1, do_mem_nm,
  1157. "memory modify (constant address)",
  1158. "[.b, .w, .l" HELP_Q "] address"
  1159. );
  1160. U_BOOT_CMD(
  1161. mw, 5, 1, do_mem_mw,
  1162. "memory write (fill)",
  1163. "[.b, .w, .l" HELP_Q "] address value [count]"
  1164. );
  1165. U_BOOT_CMD(
  1166. cp, 5, 1, do_mem_cp,
  1167. "memory copy",
  1168. "[.b, .w, .l" HELP_Q "] source target count"
  1169. );
  1170. U_BOOT_CMD(
  1171. cmp, 5, 1, do_mem_cmp,
  1172. "memory compare",
  1173. "[.b, .w, .l" HELP_Q "] addr1 addr2 count"
  1174. );
  1175. #ifdef CONFIG_CMD_MEM_SEARCH
  1176. /**************************************************/
  1177. U_BOOT_CMD(
  1178. ms, 255, 1, do_mem_search,
  1179. "memory search",
  1180. "[.b, .w, .l" HELP_Q ", .s] [-q | -<n>] address #-of-objects <value>..."
  1181. " -q = quiet, -l<val> = match limit"
  1182. );
  1183. #endif
  1184. #ifdef CONFIG_CMD_CRC32
  1185. #ifndef CONFIG_CRC32_VERIFY
  1186. U_BOOT_CMD(
  1187. crc32, 4, 1, do_mem_crc,
  1188. "checksum calculation",
  1189. "address count [addr]\n - compute CRC32 checksum [save at addr]"
  1190. );
  1191. #else /* CONFIG_CRC32_VERIFY */
  1192. U_BOOT_CMD(
  1193. crc32, 5, 1, do_mem_crc,
  1194. "checksum calculation",
  1195. "address count [addr]\n - compute CRC32 checksum [save at addr]\n"
  1196. "-v address count crc\n - verify crc of memory area"
  1197. );
  1198. #endif /* CONFIG_CRC32_VERIFY */
  1199. #endif
  1200. #ifdef CONFIG_CMD_MEMINFO
  1201. static int do_mem_info(struct cmd_tbl *cmdtp, int flag, int argc,
  1202. char *const argv[])
  1203. {
  1204. puts("DRAM: ");
  1205. print_size(gd->ram_size, "\n");
  1206. return 0;
  1207. }
  1208. #endif
  1209. U_BOOT_CMD(
  1210. base, 2, 1, do_mem_base,
  1211. "print or set address offset",
  1212. "\n - print address offset for memory commands\n"
  1213. "base off\n - set address offset for memory commands to 'off'"
  1214. );
  1215. U_BOOT_CMD(
  1216. loop, 3, 1, do_mem_loop,
  1217. "infinite loop on address range",
  1218. "[.b, .w, .l" HELP_Q "] address number_of_objects"
  1219. );
  1220. #ifdef CONFIG_LOOPW
  1221. U_BOOT_CMD(
  1222. loopw, 4, 1, do_mem_loopw,
  1223. "infinite write loop on address range",
  1224. "[.b, .w, .l" HELP_Q "] address number_of_objects data_to_write"
  1225. );
  1226. #endif /* CONFIG_LOOPW */
  1227. #ifdef CONFIG_CMD_MEMTEST
  1228. U_BOOT_CMD(
  1229. mtest, 5, 1, do_mem_mtest,
  1230. "simple RAM read/write test",
  1231. "[start [end [pattern [iterations]]]]"
  1232. );
  1233. #endif /* CONFIG_CMD_MEMTEST */
  1234. #ifdef CONFIG_CMD_MX_CYCLIC
  1235. U_BOOT_CMD(
  1236. mdc, 4, 1, do_mem_mdc,
  1237. "memory display cyclic",
  1238. "[.b, .w, .l" HELP_Q "] address count delay(ms)"
  1239. );
  1240. U_BOOT_CMD(
  1241. mwc, 4, 1, do_mem_mwc,
  1242. "memory write cyclic",
  1243. "[.b, .w, .l" HELP_Q "] address value delay(ms)"
  1244. );
  1245. #endif /* CONFIG_CMD_MX_CYCLIC */
  1246. #ifdef CONFIG_CMD_MEMINFO
  1247. U_BOOT_CMD(
  1248. meminfo, 3, 1, do_mem_info,
  1249. "display memory information",
  1250. ""
  1251. );
  1252. #endif
  1253. #ifdef CONFIG_CMD_RANDOM
  1254. U_BOOT_CMD(
  1255. random, 4, 0, do_random,
  1256. "fill memory with random pattern",
  1257. "<addr> <len> [<seed>]\n"
  1258. " - Fill 'len' bytes of memory starting at 'addr' with random data\n"
  1259. );
  1260. #endif