3 * Kyle Harris, kharris@nexus-tech.net
5 * SPDX-License-Identifier: GPL-2.0+
13 static int curr_device
= -1;
14 #ifndef CONFIG_GENERIC_MMC
15 int do_mmc (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
22 if (strcmp(argv
[1], "init") == 0) {
28 } else if (argc
== 3) {
29 dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
34 if (mmc_legacy_init(dev
) != 0) {
35 puts("No MMC card found\n");
40 printf("mmc%d is available\n", curr_device
);
41 } else if (strcmp(argv
[1], "device") == 0) {
43 if (curr_device
< 0) {
44 puts("No MMC device available\n");
47 } else if (argc
== 3) {
48 dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
50 #ifdef CONFIG_SYS_MMC_SET_DEV
51 if (mmc_set_dev(dev
) != 0)
59 printf("mmc%d is current device\n", curr_device
);
70 "init [dev] - init MMC sub system\n"
71 "mmc device [dev] - show or set current device"
73 #else /* !CONFIG_GENERIC_MMC */
75 static void print_mmcinfo(struct mmc
*mmc
)
79 printf("Device: %s\n", mmc
->cfg
->name
);
80 printf("Manufacturer ID: %x\n", mmc
->cid
[0] >> 24);
81 printf("OEM: %x\n", (mmc
->cid
[0] >> 8) & 0xffff);
82 printf("Name: %c%c%c%c%c \n", mmc
->cid
[0] & 0xff,
83 (mmc
->cid
[1] >> 24), (mmc
->cid
[1] >> 16) & 0xff,
84 (mmc
->cid
[1] >> 8) & 0xff, mmc
->cid
[1] & 0xff);
86 printf("Tran Speed: %d\n", mmc
->tran_speed
);
87 printf("Rd Block Len: %d\n", mmc
->read_bl_len
);
89 printf("%s version %d.%d", IS_SD(mmc
) ? "SD" : "MMC",
90 EXTRACT_SDMMC_MAJOR_VERSION(mmc
->version
),
91 EXTRACT_SDMMC_MINOR_VERSION(mmc
->version
));
92 if (EXTRACT_SDMMC_CHANGE_VERSION(mmc
->version
) != 0)
93 printf(".%d", EXTRACT_SDMMC_CHANGE_VERSION(mmc
->version
));
96 printf("High Capacity: %s\n", mmc
->high_capacity
? "Yes" : "No");
98 print_size(mmc
->capacity
, "\n");
100 printf("Bus Width: %d-bit%s\n", mmc
->bus_width
,
101 mmc
->ddr_mode
? " DDR" : "");
103 puts("Erase Group Size: ");
104 print_size(((u64
)mmc
->erase_grp_size
) << 9, "\n");
106 if (!IS_SD(mmc
) && mmc
->version
>= MMC_VERSION_4_41
) {
107 bool has_enh
= (mmc
->part_support
& ENHNCD_SUPPORT
) != 0;
108 bool usr_enh
= has_enh
&& (mmc
->part_attr
& EXT_CSD_ENH_USR
);
110 puts("HC WP Group Size: ");
111 print_size(((u64
)mmc
->hc_wp_grp_size
) << 9, "\n");
113 puts("User Capacity: ");
114 print_size(mmc
->capacity_user
, usr_enh
? " ENH" : "");
115 if (mmc
->wr_rel_set
& EXT_CSD_WR_DATA_REL_USR
)
120 puts("User Enhanced Start: ");
121 print_size(mmc
->enh_user_start
, "\n");
122 puts("User Enhanced Size: ");
123 print_size(mmc
->enh_user_size
, "\n");
125 puts("Boot Capacity: ");
126 print_size(mmc
->capacity_boot
, has_enh
? " ENH\n" : "\n");
127 puts("RPMB Capacity: ");
128 print_size(mmc
->capacity_rpmb
, has_enh
? " ENH\n" : "\n");
130 for (i
= 0; i
< ARRAY_SIZE(mmc
->capacity_gp
); i
++) {
131 bool is_enh
= has_enh
&&
132 (mmc
->part_attr
& EXT_CSD_ENH_GP(i
));
133 if (mmc
->capacity_gp
[i
]) {
134 printf("GP%i Capacity: ", i
+1);
135 print_size(mmc
->capacity_gp
[i
],
136 is_enh
? " ENH" : "");
137 if (mmc
->wr_rel_set
& EXT_CSD_WR_DATA_REL_GP(i
))
145 static struct mmc
*init_mmc_device(int dev
, bool force_init
)
148 mmc
= find_mmc_device(dev
);
150 printf("no mmc device at slot %x\n", dev
);
160 static int do_mmcinfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
164 if (curr_device
< 0) {
165 if (get_mmc_num() > 0)
168 puts("No MMC device available\n");
173 mmc
= init_mmc_device(curr_device
, false);
175 return CMD_RET_FAILURE
;
178 return CMD_RET_SUCCESS
;
181 #ifdef CONFIG_SUPPORT_EMMC_RPMB
182 static int confirm_key_prog(void)
184 puts("Warning: Programming authentication key can be done only once !\n"
185 " Use this command only if you are sure of what you are doing,\n"
186 "Really perform the key programming? <y/N> ");
190 puts("Authentication key programming aborted\n");
193 static int do_mmcrpmb_key(cmd_tbl_t
*cmdtp
, int flag
,
194 int argc
, char * const argv
[])
197 struct mmc
*mmc
= find_mmc_device(curr_device
);
200 return CMD_RET_USAGE
;
202 key_addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
203 if (!confirm_key_prog())
204 return CMD_RET_FAILURE
;
205 if (mmc_rpmb_set_key(mmc
, key_addr
)) {
206 printf("ERROR - Key already programmed ?\n");
207 return CMD_RET_FAILURE
;
209 return CMD_RET_SUCCESS
;
211 static int do_mmcrpmb_read(cmd_tbl_t
*cmdtp
, int flag
,
212 int argc
, char * const argv
[])
217 void *key_addr
= NULL
;
218 struct mmc
*mmc
= find_mmc_device(curr_device
);
221 return CMD_RET_USAGE
;
223 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
224 blk
= simple_strtoul(argv
[2], NULL
, 16);
225 cnt
= simple_strtoul(argv
[3], NULL
, 16);
228 key_addr
= (void *)simple_strtoul(argv
[4], NULL
, 16);
230 printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
231 curr_device
, blk
, cnt
);
232 n
= mmc_rpmb_read(mmc
, addr
, blk
, cnt
, key_addr
);
234 printf("%d RPMB blocks read: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
236 return CMD_RET_FAILURE
;
237 return CMD_RET_SUCCESS
;
239 static int do_mmcrpmb_write(cmd_tbl_t
*cmdtp
, int flag
,
240 int argc
, char * const argv
[])
246 struct mmc
*mmc
= find_mmc_device(curr_device
);
249 return CMD_RET_USAGE
;
251 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
252 blk
= simple_strtoul(argv
[2], NULL
, 16);
253 cnt
= simple_strtoul(argv
[3], NULL
, 16);
254 key_addr
= (void *)simple_strtoul(argv
[4], NULL
, 16);
256 printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
257 curr_device
, blk
, cnt
);
258 n
= mmc_rpmb_write(mmc
, addr
, blk
, cnt
, key_addr
);
260 printf("%d RPMB blocks written: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
262 return CMD_RET_FAILURE
;
263 return CMD_RET_SUCCESS
;
265 static int do_mmcrpmb_counter(cmd_tbl_t
*cmdtp
, int flag
,
266 int argc
, char * const argv
[])
268 unsigned long counter
;
269 struct mmc
*mmc
= find_mmc_device(curr_device
);
271 if (mmc_rpmb_get_counter(mmc
, &counter
))
272 return CMD_RET_FAILURE
;
273 printf("RPMB Write counter= %lx\n", counter
);
274 return CMD_RET_SUCCESS
;
277 static cmd_tbl_t cmd_rpmb
[] = {
278 U_BOOT_CMD_MKENT(key
, 2, 0, do_mmcrpmb_key
, "", ""),
279 U_BOOT_CMD_MKENT(read
, 5, 1, do_mmcrpmb_read
, "", ""),
280 U_BOOT_CMD_MKENT(write
, 5, 0, do_mmcrpmb_write
, "", ""),
281 U_BOOT_CMD_MKENT(counter
, 1, 1, do_mmcrpmb_counter
, "", ""),
284 static int do_mmcrpmb(cmd_tbl_t
*cmdtp
, int flag
,
285 int argc
, char * const argv
[])
292 cp
= find_cmd_tbl(argv
[1], cmd_rpmb
, ARRAY_SIZE(cmd_rpmb
));
294 /* Drop the rpmb subcommand */
298 if (cp
== NULL
|| argc
> cp
->maxargs
)
299 return CMD_RET_USAGE
;
300 if (flag
== CMD_FLAG_REPEAT
&& !cp
->repeatable
)
301 return CMD_RET_SUCCESS
;
303 mmc
= init_mmc_device(curr_device
, false);
305 return CMD_RET_FAILURE
;
307 if (!(mmc
->version
& MMC_VERSION_MMC
)) {
308 printf("It is not a EMMC device\n");
309 return CMD_RET_FAILURE
;
311 if (mmc
->version
< MMC_VERSION_4_41
) {
312 printf("RPMB not supported before version 4.41\n");
313 return CMD_RET_FAILURE
;
315 /* Switch to the RPMB partition */
316 original_part
= mmc
->block_dev
.hwpart
;
317 if (blk_select_hwpart_devnum(IF_TYPE_MMC
, curr_device
, MMC_PART_RPMB
) !=
319 return CMD_RET_FAILURE
;
320 ret
= cp
->cmd(cmdtp
, flag
, argc
, argv
);
322 /* Return to original partition */
323 if (blk_select_hwpart_devnum(IF_TYPE_MMC
, curr_device
, original_part
) !=
325 return CMD_RET_FAILURE
;
330 static int do_mmc_read(cmd_tbl_t
*cmdtp
, int flag
,
331 int argc
, char * const argv
[])
338 return CMD_RET_USAGE
;
340 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
341 blk
= simple_strtoul(argv
[2], NULL
, 16);
342 cnt
= simple_strtoul(argv
[3], NULL
, 16);
344 mmc
= init_mmc_device(curr_device
, false);
346 return CMD_RET_FAILURE
;
348 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
349 curr_device
, blk
, cnt
);
351 n
= blk_dread(&mmc
->block_dev
, blk
, cnt
, addr
);
352 /* flush cache after read */
353 flush_cache((ulong
)addr
, cnt
* 512); /* FIXME */
354 printf("%d blocks read: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
356 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
358 static int do_mmc_write(cmd_tbl_t
*cmdtp
, int flag
,
359 int argc
, char * const argv
[])
366 return CMD_RET_USAGE
;
368 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
369 blk
= simple_strtoul(argv
[2], NULL
, 16);
370 cnt
= simple_strtoul(argv
[3], NULL
, 16);
372 mmc
= init_mmc_device(curr_device
, false);
374 return CMD_RET_FAILURE
;
376 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
377 curr_device
, blk
, cnt
);
379 if (mmc_getwp(mmc
) == 1) {
380 printf("Error: card is write protected!\n");
381 return CMD_RET_FAILURE
;
383 n
= blk_dwrite(&mmc
->block_dev
, blk
, cnt
, addr
);
384 printf("%d blocks written: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
386 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
388 static int do_mmc_erase(cmd_tbl_t
*cmdtp
, int flag
,
389 int argc
, char * const argv
[])
395 return CMD_RET_USAGE
;
397 blk
= simple_strtoul(argv
[1], NULL
, 16);
398 cnt
= simple_strtoul(argv
[2], NULL
, 16);
400 mmc
= init_mmc_device(curr_device
, false);
402 return CMD_RET_FAILURE
;
404 printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
405 curr_device
, blk
, cnt
);
407 if (mmc_getwp(mmc
) == 1) {
408 printf("Error: card is write protected!\n");
409 return CMD_RET_FAILURE
;
411 n
= blk_derase(&mmc
->block_dev
, blk
, cnt
);
412 printf("%d blocks erased: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
414 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
416 static int do_mmc_rescan(cmd_tbl_t
*cmdtp
, int flag
,
417 int argc
, char * const argv
[])
421 mmc
= init_mmc_device(curr_device
, true);
423 return CMD_RET_FAILURE
;
425 return CMD_RET_SUCCESS
;
427 static int do_mmc_part(cmd_tbl_t
*cmdtp
, int flag
,
428 int argc
, char * const argv
[])
430 struct blk_desc
*mmc_dev
;
433 mmc
= init_mmc_device(curr_device
, false);
435 return CMD_RET_FAILURE
;
437 mmc_dev
= blk_get_devnum_by_type(IF_TYPE_MMC
, curr_device
);
438 if (mmc_dev
!= NULL
&& mmc_dev
->type
!= DEV_TYPE_UNKNOWN
) {
440 return CMD_RET_SUCCESS
;
443 puts("get mmc type error!\n");
444 return CMD_RET_FAILURE
;
446 static int do_mmc_dev(cmd_tbl_t
*cmdtp
, int flag
,
447 int argc
, char * const argv
[])
449 int dev
, part
= 0, ret
;
454 } else if (argc
== 2) {
455 dev
= simple_strtoul(argv
[1], NULL
, 10);
456 } else if (argc
== 3) {
457 dev
= (int)simple_strtoul(argv
[1], NULL
, 10);
458 part
= (int)simple_strtoul(argv
[2], NULL
, 10);
459 if (part
> PART_ACCESS_MASK
) {
460 printf("#part_num shouldn't be larger than %d\n",
462 return CMD_RET_FAILURE
;
465 return CMD_RET_USAGE
;
468 mmc
= init_mmc_device(dev
, true);
470 return CMD_RET_FAILURE
;
472 ret
= blk_select_hwpart_devnum(IF_TYPE_MMC
, dev
, part
);
473 printf("switch to partitions #%d, %s\n",
474 part
, (!ret
) ? "OK" : "ERROR");
479 if (mmc
->part_config
== MMCPART_NOAVAILABLE
)
480 printf("mmc%d is current device\n", curr_device
);
482 printf("mmc%d(part %d) is current device\n",
483 curr_device
, mmc
->block_dev
.hwpart
);
485 return CMD_RET_SUCCESS
;
487 static int do_mmc_list(cmd_tbl_t
*cmdtp
, int flag
,
488 int argc
, char * const argv
[])
490 print_mmc_devices('\n');
491 return CMD_RET_SUCCESS
;
494 static int parse_hwpart_user(struct mmc_hwpart_conf
*pconf
,
495 int argc
, char * const argv
[])
499 memset(&pconf
->user
, 0, sizeof(pconf
->user
));
502 if (!strcmp(argv
[i
], "enh")) {
505 pconf
->user
.enh_start
=
506 simple_strtoul(argv
[i
+1], NULL
, 10);
507 pconf
->user
.enh_size
=
508 simple_strtoul(argv
[i
+2], NULL
, 10);
510 } else if (!strcmp(argv
[i
], "wrrel")) {
513 pconf
->user
.wr_rel_change
= 1;
514 if (!strcmp(argv
[i
+1], "on"))
515 pconf
->user
.wr_rel_set
= 1;
516 else if (!strcmp(argv
[i
+1], "off"))
517 pconf
->user
.wr_rel_set
= 0;
528 static int parse_hwpart_gp(struct mmc_hwpart_conf
*pconf
, int pidx
,
529 int argc
, char * const argv
[])
533 memset(&pconf
->gp_part
[pidx
], 0, sizeof(pconf
->gp_part
[pidx
]));
537 pconf
->gp_part
[pidx
].size
= simple_strtoul(argv
[0], NULL
, 10);
541 if (!strcmp(argv
[i
], "enh")) {
542 pconf
->gp_part
[pidx
].enhanced
= 1;
544 } else if (!strcmp(argv
[i
], "wrrel")) {
547 pconf
->gp_part
[pidx
].wr_rel_change
= 1;
548 if (!strcmp(argv
[i
+1], "on"))
549 pconf
->gp_part
[pidx
].wr_rel_set
= 1;
550 else if (!strcmp(argv
[i
+1], "off"))
551 pconf
->gp_part
[pidx
].wr_rel_set
= 0;
562 static int do_mmc_hwpartition(cmd_tbl_t
*cmdtp
, int flag
,
563 int argc
, char * const argv
[])
566 struct mmc_hwpart_conf pconf
= { };
567 enum mmc_hwpart_conf_mode mode
= MMC_HWPART_CONF_CHECK
;
570 mmc
= init_mmc_device(curr_device
, false);
572 return CMD_RET_FAILURE
;
575 return CMD_RET_USAGE
;
578 if (!strcmp(argv
[i
], "user")) {
580 r
= parse_hwpart_user(&pconf
, argc
-i
, &argv
[i
]);
582 return CMD_RET_USAGE
;
584 } else if (!strncmp(argv
[i
], "gp", 2) &&
585 strlen(argv
[i
]) == 3 &&
586 argv
[i
][2] >= '1' && argv
[i
][2] <= '4') {
587 pidx
= argv
[i
][2] - '1';
589 r
= parse_hwpart_gp(&pconf
, pidx
, argc
-i
, &argv
[i
]);
591 return CMD_RET_USAGE
;
593 } else if (!strcmp(argv
[i
], "check")) {
594 mode
= MMC_HWPART_CONF_CHECK
;
596 } else if (!strcmp(argv
[i
], "set")) {
597 mode
= MMC_HWPART_CONF_SET
;
599 } else if (!strcmp(argv
[i
], "complete")) {
600 mode
= MMC_HWPART_CONF_COMPLETE
;
603 return CMD_RET_USAGE
;
607 puts("Partition configuration:\n");
608 if (pconf
.user
.enh_size
) {
609 puts("\tUser Enhanced Start: ");
610 print_size(((u64
)pconf
.user
.enh_start
) << 9, "\n");
611 puts("\tUser Enhanced Size: ");
612 print_size(((u64
)pconf
.user
.enh_size
) << 9, "\n");
614 puts("\tNo enhanced user data area\n");
616 if (pconf
.user
.wr_rel_change
)
617 printf("\tUser partition write reliability: %s\n",
618 pconf
.user
.wr_rel_set
? "on" : "off");
619 for (pidx
= 0; pidx
< 4; pidx
++) {
620 if (pconf
.gp_part
[pidx
].size
) {
621 printf("\tGP%i Capacity: ", pidx
+1);
622 print_size(((u64
)pconf
.gp_part
[pidx
].size
) << 9,
623 pconf
.gp_part
[pidx
].enhanced
?
626 printf("\tNo GP%i partition\n", pidx
+1);
628 if (pconf
.gp_part
[pidx
].wr_rel_change
)
629 printf("\tGP%i write reliability: %s\n", pidx
+1,
630 pconf
.gp_part
[pidx
].wr_rel_set
? "on" : "off");
633 if (!mmc_hwpart_config(mmc
, &pconf
, mode
)) {
634 if (mode
== MMC_HWPART_CONF_COMPLETE
)
635 puts("Partitioning successful, "
636 "power-cycle to make effective\n");
637 return CMD_RET_SUCCESS
;
640 return CMD_RET_FAILURE
;
644 #ifdef CONFIG_SUPPORT_EMMC_BOOT
645 static int do_mmc_bootbus(cmd_tbl_t
*cmdtp
, int flag
,
646 int argc
, char * const argv
[])
650 u8 width
, reset
, mode
;
653 return CMD_RET_USAGE
;
654 dev
= simple_strtoul(argv
[1], NULL
, 10);
655 width
= simple_strtoul(argv
[2], NULL
, 10);
656 reset
= simple_strtoul(argv
[3], NULL
, 10);
657 mode
= simple_strtoul(argv
[4], NULL
, 10);
659 mmc
= init_mmc_device(dev
, false);
661 return CMD_RET_FAILURE
;
664 puts("BOOT_BUS_WIDTH only exists on eMMC\n");
665 return CMD_RET_FAILURE
;
668 /* acknowledge to be sent during boot operation */
669 return mmc_set_boot_bus_width(mmc
, width
, reset
, mode
);
671 static int do_mmc_boot_resize(cmd_tbl_t
*cmdtp
, int flag
,
672 int argc
, char * const argv
[])
676 u32 bootsize
, rpmbsize
;
679 return CMD_RET_USAGE
;
680 dev
= simple_strtoul(argv
[1], NULL
, 10);
681 bootsize
= simple_strtoul(argv
[2], NULL
, 10);
682 rpmbsize
= simple_strtoul(argv
[3], NULL
, 10);
684 mmc
= init_mmc_device(dev
, false);
686 return CMD_RET_FAILURE
;
689 printf("It is not a EMMC device\n");
690 return CMD_RET_FAILURE
;
693 if (mmc_boot_partition_size_change(mmc
, bootsize
, rpmbsize
)) {
694 printf("EMMC boot partition Size change Failed.\n");
695 return CMD_RET_FAILURE
;
698 printf("EMMC boot partition Size %d MB\n", bootsize
);
699 printf("EMMC RPMB partition Size %d MB\n", rpmbsize
);
700 return CMD_RET_SUCCESS
;
702 static int do_mmc_partconf(cmd_tbl_t
*cmdtp
, int flag
,
703 int argc
, char * const argv
[])
707 u8 ack
, part_num
, access
;
710 return CMD_RET_USAGE
;
712 dev
= simple_strtoul(argv
[1], NULL
, 10);
713 ack
= simple_strtoul(argv
[2], NULL
, 10);
714 part_num
= simple_strtoul(argv
[3], NULL
, 10);
715 access
= simple_strtoul(argv
[4], NULL
, 10);
717 mmc
= init_mmc_device(dev
, false);
719 return CMD_RET_FAILURE
;
722 puts("PARTITION_CONFIG only exists on eMMC\n");
723 return CMD_RET_FAILURE
;
726 /* acknowledge to be sent during boot operation */
727 return mmc_set_part_conf(mmc
, ack
, part_num
, access
);
729 static int do_mmc_rst_func(cmd_tbl_t
*cmdtp
, int flag
,
730 int argc
, char * const argv
[])
737 * Set the RST_n_ENABLE bit of RST_n_FUNCTION
738 * The only valid values are 0x0, 0x1 and 0x2 and writing
739 * a value of 0x1 or 0x2 sets the value permanently.
742 return CMD_RET_USAGE
;
744 dev
= simple_strtoul(argv
[1], NULL
, 10);
745 enable
= simple_strtoul(argv
[2], NULL
, 10);
748 puts("Invalid RST_n_ENABLE value\n");
749 return CMD_RET_USAGE
;
752 mmc
= init_mmc_device(dev
, false);
754 return CMD_RET_FAILURE
;
757 puts("RST_n_FUNCTION only exists on eMMC\n");
758 return CMD_RET_FAILURE
;
761 return mmc_set_rst_n_function(mmc
, enable
);
764 static int do_mmc_setdsr(cmd_tbl_t
*cmdtp
, int flag
,
765 int argc
, char * const argv
[])
772 return CMD_RET_USAGE
;
773 val
= simple_strtoul(argv
[2], NULL
, 16);
775 mmc
= find_mmc_device(curr_device
);
777 printf("no mmc device at slot %x\n", curr_device
);
778 return CMD_RET_FAILURE
;
780 ret
= mmc_set_dsr(mmc
, val
);
781 printf("set dsr %s\n", (!ret
) ? "OK, force rescan" : "ERROR");
785 return CMD_RET_FAILURE
;
787 return CMD_RET_SUCCESS
;
792 static cmd_tbl_t cmd_mmc
[] = {
793 U_BOOT_CMD_MKENT(info
, 1, 0, do_mmcinfo
, "", ""),
794 U_BOOT_CMD_MKENT(read
, 4, 1, do_mmc_read
, "", ""),
795 U_BOOT_CMD_MKENT(write
, 4, 0, do_mmc_write
, "", ""),
796 U_BOOT_CMD_MKENT(erase
, 3, 0, do_mmc_erase
, "", ""),
797 U_BOOT_CMD_MKENT(rescan
, 1, 1, do_mmc_rescan
, "", ""),
798 U_BOOT_CMD_MKENT(part
, 1, 1, do_mmc_part
, "", ""),
799 U_BOOT_CMD_MKENT(dev
, 3, 0, do_mmc_dev
, "", ""),
800 U_BOOT_CMD_MKENT(list
, 1, 1, do_mmc_list
, "", ""),
801 U_BOOT_CMD_MKENT(hwpartition
, 28, 0, do_mmc_hwpartition
, "", ""),
802 #ifdef CONFIG_SUPPORT_EMMC_BOOT
803 U_BOOT_CMD_MKENT(bootbus
, 5, 0, do_mmc_bootbus
, "", ""),
804 U_BOOT_CMD_MKENT(bootpart
-resize
, 4, 0, do_mmc_boot_resize
, "", ""),
805 U_BOOT_CMD_MKENT(partconf
, 5, 0, do_mmc_partconf
, "", ""),
806 U_BOOT_CMD_MKENT(rst
-function
, 3, 0, do_mmc_rst_func
, "", ""),
808 #ifdef CONFIG_SUPPORT_EMMC_RPMB
809 U_BOOT_CMD_MKENT(rpmb
, CONFIG_SYS_MAXARGS
, 1, do_mmcrpmb
, "", ""),
811 U_BOOT_CMD_MKENT(setdsr
, 2, 0, do_mmc_setdsr
, "", ""),
814 static int do_mmcops(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
818 cp
= find_cmd_tbl(argv
[1], cmd_mmc
, ARRAY_SIZE(cmd_mmc
));
820 /* Drop the mmc command */
824 if (cp
== NULL
|| argc
> cp
->maxargs
)
825 return CMD_RET_USAGE
;
826 if (flag
== CMD_FLAG_REPEAT
&& !cp
->repeatable
)
827 return CMD_RET_SUCCESS
;
829 if (curr_device
< 0) {
830 if (get_mmc_num() > 0) {
833 puts("No MMC device available\n");
834 return CMD_RET_FAILURE
;
837 return cp
->cmd(cmdtp
, flag
, argc
, argv
);
841 mmc
, 29, 1, do_mmcops
,
843 "info - display info of the current MMC device\n"
844 "mmc read addr blk# cnt\n"
845 "mmc write addr blk# cnt\n"
846 "mmc erase blk# cnt\n"
848 "mmc part - lists available partition on current mmc device\n"
849 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
850 "mmc list - lists available devices\n"
851 "mmc hwpartition [args...] - does hardware partitioning\n"
852 " arguments (sizes in 512-byte blocks):\n"
853 " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n"
854 " [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n"
855 " [check|set|complete] - mode, complete set partitioning completed\n"
856 " WARNING: Partitioning is a write-once setting once it is set to complete.\n"
857 " Power cycling is required to initialize partitions after set to complete.\n"
858 #ifdef CONFIG_SUPPORT_EMMC_BOOT
859 "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
860 " - Set the BOOT_BUS_WIDTH field of the specified device\n"
861 "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
862 " - Change sizes of boot and RPMB partitions of specified device\n"
863 "mmc partconf dev boot_ack boot_partition partition_access\n"
864 " - Change the bits of the PARTITION_CONFIG field of the specified device\n"
865 "mmc rst-function dev value\n"
866 " - Change the RST_n_FUNCTION field of the specified device\n"
867 " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
869 #ifdef CONFIG_SUPPORT_EMMC_RPMB
870 "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
871 "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
872 "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
873 "mmc rpmb counter - read the value of the write counter\n"
875 "mmc setdsr <value> - set DSR register value\n"
878 /* Old command kept for compatibility. Same as 'mmc info' */
880 mmcinfo
, 1, 0, do_mmcinfo
,
882 "- display info of the current MMC device"
885 #endif /* !CONFIG_GENERIC_MMC */