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 | |
| 74 | static void print_mmcinfo(struct mmc *mmc) |
| 75 | { |
Diego Santa Cruz | c5f0d3f | 2014-12-23 10:50:16 +0100 | [diff] [blame] | 76 | int i; |
| 77 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 78 | printf("Device: %s\n", mmc->cfg->name); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 79 | printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24); |
| 80 | printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff); |
| 81 | printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff, |
| 82 | (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff, |
| 83 | (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff); |
| 84 | |
| 85 | printf("Tran Speed: %d\n", mmc->tran_speed); |
| 86 | printf("Rd Block Len: %d\n", mmc->read_bl_len); |
| 87 | |
Pantelis Antoniou | 4b7cee5 | 2015-01-23 12:12:01 +0200 | [diff] [blame] | 88 | printf("%s version %d.%d", IS_SD(mmc) ? "SD" : "MMC", |
| 89 | EXTRACT_SDMMC_MAJOR_VERSION(mmc->version), |
| 90 | EXTRACT_SDMMC_MINOR_VERSION(mmc->version)); |
| 91 | if (EXTRACT_SDMMC_CHANGE_VERSION(mmc->version) != 0) |
| 92 | printf(".%d", EXTRACT_SDMMC_CHANGE_VERSION(mmc->version)); |
| 93 | printf("\n"); |
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 | |
Andrew Gabbasov | 786e8f8 | 2014-12-01 06:59:09 -0600 | [diff] [blame] | 99 | printf("Bus Width: %d-bit%s\n", mmc->bus_width, |
| 100 | mmc->ddr_mode ? " DDR" : ""); |
Diego Santa Cruz | c5f0d3f | 2014-12-23 10:50:16 +0100 | [diff] [blame] | 101 | |
Diego Santa Cruz | b036152 | 2014-12-23 10:50:26 +0100 | [diff] [blame] | 102 | puts("Erase Group Size: "); |
| 103 | print_size(((u64)mmc->erase_grp_size) << 9, "\n"); |
| 104 | |
Diego Santa Cruz | 525ada2 | 2014-12-23 10:50:19 +0100 | [diff] [blame] | 105 | if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) { |
Diego Santa Cruz | c3dbb4f | 2014-12-23 10:50:17 +0100 | [diff] [blame] | 106 | bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0; |
Diego Santa Cruz | beb98a1 | 2014-12-23 10:50:23 +0100 | [diff] [blame] | 107 | bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR); |
Diego Santa Cruz | b036152 | 2014-12-23 10:50:26 +0100 | [diff] [blame] | 108 | |
| 109 | puts("HC WP Group Size: "); |
| 110 | print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n"); |
| 111 | |
Diego Santa Cruz | c5f0d3f | 2014-12-23 10:50:16 +0100 | [diff] [blame] | 112 | puts("User Capacity: "); |
Diego Santa Cruz | 9e41a00 | 2014-12-23 10:50:33 +0100 | [diff] [blame] | 113 | print_size(mmc->capacity_user, usr_enh ? " ENH" : ""); |
| 114 | if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_USR) |
| 115 | puts(" WRREL\n"); |
| 116 | else |
| 117 | putc('\n'); |
Diego Santa Cruz | beb98a1 | 2014-12-23 10:50:23 +0100 | [diff] [blame] | 118 | if (usr_enh) { |
| 119 | puts("User Enhanced Start: "); |
| 120 | print_size(mmc->enh_user_start, "\n"); |
| 121 | puts("User Enhanced Size: "); |
| 122 | print_size(mmc->enh_user_size, "\n"); |
| 123 | } |
Diego Santa Cruz | c5f0d3f | 2014-12-23 10:50:16 +0100 | [diff] [blame] | 124 | puts("Boot Capacity: "); |
Diego Santa Cruz | c3dbb4f | 2014-12-23 10:50:17 +0100 | [diff] [blame] | 125 | print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n"); |
Diego Santa Cruz | c5f0d3f | 2014-12-23 10:50:16 +0100 | [diff] [blame] | 126 | puts("RPMB Capacity: "); |
Diego Santa Cruz | c3dbb4f | 2014-12-23 10:50:17 +0100 | [diff] [blame] | 127 | print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n"); |
Diego Santa Cruz | b036152 | 2014-12-23 10:50:26 +0100 | [diff] [blame] | 128 | |
Diego Santa Cruz | c5f0d3f | 2014-12-23 10:50:16 +0100 | [diff] [blame] | 129 | for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) { |
Diego Santa Cruz | c3dbb4f | 2014-12-23 10:50:17 +0100 | [diff] [blame] | 130 | bool is_enh = has_enh && |
| 131 | (mmc->part_attr & EXT_CSD_ENH_GP(i)); |
Diego Santa Cruz | c5f0d3f | 2014-12-23 10:50:16 +0100 | [diff] [blame] | 132 | if (mmc->capacity_gp[i]) { |
Diego Santa Cruz | f289fd7 | 2014-12-23 10:50:18 +0100 | [diff] [blame] | 133 | printf("GP%i Capacity: ", i+1); |
Diego Santa Cruz | c3dbb4f | 2014-12-23 10:50:17 +0100 | [diff] [blame] | 134 | print_size(mmc->capacity_gp[i], |
Diego Santa Cruz | 9e41a00 | 2014-12-23 10:50:33 +0100 | [diff] [blame] | 135 | is_enh ? " ENH" : ""); |
| 136 | if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_GP(i)) |
| 137 | puts(" WRREL\n"); |
| 138 | else |
| 139 | putc('\n'); |
Diego Santa Cruz | c5f0d3f | 2014-12-23 10:50:16 +0100 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | } |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 143 | } |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 144 | static struct mmc *init_mmc_device(int dev, bool force_init) |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 145 | { |
| 146 | struct mmc *mmc; |
| 147 | mmc = find_mmc_device(dev); |
| 148 | if (!mmc) { |
| 149 | printf("no mmc device at slot %x\n", dev); |
| 150 | return NULL; |
| 151 | } |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 152 | if (force_init) |
| 153 | mmc->has_init = 0; |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 154 | if (mmc_init(mmc)) |
| 155 | return NULL; |
| 156 | return mmc; |
| 157 | } |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 158 | 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] | 159 | { |
| 160 | struct mmc *mmc; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 161 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 162 | if (curr_device < 0) { |
| 163 | if (get_mmc_num() > 0) |
| 164 | curr_device = 0; |
| 165 | else { |
| 166 | puts("No MMC device available\n"); |
| 167 | return 1; |
| 168 | } |
| 169 | } |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 170 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 171 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 172 | if (!mmc) |
| 173 | return CMD_RET_FAILURE; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 174 | |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 175 | print_mmcinfo(mmc); |
| 176 | return CMD_RET_SUCCESS; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 177 | } |
| 178 | |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 179 | #ifdef CONFIG_SUPPORT_EMMC_RPMB |
| 180 | static int confirm_key_prog(void) |
| 181 | { |
| 182 | puts("Warning: Programming authentication key can be done only once !\n" |
| 183 | " Use this command only if you are sure of what you are doing,\n" |
| 184 | "Really perform the key programming? <y/N> "); |
| 185 | if (confirm_yesno()) |
| 186 | return 1; |
| 187 | |
| 188 | puts("Authentication key programming aborted\n"); |
| 189 | return 0; |
| 190 | } |
| 191 | static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag, |
| 192 | int argc, char * const argv[]) |
| 193 | { |
| 194 | void *key_addr; |
| 195 | struct mmc *mmc = find_mmc_device(curr_device); |
| 196 | |
| 197 | if (argc != 2) |
| 198 | return CMD_RET_USAGE; |
| 199 | |
| 200 | key_addr = (void *)simple_strtoul(argv[1], NULL, 16); |
| 201 | if (!confirm_key_prog()) |
| 202 | return CMD_RET_FAILURE; |
| 203 | if (mmc_rpmb_set_key(mmc, key_addr)) { |
| 204 | printf("ERROR - Key already programmed ?\n"); |
| 205 | return CMD_RET_FAILURE; |
| 206 | } |
| 207 | return CMD_RET_SUCCESS; |
| 208 | } |
| 209 | static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag, |
| 210 | int argc, char * const argv[]) |
| 211 | { |
| 212 | u16 blk, cnt; |
| 213 | void *addr; |
| 214 | int n; |
| 215 | void *key_addr = NULL; |
| 216 | struct mmc *mmc = find_mmc_device(curr_device); |
| 217 | |
| 218 | if (argc < 4) |
| 219 | return CMD_RET_USAGE; |
| 220 | |
| 221 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
| 222 | blk = simple_strtoul(argv[2], NULL, 16); |
| 223 | cnt = simple_strtoul(argv[3], NULL, 16); |
| 224 | |
| 225 | if (argc == 5) |
| 226 | key_addr = (void *)simple_strtoul(argv[4], NULL, 16); |
| 227 | |
| 228 | printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ", |
| 229 | curr_device, blk, cnt); |
| 230 | n = mmc_rpmb_read(mmc, addr, blk, cnt, key_addr); |
| 231 | |
| 232 | printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR"); |
| 233 | if (n != cnt) |
| 234 | return CMD_RET_FAILURE; |
| 235 | return CMD_RET_SUCCESS; |
| 236 | } |
| 237 | static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag, |
| 238 | int argc, char * const argv[]) |
| 239 | { |
| 240 | u16 blk, cnt; |
| 241 | void *addr; |
| 242 | int n; |
| 243 | void *key_addr; |
| 244 | struct mmc *mmc = find_mmc_device(curr_device); |
| 245 | |
| 246 | if (argc != 5) |
| 247 | return CMD_RET_USAGE; |
| 248 | |
| 249 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
| 250 | blk = simple_strtoul(argv[2], NULL, 16); |
| 251 | cnt = simple_strtoul(argv[3], NULL, 16); |
| 252 | key_addr = (void *)simple_strtoul(argv[4], NULL, 16); |
| 253 | |
| 254 | printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ", |
| 255 | curr_device, blk, cnt); |
| 256 | n = mmc_rpmb_write(mmc, addr, blk, cnt, key_addr); |
| 257 | |
| 258 | printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR"); |
| 259 | if (n != cnt) |
| 260 | return CMD_RET_FAILURE; |
| 261 | return CMD_RET_SUCCESS; |
| 262 | } |
| 263 | static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag, |
| 264 | int argc, char * const argv[]) |
| 265 | { |
| 266 | unsigned long counter; |
| 267 | struct mmc *mmc = find_mmc_device(curr_device); |
| 268 | |
| 269 | if (mmc_rpmb_get_counter(mmc, &counter)) |
| 270 | return CMD_RET_FAILURE; |
| 271 | printf("RPMB Write counter= %lx\n", counter); |
| 272 | return CMD_RET_SUCCESS; |
| 273 | } |
| 274 | |
| 275 | static cmd_tbl_t cmd_rpmb[] = { |
| 276 | U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""), |
| 277 | U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""), |
| 278 | U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""), |
| 279 | U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""), |
| 280 | }; |
| 281 | |
| 282 | static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag, |
| 283 | int argc, char * const argv[]) |
| 284 | { |
| 285 | cmd_tbl_t *cp; |
| 286 | struct mmc *mmc; |
| 287 | char original_part; |
| 288 | int ret; |
| 289 | |
| 290 | cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb)); |
| 291 | |
| 292 | /* Drop the rpmb subcommand */ |
| 293 | argc--; |
| 294 | argv++; |
| 295 | |
| 296 | if (cp == NULL || argc > cp->maxargs) |
| 297 | return CMD_RET_USAGE; |
| 298 | if (flag == CMD_FLAG_REPEAT && !cp->repeatable) |
| 299 | return CMD_RET_SUCCESS; |
| 300 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 301 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 302 | if (!mmc) |
| 303 | return CMD_RET_FAILURE; |
| 304 | |
| 305 | if (!(mmc->version & MMC_VERSION_MMC)) { |
| 306 | printf("It is not a EMMC device\n"); |
| 307 | return CMD_RET_FAILURE; |
| 308 | } |
| 309 | if (mmc->version < MMC_VERSION_4_41) { |
| 310 | printf("RPMB not supported before version 4.41\n"); |
| 311 | return CMD_RET_FAILURE; |
| 312 | } |
| 313 | /* Switch to the RPMB partition */ |
| 314 | original_part = mmc->part_num; |
| 315 | if (mmc->part_num != MMC_PART_RPMB) { |
| 316 | if (mmc_switch_part(curr_device, MMC_PART_RPMB) != 0) |
| 317 | return CMD_RET_FAILURE; |
| 318 | mmc->part_num = MMC_PART_RPMB; |
| 319 | } |
| 320 | ret = cp->cmd(cmdtp, flag, argc, argv); |
| 321 | |
| 322 | /* Return to original partition */ |
| 323 | if (mmc->part_num != original_part) { |
| 324 | if (mmc_switch_part(curr_device, original_part) != 0) |
| 325 | return CMD_RET_FAILURE; |
| 326 | mmc->part_num = original_part; |
| 327 | } |
| 328 | return ret; |
| 329 | } |
| 330 | #endif |
| 331 | |
| 332 | static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, |
| 333 | int argc, char * const argv[]) |
| 334 | { |
| 335 | struct mmc *mmc; |
| 336 | u32 blk, cnt, n; |
| 337 | void *addr; |
| 338 | |
| 339 | if (argc != 4) |
| 340 | return CMD_RET_USAGE; |
| 341 | |
| 342 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
| 343 | blk = simple_strtoul(argv[2], NULL, 16); |
| 344 | cnt = simple_strtoul(argv[3], NULL, 16); |
| 345 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 346 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 347 | if (!mmc) |
| 348 | return CMD_RET_FAILURE; |
| 349 | |
| 350 | printf("\nMMC read: dev # %d, block # %d, count %d ... ", |
| 351 | curr_device, blk, cnt); |
| 352 | |
| 353 | n = mmc->block_dev.block_read(curr_device, blk, cnt, addr); |
| 354 | /* flush cache after read */ |
| 355 | flush_cache((ulong)addr, cnt * 512); /* FIXME */ |
| 356 | printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR"); |
| 357 | |
| 358 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
| 359 | } |
| 360 | static int do_mmc_write(cmd_tbl_t *cmdtp, int flag, |
| 361 | int argc, char * const argv[]) |
| 362 | { |
| 363 | struct mmc *mmc; |
| 364 | u32 blk, cnt, n; |
| 365 | void *addr; |
| 366 | |
| 367 | if (argc != 4) |
| 368 | return CMD_RET_USAGE; |
| 369 | |
| 370 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
| 371 | blk = simple_strtoul(argv[2], NULL, 16); |
| 372 | cnt = simple_strtoul(argv[3], NULL, 16); |
| 373 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 374 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 375 | if (!mmc) |
| 376 | return CMD_RET_FAILURE; |
| 377 | |
| 378 | printf("\nMMC write: dev # %d, block # %d, count %d ... ", |
| 379 | curr_device, blk, cnt); |
| 380 | |
| 381 | if (mmc_getwp(mmc) == 1) { |
| 382 | printf("Error: card is write protected!\n"); |
| 383 | return CMD_RET_FAILURE; |
| 384 | } |
| 385 | n = mmc->block_dev.block_write(curr_device, blk, cnt, addr); |
| 386 | printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR"); |
| 387 | |
| 388 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
| 389 | } |
| 390 | static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag, |
| 391 | int argc, char * const argv[]) |
| 392 | { |
| 393 | struct mmc *mmc; |
| 394 | u32 blk, cnt, n; |
| 395 | |
| 396 | if (argc != 3) |
| 397 | return CMD_RET_USAGE; |
| 398 | |
| 399 | blk = simple_strtoul(argv[1], NULL, 16); |
| 400 | cnt = simple_strtoul(argv[2], NULL, 16); |
| 401 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 402 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 403 | if (!mmc) |
| 404 | return CMD_RET_FAILURE; |
| 405 | |
| 406 | printf("\nMMC erase: dev # %d, block # %d, count %d ... ", |
| 407 | curr_device, blk, cnt); |
| 408 | |
| 409 | if (mmc_getwp(mmc) == 1) { |
| 410 | printf("Error: card is write protected!\n"); |
| 411 | return CMD_RET_FAILURE; |
| 412 | } |
| 413 | n = mmc->block_dev.block_erase(curr_device, blk, cnt); |
| 414 | printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR"); |
| 415 | |
| 416 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
| 417 | } |
| 418 | static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag, |
| 419 | int argc, char * const argv[]) |
| 420 | { |
| 421 | struct mmc *mmc; |
| 422 | |
Stephen Warren | 941944e | 2014-05-23 13:24:46 -0600 | [diff] [blame] | 423 | mmc = init_mmc_device(curr_device, true); |
| 424 | if (!mmc) |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 425 | return CMD_RET_FAILURE; |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 426 | |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 427 | return CMD_RET_SUCCESS; |
| 428 | } |
| 429 | static int do_mmc_part(cmd_tbl_t *cmdtp, int flag, |
| 430 | int argc, char * const argv[]) |
| 431 | { |
| 432 | block_dev_desc_t *mmc_dev; |
| 433 | struct mmc *mmc; |
| 434 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 435 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 436 | if (!mmc) |
| 437 | return CMD_RET_FAILURE; |
| 438 | |
| 439 | mmc_dev = mmc_get_dev(curr_device); |
| 440 | if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) { |
| 441 | print_part(mmc_dev); |
| 442 | return CMD_RET_SUCCESS; |
| 443 | } |
| 444 | |
| 445 | puts("get mmc type error!\n"); |
| 446 | return CMD_RET_FAILURE; |
| 447 | } |
| 448 | static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag, |
| 449 | int argc, char * const argv[]) |
| 450 | { |
Stephen Warren | 60dc58f | 2014-05-23 12:48:10 -0600 | [diff] [blame] | 451 | int dev, part = 0, ret; |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 452 | struct mmc *mmc; |
| 453 | |
| 454 | if (argc == 1) { |
| 455 | dev = curr_device; |
| 456 | } else if (argc == 2) { |
| 457 | dev = simple_strtoul(argv[1], NULL, 10); |
| 458 | } else if (argc == 3) { |
| 459 | dev = (int)simple_strtoul(argv[1], NULL, 10); |
| 460 | part = (int)simple_strtoul(argv[2], NULL, 10); |
| 461 | if (part > PART_ACCESS_MASK) { |
| 462 | printf("#part_num shouldn't be larger than %d\n", |
| 463 | PART_ACCESS_MASK); |
| 464 | return CMD_RET_FAILURE; |
| 465 | } |
| 466 | } else { |
| 467 | return CMD_RET_USAGE; |
| 468 | } |
| 469 | |
Stephen Warren | a571092 | 2014-05-23 13:24:47 -0600 | [diff] [blame] | 470 | mmc = init_mmc_device(dev, true); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 471 | if (!mmc) |
| 472 | return CMD_RET_FAILURE; |
| 473 | |
Stephen Warren | 60dc58f | 2014-05-23 12:48:10 -0600 | [diff] [blame] | 474 | ret = mmc_select_hwpart(dev, part); |
| 475 | printf("switch to partitions #%d, %s\n", |
| 476 | part, (!ret) ? "OK" : "ERROR"); |
| 477 | if (ret) |
| 478 | return 1; |
| 479 | |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 480 | curr_device = dev; |
| 481 | if (mmc->part_config == MMCPART_NOAVAILABLE) |
| 482 | printf("mmc%d is current device\n", curr_device); |
| 483 | else |
| 484 | printf("mmc%d(part %d) is current device\n", |
| 485 | curr_device, mmc->part_num); |
| 486 | |
| 487 | return CMD_RET_SUCCESS; |
| 488 | } |
| 489 | static int do_mmc_list(cmd_tbl_t *cmdtp, int flag, |
| 490 | int argc, char * const argv[]) |
| 491 | { |
| 492 | print_mmc_devices('\n'); |
| 493 | return CMD_RET_SUCCESS; |
| 494 | } |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 495 | |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 496 | static int parse_hwpart_user(struct mmc_hwpart_conf *pconf, |
| 497 | int argc, char * const argv[]) |
| 498 | { |
| 499 | int i = 0; |
| 500 | |
| 501 | memset(&pconf->user, 0, sizeof(pconf->user)); |
| 502 | |
| 503 | while (i < argc) { |
| 504 | if (!strcmp(argv[i], "enh")) { |
| 505 | if (i + 2 >= argc) |
| 506 | return -1; |
| 507 | pconf->user.enh_start = |
| 508 | simple_strtoul(argv[i+1], NULL, 10); |
| 509 | pconf->user.enh_size = |
| 510 | simple_strtoul(argv[i+2], NULL, 10); |
| 511 | i += 3; |
| 512 | } else if (!strcmp(argv[i], "wrrel")) { |
| 513 | if (i + 1 >= argc) |
| 514 | return -1; |
| 515 | pconf->user.wr_rel_change = 1; |
| 516 | if (!strcmp(argv[i+1], "on")) |
| 517 | pconf->user.wr_rel_set = 1; |
| 518 | else if (!strcmp(argv[i+1], "off")) |
| 519 | pconf->user.wr_rel_set = 0; |
| 520 | else |
| 521 | return -1; |
| 522 | i += 2; |
| 523 | } else { |
| 524 | break; |
| 525 | } |
| 526 | } |
| 527 | return i; |
| 528 | } |
| 529 | |
| 530 | static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx, |
| 531 | int argc, char * const argv[]) |
| 532 | { |
| 533 | int i; |
| 534 | |
| 535 | memset(&pconf->gp_part[pidx], 0, sizeof(pconf->gp_part[pidx])); |
| 536 | |
| 537 | if (1 >= argc) |
| 538 | return -1; |
| 539 | pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10); |
| 540 | |
| 541 | i = 1; |
| 542 | while (i < argc) { |
| 543 | if (!strcmp(argv[i], "enh")) { |
| 544 | pconf->gp_part[pidx].enhanced = 1; |
| 545 | i += 1; |
| 546 | } else if (!strcmp(argv[i], "wrrel")) { |
| 547 | if (i + 1 >= argc) |
| 548 | return -1; |
| 549 | pconf->gp_part[pidx].wr_rel_change = 1; |
| 550 | if (!strcmp(argv[i+1], "on")) |
| 551 | pconf->gp_part[pidx].wr_rel_set = 1; |
| 552 | else if (!strcmp(argv[i+1], "off")) |
| 553 | pconf->gp_part[pidx].wr_rel_set = 0; |
| 554 | else |
| 555 | return -1; |
| 556 | i += 2; |
| 557 | } else { |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | return i; |
| 562 | } |
| 563 | |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 564 | static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag, |
| 565 | int argc, char * const argv[]) |
| 566 | { |
| 567 | struct mmc *mmc; |
| 568 | struct mmc_hwpart_conf pconf = { }; |
| 569 | enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK; |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 570 | int i, r, pidx; |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 571 | |
| 572 | mmc = init_mmc_device(curr_device, false); |
| 573 | if (!mmc) |
| 574 | return CMD_RET_FAILURE; |
| 575 | |
| 576 | if (argc < 1) |
| 577 | return CMD_RET_USAGE; |
| 578 | i = 1; |
| 579 | while (i < argc) { |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 580 | if (!strcmp(argv[i], "user")) { |
| 581 | i++; |
| 582 | r = parse_hwpart_user(&pconf, argc-i, &argv[i]); |
| 583 | if (r < 0) |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 584 | return CMD_RET_USAGE; |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 585 | i += r; |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 586 | } else if (!strncmp(argv[i], "gp", 2) && |
| 587 | strlen(argv[i]) == 3 && |
| 588 | argv[i][2] >= '1' && argv[i][2] <= '4') { |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 589 | pidx = argv[i][2] - '1'; |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 590 | i++; |
| 591 | r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]); |
| 592 | if (r < 0) |
| 593 | return CMD_RET_USAGE; |
| 594 | i += r; |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 595 | } else if (!strcmp(argv[i], "check")) { |
| 596 | mode = MMC_HWPART_CONF_CHECK; |
| 597 | i++; |
| 598 | } else if (!strcmp(argv[i], "set")) { |
| 599 | mode = MMC_HWPART_CONF_SET; |
| 600 | i++; |
| 601 | } else if (!strcmp(argv[i], "complete")) { |
| 602 | mode = MMC_HWPART_CONF_COMPLETE; |
| 603 | i++; |
| 604 | } else { |
| 605 | return CMD_RET_USAGE; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | puts("Partition configuration:\n"); |
| 610 | if (pconf.user.enh_size) { |
| 611 | puts("\tUser Enhanced Start: "); |
| 612 | print_size(((u64)pconf.user.enh_start) << 9, "\n"); |
| 613 | puts("\tUser Enhanced Size: "); |
| 614 | print_size(((u64)pconf.user.enh_size) << 9, "\n"); |
| 615 | } else { |
| 616 | puts("\tNo enhanced user data area\n"); |
| 617 | } |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 618 | if (pconf.user.wr_rel_change) |
| 619 | printf("\tUser partition write reliability: %s\n", |
| 620 | pconf.user.wr_rel_set ? "on" : "off"); |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 621 | for (pidx = 0; pidx < 4; pidx++) { |
| 622 | if (pconf.gp_part[pidx].size) { |
| 623 | printf("\tGP%i Capacity: ", pidx+1); |
| 624 | print_size(((u64)pconf.gp_part[pidx].size) << 9, |
| 625 | pconf.gp_part[pidx].enhanced ? |
| 626 | " ENH\n" : "\n"); |
| 627 | } else { |
| 628 | printf("\tNo GP%i partition\n", pidx+1); |
| 629 | } |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 630 | if (pconf.gp_part[pidx].wr_rel_change) |
| 631 | printf("\tGP%i write reliability: %s\n", pidx+1, |
| 632 | pconf.gp_part[pidx].wr_rel_set ? "on" : "off"); |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | if (!mmc_hwpart_config(mmc, &pconf, mode)) { |
| 636 | if (mode == MMC_HWPART_CONF_COMPLETE) |
| 637 | puts("Partitioning successful, " |
| 638 | "power-cycle to make effective\n"); |
| 639 | return CMD_RET_SUCCESS; |
| 640 | } else { |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 641 | puts("Failed!\n"); |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 642 | return CMD_RET_FAILURE; |
| 643 | } |
| 644 | } |
| 645 | |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 646 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 647 | static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag, |
| 648 | int argc, char * const argv[]) |
| 649 | { |
| 650 | int dev; |
| 651 | struct mmc *mmc; |
| 652 | u8 width, reset, mode; |
| 653 | |
| 654 | if (argc != 5) |
| 655 | return CMD_RET_USAGE; |
| 656 | dev = simple_strtoul(argv[1], NULL, 10); |
| 657 | width = simple_strtoul(argv[2], NULL, 10); |
| 658 | reset = simple_strtoul(argv[3], NULL, 10); |
| 659 | mode = simple_strtoul(argv[4], NULL, 10); |
| 660 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 661 | mmc = init_mmc_device(dev, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 662 | if (!mmc) |
| 663 | return CMD_RET_FAILURE; |
| 664 | |
| 665 | if (IS_SD(mmc)) { |
| 666 | puts("BOOT_BUS_WIDTH only exists on eMMC\n"); |
| 667 | return CMD_RET_FAILURE; |
| 668 | } |
| 669 | |
| 670 | /* acknowledge to be sent during boot operation */ |
| 671 | return mmc_set_boot_bus_width(mmc, width, reset, mode); |
| 672 | } |
| 673 | static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag, |
| 674 | int argc, char * const argv[]) |
| 675 | { |
| 676 | int dev; |
| 677 | struct mmc *mmc; |
| 678 | u32 bootsize, rpmbsize; |
| 679 | |
| 680 | if (argc != 4) |
| 681 | return CMD_RET_USAGE; |
| 682 | dev = simple_strtoul(argv[1], NULL, 10); |
| 683 | bootsize = simple_strtoul(argv[2], NULL, 10); |
| 684 | rpmbsize = simple_strtoul(argv[3], NULL, 10); |
| 685 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 686 | mmc = init_mmc_device(dev, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 687 | if (!mmc) |
| 688 | return CMD_RET_FAILURE; |
| 689 | |
| 690 | if (IS_SD(mmc)) { |
| 691 | printf("It is not a EMMC device\n"); |
| 692 | return CMD_RET_FAILURE; |
| 693 | } |
| 694 | |
| 695 | if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) { |
| 696 | printf("EMMC boot partition Size change Failed.\n"); |
| 697 | return CMD_RET_FAILURE; |
| 698 | } |
| 699 | |
| 700 | printf("EMMC boot partition Size %d MB\n", bootsize); |
| 701 | printf("EMMC RPMB partition Size %d MB\n", rpmbsize); |
| 702 | return CMD_RET_SUCCESS; |
| 703 | } |
| 704 | static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag, |
| 705 | int argc, char * const argv[]) |
| 706 | { |
| 707 | int dev; |
| 708 | struct mmc *mmc; |
| 709 | u8 ack, part_num, access; |
| 710 | |
| 711 | if (argc != 5) |
| 712 | return CMD_RET_USAGE; |
| 713 | |
| 714 | dev = simple_strtoul(argv[1], NULL, 10); |
| 715 | ack = simple_strtoul(argv[2], NULL, 10); |
| 716 | part_num = simple_strtoul(argv[3], NULL, 10); |
| 717 | access = simple_strtoul(argv[4], NULL, 10); |
| 718 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 719 | mmc = init_mmc_device(dev, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 720 | if (!mmc) |
| 721 | return CMD_RET_FAILURE; |
| 722 | |
| 723 | if (IS_SD(mmc)) { |
| 724 | puts("PARTITION_CONFIG only exists on eMMC\n"); |
| 725 | return CMD_RET_FAILURE; |
| 726 | } |
| 727 | |
| 728 | /* acknowledge to be sent during boot operation */ |
| 729 | return mmc_set_part_conf(mmc, ack, part_num, access); |
| 730 | } |
| 731 | static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag, |
| 732 | int argc, char * const argv[]) |
| 733 | { |
| 734 | int dev; |
| 735 | struct mmc *mmc; |
| 736 | u8 enable; |
| 737 | |
| 738 | /* |
| 739 | * Set the RST_n_ENABLE bit of RST_n_FUNCTION |
| 740 | * The only valid values are 0x0, 0x1 and 0x2 and writing |
| 741 | * a value of 0x1 or 0x2 sets the value permanently. |
| 742 | */ |
| 743 | if (argc != 3) |
| 744 | return CMD_RET_USAGE; |
| 745 | |
| 746 | dev = simple_strtoul(argv[1], NULL, 10); |
| 747 | enable = simple_strtoul(argv[2], NULL, 10); |
| 748 | |
| 749 | if (enable > 2 || enable < 0) { |
| 750 | puts("Invalid RST_n_ENABLE value\n"); |
| 751 | return CMD_RET_USAGE; |
| 752 | } |
| 753 | |
Stephen Warren | 1ae24a5 | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 754 | mmc = init_mmc_device(dev, false); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 755 | if (!mmc) |
| 756 | return CMD_RET_FAILURE; |
| 757 | |
| 758 | if (IS_SD(mmc)) { |
| 759 | puts("RST_n_FUNCTION only exists on eMMC\n"); |
| 760 | return CMD_RET_FAILURE; |
| 761 | } |
| 762 | |
| 763 | return mmc_set_rst_n_function(mmc, enable); |
| 764 | } |
| 765 | #endif |
| 766 | static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag, |
| 767 | int argc, char * const argv[]) |
| 768 | { |
| 769 | struct mmc *mmc; |
| 770 | u32 val; |
| 771 | int ret; |
| 772 | |
| 773 | if (argc != 2) |
| 774 | return CMD_RET_USAGE; |
| 775 | val = simple_strtoul(argv[2], NULL, 16); |
| 776 | |
| 777 | mmc = find_mmc_device(curr_device); |
| 778 | if (!mmc) { |
| 779 | printf("no mmc device at slot %x\n", curr_device); |
| 780 | return CMD_RET_FAILURE; |
| 781 | } |
| 782 | ret = mmc_set_dsr(mmc, val); |
| 783 | printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR"); |
| 784 | if (!ret) { |
| 785 | mmc->has_init = 0; |
| 786 | if (mmc_init(mmc)) |
| 787 | return CMD_RET_FAILURE; |
| 788 | else |
| 789 | return CMD_RET_SUCCESS; |
| 790 | } |
| 791 | return ret; |
| 792 | } |
| 793 | |
| 794 | static cmd_tbl_t cmd_mmc[] = { |
| 795 | U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""), |
| 796 | U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""), |
| 797 | U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""), |
| 798 | U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""), |
| 799 | U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""), |
| 800 | U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""), |
| 801 | U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""), |
| 802 | U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""), |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 803 | U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""), |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 804 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 805 | U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""), |
Wally Yeh | fa7b885 | 2014-09-25 23:00:16 +0800 | [diff] [blame] | 806 | U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""), |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 807 | U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""), |
| 808 | U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""), |
| 809 | #endif |
| 810 | #ifdef CONFIG_SUPPORT_EMMC_RPMB |
| 811 | U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""), |
| 812 | #endif |
| 813 | U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""), |
| 814 | }; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 815 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 816 | 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] | 817 | { |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 818 | cmd_tbl_t *cp; |
Lei Wen | 6be95cc | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 819 | |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 820 | cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc)); |
| 821 | |
| 822 | /* Drop the mmc command */ |
| 823 | argc--; |
| 824 | argv++; |
| 825 | |
| 826 | if (cp == NULL || argc > cp->maxargs) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 827 | return CMD_RET_USAGE; |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 828 | if (flag == CMD_FLAG_REPEAT && !cp->repeatable) |
| 829 | return CMD_RET_SUCCESS; |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 830 | |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 831 | if (curr_device < 0) { |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 832 | if (get_mmc_num() > 0) { |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 833 | curr_device = 0; |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 834 | } else { |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 835 | puts("No MMC device available\n"); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 836 | return CMD_RET_FAILURE; |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 837 | } |
| 838 | } |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 839 | return cp->cmd(cmdtp, flag, argc, argv); |
Andy Fleming | 272cc70 | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | U_BOOT_CMD( |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 843 | mmc, 29, 1, do_mmcops, |
Mike Frysinger | 852dbfd | 2009-03-23 22:27:34 -0400 | [diff] [blame] | 844 | "MMC sub system", |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 845 | "info - display info of the current MMC device\n" |
| 846 | "mmc read addr blk# cnt\n" |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 847 | "mmc write addr blk# cnt\n" |
Lei Wen | e6f99a5 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 848 | "mmc erase blk# cnt\n" |
Lei Wen | ea6ebe2 | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 849 | "mmc rescan\n" |
| 850 | "mmc part - lists available partition on current mmc device\n" |
Lei Wen | bc897b1 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 851 | "mmc dev [dev] [part] - show or set current mmc device [partition]\n" |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 852 | "mmc list - lists available devices\n" |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 853 | "mmc hwpartition [args...] - does hardware partitioning\n" |
| 854 | " arguments (sizes in 512-byte blocks):\n" |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 855 | " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n" |
| 856 | " [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n" |
Diego Santa Cruz | c599f53 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 857 | " [check|set|complete] - mode, complete set partitioning completed\n" |
Diego Santa Cruz | 189f963 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 858 | " WARNING: Partitioning is a write-once setting once it is set to complete.\n" |
| 859 | " Power cycling is required to initialize partitions after set to complete.\n" |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 860 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
Tom Rini | 5a99b9d | 2014-02-05 10:24:22 -0500 | [diff] [blame] | 861 | "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n" |
| 862 | " - Set the BOOT_BUS_WIDTH field of the specified device\n" |
Tom Rini | f1fd957 | 2014-02-05 10:24:20 -0500 | [diff] [blame] | 863 | "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n" |
| 864 | " - Change sizes of boot and RPMB partitions of specified device\n" |
Tom Rini | 792970b | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 865 | "mmc partconf dev boot_ack boot_partition partition_access\n" |
| 866 | " - 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] | 867 | "mmc rst-function dev value\n" |
| 868 | " - Change the RST_n_FUNCTION field of the specified device\n" |
| 869 | " 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] | 870 | #endif |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 871 | #ifdef CONFIG_SUPPORT_EMMC_RPMB |
| 872 | "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n" |
| 873 | "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n" |
| 874 | "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n" |
| 875 | "mmc rpmb counter - read the value of the write counter\n" |
| 876 | #endif |
| 877 | "mmc setdsr <value> - set DSR register value\n" |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 878 | ); |
Pierre Aubert | 1fd93c6 | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 879 | |
| 880 | /* Old command kept for compatibility. Same as 'mmc info' */ |
| 881 | U_BOOT_CMD( |
| 882 | mmcinfo, 1, 0, do_mmcinfo, |
| 883 | "display MMC info", |
| 884 | "- display info of the current MMC device" |
| 885 | ); |
| 886 | |
Amar | 2a91c91 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 887 | #endif /* !CONFIG_GENERIC_MMC */ |