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