1 // SPDX-License-Identifier: GPL-2.0+
4 * Kyle Harris, kharris@nexus-tech.net
12 static int curr_device
= -1;
14 static void print_mmcinfo(struct mmc
*mmc
)
18 printf("Device: %s\n", mmc
->cfg
->name
);
19 printf("Manufacturer ID: %x\n", mmc
->cid
[0] >> 24);
20 printf("OEM: %x\n", (mmc
->cid
[0] >> 8) & 0xffff);
21 printf("Name: %c%c%c%c%c \n", mmc
->cid
[0] & 0xff,
22 (mmc
->cid
[1] >> 24), (mmc
->cid
[1] >> 16) & 0xff,
23 (mmc
->cid
[1] >> 8) & 0xff, mmc
->cid
[1] & 0xff);
25 printf("Bus Speed: %d\n", mmc
->clock
);
26 #if CONFIG_IS_ENABLED(MMC_VERBOSE)
27 printf("Mode : %s\n", mmc_mode_name(mmc
->selected_mode
));
28 mmc_dump_capabilities("card capabilities", mmc
->card_caps
);
29 mmc_dump_capabilities("host capabilities", mmc
->host_caps
);
31 printf("Rd Block Len: %d\n", mmc
->read_bl_len
);
33 printf("%s version %d.%d", IS_SD(mmc
) ? "SD" : "MMC",
34 EXTRACT_SDMMC_MAJOR_VERSION(mmc
->version
),
35 EXTRACT_SDMMC_MINOR_VERSION(mmc
->version
));
36 if (EXTRACT_SDMMC_CHANGE_VERSION(mmc
->version
) != 0)
37 printf(".%d", EXTRACT_SDMMC_CHANGE_VERSION(mmc
->version
));
40 printf("High Capacity: %s\n", mmc
->high_capacity
? "Yes" : "No");
42 print_size(mmc
->capacity
, "\n");
44 printf("Bus Width: %d-bit%s\n", mmc
->bus_width
,
45 mmc
->ddr_mode
? " DDR" : "");
47 #if CONFIG_IS_ENABLED(MMC_WRITE)
48 puts("Erase Group Size: ");
49 print_size(((u64
)mmc
->erase_grp_size
) << 9, "\n");
52 if (!IS_SD(mmc
) && mmc
->version
>= MMC_VERSION_4_41
) {
53 bool has_enh
= (mmc
->part_support
& ENHNCD_SUPPORT
) != 0;
54 bool usr_enh
= has_enh
&& (mmc
->part_attr
& EXT_CSD_ENH_USR
);
56 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
57 puts("HC WP Group Size: ");
58 print_size(((u64
)mmc
->hc_wp_grp_size
) << 9, "\n");
61 puts("User Capacity: ");
62 print_size(mmc
->capacity_user
, usr_enh
? " ENH" : "");
63 if (mmc
->wr_rel_set
& EXT_CSD_WR_DATA_REL_USR
)
68 puts("User Enhanced Start: ");
69 print_size(mmc
->enh_user_start
, "\n");
70 puts("User Enhanced Size: ");
71 print_size(mmc
->enh_user_size
, "\n");
73 puts("Boot Capacity: ");
74 print_size(mmc
->capacity_boot
, has_enh
? " ENH\n" : "\n");
75 puts("RPMB Capacity: ");
76 print_size(mmc
->capacity_rpmb
, has_enh
? " ENH\n" : "\n");
78 for (i
= 0; i
< ARRAY_SIZE(mmc
->capacity_gp
); i
++) {
79 bool is_enh
= has_enh
&&
80 (mmc
->part_attr
& EXT_CSD_ENH_GP(i
));
81 if (mmc
->capacity_gp
[i
]) {
82 printf("GP%i Capacity: ", i
+1);
83 print_size(mmc
->capacity_gp
[i
],
84 is_enh
? " ENH" : "");
85 if (mmc
->wr_rel_set
& EXT_CSD_WR_DATA_REL_GP(i
))
93 static struct mmc
*init_mmc_device(int dev
, bool force_init
)
96 mmc
= find_mmc_device(dev
);
98 printf("no mmc device at slot %x\n", dev
);
108 static int do_mmcinfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
112 if (curr_device
< 0) {
113 if (get_mmc_num() > 0)
116 puts("No MMC device available\n");
121 mmc
= init_mmc_device(curr_device
, false);
123 return CMD_RET_FAILURE
;
126 return CMD_RET_SUCCESS
;
129 #ifdef CONFIG_SUPPORT_EMMC_RPMB
130 static int confirm_key_prog(void)
132 puts("Warning: Programming authentication key can be done only once !\n"
133 " Use this command only if you are sure of what you are doing,\n"
134 "Really perform the key programming? <y/N> ");
138 puts("Authentication key programming aborted\n");
141 static int do_mmcrpmb_key(cmd_tbl_t
*cmdtp
, int flag
,
142 int argc
, char * const argv
[])
145 struct mmc
*mmc
= find_mmc_device(curr_device
);
148 return CMD_RET_USAGE
;
150 key_addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
151 if (!confirm_key_prog())
152 return CMD_RET_FAILURE
;
153 if (mmc_rpmb_set_key(mmc
, key_addr
)) {
154 printf("ERROR - Key already programmed ?\n");
155 return CMD_RET_FAILURE
;
157 return CMD_RET_SUCCESS
;
159 static int do_mmcrpmb_read(cmd_tbl_t
*cmdtp
, int flag
,
160 int argc
, char * const argv
[])
165 void *key_addr
= NULL
;
166 struct mmc
*mmc
= find_mmc_device(curr_device
);
169 return CMD_RET_USAGE
;
171 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
172 blk
= simple_strtoul(argv
[2], NULL
, 16);
173 cnt
= simple_strtoul(argv
[3], NULL
, 16);
176 key_addr
= (void *)simple_strtoul(argv
[4], NULL
, 16);
178 printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ",
179 curr_device
, blk
, cnt
);
180 n
= mmc_rpmb_read(mmc
, addr
, blk
, cnt
, key_addr
);
182 printf("%d RPMB blocks read: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
184 return CMD_RET_FAILURE
;
185 return CMD_RET_SUCCESS
;
187 static int do_mmcrpmb_write(cmd_tbl_t
*cmdtp
, int flag
,
188 int argc
, char * const argv
[])
194 struct mmc
*mmc
= find_mmc_device(curr_device
);
197 return CMD_RET_USAGE
;
199 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
200 blk
= simple_strtoul(argv
[2], NULL
, 16);
201 cnt
= simple_strtoul(argv
[3], NULL
, 16);
202 key_addr
= (void *)simple_strtoul(argv
[4], NULL
, 16);
204 printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ",
205 curr_device
, blk
, cnt
);
206 n
= mmc_rpmb_write(mmc
, addr
, blk
, cnt
, key_addr
);
208 printf("%d RPMB blocks written: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
210 return CMD_RET_FAILURE
;
211 return CMD_RET_SUCCESS
;
213 static int do_mmcrpmb_counter(cmd_tbl_t
*cmdtp
, int flag
,
214 int argc
, char * const argv
[])
216 unsigned long counter
;
217 struct mmc
*mmc
= find_mmc_device(curr_device
);
219 if (mmc_rpmb_get_counter(mmc
, &counter
))
220 return CMD_RET_FAILURE
;
221 printf("RPMB Write counter= %lx\n", counter
);
222 return CMD_RET_SUCCESS
;
225 static cmd_tbl_t cmd_rpmb
[] = {
226 U_BOOT_CMD_MKENT(key
, 2, 0, do_mmcrpmb_key
, "", ""),
227 U_BOOT_CMD_MKENT(read
, 5, 1, do_mmcrpmb_read
, "", ""),
228 U_BOOT_CMD_MKENT(write
, 5, 0, do_mmcrpmb_write
, "", ""),
229 U_BOOT_CMD_MKENT(counter
, 1, 1, do_mmcrpmb_counter
, "", ""),
232 static int do_mmcrpmb(cmd_tbl_t
*cmdtp
, int flag
,
233 int argc
, char * const argv
[])
240 cp
= find_cmd_tbl(argv
[1], cmd_rpmb
, ARRAY_SIZE(cmd_rpmb
));
242 /* Drop the rpmb subcommand */
246 if (cp
== NULL
|| argc
> cp
->maxargs
)
247 return CMD_RET_USAGE
;
248 if (flag
== CMD_FLAG_REPEAT
&& !cp
->repeatable
)
249 return CMD_RET_SUCCESS
;
251 mmc
= init_mmc_device(curr_device
, false);
253 return CMD_RET_FAILURE
;
255 if (!(mmc
->version
& MMC_VERSION_MMC
)) {
256 printf("It is not a EMMC device\n");
257 return CMD_RET_FAILURE
;
259 if (mmc
->version
< MMC_VERSION_4_41
) {
260 printf("RPMB not supported before version 4.41\n");
261 return CMD_RET_FAILURE
;
263 /* Switch to the RPMB partition */
265 original_part
= mmc
->block_dev
.hwpart
;
267 original_part
= mmc_get_blk_desc(mmc
)->hwpart
;
269 if (blk_select_hwpart_devnum(IF_TYPE_MMC
, curr_device
, MMC_PART_RPMB
) !=
271 return CMD_RET_FAILURE
;
272 ret
= cp
->cmd(cmdtp
, flag
, argc
, argv
);
274 /* Return to original partition */
275 if (blk_select_hwpart_devnum(IF_TYPE_MMC
, curr_device
, original_part
) !=
277 return CMD_RET_FAILURE
;
282 static int do_mmc_read(cmd_tbl_t
*cmdtp
, int flag
,
283 int argc
, char * const argv
[])
290 return CMD_RET_USAGE
;
292 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
293 blk
= simple_strtoul(argv
[2], NULL
, 16);
294 cnt
= simple_strtoul(argv
[3], NULL
, 16);
296 mmc
= init_mmc_device(curr_device
, false);
298 return CMD_RET_FAILURE
;
300 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
301 curr_device
, blk
, cnt
);
303 n
= blk_dread(mmc_get_blk_desc(mmc
), blk
, cnt
, addr
);
304 printf("%d blocks read: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
306 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
309 #if CONFIG_IS_ENABLED(MMC_WRITE)
310 static int do_mmc_write(cmd_tbl_t
*cmdtp
, int flag
,
311 int argc
, char * const argv
[])
318 return CMD_RET_USAGE
;
320 addr
= (void *)simple_strtoul(argv
[1], NULL
, 16);
321 blk
= simple_strtoul(argv
[2], NULL
, 16);
322 cnt
= simple_strtoul(argv
[3], NULL
, 16);
324 mmc
= init_mmc_device(curr_device
, false);
326 return CMD_RET_FAILURE
;
328 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
329 curr_device
, blk
, cnt
);
331 if (mmc_getwp(mmc
) == 1) {
332 printf("Error: card is write protected!\n");
333 return CMD_RET_FAILURE
;
335 n
= blk_dwrite(mmc_get_blk_desc(mmc
), blk
, cnt
, addr
);
336 printf("%d blocks written: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
338 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
340 static int do_mmc_erase(cmd_tbl_t
*cmdtp
, int flag
,
341 int argc
, char * const argv
[])
347 return CMD_RET_USAGE
;
349 blk
= simple_strtoul(argv
[1], NULL
, 16);
350 cnt
= simple_strtoul(argv
[2], NULL
, 16);
352 mmc
= init_mmc_device(curr_device
, false);
354 return CMD_RET_FAILURE
;
356 printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
357 curr_device
, blk
, cnt
);
359 if (mmc_getwp(mmc
) == 1) {
360 printf("Error: card is write protected!\n");
361 return CMD_RET_FAILURE
;
363 n
= blk_derase(mmc_get_blk_desc(mmc
), blk
, cnt
);
364 printf("%d blocks erased: %s\n", n
, (n
== cnt
) ? "OK" : "ERROR");
366 return (n
== cnt
) ? CMD_RET_SUCCESS
: CMD_RET_FAILURE
;
370 static int do_mmc_rescan(cmd_tbl_t
*cmdtp
, int flag
,
371 int argc
, char * const argv
[])
375 mmc
= init_mmc_device(curr_device
, true);
377 return CMD_RET_FAILURE
;
379 return CMD_RET_SUCCESS
;
381 static int do_mmc_part(cmd_tbl_t
*cmdtp
, int flag
,
382 int argc
, char * const argv
[])
384 struct blk_desc
*mmc_dev
;
387 mmc
= init_mmc_device(curr_device
, false);
389 return CMD_RET_FAILURE
;
391 mmc_dev
= blk_get_devnum_by_type(IF_TYPE_MMC
, curr_device
);
392 if (mmc_dev
!= NULL
&& mmc_dev
->type
!= DEV_TYPE_UNKNOWN
) {
394 return CMD_RET_SUCCESS
;
397 puts("get mmc type error!\n");
398 return CMD_RET_FAILURE
;
400 static int do_mmc_dev(cmd_tbl_t
*cmdtp
, int flag
,
401 int argc
, char * const argv
[])
403 int dev
, part
= 0, ret
;
408 } else if (argc
== 2) {
409 dev
= simple_strtoul(argv
[1], NULL
, 10);
410 } else if (argc
== 3) {
411 dev
= (int)simple_strtoul(argv
[1], NULL
, 10);
412 part
= (int)simple_strtoul(argv
[2], NULL
, 10);
413 if (part
> PART_ACCESS_MASK
) {
414 printf("#part_num shouldn't be larger than %d\n",
416 return CMD_RET_FAILURE
;
419 return CMD_RET_USAGE
;
422 mmc
= init_mmc_device(dev
, true);
424 return CMD_RET_FAILURE
;
426 ret
= blk_select_hwpart_devnum(IF_TYPE_MMC
, dev
, part
);
427 printf("switch to partitions #%d, %s\n",
428 part
, (!ret
) ? "OK" : "ERROR");
433 if (mmc
->part_config
== MMCPART_NOAVAILABLE
)
434 printf("mmc%d is current device\n", curr_device
);
436 printf("mmc%d(part %d) is current device\n",
437 curr_device
, mmc_get_blk_desc(mmc
)->hwpart
);
439 return CMD_RET_SUCCESS
;
441 static int do_mmc_list(cmd_tbl_t
*cmdtp
, int flag
,
442 int argc
, char * const argv
[])
444 print_mmc_devices('\n');
445 return CMD_RET_SUCCESS
;
448 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
449 static int parse_hwpart_user(struct mmc_hwpart_conf
*pconf
,
450 int argc
, char * const argv
[])
454 memset(&pconf
->user
, 0, sizeof(pconf
->user
));
457 if (!strcmp(argv
[i
], "enh")) {
460 pconf
->user
.enh_start
=
461 simple_strtoul(argv
[i
+1], NULL
, 10);
462 pconf
->user
.enh_size
=
463 simple_strtoul(argv
[i
+2], NULL
, 10);
465 } else if (!strcmp(argv
[i
], "wrrel")) {
468 pconf
->user
.wr_rel_change
= 1;
469 if (!strcmp(argv
[i
+1], "on"))
470 pconf
->user
.wr_rel_set
= 1;
471 else if (!strcmp(argv
[i
+1], "off"))
472 pconf
->user
.wr_rel_set
= 0;
483 static int parse_hwpart_gp(struct mmc_hwpart_conf
*pconf
, int pidx
,
484 int argc
, char * const argv
[])
488 memset(&pconf
->gp_part
[pidx
], 0, sizeof(pconf
->gp_part
[pidx
]));
492 pconf
->gp_part
[pidx
].size
= simple_strtoul(argv
[0], NULL
, 10);
496 if (!strcmp(argv
[i
], "enh")) {
497 pconf
->gp_part
[pidx
].enhanced
= 1;
499 } else if (!strcmp(argv
[i
], "wrrel")) {
502 pconf
->gp_part
[pidx
].wr_rel_change
= 1;
503 if (!strcmp(argv
[i
+1], "on"))
504 pconf
->gp_part
[pidx
].wr_rel_set
= 1;
505 else if (!strcmp(argv
[i
+1], "off"))
506 pconf
->gp_part
[pidx
].wr_rel_set
= 0;
517 static int do_mmc_hwpartition(cmd_tbl_t
*cmdtp
, int flag
,
518 int argc
, char * const argv
[])
521 struct mmc_hwpart_conf pconf
= { };
522 enum mmc_hwpart_conf_mode mode
= MMC_HWPART_CONF_CHECK
;
525 mmc
= init_mmc_device(curr_device
, false);
527 return CMD_RET_FAILURE
;
530 return CMD_RET_USAGE
;
533 if (!strcmp(argv
[i
], "user")) {
535 r
= parse_hwpart_user(&pconf
, argc
-i
, &argv
[i
]);
537 return CMD_RET_USAGE
;
539 } else if (!strncmp(argv
[i
], "gp", 2) &&
540 strlen(argv
[i
]) == 3 &&
541 argv
[i
][2] >= '1' && argv
[i
][2] <= '4') {
542 pidx
= argv
[i
][2] - '1';
544 r
= parse_hwpart_gp(&pconf
, pidx
, argc
-i
, &argv
[i
]);
546 return CMD_RET_USAGE
;
548 } else if (!strcmp(argv
[i
], "check")) {
549 mode
= MMC_HWPART_CONF_CHECK
;
551 } else if (!strcmp(argv
[i
], "set")) {
552 mode
= MMC_HWPART_CONF_SET
;
554 } else if (!strcmp(argv
[i
], "complete")) {
555 mode
= MMC_HWPART_CONF_COMPLETE
;
558 return CMD_RET_USAGE
;
562 puts("Partition configuration:\n");
563 if (pconf
.user
.enh_size
) {
564 puts("\tUser Enhanced Start: ");
565 print_size(((u64
)pconf
.user
.enh_start
) << 9, "\n");
566 puts("\tUser Enhanced Size: ");
567 print_size(((u64
)pconf
.user
.enh_size
) << 9, "\n");
569 puts("\tNo enhanced user data area\n");
571 if (pconf
.user
.wr_rel_change
)
572 printf("\tUser partition write reliability: %s\n",
573 pconf
.user
.wr_rel_set
? "on" : "off");
574 for (pidx
= 0; pidx
< 4; pidx
++) {
575 if (pconf
.gp_part
[pidx
].size
) {
576 printf("\tGP%i Capacity: ", pidx
+1);
577 print_size(((u64
)pconf
.gp_part
[pidx
].size
) << 9,
578 pconf
.gp_part
[pidx
].enhanced
?
581 printf("\tNo GP%i partition\n", pidx
+1);
583 if (pconf
.gp_part
[pidx
].wr_rel_change
)
584 printf("\tGP%i write reliability: %s\n", pidx
+1,
585 pconf
.gp_part
[pidx
].wr_rel_set
? "on" : "off");
588 if (!mmc_hwpart_config(mmc
, &pconf
, mode
)) {
589 if (mode
== MMC_HWPART_CONF_COMPLETE
)
590 puts("Partitioning successful, "
591 "power-cycle to make effective\n");
592 return CMD_RET_SUCCESS
;
595 return CMD_RET_FAILURE
;
600 #ifdef CONFIG_SUPPORT_EMMC_BOOT
601 static int do_mmc_bootbus(cmd_tbl_t
*cmdtp
, int flag
,
602 int argc
, char * const argv
[])
606 u8 width
, reset
, mode
;
609 return CMD_RET_USAGE
;
610 dev
= simple_strtoul(argv
[1], NULL
, 10);
611 width
= simple_strtoul(argv
[2], NULL
, 10);
612 reset
= simple_strtoul(argv
[3], NULL
, 10);
613 mode
= simple_strtoul(argv
[4], NULL
, 10);
615 mmc
= init_mmc_device(dev
, false);
617 return CMD_RET_FAILURE
;
620 puts("BOOT_BUS_WIDTH only exists on eMMC\n");
621 return CMD_RET_FAILURE
;
624 /* acknowledge to be sent during boot operation */
625 return mmc_set_boot_bus_width(mmc
, width
, reset
, mode
);
627 static int do_mmc_boot_resize(cmd_tbl_t
*cmdtp
, int flag
,
628 int argc
, char * const argv
[])
632 u32 bootsize
, rpmbsize
;
635 return CMD_RET_USAGE
;
636 dev
= simple_strtoul(argv
[1], NULL
, 10);
637 bootsize
= simple_strtoul(argv
[2], NULL
, 10);
638 rpmbsize
= simple_strtoul(argv
[3], NULL
, 10);
640 mmc
= init_mmc_device(dev
, false);
642 return CMD_RET_FAILURE
;
645 printf("It is not a EMMC device\n");
646 return CMD_RET_FAILURE
;
649 if (mmc_boot_partition_size_change(mmc
, bootsize
, rpmbsize
)) {
650 printf("EMMC boot partition Size change Failed.\n");
651 return CMD_RET_FAILURE
;
654 printf("EMMC boot partition Size %d MB\n", bootsize
);
655 printf("EMMC RPMB partition Size %d MB\n", rpmbsize
);
656 return CMD_RET_SUCCESS
;
659 static int mmc_partconf_print(struct mmc
*mmc
)
661 u8 ack
, access
, part
;
663 if (mmc
->part_config
== MMCPART_NOAVAILABLE
) {
664 printf("No part_config info for ver. 0x%x\n", mmc
->version
);
665 return CMD_RET_FAILURE
;
668 access
= EXT_CSD_EXTRACT_PARTITION_ACCESS(mmc
->part_config
);
669 ack
= EXT_CSD_EXTRACT_BOOT_ACK(mmc
->part_config
);
670 part
= EXT_CSD_EXTRACT_BOOT_PART(mmc
->part_config
);
672 printf("EXT_CSD[179], PARTITION_CONFIG:\n"
674 "BOOT_PARTITION_ENABLE: 0x%x\n"
675 "PARTITION_ACCESS: 0x%x\n", ack
, part
, access
);
677 return CMD_RET_SUCCESS
;
680 static int do_mmc_partconf(cmd_tbl_t
*cmdtp
, int flag
,
681 int argc
, char * const argv
[])
685 u8 ack
, part_num
, access
;
687 if (argc
!= 2 && argc
!= 5)
688 return CMD_RET_USAGE
;
690 dev
= simple_strtoul(argv
[1], NULL
, 10);
692 mmc
= init_mmc_device(dev
, false);
694 return CMD_RET_FAILURE
;
697 puts("PARTITION_CONFIG only exists on eMMC\n");
698 return CMD_RET_FAILURE
;
702 return mmc_partconf_print(mmc
);
704 ack
= simple_strtoul(argv
[2], NULL
, 10);
705 part_num
= simple_strtoul(argv
[3], NULL
, 10);
706 access
= simple_strtoul(argv
[4], NULL
, 10);
708 /* acknowledge to be sent during boot operation */
709 return mmc_set_part_conf(mmc
, ack
, part_num
, access
);
711 static int do_mmc_rst_func(cmd_tbl_t
*cmdtp
, int flag
,
712 int argc
, char * const argv
[])
719 * Set the RST_n_ENABLE bit of RST_n_FUNCTION
720 * The only valid values are 0x0, 0x1 and 0x2 and writing
721 * a value of 0x1 or 0x2 sets the value permanently.
724 return CMD_RET_USAGE
;
726 dev
= simple_strtoul(argv
[1], NULL
, 10);
727 enable
= simple_strtoul(argv
[2], NULL
, 10);
730 puts("Invalid RST_n_ENABLE value\n");
731 return CMD_RET_USAGE
;
734 mmc
= init_mmc_device(dev
, false);
736 return CMD_RET_FAILURE
;
739 puts("RST_n_FUNCTION only exists on eMMC\n");
740 return CMD_RET_FAILURE
;
743 return mmc_set_rst_n_function(mmc
, enable
);
746 static int do_mmc_setdsr(cmd_tbl_t
*cmdtp
, int flag
,
747 int argc
, char * const argv
[])
754 return CMD_RET_USAGE
;
755 val
= simple_strtoul(argv
[1], NULL
, 16);
757 mmc
= find_mmc_device(curr_device
);
759 printf("no mmc device at slot %x\n", curr_device
);
760 return CMD_RET_FAILURE
;
762 ret
= mmc_set_dsr(mmc
, val
);
763 printf("set dsr %s\n", (!ret
) ? "OK, force rescan" : "ERROR");
767 return CMD_RET_FAILURE
;
769 return CMD_RET_SUCCESS
;
774 #ifdef CONFIG_CMD_BKOPS_ENABLE
775 static int do_mmc_bkops_enable(cmd_tbl_t
*cmdtp
, int flag
,
776 int argc
, char * const argv
[])
782 return CMD_RET_USAGE
;
784 dev
= simple_strtoul(argv
[1], NULL
, 10);
786 mmc
= init_mmc_device(dev
, false);
788 return CMD_RET_FAILURE
;
791 puts("BKOPS_EN only exists on eMMC\n");
792 return CMD_RET_FAILURE
;
795 return mmc_set_bkops_enable(mmc
);
799 static cmd_tbl_t cmd_mmc
[] = {
800 U_BOOT_CMD_MKENT(info
, 1, 0, do_mmcinfo
, "", ""),
801 U_BOOT_CMD_MKENT(read
, 4, 1, do_mmc_read
, "", ""),
802 #if CONFIG_IS_ENABLED(MMC_WRITE)
803 U_BOOT_CMD_MKENT(write
, 4, 0, do_mmc_write
, "", ""),
804 U_BOOT_CMD_MKENT(erase
, 3, 0, do_mmc_erase
, "", ""),
806 U_BOOT_CMD_MKENT(rescan
, 1, 1, do_mmc_rescan
, "", ""),
807 U_BOOT_CMD_MKENT(part
, 1, 1, do_mmc_part
, "", ""),
808 U_BOOT_CMD_MKENT(dev
, 3, 0, do_mmc_dev
, "", ""),
809 U_BOOT_CMD_MKENT(list
, 1, 1, do_mmc_list
, "", ""),
810 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
811 U_BOOT_CMD_MKENT(hwpartition
, 28, 0, do_mmc_hwpartition
, "", ""),
813 #ifdef CONFIG_SUPPORT_EMMC_BOOT
814 U_BOOT_CMD_MKENT(bootbus
, 5, 0, do_mmc_bootbus
, "", ""),
815 U_BOOT_CMD_MKENT(bootpart
-resize
, 4, 0, do_mmc_boot_resize
, "", ""),
816 U_BOOT_CMD_MKENT(partconf
, 5, 0, do_mmc_partconf
, "", ""),
817 U_BOOT_CMD_MKENT(rst
-function
, 3, 0, do_mmc_rst_func
, "", ""),
819 #ifdef CONFIG_SUPPORT_EMMC_RPMB
820 U_BOOT_CMD_MKENT(rpmb
, CONFIG_SYS_MAXARGS
, 1, do_mmcrpmb
, "", ""),
822 U_BOOT_CMD_MKENT(setdsr
, 2, 0, do_mmc_setdsr
, "", ""),
823 #ifdef CONFIG_CMD_BKOPS_ENABLE
824 U_BOOT_CMD_MKENT(bkops
-enable
, 2, 0, do_mmc_bkops_enable
, "", ""),
828 static int do_mmcops(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
832 cp
= find_cmd_tbl(argv
[1], cmd_mmc
, ARRAY_SIZE(cmd_mmc
));
834 /* Drop the mmc command */
838 if (cp
== NULL
|| argc
> cp
->maxargs
)
839 return CMD_RET_USAGE
;
840 if (flag
== CMD_FLAG_REPEAT
&& !cp
->repeatable
)
841 return CMD_RET_SUCCESS
;
843 if (curr_device
< 0) {
844 if (get_mmc_num() > 0) {
847 puts("No MMC device available\n");
848 return CMD_RET_FAILURE
;
851 return cp
->cmd(cmdtp
, flag
, argc
, argv
);
855 mmc
, 29, 1, do_mmcops
,
857 "info - display info of the current MMC device\n"
858 "mmc read addr blk# cnt\n"
859 "mmc write addr blk# cnt\n"
860 "mmc erase blk# cnt\n"
862 "mmc part - lists available partition on current mmc device\n"
863 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
864 "mmc list - lists available devices\n"
865 "mmc hwpartition [args...] - does hardware partitioning\n"
866 " arguments (sizes in 512-byte blocks):\n"
867 " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n"
868 " [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n"
869 " [check|set|complete] - mode, complete set partitioning completed\n"
870 " WARNING: Partitioning is a write-once setting once it is set to complete.\n"
871 " Power cycling is required to initialize partitions after set to complete.\n"
872 #ifdef CONFIG_SUPPORT_EMMC_BOOT
873 "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
874 " - Set the BOOT_BUS_WIDTH field of the specified device\n"
875 "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
876 " - Change sizes of boot and RPMB partitions of specified device\n"
877 "mmc partconf dev [boot_ack boot_partition partition_access]\n"
878 " - Show or change the bits of the PARTITION_CONFIG field of the specified device\n"
879 "mmc rst-function dev value\n"
880 " - Change the RST_n_FUNCTION field of the specified device\n"
881 " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
883 #ifdef CONFIG_SUPPORT_EMMC_RPMB
884 "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
885 "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
886 "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
887 "mmc rpmb counter - read the value of the write counter\n"
889 "mmc setdsr <value> - set DSR register value\n"
890 #ifdef CONFIG_CMD_BKOPS_ENABLE
891 "mmc bkops-enable <dev> - enable background operations handshake on device\n"
892 " WARNING: This is a write-once setting.\n"
896 /* Old command kept for compatibility. Same as 'mmc info' */
898 mmcinfo
, 1, 0, do_mmcinfo
,
900 "- display info of the current MMC device"