wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Kyle Harris, kharris@nexus-tech.net |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 10 | #include <mmc.h> |
| 11 | |
Mike Frysinger | 0289fe6 | 2009-06-14 21:35:21 -0400 | [diff] [blame] | 12 | static int curr_device = -1; |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 13 | #ifndef CONFIG_GENERIC_MMC |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 14 | int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 15 | { |
Minkyu Kang | 0f92290 | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 16 | int dev; |
| 17 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 18 | if (argc < 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 19 | return CMD_RET_USAGE; |
Minkyu Kang | 0f92290 | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 20 | |
| 21 | if (strcmp(argv[1], "init") == 0) { |
| 22 | if (argc == 2) { |
| 23 | if (curr_device < 0) |
| 24 | dev = 1; |
| 25 | else |
| 26 | dev = curr_device; |
| 27 | } else if (argc == 3) { |
| 28 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 29 | } else { |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 30 | return CMD_RET_USAGE; |
Minkyu Kang | 0f92290 | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | if (mmc_legacy_init(dev) != 0) { |
| 34 | puts("No MMC card found\n"); |
| 35 | return 1; |
| 36 | } |
| 37 | |
| 38 | curr_device = dev; |
| 39 | printf("mmc%d is available\n", curr_device); |
| 40 | } else if (strcmp(argv[1], "device") == 0) { |
| 41 | if (argc == 2) { |
| 42 | if (curr_device < 0) { |
| 43 | puts("No MMC device available\n"); |
| 44 | return 1; |
| 45 | } |
| 46 | } else if (argc == 3) { |
| 47 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 48 | |
| 49 | #ifdef CONFIG_SYS_MMC_SET_DEV |
| 50 | if (mmc_set_dev(dev) != 0) |
| 51 | return 1; |
| 52 | #endif |
| 53 | curr_device = dev; |
| 54 | } else { |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 55 | return CMD_RET_USAGE; |
Minkyu Kang | 0f92290 | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | printf("mmc%d is current device\n", curr_device); |
| 59 | } else { |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 60 | return CMD_RET_USAGE; |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 61 | } |
Minkyu Kang | 0f92290 | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 62 | |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 66 | U_BOOT_CMD( |
Minkyu Kang | 0f92290 | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 67 | mmc, 3, 1, do_mmc, |
| 68 | "MMC sub-system", |
| 69 | "init [dev] - init MMC sub system\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 70 | "mmc device [dev] - show or set current device" |
wdenk | f12e396 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 71 | ); |
Dirk Behme | df8852a | 2009-02-18 19:59:39 +0100 | [diff] [blame] | 72 | #else /* !CONFIG_GENERIC_MMC */ |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 73 | |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 74 | enum mmc_state { |
| 75 | MMC_INVALID, |
| 76 | MMC_READ, |
| 77 | MMC_WRITE, |
Lei Wen | ea52676 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 78 | MMC_ERASE, |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 79 | }; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 80 | static void print_mmcinfo(struct mmc *mmc) |
| 81 | { |
| 82 | printf("Device: %s\n", mmc->name); |
| 83 | printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24); |
| 84 | printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff); |
| 85 | printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff, |
| 86 | (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff, |
| 87 | (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff); |
| 88 | |
| 89 | printf("Tran Speed: %d\n", mmc->tran_speed); |
| 90 | printf("Rd Block Len: %d\n", mmc->read_bl_len); |
| 91 | |
| 92 | printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC", |
Jaehoon Chung | 6108ef6 | 2013-01-29 19:31:16 +0000 | [diff] [blame] | 93 | (mmc->version >> 8) & 0xf, mmc->version & 0xff); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 94 | |
| 95 | printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No"); |
Minkyu Kang | 316f81a | 2011-01-04 01:04:19 +0000 | [diff] [blame] | 96 | puts("Capacity: "); |
| 97 | print_size(mmc->capacity, "\n"); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 98 | |
| 99 | printf("Bus Width: %d-bit\n", mmc->bus_width); |
| 100 | } |
| 101 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 102 | static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 103 | { |
| 104 | struct mmc *mmc; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 105 | |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 106 | if (curr_device < 0) { |
| 107 | if (get_mmc_num() > 0) |
| 108 | curr_device = 0; |
| 109 | else { |
| 110 | puts("No MMC device available\n"); |
| 111 | return 1; |
| 112 | } |
| 113 | } |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 114 | |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 115 | mmc = find_mmc_device(curr_device); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 116 | |
| 117 | if (mmc) { |
| 118 | mmc_init(mmc); |
| 119 | |
| 120 | print_mmcinfo(mmc); |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 121 | return 0; |
| 122 | } else { |
| 123 | printf("no mmc device at slot %x\n", curr_device); |
| 124 | return 1; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 125 | } |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 128 | U_BOOT_CMD( |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 129 | mmcinfo, 1, 0, do_mmcinfo, |
Frans Meulenbroeks | 0dddc00 | 2010-07-31 15:01:52 +0200 | [diff] [blame] | 130 | "display MMC info", |
Robert P. J. Day | 31cf33c | 2012-11-11 03:24:44 +0000 | [diff] [blame] | 131 | "- display info of the current MMC device" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 132 | ); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 133 | |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 134 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 135 | static int boot_part_access(struct mmc *mmc, u8 ack, u8 part_num, u8 access) |
| 136 | { |
| 137 | int err; |
| 138 | err = mmc_boot_part_access(mmc, ack, part_num, access); |
| 139 | |
| 140 | if ((err == 0) && (access != 0)) { |
| 141 | printf("\t\t\t!!!Notice!!!\n"); |
| 142 | |
| 143 | printf("!You must close EMMC boot Partition"); |
| 144 | printf("after all images are written\n"); |
| 145 | |
| 146 | printf("!EMMC boot partition has continuity"); |
| 147 | printf("at image writing time.\n"); |
| 148 | |
| 149 | printf("!So, do not close the boot partition"); |
| 150 | printf("before all images are written.\n"); |
| 151 | return 0; |
| 152 | } else if ((err == 0) && (access == 0)) |
| 153 | return 0; |
| 154 | else if ((err != 0) && (access != 0)) { |
| 155 | printf("EMMC boot partition-%d OPEN Failed.\n", part_num); |
| 156 | return 1; |
| 157 | } else { |
| 158 | printf("EMMC boot partition-%d CLOSE Failed.\n", part_num); |
| 159 | return 1; |
| 160 | } |
| 161 | } |
| 162 | #endif |
| 163 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 164 | static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 165 | { |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 166 | enum mmc_state state; |
| 167 | |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 168 | if (argc < 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 169 | return CMD_RET_USAGE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 170 | |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 171 | if (curr_device < 0) { |
| 172 | if (get_mmc_num() > 0) |
| 173 | curr_device = 0; |
| 174 | else { |
| 175 | puts("No MMC device available\n"); |
| 176 | return 1; |
| 177 | } |
| 178 | } |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 179 | |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 180 | if (strcmp(argv[1], "rescan") == 0) { |
Stephen Warren | 18faca7 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 181 | struct mmc *mmc; |
Rabin Vincent | 3e448aa | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 182 | |
Stephen Warren | 18faca7 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 183 | if (argc != 2) |
| 184 | return CMD_RET_USAGE; |
| 185 | |
| 186 | mmc = find_mmc_device(curr_device); |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 187 | if (!mmc) { |
| 188 | printf("no mmc device at slot %x\n", curr_device); |
| 189 | return 1; |
| 190 | } |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 191 | |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 192 | mmc->has_init = 0; |
Lei Wen | 61dba93 | 2010-09-13 22:07:28 +0800 | [diff] [blame] | 193 | |
Michael Jones | 67a8bd8 | 2011-07-14 23:09:43 +0000 | [diff] [blame] | 194 | if (mmc_init(mmc)) |
| 195 | return 1; |
| 196 | else |
| 197 | return 0; |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 198 | } else if (strncmp(argv[1], "part", 4) == 0) { |
| 199 | block_dev_desc_t *mmc_dev; |
Stephen Warren | 18faca7 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 200 | struct mmc *mmc; |
Lei Wen | 61dba93 | 2010-09-13 22:07:28 +0800 | [diff] [blame] | 201 | |
Stephen Warren | 18faca7 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 202 | if (argc != 2) |
| 203 | return CMD_RET_USAGE; |
| 204 | |
| 205 | mmc = find_mmc_device(curr_device); |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 206 | if (!mmc) { |
| 207 | printf("no mmc device at slot %x\n", curr_device); |
Lei Wen | 61dba93 | 2010-09-13 22:07:28 +0800 | [diff] [blame] | 208 | return 1; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 209 | } |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 210 | mmc_init(mmc); |
| 211 | mmc_dev = mmc_get_dev(curr_device); |
| 212 | if (mmc_dev != NULL && |
| 213 | mmc_dev->type != DEV_TYPE_UNKNOWN) { |
| 214 | print_part(mmc_dev); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 215 | return 0; |
| 216 | } |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 217 | |
| 218 | puts("get mmc type error!\n"); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 219 | return 1; |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 220 | } else if (strcmp(argv[1], "list") == 0) { |
Stephen Warren | 18faca7 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 221 | if (argc != 2) |
| 222 | return CMD_RET_USAGE; |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 223 | print_mmc_devices('\n'); |
| 224 | return 0; |
| 225 | } else if (strcmp(argv[1], "dev") == 0) { |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 226 | int dev, part = -1; |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 227 | struct mmc *mmc; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 228 | |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 229 | if (argc == 2) |
| 230 | dev = curr_device; |
| 231 | else if (argc == 3) |
| 232 | dev = simple_strtoul(argv[2], NULL, 10); |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 233 | else if (argc == 4) { |
| 234 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 235 | part = (int)simple_strtoul(argv[3], NULL, 10); |
| 236 | if (part > PART_ACCESS_MASK) { |
| 237 | printf("#part_num shouldn't be larger" |
| 238 | " than %d\n", PART_ACCESS_MASK); |
| 239 | return 1; |
| 240 | } |
| 241 | } else |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 242 | return CMD_RET_USAGE; |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 243 | |
| 244 | mmc = find_mmc_device(dev); |
| 245 | if (!mmc) { |
| 246 | printf("no mmc device at slot %x\n", dev); |
| 247 | return 1; |
| 248 | } |
| 249 | |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 250 | mmc_init(mmc); |
| 251 | if (part != -1) { |
| 252 | int ret; |
| 253 | if (mmc->part_config == MMCPART_NOAVAILABLE) { |
| 254 | printf("Card doesn't support part_switch\n"); |
| 255 | return 1; |
| 256 | } |
| 257 | |
| 258 | if (part != mmc->part_num) { |
| 259 | ret = mmc_switch_part(dev, part); |
| 260 | if (!ret) |
| 261 | mmc->part_num = part; |
| 262 | |
Robert P. J. Day | e3f2c2e | 2013-08-21 11:39:19 -0400 | [diff] [blame] | 263 | printf("switch to partitions #%d, %s\n", |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 264 | part, (!ret) ? "OK" : "ERROR"); |
| 265 | } |
| 266 | } |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 267 | curr_device = dev; |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 268 | if (mmc->part_config == MMCPART_NOAVAILABLE) |
| 269 | printf("mmc%d is current device\n", curr_device); |
| 270 | else |
| 271 | printf("mmc%d(part %d) is current device\n", |
| 272 | curr_device, mmc->part_num); |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 273 | |
| 274 | return 0; |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 275 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 276 | } else if ((strcmp(argv[1], "open") == 0) || |
| 277 | (strcmp(argv[1], "close") == 0)) { |
| 278 | int dev; |
| 279 | struct mmc *mmc; |
| 280 | u8 part_num, access = 0; |
| 281 | |
| 282 | if (argc == 4) { |
| 283 | dev = simple_strtoul(argv[2], NULL, 10); |
| 284 | part_num = simple_strtoul(argv[3], NULL, 10); |
| 285 | } else { |
| 286 | return CMD_RET_USAGE; |
| 287 | } |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 288 | |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 289 | mmc = find_mmc_device(dev); |
| 290 | if (!mmc) { |
| 291 | printf("no mmc device at slot %x\n", dev); |
| 292 | return 1; |
| 293 | } |
| 294 | |
| 295 | if (IS_SD(mmc)) { |
| 296 | printf("SD device cannot be opened/closed\n"); |
| 297 | return 1; |
| 298 | } |
| 299 | |
| 300 | if ((part_num <= 0) || (part_num > MMC_NUM_BOOT_PARTITION)) { |
| 301 | printf("Invalid boot partition number:\n"); |
| 302 | printf("Boot partition number cannot be <= 0\n"); |
| 303 | printf("EMMC44 supports only 2 boot partitions\n"); |
| 304 | return 1; |
| 305 | } |
| 306 | |
| 307 | if (strcmp(argv[1], "open") == 0) |
| 308 | access = part_num; /* enable R/W access to boot part*/ |
| 309 | else |
| 310 | access = 0; /* No access to boot partition */ |
| 311 | |
| 312 | /* acknowledge to be sent during boot operation */ |
| 313 | return boot_part_access(mmc, 1, part_num, access); |
| 314 | |
| 315 | } else if (strcmp(argv[1], "bootpart") == 0) { |
| 316 | int dev; |
| 317 | dev = simple_strtoul(argv[2], NULL, 10); |
| 318 | |
| 319 | u32 bootsize = simple_strtoul(argv[3], NULL, 10); |
| 320 | u32 rpmbsize = simple_strtoul(argv[4], NULL, 10); |
| 321 | struct mmc *mmc = find_mmc_device(dev); |
| 322 | if (!mmc) { |
| 323 | printf("no mmc device at slot %x\n", dev); |
| 324 | return 1; |
| 325 | } |
| 326 | |
| 327 | if (IS_SD(mmc)) { |
| 328 | printf("It is not a EMMC device\n"); |
| 329 | return 1; |
| 330 | } |
| 331 | |
| 332 | if (0 == mmc_boot_partition_size_change(mmc, |
| 333 | bootsize, rpmbsize)) { |
| 334 | printf("EMMC boot partition Size %d MB\n", bootsize); |
| 335 | printf("EMMC RPMB partition Size %d MB\n", rpmbsize); |
| 336 | return 0; |
| 337 | } else { |
| 338 | printf("EMMC boot partition Size change Failed.\n"); |
| 339 | return 1; |
| 340 | } |
| 341 | #endif /* CONFIG_SUPPORT_EMMC_BOOT */ |
| 342 | } |
Markus Niebel | 0395141 | 2013-12-16 13:40:46 +0100 | [diff] [blame] | 343 | |
| 344 | else if (argc == 3 && strcmp(argv[1], "setdsr") == 0) { |
| 345 | struct mmc *mmc = find_mmc_device(curr_device); |
| 346 | u32 val = simple_strtoul(argv[2], NULL, 16); |
| 347 | int ret; |
| 348 | |
| 349 | if (!mmc) { |
| 350 | printf("no mmc device at slot %x\n", curr_device); |
| 351 | return 1; |
| 352 | } |
| 353 | ret = mmc_set_dsr(mmc, val); |
| 354 | printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR"); |
| 355 | if (!ret) { |
| 356 | mmc->has_init = 0; |
| 357 | if (mmc_init(mmc)) |
| 358 | return 1; |
| 359 | else |
| 360 | return 0; |
| 361 | } |
| 362 | return ret; |
| 363 | } |
| 364 | |
Taylor Hutt | 9cd2f42 | 2012-11-22 09:13:00 +0000 | [diff] [blame] | 365 | state = MMC_INVALID; |
| 366 | if (argc == 5 && strcmp(argv[1], "read") == 0) |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 367 | state = MMC_READ; |
Taylor Hutt | 9cd2f42 | 2012-11-22 09:13:00 +0000 | [diff] [blame] | 368 | else if (argc == 5 && strcmp(argv[1], "write") == 0) |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 369 | state = MMC_WRITE; |
Taylor Hutt | 9cd2f42 | 2012-11-22 09:13:00 +0000 | [diff] [blame] | 370 | else if (argc == 4 && strcmp(argv[1], "erase") == 0) |
Lei Wen | ea52676 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 371 | state = MMC_ERASE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 372 | |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 373 | if (state != MMC_INVALID) { |
| 374 | struct mmc *mmc = find_mmc_device(curr_device); |
Lei Wen | ea52676 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 375 | int idx = 2; |
| 376 | u32 blk, cnt, n; |
| 377 | void *addr; |
| 378 | |
| 379 | if (state != MMC_ERASE) { |
| 380 | addr = (void *)simple_strtoul(argv[idx], NULL, 16); |
| 381 | ++idx; |
| 382 | } else |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 383 | addr = NULL; |
Lei Wen | ea52676 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 384 | blk = simple_strtoul(argv[idx], NULL, 16); |
| 385 | cnt = simple_strtoul(argv[idx + 1], NULL, 16); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 386 | |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 387 | if (!mmc) { |
| 388 | printf("no mmc device at slot %x\n", curr_device); |
| 389 | return 1; |
| 390 | } |
Rabin Vincent | 3e448aa | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 391 | |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 392 | printf("\nMMC %s: dev # %d, block # %d, count %d ... ", |
| 393 | argv[1], curr_device, blk, cnt); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 394 | |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 395 | mmc_init(mmc); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 396 | |
Nikita Kiryanov | 020f261 | 2012-12-03 02:19:46 +0000 | [diff] [blame] | 397 | if ((state == MMC_WRITE || state == MMC_ERASE)) { |
| 398 | if (mmc_getwp(mmc) == 1) { |
| 399 | printf("Error: card is write protected!\n"); |
| 400 | return 1; |
| 401 | } |
| 402 | } |
| 403 | |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 404 | switch (state) { |
| 405 | case MMC_READ: |
| 406 | n = mmc->block_dev.block_read(curr_device, blk, |
| 407 | cnt, addr); |
| 408 | /* flush cache after read */ |
| 409 | flush_cache((ulong)addr, cnt * 512); /* FIXME */ |
| 410 | break; |
| 411 | case MMC_WRITE: |
| 412 | n = mmc->block_dev.block_write(curr_device, blk, |
| 413 | cnt, addr); |
| 414 | break; |
Lei Wen | ea52676 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 415 | case MMC_ERASE: |
| 416 | n = mmc->block_dev.block_erase(curr_device, blk, cnt); |
| 417 | break; |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 418 | default: |
| 419 | BUG(); |
| 420 | } |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 421 | |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 422 | printf("%d blocks %s: %s\n", |
| 423 | n, argv[1], (n == cnt) ? "OK" : "ERROR"); |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 424 | return (n == cnt) ? 0 : 1; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 425 | } |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 426 | |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 427 | return CMD_RET_USAGE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | U_BOOT_CMD( |
| 431 | mmc, 6, 1, do_mmcops, |
Mike Frysinger | 27e1e62 | 2009-03-23 22:27:34 -0400 | [diff] [blame] | 432 | "MMC sub system", |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 433 | "read addr blk# cnt\n" |
| 434 | "mmc write addr blk# cnt\n" |
Lei Wen | ea52676 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 435 | "mmc erase blk# cnt\n" |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 436 | "mmc rescan\n" |
| 437 | "mmc part - lists available partition on current mmc device\n" |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 438 | "mmc dev [dev] [part] - show or set current mmc device [partition]\n" |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 439 | "mmc list - lists available devices\n" |
| 440 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 441 | "mmc open <dev> <boot_partition>\n" |
| 442 | " - Enable boot_part for booting and enable R/W access of boot_part\n" |
| 443 | "mmc close <dev> <boot_partition>\n" |
| 444 | " - Enable boot_part for booting and disable access to boot_part\n" |
| 445 | "mmc bootpart <device num> <boot part size MB> <RPMB part size MB>\n" |
Robert P. J. Day | e3f2c2e | 2013-08-21 11:39:19 -0400 | [diff] [blame] | 446 | " - change sizes of boot and RPMB partitions of specified device\n" |
Dirk Behme | df8852a | 2009-02-18 19:59:39 +0100 | [diff] [blame] | 447 | #endif |
Markus Niebel | 0395141 | 2013-12-16 13:40:46 +0100 | [diff] [blame] | 448 | "mmc setdsr - set DSR register value\n" |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 449 | ); |
| 450 | #endif /* !CONFIG_GENERIC_MMC */ |