Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or |
| 3 | * modify it under the terms of the GNU General Public |
| 4 | * License v2 as published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 9 | * General Public License for more details. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public |
| 12 | * License along with this program; if not, write to the |
| 13 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 14 | * Boston, MA 021110-1307, USA. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <sys/ioctl.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <dirent.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <unistd.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <libgen.h> |
| 27 | #include <limits.h> |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 28 | #include <ctype.h> |
| 29 | |
| 30 | #include "mmc.h" |
| 31 | #include "mmc_cmds.h" |
| 32 | |
| 33 | int read_extcsd(int fd, __u8 *ext_csd) |
| 34 | { |
| 35 | int ret = 0; |
| 36 | struct mmc_ioc_cmd idata; |
| 37 | memset(&idata, 0, sizeof(idata)); |
| 38 | memset(ext_csd, 0, sizeof(__u8) * 512); |
| 39 | idata.write_flag = 0; |
| 40 | idata.opcode = MMC_SEND_EXT_CSD; |
| 41 | idata.arg = 0; |
| 42 | idata.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
| 43 | idata.blksz = 512; |
| 44 | idata.blocks = 1; |
| 45 | mmc_ioc_cmd_set_data(idata, ext_csd); |
| 46 | |
| 47 | ret = ioctl(fd, MMC_IOC_CMD, &idata); |
| 48 | if (ret) |
| 49 | perror("ioctl"); |
| 50 | |
| 51 | return ret; |
| 52 | } |
| 53 | |
| 54 | int write_extcsd_value(int fd, __u8 index, __u8 value) |
| 55 | { |
| 56 | int ret = 0; |
| 57 | struct mmc_ioc_cmd idata; |
| 58 | |
| 59 | memset(&idata, 0, sizeof(idata)); |
| 60 | idata.write_flag = 1; |
| 61 | idata.opcode = MMC_SWITCH; |
| 62 | idata.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | |
| 63 | (index << 16) | |
| 64 | (value << 8) | |
| 65 | EXT_CSD_CMD_SET_NORMAL; |
| 66 | idata.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; |
| 67 | |
| 68 | ret = ioctl(fd, MMC_IOC_CMD, &idata); |
| 69 | if (ret) |
| 70 | perror("ioctl"); |
| 71 | |
| 72 | return ret; |
| 73 | } |
| 74 | |
Ben Gardiner | 27c357d | 2013-05-30 17:12:47 -0400 | [diff] [blame] | 75 | int send_status(int fd, __u32 *response) |
| 76 | { |
| 77 | int ret = 0; |
| 78 | struct mmc_ioc_cmd idata; |
| 79 | |
| 80 | memset(&idata, 0, sizeof(idata)); |
| 81 | idata.opcode = MMC_SEND_STATUS; |
| 82 | idata.arg = (1 << 16); |
| 83 | idata.flags = MMC_RSP_R1 | MMC_CMD_AC; |
| 84 | |
| 85 | ret = ioctl(fd, MMC_IOC_CMD, &idata); |
| 86 | if (ret) |
| 87 | perror("ioctl"); |
| 88 | |
| 89 | *response = idata.response[0]; |
| 90 | |
| 91 | return ret; |
| 92 | } |
| 93 | |
Chris Ball | b9c7a17 | 2012-02-20 12:34:25 -0500 | [diff] [blame] | 94 | void print_writeprotect_status(__u8 *ext_csd) |
| 95 | { |
| 96 | __u8 reg; |
| 97 | __u8 ext_csd_rev = ext_csd[192]; |
| 98 | |
| 99 | /* A43: reserved [174:0] */ |
| 100 | if (ext_csd_rev >= 5) { |
| 101 | printf("Boot write protection status registers" |
| 102 | " [BOOT_WP_STATUS]: 0x%02x\n", ext_csd[174]); |
| 103 | |
| 104 | reg = ext_csd[EXT_CSD_BOOT_WP]; |
| 105 | printf("Boot Area Write protection [BOOT_WP]: 0x%02x\n", reg); |
| 106 | printf(" Power ro locking: "); |
| 107 | if (reg & EXT_CSD_BOOT_WP_B_PWR_WP_DIS) |
| 108 | printf("not possible\n"); |
| 109 | else |
| 110 | printf("possible\n"); |
| 111 | |
| 112 | printf(" Permanent ro locking: "); |
| 113 | if (reg & EXT_CSD_BOOT_WP_B_PERM_WP_DIS) |
| 114 | printf("not possible\n"); |
| 115 | else |
| 116 | printf("possible\n"); |
| 117 | |
| 118 | printf(" ro lock status: "); |
| 119 | if (reg & EXT_CSD_BOOT_WP_B_PWR_WP_EN) |
| 120 | printf("locked until next power on\n"); |
| 121 | else if (reg & EXT_CSD_BOOT_WP_B_PERM_WP_EN) |
| 122 | printf("locked permanently\n"); |
| 123 | else |
| 124 | printf("not locked\n"); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | int do_writeprotect_get(int nargs, char **argv) |
| 129 | { |
| 130 | __u8 ext_csd[512]; |
| 131 | int fd, ret; |
| 132 | char *device; |
| 133 | |
Chris Ball | 8ba4466 | 2012-04-19 13:22:54 -0400 | [diff] [blame] | 134 | CHECK(nargs != 2, "Usage: mmc writeprotect get </path/to/mmcblkX>\n", |
| 135 | exit(1)); |
Chris Ball | b9c7a17 | 2012-02-20 12:34:25 -0500 | [diff] [blame] | 136 | |
| 137 | device = argv[1]; |
| 138 | |
| 139 | fd = open(device, O_RDWR); |
| 140 | if (fd < 0) { |
| 141 | perror("open"); |
| 142 | exit(1); |
| 143 | } |
| 144 | |
| 145 | ret = read_extcsd(fd, ext_csd); |
| 146 | if (ret) { |
| 147 | fprintf(stderr, "Could not read EXT_CSD from %s\n", device); |
| 148 | exit(1); |
| 149 | } |
| 150 | |
| 151 | print_writeprotect_status(ext_csd); |
| 152 | |
| 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | int do_writeprotect_set(int nargs, char **argv) |
| 157 | { |
| 158 | __u8 ext_csd[512], value; |
| 159 | int fd, ret; |
| 160 | char *device; |
| 161 | |
Chris Ball | 8ba4466 | 2012-04-19 13:22:54 -0400 | [diff] [blame] | 162 | CHECK(nargs != 2, "Usage: mmc writeprotect set </path/to/mmcblkX>\n", |
| 163 | exit(1)); |
Chris Ball | b9c7a17 | 2012-02-20 12:34:25 -0500 | [diff] [blame] | 164 | |
| 165 | device = argv[1]; |
| 166 | |
| 167 | fd = open(device, O_RDWR); |
| 168 | if (fd < 0) { |
| 169 | perror("open"); |
| 170 | exit(1); |
| 171 | } |
| 172 | |
| 173 | ret = read_extcsd(fd, ext_csd); |
| 174 | if (ret) { |
| 175 | fprintf(stderr, "Could not read EXT_CSD from %s\n", device); |
| 176 | exit(1); |
| 177 | } |
| 178 | |
| 179 | value = ext_csd[EXT_CSD_BOOT_WP] | |
| 180 | EXT_CSD_BOOT_WP_B_PWR_WP_EN; |
| 181 | ret = write_extcsd_value(fd, EXT_CSD_BOOT_WP, value); |
| 182 | if (ret) { |
| 183 | fprintf(stderr, "Could not write 0x%02x to " |
| 184 | "EXT_CSD[%d] in %s\n", |
| 185 | value, EXT_CSD_BOOT_WP, device); |
| 186 | exit(1); |
| 187 | } |
| 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | |
Saugata Das | b7e2599 | 2012-05-17 09:26:34 -0400 | [diff] [blame] | 192 | int do_disable_512B_emulation(int nargs, char **argv) |
| 193 | { |
| 194 | __u8 ext_csd[512], native_sector_size, data_sector_size, wr_rel_param; |
| 195 | int fd, ret; |
| 196 | char *device; |
| 197 | |
| 198 | CHECK(nargs != 2, "Usage: mmc disable 512B emulation </path/to/mmcblkX>\n", exit(1)); |
| 199 | device = argv[1]; |
| 200 | |
| 201 | fd = open(device, O_RDWR); |
| 202 | if (fd < 0) { |
| 203 | perror("open"); |
| 204 | exit(1); |
| 205 | } |
| 206 | |
| 207 | ret = read_extcsd(fd, ext_csd); |
| 208 | if (ret) { |
| 209 | fprintf(stderr, "Could not read EXT_CSD from %s\n", device); |
| 210 | exit(1); |
| 211 | } |
| 212 | |
| 213 | wr_rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; |
| 214 | native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE]; |
| 215 | data_sector_size = ext_csd[EXT_CSD_DATA_SECTOR_SIZE]; |
| 216 | |
| 217 | if (native_sector_size && !data_sector_size && |
| 218 | (wr_rel_param & EN_REL_WR)) { |
| 219 | ret = write_extcsd_value(fd, EXT_CSD_USE_NATIVE_SECTOR, 1); |
| 220 | |
| 221 | if (ret) { |
| 222 | fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n", |
| 223 | 1, EXT_CSD_BOOT_WP, device); |
| 224 | exit(1); |
| 225 | } |
| 226 | printf("MMC disable 512B emulation successful. Now reset the device to switch to 4KB native sector mode.\n"); |
| 227 | } else if (native_sector_size && data_sector_size) { |
| 228 | printf("MMC 512B emulation mode is already disabled; doing nothing.\n"); |
| 229 | } else { |
| 230 | printf("MMC does not support disabling 512B emulation mode.\n"); |
| 231 | } |
| 232 | |
| 233 | return ret; |
| 234 | } |
| 235 | |
Giuseppe CAVALLARO | 7bd1320 | 2012-04-19 10:58:37 +0200 | [diff] [blame] | 236 | int do_write_boot_en(int nargs, char **argv) |
| 237 | { |
| 238 | __u8 ext_csd[512]; |
| 239 | __u8 value = 0; |
| 240 | int fd, ret; |
| 241 | char *device; |
| 242 | int boot_area, send_ack; |
| 243 | |
| 244 | CHECK(nargs != 4, "Usage: mmc bootpart enable <partition_number> " |
| 245 | "<send_ack> </path/to/mmcblkX>\n", exit(1)); |
| 246 | |
| 247 | /* |
| 248 | * If <send_ack> is 1, the device will send acknowledgment |
| 249 | * pattern "010" to the host when boot operation begins. |
| 250 | * If <send_ack> is 0, it won't. |
| 251 | */ |
| 252 | boot_area = strtol(argv[1], NULL, 10); |
| 253 | send_ack = strtol(argv[2], NULL, 10); |
| 254 | device = argv[3]; |
| 255 | |
| 256 | fd = open(device, O_RDWR); |
| 257 | if (fd < 0) { |
| 258 | perror("open"); |
| 259 | exit(1); |
| 260 | } |
| 261 | |
| 262 | ret = read_extcsd(fd, ext_csd); |
| 263 | if (ret) { |
| 264 | fprintf(stderr, "Could not read EXT_CSD from %s\n", device); |
| 265 | exit(1); |
| 266 | } |
| 267 | |
| 268 | value = ext_csd[EXT_CSD_PART_CONFIG]; |
| 269 | |
| 270 | switch (boot_area) { |
| 271 | case EXT_CSD_PART_CONFIG_ACC_BOOT0: |
| 272 | value |= (1 << 3); |
| 273 | value &= ~(3 << 4); |
| 274 | break; |
| 275 | case EXT_CSD_PART_CONFIG_ACC_BOOT1: |
| 276 | value |= (1 << 4); |
| 277 | value &= ~(1 << 3); |
| 278 | value &= ~(1 << 5); |
| 279 | break; |
| 280 | case EXT_CSD_PART_CONFIG_ACC_USER_AREA: |
| 281 | value |= (boot_area << 3); |
| 282 | break; |
| 283 | default: |
| 284 | fprintf(stderr, "Cannot enable the boot area\n"); |
| 285 | exit(1); |
| 286 | } |
| 287 | if (send_ack) |
| 288 | value |= EXT_CSD_PART_CONFIG_ACC_ACK; |
| 289 | else |
| 290 | value &= ~EXT_CSD_PART_CONFIG_ACC_ACK; |
| 291 | |
| 292 | ret = write_extcsd_value(fd, EXT_CSD_PART_CONFIG, value); |
| 293 | if (ret) { |
| 294 | fprintf(stderr, "Could not write 0x%02x to " |
| 295 | "EXT_CSD[%d] in %s\n", |
| 296 | value, EXT_CSD_PART_CONFIG, device); |
| 297 | exit(1); |
| 298 | } |
| 299 | return ret; |
| 300 | } |
| 301 | |
Chris Ball | f74dfe2 | 2012-10-19 16:49:55 -0400 | [diff] [blame] | 302 | int do_hwreset(int value, int nargs, char **argv) |
| 303 | { |
| 304 | __u8 ext_csd[512]; |
| 305 | int fd, ret; |
| 306 | char *device; |
| 307 | |
| 308 | CHECK(nargs != 2, "Usage: mmc hwreset enable </path/to/mmcblkX>\n", |
| 309 | exit(1)); |
| 310 | |
| 311 | device = argv[1]; |
| 312 | |
| 313 | fd = open(device, O_RDWR); |
| 314 | if (fd < 0) { |
| 315 | perror("open"); |
| 316 | exit(1); |
| 317 | } |
| 318 | |
| 319 | ret = read_extcsd(fd, ext_csd); |
| 320 | if (ret) { |
| 321 | fprintf(stderr, "Could not read EXT_CSD from %s\n", device); |
| 322 | exit(1); |
| 323 | } |
| 324 | |
| 325 | if ((ext_csd[EXT_CSD_RST_N_FUNCTION] & EXT_CSD_RST_N_EN_MASK) == |
| 326 | EXT_CSD_HW_RESET_EN) { |
| 327 | fprintf(stderr, |
| 328 | "H/W Reset is already permanently enabled on %s\n", |
| 329 | device); |
| 330 | exit(1); |
| 331 | } |
| 332 | if ((ext_csd[EXT_CSD_RST_N_FUNCTION] & EXT_CSD_RST_N_EN_MASK) == |
| 333 | EXT_CSD_HW_RESET_DIS) { |
| 334 | fprintf(stderr, |
| 335 | "H/W Reset is already permanently disabled on %s\n", |
| 336 | device); |
| 337 | exit(1); |
| 338 | } |
| 339 | |
| 340 | ret = write_extcsd_value(fd, EXT_CSD_RST_N_FUNCTION, value); |
| 341 | if (ret) { |
| 342 | fprintf(stderr, |
| 343 | "Could not write 0x%02x to EXT_CSD[%d] in %s\n", |
| 344 | value, EXT_CSD_RST_N_FUNCTION, device); |
| 345 | exit(1); |
| 346 | } |
| 347 | |
| 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | int do_hwreset_en(int nargs, char **argv) |
| 352 | { |
| 353 | return do_hwreset(EXT_CSD_HW_RESET_EN, nargs, argv); |
| 354 | } |
| 355 | |
| 356 | int do_hwreset_dis(int nargs, char **argv) |
| 357 | { |
| 358 | return do_hwreset(EXT_CSD_HW_RESET_DIS, nargs, argv); |
| 359 | } |
| 360 | |
Jaehoon Chung | 8649651 | 2012-09-21 10:08:05 +0000 | [diff] [blame] | 361 | int do_write_bkops_en(int nargs, char **argv) |
| 362 | { |
| 363 | __u8 ext_csd[512], value = 0; |
| 364 | int fd, ret; |
| 365 | char *device; |
| 366 | |
| 367 | CHECK(nargs != 2, "Usage: mmc bkops enable </path/to/mmcblkX>\n", |
| 368 | exit(1)); |
| 369 | |
| 370 | device = argv[1]; |
| 371 | |
| 372 | fd = open(device, O_RDWR); |
| 373 | if (fd < 0) { |
| 374 | perror("open"); |
| 375 | exit(1); |
| 376 | } |
| 377 | |
| 378 | ret = read_extcsd(fd, ext_csd); |
| 379 | if (ret) { |
| 380 | fprintf(stderr, "Could not read EXT_CSD from %s\n", device); |
| 381 | exit(1); |
| 382 | } |
| 383 | |
| 384 | if (!(ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1)) { |
| 385 | fprintf(stderr, "%s doesn't support BKOPS\n", device); |
| 386 | exit(1); |
| 387 | } |
| 388 | |
| 389 | ret = write_extcsd_value(fd, EXT_CSD_BKOPS_EN, BKOPS_ENABLE); |
| 390 | if (ret) { |
| 391 | fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n", |
| 392 | value, EXT_CSD_BKOPS_EN, device); |
| 393 | exit(1); |
| 394 | } |
| 395 | |
| 396 | return ret; |
| 397 | } |
| 398 | |
Ben Gardiner | 27c357d | 2013-05-30 17:12:47 -0400 | [diff] [blame] | 399 | int do_status_get(int nargs, char **argv) |
| 400 | { |
| 401 | __u32 response; |
| 402 | int fd, ret; |
| 403 | char *device; |
| 404 | |
| 405 | CHECK(nargs != 2, "Usage: mmc status get </path/to/mmcblkX>\n", |
| 406 | exit(1)); |
| 407 | |
| 408 | device = argv[1]; |
| 409 | |
| 410 | fd = open(device, O_RDWR); |
| 411 | if (fd < 0) { |
| 412 | perror("open"); |
| 413 | exit(1); |
| 414 | } |
| 415 | |
| 416 | ret = send_status(fd, &response); |
| 417 | if (ret) { |
| 418 | fprintf(stderr, "Could not read response to SEND_STATUS from %s\n", device); |
| 419 | exit(1); |
| 420 | } |
| 421 | |
| 422 | printf("SEND_STATUS response: 0x%08x\n", response); |
| 423 | |
| 424 | return ret; |
| 425 | } |
| 426 | |
Ben Gardiner | 4e85023 | 2013-05-30 17:12:49 -0400 | [diff] [blame^] | 427 | unsigned int get_sector_count(__u8 *ext_csd) |
| 428 | { |
| 429 | return (ext_csd[EXT_CSD_SEC_COUNT_3] << 24) | |
| 430 | (ext_csd[EXT_CSD_SEC_COUNT_2] << 16) | |
| 431 | (ext_csd[EXT_CSD_SEC_COUNT_1] << 8) | |
| 432 | ext_csd[EXT_CSD_SEC_COUNT_0]; |
| 433 | } |
| 434 | |
| 435 | int is_blockaddresed(__u8 *ext_csd) |
| 436 | { |
| 437 | unsigned int sectors = get_sector_count(ext_csd); |
| 438 | |
| 439 | return (sectors > (2u * 1024 * 1024 * 1024) / 512); |
| 440 | } |
| 441 | |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 442 | int do_read_extcsd(int nargs, char **argv) |
| 443 | { |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 444 | __u8 ext_csd[512], ext_csd_rev, reg; |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 445 | int fd, ret; |
| 446 | char *device; |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 447 | const char *str; |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 448 | |
Chris Ball | 8ba4466 | 2012-04-19 13:22:54 -0400 | [diff] [blame] | 449 | CHECK(nargs != 2, "Usage: mmc extcsd read </path/to/mmcblkX>\n", |
| 450 | exit(1)); |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 451 | |
| 452 | device = argv[1]; |
| 453 | |
| 454 | fd = open(device, O_RDWR); |
| 455 | if (fd < 0) { |
| 456 | perror("open"); |
| 457 | exit(1); |
| 458 | } |
| 459 | |
| 460 | ret = read_extcsd(fd, ext_csd); |
| 461 | if (ret) { |
| 462 | fprintf(stderr, "Could not read EXT_CSD from %s\n", device); |
| 463 | exit(1); |
| 464 | } |
| 465 | |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 466 | ext_csd_rev = ext_csd[192]; |
| 467 | |
| 468 | switch (ext_csd_rev) { |
| 469 | case 6: |
| 470 | str = "4.5"; |
| 471 | break; |
| 472 | case 5: |
| 473 | str = "4.41"; |
| 474 | break; |
| 475 | case 3: |
| 476 | str = "4.3"; |
| 477 | break; |
| 478 | case 2: |
| 479 | str = "4.2"; |
| 480 | break; |
| 481 | case 1: |
| 482 | str = "4.1"; |
| 483 | break; |
| 484 | case 0: |
| 485 | str = "4.0"; |
| 486 | break; |
| 487 | default: |
| 488 | goto out_free; |
| 489 | } |
| 490 | printf("=============================================\n"); |
| 491 | printf(" Extended CSD rev 1.%d (MMC %s)\n", ext_csd_rev, str); |
| 492 | printf("=============================================\n\n"); |
| 493 | |
| 494 | if (ext_csd_rev < 3) |
| 495 | goto out_free; /* No ext_csd */ |
| 496 | |
| 497 | /* Parse the Extended CSD registers. |
| 498 | * Reserved bit should be read as "0" in case of spec older |
| 499 | * than A441. |
| 500 | */ |
| 501 | reg = ext_csd[EXT_CSD_S_CMD_SET]; |
| 502 | printf("Card Supported Command sets [S_CMD_SET: 0x%02x]\n", reg); |
| 503 | if (!reg) |
Chris Ball | b9c7a17 | 2012-02-20 12:34:25 -0500 | [diff] [blame] | 504 | printf(" - Standard MMC command sets\n"); |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 505 | |
| 506 | reg = ext_csd[EXT_CSD_HPI_FEATURE]; |
| 507 | printf("HPI Features [HPI_FEATURE: 0x%02x]: ", reg); |
| 508 | if (reg & EXT_CSD_HPI_SUPP) { |
| 509 | if (reg & EXT_CSD_HPI_IMPL) |
Chris Ball | b9c7a17 | 2012-02-20 12:34:25 -0500 | [diff] [blame] | 510 | printf("implementation based on CMD12\n"); |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 511 | else |
| 512 | printf("implementation based on CMD13\n"); |
| 513 | } |
| 514 | |
| 515 | printf("Background operations support [BKOPS_SUPPORT: 0x%02x]\n", |
| 516 | ext_csd[502]); |
| 517 | |
| 518 | if (ext_csd_rev >= 6) { |
| 519 | printf("Max Packet Read Cmd [MAX_PACKED_READS: 0x%02x]\n", |
| 520 | ext_csd[501]); |
| 521 | printf("Max Packet Write Cmd [MAX_PACKED_WRITES: 0x%02x]\n", |
| 522 | ext_csd[500]); |
| 523 | printf("Data TAG support [DATA_TAG_SUPPORT: 0x%02x]\n", |
| 524 | ext_csd[499]); |
| 525 | |
| 526 | printf("Data TAG Unit Size [TAG_UNIT_SIZE: 0x%02x]\n", |
| 527 | ext_csd[498]); |
| 528 | printf("Tag Resources Size [TAG_RES_SIZE: 0x%02x]\n", |
| 529 | ext_csd[497]); |
| 530 | printf("Context Management Capabilities" |
| 531 | " [CONTEXT_CAPABILITIES: 0x%02x]\n", ext_csd[496]); |
| 532 | printf("Large Unit Size [LARGE_UNIT_SIZE_M1: 0x%02x]\n", |
| 533 | ext_csd[495]); |
| 534 | printf("Extended partition attribute support" |
| 535 | " [EXT_SUPPORT: 0x%02x]\n", ext_csd[494]); |
| 536 | printf("Generic CMD6 Timer [GENERIC_CMD6_TIME: 0x%02x]\n", |
| 537 | ext_csd[248]); |
| 538 | printf("Power off notification [POWER_OFF_LONG_TIME: 0x%02x]\n", |
| 539 | ext_csd[247]); |
| 540 | printf("Cache Size [CACHE_SIZE] is %d KiB\n", |
| 541 | ext_csd[249] << 0 | (ext_csd[250] << 8) | |
| 542 | (ext_csd[251] << 16) | (ext_csd[252] << 24)); |
| 543 | } |
| 544 | |
| 545 | /* A441: Reserved [501:247] |
| 546 | A43: reserved [246:229] */ |
| 547 | if (ext_csd_rev >= 5) { |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 548 | printf("Background operations status" |
Chris Ball | b9c7a17 | 2012-02-20 12:34:25 -0500 | [diff] [blame] | 549 | " [BKOPS_STATUS: 0x%02x]\n", ext_csd[246]); |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 550 | |
| 551 | /* CORRECTLY_PRG_SECTORS_NUM [245:242] TODO */ |
| 552 | |
| 553 | printf("1st Initialisation Time after programmed sector" |
| 554 | " [INI_TIMEOUT_AP: 0x%02x]\n", ext_csd[241]); |
| 555 | |
| 556 | /* A441: reserved [240] */ |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 557 | printf("Power class for 52MHz, DDR at 3.6V" |
| 558 | " [PWR_CL_DDR_52_360: 0x%02x]\n", ext_csd[239]); |
| 559 | printf("Power class for 52MHz, DDR at 1.95V" |
| 560 | " [PWR_CL_DDR_52_195: 0x%02x]\n", ext_csd[238]); |
| 561 | |
| 562 | /* A441: reserved [237-236] */ |
| 563 | |
| 564 | if (ext_csd_rev >= 6) { |
| 565 | printf("Power class for 200MHz at 3.6V" |
| 566 | " [PWR_CL_200_360: 0x%02x]\n", ext_csd[237]); |
| 567 | printf("Power class for 200MHz, at 1.95V" |
| 568 | " [PWR_CL_200_195: 0x%02x]\n", ext_csd[236]); |
| 569 | } |
Chris Ball | b9c7a17 | 2012-02-20 12:34:25 -0500 | [diff] [blame] | 570 | printf("Minimum Performance for 8bit at 52MHz in DDR mode:\n"); |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 571 | printf(" [MIN_PERF_DDR_W_8_52: 0x%02x]\n", ext_csd[235]); |
| 572 | printf(" [MIN_PERF_DDR_R_8_52: 0x%02x]\n", ext_csd[234]); |
| 573 | /* A441: reserved [233] */ |
| 574 | printf("TRIM Multiplier [TRIM_MULT: 0x%02x]\n", ext_csd[232]); |
| 575 | printf("Secure Feature support [SEC_FEATURE_SUPPORT: 0x%02x]\n", |
| 576 | ext_csd[231]); |
| 577 | } |
| 578 | if (ext_csd_rev == 5) { /* Obsolete in 4.5 */ |
| 579 | printf("Secure Erase Multiplier [SEC_ERASE_MULT: 0x%02x]\n", |
| 580 | ext_csd[230]); |
| 581 | printf("Secure TRIM Multiplier [SEC_TRIM_MULT: 0x%02x]\n", |
| 582 | ext_csd[229]); |
| 583 | } |
| 584 | reg = ext_csd[EXT_CSD_BOOT_INFO]; |
| 585 | printf("Boot Information [BOOT_INFO: 0x%02x]\n", reg); |
| 586 | if (reg & EXT_CSD_BOOT_INFO_ALT) |
| 587 | printf(" Device supports alternative boot method\n"); |
| 588 | if (reg & EXT_CSD_BOOT_INFO_DDR_DDR) |
| 589 | printf(" Device supports dual data rate during boot\n"); |
| 590 | if (reg & EXT_CSD_BOOT_INFO_HS_MODE) |
| 591 | printf(" Device supports high speed timing during boot\n"); |
| 592 | |
| 593 | /* A441/A43: reserved [227] */ |
| 594 | printf("Boot partition size [BOOT_SIZE_MULTI: 0x%02x]\n", ext_csd[226]); |
| 595 | printf("Access size [ACC_SIZE: 0x%02x]\n", ext_csd[225]); |
| 596 | printf("High-capacity erase unit size [HC_ERASE_GRP_SIZE: 0x%02x]\n", |
| 597 | ext_csd[224]); |
| 598 | printf("High-capacity erase timeout [ERASE_TIMEOUT_MULT: 0x%02x]\n", |
| 599 | ext_csd[223]); |
| 600 | printf("Reliable write sector count [REL_WR_SEC_C: 0x%02x]\n", |
| 601 | ext_csd[222]); |
| 602 | printf("High-capacity W protect group size [HC_WP_GRP_SIZE: 0x%02x]\n", |
| 603 | ext_csd[221]); |
| 604 | printf("Sleep current (VCC) [S_C_VCC: 0x%02x]\n", ext_csd[220]); |
| 605 | printf("Sleep current (VCCQ) [S_C_VCCQ: 0x%02x]\n", ext_csd[219]); |
| 606 | /* A441/A43: reserved [218] */ |
| 607 | printf("Sleep/awake timeout [S_A_TIMEOUT: 0x%02x]\n", ext_csd[217]); |
| 608 | /* A441/A43: reserved [216] */ |
Ben Gardiner | 4e85023 | 2013-05-30 17:12:49 -0400 | [diff] [blame^] | 609 | |
| 610 | unsigned int sectors = get_sector_count(ext_csd); |
| 611 | printf("Sector Count [SEC_COUNT: 0x%08x]\n", sectors); |
| 612 | if (is_blockaddresed(ext_csd)) |
| 613 | printf(" Device is block-addressed\n"); |
| 614 | else |
| 615 | printf(" Device is NOT block-addressed\n"); |
| 616 | |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 617 | /* A441/A43: reserved [211] */ |
| 618 | printf("Minimum Write Performance for 8bit:\n"); |
| 619 | printf(" [MIN_PERF_W_8_52: 0x%02x]\n", ext_csd[210]); |
| 620 | printf(" [MIN_PERF_R_8_52: 0x%02x]\n", ext_csd[209]); |
| 621 | printf(" [MIN_PERF_W_8_26_4_52: 0x%02x]\n", ext_csd[208]); |
| 622 | printf(" [MIN_PERF_R_8_26_4_52: 0x%02x]\n", ext_csd[207]); |
| 623 | printf("Minimum Write Performance for 4bit:\n"); |
| 624 | printf(" [MIN_PERF_W_4_26: 0x%02x]\n", ext_csd[206]); |
| 625 | printf(" [MIN_PERF_R_4_26: 0x%02x]\n", ext_csd[205]); |
| 626 | /* A441/A43: reserved [204] */ |
| 627 | printf("Power classes registers:\n"); |
| 628 | printf(" [PWR_CL_26_360: 0x%02x]\n", ext_csd[203]); |
| 629 | printf(" [PWR_CL_52_360: 0x%02x]\n", ext_csd[202]); |
| 630 | printf(" [PWR_CL_26_195: 0x%02x]\n", ext_csd[201]); |
| 631 | printf(" [PWR_CL_52_195: 0x%02x]\n", ext_csd[200]); |
| 632 | |
| 633 | /* A43: reserved [199:198] */ |
| 634 | if (ext_csd_rev >= 5) { |
| 635 | printf("Partition switching timing " |
| 636 | "[PARTITION_SWITCH_TIME: 0x%02x]\n", ext_csd[199]); |
| 637 | printf("Out-of-interrupt busy timing" |
| 638 | " [OUT_OF_INTERRUPT_TIME: 0x%02x]\n", ext_csd[198]); |
| 639 | } |
| 640 | |
| 641 | /* A441/A43: reserved [197] [195] [193] [190] [188] |
| 642 | * [186] [184] [182] [180] [176] */ |
| 643 | |
| 644 | if (ext_csd_rev >= 6) |
| 645 | printf("I/O Driver Strength [DRIVER_STRENGTH: 0x%02x]\n", |
| 646 | ext_csd[197]); |
| 647 | |
Oleg Matcovschi | 64f63a3 | 2013-05-23 17:11:07 -0700 | [diff] [blame] | 648 | /* DEVICE_TYPE in A45, CARD_TYPE in A441 */ |
| 649 | reg = ext_csd[196]; |
| 650 | printf("Card Type [CARD_TYPE: 0x%02x]\n", reg); |
| 651 | if (reg & 0x20) printf(" HS200 Single Data Rate eMMC @200MHz 1.2VI/O\n"); |
| 652 | if (reg & 0x10) printf(" HS200 Single Data Rate eMMC @200MHz 1.8VI/O\n"); |
| 653 | if (reg & 0x08) printf(" HS Dual Data Rate eMMC @52MHz 1.2VI/O\n"); |
| 654 | if (reg & 0x04) printf(" HS Dual Data Rate eMMC @52MHz 1.8V or 3VI/O\n"); |
| 655 | if (reg & 0x02) printf(" HS eMMC @52MHz - at rated device voltage(s)\n"); |
| 656 | if (reg & 0x01) printf(" HS eMMC @26MHz - at rated device voltage(s)\n"); |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 657 | |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 658 | printf("CSD structure version [CSD_STRUCTURE: 0x%02x]\n", ext_csd[194]); |
| 659 | /* ext_csd_rev = ext_csd[192] (already done!!!) */ |
| 660 | printf("Command set [CMD_SET: 0x%02x]\n", ext_csd[191]); |
| 661 | printf("Command set revision [CMD_SET_REV: 0x%02x]\n", ext_csd[189]); |
| 662 | printf("Power class [POWER_CLASS: 0x%02x]\n", ext_csd[187]); |
| 663 | printf("High-speed interface timing [HS_TIMING: 0x%02x]\n", |
| 664 | ext_csd[185]); |
| 665 | /* bus_width: ext_csd[183] not readable */ |
| 666 | printf("Erased memory content [ERASED_MEM_CONT: 0x%02x]\n", |
| 667 | ext_csd[181]); |
| 668 | reg = ext_csd[EXT_CSD_BOOT_CFG]; |
| 669 | printf("Boot configuration bytes [PARTITION_CONFIG: 0x%02x]\n", reg); |
Mario Schuknecht | 8c0c40d | 2013-05-15 08:28:04 +0200 | [diff] [blame] | 670 | switch ((reg & EXT_CSD_BOOT_CFG_EN)>>3) { |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 671 | case 0x0: |
| 672 | printf(" Not boot enable\n"); |
| 673 | break; |
| 674 | case 0x1: |
| 675 | printf(" Boot Partition 1 enabled\n"); |
| 676 | break; |
| 677 | case 0x2: |
| 678 | printf(" Boot Partition 2 enabled\n"); |
| 679 | break; |
| 680 | case 0x7: |
| 681 | printf(" User Area Enabled for boot\n"); |
| 682 | break; |
| 683 | } |
| 684 | switch (reg & EXT_CSD_BOOT_CFG_ACC) { |
| 685 | case 0x0: |
| 686 | printf(" No access to boot partition\n"); |
| 687 | break; |
| 688 | case 0x1: |
| 689 | printf(" R/W Boot Partition 1\n"); |
| 690 | break; |
| 691 | case 0x2: |
| 692 | printf(" R/W Boot Partition 2\n"); |
| 693 | break; |
Mario Schuknecht | 8c0c40d | 2013-05-15 08:28:04 +0200 | [diff] [blame] | 694 | case 0x3: |
| 695 | printf(" R/W Replay Protected Memory Block (RPMB)\n"); |
| 696 | break; |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 697 | default: |
Mario Schuknecht | 8c0c40d | 2013-05-15 08:28:04 +0200 | [diff] [blame] | 698 | printf(" Access to General Purpose partition %d\n", |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 699 | (reg & EXT_CSD_BOOT_CFG_ACC) - 3); |
| 700 | break; |
| 701 | } |
| 702 | |
| 703 | printf("Boot config protection [BOOT_CONFIG_PROT: 0x%02x]\n", |
| 704 | ext_csd[178]); |
| 705 | printf("Boot bus Conditions [BOOT_BUS_CONDITIONS: 0x%02x]\n", |
| 706 | ext_csd[177]); |
| 707 | printf("High-density erase group definition" |
| 708 | " [ERASE_GROUP_DEF: 0x%02x]\n", ext_csd[175]); |
| 709 | |
Chris Ball | b9c7a17 | 2012-02-20 12:34:25 -0500 | [diff] [blame] | 710 | print_writeprotect_status(ext_csd); |
| 711 | |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 712 | if (ext_csd_rev >= 5) { |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 713 | /* A441]: reserved [172] */ |
| 714 | printf("User area write protection register" |
| 715 | " [USER_WP]: 0x%02x\n", ext_csd[171]); |
| 716 | /* A441]: reserved [170] */ |
| 717 | printf("FW configuration [FW_CONFIG]: 0x%02x\n", ext_csd[169]); |
| 718 | printf("RPMB Size [RPMB_SIZE_MULT]: 0x%02x\n", ext_csd[168]); |
| 719 | printf("Write reliability setting register" |
| 720 | " [WR_REL_SET]: 0x%02x\n", ext_csd[167]); |
| 721 | printf("Write reliability parameter register" |
| 722 | " [WR_REL_PARAM]: 0x%02x\n", ext_csd[166]); |
| 723 | /* sanitize_start ext_csd[165]]: not readable |
| 724 | * bkops_start ext_csd[164]]: only writable */ |
| 725 | printf("Enable background operations handshake" |
| 726 | " [BKOPS_EN]: 0x%02x\n", ext_csd[163]); |
| 727 | printf("H/W reset function" |
| 728 | " [RST_N_FUNCTION]: 0x%02x\n", ext_csd[162]); |
| 729 | printf("HPI management [HPI_MGMT]: 0x%02x\n", ext_csd[161]); |
Ben Gardiner | 82bd950 | 2013-06-27 11:04:10 -0400 | [diff] [blame] | 730 | reg = ext_csd[EXT_CSD_PARTITIONING_SUPPORT]; |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 731 | printf("Partitioning Support [PARTITIONING_SUPPORT]: 0x%02x\n", |
| 732 | reg); |
Ben Gardiner | 82bd950 | 2013-06-27 11:04:10 -0400 | [diff] [blame] | 733 | if (reg & EXT_CSD_PARTITIONING_EN) |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 734 | printf(" Device support partitioning feature\n"); |
| 735 | else |
| 736 | printf(" Device NOT support partitioning feature\n"); |
Ben Gardiner | 82bd950 | 2013-06-27 11:04:10 -0400 | [diff] [blame] | 737 | if (reg & EXT_CSD_ENH_ATTRIBUTE_EN) |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 738 | printf(" Device can have enhanced tech.\n"); |
| 739 | else |
| 740 | printf(" Device cannot have enhanced tech.\n"); |
| 741 | |
| 742 | printf("Max Enhanced Area Size [MAX_ENH_SIZE_MULT]: 0x%06x\n", |
| 743 | (ext_csd[159] << 16) | (ext_csd[158] << 8) | |
| 744 | ext_csd[157]); |
| 745 | printf("Partitions attribute [PARTITIONS_ATTRIBUTE]: 0x%02x\n", |
| 746 | ext_csd[156]); |
Ben Gardiner | a6cd98d | 2013-05-30 17:12:46 -0400 | [diff] [blame] | 747 | reg = ext_csd[EXT_CSD_PARTITION_SETTING_COMPLETED]; |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 748 | printf("Partitioning Setting" |
| 749 | " [PARTITION_SETTING_COMPLETED]: 0x%02x\n", |
Ben Gardiner | a6cd98d | 2013-05-30 17:12:46 -0400 | [diff] [blame] | 750 | reg); |
| 751 | if (reg) |
| 752 | printf(" Device partition setting complete\n"); |
| 753 | else |
| 754 | printf(" Device partition setting NOT complete\n"); |
| 755 | |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 756 | printf("General Purpose Partition Size\n" |
| 757 | " [GP_SIZE_MULT_4]: 0x%06x\n", (ext_csd[154] << 16) | |
| 758 | (ext_csd[153] << 8) | ext_csd[152]); |
| 759 | printf(" [GP_SIZE_MULT_3]: 0x%06x\n", (ext_csd[151] << 16) | |
| 760 | (ext_csd[150] << 8) | ext_csd[149]); |
| 761 | printf(" [GP_SIZE_MULT_2]: 0x%06x\n", (ext_csd[148] << 16) | |
| 762 | (ext_csd[147] << 8) | ext_csd[146]); |
| 763 | printf(" [GP_SIZE_MULT_1]: 0x%06x\n", (ext_csd[145] << 16) | |
| 764 | (ext_csd[144] << 8) | ext_csd[143]); |
| 765 | |
| 766 | printf("Enhanced User Data Area Size" |
| 767 | " [ENH_SIZE_MULT]: 0x%06x\n", (ext_csd[142] << 16) | |
| 768 | (ext_csd[141] << 8) | ext_csd[140]); |
Ben Gardiner | 68f490b | 2013-05-30 17:12:48 -0400 | [diff] [blame] | 769 | |
| 770 | reg = (ext_csd[EXT_CSD_ENH_START_ADDR_3] << 24) | |
| 771 | (ext_csd[EXT_CSD_ENH_START_ADDR_2] << 16) | |
| 772 | (ext_csd[EXT_CSD_ENH_START_ADDR_1] << 8) | |
| 773 | ext_csd[EXT_CSD_ENH_START_ADDR_0]; |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 774 | printf("Enhanced User Data Start Address" |
Ben Gardiner | 68f490b | 2013-05-30 17:12:48 -0400 | [diff] [blame] | 775 | " [ENH_START_ADDR]: 0x%06x\n", reg); |
Ben Gardiner | 4e85023 | 2013-05-30 17:12:49 -0400 | [diff] [blame^] | 776 | printf(" i.e. %lu bytes offset\n", (is_blockaddresed(ext_csd) ? |
| 777 | 1l : 512l) * reg); |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 778 | |
| 779 | /* A441]: reserved [135] */ |
| 780 | printf("Bad Block Management mode" |
| 781 | " [SEC_BAD_BLK_MGMNT]: 0x%02x\n", ext_csd[134]); |
| 782 | /* A441: reserved [133:0] */ |
| 783 | } |
| 784 | /* B45 */ |
| 785 | if (ext_csd_rev >= 6) { |
| 786 | int j; |
| 787 | /* tcase_support ext_csd[132] not readable */ |
| 788 | printf("Periodic Wake-up [PERIODIC_WAKEUP]: 0x%02x\n", |
| 789 | ext_csd[131]); |
| 790 | printf("Program CID/CSD in DDR mode support" |
| 791 | " [PROGRAM_CID_CSD_DDR_SUPPORT]: 0x%02x\n", |
| 792 | ext_csd[130]); |
| 793 | |
| 794 | for (j = 127; j >= 64; j--) |
| 795 | printf("Vendor Specific Fields" |
| 796 | " [VENDOR_SPECIFIC_FIELD[%d]]: 0x%02x\n", |
| 797 | j, ext_csd[j]); |
| 798 | |
| 799 | printf("Native sector size [NATIVE_SECTOR_SIZE]: 0x%02x\n", |
| 800 | ext_csd[63]); |
| 801 | printf("Sector size emulation [USE_NATIVE_SECTOR]: 0x%02x\n", |
| 802 | ext_csd[62]); |
| 803 | printf("Sector size [DATA_SECTOR_SIZE]: 0x%02x\n", ext_csd[61]); |
| 804 | printf("1st initialization after disabling sector" |
| 805 | " size emulation [INI_TIMEOUT_EMU]: 0x%02x\n", |
| 806 | ext_csd[60]); |
| 807 | printf("Class 6 commands control [CLASS_6_CTRL]: 0x%02x\n", |
| 808 | ext_csd[59]); |
| 809 | printf("Number of addressed group to be Released" |
| 810 | "[DYNCAP_NEEDED]: 0x%02x\n", ext_csd[58]); |
| 811 | printf("Exception events control" |
| 812 | " [EXCEPTION_EVENTS_CTRL]: 0x%04x\n", |
| 813 | (ext_csd[57] << 8) | ext_csd[56]); |
| 814 | printf("Exception events status" |
| 815 | "[EXCEPTION_EVENTS_STATUS]: 0x%04x\n", |
| 816 | (ext_csd[55] << 8) | ext_csd[54]); |
| 817 | printf("Extended Partitions Attribute" |
| 818 | " [EXT_PARTITIONS_ATTRIBUTE]: 0x%04x\n", |
| 819 | (ext_csd[53] << 8) | ext_csd[52]); |
| 820 | |
| 821 | for (j = 51; j >= 37; j--) |
| 822 | printf("Context configuration" |
| 823 | " [CONTEXT_CONF[%d]]: 0x%02x\n", j, ext_csd[j]); |
| 824 | |
| 825 | printf("Packed command status" |
| 826 | " [PACKED_COMMAND_STATUS]: 0x%02x\n", ext_csd[36]); |
| 827 | printf("Packed command failure index" |
| 828 | " [PACKED_FAILURE_INDEX]: 0x%02x\n", ext_csd[35]); |
| 829 | printf("Power Off Notification" |
| 830 | " [POWER_OFF_NOTIFICATION]: 0x%02x\n", ext_csd[34]); |
Oleg Matcovschi | 64f63a3 | 2013-05-23 17:11:07 -0700 | [diff] [blame] | 831 | printf("Control to turn the Cache ON/OFF" |
| 832 | " [CACHE_CTRL]: 0x%02x\n", ext_csd[33]); |
Giuseppe CAVALLARO | a5bf4a2 | 2012-02-20 09:45:29 +0100 | [diff] [blame] | 833 | /* flush_cache ext_csd[32] not readable */ |
| 834 | /*Reserved [31:0] */ |
| 835 | } |
| 836 | |
| 837 | out_free: |
Johan RUDHOLM | a8bfde7 | 2012-02-12 11:46:44 -0500 | [diff] [blame] | 838 | return ret; |
| 839 | } |
Yaniv Gardi | 21bb473 | 2013-05-26 13:25:33 -0400 | [diff] [blame] | 840 | |
| 841 | int do_sanitize(int nargs, char **argv) |
| 842 | { |
| 843 | int fd, ret; |
| 844 | char *device; |
| 845 | |
| 846 | CHECK(nargs != 2, "Usage: mmc sanitize </path/to/mmcblkX>\n", |
| 847 | exit(1)); |
| 848 | |
| 849 | device = argv[1]; |
| 850 | |
| 851 | fd = open(device, O_RDWR); |
| 852 | if (fd < 0) { |
| 853 | perror("open"); |
| 854 | exit(1); |
| 855 | } |
| 856 | |
| 857 | ret = write_extcsd_value(fd, EXT_CSD_SANITIZE_START, 1); |
| 858 | if (ret) { |
| 859 | fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n", |
| 860 | 1, EXT_CSD_SANITIZE_START, device); |
| 861 | exit(1); |
| 862 | } |
| 863 | |
| 864 | return ret; |
| 865 | |
| 866 | } |
| 867 | |