summaryrefslogtreecommitdiff
path: root/common/cmd_mmc.c
diff options
context:
space:
mode:
authorLei Wen <leiwen@marvell.com>2011-05-02 16:26:25 +0000
committerAndy Fleming <afleming@freescale.com>2011-05-18 14:36:35 -0500
commitea6ebe21772568ee97fb5c23c01e993140f0e0e6 (patch)
tree2abbfeafb64e44f214f36c685f562c0483005d05 /common/cmd_mmc.c
parented018b21d61614e0431f6bf514bec6e4bf64fe31 (diff)
cmd_mmc: eliminate device num in the mmc command
mmc command applied device, like ide and usb... Signed-off-by: Lei Wen <leiwen@marvell.com> Acked-by: Andy Fleming <afleming@freescale.com>
Diffstat (limited to 'common/cmd_mmc.c')
-rw-r--r--common/cmd_mmc.c198
1 files changed, 110 insertions, 88 deletions
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index 6166749ad5a..e266d4fa43f 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -25,9 +25,8 @@
#include <command.h>
#include <mmc.h>
-#ifndef CONFIG_GENERIC_MMC
static int curr_device = -1;
-
+#ifndef CONFIG_GENERIC_MMC
int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int dev;
@@ -113,140 +112,163 @@ static void print_mmcinfo(struct mmc *mmc)
int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
struct mmc *mmc;
- int dev_num;
- if (argc < 2)
- dev_num = 0;
- else
- dev_num = simple_strtoul(argv[1], NULL, 0);
+ if (curr_device < 0) {
+ if (get_mmc_num() > 0)
+ curr_device = 0;
+ else {
+ puts("No MMC device available\n");
+ return 1;
+ }
+ }
- mmc = find_mmc_device(dev_num);
+ mmc = find_mmc_device(curr_device);
if (mmc) {
mmc_init(mmc);
print_mmcinfo(mmc);
+ return 0;
+ } else {
+ printf("no mmc device at slot %x\n", curr_device);
+ return 1;
}
-
- return 0;
}
U_BOOT_CMD(
- mmcinfo, 2, 0, do_mmcinfo,
+ mmcinfo, 1, 0, do_mmcinfo,
"display MMC info",
- "<dev num>\n"
" - device number of the device to dislay info of\n"
""
);
int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- int rc = 0;
+ if (argc < 2)
+ return cmd_usage(cmdtp);
- switch (argc) {
- case 3:
- if (strcmp(argv[1], "rescan") == 0) {
- int dev = simple_strtoul(argv[2], NULL, 10);
- struct mmc *mmc = find_mmc_device(dev);
+ if (curr_device < 0) {
+ if (get_mmc_num() > 0)
+ curr_device = 0;
+ else {
+ puts("No MMC device available\n");
+ return 1;
+ }
+ }
- if (!mmc)
- return 1;
+ if (strcmp(argv[1], "rescan") == 0) {
+ struct mmc *mmc = find_mmc_device(curr_device);
- mmc_init(mmc);
+ if (!mmc) {
+ printf("no mmc device at slot %x\n", curr_device);
+ return 1;
+ }
+
+ mmc_init(mmc);
+ return 0;
+ } else if (strncmp(argv[1], "part", 4) == 0) {
+ block_dev_desc_t *mmc_dev;
+ struct mmc *mmc = find_mmc_device(curr_device);
+
+ if (!mmc) {
+ printf("no mmc device at slot %x\n", curr_device);
+ return 1;
+ }
+ mmc_init(mmc);
+ mmc_dev = mmc_get_dev(curr_device);
+ if (mmc_dev != NULL &&
+ mmc_dev->type != DEV_TYPE_UNKNOWN) {
+ print_part(mmc_dev);
return 0;
- } else if (strncmp(argv[1], "part", 4) == 0) {
- int dev = simple_strtoul(argv[2], NULL, 10);
- block_dev_desc_t *mmc_dev;
- struct mmc *mmc = find_mmc_device(dev);
+ }
- if (!mmc) {
- puts("no mmc devices available\n");
- return 1;
- }
- mmc_init(mmc);
- mmc_dev = mmc_get_dev(dev);
- if (mmc_dev != NULL &&
- mmc_dev->type != DEV_TYPE_UNKNOWN) {
- print_part(mmc_dev);
- return 0;
- }
+ puts("get mmc type error!\n");
+ return 1;
+ } else if (strcmp(argv[1], "list") == 0) {
+ print_mmc_devices('\n');
+ return 0;
+ } else if (strcmp(argv[1], "dev") == 0) {
+ int dev;
+ struct mmc *mmc;
+
+ if (argc == 2)
+ dev = curr_device;
+ else if (argc == 3)
+ dev = simple_strtoul(argv[2], NULL, 10);
+ else
+ return cmd_usage(cmdtp);
- puts("get mmc type error!\n");
+ mmc = find_mmc_device(dev);
+ if (!mmc) {
+ printf("no mmc device at slot %x\n", dev);
return 1;
}
- case 0:
- case 1:
- case 4:
- return cmd_usage(cmdtp);
+ curr_device = dev;
+ printf("mmc%d is current device\n", curr_device);
- case 2:
- if (!strcmp(argv[1], "list")) {
- print_mmc_devices('\n');
- return 0;
+ return 0;
+ } else if (strcmp(argv[1], "read") == 0) {
+ void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
+ u32 cnt = simple_strtoul(argv[4], NULL, 16);
+ u32 n;
+ u32 blk = simple_strtoul(argv[3], NULL, 16);
+ struct mmc *mmc = find_mmc_device(curr_device);
+
+ if (!mmc) {
+ printf("no mmc device at slot %x\n", curr_device);
+ return 1;
}
- return 1;
- default: /* at least 5 args */
- if (strcmp(argv[1], "read") == 0) {
- int dev = simple_strtoul(argv[2], NULL, 10);
- void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
- u32 cnt = simple_strtoul(argv[5], NULL, 16);
- u32 n;
- u32 blk = simple_strtoul(argv[4], NULL, 16);
- struct mmc *mmc = find_mmc_device(dev);
-
- if (!mmc)
- return 1;
- printf("\nMMC read: dev # %d, block # %d, count %d ... ",
- dev, blk, cnt);
+ printf("\nMMC read: dev # %d, block # %d, count %d ... ",
+ curr_device, blk, cnt);
- mmc_init(mmc);
+ mmc_init(mmc);
- n = mmc->block_dev.block_read(dev, blk, cnt, addr);
+ n = mmc->block_dev.block_read(curr_device, blk, cnt, addr);
- /* flush cache after read */
- flush_cache((ulong)addr, cnt * 512); /* FIXME */
+ /* flush cache after read */
+ flush_cache((ulong)addr, cnt * 512); /* FIXME */
- printf("%d blocks read: %s\n",
+ printf("%d blocks read: %s\n",
n, (n==cnt) ? "OK" : "ERROR");
- return (n == cnt) ? 0 : 1;
- } else if (strcmp(argv[1], "write") == 0) {
- int dev = simple_strtoul(argv[2], NULL, 10);
- void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
- u32 cnt = simple_strtoul(argv[5], NULL, 16);
- u32 n;
- struct mmc *mmc = find_mmc_device(dev);
+ return (n == cnt) ? 0 : 1;
+ } else if (strcmp(argv[1], "write") == 0) {
+ void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
+ u32 cnt = simple_strtoul(argv[4], NULL, 16);
+ u32 n;
+ struct mmc *mmc = find_mmc_device(curr_device);
- int blk = simple_strtoul(argv[4], NULL, 16);
+ int blk = simple_strtoul(argv[3], NULL, 16);
- if (!mmc)
- return 1;
+ if (!mmc) {
+ printf("no mmc device at slot %x\n", curr_device);
+ return 1;
+ }
- printf("\nMMC write: dev # %d, block # %d, count %d ... ",
- dev, blk, cnt);
+ printf("\nMMC write: dev # %d, block # %d, count %d ... ",
+ curr_device, blk, cnt);
- mmc_init(mmc);
+ mmc_init(mmc);
- n = mmc->block_dev.block_write(dev, blk, cnt, addr);
+ n = mmc->block_dev.block_write(curr_device, blk, cnt, addr);
- printf("%d blocks written: %s\n",
+ printf("%d blocks written: %s\n",
n, (n == cnt) ? "OK" : "ERROR");
- return (n == cnt) ? 0 : 1;
- } else
- rc = cmd_usage(cmdtp);
-
- return rc;
+ return (n == cnt) ? 0 : 1;
}
+
+ return cmd_usage(cmdtp);
}
U_BOOT_CMD(
mmc, 6, 1, do_mmcops,
"MMC sub system",
- "read <device num> addr blk# cnt\n"
- "mmc write <device num> addr blk# cnt\n"
- "mmc rescan <device num>\n"
- "mmc part <device num> - lists available partition on mmc\n"
+ "read addr blk# cnt\n"
+ "mmc write addr blk# cnt\n"
+ "mmc rescan\n"
+ "mmc part - lists available partition on current mmc device\n"
+ "mmc dev [dev] - show or set current mmc device\n"
"mmc list - lists available devices");
#endif