3 * Kyle Harris, kharris@nexus-tech.net
5 * SPDX-License-Identifier: GPL-2.0+
13 static int curr_device = -1;
15 static void print_mmcinfo(struct mmc *mmc)
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);
26 printf("Bus Speed: %d\n", mmc->clock);
27 #if CONFIG_IS_ENABLED(MMC_VERBOSE)
28 printf("Mode : %s\n", mmc_mode_name(mmc->selected_mode));
29 mmc_dump_capabilities("card capabilities", mmc->card_caps);
30 mmc_dump_capabilities("host capabilities", mmc->host_caps);
32 printf("Rd Block Len: %d\n", mmc->read_bl_len);
34 printf("%s version %d.%d", IS_SD(mmc) ? "SD" : "MMC",
35 EXTRACT_SDMMC_MAJOR_VERSION(mmc->version),
36 EXTRACT_SDMMC_MINOR_VERSION(mmc->version));
37 if (EXTRACT_SDMMC_CHANGE_VERSION(mmc->version) != 0)
38 printf(".%d", EXTRACT_SDMMC_CHANGE_VERSION(mmc->version));
41 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
43 print_size(mmc->capacity, "\n");
45 printf("Bus Width: %d-bit%s\n", mmc->bus_width,
46 mmc->ddr_mode ? " DDR" : "");
48 #if CONFIG_IS_ENABLED(MMC_WRITE)
49 puts("Erase Group Size: ");
50 print_size(((u64)mmc->erase_grp_size) << 9, "\n");
53 if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) {
54 bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0;
55 bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR);
57 puts("HC WP Group Size: ");
58 print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n");
60 puts("User Capacity: ");
61 print_size(mmc->capacity_user, usr_enh ? " ENH" : "");
62 if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_USR)
67 puts("User Enhanced Start: ");
68 print_size(mmc->enh_user_start, "\n");
69 puts("User Enhanced Size: ");
70 print_size(mmc->enh_user_size, "\n");
72 puts("Boot Capacity: ");
73 print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n");
74 puts("RPMB Capacity: ");
75 print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n");
77 for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
78 bool is_enh = has_enh &&
79 (mmc->part_attr & EXT_CSD_ENH_GP(i));
80 if (mmc->capacity_gp[i]) {
81 printf("GP%i Capacity: ", i+1);
82 print_size(mmc->capacity_gp[i],
83 is_enh ? " ENH" : "");
84 if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_GP(i))
92 static struct mmc *init_mmc_device(int dev, bool force_init)
95 mmc = find_mmc_device(dev);
97 printf("no mmc device at slot %x\n", dev);
107 static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
111 if (curr_device < 0) {
112 if (get_mmc_num() > 0)
115 puts("No MMC device available\n");
120 mmc = init_mmc_device(curr_device, false);
122 return CMD_RET_FAILURE;
125 return CMD_RET_SUCCESS;
128 #ifdef CONFIG_SUPPORT_EMMC_RPMB
129 static int confirm_key_prog(void)
131 puts("Warning: Programming authentication key can be done only once !\n"
132 " Use this command only if you are sure of what you are doing,\n"
133 "Really perform the key programming? <y/N> ");
137 puts("Authentication key programming aborted\n");
140 static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
141 int argc, char * const argv[])
144 struct mmc *mmc = find_mmc_device(curr_device);
147 return CMD_RET_USAGE;
149 key_addr = (void *)simple_strtoul(argv[1], NULL, 16);
150 if (!confirm_key_prog())
151 return CMD_RET_FAILURE;
152 if (mmc_rpmb_set_key(mmc, key_addr)) {
153 printf("ERROR - Key already programmed ?\n");
154 return CMD_RET_FAILURE;
156 return CMD_RET_SUCCESS;
158 static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
159 int argc, char * const argv[])
164 void *key_addr = NULL;
165 struct mmc *mmc = find_mmc_device(curr_device);
168 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);
175 key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
177 printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
178 curr_device, blk, cnt);
179 n = mmc_rpmb_read(mmc, addr, blk, cnt, key_addr);
181 printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
183 return CMD_RET_FAILURE;
184 return CMD_RET_SUCCESS;
186 static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
187 int argc, char * const argv[])
193 struct mmc *mmc = find_mmc_device(curr_device);
196 return CMD_RET_USAGE;
198 addr = (void *)simple_strtoul(argv[1], NULL, 16);
199 blk = simple_strtoul(argv[2], NULL, 16);
200 cnt = simple_strtoul(argv[3], NULL, 16);
201 key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
203 printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
204 curr_device, blk, cnt);
205 n = mmc_rpmb_write(mmc, addr, blk, cnt, key_addr);
207 printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
209 return CMD_RET_FAILURE;
210 return CMD_RET_SUCCESS;
212 static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
213 int argc, char * const argv[])
215 unsigned long counter;
216 struct mmc *mmc = find_mmc_device(curr_device);
218 if (mmc_rpmb_get_counter(mmc, &counter))
219 return CMD_RET_FAILURE;
220 printf("RPMB Write counter= %lx\n", counter);
221 return CMD_RET_SUCCESS;
224 static cmd_tbl_t cmd_rpmb[] = {
225 U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""),
226 U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""),
227 U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""),
228 U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""),
231 static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
232 int argc, char * const argv[])
239 cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
241 /* Drop the rpmb subcommand */
245 if (cp == NULL || argc > cp->maxargs)
246 return CMD_RET_USAGE;
247 if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
248 return CMD_RET_SUCCESS;
250 mmc = init_mmc_device(curr_device, false);
252 return CMD_RET_FAILURE;
254 if (!(mmc->version & MMC_VERSION_MMC)) {
255 printf("It is not a EMMC device\n");
256 return CMD_RET_FAILURE;
258 if (mmc->version < MMC_VERSION_4_41) {
259 printf("RPMB not supported before version 4.41\n");
260 return CMD_RET_FAILURE;
262 /* Switch to the RPMB partition */
264 original_part = mmc->block_dev.hwpart;
266 original_part = mmc_get_blk_desc(mmc)->hwpart;
268 if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, MMC_PART_RPMB) !=
270 return CMD_RET_FAILURE;
271 ret = cp->cmd(cmdtp, flag, argc, argv);
273 /* Return to original partition */
274 if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, original_part) !=
276 return CMD_RET_FAILURE;
281 static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
282 int argc, char * const argv[])
289 return CMD_RET_USAGE;
291 addr = (void *)simple_strtoul(argv[1], NULL, 16);
292 blk = simple_strtoul(argv[2], NULL, 16);
293 cnt = simple_strtoul(argv[3], NULL, 16);
295 mmc = init_mmc_device(curr_device, false);
297 return CMD_RET_FAILURE;
299 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
300 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");
305 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
308 #if CONFIG_IS_ENABLED(MMC_WRITE)
309 static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
310 int argc, char * const argv[])
317 return CMD_RET_USAGE;
319 addr = (void *)simple_strtoul(argv[1], NULL, 16);
320 blk = simple_strtoul(argv[2], NULL, 16);
321 cnt = simple_strtoul(argv[3], NULL, 16);
323 mmc = init_mmc_device(curr_device, false);
325 return CMD_RET_FAILURE;
327 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
328 curr_device, blk, cnt);
330 if (mmc_getwp(mmc) == 1) {
331 printf("Error: card is write protected!\n");
332 return CMD_RET_FAILURE;
334 n = blk_dwrite(mmc_get_blk_desc(mmc), blk, cnt, addr);
335 printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
337 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
339 static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
340 int argc, char * const argv[])
346 return CMD_RET_USAGE;
348 blk = simple_strtoul(argv[1], NULL, 16);
349 cnt = simple_strtoul(argv[2], NULL, 16);
351 mmc = init_mmc_device(curr_device, false);
353 return CMD_RET_FAILURE;
355 printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
356 curr_device, blk, cnt);
358 if (mmc_getwp(mmc) == 1) {
359 printf("Error: card is write protected!\n");
360 return CMD_RET_FAILURE;
362 n = blk_derase(mmc_get_blk_desc(mmc), blk, cnt);
363 printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
365 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
369 static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
370 int argc, char * const argv[])
374 mmc = init_mmc_device(curr_device, true);
376 return CMD_RET_FAILURE;
378 return CMD_RET_SUCCESS;
380 static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
381 int argc, char * const argv[])
383 struct blk_desc *mmc_dev;
386 mmc = init_mmc_device(curr_device, false);
388 return CMD_RET_FAILURE;
390 mmc_dev = blk_get_devnum_by_type(IF_TYPE_MMC, curr_device);
391 if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
393 return CMD_RET_SUCCESS;
396 puts("get mmc type error!\n");
397 return CMD_RET_FAILURE;
399 static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
400 int argc, char * const argv[])
402 int dev, part = 0, ret;
407 } else if (argc == 2) {
408 dev = simple_strtoul(argv[1], NULL, 10);
409 } else if (argc == 3) {
410 dev = (int)simple_strtoul(argv[1], NULL, 10);
411 part = (int)simple_strtoul(argv[2], NULL, 10);
412 if (part > PART_ACCESS_MASK) {
413 printf("#part_num shouldn't be larger than %d\n",
415 return CMD_RET_FAILURE;
418 return CMD_RET_USAGE;
421 mmc = init_mmc_device(dev, true);
423 return CMD_RET_FAILURE;
425 ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part);
426 printf("switch to partitions #%d, %s\n",
427 part, (!ret) ? "OK" : "ERROR");
432 if (mmc->part_config == MMCPART_NOAVAILABLE)
433 printf("mmc%d is current device\n", curr_device);
435 printf("mmc%d(part %d) is current device\n",
436 curr_device, mmc_get_blk_desc(mmc)->hwpart);
438 return CMD_RET_SUCCESS;
440 static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
441 int argc, char * const argv[])
443 print_mmc_devices('\n');
444 return CMD_RET_SUCCESS;
447 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
448 static int parse_hwpart_user(struct mmc_hwpart_conf *pconf,
449 int argc, char * const argv[])
453 memset(&pconf->user, 0, sizeof(pconf->user));
456 if (!strcmp(argv[i], "enh")) {
459 pconf->user.enh_start =
460 simple_strtoul(argv[i+1], NULL, 10);
461 pconf->user.enh_size =
462 simple_strtoul(argv[i+2], NULL, 10);
464 } else if (!strcmp(argv[i], "wrrel")) {
467 pconf->user.wr_rel_change = 1;
468 if (!strcmp(argv[i+1], "on"))
469 pconf->user.wr_rel_set = 1;
470 else if (!strcmp(argv[i+1], "off"))
471 pconf->user.wr_rel_set = 0;
482 static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
483 int argc, char * const argv[])
487 memset(&pconf->gp_part[pidx], 0, sizeof(pconf->gp_part[pidx]));
491 pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10);
495 if (!strcmp(argv[i], "enh")) {
496 pconf->gp_part[pidx].enhanced = 1;
498 } else if (!strcmp(argv[i], "wrrel")) {
501 pconf->gp_part[pidx].wr_rel_change = 1;
502 if (!strcmp(argv[i+1], "on"))
503 pconf->gp_part[pidx].wr_rel_set = 1;
504 else if (!strcmp(argv[i+1], "off"))
505 pconf->gp_part[pidx].wr_rel_set = 0;
516 static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag,
517 int argc, char * const argv[])
520 struct mmc_hwpart_conf pconf = { };
521 enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK;
524 mmc = init_mmc_device(curr_device, false);
526 return CMD_RET_FAILURE;
529 return CMD_RET_USAGE;
532 if (!strcmp(argv[i], "user")) {
534 r = parse_hwpart_user(&pconf, argc-i, &argv[i]);
536 return CMD_RET_USAGE;
538 } else if (!strncmp(argv[i], "gp", 2) &&
539 strlen(argv[i]) == 3 &&
540 argv[i][2] >= '1' && argv[i][2] <= '4') {
541 pidx = argv[i][2] - '1';
543 r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]);
545 return CMD_RET_USAGE;
547 } else if (!strcmp(argv[i], "check")) {
548 mode = MMC_HWPART_CONF_CHECK;
550 } else if (!strcmp(argv[i], "set")) {
551 mode = MMC_HWPART_CONF_SET;
553 } else if (!strcmp(argv[i], "complete")) {
554 mode = MMC_HWPART_CONF_COMPLETE;
557 return CMD_RET_USAGE;
561 puts("Partition configuration:\n");
562 if (pconf.user.enh_size) {
563 puts("\tUser Enhanced Start: ");
564 print_size(((u64)pconf.user.enh_start) << 9, "\n");
565 puts("\tUser Enhanced Size: ");
566 print_size(((u64)pconf.user.enh_size) << 9, "\n");
568 puts("\tNo enhanced user data area\n");
570 if (pconf.user.wr_rel_change)
571 printf("\tUser partition write reliability: %s\n",
572 pconf.user.wr_rel_set ? "on" : "off");
573 for (pidx = 0; pidx < 4; pidx++) {
574 if (pconf.gp_part[pidx].size) {
575 printf("\tGP%i Capacity: ", pidx+1);
576 print_size(((u64)pconf.gp_part[pidx].size) << 9,
577 pconf.gp_part[pidx].enhanced ?
580 printf("\tNo GP%i partition\n", pidx+1);
582 if (pconf.gp_part[pidx].wr_rel_change)
583 printf("\tGP%i write reliability: %s\n", pidx+1,
584 pconf.gp_part[pidx].wr_rel_set ? "on" : "off");
587 if (!mmc_hwpart_config(mmc, &pconf, mode)) {
588 if (mode == MMC_HWPART_CONF_COMPLETE)
589 puts("Partitioning successful, "
590 "power-cycle to make effective\n");
591 return CMD_RET_SUCCESS;
594 return CMD_RET_FAILURE;
599 #ifdef CONFIG_SUPPORT_EMMC_BOOT
600 static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
601 int argc, char * const argv[])
605 u8 width, reset, mode;
608 return CMD_RET_USAGE;
609 dev = simple_strtoul(argv[1], NULL, 10);
610 width = simple_strtoul(argv[2], NULL, 10);
611 reset = simple_strtoul(argv[3], NULL, 10);
612 mode = simple_strtoul(argv[4], NULL, 10);
614 mmc = init_mmc_device(dev, false);
616 return CMD_RET_FAILURE;
619 puts("BOOT_BUS_WIDTH only exists on eMMC\n");
620 return CMD_RET_FAILURE;
623 /* acknowledge to be sent during boot operation */
624 return mmc_set_boot_bus_width(mmc, width, reset, mode);
626 static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
627 int argc, char * const argv[])
631 u32 bootsize, rpmbsize;
634 return CMD_RET_USAGE;
635 dev = simple_strtoul(argv[1], NULL, 10);
636 bootsize = simple_strtoul(argv[2], NULL, 10);
637 rpmbsize = simple_strtoul(argv[3], NULL, 10);
639 mmc = init_mmc_device(dev, false);
641 return CMD_RET_FAILURE;
644 printf("It is not a EMMC device\n");
645 return CMD_RET_FAILURE;
648 if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) {
649 printf("EMMC boot partition Size change Failed.\n");
650 return CMD_RET_FAILURE;
653 printf("EMMC boot partition Size %d MB\n", bootsize);
654 printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
655 return CMD_RET_SUCCESS;
658 static int mmc_partconf_print(struct mmc *mmc)
660 u8 ack, access, part;
662 if (mmc->part_config == MMCPART_NOAVAILABLE) {
663 printf("No part_config info for ver. 0x%x\n", mmc->version);
664 return CMD_RET_FAILURE;
667 access = EXT_CSD_EXTRACT_PARTITION_ACCESS(mmc->part_config);
668 ack = EXT_CSD_EXTRACT_BOOT_ACK(mmc->part_config);
669 part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
671 printf("EXT_CSD[179], PARTITION_CONFIG:\n"
673 "BOOT_PARTITION_ENABLE: 0x%x\n"
674 "PARTITION_ACCESS: 0x%x\n", ack, part, access);
676 return CMD_RET_SUCCESS;
679 static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
680 int argc, char * const argv[])
684 u8 ack, part_num, access;
686 if (argc != 2 && argc != 5)
687 return CMD_RET_USAGE;
689 dev = simple_strtoul(argv[1], NULL, 10);
691 mmc = init_mmc_device(dev, false);
693 return CMD_RET_FAILURE;
696 puts("PARTITION_CONFIG only exists on eMMC\n");
697 return CMD_RET_FAILURE;
701 return mmc_partconf_print(mmc);
703 ack = simple_strtoul(argv[2], NULL, 10);
704 part_num = simple_strtoul(argv[3], NULL, 10);
705 access = simple_strtoul(argv[4], NULL, 10);
707 /* acknowledge to be sent during boot operation */
708 return mmc_set_part_conf(mmc, ack, part_num, access);
710 static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
711 int argc, char * const argv[])
718 * Set the RST_n_ENABLE bit of RST_n_FUNCTION
719 * The only valid values are 0x0, 0x1 and 0x2 and writing
720 * a value of 0x1 or 0x2 sets the value permanently.
723 return CMD_RET_USAGE;
725 dev = simple_strtoul(argv[1], NULL, 10);
726 enable = simple_strtoul(argv[2], NULL, 10);
729 puts("Invalid RST_n_ENABLE value\n");
730 return CMD_RET_USAGE;
733 mmc = init_mmc_device(dev, false);
735 return CMD_RET_FAILURE;
738 puts("RST_n_FUNCTION only exists on eMMC\n");
739 return CMD_RET_FAILURE;
742 return mmc_set_rst_n_function(mmc, enable);
745 static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
746 int argc, char * const argv[])
753 return CMD_RET_USAGE;
754 val = simple_strtoul(argv[1], NULL, 16);
756 mmc = find_mmc_device(curr_device);
758 printf("no mmc device at slot %x\n", curr_device);
759 return CMD_RET_FAILURE;
761 ret = mmc_set_dsr(mmc, val);
762 printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR");
766 return CMD_RET_FAILURE;
768 return CMD_RET_SUCCESS;
773 #ifdef CONFIG_CMD_BKOPS_ENABLE
774 static int do_mmc_bkops_enable(cmd_tbl_t *cmdtp, int flag,
775 int argc, char * const argv[])
781 return CMD_RET_USAGE;
783 dev = simple_strtoul(argv[1], NULL, 10);
785 mmc = init_mmc_device(dev, false);
787 return CMD_RET_FAILURE;
790 puts("BKOPS_EN only exists on eMMC\n");
791 return CMD_RET_FAILURE;
794 return mmc_set_bkops_enable(mmc);
798 static cmd_tbl_t cmd_mmc[] = {
799 U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
800 U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
801 #if CONFIG_IS_ENABLED(MMC_WRITE)
802 U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
803 U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
805 U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
806 U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
807 U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""),
808 U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""),
809 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
810 U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""),
812 #ifdef CONFIG_SUPPORT_EMMC_BOOT
813 U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
814 U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""),
815 U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
816 U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
818 #ifdef CONFIG_SUPPORT_EMMC_RPMB
819 U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""),
821 U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
822 #ifdef CONFIG_CMD_BKOPS_ENABLE
823 U_BOOT_CMD_MKENT(bkops-enable, 2, 0, do_mmc_bkops_enable, "", ""),
827 static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
831 cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
833 /* Drop the mmc command */
837 if (cp == NULL || argc > cp->maxargs)
838 return CMD_RET_USAGE;
839 if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
840 return CMD_RET_SUCCESS;
842 if (curr_device < 0) {
843 if (get_mmc_num() > 0) {
846 puts("No MMC device available\n");
847 return CMD_RET_FAILURE;
850 return cp->cmd(cmdtp, flag, argc, argv);
854 mmc, 29, 1, do_mmcops,
856 "info - display info of the current MMC device\n"
857 "mmc read addr blk# cnt\n"
858 "mmc write addr blk# cnt\n"
859 "mmc erase blk# cnt\n"
861 "mmc part - lists available partition on current mmc device\n"
862 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
863 "mmc list - lists available devices\n"
864 "mmc hwpartition [args...] - does hardware partitioning\n"
865 " arguments (sizes in 512-byte blocks):\n"
866 " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n"
867 " [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n"
868 " [check|set|complete] - mode, complete set partitioning completed\n"
869 " WARNING: Partitioning is a write-once setting once it is set to complete.\n"
870 " Power cycling is required to initialize partitions after set to complete.\n"
871 #ifdef CONFIG_SUPPORT_EMMC_BOOT
872 "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
873 " - Set the BOOT_BUS_WIDTH field of the specified device\n"
874 "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
875 " - Change sizes of boot and RPMB partitions of specified device\n"
876 "mmc partconf dev [boot_ack boot_partition partition_access]\n"
877 " - Show or change the bits of the PARTITION_CONFIG field of the specified device\n"
878 "mmc rst-function dev value\n"
879 " - Change the RST_n_FUNCTION field of the specified device\n"
880 " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
882 #ifdef CONFIG_SUPPORT_EMMC_RPMB
883 "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
884 "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
885 "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
886 "mmc rpmb counter - read the value of the write counter\n"
888 "mmc setdsr <value> - set DSR register value\n"
889 #ifdef CONFIG_CMD_BKOPS_ENABLE
890 "mmc bkops-enable <dev> - enable background operations handshake on device\n"
891 " WARNING: This is a write-once setting.\n"
895 /* Old command kept for compatibility. Same as 'mmc info' */
897 mmcinfo, 1, 0, do_mmcinfo,
899 "- display info of the current MMC device"