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[])
35 return cmd_usage(cmdtp);
37 if (strcmp(argv[1], "init") == 0) {
43 } else if (argc == 3) {
44 dev = (int)simple_strtoul(argv[2], NULL, 10);
46 return cmd_usage(cmdtp);
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)
71 return cmd_usage(cmdtp);
74 printf("mmc%d is current device\n", curr_device);
76 return cmd_usage(cmdtp);
85 "init [dev] - init MMC sub system\n"
86 "mmc device [dev] - show or set current device"
88 #else /* !CONFIG_GENERIC_MMC */
91 #ifdef CONFIG_BOOT_PARTITION_ACCESS
92 #define MMC_PARTITION_SWITCH(mmc, part, enable_boot) \
97 "\nError: SD partition can only be 0 or 1\n");\
100 if (sd_switch_partition(mmc, part) < 0) { \
102 printf("\nError: Unable to switch SD "\
108 if (mmc_switch_partition(mmc, part, enable_boot) \
110 printf("Error: Fail to switch " \
111 "partition to %d\n", part); \
125 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
126 static void print_mmcinfo(struct mmc *mmc)
128 printf("Device: %s\n", mmc->name);
129 printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
130 printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
131 printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
132 (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
133 (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
135 printf("Tran Speed: %d\n", mmc->tran_speed);
136 printf("Rd Block Len: %d\n", mmc->read_bl_len);
138 printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
139 (mmc->version >> 4) & 0xf, mmc->version & 0xf);
141 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
143 print_size(mmc->capacity, "\n");
145 printf("Bus Width: %d-bit\n", mmc->bus_width);
148 int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
152 if (curr_device < 0) {
153 if (get_mmc_num() > 0)
156 puts("No MMC device available\n");
161 mmc = find_mmc_device(curr_device);
166 puts("MMC card init failed!\n");
175 printf("no mmc device at slot %x\n", curr_device);
177 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
182 U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo,
183 "mmcinfo <dev num>-- display MMC info",
186 mmcinfo, 1, 0, do_mmcinfo,
188 " - device number of the device to dislay info of\n"
189 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
193 int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
197 #ifdef CONFIG_BOOT_PARTITION_ACCESS
201 enum mmc_state state;
202 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
205 return cmd_usage(cmdtp);
207 if (curr_device < 0) {
208 if (get_mmc_num() > 0)
211 puts("No MMC device available\n");
216 if (strcmp(argv[1], "rescan") == 0) {
217 struct mmc *mmc = find_mmc_device(curr_device);
220 printf("no mmc device at slot %x\n", curr_device);
230 } else if (strncmp(argv[1], "part", 4) == 0) {
231 block_dev_desc_t *mmc_dev;
232 struct mmc *mmc = find_mmc_device(curr_device);
235 printf("no mmc device at slot %x\n", curr_device);
239 mmc_dev = mmc_get_dev(curr_device);
240 if (mmc_dev != NULL &&
241 mmc_dev->type != DEV_TYPE_UNKNOWN) {
246 puts("get mmc type error!\n");
249 #ifdef CONFIG_BOOT_PARTITION_ACCESS
250 case 7: /* Fall through */
251 part = simple_strtoul(argv[6], NULL, 10);
253 default: /* at least 5 args */
254 if (strcmp(argv[1], "read") == 0) {
255 int dev = simple_strtoul(argv[2], NULL, 10);
256 void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
257 u32 cnt = simple_strtoul(argv[5], NULL, 16);
259 u32 blk = simple_strtoul(argv[4], NULL, 16);
261 struct mmc *mmc = find_mmc_device(dev);
265 } else if (strcmp(argv[1], "list") == 0) {
266 print_mmc_devices('\n');
268 } else if (strcmp(argv[1], "dev") == 0) {
275 dev = simple_strtoul(argv[2], NULL, 10);
276 else if (argc == 4) {
277 dev = (int)simple_strtoul(argv[2], NULL, 10);
278 part = (int)simple_strtoul(argv[3], NULL, 10);
279 if (part > PART_ACCESS_MASK) {
280 printf("#part_num shouldn't be larger"
281 " than %d\n", PART_ACCESS_MASK);
282 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
286 return cmd_usage(cmdtp);
289 #ifdef CONFIG_BOOT_PARTITION_ACCESS
290 printf("\nMMC read: dev # %d, block # %d, "
291 "count %d partition # %d ... \n",
292 dev, blk, cnt, part);
294 printf("\nMMC read: dev # %d, block # %d,"
295 "count %d ... \n", dev, blk, cnt);
300 #ifdef CONFIG_BOOT_PARTITION_ACCESS
301 if (((mmc->boot_config &
302 EXT_CSD_BOOT_PARTITION_ACCESS_MASK) != part)
305 * After mmc_init, we now know whether
306 * this is a eSD/eMMC which support boot
309 MMC_PARTITION_SWITCH(mmc, part, 0);
313 n = mmc->block_dev.block_read(dev, blk, cnt, addr);
315 mmc = find_mmc_device(dev);
317 printf("no mmc device at slot %x\n", dev);
320 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
325 if (mmc->part_config == MMCPART_NOAVAILABLE) {
326 printf("Card doesn't support part_switch\n");
331 printf("%d blocks read: %s\n",
332 n, (n==cnt) ? "OK" : "ERROR");
333 return (n == cnt) ? 0 : 1;
334 } else if (strcmp(argv[1], "write") == 0) {
335 int dev = simple_strtoul(argv[2], NULL, 10);
336 void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
337 u32 cnt = simple_strtoul(argv[5], NULL, 16);
340 struct mmc *mmc = find_mmc_device(dev);
342 if (part != mmc->part_num) {
343 ret = mmc_switch_part(dev, part);
345 mmc->part_num = part;
346 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
348 printf("switch to partions #%d, %s\n",
349 part, (!ret) ? "OK" : "ERROR");
353 if (mmc->part_config == MMCPART_NOAVAILABLE)
354 printf("mmc%d is current device\n", curr_device);
356 printf("mmc%d(part %d) is current device\n",
357 curr_device, mmc->part_num);
363 #ifdef CONFIG_BOOT_PARTITION_ACCESS
364 printf("\nMMC write: dev # %d, block # %d, "
365 "count %d, partition # %d ... \n",
366 dev, blk, cnt, part);
368 printf("\nMMC write: dev # %d, block # %d, "
373 if (strcmp(argv[1], "read") == 0)
375 else if (strcmp(argv[1], "write") == 0)
377 else if (strcmp(argv[1], "erase") == 0)
382 if (state != MMC_INVALID) {
383 struct mmc *mmc = find_mmc_device(curr_device);
388 if (state != MMC_ERASE) {
389 addr = (void *)simple_strtoul(argv[idx], NULL, 16);
393 blk = simple_strtoul(argv[idx], NULL, 16);
394 cnt = simple_strtoul(argv[idx + 1], NULL, 16);
397 printf("no mmc device at slot %x\n", curr_device);
400 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
402 printf("\nMMC %s: dev # %d, block # %d, count %d ... ",
403 argv[1], curr_device, blk, cnt);
406 #ifdef CONFIG_BOOT_PARTITION_ACCESS
407 if (((mmc->boot_config &
408 EXT_CSD_BOOT_PARTITION_ACCESS_MASK) != part)
411 * After mmc_init, we now know whether this is a
412 * eSD/eMMC which support boot partition
414 MMC_PARTITION_SWITCH(mmc, part, 1);
418 n = mmc->block_dev.block_write(dev, blk, cnt, addr);
421 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
425 n = mmc->block_dev.block_read(curr_device, blk,
427 /* flush cache after read */
428 flush_cache((ulong)addr, cnt * 512); /* FIXME */
431 n = mmc->block_dev.block_write(curr_device, blk,
435 n = mmc->block_dev.block_erase(curr_device, blk, cnt);
441 printf("%d blocks %s: %s\n",
442 n, argv[1], (n == cnt) ? "OK" : "ERROR");
443 return (n == cnt) ? 0 : 1;
446 return cmd_usage(cmdtp);
450 mmc, 6, 1, do_mmcops,
453 "mmc read <device num> addr blk# cnt\n"
454 "mmc write <device num> addr blk# cnt\n"
455 "mmc rescan <device num>\n"
457 "read addr blk# cnt\n"
458 "mmc write addr blk# cnt\n"
459 "mmc erase blk# cnt\n"
461 "mmc part - lists available partition on current mmc device\n"
462 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
463 >>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
464 "mmc list - lists available devices");
467 mmc, 7, 1, do_mmcops,
469 "mmc read <device num> addr blk# cnt [partition]\n"
470 "mmc write <device num> addr blk# cnt [partition]\n"
471 "mmc rescan <device num>\n"
472 "mmc list - lists available devices");