]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_mmc.c
3 * Kyle Harris, kharris@nexus-tech.net
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 static int curr_device
= -1;
29 #ifndef CONFIG_GENERIC_MMC
30 int do_mmc (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
37 if (strcmp(argv
[1], "init") == 0) {
43 } else if (argc
== 3) {
44 dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
49 if (mmc_legacy_init(dev
) != 0) {
50 puts("No MMC card found\n");
55 printf("mmc%d is available\n", curr_device
);
56 } else if (strcmp(argv
[1], "device") == 0) {
58 if (curr_device
< 0) {
59 puts("No MMC device available\n");
62 } else if (argc
== 3) {
63 dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
65 #ifdef CONFIG_SYS_MMC_SET_DEV
66 if (mmc_set_dev(dev
) != 0)
74 printf("mmc%d is current device\n", curr_device
);
85 "init [dev] - init MMC sub system\n"
86 "mmc device [dev] - show or set current device"
88 #else /* !CONFIG_GENERIC_MMC */
96 static void print_mmcinfo(struct mmc
*mmc
)
98 printf("Device: %s\n", mmc
->name
);
99 printf("Manufacturer ID: %x\n", mmc
->cid
[0] >> 24);
100 printf("OEM: %x\n", (mmc
->cid
[0] >> 8) & 0xffff);
101 printf("Name: %c%c%c%c%c \n", mmc
->cid
[0] & 0xff,
102 (mmc
->cid
[1] >> 24), (mmc
->cid
[1] >> 16) & 0xff,
103 (mmc
->cid
[1] >> 8) & 0xff, mmc
->cid
[1] & 0xff);
105 printf("Tran Speed: %d\n", mmc
->tran_speed
);
106 printf("Rd Block Len: %d\n", mmc
->read_bl_len
);
108 printf("%s version %d.%d\n", IS_SD(mmc
) ? "SD" : "MMC",
109 (mmc
->version
>> 8) & 0xf, mmc
->version
& 0xff);
111 printf("High Capacity: %s\n", mmc
->high_capacity
? "Yes" : "No");
113 print_size(mmc
->capacity
, "\n");
115 printf("Bus Width: %d-bit\n", mmc
->bus_width
);
118 static int do_mmcinfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
122 if (curr_device
< 0) {
123 if (get_mmc_num() > 0)
126 puts("No MMC device available\n");
131 mmc
= find_mmc_device(curr_device
);
139 printf("no mmc device at slot %x\n", curr_device
);
145 mmcinfo
, 1, 0, do_mmcinfo
,
147 "- display info of the current MMC device"
150 #ifdef CONFIG_SUPPORT_EMMC_BOOT
151 static int boot_part_access(struct mmc
*mmc
, u8 ack
, u8 part_num
, u8 access
)
154 err
= mmc_boot_part_access(mmc
, ack
, part_num
, access
);
156 if ((err
== 0) && (access
!= 0)) {
157 printf("\t\t\t!!!Notice!!!\n");
159 printf("!You must close EMMC boot Partition");
160 printf("after all images are written\n");
162 printf("!EMMC boot partition has continuity");
163 printf("at image writing time.\n");
165 printf("!So, do not close the boot partition");
166 printf("before all images are written.\n");
168 } else if ((err
== 0) && (access
== 0))
170 else if ((err
!= 0) && (access
!= 0)) {
171 printf("EMMC boot partition-%d OPEN Failed.\n", part_num
);
174 printf("EMMC boot partition-%d CLOSE Failed.\n", part_num
);
180 static int do_mmcops(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
182 enum mmc_state state
;
185 return CMD_RET_USAGE
;
187 if (curr_device
< 0) {
188 if (get_mmc_num() > 0)
191 puts("No MMC device available\n");
196 if (strcmp(argv
[1], "rescan") == 0) {
200 return CMD_RET_USAGE
;
202 mmc
= find_mmc_device(curr_device
);
204 printf("no mmc device at slot %x\n", curr_device
);
214 } else if (strncmp(argv
[1], "part", 4) == 0) {
215 block_dev_desc_t
*mmc_dev
;
219 return CMD_RET_USAGE
;
221 mmc
= find_mmc_device(curr_device
);
223 printf("no mmc device at slot %x\n", curr_device
);
227 mmc_dev
= mmc_get_dev(curr_device
);
228 if (mmc_dev
!= NULL
&&
229 mmc_dev
->type
!= DEV_TYPE_UNKNOWN
) {
234 puts("get mmc type error!\n");
236 } else if (strcmp(argv
[1], "list") == 0) {
238 return CMD_RET_USAGE
;
239 print_mmc_devices('\n');
241 } else if (strcmp(argv
[1], "dev") == 0) {
248 dev
= simple_strtoul(argv
[2], NULL
, 10);
249 else if (argc
== 4) {
250 dev
= (int)simple_strtoul(argv
[2], NULL
, 10);
251 part
= (int)simple_strtoul(argv
[3], NULL
, 10);
252 if (part
> PART_ACCESS_MASK
) {
253 printf("#part_num shouldn't be larger"
254 " than %d\n", PART_ACCESS_MASK
);
258 return CMD_RET_USAGE
;
260 mmc
= find_mmc_device(dev
);
262 printf("no mmc device at slot %x\n", dev
);
269 if (mmc
->part_config
== MMCPART_NOAVAILABLE
) {
270 printf("Card doesn't support part_switch\n");
274 if (part
!= mmc
->part_num
) {
275 ret
= mmc_switch_part(dev
, part
);
277 mmc
->part_num
= part
;
279 printf("switch to partions #%d, %s\n",
280 part
, (!ret
) ? "OK" : "ERROR");
284 if (mmc
->part_config
== MMCPART_NOAVAILABLE
)
285 printf("mmc%d is current device\n", curr_device
);
287 printf("mmc%d(part %d) is current device\n",
288 curr_device
, mmc
->part_num
);
291 #ifdef CONFIG_SUPPORT_EMMC_BOOT
292 } else if ((strcmp(argv
[1], "open") == 0) ||
293 (strcmp(argv
[1], "close") == 0)) {
296 u8 part_num
, access
= 0;
299 dev
= simple_strtoul(argv
[2], NULL
, 10);
300 part_num
= simple_strtoul(argv
[3], NULL
, 10);
302 return CMD_RET_USAGE
;
305 mmc
= find_mmc_device(dev
);
307 printf("no mmc device at slot %x\n", dev
);
312 printf("SD device cannot be opened/closed\n");
316 if ((part_num
<= 0) || (part_num
> MMC_NUM_BOOT_PARTITION
)) {
317 printf("Invalid boot partition number:\n");
318 printf("Boot partition number cannot be <= 0\n");
319 printf("EMMC44 supports only 2 boot partitions\n");
323 if (strcmp(argv
[1], "open") == 0)
324 access
= part_num
; /* enable R/W access to boot part*/
326 access
= 0; /* No access to boot partition */
328 /* acknowledge to be sent during boot operation */
329 return boot_part_access(mmc
, 1, part_num
, access
);
331 } else if (strcmp(argv
[1], "bootpart") == 0) {
333 dev
= simple_strtoul(argv
[2], NULL
, 10);
335 u32 bootsize
= simple_strtoul(argv
[3], NULL
, 10);
336 u32 rpmbsize
= simple_strtoul(argv
[4], NULL
, 10);
337 struct mmc
*mmc
= find_mmc_device(dev
);
339 printf("no mmc device at slot %x\n", dev
);
344 printf("It is not a EMMC device\n");
348 if (0 == mmc_boot_partition_size_change(mmc
,
349 bootsize
, rpmbsize
)) {
350 printf("EMMC boot partition Size %d MB\n", bootsize
);
351 printf("EMMC RPMB partition Size %d MB\n", rpmbsize
);
354 printf("EMMC boot partition Size change Failed.\n");
357 #endif /* CONFIG_SUPPORT_EMMC_BOOT */
360 if (argc
== 5 && strcmp(argv
[1], "read") == 0)
362 else if (argc
== 5 && strcmp(argv
[1], "write") == 0)
364 else if (argc
== 4 && strcmp(argv
[1], "erase") == 0)
367 if (state
!= MMC_INVALID
) {
368 struct mmc
*mmc
= find_mmc_device(curr_device
);
373 if (state
!= MMC_ERASE
) {
374 addr
= (void *)simple_strtoul(argv
[idx
], NULL
, 16);
378 blk
= simple_strtoul(argv
[idx
], NULL
, 16);
379 cnt
= simple_strtoul(argv
[idx
+ 1], NULL
, 16);
382 printf("no mmc device at slot %x\n", curr_device
);
386 printf("\nMMC %s: dev # %d, block # %d, count %d ... ",
387 argv
[1], curr_device
, blk
, cnt
);
391 if ((state
== MMC_WRITE
|| state
== MMC_ERASE
)) {
392 if (mmc_getwp(mmc
) == 1) {
393 printf("Error: card is write protected!\n");
400 n
= mmc
->block_dev
.block_read(curr_device
, blk
,
402 /* flush cache after read */
403 flush_cache((ulong
)addr
, cnt
* 512); /* FIXME */
406 n
= mmc
->block_dev
.block_write(curr_device
, blk
,
410 n
= mmc
->block_dev
.block_erase(curr_device
, blk
, cnt
);
416 printf("%d blocks %s: %s\n",
417 n
, argv
[1], (n
== cnt
) ? "OK" : "ERROR");
418 return (n
== cnt
) ? 0 : 1;
421 return CMD_RET_USAGE
;
425 mmc
, 6, 1, do_mmcops
,
427 "read addr blk# cnt\n"
428 "mmc write addr blk# cnt\n"
429 "mmc erase blk# cnt\n"
431 "mmc part - lists available partition on current mmc device\n"
432 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
433 "mmc list - lists available devices\n"
434 #ifdef CONFIG_SUPPORT_EMMC_BOOT
435 "mmc open <dev> <boot_partition>\n"
436 " - Enable boot_part for booting and enable R/W access of boot_part\n"
437 "mmc close <dev> <boot_partition>\n"
438 " - Enable boot_part for booting and disable access to boot_part\n"
439 "mmc bootpart <device num> <boot part size MB> <RPMB part size MB>\n"
440 " - change sizes of boot and RPMB partions of specified device\n"
443 #endif /* !CONFIG_GENERIC_MMC */