cmd_mmc.c 18 KB

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