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", IS_SD(mmc) ? "SD" : "MMC",
89 EXTRACT_SDMMC_MAJOR_VERSION(mmc->version),
90 EXTRACT_SDMMC_MINOR_VERSION(mmc->version));
91 if (EXTRACT_SDMMC_CHANGE_VERSION(mmc->version) != 0)
92 printf(".%d", EXTRACT_SDMMC_CHANGE_VERSION(mmc->version));
95 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
97 print_size(mmc->capacity, "\n");
99 printf("Bus Width: %d-bit%s\n", mmc->bus_width,
100 mmc->ddr_mode ? " DDR" : "");
102 puts("Erase Group Size: ");
103 print_size(((u64)mmc->erase_grp_size) << 9, "\n");
105 if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) {
106 bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0;
107 bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR);
109 puts("HC WP Group Size: ");
110 print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n");
112 puts("User Capacity: ");
113 print_size(mmc->capacity_user, usr_enh ? " ENH" : "");
114 if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_USR)
119 puts("User Enhanced Start: ");
120 print_size(mmc->enh_user_start, "\n");
121 puts("User Enhanced Size: ");
122 print_size(mmc->enh_user_size, "\n");
124 puts("Boot Capacity: ");
125 print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n");
126 puts("RPMB Capacity: ");
127 print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n");
129 for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
130 bool is_enh = has_enh &&
131 (mmc->part_attr & EXT_CSD_ENH_GP(i));
132 if (mmc->capacity_gp[i]) {
133 printf("GP%i Capacity: ", i+1);
134 print_size(mmc->capacity_gp[i],
135 is_enh ? " ENH" : "");
136 if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_GP(i))
144 static struct mmc *init_mmc_device(int dev, bool force_init)
147 mmc = find_mmc_device(dev);
149 printf("no mmc device at slot %x\n", dev);
158 static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
162 if (curr_device < 0) {
163 if (get_mmc_num() > 0)
166 puts("No MMC device available\n");
171 mmc = init_mmc_device(curr_device, false);
173 return CMD_RET_FAILURE;
176 return CMD_RET_SUCCESS;
179 #ifdef CONFIG_SUPPORT_EMMC_RPMB
180 static int confirm_key_prog(void)
182 puts("Warning: Programming authentication key can be done only once !\n"
183 " Use this command only if you are sure of what you are doing,\n"
184 "Really perform the key programming? <y/N> ");
188 puts("Authentication key programming aborted\n");
191 static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
192 int argc, char * const argv[])
195 struct mmc *mmc = find_mmc_device(curr_device);
198 return CMD_RET_USAGE;
200 key_addr = (void *)simple_strtoul(argv[1], NULL, 16);
201 if (!confirm_key_prog())
202 return CMD_RET_FAILURE;
203 if (mmc_rpmb_set_key(mmc, key_addr)) {
204 printf("ERROR - Key already programmed ?\n");
205 return CMD_RET_FAILURE;
207 return CMD_RET_SUCCESS;
209 static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
210 int argc, char * const argv[])
215 void *key_addr = NULL;
216 struct mmc *mmc = find_mmc_device(curr_device);
219 return CMD_RET_USAGE;
221 addr = (void *)simple_strtoul(argv[1], NULL, 16);
222 blk = simple_strtoul(argv[2], NULL, 16);
223 cnt = simple_strtoul(argv[3], NULL, 16);
226 key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
228 printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
229 curr_device, blk, cnt);
230 n = mmc_rpmb_read(mmc, addr, blk, cnt, key_addr);
232 printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
234 return CMD_RET_FAILURE;
235 return CMD_RET_SUCCESS;
237 static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
238 int argc, char * const argv[])
244 struct mmc *mmc = find_mmc_device(curr_device);
247 return CMD_RET_USAGE;
249 addr = (void *)simple_strtoul(argv[1], NULL, 16);
250 blk = simple_strtoul(argv[2], NULL, 16);
251 cnt = simple_strtoul(argv[3], NULL, 16);
252 key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
254 printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
255 curr_device, blk, cnt);
256 n = mmc_rpmb_write(mmc, addr, blk, cnt, key_addr);
258 printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
260 return CMD_RET_FAILURE;
261 return CMD_RET_SUCCESS;
263 static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
264 int argc, char * const argv[])
266 unsigned long counter;
267 struct mmc *mmc = find_mmc_device(curr_device);
269 if (mmc_rpmb_get_counter(mmc, &counter))
270 return CMD_RET_FAILURE;
271 printf("RPMB Write counter= %lx\n", counter);
272 return CMD_RET_SUCCESS;
275 static cmd_tbl_t cmd_rpmb[] = {
276 U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""),
277 U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""),
278 U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""),
279 U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""),
282 static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
283 int argc, char * const argv[])
290 cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
292 /* Drop the rpmb subcommand */
296 if (cp == NULL || argc > cp->maxargs)
297 return CMD_RET_USAGE;
298 if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
299 return CMD_RET_SUCCESS;
301 mmc = init_mmc_device(curr_device, false);
303 return CMD_RET_FAILURE;
305 if (!(mmc->version & MMC_VERSION_MMC)) {
306 printf("It is not a EMMC device\n");
307 return CMD_RET_FAILURE;
309 if (mmc->version < MMC_VERSION_4_41) {
310 printf("RPMB not supported before version 4.41\n");
311 return CMD_RET_FAILURE;
313 /* Switch to the RPMB partition */
314 original_part = mmc->part_num;
315 if (mmc->part_num != MMC_PART_RPMB) {
316 if (mmc_switch_part(curr_device, MMC_PART_RPMB) != 0)
317 return CMD_RET_FAILURE;
318 mmc->part_num = MMC_PART_RPMB;
320 ret = cp->cmd(cmdtp, flag, argc, argv);
322 /* Return to original partition */
323 if (mmc->part_num != original_part) {
324 if (mmc_switch_part(curr_device, original_part) != 0)
325 return CMD_RET_FAILURE;
326 mmc->part_num = original_part;
332 static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
333 int argc, char * const argv[])
340 return CMD_RET_USAGE;
342 addr = (void *)simple_strtoul(argv[1], NULL, 16);
343 blk = simple_strtoul(argv[2], NULL, 16);
344 cnt = simple_strtoul(argv[3], NULL, 16);
346 mmc = init_mmc_device(curr_device, false);
348 return CMD_RET_FAILURE;
350 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
351 curr_device, blk, cnt);
353 n = mmc->block_dev.block_read(curr_device, blk, cnt, addr);
354 /* flush cache after read */
355 flush_cache((ulong)addr, cnt * 512); /* FIXME */
356 printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
358 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
360 static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
361 int argc, char * const argv[])
368 return CMD_RET_USAGE;
370 addr = (void *)simple_strtoul(argv[1], NULL, 16);
371 blk = simple_strtoul(argv[2], NULL, 16);
372 cnt = simple_strtoul(argv[3], NULL, 16);
374 mmc = init_mmc_device(curr_device, false);
376 return CMD_RET_FAILURE;
378 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
379 curr_device, blk, cnt);
381 if (mmc_getwp(mmc) == 1) {
382 printf("Error: card is write protected!\n");
383 return CMD_RET_FAILURE;
385 n = mmc->block_dev.block_write(curr_device, blk, cnt, addr);
386 printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
388 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
390 static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
391 int argc, char * const argv[])
397 return CMD_RET_USAGE;
399 blk = simple_strtoul(argv[1], NULL, 16);
400 cnt = simple_strtoul(argv[2], NULL, 16);
402 mmc = init_mmc_device(curr_device, false);
404 return CMD_RET_FAILURE;
406 printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
407 curr_device, blk, cnt);
409 if (mmc_getwp(mmc) == 1) {
410 printf("Error: card is write protected!\n");
411 return CMD_RET_FAILURE;
413 n = mmc->block_dev.block_erase(curr_device, blk, cnt);
414 printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
416 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
418 static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
419 int argc, char * const argv[])
423 mmc = init_mmc_device(curr_device, true);
425 return CMD_RET_FAILURE;
427 return CMD_RET_SUCCESS;
429 static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
430 int argc, char * const argv[])
432 block_dev_desc_t *mmc_dev;
435 mmc = init_mmc_device(curr_device, false);
437 return CMD_RET_FAILURE;
439 mmc_dev = mmc_get_dev(curr_device);
440 if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
442 return CMD_RET_SUCCESS;
445 puts("get mmc type error!\n");
446 return CMD_RET_FAILURE;
448 static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
449 int argc, char * const argv[])
451 int dev, part = 0, ret;
456 } else if (argc == 2) {
457 dev = simple_strtoul(argv[1], NULL, 10);
458 } else if (argc == 3) {
459 dev = (int)simple_strtoul(argv[1], NULL, 10);
460 part = (int)simple_strtoul(argv[2], NULL, 10);
461 if (part > PART_ACCESS_MASK) {
462 printf("#part_num shouldn't be larger than %d\n",
464 return CMD_RET_FAILURE;
467 return CMD_RET_USAGE;
470 mmc = init_mmc_device(dev, true);
472 return CMD_RET_FAILURE;
474 ret = mmc_select_hwpart(dev, part);
475 printf("switch to partitions #%d, %s\n",
476 part, (!ret) ? "OK" : "ERROR");
481 if (mmc->part_config == MMCPART_NOAVAILABLE)
482 printf("mmc%d is current device\n", curr_device);
484 printf("mmc%d(part %d) is current device\n",
485 curr_device, mmc->part_num);
487 return CMD_RET_SUCCESS;
489 static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
490 int argc, char * const argv[])
492 print_mmc_devices('\n');
493 return CMD_RET_SUCCESS;
496 static int parse_hwpart_user(struct mmc_hwpart_conf *pconf,
497 int argc, char * const argv[])
501 memset(&pconf->user, 0, sizeof(pconf->user));
504 if (!strcmp(argv[i], "enh")) {
507 pconf->user.enh_start =
508 simple_strtoul(argv[i+1], NULL, 10);
509 pconf->user.enh_size =
510 simple_strtoul(argv[i+2], NULL, 10);
512 } else if (!strcmp(argv[i], "wrrel")) {
515 pconf->user.wr_rel_change = 1;
516 if (!strcmp(argv[i+1], "on"))
517 pconf->user.wr_rel_set = 1;
518 else if (!strcmp(argv[i+1], "off"))
519 pconf->user.wr_rel_set = 0;
530 static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
531 int argc, char * const argv[])
535 memset(&pconf->gp_part[pidx], 0, sizeof(pconf->gp_part[pidx]));
539 pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10);
543 if (!strcmp(argv[i], "enh")) {
544 pconf->gp_part[pidx].enhanced = 1;
546 } else if (!strcmp(argv[i], "wrrel")) {
549 pconf->gp_part[pidx].wr_rel_change = 1;
550 if (!strcmp(argv[i+1], "on"))
551 pconf->gp_part[pidx].wr_rel_set = 1;
552 else if (!strcmp(argv[i+1], "off"))
553 pconf->gp_part[pidx].wr_rel_set = 0;
564 static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag,
565 int argc, char * const argv[])
568 struct mmc_hwpart_conf pconf = { };
569 enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
572 mmc = init_mmc_device(curr_device, false);
574 return CMD_RET_FAILURE;
577 return CMD_RET_USAGE;
580 if (!strcmp(argv[i], "user")) {
582 r = parse_hwpart_user(&pconf, argc-i, &argv[i]);
584 return CMD_RET_USAGE;
586 } else if (!strncmp(argv[i], "gp", 2) &&
587 strlen(argv[i]) == 3 &&
588 argv[i][2] >= '1' && argv[i][2] <= '4') {
589 pidx = argv[i][2] - '1';
591 r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]);
593 return CMD_RET_USAGE;
595 } else if (!strcmp(argv[i], "check")) {
596 mode = MMC_HWPART_CONF_CHECK;
598 } else if (!strcmp(argv[i], "set")) {
599 mode = MMC_HWPART_CONF_SET;
601 } else if (!strcmp(argv[i], "complete")) {
602 mode = MMC_HWPART_CONF_COMPLETE;
605 return CMD_RET_USAGE;
609 puts("Partition configuration:\n");
610 if (pconf.user.enh_size) {
611 puts("\tUser Enhanced Start: ");
612 print_size(((u64)pconf.user.enh_start) << 9, "\n");
613 puts("\tUser Enhanced Size: ");
614 print_size(((u64)pconf.user.enh_size) << 9, "\n");
616 puts("\tNo enhanced user data area\n");
618 if (pconf.user.wr_rel_change)
619 printf("\tUser partition write reliability: %s\n",
620 pconf.user.wr_rel_set ? "on" : "off");
621 for (pidx = 0; pidx < 4; pidx++) {
622 if (pconf.gp_part[pidx].size) {
623 printf("\tGP%i Capacity: ", pidx+1);
624 print_size(((u64)pconf.gp_part[pidx].size) << 9,
625 pconf.gp_part[pidx].enhanced ?
628 printf("\tNo GP%i partition\n", pidx+1);
630 if (pconf.gp_part[pidx].wr_rel_change)
631 printf("\tGP%i write reliability: %s\n", pidx+1,
632 pconf.gp_part[pidx].wr_rel_set ? "on" : "off");
635 if (!mmc_hwpart_config(mmc, &pconf, mode)) {
636 if (mode == MMC_HWPART_CONF_COMPLETE)
637 puts("Partitioning successful, "
638 "power-cycle to make effective\n");
639 return CMD_RET_SUCCESS;
642 return CMD_RET_FAILURE;
646 #ifdef CONFIG_SUPPORT_EMMC_BOOT
647 static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
648 int argc, char * const argv[])
652 u8 width, reset, mode;
655 return CMD_RET_USAGE;
656 dev = simple_strtoul(argv[1], NULL, 10);
657 width = simple_strtoul(argv[2], NULL, 10);
658 reset = simple_strtoul(argv[3], NULL, 10);
659 mode = simple_strtoul(argv[4], NULL, 10);
661 mmc = init_mmc_device(dev, false);
663 return CMD_RET_FAILURE;
666 puts("BOOT_BUS_WIDTH only exists on eMMC\n");
667 return CMD_RET_FAILURE;
670 /* acknowledge to be sent during boot operation */
671 return mmc_set_boot_bus_width(mmc, width, reset, mode);
673 static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
674 int argc, char * const argv[])
678 u32 bootsize, rpmbsize;
681 return CMD_RET_USAGE;
682 dev = simple_strtoul(argv[1], NULL, 10);
683 bootsize = simple_strtoul(argv[2], NULL, 10);
684 rpmbsize = simple_strtoul(argv[3], NULL, 10);
686 mmc = init_mmc_device(dev, false);
688 return CMD_RET_FAILURE;
691 printf("It is not a EMMC device\n");
692 return CMD_RET_FAILURE;
695 if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) {
696 printf("EMMC boot partition Size change Failed.\n");
697 return CMD_RET_FAILURE;
700 printf("EMMC boot partition Size %d MB\n", bootsize);
701 printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
702 return CMD_RET_SUCCESS;
704 static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
705 int argc, char * const argv[])
709 u8 ack, part_num, access;
712 return CMD_RET_USAGE;
714 dev = simple_strtoul(argv[1], NULL, 10);
715 ack = simple_strtoul(argv[2], NULL, 10);
716 part_num = simple_strtoul(argv[3], NULL, 10);
717 access = simple_strtoul(argv[4], NULL, 10);
719 mmc = init_mmc_device(dev, false);
721 return CMD_RET_FAILURE;
724 puts("PARTITION_CONFIG only exists on eMMC\n");
725 return CMD_RET_FAILURE;
728 /* acknowledge to be sent during boot operation */
729 return mmc_set_part_conf(mmc, ack, part_num, access);
731 static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
732 int argc, char * const argv[])
739 * Set the RST_n_ENABLE bit of RST_n_FUNCTION
740 * The only valid values are 0x0, 0x1 and 0x2 and writing
741 * a value of 0x1 or 0x2 sets the value permanently.
744 return CMD_RET_USAGE;
746 dev = simple_strtoul(argv[1], NULL, 10);
747 enable = simple_strtoul(argv[2], NULL, 10);
749 if (enable > 2 || enable < 0) {
750 puts("Invalid RST_n_ENABLE value\n");
751 return CMD_RET_USAGE;
754 mmc = init_mmc_device(dev, false);
756 return CMD_RET_FAILURE;
759 puts("RST_n_FUNCTION only exists on eMMC\n");
760 return CMD_RET_FAILURE;
763 return mmc_set_rst_n_function(mmc, enable);
766 static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
767 int argc, char * const argv[])
774 return CMD_RET_USAGE;
775 val = simple_strtoul(argv[2], NULL, 16);
777 mmc = find_mmc_device(curr_device);
779 printf("no mmc device at slot %x\n", curr_device);
780 return CMD_RET_FAILURE;
782 ret = mmc_set_dsr(mmc, val);
783 printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR");
787 return CMD_RET_FAILURE;
789 return CMD_RET_SUCCESS;
794 static cmd_tbl_t cmd_mmc[] = {
795 U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
796 U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
797 U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
798 U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
799 U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
800 U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
801 U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""),
802 U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""),
803 U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),
804 #ifdef CONFIG_SUPPORT_EMMC_BOOT
805 U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
806 U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""),
807 U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
808 U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
810 #ifdef CONFIG_SUPPORT_EMMC_RPMB
811 U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""),
813 U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
816 static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
820 cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
822 /* Drop the mmc command */
826 if (cp == NULL || argc > cp->maxargs)
827 return CMD_RET_USAGE;
828 if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
829 return CMD_RET_SUCCESS;
831 if (curr_device < 0) {
832 if (get_mmc_num() > 0) {
835 puts("No MMC device available\n");
836 return CMD_RET_FAILURE;
839 return cp->cmd(cmdtp, flag, argc, argv);
843 mmc, 29, 1, do_mmcops,
845 "info - display info of the current MMC device\n"
846 "mmc read addr blk# cnt\n"
847 "mmc write addr blk# cnt\n"
848 "mmc erase blk# cnt\n"
850 "mmc part - lists available partition on current mmc device\n"
851 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
852 "mmc list - lists available devices\n"
853 "mmc hwpartition [args...] - does hardware partitioning\n"
854 " arguments (sizes in 512-byte blocks):\n"
855 " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n"
856 " [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n"
857 " [check|set|complete] - mode, complete set partitioning completed\n"
858 " WARNING: Partitioning is a write-once setting once it is set to complete.\n"
859 " Power cycling is required to initialize partitions after set to complete.\n"
860 #ifdef CONFIG_SUPPORT_EMMC_BOOT
861 "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
862 " - Set the BOOT_BUS_WIDTH field of the specified device\n"
863 "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
864 " - Change sizes of boot and RPMB partitions of specified device\n"
865 "mmc partconf dev boot_ack boot_partition partition_access\n"
866 " - Change the bits of the PARTITION_CONFIG field of the specified device\n"
867 "mmc rst-function dev value\n"
868 " - Change the RST_n_FUNCTION field of the specified device\n"
869 " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
871 #ifdef CONFIG_SUPPORT_EMMC_RPMB
872 "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
873 "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
874 "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
875 "mmc rpmb counter - read the value of the write counter\n"
877 "mmc setdsr <value> - set DSR register value\n"
880 /* Old command kept for compatibility. Same as 'mmc info' */
882 mmcinfo, 1, 0, do_mmcinfo,
884 "- display info of the current MMC device"
887 #endif /* !CONFIG_GENERIC_MMC */