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