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