X-Git-Url: https://git.kernelconcepts.de/?a=blobdiff_plain;f=common%2Fcmd_mmc.c;h=eb0976b4d8b1e01973db70368d050a53ddb8a845;hb=aa23280e1c7b5d3a6d934570e83bb71136ace206;hp=96478e45c14039cd88a1a59427d0ec7f1a44d07e;hpb=b9206e61f3d87535ac4f4b0b858e674fd1edfeaf;p=karo-tx-uboot.git diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c index 96478e45c1..eb0976b4d8 100644 --- a/common/cmd_mmc.c +++ b/common/cmd_mmc.c @@ -11,7 +11,7 @@ static int curr_device = -1; #ifndef CONFIG_GENERIC_MMC -int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +int do_mmc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int dev; @@ -32,7 +32,7 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (mmc_legacy_init(dev) != 0) { puts("No MMC card found\n"); - return 1; + return CMD_RET_FAILURE; } curr_device = dev; @@ -41,14 +41,14 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc == 2) { if (curr_device < 0) { puts("No MMC device available\n"); - return 1; + return CMD_RET_FAILURE; } } 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; + return CMD_RET_FAILURE; #endif curr_device = dev; } else { @@ -60,7 +60,7 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_USAGE; } - return 0; + return CMD_RET_SUCCESS; } U_BOOT_CMD( @@ -73,6 +73,8 @@ U_BOOT_CMD( static void print_mmcinfo(struct mmc *mmc) { + int i; + printf("Device: %s\n", mmc->cfg->name); printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24); printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff); @@ -83,8 +85,12 @@ static void print_mmcinfo(struct mmc *mmc) printf("Tran Speed: %d\n", mmc->tran_speed); printf("Rd Block Len: %d\n", mmc->read_bl_len); - printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC", - (mmc->version >> 8) & 0xf, mmc->version & 0xff); + 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("\n"); printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No"); puts("Capacity: "); @@ -92,7 +98,50 @@ static void print_mmcinfo(struct mmc *mmc) printf("Bus Width: %d-bit%s\n", mmc->bus_width, mmc->ddr_mode ? " DDR" : ""); + + puts("Erase Group Size: "); + print_size(((u64)mmc->erase_grp_size) << 9, "\n"); + + if (!IS_SD(mmc) && mmc->version >= MMC_VERSION_4_41) { + bool has_enh = (mmc->part_support & ENHNCD_SUPPORT) != 0; + bool usr_enh = has_enh && (mmc->part_attr & EXT_CSD_ENH_USR); + + puts("HC WP Group Size: "); + print_size(((u64)mmc->hc_wp_grp_size) << 9, "\n"); + + puts("User Capacity: "); + print_size(mmc->capacity_user, usr_enh ? " ENH" : ""); + if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_USR) + puts(" WRREL\n"); + else + putc('\n'); + if (usr_enh) { + puts("User Enhanced Start: "); + print_size(mmc->enh_user_start, "\n"); + puts("User Enhanced Size: "); + print_size(mmc->enh_user_size, "\n"); + } + puts("Boot Capacity: "); + print_size(mmc->capacity_boot, has_enh ? " ENH\n" : "\n"); + puts("RPMB Capacity: "); + print_size(mmc->capacity_rpmb, has_enh ? " ENH\n" : "\n"); + + for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) { + bool is_enh = has_enh && + (mmc->part_attr & EXT_CSD_ENH_GP(i)); + if (mmc->capacity_gp[i]) { + printf("GP%i Capacity: ", i+1); + print_size(mmc->capacity_gp[i], + is_enh ? " ENH" : ""); + if (mmc->wr_rel_set & EXT_CSD_WR_DATA_REL_GP(i)) + puts(" WRREL\n"); + else + putc('\n'); + } + } + } } + static struct mmc *init_mmc_device(int dev, bool force_init) { struct mmc *mmc; @@ -107,6 +156,7 @@ static struct mmc *init_mmc_device(int dev, bool force_init) return NULL; return mmc; } + static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct mmc *mmc; @@ -116,7 +166,7 @@ static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) curr_device = 0; else { puts("No MMC device available\n"); - return 1; + return CMD_RET_FAILURE; } } @@ -140,6 +190,7 @@ static int confirm_key_prog(void) puts("Authentication key programming aborted\n"); return 0; } + static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -158,6 +209,7 @@ static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag, } return CMD_RET_SUCCESS; } + static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -186,6 +238,7 @@ static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; return CMD_RET_SUCCESS; } + static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -212,6 +265,7 @@ static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; return CMD_RET_SUCCESS; } + static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -309,6 +363,7 @@ static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; } + static int do_mmc_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -339,6 +394,7 @@ static int do_mmc_write(cmd_tbl_t *cmdtp, int flag, 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[]) { @@ -367,6 +423,7 @@ static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag, return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; } + static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -378,6 +435,7 @@ static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag, return CMD_RET_SUCCESS; } + static int do_mmc_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -397,6 +455,7 @@ static int do_mmc_part(cmd_tbl_t *cmdtp, int flag, puts("get mmc type error!\n"); return CMD_RET_FAILURE; } + static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -438,12 +497,163 @@ static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag, return CMD_RET_SUCCESS; } + static int do_mmc_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { print_mmc_devices('\n'); return CMD_RET_SUCCESS; } + +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; +} + +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; + int i, r, pidx; + + 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) { + if (!strcmp(argv[i], "user")) { + i++; + r = parse_hwpart_user(&pconf, argc-i, &argv[i]); + if (r < 0) + return CMD_RET_USAGE; + i += r; + } else if (!strncmp(argv[i], "gp", 2) && + strlen(argv[i]) == 3 && + argv[i][2] >= '1' && argv[i][2] <= '4') { + pidx = argv[i][2] - '1'; + i++; + r = parse_hwpart_gp(&pconf, pidx, argc-i, &argv[i]); + if (r < 0) + return CMD_RET_USAGE; + i += r; + } 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:\n"); + if (pconf.user.enh_size) { + puts("\tUser Enhanced Start: "); + print_size(((u64)pconf.user.enh_start) << 9, "\n"); + puts("\tUser Enhanced Size: "); + print_size(((u64)pconf.user.enh_size) << 9, "\n"); + } else { + puts("\tNo enhanced user data area\n"); + } + if (pconf.user.wr_rel_change) + printf("\tUser partition write reliability: %s\n", + pconf.user.wr_rel_set ? "on" : "off"); + 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\n" : "\n"); + } else { + printf("\tNo GP%i partition\n", pidx+1); + } + if (pconf.gp_part[pidx].wr_rel_change) + printf("\tGP%i write reliability: %s\n", pidx+1, + pconf.gp_part[pidx].wr_rel_set ? "on" : "off"); + } + + if (!mmc_hwpart_config(mmc, &pconf, mode)) { + if (mode == MMC_HWPART_CONF_COMPLETE) + puts("Partitioning successful, power-cycle to make effective\n"); + return CMD_RET_SUCCESS; + } else { + puts("Failed!\n"); + return CMD_RET_FAILURE; + } +} + #ifdef CONFIG_SUPPORT_EMMC_BOOT static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -451,50 +661,97 @@ static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag, int dev; struct mmc *mmc; u8 width, reset, mode; + int ret; + char *end; 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); + + dev = simple_strtoul(argv[1], &end, 10); + if (dev < 0 || dev >= get_mmc_dev_count() || *end != '\0') { + printf("Invalid mmc device '%s'; should be [0..%u]\n", + argv[1], get_mmc_dev_count() - 1); + return CMD_RET_FAILURE; + } + + width = simple_strtoul(argv[2], &end, 10); + if (width > 2 || *end != '\0') { + printf("Invalid boot_bus_width parameter '%s'; expected [0..2]\n", + argv[2]); + return CMD_RET_FAILURE; + } + + reset = simple_strtoul(argv[3], &end, 10); + if (reset > 1 || *end != '\0') { + printf("Invalid reset_boot_bus_width parameter '%s'; expected 0 or 1\n", + argv[3]); + return CMD_RET_FAILURE; + } + mode = simple_strtoul(argv[4], &end, 10); + if (mode > 2 || *end != '\0') { + printf("Invalid boot_mode parameter '%s'; expected [0..2]\n", + argv[4]); + return CMD_RET_FAILURE; + } mmc = init_mmc_device(dev, false); - if (!mmc) + if (!mmc) { + printf("Failed to init MMC device %d\n", dev); return CMD_RET_FAILURE; + } if (IS_SD(mmc)) { puts("BOOT_BUS_WIDTH only exists on eMMC\n"); return CMD_RET_FAILURE; } - /* acknowledge to be sent during boot operation */ - return mmc_set_boot_bus_width(mmc, width, reset, mode); + ret = mmc_set_boot_bus_width(mmc, width, reset, mode); + if (ret) + printf("Setting boot bus width failed: %d\n", ret); + return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS; } + 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; + int ret; + char *end; 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); + + dev = simple_strtoul(argv[1], &end, 10); + if (dev < 0 || dev >= get_mmc_dev_count() || *end != '\0') { + printf("Invalid mmc device '%s'; should be [0..%u]\n", + argv[1], get_mmc_dev_count() - 1); + return CMD_RET_FAILURE; + } + + bootsize = simple_strtoul(argv[2], &end, 10); + if (bootsize > 64 || *end != '\0') { + return CMD_RET_FAILURE; + } + + rpmbsize = simple_strtoul(argv[3], &end, 10); + if (rpmbsize > 64 || *end != '\0') { + return CMD_RET_FAILURE; + } mmc = init_mmc_device(dev, false); if (!mmc) return CMD_RET_FAILURE; if (IS_SD(mmc)) { - printf("It is not a EMMC device\n"); + printf("mmc device %d is not an EMMC device\n", dev); return CMD_RET_FAILURE; } - if (mmc_boot_partition_size_change(mmc, bootsize, rpmbsize)) { - printf("EMMC boot partition Size change Failed.\n"); + ret = mmc_boot_partition_size_change(mmc, bootsize, rpmbsize); + if (ret) { + printf("EMMC boot partition size change failed: %d\n", ret); return CMD_RET_FAILURE; } @@ -502,20 +759,43 @@ static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag, printf("EMMC RPMB partition Size %d MB\n", rpmbsize); return CMD_RET_SUCCESS; } + 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; + char *end; + int ret; if (argc != 5) return CMD_RET_USAGE; - dev = simple_strtoul(argv[1], NULL, 10); - ack = simple_strtoul(argv[2], NULL, 10); - part_num = simple_strtoul(argv[3], NULL, 10); - access = simple_strtoul(argv[4], NULL, 10); + dev = simple_strtoul(argv[1], &end, 10); + if (dev < 0 || dev >= get_mmc_dev_count() || *end != '\0') { + printf("Invalid mmc device '%s'; should be [0..%u]\n", + argv[1], get_mmc_dev_count() - 1); + return CMD_RET_FAILURE; + } + + ack = simple_strtoul(argv[2], &end, 10); + if (ack < 0 || ack > 1 || *end != '\0') { + printf("Invalid boot_ack value: %s\n", argv[2]); + return CMD_RET_FAILURE; + } + + part_num = simple_strtoul(argv[3], &end, 10); + if (part_num < 0 || (part_num > 4 && part_num != 7) || *end != '\0') { + printf("Invalid part_num: %s\n", argv[3]); + return CMD_RET_FAILURE; + } + + access = simple_strtoul(argv[4], &end, 10); + if (access < 0 || access > 7 || *end != '\0') { + printf("Invalid access value: %s\n", argv[4]); + return CMD_RET_FAILURE; + } mmc = init_mmc_device(dev, false); if (!mmc) @@ -527,14 +807,19 @@ static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag, } /* acknowledge to be sent during boot operation */ - return mmc_set_part_conf(mmc, ack, part_num, access); + ret = mmc_set_part_conf(mmc, ack, part_num, access); + if (ret) + printf("partconf failed: %d\n", ret); + return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS; } + static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int dev; struct mmc *mmc; u8 enable; + char *end; /* * Set the RST_n_ENABLE bit of RST_n_FUNCTION @@ -544,8 +829,14 @@ static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag, if (argc != 3) return CMD_RET_USAGE; - dev = simple_strtoul(argv[1], NULL, 10); - enable = simple_strtoul(argv[2], NULL, 10); + dev = simple_strtoul(argv[1], &end, 10); + if (dev < 0 || dev >= get_mmc_dev_count() || *end != '\0') { + printf("Invalid mmc device '%s'; should be [0..%u]\n", + argv[1], get_mmc_dev_count() - 1); + return CMD_RET_FAILURE; + } + + enable = simple_strtoul(argv[2], &end, 10); if (enable > 2 || enable < 0) { puts("Invalid RST_n_ENABLE value\n"); @@ -564,16 +855,23 @@ static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag, 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; + char *end; int ret; if (argc != 2) return CMD_RET_USAGE; - val = simple_strtoul(argv[2], NULL, 16); + val = simple_strtoul(argv[2], &end, 16); + if (val > 0xffff || *end != '\0') { + printf("Invalid DSR value '%s'; expected hex number [0..ffff]\n", + argv[2]); + return CMD_RET_FAILURE; + } mmc = find_mmc_device(curr_device); if (!mmc) { @@ -601,6 +899,7 @@ static cmd_tbl_t cmd_mmc[] = { 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, "", ""), + U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""), #ifdef CONFIG_SUPPORT_EMMC_BOOT U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""), U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""), @@ -640,7 +939,7 @@ static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } U_BOOT_CMD( - mmc, 7, 1, do_mmcops, + mmc, 29, 1, do_mmcops, "MMC sub system", "info - display info of the current MMC device\n" "mmc read addr blk# cnt\n" @@ -650,6 +949,13 @@ U_BOOT_CMD( "mmc part - lists available partition on current mmc device\n" "mmc dev [dev] [part] - show or set current mmc device [partition]\n" "mmc list - lists available devices\n" + "mmc hwpartition [args...] - does hardware partitioning\n" + " arguments (sizes in 512-byte blocks):\n" + " [user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes\n" + " [gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition\n" + " [check|set|complete] - mode, complete set partitioning completed\n" + " WARNING: Partitioning is a write-once setting once it is set to complete.\n" + " Power cycling is required to initialize partitions after set to complete.\n" #ifdef CONFIG_SUPPORT_EMMC_BOOT "mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n" " - Set the BOOT_BUS_WIDTH field of the specified device\n"