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