mmc.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2003
  4. * Kyle Harris, kharris@nexus-tech.net
  5. */
  6. #include <common.h>
  7. #include <blk.h>
  8. #include <command.h>
  9. #include <console.h>
  10. #include <memalign.h>
  11. #include <mmc.h>
  12. #include <part.h>
  13. #include <sparse_format.h>
  14. #include <image-sparse.h>
  15. static int curr_device = -1;
  16. static void print_mmcinfo(struct mmc *mmc)
  17. {
  18. int i;
  19. printf("Device: %s\n", mmc->cfg->name);
  20. printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
  21. printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
  22. printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
  23. (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
  24. (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
  25. printf("Bus Speed: %d\n", mmc->clock);
  26. #if CONFIG_IS_ENABLED(MMC_VERBOSE)
  27. printf("Mode: %s\n", mmc_mode_name(mmc->selected_mode));
  28. mmc_dump_capabilities("card capabilities", mmc->card_caps);
  29. mmc_dump_capabilities("host capabilities", mmc->host_caps);
  30. #endif
  31. printf("Rd Block Len: %d\n", mmc->read_bl_len);
  32. printf("%s version %d.%d", IS_SD(mmc) ? "SD" : "MMC",
  33. EXTRACT_SDMMC_MAJOR_VERSION(mmc->version),
  34. EXTRACT_SDMMC_MINOR_VERSION(mmc->version));
  35. if (EXTRACT_SDMMC_CHANGE_VERSION(mmc->version) != 0)
  36. printf(".%d", EXTRACT_SDMMC_CHANGE_VERSION(mmc->version));
  37. printf("\n");
  38. printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
  39. puts("Capacity: ");
  40. print_size(mmc->capacity, "\n");
  41. printf("Bus Width: %d-bit%s\n", mmc->bus_width,
  42. mmc->ddr_mode ? " DDR" : "");
  43. #if CONFIG_IS_ENABLED(MMC_WRITE)
  44. puts("Erase Group Size: ");
  45. print_size(((u64)mmc->erase_grp_size) << 9, "\n");
  46. #endif
  47. if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) {
  48. bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0;
  49. bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR);
  50. ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
  51. u8 wp;
  52. int ret;
  53. #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
  54. puts("HC WP Group Size: ");
  55. print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n");
  56. #endif
  57. puts("User Capacity: ");
  58. print_size(mmc->capacity_user, usr_enh ? " ENH" : "");
  59. if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_USR)
  60. puts(" WRREL\n");
  61. else
  62. putc('\n');
  63. if (usr_enh) {
  64. puts("User Enhanced Start: ");
  65. print_size(mmc->enh_user_start, "\n");
  66. puts("User Enhanced Size: ");
  67. print_size(mmc->enh_user_size, "\n");
  68. }
  69. puts("Boot Capacity: ");
  70. print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n");
  71. puts("RPMB Capacity: ");
  72. print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n");
  73. for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
  74. bool is_enh = has_enh &&
  75. (mmc->part_attr & EXT_CSD_ENH_GP(i));
  76. if (mmc->capacity_gp[i]) {
  77. printf("GP%i Capacity: ", i+1);
  78. print_size(mmc->capacity_gp[i],
  79. is_enh ? " ENH" : "");
  80. if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_GP(i))
  81. puts(" WRREL\n");
  82. else
  83. putc('\n');
  84. }
  85. }
  86. ret = mmc_send_ext_csd(mmc, ext_csd);
  87. if (ret)
  88. return;
  89. wp = ext_csd[EXT_CSD_BOOT_WP_STATUS];
  90. for (i = 0; i < 2; ++i) {
  91. printf("Boot area %d is ", i);
  92. switch (wp & 3) {
  93. case 0:
  94. printf("not write protected\n");
  95. break;
  96. case 1:
  97. printf("power on protected\n");
  98. break;
  99. case 2:
  100. printf("permanently protected\n");
  101. break;
  102. default:
  103. printf("in reserved protection state\n");
  104. break;
  105. }
  106. wp >>= 2;
  107. }
  108. }
  109. }
  110. static struct mmc *__init_mmc_device(int dev, bool force_init,
  111. enum bus_mode speed_mode)
  112. {
  113. struct mmc *mmc;
  114. mmc = find_mmc_device(dev);
  115. if (!mmc) {
  116. printf("no mmc device at slot %x\n", dev);
  117. return NULL;
  118. }
  119. if (!mmc_getcd(mmc))
  120. force_init = true;
  121. if (force_init)
  122. mmc->has_init = 0;
  123. if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET))
  124. mmc->user_speed_mode = speed_mode;
  125. if (mmc_init(mmc))
  126. return NULL;
  127. #ifdef CONFIG_BLOCK_CACHE
  128. struct blk_desc *bd = mmc_get_blk_desc(mmc);
  129. blkcache_invalidate(bd->if_type, bd->devnum);
  130. #endif
  131. return mmc;
  132. }
  133. static struct mmc *init_mmc_device(int dev, bool force_init)
  134. {
  135. return __init_mmc_device(dev, force_init, MMC_MODES_END);
  136. }
  137. static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc,
  138. char *const argv[])
  139. {
  140. struct mmc *mmc;
  141. if (curr_device < 0) {
  142. if (get_mmc_num() > 0)
  143. curr_device = 0;
  144. else {
  145. puts("No MMC device available\n");
  146. return 1;
  147. }
  148. }
  149. mmc = init_mmc_device(curr_device, false);
  150. if (!mmc)
  151. return CMD_RET_FAILURE;
  152. print_mmcinfo(mmc);
  153. return CMD_RET_SUCCESS;
  154. }
  155. #if CONFIG_IS_ENABLED(CMD_MMC_RPMB)
  156. static int confirm_key_prog(void)
  157. {
  158. puts("Warning: Programming authentication key can be done only once !\n"
  159. " Use this command only if you are sure of what you are doing,\n"
  160. "Really perform the key programming? <y/N> ");
  161. if (confirm_yesno())
  162. return 1;
  163. puts("Authentication key programming aborted\n");
  164. return 0;
  165. }
  166. static int do_mmcrpmb_key(struct cmd_tbl *cmdtp, int flag,
  167. int argc, char *const argv[])
  168. {
  169. void *key_addr;
  170. struct mmc *mmc = find_mmc_device(curr_device);
  171. if (argc != 2)
  172. return CMD_RET_USAGE;
  173. key_addr = (void *)hextoul(argv[1], NULL);
  174. if (!confirm_key_prog())
  175. return CMD_RET_FAILURE;
  176. if (mmc_rpmb_set_key(mmc, key_addr)) {
  177. printf("ERROR - Key already programmed ?\n");
  178. return CMD_RET_FAILURE;
  179. }
  180. return CMD_RET_SUCCESS;
  181. }
  182. static int do_mmcrpmb_read(struct cmd_tbl *cmdtp, int flag,
  183. int argc, char *const argv[])
  184. {
  185. u16 blk, cnt;
  186. void *addr;
  187. int n;
  188. void *key_addr = NULL;
  189. struct mmc *mmc = find_mmc_device(curr_device);
  190. if (argc < 4)
  191. return CMD_RET_USAGE;
  192. addr = (void *)hextoul(argv[1], NULL);
  193. blk = hextoul(argv[2], NULL);
  194. cnt = hextoul(argv[3], NULL);
  195. if (argc == 5)
  196. key_addr = (void *)hextoul(argv[4], NULL);
  197. printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
  198. curr_device, blk, cnt);
  199. n = mmc_rpmb_read(mmc, addr, blk, cnt, key_addr);
  200. printf("%d RPMB blocks read: %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_write(struct cmd_tbl *cmdtp, int flag,
  206. int argc, char *const argv[])
  207. {
  208. u16 blk, cnt;
  209. void *addr;
  210. int n;
  211. void *key_addr;
  212. struct mmc *mmc = find_mmc_device(curr_device);
  213. if (argc != 5)
  214. return CMD_RET_USAGE;
  215. addr = (void *)hextoul(argv[1], NULL);
  216. blk = hextoul(argv[2], NULL);
  217. cnt = hextoul(argv[3], NULL);
  218. key_addr = (void *)hextoul(argv[4], NULL);
  219. printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
  220. curr_device, blk, cnt);
  221. n = mmc_rpmb_write(mmc, addr, blk, cnt, key_addr);
  222. printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  223. if (n != cnt)
  224. return CMD_RET_FAILURE;
  225. return CMD_RET_SUCCESS;
  226. }
  227. static int do_mmcrpmb_counter(struct cmd_tbl *cmdtp, int flag,
  228. int argc, char *const argv[])
  229. {
  230. unsigned long counter;
  231. struct mmc *mmc = find_mmc_device(curr_device);
  232. if (mmc_rpmb_get_counter(mmc, &counter))
  233. return CMD_RET_FAILURE;
  234. printf("RPMB Write counter= %lx\n", counter);
  235. return CMD_RET_SUCCESS;
  236. }
  237. static struct cmd_tbl cmd_rpmb[] = {
  238. U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""),
  239. U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""),
  240. U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""),
  241. U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""),
  242. };
  243. static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag,
  244. int argc, char *const argv[])
  245. {
  246. struct cmd_tbl *cp;
  247. struct mmc *mmc;
  248. char original_part;
  249. int ret;
  250. cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
  251. /* Drop the rpmb subcommand */
  252. argc--;
  253. argv++;
  254. if (cp == NULL || argc > cp->maxargs)
  255. return CMD_RET_USAGE;
  256. if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
  257. return CMD_RET_SUCCESS;
  258. mmc = init_mmc_device(curr_device, false);
  259. if (!mmc)
  260. return CMD_RET_FAILURE;
  261. if (!(mmc->version & MMC_VERSION_MMC)) {
  262. printf("It is not an eMMC device\n");
  263. return CMD_RET_FAILURE;
  264. }
  265. if (mmc->version < MMC_VERSION_4_41) {
  266. printf("RPMB not supported before version 4.41\n");
  267. return CMD_RET_FAILURE;
  268. }
  269. /* Switch to the RPMB partition */
  270. #ifndef CONFIG_BLK
  271. original_part = mmc->block_dev.hwpart;
  272. #else
  273. original_part = mmc_get_blk_desc(mmc)->hwpart;
  274. #endif
  275. if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, MMC_PART_RPMB) !=
  276. 0)
  277. return CMD_RET_FAILURE;
  278. ret = cp->cmd(cmdtp, flag, argc, argv);
  279. /* Return to original partition */
  280. if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, original_part) !=
  281. 0)
  282. return CMD_RET_FAILURE;
  283. return ret;
  284. }
  285. #endif
  286. static int do_mmc_read(struct cmd_tbl *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 *)hextoul(argv[1], NULL);
  295. blk = hextoul(argv[2], NULL);
  296. cnt = hextoul(argv[3], NULL);
  297. mmc = init_mmc_device(curr_device, false);
  298. if (!mmc)
  299. return CMD_RET_FAILURE;
  300. printf("\nMMC read: dev # %d, block # %d, count %d ... ",
  301. curr_device, blk, cnt);
  302. n = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, addr);
  303. printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  304. return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
  305. }
  306. #if CONFIG_IS_ENABLED(CMD_MMC_SWRITE)
  307. static lbaint_t mmc_sparse_write(struct sparse_storage *info, lbaint_t blk,
  308. lbaint_t blkcnt, const void *buffer)
  309. {
  310. struct blk_desc *dev_desc = info->priv;
  311. return blk_dwrite(dev_desc, blk, blkcnt, buffer);
  312. }
  313. static lbaint_t mmc_sparse_reserve(struct sparse_storage *info,
  314. lbaint_t blk, lbaint_t blkcnt)
  315. {
  316. return blkcnt;
  317. }
  318. static int do_mmc_sparse_write(struct cmd_tbl *cmdtp, int flag,
  319. int argc, char *const argv[])
  320. {
  321. struct sparse_storage sparse;
  322. struct blk_desc *dev_desc;
  323. struct mmc *mmc;
  324. char dest[11];
  325. void *addr;
  326. u32 blk;
  327. if (argc != 3)
  328. return CMD_RET_USAGE;
  329. addr = (void *)hextoul(argv[1], NULL);
  330. blk = hextoul(argv[2], NULL);
  331. if (!is_sparse_image(addr)) {
  332. printf("Not a sparse image\n");
  333. return CMD_RET_FAILURE;
  334. }
  335. mmc = init_mmc_device(curr_device, false);
  336. if (!mmc)
  337. return CMD_RET_FAILURE;
  338. printf("\nMMC Sparse write: dev # %d, block # %d ... ",
  339. curr_device, blk);
  340. if (mmc_getwp(mmc) == 1) {
  341. printf("Error: card is write protected!\n");
  342. return CMD_RET_FAILURE;
  343. }
  344. dev_desc = mmc_get_blk_desc(mmc);
  345. sparse.priv = dev_desc;
  346. sparse.blksz = 512;
  347. sparse.start = blk;
  348. sparse.size = dev_desc->lba - blk;
  349. sparse.write = mmc_sparse_write;
  350. sparse.reserve = mmc_sparse_reserve;
  351. sparse.mssg = NULL;
  352. sprintf(dest, "0x" LBAF, sparse.start * sparse.blksz);
  353. if (write_sparse_image(&sparse, dest, addr, NULL))
  354. return CMD_RET_FAILURE;
  355. else
  356. return CMD_RET_SUCCESS;
  357. }
  358. #endif
  359. #if CONFIG_IS_ENABLED(MMC_WRITE)
  360. static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
  361. int argc, char *const argv[])
  362. {
  363. struct mmc *mmc;
  364. u32 blk, cnt, n;
  365. void *addr;
  366. if (argc != 4)
  367. return CMD_RET_USAGE;
  368. addr = (void *)hextoul(argv[1], NULL);
  369. blk = hextoul(argv[2], NULL);
  370. cnt = hextoul(argv[3], NULL);
  371. mmc = init_mmc_device(curr_device, false);
  372. if (!mmc)
  373. return CMD_RET_FAILURE;
  374. printf("\nMMC write: dev # %d, block # %d, count %d ... ",
  375. curr_device, blk, cnt);
  376. if (mmc_getwp(mmc) == 1) {
  377. printf("Error: card is write protected!\n");
  378. return CMD_RET_FAILURE;
  379. }
  380. n = blk_dwrite(mmc_get_blk_desc(mmc), blk, cnt, addr);
  381. printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  382. return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
  383. }
  384. static int do_mmc_erase(struct cmd_tbl *cmdtp, int flag,
  385. int argc, char *const argv[])
  386. {
  387. struct mmc *mmc;
  388. u32 blk, cnt, n;
  389. if (argc != 3)
  390. return CMD_RET_USAGE;
  391. blk = hextoul(argv[1], NULL);
  392. cnt = hextoul(argv[2], NULL);
  393. mmc = init_mmc_device(curr_device, false);
  394. if (!mmc)
  395. return CMD_RET_FAILURE;
  396. printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
  397. curr_device, blk, cnt);
  398. if (mmc_getwp(mmc) == 1) {
  399. printf("Error: card is write protected!\n");
  400. return CMD_RET_FAILURE;
  401. }
  402. n = blk_derase(mmc_get_blk_desc(mmc), blk, cnt);
  403. printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
  404. return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
  405. }
  406. #endif
  407. static int do_mmc_rescan(struct cmd_tbl *cmdtp, int flag,
  408. int argc, char *const argv[])
  409. {
  410. struct mmc *mmc;
  411. enum bus_mode speed_mode = MMC_MODES_END;
  412. if (argc == 1) {
  413. mmc = init_mmc_device(curr_device, true);
  414. } else if (argc == 2) {
  415. speed_mode = (int)dectoul(argv[1], NULL);
  416. mmc = __init_mmc_device(curr_device, true, speed_mode);
  417. } else {
  418. return CMD_RET_USAGE;
  419. }
  420. if (!mmc)
  421. return CMD_RET_FAILURE;
  422. return CMD_RET_SUCCESS;
  423. }
  424. static int do_mmc_part(struct cmd_tbl *cmdtp, int flag,
  425. int argc, char *const argv[])
  426. {
  427. struct blk_desc *mmc_dev;
  428. struct mmc *mmc;
  429. mmc = init_mmc_device(curr_device, false);
  430. if (!mmc)
  431. return CMD_RET_FAILURE;
  432. mmc_dev = blk_get_devnum_by_type(IF_TYPE_MMC, curr_device);
  433. if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
  434. part_print(mmc_dev);
  435. return CMD_RET_SUCCESS;
  436. }
  437. puts("get mmc type error!\n");
  438. return CMD_RET_FAILURE;
  439. }
  440. static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag,
  441. int argc, char *const argv[])
  442. {
  443. int dev, part = 0, ret;
  444. struct mmc *mmc;
  445. enum bus_mode speed_mode = MMC_MODES_END;
  446. if (argc == 1) {
  447. dev = curr_device;
  448. mmc = init_mmc_device(dev, true);
  449. } else if (argc == 2) {
  450. dev = (int)dectoul(argv[1], NULL);
  451. mmc = init_mmc_device(dev, true);
  452. } else if (argc == 3) {
  453. dev = (int)dectoul(argv[1], NULL);
  454. part = (int)dectoul(argv[2], NULL);
  455. if (part > PART_ACCESS_MASK) {
  456. printf("#part_num shouldn't be larger than %d\n",
  457. PART_ACCESS_MASK);
  458. return CMD_RET_FAILURE;
  459. }
  460. mmc = init_mmc_device(dev, true);
  461. } else if (argc == 4) {
  462. dev = (int)dectoul(argv[1], NULL);
  463. part = (int)dectoul(argv[2], NULL);
  464. if (part > PART_ACCESS_MASK) {
  465. printf("#part_num shouldn't be larger than %d\n",
  466. PART_ACCESS_MASK);
  467. return CMD_RET_FAILURE;
  468. }
  469. speed_mode = (int)dectoul(argv[3], NULL);
  470. mmc = __init_mmc_device(dev, true, speed_mode);
  471. } else {
  472. return CMD_RET_USAGE;
  473. }
  474. if (!mmc)
  475. return CMD_RET_FAILURE;
  476. ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part);
  477. printf("switch to partitions #%d, %s\n",
  478. part, (!ret) ? "OK" : "ERROR");
  479. if (ret)
  480. return 1;
  481. curr_device = dev;
  482. if (mmc->part_config == MMCPART_NOAVAILABLE)
  483. printf("mmc%d is current device\n", curr_device);
  484. else
  485. printf("mmc%d(part %d) is current device\n",
  486. curr_device, mmc_get_blk_desc(mmc)->hwpart);
  487. return CMD_RET_SUCCESS;
  488. }
  489. static int do_mmc_list(struct cmd_tbl *cmdtp, int flag,
  490. int argc, char *const argv[])
  491. {
  492. print_mmc_devices('\n');
  493. return CMD_RET_SUCCESS;
  494. }
  495. #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
  496. static void parse_hwpart_user_enh_size(struct mmc *mmc,
  497. struct mmc_hwpart_conf *pconf,
  498. char *argv)
  499. {
  500. int ret;
  501. pconf->user.enh_size = 0;
  502. if (!strcmp(argv, "-")) { /* The rest of eMMC */
  503. ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
  504. ret = mmc_send_ext_csd(mmc, ext_csd);
  505. if (ret)
  506. return;
  507. /* This value is in 512B block units */
  508. pconf->user.enh_size =
  509. ((ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16) +
  510. (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) +
  511. ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT]) * 1024 *
  512. ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] *
  513. ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
  514. pconf->user.enh_size -= pconf->user.enh_start;
  515. } else {
  516. pconf->user.enh_size = dectoul(argv, NULL);
  517. }
  518. }
  519. static int parse_hwpart_user(struct mmc *mmc, struct mmc_hwpart_conf *pconf,
  520. int argc, char *const argv[])
  521. {
  522. int i = 0;
  523. memset(&pconf->user, 0, sizeof(pconf->user));
  524. while (i < argc) {
  525. if (!strcmp(argv[i], "enh")) {
  526. if (i + 2 >= argc)
  527. return -1;
  528. pconf->user.enh_start =
  529. dectoul(argv[i + 1], NULL);
  530. parse_hwpart_user_enh_size(mmc, pconf, argv[i + 2]);
  531. i += 3;
  532. } else if (!strcmp(argv[i], "wrrel")) {
  533. if (i + 1 >= argc)
  534. return -1;
  535. pconf->user.wr_rel_change = 1;
  536. if (!strcmp(argv[i+1], "on"))
  537. pconf->user.wr_rel_set = 1;
  538. else if (!strcmp(argv[i+1], "off"))
  539. pconf->user.wr_rel_set = 0;
  540. else
  541. return -1;
  542. i += 2;
  543. } else {
  544. break;
  545. }
  546. }
  547. return i;
  548. }
  549. static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
  550. int argc, char *const argv[])
  551. {
  552. int i;
  553. memset(&pconf->gp_part[pidx], 0, sizeof(pconf->gp_part[pidx]));
  554. if (1 >= argc)
  555. return -1;
  556. pconf->gp_part[pidx].size = dectoul(argv[0], NULL);
  557. i = 1;
  558. while (i < argc) {
  559. if (!strcmp(argv[i], "enh")) {
  560. pconf->gp_part[pidx].enhanced = 1;
  561. i += 1;
  562. } else if (!strcmp(argv[i], "wrrel")) {
  563. if (i + 1 >= argc)
  564. return -1;
  565. pconf->gp_part[pidx].wr_rel_change = 1;
  566. if (!strcmp(argv[i+1], "on"))
  567. pconf->gp_part[pidx].wr_rel_set = 1;
  568. else if (!strcmp(argv[i+1], "off"))
  569. pconf->gp_part[pidx].wr_rel_set = 0;
  570. else
  571. return -1;
  572. i += 2;
  573. } else {
  574. break;
  575. }
  576. }
  577. return i;
  578. }
  579. static int do_mmc_hwpartition(struct cmd_tbl *cmdtp, int flag,
  580. int argc, char *const argv[])
  581. {
  582. struct mmc *mmc;
  583. struct mmc_hwpart_conf pconf = { };
  584. enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
  585. int i, r, pidx;
  586. mmc = init_mmc_device(curr_device, false);
  587. if (!mmc)
  588. return CMD_RET_FAILURE;
  589. if (IS_SD(mmc)) {
  590. puts("SD doesn't support partitioning\n");
  591. return CMD_RET_FAILURE;
  592. }
  593. if (argc < 1)
  594. return CMD_RET_USAGE;
  595. i = 1;
  596. while (i < argc) {
  597. if (!strcmp(argv[i], "user")) {
  598. i++;
  599. r = parse_hwpart_user(mmc, &pconf, argc - i, &argv[i]);
  600. if (r < 0)
  601. return CMD_RET_USAGE;
  602. i += r;
  603. } else if (!strncmp(argv[i], "gp", 2) &&
  604. strlen(argv[i]) == 3 &&
  605. argv[i][2] >= '1' && argv[i][2] <= '4') {
  606. pidx = argv[i][2] - '1';
  607. i++;
  608. r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]);
  609. if (r < 0)
  610. return CMD_RET_USAGE;
  611. i += r;
  612. } else if (!strcmp(argv[i], "check")) {
  613. mode = MMC_HWPART_CONF_CHECK;
  614. i++;
  615. } else if (!strcmp(argv[i], "set")) {
  616. mode = MMC_HWPART_CONF_SET;
  617. i++;
  618. } else if (!strcmp(argv[i], "complete")) {
  619. mode = MMC_HWPART_CONF_COMPLETE;
  620. i++;
  621. } else {
  622. return CMD_RET_USAGE;
  623. }
  624. }
  625. puts("Partition configuration:\n");
  626. if (pconf.user.enh_size) {
  627. puts("\tUser Enhanced Start: ");
  628. print_size(((u64)pconf.user.enh_start) << 9, "\n");
  629. puts("\tUser Enhanced Size: ");
  630. print_size(((u64)pconf.user.enh_size) << 9, "\n");
  631. } else {
  632. puts("\tNo enhanced user data area\n");
  633. }
  634. if (pconf.user.wr_rel_change)
  635. printf("\tUser partition write reliability: %s\n",
  636. pconf.user.wr_rel_set ? "on" : "off");
  637. for (pidx = 0; pidx < 4; pidx++) {
  638. if (pconf.gp_part[pidx].size) {
  639. printf("\tGP%i Capacity: ", pidx+1);
  640. print_size(((u64)pconf.gp_part[pidx].size) << 9,
  641. pconf.gp_part[pidx].enhanced ?
  642. " ENH\n" : "\n");
  643. } else {
  644. printf("\tNo GP%i partition\n", pidx+1);
  645. }
  646. if (pconf.gp_part[pidx].wr_rel_change)
  647. printf("\tGP%i write reliability: %s\n", pidx+1,
  648. pconf.gp_part[pidx].wr_rel_set ? "on" : "off");
  649. }
  650. if (!mmc_hwpart_config(mmc, &pconf, mode)) {
  651. if (mode == MMC_HWPART_CONF_COMPLETE)
  652. puts("Partitioning successful, "
  653. "power-cycle to make effective\n");
  654. return CMD_RET_SUCCESS;
  655. } else {
  656. puts("Failed!\n");
  657. return CMD_RET_FAILURE;
  658. }
  659. }
  660. #endif
  661. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  662. static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int flag,
  663. int argc, char *const argv[])
  664. {
  665. int dev;
  666. struct mmc *mmc;
  667. u8 width, reset, mode;
  668. if (argc != 5)
  669. return CMD_RET_USAGE;
  670. dev = dectoul(argv[1], NULL);
  671. width = dectoul(argv[2], NULL);
  672. reset = dectoul(argv[3], NULL);
  673. mode = dectoul(argv[4], NULL);
  674. mmc = init_mmc_device(dev, false);
  675. if (!mmc)
  676. return CMD_RET_FAILURE;
  677. if (IS_SD(mmc)) {
  678. puts("BOOT_BUS_WIDTH only exists on eMMC\n");
  679. return CMD_RET_FAILURE;
  680. }
  681. /*
  682. * BOOT_BUS_CONDITIONS[177]
  683. * BOOT_MODE[4:3]
  684. * 0x0 : Use SDR + Backward compatible timing in boot operation
  685. * 0x1 : Use SDR + High Speed Timing in boot operation mode
  686. * 0x2 : Use DDR in boot operation
  687. * RESET_BOOT_BUS_CONDITIONS
  688. * 0x0 : Reset bus width to x1, SDR, Backward compatible
  689. * 0x1 : Retain BOOT_BUS_WIDTH and BOOT_MODE
  690. * BOOT_BUS_WIDTH
  691. * 0x0 : x1(sdr) or x4 (ddr) buswidth
  692. * 0x1 : x4(sdr/ddr) buswith
  693. * 0x2 : x8(sdr/ddr) buswith
  694. *
  695. */
  696. if (width >= 0x3) {
  697. printf("boot_bus_width %d is invalid\n", width);
  698. return CMD_RET_FAILURE;
  699. }
  700. if (reset >= 0x2) {
  701. printf("reset_boot_bus_width %d is invalid\n", reset);
  702. return CMD_RET_FAILURE;
  703. }
  704. if (mode >= 0x3) {
  705. printf("reset_boot_bus_width %d is invalid\n", mode);
  706. return CMD_RET_FAILURE;
  707. }
  708. /* acknowledge to be sent during boot operation */
  709. if (mmc_set_boot_bus_width(mmc, width, reset, mode)) {
  710. puts("BOOT_BUS_WIDTH is failed to change.\n");
  711. return CMD_RET_FAILURE;
  712. }
  713. printf("Set to BOOT_BUS_WIDTH = 0x%x, RESET = 0x%x, BOOT_MODE = 0x%x\n",
  714. width, reset, mode);
  715. return CMD_RET_SUCCESS;
  716. }
  717. static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag,
  718. int argc, char *const argv[])
  719. {
  720. int dev;
  721. struct mmc *mmc;
  722. u32 bootsize, rpmbsize;
  723. if (argc != 4)
  724. return CMD_RET_USAGE;
  725. dev = dectoul(argv[1], NULL);
  726. bootsize = dectoul(argv[2], NULL);
  727. rpmbsize = dectoul(argv[3], NULL);
  728. mmc = init_mmc_device(dev, false);
  729. if (!mmc)
  730. return CMD_RET_FAILURE;
  731. if (IS_SD(mmc)) {
  732. printf("It is not an eMMC device\n");
  733. return CMD_RET_FAILURE;
  734. }
  735. if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) {
  736. printf("EMMC boot partition Size change Failed.\n");
  737. return CMD_RET_FAILURE;
  738. }
  739. printf("EMMC boot partition Size %d MB\n", bootsize);
  740. printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
  741. return CMD_RET_SUCCESS;
  742. }
  743. static int mmc_partconf_print(struct mmc *mmc, const char *varname)
  744. {
  745. u8 ack, access, part;
  746. if (mmc->part_config == MMCPART_NOAVAILABLE) {
  747. printf("No part_config info for ver. 0x%x\n", mmc->version);
  748. return CMD_RET_FAILURE;
  749. }
  750. access = EXT_CSD_EXTRACT_PARTITION_ACCESS(mmc->part_config);
  751. ack = EXT_CSD_EXTRACT_BOOT_ACK(mmc->part_config);
  752. part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
  753. if(varname)
  754. env_set_hex(varname, part);
  755. printf("EXT_CSD[179], PARTITION_CONFIG:\n"
  756. "BOOT_ACK: 0x%x\n"
  757. "BOOT_PARTITION_ENABLE: 0x%x\n"
  758. "PARTITION_ACCESS: 0x%x\n", ack, part, access);
  759. return CMD_RET_SUCCESS;
  760. }
  761. static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
  762. int argc, char *const argv[])
  763. {
  764. int dev;
  765. struct mmc *mmc;
  766. u8 ack, part_num, access;
  767. if (argc != 2 && argc != 3 && argc != 5)
  768. return CMD_RET_USAGE;
  769. dev = dectoul(argv[1], NULL);
  770. mmc = init_mmc_device(dev, false);
  771. if (!mmc)
  772. return CMD_RET_FAILURE;
  773. if (IS_SD(mmc)) {
  774. puts("PARTITION_CONFIG only exists on eMMC\n");
  775. return CMD_RET_FAILURE;
  776. }
  777. if (argc == 2 || argc == 3)
  778. return mmc_partconf_print(mmc, argc == 3 ? argv[2] : NULL);
  779. ack = dectoul(argv[2], NULL);
  780. part_num = dectoul(argv[3], NULL);
  781. access = dectoul(argv[4], NULL);
  782. /* acknowledge to be sent during boot operation */
  783. return mmc_set_part_conf(mmc, ack, part_num, access);
  784. }
  785. static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
  786. int argc, char *const argv[])
  787. {
  788. int dev;
  789. struct mmc *mmc;
  790. u8 enable;
  791. /*
  792. * Set the RST_n_ENABLE bit of RST_n_FUNCTION
  793. * The only valid values are 0x0, 0x1 and 0x2 and writing
  794. * a value of 0x1 or 0x2 sets the value permanently.
  795. */
  796. if (argc != 3)
  797. return CMD_RET_USAGE;
  798. dev = dectoul(argv[1], NULL);
  799. enable = dectoul(argv[2], NULL);
  800. if (enable > 2) {
  801. puts("Invalid RST_n_ENABLE value\n");
  802. return CMD_RET_USAGE;
  803. }
  804. mmc = init_mmc_device(dev, false);
  805. if (!mmc)
  806. return CMD_RET_FAILURE;
  807. if (IS_SD(mmc)) {
  808. puts("RST_n_FUNCTION only exists on eMMC\n");
  809. return CMD_RET_FAILURE;
  810. }
  811. return mmc_set_rst_n_function(mmc, enable);
  812. }
  813. #endif
  814. static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
  815. int argc, char *const argv[])
  816. {
  817. struct mmc *mmc;
  818. u32 val;
  819. int ret;
  820. if (argc != 2)
  821. return CMD_RET_USAGE;
  822. val = hextoul(argv[1], NULL);
  823. mmc = find_mmc_device(curr_device);
  824. if (!mmc) {
  825. printf("no mmc device at slot %x\n", curr_device);
  826. return CMD_RET_FAILURE;
  827. }
  828. ret = mmc_set_dsr(mmc, val);
  829. printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR");
  830. if (!ret) {
  831. mmc->has_init = 0;
  832. if (mmc_init(mmc))
  833. return CMD_RET_FAILURE;
  834. else
  835. return CMD_RET_SUCCESS;
  836. }
  837. return ret;
  838. }
  839. #ifdef CONFIG_CMD_BKOPS_ENABLE
  840. static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag,
  841. int argc, char *const argv[])
  842. {
  843. int dev;
  844. struct mmc *mmc;
  845. if (argc != 2)
  846. return CMD_RET_USAGE;
  847. dev = dectoul(argv[1], NULL);
  848. mmc = init_mmc_device(dev, false);
  849. if (!mmc)
  850. return CMD_RET_FAILURE;
  851. if (IS_SD(mmc)) {
  852. puts("BKOPS_EN only exists on eMMC\n");
  853. return CMD_RET_FAILURE;
  854. }
  855. return mmc_set_bkops_enable(mmc);
  856. }
  857. #endif
  858. static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
  859. int argc, char * const argv[])
  860. {
  861. int err;
  862. struct mmc *mmc;
  863. mmc = init_mmc_device(curr_device, false);
  864. if (!mmc)
  865. return CMD_RET_FAILURE;
  866. if (IS_SD(mmc)) {
  867. printf("It is not an eMMC device\n");
  868. return CMD_RET_FAILURE;
  869. }
  870. err = mmc_boot_wp(mmc);
  871. if (err)
  872. return CMD_RET_FAILURE;
  873. printf("boot areas protected\n");
  874. return CMD_RET_SUCCESS;
  875. }
  876. static struct cmd_tbl cmd_mmc[] = {
  877. U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
  878. U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
  879. U_BOOT_CMD_MKENT(wp, 1, 0, do_mmc_boot_wp, "", ""),
  880. #if CONFIG_IS_ENABLED(MMC_WRITE)
  881. U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
  882. U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
  883. #endif
  884. #if CONFIG_IS_ENABLED(CMD_MMC_SWRITE)
  885. U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""),
  886. #endif
  887. U_BOOT_CMD_MKENT(rescan, 2, 1, do_mmc_rescan, "", ""),
  888. U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
  889. U_BOOT_CMD_MKENT(dev, 4, 0, do_mmc_dev, "", ""),
  890. U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""),
  891. #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
  892. U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),
  893. #endif
  894. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  895. U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
  896. U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""),
  897. U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
  898. U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
  899. #endif
  900. #if CONFIG_IS_ENABLED(CMD_MMC_RPMB)
  901. U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""),
  902. #endif
  903. U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
  904. #ifdef CONFIG_CMD_BKOPS_ENABLE
  905. U_BOOT_CMD_MKENT(bkops-enable, 2, 0, do_mmc_bkops_enable, "", ""),
  906. #endif
  907. };
  908. static int do_mmcops(struct cmd_tbl *cmdtp, int flag, int argc,
  909. char *const argv[])
  910. {
  911. struct cmd_tbl *cp;
  912. cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
  913. /* Drop the mmc command */
  914. argc--;
  915. argv++;
  916. if (cp == NULL || argc > cp->maxargs)
  917. return CMD_RET_USAGE;
  918. if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
  919. return CMD_RET_SUCCESS;
  920. if (curr_device < 0) {
  921. if (get_mmc_num() > 0) {
  922. curr_device = 0;
  923. } else {
  924. puts("No MMC device available\n");
  925. return CMD_RET_FAILURE;
  926. }
  927. }
  928. return cp->cmd(cmdtp, flag, argc, argv);
  929. }
  930. U_BOOT_CMD(
  931. mmc, 29, 1, do_mmcops,
  932. "MMC sub system",
  933. "info - display info of the current MMC device\n"
  934. "mmc read addr blk# cnt\n"
  935. "mmc write addr blk# cnt\n"
  936. #if CONFIG_IS_ENABLED(CMD_MMC_SWRITE)
  937. "mmc swrite addr blk#\n"
  938. #endif
  939. "mmc erase blk# cnt\n"
  940. "mmc rescan [mode]\n"
  941. "mmc part - lists available partition on current mmc device\n"
  942. "mmc dev [dev] [part] [mode] - show or set current mmc device [partition] and set mode\n"
  943. " - the required speed mode is passed as the index from the following list\n"
  944. " [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52, UHS_SDR12, UHS_SDR25,\n"
  945. " UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200, MMC_HS_400, MMC_HS_400_ES]\n"
  946. "mmc list - lists available devices\n"
  947. "mmc wp - power on write protect boot partitions\n"
  948. #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
  949. "mmc hwpartition <USER> <GP> <MODE> - does hardware partitioning\n"
  950. " arguments (sizes in 512-byte blocks):\n"
  951. " USER - <user> <enh> <start> <cnt> <wrrel> <{on|off}>\n"
  952. " : sets user data area attributes\n"
  953. " GP - <{gp1|gp2|gp3|gp4}> <cnt> <enh> <wrrel> <{on|off}>\n"
  954. " : general purpose partition\n"
  955. " MODE - <{check|set|complete}>\n"
  956. " : mode, complete set partitioning completed\n"
  957. " WARNING: Partitioning is a write-once setting once it is set to complete.\n"
  958. " Power cycling is required to initialize partitions after set to complete.\n"
  959. #endif
  960. #ifdef CONFIG_SUPPORT_EMMC_BOOT
  961. "mmc bootbus <dev> <boot_bus_width> <reset_boot_bus_width> <boot_mode>\n"
  962. " - Set the BOOT_BUS_WIDTH field of the specified device\n"
  963. "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
  964. " - Change sizes of boot and RPMB partitions of specified device\n"
  965. "mmc partconf <dev> [[varname] | [<boot_ack> <boot_partition> <partition_access>]]\n"
  966. " - Show or change the bits of the PARTITION_CONFIG field of the specified device\n"
  967. " If showing the bits, optionally store the boot_partition field into varname\n"
  968. "mmc rst-function <dev> <value>\n"
  969. " - Change the RST_n_FUNCTION field of the specified device\n"
  970. " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
  971. #endif
  972. #if CONFIG_IS_ENABLED(CMD_MMC_RPMB)
  973. "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
  974. "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
  975. "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
  976. "mmc rpmb counter - read the value of the write counter\n"
  977. #endif
  978. "mmc setdsr <value> - set DSR register value\n"
  979. #ifdef CONFIG_CMD_BKOPS_ENABLE
  980. "mmc bkops-enable <dev> - enable background operations handshake on device\n"
  981. " WARNING: This is a write-once setting.\n"
  982. #endif
  983. );
  984. /* Old command kept for compatibility. Same as 'mmc info' */
  985. U_BOOT_CMD(
  986. mmcinfo, 1, 0, do_mmcinfo,
  987. "display MMC info",
  988. "- display info of the current MMC device"
  989. );