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
);
159 static int do_mmcinfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
163 if (curr_device
< 0) {
164 if (get_mmc_num() > 0)
167 puts("No MMC device available\n");
172 mmc
= init_mmc_device(curr_device
, false);
174 return CMD_RET_FAILURE
;
177 return CMD_RET_SUCCESS
;
180 #ifdef CONFIG_SUPPORT_EMMC_RPMB
181 static int confirm_key_prog(void)
183 puts("Warning: Programming authentication key can be done only once !\n"
184 " Use this command only if you are sure of what you are doing,\n"
185 "Really perform the key programming? <y/N> ");
189 puts("Authentication key programming aborted\n");
192 static int do_mmcrpmb_key(cmd_tbl_t
*cmdtp
, int flag
,
193 int argc
, char * const argv
[])
196 struct mmc
*mmc
= find_mmc_device(curr_device
);
199 return CMD_RET_USAGE
;
201 key_addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
202 if (!confirm_key_prog())
203 return CMD_RET_FAILURE
;
204 if (mmc_rpmb_set_key(mmc
, key_addr
)) {
205 printf("ERROR - Key already programmed ?\n");
206 return CMD_RET_FAILURE
;
208 return CMD_RET_SUCCESS
;
210 static int do_mmcrpmb_read(cmd_tbl_t
*cmdtp
, int flag
,
211 int argc
, char * const argv
[])
216 void *key_addr
= NULL
;
217 struct mmc
*mmc
= find_mmc_device(curr_device
);
220 return CMD_RET_USAGE
;
222 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
223 blk
= simple_strtoul(argv
[2], NULL
, 16);
224 cnt
= simple_strtoul(argv
[3], NULL
, 16);
227 key_addr
= (void *)simple_strtoul(argv
[4], NULL
, 16);
229 printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
230 curr_device
, blk
, cnt
);
231 n
= mmc_rpmb_read(mmc
, addr
, blk
, cnt
, key_addr
);
233 printf("%d RPMB blocks read: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
235 return CMD_RET_FAILURE
;
236 return CMD_RET_SUCCESS
;
238 static int do_mmcrpmb_write(cmd_tbl_t
*cmdtp
, int flag
,
239 int argc
, char * const argv
[])
245 struct mmc
*mmc
= find_mmc_device(curr_device
);
248 return CMD_RET_USAGE
;
250 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
251 blk
= simple_strtoul(argv
[2], NULL
, 16);
252 cnt
= simple_strtoul(argv
[3], NULL
, 16);
253 key_addr
= (void *)simple_strtoul(argv
[4], NULL
, 16);
255 printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
256 curr_device
, blk
, cnt
);
257 n
= mmc_rpmb_write(mmc
, addr
, blk
, cnt
, key_addr
);
259 printf("%d RPMB blocks written: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
261 return CMD_RET_FAILURE
;
262 return CMD_RET_SUCCESS
;
264 static int do_mmcrpmb_counter(cmd_tbl_t
*cmdtp
, int flag
,
265 int argc
, char * const argv
[])
267 unsigned long counter
;
268 struct mmc
*mmc
= find_mmc_device(curr_device
);
270 if (mmc_rpmb_get_counter(mmc
, &counter
))
271 return CMD_RET_FAILURE
;
272 printf("RPMB Write counter= %lx\n", counter
);
273 return CMD_RET_SUCCESS
;
276 static cmd_tbl_t cmd_rpmb
[] = {
277 U_BOOT_CMD_MKENT(key
, 2, 0, do_mmcrpmb_key
, "", ""),
278 U_BOOT_CMD_MKENT(read
, 5, 1, do_mmcrpmb_read
, "", ""),
279 U_BOOT_CMD_MKENT(write
, 5, 0, do_mmcrpmb_write
, "", ""),
280 U_BOOT_CMD_MKENT(counter
, 1, 1, do_mmcrpmb_counter
, "", ""),
283 static int do_mmcrpmb(cmd_tbl_t
*cmdtp
, int flag
,
284 int argc
, char * const argv
[])
291 cp
= find_cmd_tbl(argv
[1], cmd_rpmb
, ARRAY_SIZE(cmd_rpmb
));
293 /* Drop the rpmb subcommand */
297 if (cp
== NULL
|| argc
> cp
->maxargs
)
298 return CMD_RET_USAGE
;
299 if (flag
== CMD_FLAG_REPEAT
&& !cp
->repeatable
)
300 return CMD_RET_SUCCESS
;
302 mmc
= init_mmc_device(curr_device
, false);
304 return CMD_RET_FAILURE
;
306 if (!(mmc
->version
& MMC_VERSION_MMC
)) {
307 printf("It is not a EMMC device\n");
308 return CMD_RET_FAILURE
;
310 if (mmc
->version
< MMC_VERSION_4_41
) {
311 printf("RPMB not supported before version 4.41\n");
312 return CMD_RET_FAILURE
;
314 /* Switch to the RPMB partition */
315 original_part
= mmc
->part_num
;
316 if (mmc
->part_num
!= MMC_PART_RPMB
) {
317 if (mmc_switch_part(curr_device
, MMC_PART_RPMB
) != 0)
318 return CMD_RET_FAILURE
;
319 mmc
->part_num
= MMC_PART_RPMB
;
321 ret
= cp
->cmd(cmdtp
, flag
, argc
, argv
);
323 /* Return to original partition */
324 if (mmc
->part_num
!= original_part
) {
325 if (mmc_switch_part(curr_device
, original_part
) != 0)
326 return CMD_RET_FAILURE
;
327 mmc
->part_num
= original_part
;
333 static int do_mmc_read(cmd_tbl_t
*cmdtp
, int flag
,
334 int argc
, char * const argv
[])
341 return CMD_RET_USAGE
;
343 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
344 blk
= simple_strtoul(argv
[2], NULL
, 16);
345 cnt
= simple_strtoul(argv
[3], NULL
, 16);
347 mmc
= init_mmc_device(curr_device
, false);
349 return CMD_RET_FAILURE
;
351 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
352 curr_device
, blk
, cnt
);
354 n
= mmc
->block_dev
.block_read(curr_device
, blk
, cnt
, addr
);
355 /* flush cache after read */
356 flush_cache((ulong
)addr
, cnt
* 512); /* FIXME */
357 printf("%d blocks read: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
359 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
361 static int do_mmc_write(cmd_tbl_t
*cmdtp
, int flag
,
362 int argc
, char * const argv
[])
369 return CMD_RET_USAGE
;
371 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
372 blk
= simple_strtoul(argv
[2], NULL
, 16);
373 cnt
= simple_strtoul(argv
[3], NULL
, 16);
375 mmc
= init_mmc_device(curr_device
, false);
377 return CMD_RET_FAILURE
;
379 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
380 curr_device
, blk
, cnt
);
382 if (mmc_getwp(mmc
) == 1) {
383 printf("Error: card is write protected!\n");
384 return CMD_RET_FAILURE
;
386 n
= mmc
->block_dev
.block_write(curr_device
, blk
, cnt
, addr
);
387 printf("%d blocks written: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
389 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
391 static int do_mmc_erase(cmd_tbl_t
*cmdtp
, int flag
,
392 int argc
, char * const argv
[])
398 return CMD_RET_USAGE
;
400 blk
= simple_strtoul(argv
[1], NULL
, 16);
401 cnt
= simple_strtoul(argv
[2], NULL
, 16);
403 mmc
= init_mmc_device(curr_device
, false);
405 return CMD_RET_FAILURE
;
407 printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
408 curr_device
, blk
, cnt
);
410 if (mmc_getwp(mmc
) == 1) {
411 printf("Error: card is write protected!\n");
412 return CMD_RET_FAILURE
;
414 n
= mmc
->block_dev
.block_erase(curr_device
, blk
, cnt
);
415 printf("%d blocks erased: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
417 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
419 static int do_mmc_rescan(cmd_tbl_t
*cmdtp
, int flag
,
420 int argc
, char * const argv
[])
424 mmc
= init_mmc_device(curr_device
, true);
426 return CMD_RET_FAILURE
;
428 return CMD_RET_SUCCESS
;
430 static int do_mmc_part(cmd_tbl_t
*cmdtp
, int flag
,
431 int argc
, char * const argv
[])
433 block_dev_desc_t
*mmc_dev
;
436 mmc
= init_mmc_device(curr_device
, false);
438 return CMD_RET_FAILURE
;
440 mmc_dev
= mmc_get_dev(curr_device
);
441 if (mmc_dev
!= NULL
&& mmc_dev
->type
!= DEV_TYPE_UNKNOWN
) {
443 return CMD_RET_SUCCESS
;
446 puts("get mmc type error!\n");
447 return CMD_RET_FAILURE
;
449 static int do_mmc_dev(cmd_tbl_t
*cmdtp
, int flag
,
450 int argc
, char * const argv
[])
452 int dev
, part
= 0, ret
;
457 } else if (argc
== 2) {
458 dev
= simple_strtoul(argv
[1], NULL
, 10);
459 } else if (argc
== 3) {
460 dev
= (int)simple_strtoul(argv
[1], NULL
, 10);
461 part
= (int)simple_strtoul(argv
[2], NULL
, 10);
462 if (part
> PART_ACCESS_MASK
) {
463 printf("#part_num shouldn't be larger than %d\n",
465 return CMD_RET_FAILURE
;
468 return CMD_RET_USAGE
;
471 mmc
= init_mmc_device(dev
, true);
473 return CMD_RET_FAILURE
;
475 ret
= mmc_select_hwpart(dev
, part
);
476 printf("switch to partitions #%d, %s\n",
477 part
, (!ret
) ? "OK" : "ERROR");
482 if (mmc
->part_config
== MMCPART_NOAVAILABLE
)
483 printf("mmc%d is current device\n", curr_device
);
485 printf("mmc%d(part %d) is current device\n",
486 curr_device
, mmc
->part_num
);
488 return CMD_RET_SUCCESS
;
490 static int do_mmc_list(cmd_tbl_t
*cmdtp
, int flag
,
491 int argc
, char * const argv
[])
493 print_mmc_devices('\n');
494 return CMD_RET_SUCCESS
;
497 static int parse_hwpart_user(struct mmc_hwpart_conf
*pconf
,
498 int argc
, char * const argv
[])
502 memset(&pconf
->user
, 0, sizeof(pconf
->user
));
505 if (!strcmp(argv
[i
], "enh")) {
508 pconf
->user
.enh_start
=
509 simple_strtoul(argv
[i
+1], NULL
, 10);
510 pconf
->user
.enh_size
=
511 simple_strtoul(argv
[i
+2], NULL
, 10);
513 } else if (!strcmp(argv
[i
], "wrrel")) {
516 pconf
->user
.wr_rel_change
= 1;
517 if (!strcmp(argv
[i
+1], "on"))
518 pconf
->user
.wr_rel_set
= 1;
519 else if (!strcmp(argv
[i
+1], "off"))
520 pconf
->user
.wr_rel_set
= 0;
531 static int parse_hwpart_gp(struct mmc_hwpart_conf
*pconf
, int pidx
,
532 int argc
, char * const argv
[])
536 memset(&pconf
->gp_part
[pidx
], 0, sizeof(pconf
->gp_part
[pidx
]));
540 pconf
->gp_part
[pidx
].size
= simple_strtoul(argv
[0], NULL
, 10);
544 if (!strcmp(argv
[i
], "enh")) {
545 pconf
->gp_part
[pidx
].enhanced
= 1;
547 } else if (!strcmp(argv
[i
], "wrrel")) {
550 pconf
->gp_part
[pidx
].wr_rel_change
= 1;
551 if (!strcmp(argv
[i
+1], "on"))
552 pconf
->gp_part
[pidx
].wr_rel_set
= 1;
553 else if (!strcmp(argv
[i
+1], "off"))
554 pconf
->gp_part
[pidx
].wr_rel_set
= 0;
565 static int do_mmc_hwpartition(cmd_tbl_t
*cmdtp
, int flag
,
566 int argc
, char * const argv
[])
569 struct mmc_hwpart_conf pconf
= { };
570 enum mmc_hwpart_conf_mode mode
= MMC_HWPART_CONF_CHECK
;
573 mmc
= init_mmc_device(curr_device
, false);
575 return CMD_RET_FAILURE
;
578 return CMD_RET_USAGE
;
581 if (!strcmp(argv
[i
], "user")) {
583 r
= parse_hwpart_user(&pconf
, argc
-i
, &argv
[i
]);
585 return CMD_RET_USAGE
;
587 } else if (!strncmp(argv
[i
], "gp", 2) &&
588 strlen(argv
[i
]) == 3 &&
589 argv
[i
][2] >= '1' && argv
[i
][2] <= '4') {
590 pidx
= argv
[i
][2] - '1';
592 r
= parse_hwpart_gp(&pconf
, pidx
, argc
-i
, &argv
[i
]);
594 return CMD_RET_USAGE
;
596 } else if (!strcmp(argv
[i
], "check")) {
597 mode
= MMC_HWPART_CONF_CHECK
;
599 } else if (!strcmp(argv
[i
], "set")) {
600 mode
= MMC_HWPART_CONF_SET
;
602 } else if (!strcmp(argv
[i
], "complete")) {
603 mode
= MMC_HWPART_CONF_COMPLETE
;
606 return CMD_RET_USAGE
;
610 puts("Partition configuration:\n");
611 if (pconf
.user
.enh_size
) {
612 puts("\tUser Enhanced Start: ");
613 print_size(((u64
)pconf
.user
.enh_start
) << 9, "\n");
614 puts("\tUser Enhanced Size: ");
615 print_size(((u64
)pconf
.user
.enh_size
) << 9, "\n");
617 puts("\tNo enhanced user data area\n");
619 if (pconf
.user
.wr_rel_change
)
620 printf("\tUser partition write reliability: %s\n",
621 pconf
.user
.wr_rel_set
? "on" : "off");
622 for (pidx
= 0; pidx
< 4; pidx
++) {
623 if (pconf
.gp_part
[pidx
].size
) {
624 printf("\tGP%i Capacity: ", pidx
+1);
625 print_size(((u64
)pconf
.gp_part
[pidx
].size
) << 9,
626 pconf
.gp_part
[pidx
].enhanced
?
629 printf("\tNo GP%i partition\n", pidx
+1);
631 if (pconf
.gp_part
[pidx
].wr_rel_change
)
632 printf("\tGP%i write reliability: %s\n", pidx
+1,
633 pconf
.gp_part
[pidx
].wr_rel_set
? "on" : "off");
636 if (!mmc_hwpart_config(mmc
, &pconf
, mode
)) {
637 if (mode
== MMC_HWPART_CONF_COMPLETE
)
638 puts("Partitioning successful, "
639 "power-cycle to make effective\n");
640 return CMD_RET_SUCCESS
;
643 return CMD_RET_FAILURE
;
647 #ifdef CONFIG_SUPPORT_EMMC_BOOT
648 static int do_mmc_bootbus(cmd_tbl_t
*cmdtp
, int flag
,
649 int argc
, char * const argv
[])
653 u8 width
, reset
, mode
;
656 return CMD_RET_USAGE
;
657 dev
= simple_strtoul(argv
[1], NULL
, 10);
658 width
= simple_strtoul(argv
[2], NULL
, 10);
659 reset
= simple_strtoul(argv
[3], NULL
, 10);
660 mode
= simple_strtoul(argv
[4], NULL
, 10);
662 mmc
= init_mmc_device(dev
, false);
664 return CMD_RET_FAILURE
;
667 puts("BOOT_BUS_WIDTH only exists on eMMC\n");
668 return CMD_RET_FAILURE
;
671 /* acknowledge to be sent during boot operation */
672 return mmc_set_boot_bus_width(mmc
, width
, reset
, mode
);
674 static int do_mmc_boot_resize(cmd_tbl_t
*cmdtp
, int flag
,
675 int argc
, char * const argv
[])
679 u32 bootsize
, rpmbsize
;
682 return CMD_RET_USAGE
;
683 dev
= simple_strtoul(argv
[1], NULL
, 10);
684 bootsize
= simple_strtoul(argv
[2], NULL
, 10);
685 rpmbsize
= simple_strtoul(argv
[3], NULL
, 10);
687 mmc
= init_mmc_device(dev
, false);
689 return CMD_RET_FAILURE
;
692 printf("It is not a EMMC device\n");
693 return CMD_RET_FAILURE
;
696 if (mmc_boot_partition_size_change(mmc
, bootsize
, rpmbsize
)) {
697 printf("EMMC boot partition Size change Failed.\n");
698 return CMD_RET_FAILURE
;
701 printf("EMMC boot partition Size %d MB\n", bootsize
);
702 printf("EMMC RPMB partition Size %d MB\n", rpmbsize
);
703 return CMD_RET_SUCCESS
;
705 static int do_mmc_partconf(cmd_tbl_t
*cmdtp
, int flag
,
706 int argc
, char * const argv
[])
710 u8 ack
, part_num
, access
;
713 return CMD_RET_USAGE
;
715 dev
= simple_strtoul(argv
[1], NULL
, 10);
716 ack
= simple_strtoul(argv
[2], NULL
, 10);
717 part_num
= simple_strtoul(argv
[3], NULL
, 10);
718 access
= simple_strtoul(argv
[4], NULL
, 10);
720 mmc
= init_mmc_device(dev
, false);
722 return CMD_RET_FAILURE
;
725 puts("PARTITION_CONFIG only exists on eMMC\n");
726 return CMD_RET_FAILURE
;
729 /* acknowledge to be sent during boot operation */
730 return mmc_set_part_conf(mmc
, ack
, part_num
, access
);
732 static int do_mmc_rst_func(cmd_tbl_t
*cmdtp
, int flag
,
733 int argc
, char * const argv
[])
740 * Set the RST_n_ENABLE bit of RST_n_FUNCTION
741 * The only valid values are 0x0, 0x1 and 0x2 and writing
742 * a value of 0x1 or 0x2 sets the value permanently.
745 return CMD_RET_USAGE
;
747 dev
= simple_strtoul(argv
[1], NULL
, 10);
748 enable
= simple_strtoul(argv
[2], NULL
, 10);
750 if (enable
> 2 || enable
< 0) {
751 puts("Invalid RST_n_ENABLE value\n");
752 return CMD_RET_USAGE
;
755 mmc
= init_mmc_device(dev
, false);
757 return CMD_RET_FAILURE
;
760 puts("RST_n_FUNCTION only exists on eMMC\n");
761 return CMD_RET_FAILURE
;
764 return mmc_set_rst_n_function(mmc
, enable
);
767 static int do_mmc_setdsr(cmd_tbl_t
*cmdtp
, int flag
,
768 int argc
, char * const argv
[])
775 return CMD_RET_USAGE
;
776 val
= simple_strtoul(argv
[2], NULL
, 16);
778 mmc
= find_mmc_device(curr_device
);
780 printf("no mmc device at slot %x\n", curr_device
);
781 return CMD_RET_FAILURE
;
783 ret
= mmc_set_dsr(mmc
, val
);
784 printf("set dsr %s\n", (!ret
) ? "OK, force rescan" : "ERROR");
788 return CMD_RET_FAILURE
;
790 return CMD_RET_SUCCESS
;
795 static cmd_tbl_t cmd_mmc
[] = {
796 U_BOOT_CMD_MKENT(info
, 1, 0, do_mmcinfo
, "", ""),
797 U_BOOT_CMD_MKENT(read
, 4, 1, do_mmc_read
, "", ""),
798 U_BOOT_CMD_MKENT(write
, 4, 0, do_mmc_write
, "", ""),
799 U_BOOT_CMD_MKENT(erase
, 3, 0, do_mmc_erase
, "", ""),
800 U_BOOT_CMD_MKENT(rescan
, 1, 1, do_mmc_rescan
, "", ""),
801 U_BOOT_CMD_MKENT(part
, 1, 1, do_mmc_part
, "", ""),
802 U_BOOT_CMD_MKENT(dev
, 3, 0, do_mmc_dev
, "", ""),
803 U_BOOT_CMD_MKENT(list
, 1, 1, do_mmc_list
, "", ""),
804 U_BOOT_CMD_MKENT(hwpartition
, 28, 0, do_mmc_hwpartition
, "", ""),
805 #ifdef CONFIG_SUPPORT_EMMC_BOOT
806 U_BOOT_CMD_MKENT(bootbus
, 5, 0, do_mmc_bootbus
, "", ""),
807 U_BOOT_CMD_MKENT(bootpart
-resize
, 4, 0, do_mmc_boot_resize
, "", ""),
808 U_BOOT_CMD_MKENT(partconf
, 5, 0, do_mmc_partconf
, "", ""),
809 U_BOOT_CMD_MKENT(rst
-function
, 3, 0, do_mmc_rst_func
, "", ""),
811 #ifdef CONFIG_SUPPORT_EMMC_RPMB
812 U_BOOT_CMD_MKENT(rpmb
, CONFIG_SYS_MAXARGS
, 1, do_mmcrpmb
, "", ""),
814 U_BOOT_CMD_MKENT(setdsr
, 2, 0, do_mmc_setdsr
, "", ""),
817 static int do_mmcops(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
821 cp
= find_cmd_tbl(argv
[1], cmd_mmc
, ARRAY_SIZE(cmd_mmc
));
823 /* Drop the mmc command */
827 if (cp
== NULL
|| argc
> cp
->maxargs
)
828 return CMD_RET_USAGE
;
829 if (flag
== CMD_FLAG_REPEAT
&& !cp
->repeatable
)
830 return CMD_RET_SUCCESS
;
832 if (curr_device
< 0) {
833 if (get_mmc_num() > 0) {
836 puts("No MMC device available\n");
837 return CMD_RET_FAILURE
;
840 return cp
->cmd(cmdtp
, flag
, argc
, argv
);
844 mmc
, 29, 1, do_mmcops
,
846 "info - display info of the current MMC device\n"
847 "mmc read addr blk# cnt\n"
848 "mmc write addr blk# cnt\n"
849 "mmc erase blk# cnt\n"
851 "mmc part - lists available partition on current mmc device\n"
852 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
853 "mmc list - lists available devices\n"
854 "mmc hwpartition [args...] - does hardware partitioning\n"
855 " arguments (sizes in 512-byte blocks):\n"
856 " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n"
857 " [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n"
858 " [check|set|complete] - mode, complete set partitioning completed\n"
859 " WARNING: Partitioning is a write-once setting once it is set to complete.\n"
860 " Power cycling is required to initialize partitions after set to complete.\n"
861 #ifdef CONFIG_SUPPORT_EMMC_BOOT
862 "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
863 " - Set the BOOT_BUS_WIDTH field of the specified device\n"
864 "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
865 " - Change sizes of boot and RPMB partitions of specified device\n"
866 "mmc partconf dev boot_ack boot_partition partition_access\n"
867 " - Change the bits of the PARTITION_CONFIG field of the specified device\n"
868 "mmc rst-function dev value\n"
869 " - Change the RST_n_FUNCTION field of the specified device\n"
870 " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
872 #ifdef CONFIG_SUPPORT_EMMC_RPMB
873 "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
874 "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
875 "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
876 "mmc rpmb counter - read the value of the write counter\n"
878 "mmc setdsr <value> - set DSR register value\n"
881 /* Old command kept for compatibility. Same as 'mmc info' */
883 mmcinfo
, 1, 0, do_mmcinfo
,
885 "- display info of the current MMC device"
888 #endif /* !CONFIG_GENERIC_MMC */