]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_mmc.c
karo: fdt: convert tx6qdl_fixup_flexcan() to global function karo_fdt_fixup_flexcan()
[karo-tx-uboot.git] / common / cmd_mmc.c
index aea8fe496595fd40b63279912046cf9f3328c7b9..1cdeb443fcc5474498832bb1ebf7269b4f54319a 100644 (file)
@@ -2,23 +2,7 @@
  * (C) Copyright 2003
  * Kyle Harris, kharris@nexus-tech.net
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -32,7 +16,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 +27,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 +52,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;
@@ -87,42 +71,12 @@ U_BOOT_CMD(
 );
 #else /* !CONFIG_GENERIC_MMC */
 
-<<<<<<< HEAD
-#ifdef CONFIG_BOOT_PARTITION_ACCESS
-#define MMC_PARTITION_SWITCH(mmc, part, enable_boot) \
-       do { \
-               if (IS_SD(mmc)) {       \
-                       if (part > 1)   {\
-                               printf( \
-                               "\nError: SD partition can only be 0 or 1\n");\
-                               return 1;       \
-                       }       \
-                       if (sd_switch_partition(mmc, part) < 0) {       \
-                               if (part > 0) { \
-                                       printf("\nError: Unable to switch SD "\
-                                       "partition\n");\
-                                       return 1;       \
-                               }       \
-                       }       \
-               } else {        \
-                       if (mmc_switch_partition(mmc, part, enable_boot) \
-                               < 0) {  \
-                               printf("Error: Fail to switch " \
-                                       "partition to %d\n", part);     \
-                               return 1;       \
-                       }       \
-               } \
-       } while (0)
-#endif
-
-=======
 enum mmc_state {
        MMC_INVALID,
        MMC_READ,
        MMC_WRITE,
        MMC_ERASE,
 };
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
 static void print_mmcinfo(struct mmc *mmc)
 {
        printf("Device: %s\n", mmc->name);
@@ -136,7 +90,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: ");
@@ -145,7 +99,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;
 
@@ -161,12 +115,6 @@ int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        mmc = find_mmc_device(curr_device);
 
        if (mmc) {
-<<<<<<< HEAD
-               if (mmc_init(mmc))
-                       puts("MMC card init failed!\n");
-               else
-                       print_mmcinfo(mmc);
-=======
                mmc_init(mmc);
 
                print_mmcinfo(mmc);
@@ -174,35 +122,51 @@ int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        } else {
                printf("no mmc device at slot %x\n", curr_device);
                return 1;
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
        }
 }
 
-<<<<<<< HEAD
-U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo,
-       "mmcinfo <dev num>-- display MMC info",
-=======
 U_BOOT_CMD(
        mmcinfo, 1, 0, do_mmcinfo,
        "display MMC info",
-       "    - device number of the device to dislay info of\n"
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
-       ""
+       "- display info of the current MMC device"
 );
 
-int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+#ifdef CONFIG_SUPPORT_EMMC_BOOT
+static int boot_part_access(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
 {
-<<<<<<< HEAD
-       int rc = 0;
-#ifdef CONFIG_BOOT_PARTITION_ACCESS
-       u32 part = 0;
+       int err;
+       err = mmc_boot_part_access(mmc, ack, part_num, access);
+
+       if ((err == 0) && (access != 0)) {
+               printf("\t\t\t!!!Notice!!!\n");
+
+               printf("!You must close EMMC boot Partition");
+               printf("after all images are written\n");
+
+               printf("!EMMC boot partition has continuity");
+               printf("at image writing time.\n");
+
+               printf("!So, do not close the boot partition");
+               printf("before all images are written.\n");
+               return 0;
+       } else if ((err == 0) && (access == 0))
+               return 0;
+       else if ((err != 0) && (access != 0)) {
+               printf("EMMC boot partition-%d OPEN Failed.\n", part_num);
+               return 1;
+       } else {
+               printf("EMMC boot partition-%d CLOSE Failed.\n", part_num);
+               return 1;
+       }
+}
 #endif
-=======
+
+static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
        enum mmc_state state;
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
 
        if (argc < 2)
-               return cmd_usage(cmdtp);
+               return CMD_RET_USAGE;
 
        if (curr_device < 0) {
                if (get_mmc_num() > 0)
@@ -214,8 +178,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;
@@ -229,8 +197,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;
@@ -245,24 +217,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
                puts("get mmc type error!\n");
                return 1;
-<<<<<<< HEAD
-#ifdef CONFIG_BOOT_PARTITION_ACCESS
-       case 7: /* Fall through */
-               part = simple_strtoul(argv[6], NULL, 10);
-#endif
-       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)
-=======
        } 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) {
@@ -279,45 +236,16 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        if (part > PART_ACCESS_MASK) {
                                printf("#part_num shouldn't be larger"
                                        " than %d\n", PART_ACCESS_MASK);
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
                                return 1;
                        }
                } else
-                       return cmd_usage(cmdtp);
-
-<<<<<<< HEAD
-#ifdef CONFIG_BOOT_PARTITION_ACCESS
-                       printf("\nMMC read: dev # %d, block # %d, "
-                               "count %d partition # %d ... \n",
-                               dev, blk, cnt, part);
-#else
-                       printf("\nMMC read: dev # %d, block # %d,"
-                               "count %d ... \n", dev, blk, cnt);
-#endif
+                       return CMD_RET_USAGE;
 
-                       mmc_init(mmc);
-
-#ifdef CONFIG_BOOT_PARTITION_ACCESS
-                       if (((mmc->boot_config &
-                               EXT_CSD_BOOT_PARTITION_ACCESS_MASK) != part)
-                               || IS_SD(mmc)) {
-                               /*
-                                * After mmc_init, we now know whether
-                                * this is a eSD/eMMC which support boot
-                                * partition
-                                */
-                               MMC_PARTITION_SWITCH(mmc, part, 0);
-                       }
-#endif
-
-                       n = mmc->block_dev.block_read(dev, blk, cnt, addr);
-=======
                mmc = find_mmc_device(dev);
                if (!mmc) {
                        printf("no mmc device at slot %x\n", dev);
                        return 1;
                }
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
 
                mmc_init(mmc);
                if (part != -1) {
@@ -327,23 +255,10 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                                return 1;
                        }
 
-<<<<<<< HEAD
-                       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);
-=======
                        if (part != mmc->part_num) {
                                ret = mmc_switch_part(dev, part);
                                if (!ret)
                                        mmc->part_num = part;
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
 
                                printf("switch to partions #%d, %s\n",
                                                part, (!ret) ? "OK" : "ERROR");
@@ -357,27 +272,81 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                                curr_device, mmc->part_num);
 
                return 0;
-       }
+#ifdef CONFIG_SUPPORT_EMMC_BOOT
+       } else if ((strcmp(argv[1], "open") == 0) ||
+                       (strcmp(argv[1], "close") == 0)) {
+               int dev;
+               struct mmc *mmc;
+               u8 part_num, access = 0;
 
-<<<<<<< HEAD
-#ifdef CONFIG_BOOT_PARTITION_ACCESS
-                       printf("\nMMC write: dev # %d, block # %d, "
-                               "count %d, partition # %d ... \n",
-                               dev, blk, cnt, part);
-#else
-                       printf("\nMMC write: dev # %d, block # %d, "
-                               "count %d ... \n",
-                               dev, blk, cnt);
-#endif
-=======
-       if (strcmp(argv[1], "read") == 0)
+               if (argc == 4) {
+                       dev = simple_strtoul(argv[2], NULL, 10);
+                       part_num = simple_strtoul(argv[3], NULL, 10);
+               } else {
+                       return CMD_RET_USAGE;
+               }
+
+               mmc = find_mmc_device(dev);
+               if (!mmc) {
+                       printf("no mmc device at slot %x\n", dev);
+                       return 1;
+               }
+
+               if (IS_SD(mmc)) {
+                       printf("SD device cannot be opened/closed\n");
+                       return 1;
+               }
+
+               if ((part_num <= 0) || (part_num > MMC_NUM_BOOT_PARTITION)) {
+                       printf("Invalid boot partition number:\n");
+                       printf("Boot partition number cannot be <= 0\n");
+                       printf("EMMC44 supports only 2 boot partitions\n");
+                       return 1;
+               }
+
+               if (strcmp(argv[1], "open") == 0)
+                       access = part_num; /* enable R/W access to boot part*/
+               else
+                       access = 0; /* No access to boot partition */
+
+               /* acknowledge to be sent during boot operation */
+               return boot_part_access(mmc, 1, part_num, access);
+
+       } else if (strcmp(argv[1], "bootpart") == 0) {
+               int dev;
+               dev = simple_strtoul(argv[2], NULL, 10);
+
+               u32 bootsize = simple_strtoul(argv[3], NULL, 10);
+               u32 rpmbsize = simple_strtoul(argv[4], NULL, 10);
+               struct mmc *mmc = find_mmc_device(dev);
+               if (!mmc) {
+                       printf("no mmc device at slot %x\n", dev);
+                       return 1;
+               }
+
+               if (IS_SD(mmc)) {
+                       printf("It is not a EMMC device\n");
+                       return 1;
+               }
+
+               if (0 == mmc_boot_partition_size_change(mmc,
+                                                       bootsize, rpmbsize)) {
+                       printf("EMMC boot partition Size %d MB\n", bootsize);
+                       printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
+                       return 0;
+               } else {
+                       printf("EMMC boot partition Size change Failed.\n");
+                       return 1;
+               }
+#endif /* CONFIG_SUPPORT_EMMC_BOOT */
+       }
+       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);
@@ -389,7 +358,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);
 
@@ -397,28 +366,18 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        printf("no mmc device at slot %x\n", curr_device);
                        return 1;
                }
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
 
                printf("\nMMC %s: dev # %d, block # %d, count %d ... ",
                                argv[1], curr_device, blk, cnt);
 
-<<<<<<< HEAD
-#ifdef CONFIG_BOOT_PARTITION_ACCESS
-                       if (((mmc->boot_config &
-                               EXT_CSD_BOOT_PARTITION_ACCESS_MASK) != part)
-                               || IS_SD(mmc)) {
-                               /*
-                                * After mmc_init, we now know whether this is a
-                                * eSD/eMMC which support boot partition
-                                */
-                               MMC_PARTITION_SWITCH(mmc, part, 1);
-                       }
-#endif
-
-                       n = mmc->block_dev.block_write(dev, blk, cnt, addr);
-=======
                mmc_init(mmc);
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
+
+               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:
@@ -443,31 +402,26 @@ 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(
        mmc, 6, 1, do_mmcops,
        "MMC sub system",
-<<<<<<< HEAD
-       "mmc read <device num> addr blk# cnt\n"
-       "mmc write <device num> addr blk# cnt\n"
-       "mmc rescan <device num>\n"
-=======
        "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"
->>>>>>> 9a3aae22edf1eda6326cc51c28631ca5c23b7706
-       "mmc list - lists available devices");
-#else
-U_BOOT_CMD(
-       mmc, 7, 1, do_mmcops,
-       "MMC sub system",
-       "mmc read <device num> addr blk# cnt [partition]\n"
-       "mmc write <device num> addr blk# cnt [partition]\n"
-       "mmc rescan <device num>\n"
-       "mmc list - lists available devices");
+       "mmc list - lists available devices\n"
+#ifdef CONFIG_SUPPORT_EMMC_BOOT
+       "mmc open <dev> <boot_partition>\n"
+       " - Enable boot_part for booting and enable R/W access of boot_part\n"
+       "mmc close <dev> <boot_partition>\n"
+       " - Enable boot_part for booting and disable access to boot_part\n"
+       "mmc bootpart <device num> <boot part size MB> <RPMB part size MB>\n"
+       " - change sizes of boot and RPMB partions of specified device\n"
 #endif
+       );
+#endif /* !CONFIG_GENERIC_MMC */