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