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