3 * Kyle Harris, kharris@nexus-tech.net
5 * SPDX-License-Identifier: GPL-2.0+
12 static int curr_device = -1;
13 #ifndef CONFIG_GENERIC_MMC
14 int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
21 if (strcmp(argv[1], "init") == 0) {
27 } else if (argc == 3) {
28 dev = (int)simple_strtoul(argv[2], NULL, 10);
33 if (mmc_legacy_init(dev) != 0) {
34 puts("No MMC card found\n");
39 printf("mmc%d is available\n", curr_device);
40 } else if (strcmp(argv[1], "device") == 0) {
42 if (curr_device < 0) {
43 puts("No MMC device available\n");
46 } else if (argc == 3) {
47 dev = (int)simple_strtoul(argv[2], NULL, 10);
49 #ifdef CONFIG_SYS_MMC_SET_DEV
50 if (mmc_set_dev(dev) != 0)
58 printf("mmc%d is current device\n", curr_device);
69 "init [dev] - init MMC sub system\n"
70 "mmc device [dev] - show or set current device"
72 #else /* !CONFIG_GENERIC_MMC */
74 static void print_mmcinfo(struct mmc *mmc)
78 printf("Device: %s\n", mmc->cfg->name);
79 printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
80 printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
81 printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
82 (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
83 (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
85 printf("Tran Speed: %d\n", mmc->tran_speed);
86 printf("Rd Block Len: %d\n", mmc->read_bl_len);
88 printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
89 (mmc->version >> 8) & 0xf, mmc->version & 0xff);
91 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
93 print_size(mmc->capacity, "\n");
95 printf("Bus Width: %d-bit%s\n", mmc->bus_width,
96 mmc->ddr_mode ? " DDR" : "");
98 puts("Erase Group Size: ");
99 print_size(((u64)mmc->erase_grp_size) << 9, "\n");
101 if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) {
102 bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0;
103 bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR);
105 puts("HC WP Group Size: ");
106 print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n");
108 puts("User Capacity: ");
109 print_size(mmc->capacity_user, usr_enh ? " ENH" : "");
110 if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_USR)
115 puts("User Enhanced Start: ");
116 print_size(mmc->enh_user_start, "\n");
117 puts("User Enhanced Size: ");
118 print_size(mmc->enh_user_size, "\n");
120 puts("Boot Capacity: ");
121 print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n");
122 puts("RPMB Capacity: ");
123 print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n");
125 for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
126 bool is_enh = has_enh &&
127 (mmc->part_attr & EXT_CSD_ENH_GP(i));
128 if (mmc->capacity_gp[i]) {
129 printf("GP%i Capacity: ", i+1);
130 print_size(mmc->capacity_gp[i],
131 is_enh ? " ENH" : "");
132 if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_GP(i))
140 static struct mmc *init_mmc_device(int dev, bool force_init)
143 mmc = find_mmc_device(dev);
145 printf("no mmc device at slot %x\n", dev);
154 static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
158 if (curr_device < 0) {
159 if (get_mmc_num() > 0)
162 puts("No MMC device available\n");
167 mmc = init_mmc_device(curr_device, false);
169 return CMD_RET_FAILURE;
172 return CMD_RET_SUCCESS;
175 #ifdef CONFIG_SUPPORT_EMMC_RPMB
176 static int confirm_key_prog(void)
178 puts("Warning: Programming authentication key can be done only once !\n"
179 " Use this command only if you are sure of what you are doing,\n"
180 "Really perform the key programming? <y/N> ");
184 puts("Authentication key programming aborted\n");
187 static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
188 int argc, char * const argv[])
191 struct mmc *mmc = find_mmc_device(curr_device);
194 return CMD_RET_USAGE;
196 key_addr = (void *)simple_strtoul(argv[1], NULL, 16);
197 if (!confirm_key_prog())
198 return CMD_RET_FAILURE;
199 if (mmc_rpmb_set_key(mmc, key_addr)) {
200 printf("ERROR - Key already programmed ?\n");
201 return CMD_RET_FAILURE;
203 return CMD_RET_SUCCESS;
205 static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
206 int argc, char * const argv[])
211 void *key_addr = NULL;
212 struct mmc *mmc = find_mmc_device(curr_device);
215 return CMD_RET_USAGE;
217 addr = (void *)simple_strtoul(argv[1], NULL, 16);
218 blk = simple_strtoul(argv[2], NULL, 16);
219 cnt = simple_strtoul(argv[3], NULL, 16);
222 key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
224 printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
225 curr_device, blk, cnt);
226 n = mmc_rpmb_read(mmc, addr, blk, cnt, key_addr);
228 printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
230 return CMD_RET_FAILURE;
231 return CMD_RET_SUCCESS;
233 static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
234 int argc, char * const argv[])
240 struct mmc *mmc = find_mmc_device(curr_device);
243 return CMD_RET_USAGE;
245 addr = (void *)simple_strtoul(argv[1], NULL, 16);
246 blk = simple_strtoul(argv[2], NULL, 16);
247 cnt = simple_strtoul(argv[3], NULL, 16);
248 key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
250 printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
251 curr_device, blk, cnt);
252 n = mmc_rpmb_write(mmc, addr, blk, cnt, key_addr);
254 printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
256 return CMD_RET_FAILURE;
257 return CMD_RET_SUCCESS;
259 static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
260 int argc, char * const argv[])
262 unsigned long counter;
263 struct mmc *mmc = find_mmc_device(curr_device);
265 if (mmc_rpmb_get_counter(mmc, &counter))
266 return CMD_RET_FAILURE;
267 printf("RPMB Write counter= %lx\n", counter);
268 return CMD_RET_SUCCESS;
271 static cmd_tbl_t cmd_rpmb[] = {
272 U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""),
273 U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""),
274 U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""),
275 U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""),
278 static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
279 int argc, char * const argv[])
286 cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
288 /* Drop the rpmb subcommand */
292 if (cp == NULL || argc > cp->maxargs)
293 return CMD_RET_USAGE;
294 if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
295 return CMD_RET_SUCCESS;
297 mmc = init_mmc_device(curr_device, false);
299 return CMD_RET_FAILURE;
301 if (!(mmc->version & MMC_VERSION_MMC)) {
302 printf("It is not a EMMC device\n");
303 return CMD_RET_FAILURE;
305 if (mmc->version < MMC_VERSION_4_41) {
306 printf("RPMB not supported before version 4.41\n");
307 return CMD_RET_FAILURE;
309 /* Switch to the RPMB partition */
310 original_part = mmc->part_num;
311 if (mmc->part_num != MMC_PART_RPMB) {
312 if (mmc_switch_part(curr_device, MMC_PART_RPMB) != 0)
313 return CMD_RET_FAILURE;
314 mmc->part_num = MMC_PART_RPMB;
316 ret = cp->cmd(cmdtp, flag, argc, argv);
318 /* Return to original partition */
319 if (mmc->part_num != original_part) {
320 if (mmc_switch_part(curr_device, original_part) != 0)
321 return CMD_RET_FAILURE;
322 mmc->part_num = original_part;
328 static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
329 int argc, char * const argv[])
336 return CMD_RET_USAGE;
338 addr = (void *)simple_strtoul(argv[1], NULL, 16);
339 blk = simple_strtoul(argv[2], NULL, 16);
340 cnt = simple_strtoul(argv[3], NULL, 16);
342 mmc = init_mmc_device(curr_device, false);
344 return CMD_RET_FAILURE;
346 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
347 curr_device, blk, cnt);
349 n = mmc->block_dev.block_read(curr_device, blk, cnt, addr);
350 /* flush cache after read */
351 flush_cache((ulong)addr, cnt * 512); /* FIXME */
352 printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
354 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
356 static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
357 int argc, char * const argv[])
364 return CMD_RET_USAGE;
366 addr = (void *)simple_strtoul(argv[1], NULL, 16);
367 blk = simple_strtoul(argv[2], NULL, 16);
368 cnt = simple_strtoul(argv[3], NULL, 16);
370 mmc = init_mmc_device(curr_device, false);
372 return CMD_RET_FAILURE;
374 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
375 curr_device, blk, cnt);
377 if (mmc_getwp(mmc) == 1) {
378 printf("Error: card is write protected!\n");
379 return CMD_RET_FAILURE;
381 n = mmc->block_dev.block_write(curr_device, blk, cnt, addr);
382 printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
384 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
386 static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
387 int argc, char * const argv[])
393 return CMD_RET_USAGE;
395 blk = simple_strtoul(argv[1], NULL, 16);
396 cnt = simple_strtoul(argv[2], NULL, 16);
398 mmc = init_mmc_device(curr_device, false);
400 return CMD_RET_FAILURE;
402 printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
403 curr_device, blk, cnt);
405 if (mmc_getwp(mmc) == 1) {
406 printf("Error: card is write protected!\n");
407 return CMD_RET_FAILURE;
409 n = mmc->block_dev.block_erase(curr_device, blk, cnt);
410 printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
412 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
414 static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
415 int argc, char * const argv[])
419 mmc = init_mmc_device(curr_device, true);
421 return CMD_RET_FAILURE;
423 return CMD_RET_SUCCESS;
425 static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
426 int argc, char * const argv[])
428 block_dev_desc_t *mmc_dev;
431 mmc = init_mmc_device(curr_device, false);
433 return CMD_RET_FAILURE;
435 mmc_dev = mmc_get_dev(curr_device);
436 if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
438 return CMD_RET_SUCCESS;
441 puts("get mmc type error!\n");
442 return CMD_RET_FAILURE;
444 static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
445 int argc, char * const argv[])
447 int dev, part = 0, ret;
452 } else if (argc == 2) {
453 dev = simple_strtoul(argv[1], NULL, 10);
454 } else if (argc == 3) {
455 dev = (int)simple_strtoul(argv[1], NULL, 10);
456 part = (int)simple_strtoul(argv[2], NULL, 10);
457 if (part > PART_ACCESS_MASK) {
458 printf("#part_num shouldn't be larger than %d\n",
460 return CMD_RET_FAILURE;
463 return CMD_RET_USAGE;
466 mmc = init_mmc_device(dev, true);
468 return CMD_RET_FAILURE;
470 ret = mmc_select_hwpart(dev, part);
471 printf("switch to partitions #%d, %s\n",
472 part, (!ret) ? "OK" : "ERROR");
477 if (mmc->part_config == MMCPART_NOAVAILABLE)
478 printf("mmc%d is current device\n", curr_device);
480 printf("mmc%d(part %d) is current device\n",
481 curr_device, mmc->part_num);
483 return CMD_RET_SUCCESS;
485 static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
486 int argc, char * const argv[])
488 print_mmc_devices('\n');
489 return CMD_RET_SUCCESS;
492 static int parse_hwpart_user(struct mmc_hwpart_conf *pconf,
493 int argc, char * const argv[])
497 memset(&pconf->user, 0, sizeof(pconf->user));
500 if (!strcmp(argv[i], "enh")) {
503 pconf->user.enh_start =
504 simple_strtoul(argv[i+1], NULL, 10);
505 pconf->user.enh_size =
506 simple_strtoul(argv[i+2], NULL, 10);
508 } else if (!strcmp(argv[i], "wrrel")) {
511 pconf->user.wr_rel_change = 1;
512 if (!strcmp(argv[i+1], "on"))
513 pconf->user.wr_rel_set = 1;
514 else if (!strcmp(argv[i+1], "off"))
515 pconf->user.wr_rel_set = 0;
526 static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
527 int argc, char * const argv[])
531 memset(&pconf->gp_part[pidx], 0, sizeof(pconf->gp_part[pidx]));
535 pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10);
539 if (!strcmp(argv[i], "enh")) {
540 pconf->gp_part[pidx].enhanced = 1;
542 } else if (!strcmp(argv[i], "wrrel")) {
545 pconf->gp_part[pidx].wr_rel_change = 1;
546 if (!strcmp(argv[i+1], "on"))
547 pconf->gp_part[pidx].wr_rel_set = 1;
548 else if (!strcmp(argv[i+1], "off"))
549 pconf->gp_part[pidx].wr_rel_set = 0;
560 static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag,
561 int argc, char * const argv[])
564 struct mmc_hwpart_conf pconf = { };
565 enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
568 mmc = init_mmc_device(curr_device, false);
570 return CMD_RET_FAILURE;
573 return CMD_RET_USAGE;
576 if (!strcmp(argv[i], "user")) {
578 r = parse_hwpart_user(&pconf, argc-i, &argv[i]);
580 return CMD_RET_USAGE;
582 } else if (!strncmp(argv[i], "gp", 2) &&
583 strlen(argv[i]) == 3 &&
584 argv[i][2] >= '1' && argv[i][2] <= '4') {
585 pidx = argv[i][2] - '1';
587 r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]);
589 return CMD_RET_USAGE;
591 } else if (!strcmp(argv[i], "check")) {
592 mode = MMC_HWPART_CONF_CHECK;
594 } else if (!strcmp(argv[i], "set")) {
595 mode = MMC_HWPART_CONF_SET;
597 } else if (!strcmp(argv[i], "complete")) {
598 mode = MMC_HWPART_CONF_COMPLETE;
601 return CMD_RET_USAGE;
605 puts("Partition configuration:\n");
606 if (pconf.user.enh_size) {
607 puts("\tUser Enhanced Start: ");
608 print_size(((u64)pconf.user.enh_start) << 9, "\n");
609 puts("\tUser Enhanced Size: ");
610 print_size(((u64)pconf.user.enh_size) << 9, "\n");
612 puts("\tNo enhanced user data area\n");
614 if (pconf.user.wr_rel_change)
615 printf("\tUser partition write reliability: %s\n",
616 pconf.user.wr_rel_set ? "on" : "off");
617 for (pidx = 0; pidx < 4; pidx++) {
618 if (pconf.gp_part[pidx].size) {
619 printf("\tGP%i Capacity: ", pidx+1);
620 print_size(((u64)pconf.gp_part[pidx].size) << 9,
621 pconf.gp_part[pidx].enhanced ?
624 printf("\tNo GP%i partition\n", pidx+1);
626 if (pconf.gp_part[pidx].wr_rel_change)
627 printf("\tGP%i write reliability: %s\n", pidx+1,
628 pconf.gp_part[pidx].wr_rel_set ? "on" : "off");
631 if (!mmc_hwpart_config(mmc, &pconf, mode)) {
632 if (mode == MMC_HWPART_CONF_COMPLETE)
633 puts("Partitioning successful, "
634 "power-cycle to make effective\n");
635 return CMD_RET_SUCCESS;
638 return CMD_RET_FAILURE;
642 #ifdef CONFIG_SUPPORT_EMMC_BOOT
643 static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
644 int argc, char * const argv[])
648 u8 width, reset, mode;
651 return CMD_RET_USAGE;
652 dev = simple_strtoul(argv[1], NULL, 10);
653 width = simple_strtoul(argv[2], NULL, 10);
654 reset = simple_strtoul(argv[3], NULL, 10);
655 mode = simple_strtoul(argv[4], NULL, 10);
657 mmc = init_mmc_device(dev, false);
659 return CMD_RET_FAILURE;
662 puts("BOOT_BUS_WIDTH only exists on eMMC\n");
663 return CMD_RET_FAILURE;
666 /* acknowledge to be sent during boot operation */
667 return mmc_set_boot_bus_width(mmc, width, reset, mode);
669 static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
670 int argc, char * const argv[])
674 u32 bootsize, rpmbsize;
677 return CMD_RET_USAGE;
678 dev = simple_strtoul(argv[1], NULL, 10);
679 bootsize = simple_strtoul(argv[2], NULL, 10);
680 rpmbsize = simple_strtoul(argv[3], NULL, 10);
682 mmc = init_mmc_device(dev, false);
684 return CMD_RET_FAILURE;
687 printf("It is not a EMMC device\n");
688 return CMD_RET_FAILURE;
691 if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) {
692 printf("EMMC boot partition Size change Failed.\n");
693 return CMD_RET_FAILURE;
696 printf("EMMC boot partition Size %d MB\n", bootsize);
697 printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
698 return CMD_RET_SUCCESS;
700 static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
701 int argc, char * const argv[])
705 u8 ack, part_num, access;
708 return CMD_RET_USAGE;
710 dev = simple_strtoul(argv[1], NULL, 10);
711 ack = simple_strtoul(argv[2], NULL, 10);
712 part_num = simple_strtoul(argv[3], NULL, 10);
713 access = simple_strtoul(argv[4], NULL, 10);
715 mmc = init_mmc_device(dev, false);
717 return CMD_RET_FAILURE;
720 puts("PARTITION_CONFIG only exists on eMMC\n");
721 return CMD_RET_FAILURE;
724 /* acknowledge to be sent during boot operation */
725 return mmc_set_part_conf(mmc, ack, part_num, access);
727 static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
728 int argc, char * const argv[])
735 * Set the RST_n_ENABLE bit of RST_n_FUNCTION
736 * The only valid values are 0x0, 0x1 and 0x2 and writing
737 * a value of 0x1 or 0x2 sets the value permanently.
740 return CMD_RET_USAGE;
742 dev = simple_strtoul(argv[1], NULL, 10);
743 enable = simple_strtoul(argv[2], NULL, 10);
745 if (enable > 2 || enable < 0) {
746 puts("Invalid RST_n_ENABLE value\n");
747 return CMD_RET_USAGE;
750 mmc = init_mmc_device(dev, false);
752 return CMD_RET_FAILURE;
755 puts("RST_n_FUNCTION only exists on eMMC\n");
756 return CMD_RET_FAILURE;
759 return mmc_set_rst_n_function(mmc, enable);
762 static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
763 int argc, char * const argv[])
770 return CMD_RET_USAGE;
771 val = simple_strtoul(argv[2], NULL, 16);
773 mmc = find_mmc_device(curr_device);
775 printf("no mmc device at slot %x\n", curr_device);
776 return CMD_RET_FAILURE;
778 ret = mmc_set_dsr(mmc, val);
779 printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR");
783 return CMD_RET_FAILURE;
785 return CMD_RET_SUCCESS;
790 static cmd_tbl_t cmd_mmc[] = {
791 U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
792 U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
793 U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
794 U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
795 U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
796 U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
797 U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""),
798 U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""),
799 U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),
800 #ifdef CONFIG_SUPPORT_EMMC_BOOT
801 U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
802 U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""),
803 U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
804 U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
806 #ifdef CONFIG_SUPPORT_EMMC_RPMB
807 U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""),
809 U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
812 static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
816 cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
818 /* Drop the mmc command */
822 if (cp == NULL || argc > cp->maxargs)
823 return CMD_RET_USAGE;
824 if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
825 return CMD_RET_SUCCESS;
827 if (curr_device < 0) {
828 if (get_mmc_num() > 0) {
831 puts("No MMC device available\n");
832 return CMD_RET_FAILURE;
835 return cp->cmd(cmdtp, flag, argc, argv);
839 mmc, 29, 1, do_mmcops,
841 "info - display info of the current MMC device\n"
842 "mmc read addr blk# cnt\n"
843 "mmc write addr blk# cnt\n"
844 "mmc erase blk# cnt\n"
846 "mmc part - lists available partition on current mmc device\n"
847 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
848 "mmc list - lists available devices\n"
849 "mmc hwpartition [args...] - does hardware partitioning\n"
850 " arguments (sizes in 512-byte blocks):\n"
851 " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n"
852 " [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n"
853 " [check|set|complete] - mode, complete set partitioning completed\n"
854 " WARNING: Partitioning is a write-once setting once it is set to complete.\n"
855 " Power cycling is required to initialize partitions after set to complete.\n"
856 #ifdef CONFIG_SUPPORT_EMMC_BOOT
857 "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
858 " - Set the BOOT_BUS_WIDTH field of the specified device\n"
859 "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
860 " - Change sizes of boot and RPMB partitions of specified device\n"
861 "mmc partconf dev boot_ack boot_partition partition_access\n"
862 " - Change the bits of the PARTITION_CONFIG field of the specified device\n"
863 "mmc rst-function dev value\n"
864 " - Change the RST_n_FUNCTION field of the specified device\n"
865 " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
867 #ifdef CONFIG_SUPPORT_EMMC_RPMB
868 "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
869 "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
870 "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
871 "mmc rpmb counter - read the value of the write counter\n"
873 "mmc setdsr <value> - set DSR register value\n"
876 /* Old command kept for compatibility. Same as 'mmc info' */
878 mmcinfo, 1, 0, do_mmcinfo,
880 "- display info of the current MMC device"
883 #endif /* !CONFIG_GENERIC_MMC */