]>
Commit | Line | Data |
---|---|---|
71f95118 WD |
1 | /* |
2 | * (C) Copyright 2003 | |
3 | * Kyle Harris, kharris@nexus-tech.net | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
71f95118 WD |
6 | */ |
7 | ||
8 | #include <common.h> | |
9 | #include <command.h> | |
71f95118 WD |
10 | #include <mmc.h> |
11 | ||
02e22c2d | 12 | static int curr_device = -1; |
ea6ebe21 | 13 | #ifndef CONFIG_GENERIC_MMC |
54841ab5 | 14 | int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
71f95118 | 15 | { |
869f6bf4 MK |
16 | int dev; |
17 | ||
47e26b1b | 18 | if (argc < 2) |
4c12eeb8 | 19 | return CMD_RET_USAGE; |
869f6bf4 MK |
20 | |
21 | if (strcmp(argv[1], "init") == 0) { | |
22 | if (argc == 2) { | |
23 | if (curr_device < 0) | |
24 | dev = 1; | |
25 | else | |
26 | dev = curr_device; | |
27 | } else if (argc == 3) { | |
28 | dev = (int)simple_strtoul(argv[2], NULL, 10); | |
29 | } else { | |
4c12eeb8 | 30 | return CMD_RET_USAGE; |
869f6bf4 MK |
31 | } |
32 | ||
33 | if (mmc_legacy_init(dev) != 0) { | |
34 | puts("No MMC card found\n"); | |
35 | return 1; | |
36 | } | |
37 | ||
38 | curr_device = dev; | |
39 | printf("mmc%d is available\n", curr_device); | |
40 | } else if (strcmp(argv[1], "device") == 0) { | |
41 | if (argc == 2) { | |
42 | if (curr_device < 0) { | |
43 | puts("No MMC device available\n"); | |
44 | return 1; | |
45 | } | |
46 | } else if (argc == 3) { | |
47 | dev = (int)simple_strtoul(argv[2], NULL, 10); | |
48 | ||
49 | #ifdef CONFIG_SYS_MMC_SET_DEV | |
50 | if (mmc_set_dev(dev) != 0) | |
51 | return 1; | |
52 | #endif | |
53 | curr_device = dev; | |
54 | } else { | |
4c12eeb8 | 55 | return CMD_RET_USAGE; |
869f6bf4 MK |
56 | } |
57 | ||
58 | printf("mmc%d is current device\n", curr_device); | |
59 | } else { | |
4c12eeb8 | 60 | return CMD_RET_USAGE; |
71f95118 | 61 | } |
869f6bf4 | 62 | |
71f95118 WD |
63 | return 0; |
64 | } | |
65 | ||
0d498393 | 66 | U_BOOT_CMD( |
869f6bf4 MK |
67 | mmc, 3, 1, do_mmc, |
68 | "MMC sub-system", | |
69 | "init [dev] - init MMC sub system\n" | |
a89c33db | 70 | "mmc device [dev] - show or set current device" |
b0fce99b | 71 | ); |
3511b4e2 | 72 | #else /* !CONFIG_GENERIC_MMC */ |
272cc70b AF |
73 | |
74 | static void print_mmcinfo(struct mmc *mmc) | |
75 | { | |
c5f0d3f1 DSC |
76 | int i; |
77 | ||
93bfd616 | 78 | printf("Device: %s\n", mmc->cfg->name); |
272cc70b AF |
79 | printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24); |
80 | printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff); | |
81 | printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff, | |
82 | (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff, | |
83 | (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff); | |
84 | ||
85 | printf("Tran Speed: %d\n", mmc->tran_speed); | |
86 | printf("Rd Block Len: %d\n", mmc->read_bl_len); | |
87 | ||
88 | printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC", | |
64f4a619 | 89 | (mmc->version >> 8) & 0xf, mmc->version & 0xff); |
272cc70b AF |
90 | |
91 | printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No"); | |
940e0782 MK |
92 | puts("Capacity: "); |
93 | print_size(mmc->capacity, "\n"); | |
272cc70b | 94 | |
786e8f81 AG |
95 | printf("Bus Width: %d-bit%s\n", mmc->bus_width, |
96 | mmc->ddr_mode ? " DDR" : ""); | |
c5f0d3f1 | 97 | |
b0361526 DSC |
98 | puts("Erase Group Size: "); |
99 | print_size(((u64)mmc->erase_grp_size) << 9, "\n"); | |
100 | ||
525ada21 | 101 | if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) { |
c3dbb4f9 | 102 | bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0; |
beb98a14 | 103 | bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR); |
b0361526 DSC |
104 | |
105 | puts("HC WP Group Size: "); | |
106 | print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n"); | |
107 | ||
c5f0d3f1 | 108 | puts("User Capacity: "); |
beb98a14 DSC |
109 | print_size(mmc->capacity_user, usr_enh ? " ENH\n" : "\n"); |
110 | if (usr_enh) { | |
111 | puts("User Enhanced Start: "); | |
112 | print_size(mmc->enh_user_start, "\n"); | |
113 | puts("User Enhanced Size: "); | |
114 | print_size(mmc->enh_user_size, "\n"); | |
115 | } | |
c5f0d3f1 | 116 | puts("Boot Capacity: "); |
c3dbb4f9 | 117 | print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n"); |
c5f0d3f1 | 118 | puts("RPMB Capacity: "); |
c3dbb4f9 | 119 | print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n"); |
b0361526 | 120 | |
c5f0d3f1 | 121 | for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) { |
c3dbb4f9 DSC |
122 | bool is_enh = has_enh && |
123 | (mmc->part_attr & EXT_CSD_ENH_GP(i)); | |
c5f0d3f1 | 124 | if (mmc->capacity_gp[i]) { |
f289fd73 | 125 | printf("GP%i Capacity: ", i+1); |
c3dbb4f9 DSC |
126 | print_size(mmc->capacity_gp[i], |
127 | is_enh ? " ENH\n" : "\n"); | |
c5f0d3f1 DSC |
128 | } |
129 | } | |
130 | } | |
272cc70b | 131 | } |
1ae24a50 | 132 | static struct mmc *init_mmc_device(int dev, bool force_init) |
1fd93c6e PA |
133 | { |
134 | struct mmc *mmc; | |
135 | mmc = find_mmc_device(dev); | |
136 | if (!mmc) { | |
137 | printf("no mmc device at slot %x\n", dev); | |
138 | return NULL; | |
139 | } | |
1ae24a50 SW |
140 | if (force_init) |
141 | mmc->has_init = 0; | |
1fd93c6e PA |
142 | if (mmc_init(mmc)) |
143 | return NULL; | |
144 | return mmc; | |
145 | } | |
088f1b19 | 146 | static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
272cc70b AF |
147 | { |
148 | struct mmc *mmc; | |
272cc70b | 149 | |
ea6ebe21 LW |
150 | if (curr_device < 0) { |
151 | if (get_mmc_num() > 0) | |
152 | curr_device = 0; | |
153 | else { | |
154 | puts("No MMC device available\n"); | |
155 | return 1; | |
156 | } | |
157 | } | |
272cc70b | 158 | |
1ae24a50 | 159 | mmc = init_mmc_device(curr_device, false); |
1fd93c6e PA |
160 | if (!mmc) |
161 | return CMD_RET_FAILURE; | |
272cc70b | 162 | |
1fd93c6e PA |
163 | print_mmcinfo(mmc); |
164 | return CMD_RET_SUCCESS; | |
165 | } | |
272cc70b | 166 | |
1fd93c6e PA |
167 | #ifdef CONFIG_SUPPORT_EMMC_RPMB |
168 | static int confirm_key_prog(void) | |
169 | { | |
170 | puts("Warning: Programming authentication key can be done only once !\n" | |
171 | " Use this command only if you are sure of what you are doing,\n" | |
172 | "Really perform the key programming? <y/N> "); | |
173 | if (confirm_yesno()) | |
ea6ebe21 | 174 | return 1; |
1fd93c6e PA |
175 | |
176 | puts("Authentication key programming aborted\n"); | |
177 | return 0; | |
178 | } | |
179 | static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag, | |
180 | int argc, char * const argv[]) | |
181 | { | |
182 | void *key_addr; | |
183 | struct mmc *mmc = find_mmc_device(curr_device); | |
184 | ||
185 | if (argc != 2) | |
186 | return CMD_RET_USAGE; | |
187 | ||
188 | key_addr = (void *)simple_strtoul(argv[1], NULL, 16); | |
189 | if (!confirm_key_prog()) | |
190 | return CMD_RET_FAILURE; | |
191 | if (mmc_rpmb_set_key(mmc, key_addr)) { | |
192 | printf("ERROR - Key already programmed ?\n"); | |
193 | return CMD_RET_FAILURE; | |
272cc70b | 194 | } |
1fd93c6e | 195 | return CMD_RET_SUCCESS; |
272cc70b | 196 | } |
1fd93c6e PA |
197 | static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag, |
198 | int argc, char * const argv[]) | |
199 | { | |
200 | u16 blk, cnt; | |
201 | void *addr; | |
202 | int n; | |
203 | void *key_addr = NULL; | |
204 | struct mmc *mmc = find_mmc_device(curr_device); | |
272cc70b | 205 | |
1fd93c6e PA |
206 | if (argc < 4) |
207 | return CMD_RET_USAGE; | |
272cc70b | 208 | |
1fd93c6e PA |
209 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
210 | blk = simple_strtoul(argv[2], NULL, 16); | |
211 | cnt = simple_strtoul(argv[3], NULL, 16); | |
212 | ||
213 | if (argc == 5) | |
214 | key_addr = (void *)simple_strtoul(argv[4], NULL, 16); | |
215 | ||
216 | printf("\nMMC RPMB read: dev # %d, block # %d, count %d ... ", | |
217 | curr_device, blk, cnt); | |
218 | n = mmc_rpmb_read(mmc, addr, blk, cnt, key_addr); | |
219 | ||
220 | printf("%d RPMB blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR"); | |
221 | if (n != cnt) | |
222 | return CMD_RET_FAILURE; | |
223 | return CMD_RET_SUCCESS; | |
224 | } | |
225 | static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag, | |
226 | int argc, char * const argv[]) | |
272cc70b | 227 | { |
1fd93c6e PA |
228 | u16 blk, cnt; |
229 | void *addr; | |
230 | int n; | |
231 | void *key_addr; | |
232 | struct mmc *mmc = find_mmc_device(curr_device); | |
6be95ccf | 233 | |
1fd93c6e | 234 | if (argc != 5) |
4c12eeb8 | 235 | return CMD_RET_USAGE; |
272cc70b | 236 | |
1fd93c6e PA |
237 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
238 | blk = simple_strtoul(argv[2], NULL, 16); | |
239 | cnt = simple_strtoul(argv[3], NULL, 16); | |
240 | key_addr = (void *)simple_strtoul(argv[4], NULL, 16); | |
241 | ||
242 | printf("\nMMC RPMB write: dev # %d, block # %d, count %d ... ", | |
243 | curr_device, blk, cnt); | |
244 | n = mmc_rpmb_write(mmc, addr, blk, cnt, key_addr); | |
245 | ||
246 | printf("%d RPMB blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR"); | |
247 | if (n != cnt) | |
248 | return CMD_RET_FAILURE; | |
249 | return CMD_RET_SUCCESS; | |
250 | } | |
251 | static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag, | |
252 | int argc, char * const argv[]) | |
253 | { | |
254 | unsigned long counter; | |
255 | struct mmc *mmc = find_mmc_device(curr_device); | |
256 | ||
257 | if (mmc_rpmb_get_counter(mmc, &counter)) | |
258 | return CMD_RET_FAILURE; | |
259 | printf("RPMB Write counter= %lx\n", counter); | |
260 | return CMD_RET_SUCCESS; | |
261 | } | |
262 | ||
263 | static cmd_tbl_t cmd_rpmb[] = { | |
264 | U_BOOT_CMD_MKENT(key, 2, 0, do_mmcrpmb_key, "", ""), | |
265 | U_BOOT_CMD_MKENT(read, 5, 1, do_mmcrpmb_read, "", ""), | |
266 | U_BOOT_CMD_MKENT(write, 5, 0, do_mmcrpmb_write, "", ""), | |
267 | U_BOOT_CMD_MKENT(counter, 1, 1, do_mmcrpmb_counter, "", ""), | |
268 | }; | |
269 | ||
270 | static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag, | |
271 | int argc, char * const argv[]) | |
272 | { | |
273 | cmd_tbl_t *cp; | |
274 | struct mmc *mmc; | |
275 | char original_part; | |
276 | int ret; | |
277 | ||
278 | cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb)); | |
279 | ||
280 | /* Drop the rpmb subcommand */ | |
281 | argc--; | |
282 | argv++; | |
283 | ||
284 | if (cp == NULL || argc > cp->maxargs) | |
285 | return CMD_RET_USAGE; | |
286 | if (flag == CMD_FLAG_REPEAT && !cp->repeatable) | |
287 | return CMD_RET_SUCCESS; | |
288 | ||
1ae24a50 | 289 | mmc = init_mmc_device(curr_device, false); |
1fd93c6e PA |
290 | if (!mmc) |
291 | return CMD_RET_FAILURE; | |
292 | ||
293 | if (!(mmc->version & MMC_VERSION_MMC)) { | |
294 | printf("It is not a EMMC device\n"); | |
295 | return CMD_RET_FAILURE; | |
296 | } | |
297 | if (mmc->version < MMC_VERSION_4_41) { | |
298 | printf("RPMB not supported before version 4.41\n"); | |
299 | return CMD_RET_FAILURE; | |
ea6ebe21 | 300 | } |
1fd93c6e PA |
301 | /* Switch to the RPMB partition */ |
302 | original_part = mmc->part_num; | |
303 | if (mmc->part_num != MMC_PART_RPMB) { | |
304 | if (mmc_switch_part(curr_device, MMC_PART_RPMB) != 0) | |
305 | return CMD_RET_FAILURE; | |
306 | mmc->part_num = MMC_PART_RPMB; | |
307 | } | |
308 | ret = cp->cmd(cmdtp, flag, argc, argv); | |
272cc70b | 309 | |
1fd93c6e PA |
310 | /* Return to original partition */ |
311 | if (mmc->part_num != original_part) { | |
312 | if (mmc_switch_part(curr_device, original_part) != 0) | |
313 | return CMD_RET_FAILURE; | |
314 | mmc->part_num = original_part; | |
315 | } | |
316 | return ret; | |
317 | } | |
318 | #endif | |
9fd38372 | 319 | |
1fd93c6e PA |
320 | static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, |
321 | int argc, char * const argv[]) | |
322 | { | |
323 | struct mmc *mmc; | |
324 | u32 blk, cnt, n; | |
325 | void *addr; | |
e85649c7 | 326 | |
1fd93c6e PA |
327 | if (argc != 4) |
328 | return CMD_RET_USAGE; | |
ea6ebe21 | 329 | |
1fd93c6e PA |
330 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
331 | blk = simple_strtoul(argv[2], NULL, 16); | |
332 | cnt = simple_strtoul(argv[3], NULL, 16); | |
272cc70b | 333 | |
1ae24a50 | 334 | mmc = init_mmc_device(curr_device, false); |
1fd93c6e PA |
335 | if (!mmc) |
336 | return CMD_RET_FAILURE; | |
ea6ebe21 | 337 | |
1fd93c6e PA |
338 | printf("\nMMC read: dev # %d, block # %d, count %d ... ", |
339 | curr_device, blk, cnt); | |
9fd38372 | 340 | |
1fd93c6e PA |
341 | n = mmc->block_dev.block_read(curr_device, blk, cnt, addr); |
342 | /* flush cache after read */ | |
343 | flush_cache((ulong)addr, cnt * 512); /* FIXME */ | |
344 | printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR"); | |
8f3b9642 | 345 | |
1fd93c6e PA |
346 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
347 | } | |
348 | static int do_mmc_write(cmd_tbl_t *cmdtp, int flag, | |
349 | int argc, char * const argv[]) | |
350 | { | |
351 | struct mmc *mmc; | |
352 | u32 blk, cnt, n; | |
353 | void *addr; | |
8f3b9642 | 354 | |
1fd93c6e PA |
355 | if (argc != 4) |
356 | return CMD_RET_USAGE; | |
272cc70b | 357 | |
1fd93c6e PA |
358 | addr = (void *)simple_strtoul(argv[1], NULL, 16); |
359 | blk = simple_strtoul(argv[2], NULL, 16); | |
360 | cnt = simple_strtoul(argv[3], NULL, 16); | |
bc897b1d | 361 | |
1ae24a50 | 362 | mmc = init_mmc_device(curr_device, false); |
1fd93c6e PA |
363 | if (!mmc) |
364 | return CMD_RET_FAILURE; | |
bc897b1d | 365 | |
1fd93c6e PA |
366 | printf("\nMMC write: dev # %d, block # %d, count %d ... ", |
367 | curr_device, blk, cnt); | |
272cc70b | 368 | |
1fd93c6e PA |
369 | if (mmc_getwp(mmc) == 1) { |
370 | printf("Error: card is write protected!\n"); | |
371 | return CMD_RET_FAILURE; | |
372 | } | |
373 | n = mmc->block_dev.block_write(curr_device, blk, cnt, addr); | |
374 | printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR"); | |
792970b0 | 375 | |
1fd93c6e PA |
376 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
377 | } | |
378 | static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag, | |
379 | int argc, char * const argv[]) | |
380 | { | |
381 | struct mmc *mmc; | |
382 | u32 blk, cnt, n; | |
2a91c913 | 383 | |
1fd93c6e PA |
384 | if (argc != 3) |
385 | return CMD_RET_USAGE; | |
792970b0 | 386 | |
1fd93c6e PA |
387 | blk = simple_strtoul(argv[1], NULL, 16); |
388 | cnt = simple_strtoul(argv[2], NULL, 16); | |
5a99b9de | 389 | |
1ae24a50 | 390 | mmc = init_mmc_device(curr_device, false); |
1fd93c6e PA |
391 | if (!mmc) |
392 | return CMD_RET_FAILURE; | |
5a99b9de | 393 | |
1fd93c6e PA |
394 | printf("\nMMC erase: dev # %d, block # %d, count %d ... ", |
395 | curr_device, blk, cnt); | |
5a99b9de | 396 | |
1fd93c6e PA |
397 | if (mmc_getwp(mmc) == 1) { |
398 | printf("Error: card is write protected!\n"); | |
399 | return CMD_RET_FAILURE; | |
400 | } | |
401 | n = mmc->block_dev.block_erase(curr_device, blk, cnt); | |
402 | printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR"); | |
b01e6fe6 | 403 | |
1fd93c6e PA |
404 | return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
405 | } | |
406 | static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag, | |
407 | int argc, char * const argv[]) | |
408 | { | |
409 | struct mmc *mmc; | |
2a91c913 | 410 | |
941944e4 SW |
411 | mmc = init_mmc_device(curr_device, true); |
412 | if (!mmc) | |
1fd93c6e | 413 | return CMD_RET_FAILURE; |
2a91c913 | 414 | |
1fd93c6e PA |
415 | return CMD_RET_SUCCESS; |
416 | } | |
417 | static int do_mmc_part(cmd_tbl_t *cmdtp, int flag, | |
418 | int argc, char * const argv[]) | |
419 | { | |
420 | block_dev_desc_t *mmc_dev; | |
421 | struct mmc *mmc; | |
422 | ||
1ae24a50 | 423 | mmc = init_mmc_device(curr_device, false); |
1fd93c6e PA |
424 | if (!mmc) |
425 | return CMD_RET_FAILURE; | |
426 | ||
427 | mmc_dev = mmc_get_dev(curr_device); | |
428 | if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) { | |
429 | print_part(mmc_dev); | |
430 | return CMD_RET_SUCCESS; | |
431 | } | |
432 | ||
433 | puts("get mmc type error!\n"); | |
434 | return CMD_RET_FAILURE; | |
435 | } | |
436 | static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag, | |
437 | int argc, char * const argv[]) | |
438 | { | |
60dc58f7 | 439 | int dev, part = 0, ret; |
1fd93c6e PA |
440 | struct mmc *mmc; |
441 | ||
442 | if (argc == 1) { | |
443 | dev = curr_device; | |
444 | } else if (argc == 2) { | |
445 | dev = simple_strtoul(argv[1], NULL, 10); | |
446 | } else if (argc == 3) { | |
447 | dev = (int)simple_strtoul(argv[1], NULL, 10); | |
448 | part = (int)simple_strtoul(argv[2], NULL, 10); | |
449 | if (part > PART_ACCESS_MASK) { | |
450 | printf("#part_num shouldn't be larger than %d\n", | |
451 | PART_ACCESS_MASK); | |
452 | return CMD_RET_FAILURE; | |
33ace362 | 453 | } |
1fd93c6e PA |
454 | } else { |
455 | return CMD_RET_USAGE; | |
456 | } | |
33ace362 | 457 | |
a5710920 | 458 | mmc = init_mmc_device(dev, true); |
1fd93c6e PA |
459 | if (!mmc) |
460 | return CMD_RET_FAILURE; | |
461 | ||
60dc58f7 SW |
462 | ret = mmc_select_hwpart(dev, part); |
463 | printf("switch to partitions #%d, %s\n", | |
464 | part, (!ret) ? "OK" : "ERROR"); | |
465 | if (ret) | |
466 | return 1; | |
467 | ||
1fd93c6e PA |
468 | curr_device = dev; |
469 | if (mmc->part_config == MMCPART_NOAVAILABLE) | |
470 | printf("mmc%d is current device\n", curr_device); | |
471 | else | |
472 | printf("mmc%d(part %d) is current device\n", | |
473 | curr_device, mmc->part_num); | |
33ace362 | 474 | |
1fd93c6e PA |
475 | return CMD_RET_SUCCESS; |
476 | } | |
477 | static int do_mmc_list(cmd_tbl_t *cmdtp, int flag, | |
478 | int argc, char * const argv[]) | |
479 | { | |
480 | print_mmc_devices('\n'); | |
481 | return CMD_RET_SUCCESS; | |
482 | } | |
483 | #ifdef CONFIG_SUPPORT_EMMC_BOOT | |
484 | static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag, | |
485 | int argc, char * const argv[]) | |
486 | { | |
487 | int dev; | |
488 | struct mmc *mmc; | |
489 | u8 width, reset, mode; | |
490 | ||
491 | if (argc != 5) | |
492 | return CMD_RET_USAGE; | |
493 | dev = simple_strtoul(argv[1], NULL, 10); | |
494 | width = simple_strtoul(argv[2], NULL, 10); | |
495 | reset = simple_strtoul(argv[3], NULL, 10); | |
496 | mode = simple_strtoul(argv[4], NULL, 10); | |
497 | ||
1ae24a50 | 498 | mmc = init_mmc_device(dev, false); |
1fd93c6e PA |
499 | if (!mmc) |
500 | return CMD_RET_FAILURE; | |
501 | ||
502 | if (IS_SD(mmc)) { | |
503 | puts("BOOT_BUS_WIDTH only exists on eMMC\n"); | |
504 | return CMD_RET_FAILURE; | |
2a91c913 | 505 | } |
ab71188c | 506 | |
1fd93c6e PA |
507 | /* acknowledge to be sent during boot operation */ |
508 | return mmc_set_boot_bus_width(mmc, width, reset, mode); | |
509 | } | |
510 | static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag, | |
511 | int argc, char * const argv[]) | |
512 | { | |
513 | int dev; | |
514 | struct mmc *mmc; | |
515 | u32 bootsize, rpmbsize; | |
ab71188c | 516 | |
1fd93c6e PA |
517 | if (argc != 4) |
518 | return CMD_RET_USAGE; | |
519 | dev = simple_strtoul(argv[1], NULL, 10); | |
520 | bootsize = simple_strtoul(argv[2], NULL, 10); | |
521 | rpmbsize = simple_strtoul(argv[3], NULL, 10); | |
522 | ||
1ae24a50 | 523 | mmc = init_mmc_device(dev, false); |
1fd93c6e PA |
524 | if (!mmc) |
525 | return CMD_RET_FAILURE; | |
526 | ||
527 | if (IS_SD(mmc)) { | |
528 | printf("It is not a EMMC device\n"); | |
529 | return CMD_RET_FAILURE; | |
ab71188c MN |
530 | } |
531 | ||
1fd93c6e PA |
532 | if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) { |
533 | printf("EMMC boot partition Size change Failed.\n"); | |
534 | return CMD_RET_FAILURE; | |
535 | } | |
e85649c7 | 536 | |
1fd93c6e PA |
537 | printf("EMMC boot partition Size %d MB\n", bootsize); |
538 | printf("EMMC RPMB partition Size %d MB\n", rpmbsize); | |
539 | return CMD_RET_SUCCESS; | |
540 | } | |
541 | static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag, | |
542 | int argc, char * const argv[]) | |
543 | { | |
544 | int dev; | |
545 | struct mmc *mmc; | |
546 | u8 ack, part_num, access; | |
272cc70b | 547 | |
1fd93c6e PA |
548 | if (argc != 5) |
549 | return CMD_RET_USAGE; | |
272cc70b | 550 | |
1fd93c6e PA |
551 | dev = simple_strtoul(argv[1], NULL, 10); |
552 | ack = simple_strtoul(argv[2], NULL, 10); | |
553 | part_num = simple_strtoul(argv[3], NULL, 10); | |
554 | access = simple_strtoul(argv[4], NULL, 10); | |
d23d8d7e | 555 | |
1ae24a50 | 556 | mmc = init_mmc_device(dev, false); |
1fd93c6e PA |
557 | if (!mmc) |
558 | return CMD_RET_FAILURE; | |
559 | ||
560 | if (IS_SD(mmc)) { | |
561 | puts("PARTITION_CONFIG only exists on eMMC\n"); | |
562 | return CMD_RET_FAILURE; | |
563 | } | |
564 | ||
565 | /* acknowledge to be sent during boot operation */ | |
566 | return mmc_set_part_conf(mmc, ack, part_num, access); | |
567 | } | |
568 | static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag, | |
569 | int argc, char * const argv[]) | |
570 | { | |
571 | int dev; | |
572 | struct mmc *mmc; | |
573 | u8 enable; | |
574 | ||
575 | /* | |
576 | * Set the RST_n_ENABLE bit of RST_n_FUNCTION | |
577 | * The only valid values are 0x0, 0x1 and 0x2 and writing | |
578 | * a value of 0x1 or 0x2 sets the value permanently. | |
579 | */ | |
580 | if (argc != 3) | |
581 | return CMD_RET_USAGE; | |
582 | ||
583 | dev = simple_strtoul(argv[1], NULL, 10); | |
584 | enable = simple_strtoul(argv[2], NULL, 10); | |
585 | ||
586 | if (enable > 2 || enable < 0) { | |
587 | puts("Invalid RST_n_ENABLE value\n"); | |
588 | return CMD_RET_USAGE; | |
589 | } | |
590 | ||
1ae24a50 | 591 | mmc = init_mmc_device(dev, false); |
1fd93c6e PA |
592 | if (!mmc) |
593 | return CMD_RET_FAILURE; | |
594 | ||
595 | if (IS_SD(mmc)) { | |
596 | puts("RST_n_FUNCTION only exists on eMMC\n"); | |
597 | return CMD_RET_FAILURE; | |
598 | } | |
272cc70b | 599 | |
1fd93c6e PA |
600 | return mmc_set_rst_n_function(mmc, enable); |
601 | } | |
602 | #endif | |
603 | static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag, | |
604 | int argc, char * const argv[]) | |
605 | { | |
606 | struct mmc *mmc; | |
607 | u32 val; | |
608 | int ret; | |
609 | ||
610 | if (argc != 2) | |
611 | return CMD_RET_USAGE; | |
612 | val = simple_strtoul(argv[2], NULL, 16); | |
613 | ||
614 | mmc = find_mmc_device(curr_device); | |
615 | if (!mmc) { | |
616 | printf("no mmc device at slot %x\n", curr_device); | |
617 | return CMD_RET_FAILURE; | |
618 | } | |
619 | ret = mmc_set_dsr(mmc, val); | |
620 | printf("set dsr %s\n", (!ret) ? "OK, force rescan" : "ERROR"); | |
621 | if (!ret) { | |
622 | mmc->has_init = 0; | |
623 | if (mmc_init(mmc)) | |
624 | return CMD_RET_FAILURE; | |
625 | else | |
626 | return CMD_RET_SUCCESS; | |
272cc70b | 627 | } |
1fd93c6e PA |
628 | return ret; |
629 | } | |
630 | ||
631 | static cmd_tbl_t cmd_mmc[] = { | |
632 | U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""), | |
633 | U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""), | |
634 | U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""), | |
635 | U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""), | |
636 | U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""), | |
637 | U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""), | |
638 | U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""), | |
639 | U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""), | |
640 | #ifdef CONFIG_SUPPORT_EMMC_BOOT | |
641 | U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""), | |
fa7b8851 | 642 | U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""), |
1fd93c6e PA |
643 | U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""), |
644 | U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""), | |
645 | #endif | |
646 | #ifdef CONFIG_SUPPORT_EMMC_RPMB | |
647 | U_BOOT_CMD_MKENT(rpmb, CONFIG_SYS_MAXARGS, 1, do_mmcrpmb, "", ""), | |
648 | #endif | |
649 | U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""), | |
650 | }; | |
651 | ||
652 | static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
653 | { | |
654 | cmd_tbl_t *cp; | |
655 | ||
656 | cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc)); | |
657 | ||
658 | /* Drop the mmc command */ | |
659 | argc--; | |
660 | argv++; | |
661 | ||
662 | if (cp == NULL || argc > cp->maxargs) | |
663 | return CMD_RET_USAGE; | |
664 | if (flag == CMD_FLAG_REPEAT && !cp->repeatable) | |
665 | return CMD_RET_SUCCESS; | |
ea6ebe21 | 666 | |
1fd93c6e PA |
667 | if (curr_device < 0) { |
668 | if (get_mmc_num() > 0) { | |
669 | curr_device = 0; | |
670 | } else { | |
671 | puts("No MMC device available\n"); | |
672 | return CMD_RET_FAILURE; | |
673 | } | |
674 | } | |
675 | return cp->cmd(cmdtp, flag, argc, argv); | |
272cc70b AF |
676 | } |
677 | ||
678 | U_BOOT_CMD( | |
1fd93c6e | 679 | mmc, 7, 1, do_mmcops, |
852dbfdd | 680 | "MMC sub system", |
1fd93c6e PA |
681 | "info - display info of the current MMC device\n" |
682 | "mmc read addr blk# cnt\n" | |
ea6ebe21 | 683 | "mmc write addr blk# cnt\n" |
e6f99a56 | 684 | "mmc erase blk# cnt\n" |
ea6ebe21 LW |
685 | "mmc rescan\n" |
686 | "mmc part - lists available partition on current mmc device\n" | |
bc897b1d | 687 | "mmc dev [dev] [part] - show or set current mmc device [partition]\n" |
2a91c913 A |
688 | "mmc list - lists available devices\n" |
689 | #ifdef CONFIG_SUPPORT_EMMC_BOOT | |
5a99b9de TR |
690 | "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n" |
691 | " - Set the BOOT_BUS_WIDTH field of the specified device\n" | |
f1fd957e TR |
692 | "mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n" |
693 | " - Change sizes of boot and RPMB partitions of specified device\n" | |
792970b0 TR |
694 | "mmc partconf dev boot_ack boot_partition partition_access\n" |
695 | " - Change the bits of the PARTITION_CONFIG field of the specified device\n" | |
33ace362 TR |
696 | "mmc rst-function dev value\n" |
697 | " - Change the RST_n_FUNCTION field of the specified device\n" | |
698 | " WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.\n" | |
3511b4e2 | 699 | #endif |
1fd93c6e PA |
700 | #ifdef CONFIG_SUPPORT_EMMC_RPMB |
701 | "mmc rpmb read addr blk# cnt [address of auth-key] - block size is 256 bytes\n" | |
702 | "mmc rpmb write addr blk# cnt <address of auth-key> - block size is 256 bytes\n" | |
703 | "mmc rpmb key <address of auth-key> - program the RPMB authentication key.\n" | |
704 | "mmc rpmb counter - read the value of the write counter\n" | |
705 | #endif | |
706 | "mmc setdsr <value> - set DSR register value\n" | |
2a91c913 | 707 | ); |
1fd93c6e PA |
708 | |
709 | /* Old command kept for compatibility. Same as 'mmc info' */ | |
710 | U_BOOT_CMD( | |
711 | mmcinfo, 1, 0, do_mmcinfo, | |
712 | "display MMC info", | |
713 | "- display info of the current MMC device" | |
714 | ); | |
715 | ||
2a91c913 | 716 | #endif /* !CONFIG_GENERIC_MMC */ |