]> 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 79a1088f3bbaf935868533a684bdd2fe660e780d..7d824690b7f064547a3400bd65a957538a4289f0 100644 (file)
@@ -106,7 +106,7 @@ static void print_mmcinfo(struct mmc *mmc)
        printf("Rd Block Len: %d\n", mmc->read_bl_len);
 
        printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
-                       (mmc->version >> 4) & 0xf, mmc->version & 0xf);
+                       (mmc->version >> 8) & 0xf, mmc->version & 0xff);
 
        printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
        puts("Capacity: ");
@@ -115,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;
 
@@ -144,10 +144,10 @@ 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",
-       "- dislay info of the current MMC device"
+       "- 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;
 
@@ -164,8 +164,12 @@ 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;
@@ -179,8 +183,12 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        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;
@@ -196,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) {
@@ -250,14 +260,13 @@ 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 if (strcmp(argv[1], "erase") == 0)
+       else if (argc == 4 && strcmp(argv[1], "erase") == 0)
                state = MMC_ERASE;
-       else
-               state = MMC_INVALID;
 
        if (state != MMC_INVALID) {
                struct mmc *mmc = find_mmc_device(curr_device);
@@ -269,7 +278,7 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        addr = (void *)simple_strtoul(argv[idx], NULL, 16);
                        ++idx;
                } else
-                       addr = 0;
+                       addr = NULL;
                blk = simple_strtoul(argv[idx], NULL, 16);
                cnt = simple_strtoul(argv[idx + 1], NULL, 16);
 
@@ -283,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,