]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_mmc.c
3 * Kyle Harris, kharris@nexus-tech.net
5 * SPDX-License-Identifier: GPL-2.0+
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
[])
21 if (strcmp(argv
[1], "init") == 0) {
27 } else if (argc
== 3) {
28 dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
33 if (mmc_legacy_init(dev
) != 0) {
34 puts("No MMC card found\n");
39 printf("mmc%d is available\n", curr_device
);
40 } else if (strcmp(argv
[1], "device") == 0) {
42 if (curr_device
< 0) {
43 puts("No MMC device available\n");
46 } else if (argc
== 3) {
47 dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
49 #ifdef CONFIG_SYS_MMC_SET_DEV
50 if (mmc_set_dev(dev
) != 0)
58 printf("mmc%d is current device\n", curr_device
);
69 "init [dev] - init MMC sub system\n"
70 "mmc device [dev] - show or set current device"
72 #else /* !CONFIG_GENERIC_MMC */
80 static void print_mmcinfo(struct mmc
*mmc
)
82 printf("Device: %s\n", mmc
->name
);
83 printf("Manufacturer ID: %x\n", mmc
->cid
[0] >> 24);
84 printf("OEM: %x\n", (mmc
->cid
[0] >> 8) & 0xffff);
85 printf("Name: %c%c%c%c%c \n", mmc
->cid
[0] & 0xff,
86 (mmc
->cid
[1] >> 24), (mmc
->cid
[1] >> 16) & 0xff,
87 (mmc
->cid
[1] >> 8) & 0xff, mmc
->cid
[1] & 0xff);
89 printf("Tran Speed: %d\n", mmc
->tran_speed
);
90 printf("Rd Block Len: %d\n", mmc
->read_bl_len
);
92 printf("%s version %d.%d\n", IS_SD(mmc
) ? "SD" : "MMC",
93 (mmc
->version
>> 8) & 0xf, mmc
->version
& 0xff);
95 printf("High Capacity: %s\n", mmc
->high_capacity
? "Yes" : "No");
97 print_size(mmc
->capacity
, "\n");
99 printf("Bus Width: %d-bit\n", mmc
->bus_width
);
102 static int do_mmcinfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
106 if (curr_device
< 0) {
107 if (get_mmc_num() > 0)
110 puts("No MMC device available\n");
115 mmc
= find_mmc_device(curr_device
);
123 printf("no mmc device at slot %x\n", curr_device
);
129 mmcinfo
, 1, 0, do_mmcinfo
,
131 "- display info of the current MMC device"
134 #ifdef CONFIG_SUPPORT_EMMC_BOOT
135 static int boot_part_access(struct mmc
*mmc
, u8 ack
, u8 part_num
, u8 access
)
138 err
= mmc_boot_part_access(mmc
, ack
, part_num
, access
);
140 if ((err
== 0) && (access
!= 0)) {
141 printf("\t\t\t!!!Notice!!!\n");
143 printf("!You must close EMMC boot Partition");
144 printf("after all images are written\n");
146 printf("!EMMC boot partition has continuity");
147 printf("at image writing time.\n");
149 printf("!So, do not close the boot partition");
150 printf("before all images are written.\n");
152 } else if ((err
== 0) && (access
== 0))
154 else if ((err
!= 0) && (access
!= 0)) {
155 printf("EMMC boot partition-%d OPEN Failed.\n", part_num
);
158 printf("EMMC boot partition-%d CLOSE Failed.\n", part_num
);
164 static int do_mmcops(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
166 enum mmc_state state
;
169 return CMD_RET_USAGE
;
171 if (curr_device
< 0) {
172 if (get_mmc_num() > 0)
175 puts("No MMC device available\n");
180 if (strcmp(argv
[1], "rescan") == 0) {
184 return CMD_RET_USAGE
;
186 mmc
= find_mmc_device(curr_device
);
188 printf("no mmc device at slot %x\n", curr_device
);
198 } else if (strncmp(argv
[1], "part", 4) == 0) {
199 block_dev_desc_t
*mmc_dev
;
203 return CMD_RET_USAGE
;
205 mmc
= find_mmc_device(curr_device
);
207 printf("no mmc device at slot %x\n", curr_device
);
211 mmc_dev
= mmc_get_dev(curr_device
);
212 if (mmc_dev
!= NULL
&&
213 mmc_dev
->type
!= DEV_TYPE_UNKNOWN
) {
218 puts("get mmc type error!\n");
220 } else if (strcmp(argv
[1], "list") == 0) {
222 return CMD_RET_USAGE
;
223 print_mmc_devices('\n');
225 } else if (strcmp(argv
[1], "dev") == 0) {
232 dev
= simple_strtoul(argv
[2], NULL
, 10);
233 else if (argc
== 4) {
234 dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
235 part
= (int)simple_strtoul(argv
[3], NULL
, 10);
236 if (part
> PART_ACCESS_MASK
) {
237 printf("#part_num shouldn't be larger"
238 " than %d\n", PART_ACCESS_MASK
);
242 return CMD_RET_USAGE
;
244 mmc
= find_mmc_device(dev
);
246 printf("no mmc device at slot %x\n", dev
);
253 if (mmc
->part_config
== MMCPART_NOAVAILABLE
) {
254 printf("Card doesn't support part_switch\n");
258 if (part
!= mmc
->part_num
) {
259 ret
= mmc_switch_part(dev
, part
);
261 mmc
->part_num
= part
;
263 printf("switch to partions #%d, %s\n",
264 part
, (!ret
) ? "OK" : "ERROR");
268 if (mmc
->part_config
== MMCPART_NOAVAILABLE
)
269 printf("mmc%d is current device\n", curr_device
);
271 printf("mmc%d(part %d) is current device\n",
272 curr_device
, mmc
->part_num
);
275 #ifdef CONFIG_SUPPORT_EMMC_BOOT
276 } else if ((strcmp(argv
[1], "open") == 0) ||
277 (strcmp(argv
[1], "close") == 0)) {
280 u8 part_num
, access
= 0;
283 dev
= simple_strtoul(argv
[2], NULL
, 10);
284 part_num
= simple_strtoul(argv
[3], NULL
, 10);
286 return CMD_RET_USAGE
;
289 mmc
= find_mmc_device(dev
);
291 printf("no mmc device at slot %x\n", dev
);
296 printf("SD device cannot be opened/closed\n");
300 if ((part_num
<= 0) || (part_num
> MMC_NUM_BOOT_PARTITION
)) {
301 printf("Invalid boot partition number:\n");
302 printf("Boot partition number cannot be <= 0\n");
303 printf("EMMC44 supports only 2 boot partitions\n");
307 if (strcmp(argv
[1], "open") == 0)
308 access
= part_num
; /* enable R/W access to boot part*/
310 access
= 0; /* No access to boot partition */
312 /* acknowledge to be sent during boot operation */
313 return boot_part_access(mmc
, 1, part_num
, access
);
315 } else if (strcmp(argv
[1], "bootpart") == 0) {
317 dev
= simple_strtoul(argv
[2], NULL
, 10);
319 u32 bootsize
= simple_strtoul(argv
[3], NULL
, 10);
320 u32 rpmbsize
= simple_strtoul(argv
[4], NULL
, 10);
321 struct mmc
*mmc
= find_mmc_device(dev
);
323 printf("no mmc device at slot %x\n", dev
);
328 printf("It is not a EMMC device\n");
332 if (0 == mmc_boot_partition_size_change(mmc
,
333 bootsize
, rpmbsize
)) {
334 printf("EMMC boot partition Size %d MB\n", bootsize
);
335 printf("EMMC RPMB partition Size %d MB\n", rpmbsize
);
338 printf("EMMC boot partition Size change Failed.\n");
341 #endif /* CONFIG_SUPPORT_EMMC_BOOT */
344 if (argc
== 5 && strcmp(argv
[1], "read") == 0)
346 else if (argc
== 5 && strcmp(argv
[1], "write") == 0)
348 else if (argc
== 4 && strcmp(argv
[1], "erase") == 0)
351 if (state
!= MMC_INVALID
) {
352 struct mmc
*mmc
= find_mmc_device(curr_device
);
357 if (state
!= MMC_ERASE
) {
358 addr
= (void *)simple_strtoul(argv
[idx
], NULL
, 16);
362 blk
= simple_strtoul(argv
[idx
], NULL
, 16);
363 cnt
= simple_strtoul(argv
[idx
+ 1], NULL
, 16);
366 printf("no mmc device at slot %x\n", curr_device
);
370 printf("\nMMC %s: dev # %d, block # %d, count %d ... ",
371 argv
[1], curr_device
, blk
, cnt
);
375 if ((state
== MMC_WRITE
|| state
== MMC_ERASE
)) {
376 if (mmc_getwp(mmc
) == 1) {
377 printf("Error: card is write protected!\n");
384 n
= mmc
->block_dev
.block_read(curr_device
, blk
,
386 /* flush cache after read */
387 flush_cache((ulong
)addr
, cnt
* 512); /* FIXME */
390 n
= mmc
->block_dev
.block_write(curr_device
, blk
,
394 n
= mmc
->block_dev
.block_erase(curr_device
, blk
, cnt
);
400 printf("%d blocks %s: %s\n",
401 n
, argv
[1], (n
== cnt
) ? "OK" : "ERROR");
402 return (n
== cnt
) ? 0 : 1;
405 return CMD_RET_USAGE
;
409 mmc
, 6, 1, do_mmcops
,
411 "read addr blk# cnt\n"
412 "mmc write addr blk# cnt\n"
413 "mmc erase blk# cnt\n"
415 "mmc part - lists available partition on current mmc device\n"
416 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
417 "mmc list - lists available devices\n"
418 #ifdef CONFIG_SUPPORT_EMMC_BOOT
419 "mmc open <dev> <boot_partition>\n"
420 " - Enable boot_part for booting and enable R/W access of boot_part\n"
421 "mmc close <dev> <boot_partition>\n"
422 " - Enable boot_part for booting and disable access to boot_part\n"
423 "mmc bootpart <device num> <boot part size MB> <RPMB part size MB>\n"
424 " - change sizes of boot and RPMB partions of specified device\n"
427 #endif /* !CONFIG_GENERIC_MMC */