cmd_mmc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * (C) Copyright 2003
  3. * Kyle Harris, kharris@nexus-tech.net
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <mmc.h>
  10. static int curr_device = -1;
  11. #ifndef CONFIG_GENERIC_MMC
  12. int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  13. {
  14. int dev;
  15. if (argc < 2)
  16. return CMD_RET_USAGE;
  17. if (strcmp(argv[1], "init") == 0) {
  18. if (argc == 2) {
  19. if (curr_device < 0)
  20. dev = 1;
  21. else
  22. dev = curr_device;
  23. } else if (argc == 3) {
  24. dev = (int)simple_strtoul(argv[2], NULL, 10);
  25. } else {
  26. return CMD_RET_USAGE;
  27. }
  28. if (mmc_legacy_init(dev) != 0) {
  29. puts("No MMC card found\n");
  30. return 1;
  31. }
  32. curr_device = dev;
  33. printf("mmc%d is available\n", curr_device);
  34. } else if (strcmp(argv[1], "device") == 0) {
  35. if (argc == 2) {
  36. if (curr_device < 0) {
  37. puts("No MMC device available\n");
  38. return 1;
  39. }
  40. } else if (argc == 3) {
  41. dev = (int)simple_strtoul(argv[2], NULL, 10);
  42. #ifdef CONFIG_SYS_MMC_SET_DEV
  43. if (mmc_set_dev(dev) != 0)
  44. return 1;
  45. #endif
  46. curr_device = dev;
  47. } else {
  48. return CMD_RET_USAGE;
  49. }
  50. printf("mmc%d is current device\n", curr_device);
  51. } else {
  52. return CMD_RET_USAGE;
  53. }
  54. return 0;
  55. }
  56. U_BOOT_CMD(
  57. mmc, 3, 1, do_mmc,
  58. "MMC sub-system",
  59. "init [dev] - init MMC sub system\n"
  60. "mmc device [dev] - show or set current device"
  61. );
  62. #else /* !CONFIG_GENERIC_MMC */
  63. static void print_mmcinfo(struct mmc *mmc)
  64. {
  65. printf("Device: %s\n", mmc->cfg->name);
  66. printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
  67. printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
  68. printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
  69. (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
  70. (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
  71. printf("Tran Speed: %d\n", mmc->tran_speed);
  72. printf("Rd Block Len: %d\n", mmc->read_bl_len);
  73. printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
  74. (mmc->version >> 8) & 0xf, mmc->version & 0xff);
  75. printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
  76. puts("Capacity: ");
  77. print_size(mmc->capacity, "\n");
  78. printf("Bus Width: %d-bit\n", mmc->bus_width);
  79. }
  80. static struct mmc *init_mmc_device(int dev)
  81. {
  82. struct mmc *mmc;
  83. mmc = find_mmc_device(dev);
  84. if (!mmc) {
  85. printf("no mmc device at slot %x\n", dev);
  86. return NULL;
  87. }
  88. if (mmc_init(mmc))
  89. return NULL;
  90. return mmc;
  91. }
  92. static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  93. {
  94. struct mmc *mmc;
  95. if (curr_device < 0) {
  96. if (get_mmc_num() > 0)
  97. curr_device = 0;
  98. else {
  99. puts("No MMC device available\n");
  100. return 1;
  101. }
  102. }
  103. mmc = init_mmc_device(curr_device);
  104. if (!mmc)
  105. return CMD_RET_FAILURE;
  106. print_mmcinfo(mmc);
  107. return CMD_RET_SUCCESS;
  108. }
  109. #ifdef CONFIG_SUPPORT_EMMC_RPMB
  110. static int confirm_key_prog(void)
  111. {
  112. puts("Warning: Programming authentication key can be done only once !\n"
  113. " Use this command only if you are sure of what you are doing,\n"
  114. "Really perform the key programming? <y/N> ");
  115. if (confirm_yesno())
  116. return 1;
  117. puts("Authentication key programming aborted\n");
  118. return 0;
  119. }
  120. static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
  121. int argc, char * const argv[])
  122. {
  123. void *key_addr;
  124. struct mmc *mmc = find_mmc_device(curr_device);
  125. if (argc != 2)
  126. return CMD_RET_USAGE;
  127. key_addr = (void *)simple_strtoul(argv[1], NULL, 16);
  128. if (!confirm_key_prog())
  129. return CMD_RET_FAILURE;
  130. if (mmc_rpmb_set_key(mmc, key_addr)) {
  131. printf("ERROR - Key already programmed ?\n");
  132. return CMD_RET_FAILURE;
  133. }
  134. return CMD_RET_SUCCESS;
  135. }
  136. static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
  137. int argc, char * const argv[])
  138. {
  139. u16 blk, cnt;
  140. void *addr;
  141. int n;
  142. void *key_addr = NULL;
  143. struct mmc *mmc = find_mmc_device(curr_device);
  144. if (argc < 4)
  145. return CMD_RET_USAGE;
  146. addr = (void *)simple_strtoul(argv[1], NULL, 16);
  147. blk = simple_strtoul(argv[2], NULL, 16);
  148. cnt = simple_strtoul(argv[3], NULL, 16);
  149. if (argc == 5)
  150. key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
  151. printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
  152. curr_device, blk, cnt);
  153. n = mmc_rpmb_read(mmc, addr, blk, cnt, key_addr);
  154. printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  155. if (n != cnt)
  156. return CMD_RET_FAILURE;
  157. return CMD_RET_SUCCESS;
  158. }
  159. static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
  160. int argc, char * const argv[])
  161. {
  162. u16 blk, cnt;
  163. void *addr;
  164. int n;
  165. void *key_addr;
  166. struct mmc *mmc = find_mmc_device(curr_device);
  167. if (argc != 5)
  168. return CMD_RET_USAGE;
  169. addr = (void *)simple_strtoul(argv[1], NULL, 16);
  170. blk = simple_strtoul(argv[2], NULL, 16);
  171. cnt = simple_strtoul(argv[3], NULL, 16);
  172. key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
  173. printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
  174. curr_device, blk, cnt);
  175. n = mmc_rpmb_write(mmc, addr, blk, cnt, key_addr);
  176. printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  177. if (n != cnt)
  178. return CMD_RET_FAILURE;
  179. return CMD_RET_SUCCESS;
  180. }
  181. static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
  182. int argc, char * const argv[])
  183. {
  184. unsigned long counter;
  185. struct mmc *mmc = find_mmc_device(curr_device);
  186. if (mmc_rpmb_get_counter(mmc, &counter))
  187. return CMD_RET_FAILURE;
  188. printf("RPMB Write counter= %lx\n", counter);
  189. return CMD_RET_SUCCESS;
  190. }
  191. static cmd_tbl_t cmd_rpmb[] = {
  192. U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""),
  193. U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""),
  194. U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""),
  195. U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""),
  196. };
  197. static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
  198. int argc, char * const argv[])
  199. {
  200. cmd_tbl_t *cp;
  201. struct mmc *mmc;
  202. char original_part;
  203. int ret;
  204. cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
  205. /* Drop the rpmb subcommand */
  206. argc--;
  207. argv++;
  208. if (cp == NULL || argc > cp->maxargs)
  209. return CMD_RET_USAGE;
  210. if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
  211. return CMD_RET_SUCCESS;
  212. mmc = init_mmc_device(curr_device);
  213. if (!mmc)
  214. return CMD_RET_FAILURE;
  215. if (!(mmc->version & MMC_VERSION_MMC)) {
  216. printf("It is not a EMMC device\n");
  217. return CMD_RET_FAILURE;
  218. }
  219. if (mmc->version < MMC_VERSION_4_41) {
  220. printf("RPMB not supported before version 4.41\n");
  221. return CMD_RET_FAILURE;
  222. }
  223. /* Switch to the RPMB partition */
  224. original_part = mmc->part_num;
  225. if (mmc->part_num != MMC_PART_RPMB) {
  226. if (mmc_switch_part(curr_device, MMC_PART_RPMB) != 0)
  227. return CMD_RET_FAILURE;
  228. mmc->part_num = MMC_PART_RPMB;
  229. }
  230. ret = cp->cmd(cmdtp, flag, argc, argv);
  231. /* Return to original partition */
  232. if (mmc->part_num != original_part) {
  233. if (mmc_switch_part(curr_device, original_part) != 0)
  234. return CMD_RET_FAILURE;
  235. mmc->part_num = original_part;
  236. }
  237. return ret;
  238. }
  239. #endif
  240. static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
  241. int argc, char * const argv[])
  242. {
  243. struct mmc *mmc;
  244. u32 blk, cnt, n;
  245. void *addr;
  246. if (argc != 4)
  247. return CMD_RET_USAGE;
  248. addr = (void *)simple_strtoul(argv[1], NULL, 16);
  249. blk = simple_strtoul(argv[2], NULL, 16);
  250. cnt = simple_strtoul(argv[3], NULL, 16);
  251. mmc = init_mmc_device(curr_device);
  252. if (!mmc)
  253. return CMD_RET_FAILURE;
  254. printf("\nMMC read: dev # %d, block # %d, count %d ... ",
  255. curr_device, blk, cnt);
  256. n = mmc->block_dev.block_read(curr_device, blk, cnt, addr);
  257. /* flush cache after read */
  258. flush_cache((ulong)addr, cnt * 512); /* FIXME */
  259. printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  260. return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
  261. }
  262. static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
  263. int argc, char * const argv[])
  264. {
  265. struct mmc *mmc;
  266. u32 blk, cnt, n;
  267. void *addr;
  268. if (argc != 4)
  269. return CMD_RET_USAGE;
  270. addr = (void *)simple_strtoul(argv[1], NULL, 16);
  271. blk = simple_strtoul(argv[2], NULL, 16);
  272. cnt = simple_strtoul(argv[3], NULL, 16);
  273. mmc = init_mmc_device(curr_device);
  274. if (!mmc)
  275. return CMD_RET_FAILURE;
  276. printf("\nMMC write: dev # %d, block # %d, count %d ... ",
  277. curr_device, blk, cnt);
  278. if (mmc_getwp(mmc) == 1) {
  279. printf("Error: card is write protected!\n");
  280. return CMD_RET_FAILURE;
  281. }
  282. n = mmc->block_dev.block_write(curr_device, blk, cnt, addr);
  283. printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  284. return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
  285. }
  286. static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
  287. int argc, char * const argv[])
  288. {
  289. struct mmc *mmc;
  290. u32 blk, cnt, n;
  291. if (argc != 3)
  292. return CMD_RET_USAGE;
  293. blk = simple_strtoul(argv[1], NULL, 16);
  294. cnt = simple_strtoul(argv[2], NULL, 16);
  295. mmc = init_mmc_device(curr_device);
  296. if (!mmc)
  297. return CMD_RET_FAILURE;
  298. printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
  299. curr_device, blk, cnt);
  300. if (mmc_getwp(mmc) == 1) {
  301. printf("Error: card is write protected!\n");
  302. return CMD_RET_FAILURE;
  303. }
  304. n = mmc->block_dev.block_erase(curr_device, blk, cnt);
  305. printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  306. return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
  307. }
  308. static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
  309. int argc, char * const argv[])
  310. {
  311. struct mmc *mmc;
  312. mmc = find_mmc_device(curr_device);
  313. if (!mmc) {
  314. printf("no mmc device at slot %x\n", curr_device);
  315. return CMD_RET_FAILURE;
  316. }
  317. mmc->has_init = 0;
  318. if (mmc_init(mmc))
  319. return CMD_RET_FAILURE;
  320. return CMD_RET_SUCCESS;
  321. }
  322. static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
  323. int argc, char * const argv[])
  324. {
  325. block_dev_desc_t *mmc_dev;
  326. struct mmc *mmc;
  327. mmc = init_mmc_device(curr_device);
  328. if (!mmc)
  329. return CMD_RET_FAILURE;
  330. mmc_dev = mmc_get_dev(curr_device);
  331. if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
  332. print_part(mmc_dev);
  333. return CMD_RET_SUCCESS;
  334. }
  335. puts("get mmc type error!\n");
  336. return CMD_RET_FAILURE;
  337. }
  338. static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
  339. int argc, char * const argv[])
  340. {
  341. int dev, part = -1, ret;
  342. struct mmc *mmc;
  343. if (argc == 1) {
  344. dev = curr_device;
  345. } else if (argc == 2) {
  346. dev = simple_strtoul(argv[1], NULL, 10);
  347. } else if (argc == 3) {
  348. dev = (int)simple_strtoul(argv[1], NULL, 10);
  349. part = (int)simple_strtoul(argv[2], NULL, 10);
  350. if (part > PART_ACCESS_MASK) {
  351. printf("#part_num shouldn't be larger than %d\n",
  352. PART_ACCESS_MASK);
  353. return CMD_RET_FAILURE;
  354. }
  355. } else {
  356. return CMD_RET_USAGE;
  357. }
  358. mmc = init_mmc_device(dev);
  359. if (!mmc)
  360. return CMD_RET_FAILURE;
  361. if (part != -1) {
  362. ret = mmc_select_hwpart(dev, part);
  363. printf("switch to partitions #%d, %s\n",
  364. part, (!ret) ? "OK" : "ERROR");
  365. if (ret)
  366. return 1;
  367. }
  368. curr_device = dev;
  369. if (mmc->part_config == MMCPART_NOAVAILABLE)
  370. printf("mmc%d is current device\n", curr_device);
  371. else
  372. printf("mmc%d(part %d) is current device\n",
  373. curr_device, mmc->part_num);
  374. return CMD_RET_SUCCESS;
  375. }
  376. static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
  377. int argc, char * const argv[])
  378. {
  379. print_mmc_devices('\n');
  380. return CMD_RET_SUCCESS;
  381. }
  382. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  383. static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
  384. int argc, char * const argv[])
  385. {
  386. int dev;
  387. struct mmc *mmc;
  388. u8 width, reset, mode;
  389. if (argc != 5)
  390. return CMD_RET_USAGE;
  391. dev = simple_strtoul(argv[1], NULL, 10);
  392. width = simple_strtoul(argv[2], NULL, 10);
  393. reset = simple_strtoul(argv[3], NULL, 10);
  394. mode = simple_strtoul(argv[4], NULL, 10);
  395. mmc = init_mmc_device(dev);
  396. if (!mmc)
  397. return CMD_RET_FAILURE;
  398. if (IS_SD(mmc)) {
  399. puts("BOOT_BUS_WIDTH only exists on eMMC\n");
  400. return CMD_RET_FAILURE;
  401. }
  402. /* acknowledge to be sent during boot operation */
  403. return mmc_set_boot_bus_width(mmc, width, reset, mode);
  404. }
  405. static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
  406. int argc, char * const argv[])
  407. {
  408. int dev;
  409. struct mmc *mmc;
  410. u32 bootsize, rpmbsize;
  411. if (argc != 4)
  412. return CMD_RET_USAGE;
  413. dev = simple_strtoul(argv[1], NULL, 10);
  414. bootsize = simple_strtoul(argv[2], NULL, 10);
  415. rpmbsize = simple_strtoul(argv[3], NULL, 10);
  416. mmc = init_mmc_device(dev);
  417. if (!mmc)
  418. return CMD_RET_FAILURE;
  419. if (IS_SD(mmc)) {
  420. printf("It is not a EMMC device\n");
  421. return CMD_RET_FAILURE;
  422. }
  423. if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) {
  424. printf("EMMC boot partition Size change Failed.\n");
  425. return CMD_RET_FAILURE;
  426. }
  427. printf("EMMC boot partition Size %d MB\n", bootsize);
  428. printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
  429. return CMD_RET_SUCCESS;
  430. }
  431. static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
  432. int argc, char * const argv[])
  433. {
  434. int dev;
  435. struct mmc *mmc;
  436. u8 ack, part_num, access;
  437. if (argc != 5)
  438. return CMD_RET_USAGE;
  439. dev = simple_strtoul(argv[1], NULL, 10);
  440. ack = simple_strtoul(argv[2], NULL, 10);
  441. part_num = simple_strtoul(argv[3], NULL, 10);
  442. access = simple_strtoul(argv[4], NULL, 10);
  443. mmc = init_mmc_device(dev);
  444. if (!mmc)
  445. return CMD_RET_FAILURE;
  446. if (IS_SD(mmc)) {
  447. puts("PARTITION_CONFIG only exists on eMMC\n");
  448. return CMD_RET_FAILURE;
  449. }
  450. /* acknowledge to be sent during boot operation */
  451. return mmc_set_part_conf(mmc, ack, part_num, access);
  452. }
  453. static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
  454. int argc, char * const argv[])
  455. {
  456. int dev;
  457. struct mmc *mmc;
  458. u8 enable;
  459. /*
  460. * Set the RST_n_ENABLE bit of RST_n_FUNCTION
  461. * The only valid values are 0x0, 0x1 and 0x2 and writing
  462. * a value of 0x1 or 0x2 sets the value permanently.
  463. */
  464. if (argc != 3)
  465. return CMD_RET_USAGE;
  466. dev = simple_strtoul(argv[1], NULL, 10);
  467. enable = simple_strtoul(argv[2], NULL, 10);
  468. if (enable > 2 || enable < 0) {
  469. puts("Invalid RST_n_ENABLE value\n");
  470. return CMD_RET_USAGE;
  471. }
  472. mmc = init_mmc_device(dev);
  473. if (!mmc)
  474. return CMD_RET_FAILURE;
  475. if (IS_SD(mmc)) {
  476. puts("RST_n_FUNCTION only exists on eMMC\n");
  477. return CMD_RET_FAILURE;
  478. }
  479. return mmc_set_rst_n_function(mmc, enable);
  480. }
  481. #endif
  482. static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
  483. int argc, char * const argv[])
  484. {
  485. struct mmc *mmc;
  486. u32 val;
  487. int ret;
  488. if (argc != 2)
  489. return CMD_RET_USAGE;
  490. val = simple_strtoul(argv[2], NULL, 16);
  491. mmc = find_mmc_device(curr_device);
  492. if (!mmc) {
  493. printf("no mmc device at slot %x\n", curr_device);
  494. return CMD_RET_FAILURE;
  495. }
  496. ret = mmc_set_dsr(mmc, val);
  497. printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR");
  498. if (!ret) {
  499. mmc->has_init = 0;
  500. if (mmc_init(mmc))
  501. return CMD_RET_FAILURE;
  502. else
  503. return CMD_RET_SUCCESS;
  504. }
  505. return ret;
  506. }
  507. static cmd_tbl_t cmd_mmc[] = {
  508. U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
  509. U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
  510. U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
  511. U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
  512. U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
  513. U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
  514. U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""),
  515. U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""),
  516. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  517. U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
  518. U_BOOT_CMD_MKENT(bootpart-resize, 3, 0, do_mmc_boot_resize, "", ""),
  519. U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
  520. U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
  521. #endif
  522. #ifdef CONFIG_SUPPORT_EMMC_RPMB
  523. U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""),
  524. #endif
  525. U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
  526. };
  527. static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  528. {
  529. cmd_tbl_t *cp;
  530. cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
  531. /* Drop the mmc command */
  532. argc--;
  533. argv++;
  534. if (cp == NULL || argc > cp->maxargs)
  535. return CMD_RET_USAGE;
  536. if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
  537. return CMD_RET_SUCCESS;
  538. if (curr_device < 0) {
  539. if (get_mmc_num() > 0) {
  540. curr_device = 0;
  541. } else {
  542. puts("No MMC device available\n");
  543. return CMD_RET_FAILURE;
  544. }
  545. }
  546. return cp->cmd(cmdtp, flag, argc, argv);
  547. }
  548. U_BOOT_CMD(
  549. mmc, 7, 1, do_mmcops,
  550. "MMC sub system",
  551. "info - display info of the current MMC device\n"
  552. "mmc read addr blk# cnt\n"
  553. "mmc write addr blk# cnt\n"
  554. "mmc erase blk# cnt\n"
  555. "mmc rescan\n"
  556. "mmc part - lists available partition on current mmc device\n"
  557. "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
  558. "mmc list - lists available devices\n"
  559. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  560. "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
  561. " - Set the BOOT_BUS_WIDTH field of the specified device\n"
  562. "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
  563. " - Change sizes of boot and RPMB partitions of specified device\n"
  564. "mmc partconf dev boot_ack boot_partition partition_access\n"
  565. " - Change the bits of the PARTITION_CONFIG field of the specified device\n"
  566. "mmc rst-function dev value\n"
  567. " - Change the RST_n_FUNCTION field of the specified device\n"
  568. " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
  569. #endif
  570. #ifdef CONFIG_SUPPORT_EMMC_RPMB
  571. "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
  572. "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
  573. "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
  574. "mmc rpmb counter - read the value of the write counter\n"
  575. #endif
  576. "mmc setdsr <value> - set DSR register value\n"
  577. );
  578. /* Old command kept for compatibility. Same as 'mmc info' */
  579. U_BOOT_CMD(
  580. mmcinfo, 1, 0, do_mmcinfo,
  581. "display MMC info",
  582. "- display info of the current MMC device"
  583. );
  584. #endif /* !CONFIG_GENERIC_MMC */