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