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