]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_mmc.c
disk: default to HW partition 0 if not specified
[people/ms/u-boot.git] / common / cmd_mmc.c
CommitLineData
71f95118
WD
1/*
2 * (C) Copyright 2003
3 * Kyle Harris, kharris@nexus-tech.net
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
71f95118
WD
6 */
7
8#include <common.h>
9#include <command.h>
71f95118
WD
10#include <mmc.h>
11
02e22c2d 12static int curr_device = -1;
ea6ebe21 13#ifndef CONFIG_GENERIC_MMC
54841ab5 14int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118 15{
869f6bf4
MK
16 int dev;
17
47e26b1b 18 if (argc < 2)
4c12eeb8 19 return CMD_RET_USAGE;
869f6bf4
MK
20
21 if (strcmp(argv[1], "init") == 0) {
22 if (argc == 2) {
23 if (curr_device < 0)
24 dev = 1;
25 else
26 dev = curr_device;
27 } else if (argc == 3) {
28 dev = (int)simple_strtoul(argv[2], NULL, 10);
29 } else {
4c12eeb8 30 return CMD_RET_USAGE;
869f6bf4
MK
31 }
32
33 if (mmc_legacy_init(dev) != 0) {
34 puts("No MMC card found\n");
35 return 1;
36 }
37
38 curr_device = dev;
39 printf("mmc%d is available\n", curr_device);
40 } else if (strcmp(argv[1], "device") == 0) {
41 if (argc == 2) {
42 if (curr_device < 0) {
43 puts("No MMC device available\n");
44 return 1;
45 }
46 } else if (argc == 3) {
47 dev = (int)simple_strtoul(argv[2], NULL, 10);
48
49#ifdef CONFIG_SYS_MMC_SET_DEV
50 if (mmc_set_dev(dev) != 0)
51 return 1;
52#endif
53 curr_device = dev;
54 } else {
4c12eeb8 55 return CMD_RET_USAGE;
869f6bf4
MK
56 }
57
58 printf("mmc%d is current device\n", curr_device);
59 } else {
4c12eeb8 60 return CMD_RET_USAGE;
71f95118 61 }
869f6bf4 62
71f95118
WD
63 return 0;
64}
65
0d498393 66U_BOOT_CMD(
869f6bf4
MK
67 mmc, 3, 1, do_mmc,
68 "MMC sub-system",
69 "init [dev] - init MMC sub system\n"
a89c33db 70 "mmc device [dev] - show or set current device"
b0fce99b 71);
3511b4e2 72#else /* !CONFIG_GENERIC_MMC */
272cc70b
AF
73
74static void print_mmcinfo(struct mmc *mmc)
75{
93bfd616 76 printf("Device: %s\n", mmc->cfg->name);
272cc70b
AF
77 printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
78 printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
79 printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
80 (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
81 (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
82
83 printf("Tran Speed: %d\n", mmc->tran_speed);
84 printf("Rd Block Len: %d\n", mmc->read_bl_len);
85
86 printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
64f4a619 87 (mmc->version >> 8) & 0xf, mmc->version & 0xff);
272cc70b
AF
88
89 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
940e0782
MK
90 puts("Capacity: ");
91 print_size(mmc->capacity, "\n");
272cc70b
AF
92
93 printf("Bus Width: %d-bit\n", mmc->bus_width);
94}
1fd93c6e
PA
95static struct mmc *init_mmc_device(int dev)
96{
97 struct mmc *mmc;
98 mmc = find_mmc_device(dev);
99 if (!mmc) {
100 printf("no mmc device at slot %x\n", dev);
101 return NULL;
102 }
103 if (mmc_init(mmc))
104 return NULL;
105 return mmc;
106}
088f1b19 107static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
272cc70b
AF
108{
109 struct mmc *mmc;
272cc70b 110
ea6ebe21
LW
111 if (curr_device < 0) {
112 if (get_mmc_num() > 0)
113 curr_device = 0;
114 else {
115 puts("No MMC device available\n");
116 return 1;
117 }
118 }
272cc70b 119
1fd93c6e
PA
120 mmc = init_mmc_device(curr_device);
121 if (!mmc)
122 return CMD_RET_FAILURE;
272cc70b 123
1fd93c6e
PA
124 print_mmcinfo(mmc);
125 return CMD_RET_SUCCESS;
126}
272cc70b 127
1fd93c6e
PA
128#ifdef CONFIG_SUPPORT_EMMC_RPMB
129static int confirm_key_prog(void)
130{
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> ");
134 if (confirm_yesno())
ea6ebe21 135 return 1;
1fd93c6e
PA
136
137 puts("Authentication key programming aborted\n");
138 return 0;
139}
140static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
141 int argc, char * const argv[])
142{
143 void *key_addr;
144 struct mmc *mmc = find_mmc_device(curr_device);
145
146 if (argc != 2)
147 return CMD_RET_USAGE;
148
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;
272cc70b 155 }
1fd93c6e 156 return CMD_RET_SUCCESS;
272cc70b 157}
1fd93c6e
PA
158static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
159 int argc, char * const argv[])
160{
161 u16 blk, cnt;
162 void *addr;
163 int n;
164 void *key_addr = NULL;
165 struct mmc *mmc = find_mmc_device(curr_device);
272cc70b 166
1fd93c6e
PA
167 if (argc < 4)
168 return CMD_RET_USAGE;
272cc70b 169
1fd93c6e
PA
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);
173
174 if (argc == 5)
175 key_addr = (void *)simple_strtoul(argv[4], NULL, 16);
176
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);
180
181 printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
182 if (n != cnt)
183 return CMD_RET_FAILURE;
184 return CMD_RET_SUCCESS;
185}
186static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
187 int argc, char * const argv[])
272cc70b 188{
1fd93c6e
PA
189 u16 blk, cnt;
190 void *addr;
191 int n;
192 void *key_addr;
193 struct mmc *mmc = find_mmc_device(curr_device);
6be95ccf 194
1fd93c6e 195 if (argc != 5)
4c12eeb8 196 return CMD_RET_USAGE;
272cc70b 197
1fd93c6e
PA
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);
202
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);
206
207 printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
208 if (n != cnt)
209 return CMD_RET_FAILURE;
210 return CMD_RET_SUCCESS;
211}
212static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
213 int argc, char * const argv[])
214{
215 unsigned long counter;
216 struct mmc *mmc = find_mmc_device(curr_device);
217
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;
222}
223
224static 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, "", ""),
229};
230
231static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
232 int argc, char * const argv[])
233{
234 cmd_tbl_t *cp;
235 struct mmc *mmc;
236 char original_part;
237 int ret;
238
239 cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
240
241 /* Drop the rpmb subcommand */
242 argc--;
243 argv++;
244
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;
249
250 mmc = init_mmc_device(curr_device);
251 if (!mmc)
252 return CMD_RET_FAILURE;
253
254 if (!(mmc->version & MMC_VERSION_MMC)) {
255 printf("It is not a EMMC device\n");
256 return CMD_RET_FAILURE;
257 }
258 if (mmc->version < MMC_VERSION_4_41) {
259 printf("RPMB not supported before version 4.41\n");
260 return CMD_RET_FAILURE;
ea6ebe21 261 }
1fd93c6e
PA
262 /* Switch to the RPMB partition */
263 original_part = mmc->part_num;
264 if (mmc->part_num != MMC_PART_RPMB) {
265 if (mmc_switch_part(curr_device, MMC_PART_RPMB) != 0)
266 return CMD_RET_FAILURE;
267 mmc->part_num = MMC_PART_RPMB;
268 }
269 ret = cp->cmd(cmdtp, flag, argc, argv);
272cc70b 270
1fd93c6e
PA
271 /* Return to original partition */
272 if (mmc->part_num != original_part) {
273 if (mmc_switch_part(curr_device, original_part) != 0)
274 return CMD_RET_FAILURE;
275 mmc->part_num = original_part;
276 }
277 return ret;
278}
279#endif
9fd38372 280
1fd93c6e
PA
281static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
282 int argc, char * const argv[])
283{
284 struct mmc *mmc;
285 u32 blk, cnt, n;
286 void *addr;
e85649c7 287
1fd93c6e
PA
288 if (argc != 4)
289 return CMD_RET_USAGE;
ea6ebe21 290
1fd93c6e
PA
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);
272cc70b 294
1fd93c6e
PA
295 mmc = init_mmc_device(curr_device);
296 if (!mmc)
297 return CMD_RET_FAILURE;
ea6ebe21 298
1fd93c6e
PA
299 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
300 curr_device, blk, cnt);
9fd38372 301
1fd93c6e
PA
302 n = mmc->block_dev.block_read(curr_device, blk, cnt, addr);
303 /* flush cache after read */
304 flush_cache((ulong)addr, cnt * 512); /* FIXME */
305 printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
8f3b9642 306
1fd93c6e
PA
307 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
308}
309static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
310 int argc, char * const argv[])
311{
312 struct mmc *mmc;
313 u32 blk, cnt, n;
314 void *addr;
8f3b9642 315
1fd93c6e
PA
316 if (argc != 4)
317 return CMD_RET_USAGE;
272cc70b 318
1fd93c6e
PA
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);
bc897b1d 322
1fd93c6e
PA
323 mmc = init_mmc_device(curr_device);
324 if (!mmc)
325 return CMD_RET_FAILURE;
bc897b1d 326
1fd93c6e
PA
327 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
328 curr_device, blk, cnt);
272cc70b 329
1fd93c6e
PA
330 if (mmc_getwp(mmc) == 1) {
331 printf("Error: card is write protected!\n");
332 return CMD_RET_FAILURE;
333 }
334 n = mmc->block_dev.block_write(curr_device, blk, cnt, addr);
335 printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
792970b0 336
1fd93c6e
PA
337 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
338}
339static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
340 int argc, char * const argv[])
341{
342 struct mmc *mmc;
343 u32 blk, cnt, n;
2a91c913 344
1fd93c6e
PA
345 if (argc != 3)
346 return CMD_RET_USAGE;
792970b0 347
1fd93c6e
PA
348 blk = simple_strtoul(argv[1], NULL, 16);
349 cnt = simple_strtoul(argv[2], NULL, 16);
5a99b9de 350
1fd93c6e
PA
351 mmc = init_mmc_device(curr_device);
352 if (!mmc)
353 return CMD_RET_FAILURE;
5a99b9de 354
1fd93c6e
PA
355 printf("\nMMC erase: dev # %d, block # %d, count %d ... ",
356 curr_device, blk, cnt);
5a99b9de 357
1fd93c6e
PA
358 if (mmc_getwp(mmc) == 1) {
359 printf("Error: card is write protected!\n");
360 return CMD_RET_FAILURE;
361 }
362 n = mmc->block_dev.block_erase(curr_device, blk, cnt);
363 printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
b01e6fe6 364
1fd93c6e
PA
365 return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
366}
367static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
368 int argc, char * const argv[])
369{
370 struct mmc *mmc;
2a91c913 371
1fd93c6e
PA
372 mmc = find_mmc_device(curr_device);
373 if (!mmc) {
374 printf("no mmc device at slot %x\n", curr_device);
375 return CMD_RET_FAILURE;
376 }
2a91c913 377
1fd93c6e 378 mmc->has_init = 0;
33ace362 379
1fd93c6e
PA
380 if (mmc_init(mmc))
381 return CMD_RET_FAILURE;
382 return CMD_RET_SUCCESS;
383}
384static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
385 int argc, char * const argv[])
386{
387 block_dev_desc_t *mmc_dev;
388 struct mmc *mmc;
389
390 mmc = init_mmc_device(curr_device);
391 if (!mmc)
392 return CMD_RET_FAILURE;
393
394 mmc_dev = mmc_get_dev(curr_device);
395 if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
396 print_part(mmc_dev);
397 return CMD_RET_SUCCESS;
398 }
399
400 puts("get mmc type error!\n");
401 return CMD_RET_FAILURE;
402}
403static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
404 int argc, char * const argv[])
405{
60dc58f7 406 int dev, part = 0, ret;
1fd93c6e
PA
407 struct mmc *mmc;
408
409 if (argc == 1) {
410 dev = curr_device;
411 } else if (argc == 2) {
412 dev = simple_strtoul(argv[1], NULL, 10);
413 } else if (argc == 3) {
414 dev = (int)simple_strtoul(argv[1], NULL, 10);
415 part = (int)simple_strtoul(argv[2], NULL, 10);
416 if (part > PART_ACCESS_MASK) {
417 printf("#part_num shouldn't be larger than %d\n",
418 PART_ACCESS_MASK);
419 return CMD_RET_FAILURE;
33ace362 420 }
1fd93c6e
PA
421 } else {
422 return CMD_RET_USAGE;
423 }
33ace362 424
1fd93c6e
PA
425 mmc = init_mmc_device(dev);
426 if (!mmc)
427 return CMD_RET_FAILURE;
428
60dc58f7
SW
429 ret = mmc_select_hwpart(dev, part);
430 printf("switch to partitions #%d, %s\n",
431 part, (!ret) ? "OK" : "ERROR");
432 if (ret)
433 return 1;
434
1fd93c6e
PA
435 curr_device = dev;
436 if (mmc->part_config == MMCPART_NOAVAILABLE)
437 printf("mmc%d is current device\n", curr_device);
438 else
439 printf("mmc%d(part %d) is current device\n",
440 curr_device, mmc->part_num);
33ace362 441
1fd93c6e
PA
442 return CMD_RET_SUCCESS;
443}
444static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
445 int argc, char * const argv[])
446{
447 print_mmc_devices('\n');
448 return CMD_RET_SUCCESS;
449}
450#ifdef CONFIG_SUPPORT_EMMC_BOOT
451static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
452 int argc, char * const argv[])
453{
454 int dev;
455 struct mmc *mmc;
456 u8 width, reset, mode;
457
458 if (argc != 5)
459 return CMD_RET_USAGE;
460 dev = simple_strtoul(argv[1], NULL, 10);
461 width = simple_strtoul(argv[2], NULL, 10);
462 reset = simple_strtoul(argv[3], NULL, 10);
463 mode = simple_strtoul(argv[4], NULL, 10);
464
465 mmc = init_mmc_device(dev);
466 if (!mmc)
467 return CMD_RET_FAILURE;
468
469 if (IS_SD(mmc)) {
470 puts("BOOT_BUS_WIDTH only exists on eMMC\n");
471 return CMD_RET_FAILURE;
2a91c913 472 }
ab71188c 473
1fd93c6e
PA
474 /* acknowledge to be sent during boot operation */
475 return mmc_set_boot_bus_width(mmc, width, reset, mode);
476}
477static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
478 int argc, char * const argv[])
479{
480 int dev;
481 struct mmc *mmc;
482 u32 bootsize, rpmbsize;
ab71188c 483
1fd93c6e
PA
484 if (argc != 4)
485 return CMD_RET_USAGE;
486 dev = simple_strtoul(argv[1], NULL, 10);
487 bootsize = simple_strtoul(argv[2], NULL, 10);
488 rpmbsize = simple_strtoul(argv[3], NULL, 10);
489
490 mmc = init_mmc_device(dev);
491 if (!mmc)
492 return CMD_RET_FAILURE;
493
494 if (IS_SD(mmc)) {
495 printf("It is not a EMMC device\n");
496 return CMD_RET_FAILURE;
ab71188c
MN
497 }
498
1fd93c6e
PA
499 if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) {
500 printf("EMMC boot partition Size change Failed.\n");
501 return CMD_RET_FAILURE;
502 }
e85649c7 503
1fd93c6e
PA
504 printf("EMMC boot partition Size %d MB\n", bootsize);
505 printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
506 return CMD_RET_SUCCESS;
507}
508static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
509 int argc, char * const argv[])
510{
511 int dev;
512 struct mmc *mmc;
513 u8 ack, part_num, access;
272cc70b 514
1fd93c6e
PA
515 if (argc != 5)
516 return CMD_RET_USAGE;
272cc70b 517
1fd93c6e
PA
518 dev = simple_strtoul(argv[1], NULL, 10);
519 ack = simple_strtoul(argv[2], NULL, 10);
520 part_num = simple_strtoul(argv[3], NULL, 10);
521 access = simple_strtoul(argv[4], NULL, 10);
d23d8d7e 522
1fd93c6e
PA
523 mmc = init_mmc_device(dev);
524 if (!mmc)
525 return CMD_RET_FAILURE;
526
527 if (IS_SD(mmc)) {
528 puts("PARTITION_CONFIG only exists on eMMC\n");
529 return CMD_RET_FAILURE;
530 }
531
532 /* acknowledge to be sent during boot operation */
533 return mmc_set_part_conf(mmc, ack, part_num, access);
534}
535static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
536 int argc, char * const argv[])
537{
538 int dev;
539 struct mmc *mmc;
540 u8 enable;
541
542 /*
543 * Set the RST_n_ENABLE bit of RST_n_FUNCTION
544 * The only valid values are 0x0, 0x1 and 0x2 and writing
545 * a value of 0x1 or 0x2 sets the value permanently.
546 */
547 if (argc != 3)
548 return CMD_RET_USAGE;
549
550 dev = simple_strtoul(argv[1], NULL, 10);
551 enable = simple_strtoul(argv[2], NULL, 10);
552
553 if (enable > 2 || enable < 0) {
554 puts("Invalid RST_n_ENABLE value\n");
555 return CMD_RET_USAGE;
556 }
557
558 mmc = init_mmc_device(dev);
559 if (!mmc)
560 return CMD_RET_FAILURE;
561
562 if (IS_SD(mmc)) {
563 puts("RST_n_FUNCTION only exists on eMMC\n");
564 return CMD_RET_FAILURE;
565 }
272cc70b 566
1fd93c6e
PA
567 return mmc_set_rst_n_function(mmc, enable);
568}
569#endif
570static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
571 int argc, char * const argv[])
572{
573 struct mmc *mmc;
574 u32 val;
575 int ret;
576
577 if (argc != 2)
578 return CMD_RET_USAGE;
579 val = simple_strtoul(argv[2], NULL, 16);
580
581 mmc = find_mmc_device(curr_device);
582 if (!mmc) {
583 printf("no mmc device at slot %x\n", curr_device);
584 return CMD_RET_FAILURE;
585 }
586 ret = mmc_set_dsr(mmc, val);
587 printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR");
588 if (!ret) {
589 mmc->has_init = 0;
590 if (mmc_init(mmc))
591 return CMD_RET_FAILURE;
592 else
593 return CMD_RET_SUCCESS;
272cc70b 594 }
1fd93c6e
PA
595 return ret;
596}
597
598static cmd_tbl_t cmd_mmc[] = {
599 U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
600 U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
601 U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
602 U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
603 U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
604 U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
605 U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""),
606 U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""),
607#ifdef CONFIG_SUPPORT_EMMC_BOOT
608 U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
609 U_BOOT_CMD_MKENT(bootpart-resize, 3, 0, do_mmc_boot_resize, "", ""),
610 U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
611 U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
612#endif
613#ifdef CONFIG_SUPPORT_EMMC_RPMB
614 U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""),
615#endif
616 U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
617};
618
619static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
620{
621 cmd_tbl_t *cp;
622
623 cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
624
625 /* Drop the mmc command */
626 argc--;
627 argv++;
628
629 if (cp == NULL || argc > cp->maxargs)
630 return CMD_RET_USAGE;
631 if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
632 return CMD_RET_SUCCESS;
ea6ebe21 633
1fd93c6e
PA
634 if (curr_device < 0) {
635 if (get_mmc_num() > 0) {
636 curr_device = 0;
637 } else {
638 puts("No MMC device available\n");
639 return CMD_RET_FAILURE;
640 }
641 }
642 return cp->cmd(cmdtp, flag, argc, argv);
272cc70b
AF
643}
644
645U_BOOT_CMD(
1fd93c6e 646 mmc, 7, 1, do_mmcops,
852dbfdd 647 "MMC sub system",
1fd93c6e
PA
648 "info - display info of the current MMC device\n"
649 "mmc read addr blk# cnt\n"
ea6ebe21 650 "mmc write addr blk# cnt\n"
e6f99a56 651 "mmc erase blk# cnt\n"
ea6ebe21
LW
652 "mmc rescan\n"
653 "mmc part - lists available partition on current mmc device\n"
bc897b1d 654 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
2a91c913
A
655 "mmc list - lists available devices\n"
656#ifdef CONFIG_SUPPORT_EMMC_BOOT
5a99b9de
TR
657 "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
658 " - Set the BOOT_BUS_WIDTH field of the specified device\n"
f1fd957e
TR
659 "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
660 " - Change sizes of boot and RPMB partitions of specified device\n"
792970b0
TR
661 "mmc partconf dev boot_ack boot_partition partition_access\n"
662 " - Change the bits of the PARTITION_CONFIG field of the specified device\n"
33ace362
TR
663 "mmc rst-function dev value\n"
664 " - Change the RST_n_FUNCTION field of the specified device\n"
665 " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n"
3511b4e2 666#endif
1fd93c6e
PA
667#ifdef CONFIG_SUPPORT_EMMC_RPMB
668 "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n"
669 "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n"
670 "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n"
671 "mmc rpmb counter - read the value of the write counter\n"
672#endif
673 "mmc setdsr <value> - set DSR register value\n"
2a91c913 674 );
1fd93c6e
PA
675
676/* Old command kept for compatibility. Same as 'mmc info' */
677U_BOOT_CMD(
678 mmcinfo, 1, 0, do_mmcinfo,
679 "display MMC info",
680 "- display info of the current MMC device"
681);
682
2a91c913 683#endif /* !CONFIG_GENERIC_MMC */