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 | } |
Eric Nelson | bc18166 | 2016-03-27 12:00:14 -0700 | [diff] [blame] | 153 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 154 | if (force_init) |
| 155 | mmc->has_init = 0; |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 156 | if (mmc_init(mmc)) |
| 157 | return NULL; |
| 158 | return mmc; |
| 159 | } |
Kim Phillips | dc00a68 | 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 | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 161 | { |
| 162 | struct mmc *mmc; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 163 | |
Lei Wen | d430d7c | 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 | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 172 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 173 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 174 | if (!mmc) |
| 175 | return CMD_RET_FAILURE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 176 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 177 | print_mmcinfo(mmc); |
| 178 | return CMD_RET_SUCCESS; |
| 179 | } |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 180 | |
Pierre Aubert | bcc302c | 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()) |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 188 | return 1; |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 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; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 208 | } |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 209 | return CMD_RET_SUCCESS; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 210 | } |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 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); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 219 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 220 | if (argc < 4) |
| 221 | return CMD_RET_USAGE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 222 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 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[]) |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 241 | { |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 242 | u16 blk, cnt; |
| 243 | void *addr; |
| 244 | int n; |
| 245 | void *key_addr; |
| 246 | struct mmc *mmc = find_mmc_device(curr_device); |
Lei Wen | 64b2b1e | 2011-06-22 17:03:30 +0000 | [diff] [blame] | 247 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 248 | if (argc != 5) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 249 | return CMD_RET_USAGE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 250 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 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 | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 303 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | bcc302c | 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; |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 310 | } |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 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 | a62cf49 | 2016-05-04 16:35:25 +0200 | [diff] [blame] | 316 | original_part = mmc->block_dev.hwpart; |
Stephen Warren | 1e0f92a | 2015-12-07 11:38:49 -0700 | [diff] [blame] | 317 | if (mmc_select_hwpart(curr_device, MMC_PART_RPMB) != 0) |
| 318 | return CMD_RET_FAILURE; |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 319 | ret = cp->cmd(cmdtp, flag, argc, argv); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 320 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 321 | /* Return to original partition */ |
Stephen Warren | 1e0f92a | 2015-12-07 11:38:49 -0700 | [diff] [blame] | 322 | if (mmc_select_hwpart(curr_device, original_part) != 0) |
| 323 | return CMD_RET_FAILURE; |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 324 | return ret; |
| 325 | } |
| 326 | #endif |
Rabin Vincent | 3e448aa | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 327 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 328 | static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, |
| 329 | int argc, char * const argv[]) |
| 330 | { |
| 331 | struct mmc *mmc; |
| 332 | u32 blk, cnt, n; |
| 333 | void *addr; |
Stephen Warren | 18faca7 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 334 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 335 | if (argc != 4) |
| 336 | return CMD_RET_USAGE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 337 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 338 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
| 339 | blk = simple_strtoul(argv[2], NULL, 16); |
| 340 | cnt = simple_strtoul(argv[3], NULL, 16); |
Lei Wen | 61dba93 | 2010-09-13 22:07:28 +0800 | [diff] [blame] | 341 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 342 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 343 | if (!mmc) |
| 344 | return CMD_RET_FAILURE; |
Lei Wen | 61dba93 | 2010-09-13 22:07:28 +0800 | [diff] [blame] | 345 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 346 | printf("\nMMC read: dev # %d, block # %d, count %d ... ", |
| 347 | curr_device, blk, cnt); |
Stephen Warren | 18faca7 | 2013-04-01 11:50:28 +0000 | [diff] [blame] | 348 | |
Eric Nelson | bc18166 | 2016-03-27 12:00:14 -0700 | [diff] [blame] | 349 | n = blk_dread(&mmc->block_dev, blk, cnt, addr); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 350 | /* flush cache after read */ |
| 351 | flush_cache((ulong)addr, cnt * 512); /* FIXME */ |
| 352 | printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR"); |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 353 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 354 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
| 355 | } |
| 356 | static int do_mmc_write(cmd_tbl_t *cmdtp, int flag, |
| 357 | int argc, char * const argv[]) |
| 358 | { |
| 359 | struct mmc *mmc; |
| 360 | u32 blk, cnt, n; |
| 361 | void *addr; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 362 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 363 | if (argc != 4) |
| 364 | return CMD_RET_USAGE; |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 365 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 366 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
| 367 | blk = simple_strtoul(argv[2], NULL, 16); |
| 368 | cnt = simple_strtoul(argv[3], NULL, 16); |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 369 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 370 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 371 | if (!mmc) |
| 372 | return CMD_RET_FAILURE; |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 373 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 374 | printf("\nMMC write: dev # %d, block # %d, count %d ... ", |
| 375 | curr_device, blk, cnt); |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 376 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 377 | if (mmc_getwp(mmc) == 1) { |
| 378 | printf("Error: card is write protected!\n"); |
| 379 | return CMD_RET_FAILURE; |
| 380 | } |
Eric Nelson | bc18166 | 2016-03-27 12:00:14 -0700 | [diff] [blame] | 381 | n = blk_dwrite(&mmc->block_dev, blk, cnt, addr); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 382 | printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR"); |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 383 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 384 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
| 385 | } |
| 386 | static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag, |
| 387 | int argc, char * const argv[]) |
| 388 | { |
| 389 | struct mmc *mmc; |
| 390 | u32 blk, cnt, n; |
Tom Rini | f8c6f79 | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 391 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 392 | if (argc != 3) |
| 393 | return CMD_RET_USAGE; |
Tom Rini | f8c6f79 | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 394 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 395 | blk = simple_strtoul(argv[1], NULL, 16); |
| 396 | cnt = simple_strtoul(argv[2], NULL, 16); |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 397 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 398 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 399 | if (!mmc) |
| 400 | return CMD_RET_FAILURE; |
Tom Rini | f8c6f79 | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 401 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 402 | printf("\nMMC erase: dev # %d, block # %d, count %d ... ", |
| 403 | curr_device, blk, cnt); |
Tom Rini | 4cf854c | 2014-02-05 10:24:22 -0500 | [diff] [blame] | 404 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 405 | if (mmc_getwp(mmc) == 1) { |
| 406 | printf("Error: card is write protected!\n"); |
| 407 | return CMD_RET_FAILURE; |
| 408 | } |
Eric Nelson | bc18166 | 2016-03-27 12:00:14 -0700 | [diff] [blame] | 409 | n = blk_derase(&mmc->block_dev, blk, cnt); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 410 | printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR"); |
Tom Rini | 4cf854c | 2014-02-05 10:24:22 -0500 | [diff] [blame] | 411 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 412 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
| 413 | } |
| 414 | static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag, |
| 415 | int argc, char * const argv[]) |
| 416 | { |
| 417 | struct mmc *mmc; |
Tom Rini | 4cf854c | 2014-02-05 10:24:22 -0500 | [diff] [blame] | 418 | |
Stephen Warren | 07ec4e7 | 2014-05-23 13:24:46 -0600 | [diff] [blame] | 419 | mmc = init_mmc_device(curr_device, true); |
| 420 | if (!mmc) |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 421 | return CMD_RET_FAILURE; |
Tom Rini | 4cf854c | 2014-02-05 10:24:22 -0500 | [diff] [blame] | 422 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 423 | return CMD_RET_SUCCESS; |
| 424 | } |
| 425 | static int do_mmc_part(cmd_tbl_t *cmdtp, int flag, |
| 426 | int argc, char * const argv[]) |
| 427 | { |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 428 | struct blk_desc *mmc_dev; |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 429 | struct mmc *mmc; |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 430 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 431 | mmc = init_mmc_device(curr_device, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 432 | if (!mmc) |
| 433 | return CMD_RET_FAILURE; |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 434 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 435 | mmc_dev = mmc_get_dev(curr_device); |
| 436 | if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) { |
Simon Glass | b89a844 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 437 | part_print(mmc_dev); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 438 | return CMD_RET_SUCCESS; |
| 439 | } |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 440 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 441 | puts("get mmc type error!\n"); |
| 442 | return CMD_RET_FAILURE; |
| 443 | } |
| 444 | static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag, |
| 445 | int argc, char * const argv[]) |
| 446 | { |
Stephen Warren | 1854980 | 2014-05-23 12:48:10 -0600 | [diff] [blame] | 447 | int dev, part = 0, ret; |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 448 | struct mmc *mmc; |
Tom Rini | 35a3ea1 | 2014-02-07 14:15:20 -0500 | [diff] [blame] | 449 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 450 | if (argc == 1) { |
| 451 | dev = curr_device; |
| 452 | } else if (argc == 2) { |
| 453 | dev = simple_strtoul(argv[1], NULL, 10); |
| 454 | } else if (argc == 3) { |
| 455 | dev = (int)simple_strtoul(argv[1], NULL, 10); |
| 456 | part = (int)simple_strtoul(argv[2], NULL, 10); |
| 457 | if (part > PART_ACCESS_MASK) { |
| 458 | printf("#part_num shouldn't be larger than %d\n", |
| 459 | PART_ACCESS_MASK); |
| 460 | return CMD_RET_FAILURE; |
Tom Rini | 35a3ea1 | 2014-02-07 14:15:20 -0500 | [diff] [blame] | 461 | } |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 462 | } else { |
| 463 | return CMD_RET_USAGE; |
| 464 | } |
Tom Rini | 35a3ea1 | 2014-02-07 14:15:20 -0500 | [diff] [blame] | 465 | |
Stephen Warren | cf66e6f | 2014-05-23 13:24:47 -0600 | [diff] [blame] | 466 | mmc = init_mmc_device(dev, true); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 467 | if (!mmc) |
| 468 | return CMD_RET_FAILURE; |
Tom Rini | 35a3ea1 | 2014-02-07 14:15:20 -0500 | [diff] [blame] | 469 | |
Stephen Warren | 1854980 | 2014-05-23 12:48:10 -0600 | [diff] [blame] | 470 | ret = mmc_select_hwpart(dev, part); |
| 471 | printf("switch to partitions #%d, %s\n", |
| 472 | part, (!ret) ? "OK" : "ERROR"); |
| 473 | if (ret) |
| 474 | return 1; |
| 475 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 476 | curr_device = dev; |
| 477 | if (mmc->part_config == MMCPART_NOAVAILABLE) |
| 478 | printf("mmc%d is current device\n", curr_device); |
| 479 | else |
| 480 | printf("mmc%d(part %d) is current device\n", |
Stephen Warren | 1e0f92a | 2015-12-07 11:38:49 -0700 | [diff] [blame] | 481 | curr_device, mmc->block_dev.hwpart); |
Tom Rini | 35a3ea1 | 2014-02-07 14:15:20 -0500 | [diff] [blame] | 482 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 483 | return CMD_RET_SUCCESS; |
| 484 | } |
| 485 | static int do_mmc_list(cmd_tbl_t *cmdtp, int flag, |
| 486 | int argc, char * const argv[]) |
| 487 | { |
| 488 | print_mmc_devices('\n'); |
| 489 | return CMD_RET_SUCCESS; |
| 490 | } |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 491 | |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 492 | static int parse_hwpart_user(struct mmc_hwpart_conf *pconf, |
| 493 | int argc, char * const argv[]) |
| 494 | { |
| 495 | int i = 0; |
| 496 | |
| 497 | memset(&pconf->user, 0, sizeof(pconf->user)); |
| 498 | |
| 499 | while (i < argc) { |
| 500 | if (!strcmp(argv[i], "enh")) { |
| 501 | if (i + 2 >= argc) |
| 502 | return -1; |
| 503 | pconf->user.enh_start = |
| 504 | simple_strtoul(argv[i+1], NULL, 10); |
| 505 | pconf->user.enh_size = |
| 506 | simple_strtoul(argv[i+2], NULL, 10); |
| 507 | i += 3; |
| 508 | } else if (!strcmp(argv[i], "wrrel")) { |
| 509 | if (i + 1 >= argc) |
| 510 | return -1; |
| 511 | pconf->user.wr_rel_change = 1; |
| 512 | if (!strcmp(argv[i+1], "on")) |
| 513 | pconf->user.wr_rel_set = 1; |
| 514 | else if (!strcmp(argv[i+1], "off")) |
| 515 | pconf->user.wr_rel_set = 0; |
| 516 | else |
| 517 | return -1; |
| 518 | i += 2; |
| 519 | } else { |
| 520 | break; |
| 521 | } |
| 522 | } |
| 523 | return i; |
| 524 | } |
| 525 | |
| 526 | static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx, |
| 527 | int argc, char * const argv[]) |
| 528 | { |
| 529 | int i; |
| 530 | |
| 531 | memset(&pconf->gp_part[pidx], 0, sizeof(pconf->gp_part[pidx])); |
| 532 | |
| 533 | if (1 >= argc) |
| 534 | return -1; |
| 535 | pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10); |
| 536 | |
| 537 | i = 1; |
| 538 | while (i < argc) { |
| 539 | if (!strcmp(argv[i], "enh")) { |
| 540 | pconf->gp_part[pidx].enhanced = 1; |
| 541 | i += 1; |
| 542 | } else if (!strcmp(argv[i], "wrrel")) { |
| 543 | if (i + 1 >= argc) |
| 544 | return -1; |
| 545 | pconf->gp_part[pidx].wr_rel_change = 1; |
| 546 | if (!strcmp(argv[i+1], "on")) |
| 547 | pconf->gp_part[pidx].wr_rel_set = 1; |
| 548 | else if (!strcmp(argv[i+1], "off")) |
| 549 | pconf->gp_part[pidx].wr_rel_set = 0; |
| 550 | else |
| 551 | return -1; |
| 552 | i += 2; |
| 553 | } else { |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | return i; |
| 558 | } |
| 559 | |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 560 | static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag, |
| 561 | int argc, char * const argv[]) |
| 562 | { |
| 563 | struct mmc *mmc; |
| 564 | struct mmc_hwpart_conf pconf = { }; |
| 565 | enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK; |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 566 | int i, r, pidx; |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 567 | |
| 568 | mmc = init_mmc_device(curr_device, false); |
| 569 | if (!mmc) |
| 570 | return CMD_RET_FAILURE; |
| 571 | |
| 572 | if (argc < 1) |
| 573 | return CMD_RET_USAGE; |
| 574 | i = 1; |
| 575 | while (i < argc) { |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 576 | if (!strcmp(argv[i], "user")) { |
| 577 | i++; |
| 578 | r = parse_hwpart_user(&pconf, argc-i, &argv[i]); |
| 579 | if (r < 0) |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 580 | return CMD_RET_USAGE; |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 581 | i += r; |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 582 | } else if (!strncmp(argv[i], "gp", 2) && |
| 583 | strlen(argv[i]) == 3 && |
| 584 | argv[i][2] >= '1' && argv[i][2] <= '4') { |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 585 | pidx = argv[i][2] - '1'; |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 586 | i++; |
| 587 | r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]); |
| 588 | if (r < 0) |
| 589 | return CMD_RET_USAGE; |
| 590 | i += r; |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 591 | } else if (!strcmp(argv[i], "check")) { |
| 592 | mode = MMC_HWPART_CONF_CHECK; |
| 593 | i++; |
| 594 | } else if (!strcmp(argv[i], "set")) { |
| 595 | mode = MMC_HWPART_CONF_SET; |
| 596 | i++; |
| 597 | } else if (!strcmp(argv[i], "complete")) { |
| 598 | mode = MMC_HWPART_CONF_COMPLETE; |
| 599 | i++; |
| 600 | } else { |
| 601 | return CMD_RET_USAGE; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | puts("Partition configuration:\n"); |
| 606 | if (pconf.user.enh_size) { |
| 607 | puts("\tUser Enhanced Start: "); |
| 608 | print_size(((u64)pconf.user.enh_start) << 9, "\n"); |
| 609 | puts("\tUser Enhanced Size: "); |
| 610 | print_size(((u64)pconf.user.enh_size) << 9, "\n"); |
| 611 | } else { |
| 612 | puts("\tNo enhanced user data area\n"); |
| 613 | } |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 614 | if (pconf.user.wr_rel_change) |
| 615 | printf("\tUser partition write reliability: %s\n", |
| 616 | pconf.user.wr_rel_set ? "on" : "off"); |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 617 | for (pidx = 0; pidx < 4; pidx++) { |
| 618 | if (pconf.gp_part[pidx].size) { |
| 619 | printf("\tGP%i Capacity: ", pidx+1); |
| 620 | print_size(((u64)pconf.gp_part[pidx].size) << 9, |
| 621 | pconf.gp_part[pidx].enhanced ? |
| 622 | " ENH\n" : "\n"); |
| 623 | } else { |
| 624 | printf("\tNo GP%i partition\n", pidx+1); |
| 625 | } |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 626 | if (pconf.gp_part[pidx].wr_rel_change) |
| 627 | printf("\tGP%i write reliability: %s\n", pidx+1, |
| 628 | pconf.gp_part[pidx].wr_rel_set ? "on" : "off"); |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | if (!mmc_hwpart_config(mmc, &pconf, mode)) { |
| 632 | if (mode == MMC_HWPART_CONF_COMPLETE) |
| 633 | puts("Partitioning successful, " |
| 634 | "power-cycle to make effective\n"); |
| 635 | return CMD_RET_SUCCESS; |
| 636 | } else { |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 637 | puts("Failed!\n"); |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 638 | return CMD_RET_FAILURE; |
| 639 | } |
| 640 | } |
| 641 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 642 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 643 | static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag, |
| 644 | int argc, char * const argv[]) |
| 645 | { |
| 646 | int dev; |
| 647 | struct mmc *mmc; |
| 648 | u8 width, reset, mode; |
| 649 | |
| 650 | if (argc != 5) |
| 651 | return CMD_RET_USAGE; |
| 652 | dev = simple_strtoul(argv[1], NULL, 10); |
| 653 | width = simple_strtoul(argv[2], NULL, 10); |
| 654 | reset = simple_strtoul(argv[3], NULL, 10); |
| 655 | mode = simple_strtoul(argv[4], NULL, 10); |
| 656 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 657 | mmc = init_mmc_device(dev, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 658 | if (!mmc) |
| 659 | return CMD_RET_FAILURE; |
| 660 | |
| 661 | if (IS_SD(mmc)) { |
| 662 | puts("BOOT_BUS_WIDTH only exists on eMMC\n"); |
| 663 | return CMD_RET_FAILURE; |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 664 | } |
Markus Niebel | 0395141 | 2013-12-16 13:40:46 +0100 | [diff] [blame] | 665 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 666 | /* acknowledge to be sent during boot operation */ |
| 667 | return mmc_set_boot_bus_width(mmc, width, reset, mode); |
| 668 | } |
| 669 | static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag, |
| 670 | int argc, char * const argv[]) |
| 671 | { |
| 672 | int dev; |
| 673 | struct mmc *mmc; |
| 674 | u32 bootsize, rpmbsize; |
Markus Niebel | 0395141 | 2013-12-16 13:40:46 +0100 | [diff] [blame] | 675 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 676 | if (argc != 4) |
| 677 | return CMD_RET_USAGE; |
| 678 | dev = simple_strtoul(argv[1], NULL, 10); |
| 679 | bootsize = simple_strtoul(argv[2], NULL, 10); |
| 680 | rpmbsize = simple_strtoul(argv[3], NULL, 10); |
| 681 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 682 | mmc = init_mmc_device(dev, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 683 | if (!mmc) |
| 684 | return CMD_RET_FAILURE; |
| 685 | |
| 686 | if (IS_SD(mmc)) { |
| 687 | printf("It is not a EMMC device\n"); |
| 688 | return CMD_RET_FAILURE; |
Markus Niebel | 0395141 | 2013-12-16 13:40:46 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 691 | if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) { |
| 692 | printf("EMMC boot partition Size change Failed.\n"); |
| 693 | return CMD_RET_FAILURE; |
| 694 | } |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 695 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 696 | printf("EMMC boot partition Size %d MB\n", bootsize); |
| 697 | printf("EMMC RPMB partition Size %d MB\n", rpmbsize); |
| 698 | return CMD_RET_SUCCESS; |
| 699 | } |
| 700 | static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag, |
| 701 | int argc, char * const argv[]) |
| 702 | { |
| 703 | int dev; |
| 704 | struct mmc *mmc; |
| 705 | u8 ack, part_num, access; |
Lei Wen | ea52676 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 706 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 707 | if (argc != 5) |
| 708 | return CMD_RET_USAGE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 709 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 710 | dev = simple_strtoul(argv[1], NULL, 10); |
| 711 | ack = simple_strtoul(argv[2], NULL, 10); |
| 712 | part_num = simple_strtoul(argv[3], NULL, 10); |
| 713 | access = simple_strtoul(argv[4], NULL, 10); |
Rabin Vincent | 3e448aa | 2009-04-05 13:30:53 +0530 | [diff] [blame] | 714 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 715 | mmc = init_mmc_device(dev, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 716 | if (!mmc) |
| 717 | return CMD_RET_FAILURE; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 718 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 719 | if (IS_SD(mmc)) { |
| 720 | puts("PARTITION_CONFIG only exists on eMMC\n"); |
| 721 | return CMD_RET_FAILURE; |
| 722 | } |
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 | /* acknowledge to be sent during boot operation */ |
| 725 | return mmc_set_part_conf(mmc, ack, part_num, access); |
| 726 | } |
| 727 | static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag, |
| 728 | int argc, char * const argv[]) |
| 729 | { |
| 730 | int dev; |
| 731 | struct mmc *mmc; |
| 732 | u8 enable; |
Nikita Kiryanov | 020f261 | 2012-12-03 02:19:46 +0000 | [diff] [blame] | 733 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 734 | /* |
| 735 | * Set the RST_n_ENABLE bit of RST_n_FUNCTION |
| 736 | * The only valid values are 0x0, 0x1 and 0x2 and writing |
| 737 | * a value of 0x1 or 0x2 sets the value permanently. |
| 738 | */ |
| 739 | if (argc != 3) |
| 740 | return CMD_RET_USAGE; |
| 741 | |
| 742 | dev = simple_strtoul(argv[1], NULL, 10); |
| 743 | enable = simple_strtoul(argv[2], NULL, 10); |
| 744 | |
Peng Fan | b1e455a | 2015-11-25 17:16:21 +0800 | [diff] [blame] | 745 | if (enable > 2) { |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 746 | puts("Invalid RST_n_ENABLE value\n"); |
| 747 | return CMD_RET_USAGE; |
| 748 | } |
| 749 | |
Stephen Warren | b627f4b | 2014-05-23 13:24:45 -0600 | [diff] [blame] | 750 | mmc = init_mmc_device(dev, false); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 751 | if (!mmc) |
| 752 | return CMD_RET_FAILURE; |
| 753 | |
| 754 | if (IS_SD(mmc)) { |
| 755 | puts("RST_n_FUNCTION only exists on eMMC\n"); |
| 756 | return CMD_RET_FAILURE; |
| 757 | } |
| 758 | |
| 759 | return mmc_set_rst_n_function(mmc, enable); |
| 760 | } |
| 761 | #endif |
| 762 | static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag, |
| 763 | int argc, char * const argv[]) |
| 764 | { |
| 765 | struct mmc *mmc; |
| 766 | u32 val; |
| 767 | int ret; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 768 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 769 | if (argc != 2) |
| 770 | return CMD_RET_USAGE; |
| 771 | val = simple_strtoul(argv[2], NULL, 16); |
| 772 | |
| 773 | mmc = find_mmc_device(curr_device); |
| 774 | if (!mmc) { |
| 775 | printf("no mmc device at slot %x\n", curr_device); |
| 776 | return CMD_RET_FAILURE; |
| 777 | } |
| 778 | ret = mmc_set_dsr(mmc, val); |
| 779 | printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR"); |
| 780 | if (!ret) { |
| 781 | mmc->has_init = 0; |
| 782 | if (mmc_init(mmc)) |
| 783 | return CMD_RET_FAILURE; |
| 784 | else |
| 785 | return CMD_RET_SUCCESS; |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 786 | } |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 787 | return ret; |
| 788 | } |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 789 | |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 790 | static cmd_tbl_t cmd_mmc[] = { |
| 791 | U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""), |
| 792 | U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""), |
| 793 | U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""), |
| 794 | U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""), |
| 795 | U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""), |
| 796 | U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""), |
| 797 | U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""), |
| 798 | U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""), |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 799 | U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""), |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 800 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
| 801 | U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""), |
Wally Yeh | d49c4aa | 2014-09-25 23:00:16 +0800 | [diff] [blame] | 802 | U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""), |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 803 | U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""), |
| 804 | U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""), |
| 805 | #endif |
| 806 | #ifdef CONFIG_SUPPORT_EMMC_RPMB |
| 807 | U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""), |
| 808 | #endif |
| 809 | U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""), |
| 810 | }; |
| 811 | |
| 812 | static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 813 | { |
| 814 | cmd_tbl_t *cp; |
| 815 | |
| 816 | cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc)); |
| 817 | |
| 818 | /* Drop the mmc command */ |
| 819 | argc--; |
| 820 | argv++; |
| 821 | |
| 822 | if (cp == NULL || argc > cp->maxargs) |
| 823 | return CMD_RET_USAGE; |
| 824 | if (flag == CMD_FLAG_REPEAT && !cp->repeatable) |
| 825 | return CMD_RET_SUCCESS; |
| 826 | |
| 827 | if (curr_device < 0) { |
| 828 | if (get_mmc_num() > 0) { |
| 829 | curr_device = 0; |
| 830 | } else { |
| 831 | puts("No MMC device available\n"); |
| 832 | return CMD_RET_FAILURE; |
| 833 | } |
| 834 | } |
| 835 | return cp->cmd(cmdtp, flag, argc, argv); |
Andy Fleming | ad347bb | 2008-10-30 16:41:01 -0500 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | U_BOOT_CMD( |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 839 | mmc, 29, 1, do_mmcops, |
Mike Frysinger | 27e1e62 | 2009-03-23 22:27:34 -0400 | [diff] [blame] | 840 | "MMC sub system", |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 841 | "info - display info of the current MMC device\n" |
| 842 | "mmc read addr blk# cnt\n" |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 843 | "mmc write addr blk# cnt\n" |
Lei Wen | ea52676 | 2011-06-22 17:03:31 +0000 | [diff] [blame] | 844 | "mmc erase blk# cnt\n" |
Lei Wen | d430d7c | 2011-05-02 16:26:25 +0000 | [diff] [blame] | 845 | "mmc rescan\n" |
| 846 | "mmc part - lists available partition on current mmc device\n" |
Lei Wen | 31b9980 | 2011-05-02 16:26:26 +0000 | [diff] [blame] | 847 | "mmc dev [dev] [part] - show or set current mmc device [partition]\n" |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 848 | "mmc list - lists available devices\n" |
Diego Santa Cruz | 420fc16 | 2014-12-23 10:50:30 +0100 | [diff] [blame] | 849 | "mmc hwpartition [args...] - does hardware partitioning\n" |
| 850 | " arguments (sizes in 512-byte blocks):\n" |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 851 | " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n" |
| 852 | " [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] | 853 | " [check|set|complete] - mode, complete set partitioning completed\n" |
Diego Santa Cruz | 58bda79 | 2014-12-23 10:50:32 +0100 | [diff] [blame] | 854 | " WARNING: Partitioning is a write-once setting once it is set to complete.\n" |
| 855 | " Power cycling is required to initialize partitions after set to complete.\n" |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 856 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
Tom Rini | 4cf854c | 2014-02-05 10:24:22 -0500 | [diff] [blame] | 857 | "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n" |
| 858 | " - Set the BOOT_BUS_WIDTH field of the specified device\n" |
Tom Rini | 7991946 | 2014-02-05 10:24:20 -0500 | [diff] [blame] | 859 | "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n" |
| 860 | " - Change sizes of boot and RPMB partitions of specified device\n" |
Tom Rini | f8c6f79 | 2014-02-05 10:24:21 -0500 | [diff] [blame] | 861 | "mmc partconf dev boot_ack boot_partition partition_access\n" |
| 862 | " - 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] | 863 | "mmc rst-function dev value\n" |
| 864 | " - Change the RST_n_FUNCTION field of the specified device\n" |
| 865 | " 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] | 866 | #endif |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 867 | #ifdef CONFIG_SUPPORT_EMMC_RPMB |
| 868 | "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n" |
| 869 | "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n" |
| 870 | "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n" |
| 871 | "mmc rpmb counter - read the value of the write counter\n" |
| 872 | #endif |
| 873 | "mmc setdsr <value> - set DSR register value\n" |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 874 | ); |
Pierre Aubert | bcc302c | 2014-04-24 10:30:08 +0200 | [diff] [blame] | 875 | |
| 876 | /* Old command kept for compatibility. Same as 'mmc info' */ |
| 877 | U_BOOT_CMD( |
| 878 | mmcinfo, 1, 0, do_mmcinfo, |
| 879 | "display MMC info", |
| 880 | "- display info of the current MMC device" |
| 881 | ); |
| 882 | |
Amar | 3ccad53 | 2013-04-27 11:43:00 +0530 | [diff] [blame] | 883 | #endif /* !CONFIG_GENERIC_MMC */ |