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