wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Kyle Harris, kharris@nexus-tech.net |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 10 | #include <mmc.h> |
| 11 | |
Mike Frysinger | 02e22c2 | 2009-06-14 21:35:21 -0400 | [diff] [blame] | 12 | static int curr_device = -1; |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 13 | #ifndef CONFIG_GENERIC_MMC |
Wolfgang Denk | 54841ab | 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 | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 15 | { |
Minkyu Kang | 869f6bf | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 16 | int dev; |
| 17 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 18 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 19 | return CMD_RET_USAGE; |
Minkyu Kang | 869f6bf | 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 | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 30 | return CMD_RET_USAGE; |
Minkyu Kang | 869f6bf | 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 | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 55 | return CMD_RET_USAGE; |
Minkyu Kang | 869f6bf | 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 | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 60 | return CMD_RET_USAGE; |
Minkyu Kang | 869f6bf | 2009-03-30 14:55:51 +0900 | [diff] [blame] | 61 | } |
| 62 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 66 | U_BOOT_CMD( |
Minkyu Kang | 869f6bf | 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 | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 70 | "mmc device [dev] - show or set current device" |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 71 | ); |
Dirk Behme | 3511b4e | 2009-02-18 19:59:39 +0100 | [diff] [blame] | 72 | #else /* !CONFIG_GENERIC_MMC */ |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 73 | |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 74 | enum mmc_state { |
| 75 | MMC_INVALID, |
| 76 | MMC_READ, |
| 77 | MMC_WRITE, |
Lei Wen | e6f99a5 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 78 | MMC_ERASE, |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 79 | }; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 80 | static void print_mmcinfo(struct mmc *mmc) |
| 81 | { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 82 | printf("Device: %s\n", mmc->cfg->name); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 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 | 64f4a61 | 2013-01-29 19:31:16 +0000 | [diff] [blame] | 93 | (mmc->version >> 8) & 0xf, mmc->version & 0xff); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 94 | |
| 95 | printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No"); |
Minkyu Kang | 940e078 | 2011-01-04 01:04:19 +0000 | [diff] [blame] | 96 | puts("Capacity: "); |
| 97 | print_size(mmc->capacity, "\n"); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 98 | |
| 99 | printf("Bus Width: %d-bit\n", mmc->bus_width); |
| 100 | } |
| 101 | |
Kim Phillips | 088f1b1 | 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 | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 103 | { |
| 104 | struct mmc *mmc; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 105 | |
Lei Wen | ea6ebe2 | 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 | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 114 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 115 | mmc = find_mmc_device(curr_device); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 116 | |
| 117 | if (mmc) { |
| 118 | mmc_init(mmc); |
| 119 | |
| 120 | print_mmcinfo(mmc); |
Lei Wen | ea6ebe2 | 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 | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 125 | } |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Frans Meulenbroeks | 388a29d | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 128 | U_BOOT_CMD( |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 129 | mmcinfo, 1, 0, do_mmcinfo, |
Frans Meulenbroeks | cc9f607 | 2010-07-31 15:01:52 +0200 | [diff] [blame] | 130 | "display MMC info", |
Robert P. J. Day | 59ddead | 2012-11-11 03:24:44 +0000 | [diff] [blame] | 131 | "- display info of the current MMC device" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 132 | ); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 133 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 134 | static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 135 | { |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 136 | enum mmc_state state; |
| 137 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 138 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 139 | return CMD_RET_USAGE; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 140 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 141 | if (curr_device < 0) { |
| 142 | if (get_mmc_num() > 0) |
| 143 | curr_device = 0; |
| 144 | else { |
| 145 | puts("No MMC device available\n"); |
| 146 | return 1; |
| 147 | } |
| 148 | } |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 149 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 150 | if (strcmp(argv[1], "rescan") == 0) { |
Stephen Warren | 9fd3837 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 151 | struct mmc *mmc; |
Rabin Vincent | e85649c | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 152 | |
Stephen Warren | 9fd3837 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 153 | if (argc != 2) |
| 154 | return CMD_RET_USAGE; |
| 155 | |
| 156 | mmc = find_mmc_device(curr_device); |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 157 | if (!mmc) { |
| 158 | printf("no mmc device at slot %x\n", curr_device); |
Lei Wen | 8f3b964 | 2010-09-13 22:07:28 +0800 | [diff] [blame] | 159 | return 1; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 160 | } |
| 161 | |
Lei Wen | bc897b1 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 162 | mmc->has_init = 0; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 163 | |
Michael Jones | 8fd01b8 | 2011-07-14 23:09:43 +0000 | [diff] [blame] | 164 | if (mmc_init(mmc)) |
| 165 | return 1; |
| 166 | else |
| 167 | return 0; |
Tom Rini | 792970b | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 168 | } else if (strcmp(argv[1], "part") == 0) { |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 169 | block_dev_desc_t *mmc_dev; |
Stephen Warren | 9fd3837 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 170 | struct mmc *mmc; |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 171 | |
Stephen Warren | 9fd3837 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 172 | if (argc != 2) |
| 173 | return CMD_RET_USAGE; |
| 174 | |
| 175 | mmc = find_mmc_device(curr_device); |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 176 | if (!mmc) { |
| 177 | printf("no mmc device at slot %x\n", curr_device); |
| 178 | return 1; |
| 179 | } |
| 180 | mmc_init(mmc); |
| 181 | mmc_dev = mmc_get_dev(curr_device); |
| 182 | if (mmc_dev != NULL && |
| 183 | mmc_dev->type != DEV_TYPE_UNKNOWN) { |
| 184 | print_part(mmc_dev); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 185 | return 0; |
| 186 | } |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 187 | |
| 188 | puts("get mmc type error!\n"); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 189 | return 1; |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 190 | } else if (strcmp(argv[1], "list") == 0) { |
Stephen Warren | 9fd3837 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 191 | if (argc != 2) |
| 192 | return CMD_RET_USAGE; |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 193 | print_mmc_devices('\n'); |
| 194 | return 0; |
| 195 | } else if (strcmp(argv[1], "dev") == 0) { |
Lei Wen | bc897b1 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 196 | int dev, part = -1; |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 197 | struct mmc *mmc; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 198 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 199 | if (argc == 2) |
| 200 | dev = curr_device; |
| 201 | else if (argc == 3) |
| 202 | dev = simple_strtoul(argv[2], NULL, 10); |
Lei Wen | bc897b1 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 203 | else if (argc == 4) { |
| 204 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 205 | part = (int)simple_strtoul(argv[3], NULL, 10); |
| 206 | if (part > PART_ACCESS_MASK) { |
| 207 | printf("#part_num shouldn't be larger" |
| 208 | " than %d\n", PART_ACCESS_MASK); |
| 209 | return 1; |
| 210 | } |
| 211 | } else |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 212 | return CMD_RET_USAGE; |
Rabin Vincent | e85649c | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 213 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 214 | mmc = find_mmc_device(dev); |
| 215 | if (!mmc) { |
| 216 | printf("no mmc device at slot %x\n", dev); |
| 217 | return 1; |
| 218 | } |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 219 | |
Lei Wen | bc897b1 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 220 | mmc_init(mmc); |
| 221 | if (part != -1) { |
| 222 | int ret; |
| 223 | if (mmc->part_config == MMCPART_NOAVAILABLE) { |
| 224 | printf("Card doesn't support part_switch\n"); |
| 225 | return 1; |
| 226 | } |
| 227 | |
| 228 | if (part != mmc->part_num) { |
| 229 | ret = mmc_switch_part(dev, part); |
| 230 | if (!ret) |
| 231 | mmc->part_num = part; |
| 232 | |
Robert P. J. Day | 1f8b546 | 2013-08-21 11:39:19 -0400 | [diff] [blame] | 233 | printf("switch to partitions #%d, %s\n", |
Lei Wen | bc897b1 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 234 | part, (!ret) ? "OK" : "ERROR"); |
| 235 | } |
| 236 | } |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 237 | curr_device = dev; |
Lei Wen | bc897b1 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 238 | if (mmc->part_config == MMCPART_NOAVAILABLE) |
| 239 | printf("mmc%d is current device\n", curr_device); |
| 240 | else |
| 241 | printf("mmc%d(part %d) is current device\n", |
| 242 | curr_device, mmc->part_num); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 243 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 244 | return 0; |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 245 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
Tom Rini | 792970b | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 246 | } else if (strcmp(argv[1], "partconf") == 0) { |
| 247 | int dev; |
| 248 | struct mmc *mmc; |
| 249 | u8 ack, part_num, access; |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 250 | |
Tom Rini | 792970b | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 251 | if (argc == 6) { |
| 252 | dev = simple_strtoul(argv[2], NULL, 10); |
| 253 | ack = simple_strtoul(argv[3], NULL, 10); |
| 254 | part_num = simple_strtoul(argv[4], NULL, 10); |
| 255 | access = simple_strtoul(argv[5], NULL, 10); |
| 256 | } else { |
| 257 | return CMD_RET_USAGE; |
| 258 | } |
| 259 | |
| 260 | mmc = find_mmc_device(dev); |
| 261 | if (!mmc) { |
| 262 | printf("no mmc device at slot %x\n", dev); |
| 263 | return 1; |
| 264 | } |
| 265 | |
| 266 | if (IS_SD(mmc)) { |
| 267 | puts("PARTITION_CONFIG only exists on eMMC\n"); |
| 268 | return 1; |
| 269 | } |
| 270 | |
| 271 | /* acknowledge to be sent during boot operation */ |
| 272 | return mmc_set_part_conf(mmc, ack, part_num, access); |
Tom Rini | 5a99b9d | 2014-02-05 10:24:22 -0500 | [diff] [blame] | 273 | } else if (strcmp(argv[1], "bootbus") == 0) { |
| 274 | int dev; |
| 275 | struct mmc *mmc; |
| 276 | u8 width, reset, mode; |
| 277 | |
| 278 | if (argc == 6) { |
| 279 | dev = simple_strtoul(argv[2], NULL, 10); |
| 280 | width = simple_strtoul(argv[3], NULL, 10); |
| 281 | reset = simple_strtoul(argv[4], NULL, 10); |
| 282 | mode = simple_strtoul(argv[5], NULL, 10); |
| 283 | } else { |
| 284 | return CMD_RET_USAGE; |
| 285 | } |
| 286 | |
| 287 | mmc = find_mmc_device(dev); |
| 288 | if (!mmc) { |
| 289 | printf("no mmc device at slot %x\n", dev); |
| 290 | return 1; |
| 291 | } |
| 292 | |
| 293 | if (IS_SD(mmc)) { |
| 294 | puts("BOOT_BUS_WIDTH only exists on eMMC\n"); |
| 295 | return 1; |
| 296 | } |
| 297 | |
| 298 | /* acknowledge to be sent during boot operation */ |
| 299 | return mmc_set_boot_bus_width(mmc, width, reset, mode); |
Tom Rini | f1fd957 | 2014-02-05 10:24:20 -0500 | [diff] [blame] | 300 | } else if (strcmp(argv[1], "bootpart-resize") == 0) { |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 301 | int dev; |
Tom Rini | f1fd957 | 2014-02-05 10:24:20 -0500 | [diff] [blame] | 302 | struct mmc *mmc; |
Tom Rini | b01e6fe | 2014-02-05 10:24:19 -0500 | [diff] [blame] | 303 | u32 bootsize, rpmbsize; |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 304 | |
Tom Rini | b01e6fe | 2014-02-05 10:24:19 -0500 | [diff] [blame] | 305 | if (argc == 5) { |
| 306 | dev = simple_strtoul(argv[2], NULL, 10); |
| 307 | bootsize = simple_strtoul(argv[3], NULL, 10); |
| 308 | rpmbsize = simple_strtoul(argv[4], NULL, 10); |
| 309 | } else { |
| 310 | return CMD_RET_USAGE; |
| 311 | } |
| 312 | |
| 313 | mmc = find_mmc_device(dev); |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 314 | if (!mmc) { |
| 315 | printf("no mmc device at slot %x\n", dev); |
| 316 | return 1; |
| 317 | } |
| 318 | |
| 319 | if (IS_SD(mmc)) { |
| 320 | printf("It is not a EMMC device\n"); |
| 321 | return 1; |
| 322 | } |
| 323 | |
| 324 | if (0 == mmc_boot_partition_size_change(mmc, |
| 325 | bootsize, rpmbsize)) { |
| 326 | printf("EMMC boot partition Size %d MB\n", bootsize); |
| 327 | printf("EMMC RPMB partition Size %d MB\n", rpmbsize); |
| 328 | return 0; |
| 329 | } else { |
| 330 | printf("EMMC boot partition Size change Failed.\n"); |
| 331 | return 1; |
| 332 | } |
Tom Rini | 33ace36 | 2014-02-07 14:15:20 -0500 | [diff] [blame] | 333 | } else if (strcmp(argv[1], "rst-function") == 0) { |
| 334 | /* |
| 335 | * Set the RST_n_ENABLE bit of RST_n_FUNCTION |
| 336 | * The only valid values are 0x0, 0x1 and 0x2 and writing |
| 337 | * a value of 0x1 or 0x2 sets the value permanently. |
| 338 | */ |
| 339 | int dev; |
| 340 | struct mmc *mmc; |
| 341 | u8 enable; |
| 342 | |
| 343 | if (argc == 4) { |
| 344 | dev = simple_strtoul(argv[2], NULL, 10); |
| 345 | enable = simple_strtoul(argv[3], NULL, 10); |
| 346 | } else { |
| 347 | return CMD_RET_USAGE; |
| 348 | } |
| 349 | |
| 350 | if (enable > 2 || enable < 0) { |
| 351 | puts("Invalid RST_n_ENABLE value\n"); |
| 352 | return CMD_RET_USAGE; |
| 353 | } |
| 354 | |
| 355 | mmc = find_mmc_device(dev); |
| 356 | if (!mmc) { |
| 357 | printf("no mmc device at slot %x\n", dev); |
| 358 | return 1; |
| 359 | } |
| 360 | |
| 361 | if (IS_SD(mmc)) { |
| 362 | puts("RST_n_FUNCTION only exists on eMMC\n"); |
| 363 | return 1; |
| 364 | } |
| 365 | |
| 366 | return mmc_set_rst_n_function(mmc, enable); |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 367 | #endif /* CONFIG_SUPPORT_EMMC_BOOT */ |
| 368 | } |
Markus Niebel | ab71188 | 2013-12-16 13:40:46 +0100 | [diff] [blame] | 369 | |
| 370 | else if (argc == 3 && strcmp(argv[1], "setdsr") == 0) { |
| 371 | struct mmc *mmc = find_mmc_device(curr_device); |
| 372 | u32 val = simple_strtoul(argv[2], NULL, 16); |
| 373 | int ret; |
| 374 | |
| 375 | if (!mmc) { |
| 376 | printf("no mmc device at slot %x\n", curr_device); |
| 377 | return 1; |
| 378 | } |
| 379 | ret = mmc_set_dsr(mmc, val); |
| 380 | printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR"); |
| 381 | if (!ret) { |
| 382 | mmc->has_init = 0; |
| 383 | if (mmc_init(mmc)) |
| 384 | return 1; |
| 385 | else |
| 386 | return 0; |
| 387 | } |
| 388 | return ret; |
| 389 | } |
| 390 | |
Taylor Hutt | ed80c93 | 2012-11-22 09:13:00 +0000 | [diff] [blame] | 391 | state = MMC_INVALID; |
| 392 | if (argc == 5 && strcmp(argv[1], "read") == 0) |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 393 | state = MMC_READ; |
Taylor Hutt | ed80c93 | 2012-11-22 09:13:00 +0000 | [diff] [blame] | 394 | else if (argc == 5 && strcmp(argv[1], "write") == 0) |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 395 | state = MMC_WRITE; |
Taylor Hutt | ed80c93 | 2012-11-22 09:13:00 +0000 | [diff] [blame] | 396 | else if (argc == 4 && strcmp(argv[1], "erase") == 0) |
Lei Wen | e6f99a5 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 397 | state = MMC_ERASE; |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 398 | |
| 399 | if (state != MMC_INVALID) { |
| 400 | struct mmc *mmc = find_mmc_device(curr_device); |
Lei Wen | e6f99a5 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 401 | int idx = 2; |
| 402 | u32 blk, cnt, n; |
| 403 | void *addr; |
| 404 | |
| 405 | if (state != MMC_ERASE) { |
| 406 | addr = (void *)simple_strtoul(argv[idx], NULL, 16); |
| 407 | ++idx; |
| 408 | } else |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 409 | addr = NULL; |
Lei Wen | e6f99a5 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 410 | blk = simple_strtoul(argv[idx], NULL, 16); |
| 411 | cnt = simple_strtoul(argv[idx + 1], NULL, 16); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 412 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 413 | if (!mmc) { |
| 414 | printf("no mmc device at slot %x\n", curr_device); |
| 415 | return 1; |
| 416 | } |
Rabin Vincent | e85649c | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 417 | |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 418 | printf("\nMMC %s: dev # %d, block # %d, count %d ... ", |
| 419 | argv[1], curr_device, blk, cnt); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 420 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 421 | mmc_init(mmc); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 422 | |
Nikita Kiryanov | d23d8d7 | 2012-12-03 02:19:46 +0000 | [diff] [blame] | 423 | if ((state == MMC_WRITE || state == MMC_ERASE)) { |
| 424 | if (mmc_getwp(mmc) == 1) { |
| 425 | printf("Error: card is write protected!\n"); |
| 426 | return 1; |
| 427 | } |
| 428 | } |
| 429 | |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 430 | switch (state) { |
| 431 | case MMC_READ: |
| 432 | n = mmc->block_dev.block_read(curr_device, blk, |
| 433 | cnt, addr); |
| 434 | /* flush cache after read */ |
| 435 | flush_cache((ulong)addr, cnt * 512); /* FIXME */ |
| 436 | break; |
| 437 | case MMC_WRITE: |
| 438 | n = mmc->block_dev.block_write(curr_device, blk, |
| 439 | cnt, addr); |
| 440 | break; |
Lei Wen | e6f99a5 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 441 | case MMC_ERASE: |
| 442 | n = mmc->block_dev.block_erase(curr_device, blk, cnt); |
| 443 | break; |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 444 | default: |
| 445 | BUG(); |
| 446 | } |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 447 | |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 448 | printf("%d blocks %s: %s\n", |
| 449 | n, argv[1], (n == cnt) ? "OK" : "ERROR"); |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 450 | return (n == cnt) ? 0 : 1; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 451 | } |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 452 | |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 453 | return CMD_RET_USAGE; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | U_BOOT_CMD( |
| 457 | mmc, 6, 1, do_mmcops, |
Mike Frysinger | 852dbfd | 2009-03-23 22:27:34 -0400 | [diff] [blame] | 458 | "MMC sub system", |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 459 | "read addr blk# cnt\n" |
| 460 | "mmc write addr blk# cnt\n" |
Lei Wen | e6f99a5 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 461 | "mmc erase blk# cnt\n" |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 462 | "mmc rescan\n" |
| 463 | "mmc part - lists available partition on current mmc device\n" |
Lei Wen | bc897b1 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 464 | "mmc dev [dev] [part] - show or set current mmc device [partition]\n" |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 465 | "mmc list - lists available devices\n" |
| 466 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
Tom Rini | 5a99b9d | 2014-02-05 10:24:22 -0500 | [diff] [blame] | 467 | "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n" |
| 468 | " - Set the BOOT_BUS_WIDTH field of the specified device\n" |
Tom Rini | f1fd957 | 2014-02-05 10:24:20 -0500 | [diff] [blame] | 469 | "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n" |
| 470 | " - Change sizes of boot and RPMB partitions of specified device\n" |
Tom Rini | 792970b | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 471 | "mmc partconf dev boot_ack boot_partition partition_access\n" |
| 472 | " - Change the bits of the PARTITION_CONFIG field of the specified device\n" |
Tom Rini | 33ace36 | 2014-02-07 14:15:20 -0500 | [diff] [blame] | 473 | "mmc rst-function dev value\n" |
| 474 | " - Change the RST_n_FUNCTION field of the specified device\n" |
| 475 | " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n" |
Dirk Behme | 3511b4e | 2009-02-18 19:59:39 +0100 | [diff] [blame] | 476 | #endif |
Markus Niebel | ab71188 | 2013-12-16 13:40:46 +0100 | [diff] [blame] | 477 | "mmc setdsr - set DSR register value\n" |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 478 | ); |
| 479 | #endif /* !CONFIG_GENERIC_MMC */ |