]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_mmc.c
Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / common / cmd_mmc.c
index a6458037e229b7aa1d69a5602f821db3df5380ab..9f3d6c575bfe2ef8c12b54d4fb1f0e42e2eacfa0 100644 (file)
@@ -32,7 +32,7 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        int dev;
 
        if (argc < 2)
-               return cmd_usage(cmdtp);
+               return CMD_RET_USAGE;
 
        if (strcmp(argv[1], "init") == 0) {
                if (argc == 2) {
@@ -43,7 +43,7 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                } else if (argc == 3) {
                        dev = (int)simple_strtoul(argv[2], NULL, 10);
                } else {
-                       return cmd_usage(cmdtp);
+                       return CMD_RET_USAGE;
                }
 
                if (mmc_legacy_init(dev) != 0) {
@@ -68,12 +68,12 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #endif
                        curr_device = dev;
                } else {
-                       return cmd_usage(cmdtp);
+                       return CMD_RET_USAGE;
                }
 
                printf("mmc%d is current device\n", curr_device);
        } else {
-               return cmd_usage(cmdtp);
+               return CMD_RET_USAGE;
        }
 
        return 0;
@@ -91,6 +91,7 @@ enum mmc_state {
        MMC_INVALID,
        MMC_READ,
        MMC_WRITE,
+       MMC_ERASE,
 };
 static void print_mmcinfo(struct mmc *mmc)
 {
@@ -114,7 +115,7 @@ static void print_mmcinfo(struct mmc *mmc)
        printf("Bus Width: %d-bit\n", mmc->bus_width);
 }
 
-int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        struct mmc *mmc;
 
@@ -143,16 +144,15 @@ int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 U_BOOT_CMD(
        mmcinfo, 1, 0, do_mmcinfo,
        "display MMC info",
-       "    - device number of the device to dislay info of\n"
-       ""
+       "- display info of the current MMC device"
 );
 
-int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        enum mmc_state state;
 
        if (argc < 2)
-               return cmd_usage(cmdtp);
+               return CMD_RET_USAGE;
 
        if (curr_device < 0) {
                if (get_mmc_num() > 0)
@@ -164,21 +164,31 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        }
 
        if (strcmp(argv[1], "rescan") == 0) {
-               struct mmc *mmc = find_mmc_device(curr_device);
+               struct mmc *mmc;
+
+               if (argc != 2)
+                       return CMD_RET_USAGE;
 
+               mmc = find_mmc_device(curr_device);
                if (!mmc) {
                        printf("no mmc device at slot %x\n", curr_device);
                        return 1;
                }
 
                mmc->has_init = 0;
-               mmc_init(mmc);
 
-               return 0;
+               if (mmc_init(mmc))
+                       return 1;
+               else
+                       return 0;
        } else if (strncmp(argv[1], "part", 4) == 0) {
                block_dev_desc_t *mmc_dev;
-               struct mmc *mmc = find_mmc_device(curr_device);
+               struct mmc *mmc;
+
+               if (argc != 2)
+                       return CMD_RET_USAGE;
 
+               mmc = find_mmc_device(curr_device);
                if (!mmc) {
                        printf("no mmc device at slot %x\n", curr_device);
                        return 1;
@@ -194,6 +204,8 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                puts("get mmc type error!\n");
                return 1;
        } else if (strcmp(argv[1], "list") == 0) {
+               if (argc != 2)
+                       return CMD_RET_USAGE;
                print_mmc_devices('\n');
                return 0;
        } else if (strcmp(argv[1], "dev") == 0) {
@@ -213,7 +225,7 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                                return 1;
                        }
                } else
-                       return cmd_usage(cmdtp);
+                       return CMD_RET_USAGE;
 
                mmc = find_mmc_device(dev);
                if (!mmc) {
@@ -248,19 +260,27 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                return 0;
        }
 
-       if (strcmp(argv[1], "read") == 0)
+       state = MMC_INVALID;
+       if (argc == 5 && strcmp(argv[1], "read") == 0)
                state = MMC_READ;
-       else if (strcmp(argv[1], "write") == 0)
+       else if (argc == 5 && strcmp(argv[1], "write") == 0)
                state = MMC_WRITE;
-       else
-               state = MMC_INVALID;
+       else if (argc == 4 && strcmp(argv[1], "erase") == 0)
+               state = MMC_ERASE;
 
        if (state != MMC_INVALID) {
                struct mmc *mmc = find_mmc_device(curr_device);
-               void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
-               u32 blk = simple_strtoul(argv[3], NULL, 16);
-               u32 cnt = simple_strtoul(argv[4], NULL, 16);
-               u32 n;
+               int idx = 2;
+               u32 blk, cnt, n;
+               void *addr;
+
+               if (state != MMC_ERASE) {
+                       addr = (void *)simple_strtoul(argv[idx], NULL, 16);
+                       ++idx;
+               } else
+                       addr = NULL;
+               blk = simple_strtoul(argv[idx], NULL, 16);
+               cnt = simple_strtoul(argv[idx + 1], NULL, 16);
 
                if (!mmc) {
                        printf("no mmc device at slot %x\n", curr_device);
@@ -272,6 +292,13 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
                mmc_init(mmc);
 
+               if ((state == MMC_WRITE || state == MMC_ERASE)) {
+                       if (mmc_getwp(mmc) == 1) {
+                               printf("Error: card is write protected!\n");
+                               return 1;
+                       }
+               }
+
                switch (state) {
                case MMC_READ:
                        n = mmc->block_dev.block_read(curr_device, blk,
@@ -283,6 +310,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        n = mmc->block_dev.block_write(curr_device, blk,
                                                      cnt, addr);
                        break;
+               case MMC_ERASE:
+                       n = mmc->block_dev.block_erase(curr_device, blk, cnt);
+                       break;
                default:
                        BUG();
                }
@@ -292,7 +322,7 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                return (n == cnt) ? 0 : 1;
        }
 
-       return cmd_usage(cmdtp);
+       return CMD_RET_USAGE;
 }
 
 U_BOOT_CMD(
@@ -300,6 +330,7 @@ U_BOOT_CMD(
        "MMC sub system",
        "read addr blk# cnt\n"
        "mmc write addr blk# cnt\n"
+       "mmc erase blk# cnt\n"
        "mmc rescan\n"
        "mmc part - lists available partition on current mmc device\n"
        "mmc dev [dev] [part] - show or set current mmc device [partition]\n"