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