Blame view
common/cmd_mmc.c
10.1 KB
71f951180 * Fix CONFIG_NET_... |
1 2 3 4 |
/* * (C) Copyright 2003 * Kyle Harris, kharris@nexus-tech.net * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
71f951180 * Fix CONFIG_NET_... |
6 7 8 9 |
*/ #include <common.h> #include <command.h> |
71f951180 * Fix CONFIG_NET_... |
10 |
#include <mmc.h> |
02e22c2de cmd_mmc: make cur... |
11 |
static int curr_device = -1; |
ea6ebe217 cmd_mmc: eliminat... |
12 |
#ifndef CONFIG_GENERIC_MMC |
54841ab50 Make sure that ar... |
13 |
int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
71f951180 * Fix CONFIG_NET_... |
14 |
{ |
869f6bf4d cmd_mmc: add supp... |
15 |
int dev; |
47e26b1bf cmd_usage(): simp... |
16 |
if (argc < 2) |
4c12eeb8b Convert cmd_usage... |
17 |
return CMD_RET_USAGE; |
869f6bf4d cmd_mmc: add supp... |
18 19 20 21 22 23 24 25 26 27 |
if (strcmp(argv[1], "init") == 0) { if (argc == 2) { if (curr_device < 0) dev = 1; else dev = curr_device; } else if (argc == 3) { dev = (int)simple_strtoul(argv[2], NULL, 10); } else { |
4c12eeb8b Convert cmd_usage... |
28 |
return CMD_RET_USAGE; |
869f6bf4d cmd_mmc: add supp... |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
} if (mmc_legacy_init(dev) != 0) { puts("No MMC card found "); return 1; } curr_device = dev; printf("mmc%d is available ", curr_device); } else if (strcmp(argv[1], "device") == 0) { if (argc == 2) { if (curr_device < 0) { puts("No MMC device available "); return 1; } } else if (argc == 3) { dev = (int)simple_strtoul(argv[2], NULL, 10); #ifdef CONFIG_SYS_MMC_SET_DEV if (mmc_set_dev(dev) != 0) return 1; #endif curr_device = dev; } else { |
4c12eeb8b Convert cmd_usage... |
56 |
return CMD_RET_USAGE; |
869f6bf4d cmd_mmc: add supp... |
57 58 59 60 61 |
} printf("mmc%d is current device ", curr_device); } else { |
4c12eeb8b Convert cmd_usage... |
62 |
return CMD_RET_USAGE; |
71f951180 * Fix CONFIG_NET_... |
63 |
} |
869f6bf4d cmd_mmc: add supp... |
64 |
|
71f951180 * Fix CONFIG_NET_... |
65 66 |
return 0; } |
0d4983930 Patch by Kenneth ... |
67 |
U_BOOT_CMD( |
869f6bf4d cmd_mmc: add supp... |
68 69 70 71 |
mmc, 3, 1, do_mmc, "MMC sub-system", "init [dev] - init MMC sub system " |
a89c33db9 General help mess... |
72 |
"mmc device [dev] - show or set current device" |
b0fce99bf Fix some missing ... |
73 |
); |
3511b4e20 MMC: Don't use ne... |
74 |
#else /* !CONFIG_GENERIC_MMC */ |
272cc70b2 Add MMC Framework |
75 |
|
6be95ccf9 MMC: unify mmc re... |
76 77 78 79 |
enum mmc_state { MMC_INVALID, MMC_READ, MMC_WRITE, |
e6f99a561 MMC: add erase fu... |
80 |
MMC_ERASE, |
6be95ccf9 MMC: unify mmc re... |
81 |
}; |
272cc70b2 Add MMC Framework |
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
static void print_mmcinfo(struct mmc *mmc) { printf("Device: %s ", mmc->name); 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); printf("Tran Speed: %d ", mmc->tran_speed); printf("Rd Block Len: %d ", mmc->read_bl_len); printf("%s version %d.%d ", IS_SD(mmc) ? "SD" : "MMC", |
64f4a6192 mmc: support the ... |
102 |
(mmc->version >> 8) & 0xf, mmc->version & 0xff); |
272cc70b2 Add MMC Framework |
103 104 105 |
printf("High Capacity: %s ", mmc->high_capacity ? "Yes" : "No"); |
940e07829 mmc: show mmc cap... |
106 107 108 |
puts("Capacity: "); print_size(mmc->capacity, " "); |
272cc70b2 Add MMC Framework |
109 110 111 112 |
printf("Bus Width: %d-bit ", mmc->bus_width); } |
088f1b199 common/cmd_*.c: s... |
113 |
static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
272cc70b2 Add MMC Framework |
114 115 |
{ struct mmc *mmc; |
272cc70b2 Add MMC Framework |
116 |
|
ea6ebe217 cmd_mmc: eliminat... |
117 118 119 120 121 122 123 124 125 |
if (curr_device < 0) { if (get_mmc_num() > 0) curr_device = 0; else { puts("No MMC device available "); return 1; } } |
272cc70b2 Add MMC Framework |
126 |
|
ea6ebe217 cmd_mmc: eliminat... |
127 |
mmc = find_mmc_device(curr_device); |
272cc70b2 Add MMC Framework |
128 129 130 131 132 |
if (mmc) { mmc_init(mmc); print_mmcinfo(mmc); |
ea6ebe217 cmd_mmc: eliminat... |
133 134 135 136 137 |
return 0; } else { printf("no mmc device at slot %x ", curr_device); return 1; |
272cc70b2 Add MMC Framework |
138 |
} |
272cc70b2 Add MMC Framework |
139 |
} |
388a29d02 various cmd_* fil... |
140 |
U_BOOT_CMD( |
ea6ebe217 cmd_mmc: eliminat... |
141 |
mmcinfo, 1, 0, do_mmcinfo, |
cc9f607be various cmd_* fil... |
142 |
"display MMC info", |
59ddead14 cmd_mmc.c: Fix ty... |
143 |
"- display info of the current MMC device" |
a89c33db9 General help mess... |
144 |
); |
272cc70b2 Add MMC Framework |
145 |
|
2a91c9134 COMMON: MMC: Comm... |
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
#ifdef CONFIG_SUPPORT_EMMC_BOOT static int boot_part_access(struct mmc *mmc, u8 ack, u8 part_num, u8 access) { int err; err = mmc_boot_part_access(mmc, ack, part_num, access); if ((err == 0) && (access != 0)) { printf("\t\t\t!!!Notice!!! "); printf("!You must close EMMC boot Partition"); printf("after all images are written "); printf("!EMMC boot partition has continuity"); printf("at image writing time. "); printf("!So, do not close the boot partition"); printf("before all images are written. "); return 0; } else if ((err == 0) && (access == 0)) return 0; else if ((err != 0) && (access != 0)) { printf("EMMC boot partition-%d OPEN Failed. ", part_num); return 1; } else { printf("EMMC boot partition-%d CLOSE Failed. ", part_num); return 1; } } #endif |
088f1b199 common/cmd_*.c: s... |
181 |
static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
272cc70b2 Add MMC Framework |
182 |
{ |
6be95ccf9 MMC: unify mmc re... |
183 |
enum mmc_state state; |
ea6ebe217 cmd_mmc: eliminat... |
184 |
if (argc < 2) |
4c12eeb8b Convert cmd_usage... |
185 |
return CMD_RET_USAGE; |
272cc70b2 Add MMC Framework |
186 |
|
ea6ebe217 cmd_mmc: eliminat... |
187 188 189 190 191 192 193 194 195 |
if (curr_device < 0) { if (get_mmc_num() > 0) curr_device = 0; else { puts("No MMC device available "); return 1; } } |
272cc70b2 Add MMC Framework |
196 |
|
ea6ebe217 cmd_mmc: eliminat... |
197 |
if (strcmp(argv[1], "rescan") == 0) { |
9fd383724 mmc: don't allow ... |
198 199 200 201 |
struct mmc *mmc; if (argc != 2) return CMD_RET_USAGE; |
e85649c7e mmc: check find_m... |
202 |
|
9fd383724 mmc: don't allow ... |
203 |
mmc = find_mmc_device(curr_device); |
ea6ebe217 cmd_mmc: eliminat... |
204 205 206 207 208 |
if (!mmc) { printf("no mmc device at slot %x ", curr_device); return 1; } |
bc897b1d4 mmc: enable parti... |
209 |
mmc->has_init = 0; |
272cc70b2 Add MMC Framework |
210 |
|
8fd01b8f6 mmc: rescan fails... |
211 212 213 214 |
if (mmc_init(mmc)) return 1; else return 0; |
ea6ebe217 cmd_mmc: eliminat... |
215 216 |
} else if (strncmp(argv[1], "part", 4) == 0) { block_dev_desc_t *mmc_dev; |
9fd383724 mmc: don't allow ... |
217 |
struct mmc *mmc; |
ea6ebe217 cmd_mmc: eliminat... |
218 |
|
9fd383724 mmc: don't allow ... |
219 220 221 222 |
if (argc != 2) return CMD_RET_USAGE; mmc = find_mmc_device(curr_device); |
ea6ebe217 cmd_mmc: eliminat... |
223 224 225 226 227 228 229 230 231 232 |
if (!mmc) { printf("no mmc device at slot %x ", curr_device); return 1; } mmc_init(mmc); mmc_dev = mmc_get_dev(curr_device); if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) { print_part(mmc_dev); |
272cc70b2 Add MMC Framework |
233 |
return 0; |
ea6ebe217 cmd_mmc: eliminat... |
234 |
} |
8f3b96427 mmc: print out pa... |
235 |
|
ea6ebe217 cmd_mmc: eliminat... |
236 237 238 239 |
puts("get mmc type error! "); return 1; } else if (strcmp(argv[1], "list") == 0) { |
9fd383724 mmc: don't allow ... |
240 241 |
if (argc != 2) return CMD_RET_USAGE; |
ea6ebe217 cmd_mmc: eliminat... |
242 243 244 245 |
print_mmc_devices(' '); return 0; } else if (strcmp(argv[1], "dev") == 0) { |
bc897b1d4 mmc: enable parti... |
246 |
int dev, part = -1; |
ea6ebe217 cmd_mmc: eliminat... |
247 248 249 250 251 252 |
struct mmc *mmc; if (argc == 2) dev = curr_device; else if (argc == 3) dev = simple_strtoul(argv[2], NULL, 10); |
bc897b1d4 mmc: enable parti... |
253 254 255 256 257 258 259 260 261 262 |
else if (argc == 4) { dev = (int)simple_strtoul(argv[2], NULL, 10); part = (int)simple_strtoul(argv[3], NULL, 10); if (part > PART_ACCESS_MASK) { printf("#part_num shouldn't be larger" " than %d ", PART_ACCESS_MASK); return 1; } } else |
4c12eeb8b Convert cmd_usage... |
263 |
return CMD_RET_USAGE; |
8f3b96427 mmc: print out pa... |
264 |
|
ea6ebe217 cmd_mmc: eliminat... |
265 266 267 268 |
mmc = find_mmc_device(dev); if (!mmc) { printf("no mmc device at slot %x ", dev); |
8f3b96427 mmc: print out pa... |
269 |
return 1; |
272cc70b2 Add MMC Framework |
270 |
} |
bc897b1d4 mmc: enable parti... |
271 272 273 274 275 276 277 278 279 280 281 282 283 |
mmc_init(mmc); if (part != -1) { int ret; if (mmc->part_config == MMCPART_NOAVAILABLE) { printf("Card doesn't support part_switch "); return 1; } if (part != mmc->part_num) { ret = mmc_switch_part(dev, part); if (!ret) mmc->part_num = part; |
1f8b546f9 Fix some obvious ... |
284 285 |
printf("switch to partitions #%d, %s ", |
bc897b1d4 mmc: enable parti... |
286 287 288 |
part, (!ret) ? "OK" : "ERROR"); } } |
ea6ebe217 cmd_mmc: eliminat... |
289 |
curr_device = dev; |
bc897b1d4 mmc: enable parti... |
290 291 292 293 294 295 296 |
if (mmc->part_config == MMCPART_NOAVAILABLE) printf("mmc%d is current device ", curr_device); else printf("mmc%d(part %d) is current device ", curr_device, mmc->part_num); |
272cc70b2 Add MMC Framework |
297 |
|
ea6ebe217 cmd_mmc: eliminat... |
298 |
return 0; |
2a91c9134 COMMON: MMC: Comm... |
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
#ifdef CONFIG_SUPPORT_EMMC_BOOT } else if ((strcmp(argv[1], "open") == 0) || (strcmp(argv[1], "close") == 0)) { int dev; struct mmc *mmc; u8 part_num, access = 0; if (argc == 4) { dev = simple_strtoul(argv[2], NULL, 10); part_num = simple_strtoul(argv[3], NULL, 10); } else { return CMD_RET_USAGE; } mmc = find_mmc_device(dev); if (!mmc) { printf("no mmc device at slot %x ", dev); return 1; } |
272cc70b2 Add MMC Framework |
319 |
|
2a91c9134 COMMON: MMC: Comm... |
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
if (IS_SD(mmc)) { printf("SD device cannot be opened/closed "); return 1; } if ((part_num <= 0) || (part_num > MMC_NUM_BOOT_PARTITION)) { printf("Invalid boot partition number: "); printf("Boot partition number cannot be <= 0 "); printf("EMMC44 supports only 2 boot partitions "); return 1; } if (strcmp(argv[1], "open") == 0) access = part_num; /* enable R/W access to boot part*/ else access = 0; /* No access to boot partition */ /* acknowledge to be sent during boot operation */ return boot_part_access(mmc, 1, part_num, access); } else if (strcmp(argv[1], "bootpart") == 0) { int dev; dev = simple_strtoul(argv[2], NULL, 10); u32 bootsize = simple_strtoul(argv[3], NULL, 10); u32 rpmbsize = simple_strtoul(argv[4], NULL, 10); struct mmc *mmc = find_mmc_device(dev); if (!mmc) { printf("no mmc device at slot %x ", dev); return 1; } if (IS_SD(mmc)) { printf("It is not a EMMC device "); return 1; } if (0 == mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) { printf("EMMC boot partition Size %d MB ", bootsize); printf("EMMC RPMB partition Size %d MB ", rpmbsize); return 0; } else { printf("EMMC boot partition Size change Failed. "); return 1; } #endif /* CONFIG_SUPPORT_EMMC_BOOT */ } |
ab71188ce mmc: add setdsr s... |
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
else if (argc == 3 && strcmp(argv[1], "setdsr") == 0) { struct mmc *mmc = find_mmc_device(curr_device); u32 val = simple_strtoul(argv[2], NULL, 16); int ret; if (!mmc) { printf("no mmc device at slot %x ", curr_device); return 1; } 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 1; else return 0; } return ret; } |
ed80c931b mmc: Fix incorrec... |
400 401 |
state = MMC_INVALID; if (argc == 5 && strcmp(argv[1], "read") == 0) |
6be95ccf9 MMC: unify mmc re... |
402 |
state = MMC_READ; |
ed80c931b mmc: Fix incorrec... |
403 |
else if (argc == 5 && strcmp(argv[1], "write") == 0) |
6be95ccf9 MMC: unify mmc re... |
404 |
state = MMC_WRITE; |
ed80c931b mmc: Fix incorrec... |
405 |
else if (argc == 4 && strcmp(argv[1], "erase") == 0) |
e6f99a561 MMC: add erase fu... |
406 |
state = MMC_ERASE; |
272cc70b2 Add MMC Framework |
407 |
|
6be95ccf9 MMC: unify mmc re... |
408 409 |
if (state != MMC_INVALID) { struct mmc *mmc = find_mmc_device(curr_device); |
e6f99a561 MMC: add erase fu... |
410 411 412 413 414 415 416 417 |
int idx = 2; u32 blk, cnt, n; void *addr; if (state != MMC_ERASE) { addr = (void *)simple_strtoul(argv[idx], NULL, 16); ++idx; } else |
088f1b199 common/cmd_*.c: s... |
418 |
addr = NULL; |
e6f99a561 MMC: add erase fu... |
419 420 |
blk = simple_strtoul(argv[idx], NULL, 16); cnt = simple_strtoul(argv[idx + 1], NULL, 16); |
272cc70b2 Add MMC Framework |
421 |
|
ea6ebe217 cmd_mmc: eliminat... |
422 423 424 425 426 |
if (!mmc) { printf("no mmc device at slot %x ", curr_device); return 1; } |
e85649c7e mmc: check find_m... |
427 |
|
6be95ccf9 MMC: unify mmc re... |
428 429 430 |
printf(" MMC %s: dev # %d, block # %d, count %d ... ", argv[1], curr_device, blk, cnt); |
272cc70b2 Add MMC Framework |
431 |
|
ea6ebe217 cmd_mmc: eliminat... |
432 |
mmc_init(mmc); |
272cc70b2 Add MMC Framework |
433 |
|
d23d8d7e0 mmc: add support ... |
434 435 436 437 438 439 440 |
if ((state == MMC_WRITE || state == MMC_ERASE)) { if (mmc_getwp(mmc) == 1) { printf("Error: card is write protected! "); return 1; } } |
6be95ccf9 MMC: unify mmc re... |
441 442 443 444 445 446 447 448 449 450 451 |
switch (state) { case MMC_READ: n = mmc->block_dev.block_read(curr_device, blk, cnt, addr); /* flush cache after read */ flush_cache((ulong)addr, cnt * 512); /* FIXME */ break; case MMC_WRITE: n = mmc->block_dev.block_write(curr_device, blk, cnt, addr); break; |
e6f99a561 MMC: add erase fu... |
452 453 454 |
case MMC_ERASE: n = mmc->block_dev.block_erase(curr_device, blk, cnt); break; |
6be95ccf9 MMC: unify mmc re... |
455 456 457 |
default: BUG(); } |
272cc70b2 Add MMC Framework |
458 |
|
6be95ccf9 MMC: unify mmc re... |
459 460 461 |
printf("%d blocks %s: %s ", n, argv[1], (n == cnt) ? "OK" : "ERROR"); |
ea6ebe217 cmd_mmc: eliminat... |
462 |
return (n == cnt) ? 0 : 1; |
272cc70b2 Add MMC Framework |
463 |
} |
ea6ebe217 cmd_mmc: eliminat... |
464 |
|
4c12eeb8b Convert cmd_usage... |
465 |
return CMD_RET_USAGE; |
272cc70b2 Add MMC Framework |
466 467 468 469 |
} U_BOOT_CMD( mmc, 6, 1, do_mmcops, |
852dbfdd5 more command usag... |
470 |
"MMC sub system", |
ea6ebe217 cmd_mmc: eliminat... |
471 472 473 474 |
"read addr blk# cnt " "mmc write addr blk# cnt " |
e6f99a561 MMC: add erase fu... |
475 476 |
"mmc erase blk# cnt " |
ea6ebe217 cmd_mmc: eliminat... |
477 478 479 480 |
"mmc rescan " "mmc part - lists available partition on current mmc device " |
bc897b1d4 mmc: enable parti... |
481 482 |
"mmc dev [dev] [part] - show or set current mmc device [partition] " |
2a91c9134 COMMON: MMC: Comm... |
483 484 485 486 487 488 489 490 491 492 493 494 495 |
"mmc list - lists available devices " #ifdef CONFIG_SUPPORT_EMMC_BOOT "mmc open <dev> <boot_partition> " " - Enable boot_part for booting and enable R/W access of boot_part " "mmc close <dev> <boot_partition> " " - Enable boot_part for booting and disable access to boot_part " "mmc bootpart <device num> <boot part size MB> <RPMB part size MB> " |
1f8b546f9 Fix some obvious ... |
496 497 |
" - change sizes of boot and RPMB partitions of specified device " |
3511b4e20 MMC: Don't use ne... |
498 |
#endif |
ab71188ce mmc: add setdsr s... |
499 500 |
"mmc setdsr - set DSR register value " |
2a91c9134 COMMON: MMC: Comm... |
501 502 |
); #endif /* !CONFIG_GENERIC_MMC */ |