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