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