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