X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=cmd%2Fmmc.c;h=d8f96af9fae007f093a9c7cd44f80d2e83f38b2a;hb=bea0a51b2cfa30b476cdd19b41493be844e555ab;hp=c5454bf2e130fac5b5d577fbfb2ee97ed3aaa268;hpb=52b1eaf93d6b55e1467f97b8eefdc2f8b6031c43;p=karo-tx-uboot.git diff --git a/cmd/mmc.c b/cmd/mmc.c index c5454bf2e1..d8f96af9fa 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -11,66 +11,6 @@ #include static int curr_device = -1; -#ifndef CONFIG_GENERIC_MMC -int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - int dev; - - if (argc < 2) - return CMD_RET_USAGE; - - 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 { - return CMD_RET_USAGE; - } - - if (mmc_legacy_init(dev) != 0) { - puts("No MMC card found\n"); - return 1; - } - - curr_device = dev; - printf("mmc%d is available\n", curr_device); - } else if (strcmp(argv[1], "device") == 0) { - if (argc == 2) { - if (curr_device < 0) { - puts("No MMC device available\n"); - 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 { - return CMD_RET_USAGE; - } - - printf("mmc%d is current device\n", curr_device); - } else { - return CMD_RET_USAGE; - } - - return 0; -} - -U_BOOT_CMD( - mmc, 3, 1, do_mmc, - "MMC sub-system", - "init [dev] - init MMC sub system\n" - "mmc device [dev] - show or set current device" -); -#else /* !CONFIG_GENERIC_MMC */ static void print_mmcinfo(struct mmc *mmc) { @@ -142,10 +82,11 @@ static void print_mmcinfo(struct mmc *mmc) } } } + static struct mmc *init_mmc_device(int dev, bool force_init) { - struct mmc *mmc; - mmc = find_mmc_device(dev); + struct mmc *mmc = find_mmc_device(dev); + if (!mmc) { printf("no mmc device at slot %x\n", dev); return NULL; @@ -157,14 +98,15 @@ 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[]) + +static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { struct mmc *mmc; if (curr_device < 0) { - if (get_mmc_num() > 0) + if (get_mmc_num() > 0) { curr_device = 0; - else { + } else { puts("No MMC device available\n"); return 1; } @@ -190,8 +132,9 @@ 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[]) + int argc, char *const argv[]) { void *key_addr; struct mmc *mmc = find_mmc_device(curr_device); @@ -208,8 +151,9 @@ 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[]) + int argc, char *const argv[]) { u16 blk, cnt; void *addr; @@ -236,8 +180,9 @@ 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[]) + int argc, char *const argv[]) { u16 blk, cnt; void *addr; @@ -262,14 +207,16 @@ 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[]) + int argc, char *const argv[]) { unsigned long counter; struct mmc *mmc = find_mmc_device(curr_device); if (mmc_rpmb_get_counter(mmc, &counter)) return CMD_RET_FAILURE; + printf("RPMB Write counter= %lx\n", counter); return CMD_RET_SUCCESS; } @@ -282,15 +229,13 @@ static cmd_tbl_t cmd_rpmb[] = { }; static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) + int argc, char *const argv[]) { - cmd_tbl_t *cp; + cmd_tbl_t *cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb)); struct mmc *mmc; char original_part; int ret; - cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb)); - /* Drop the rpmb subcommand */ argc--; argv++; @@ -314,19 +259,21 @@ static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag, } /* Switch to the RPMB partition */ original_part = mmc->block_dev.hwpart; - if (mmc_select_hwpart(curr_device, MMC_PART_RPMB) != 0) + if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, MMC_PART_RPMB) != + 0) return CMD_RET_FAILURE; ret = cp->cmd(cmdtp, flag, argc, argv); /* Return to original partition */ - if (mmc_select_hwpart(curr_device, original_part) != 0) + if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, original_part) != + 0) return CMD_RET_FAILURE; return ret; } #endif static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) + int argc, char *const argv[]) { struct mmc *mmc; u32 blk, cnt, n; @@ -346,15 +293,16 @@ static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, printf("\nMMC read: dev # %d, block # %d, count %d ... ", curr_device, blk, cnt); - n = blk_dread(&mmc->block_dev, blk, cnt, addr); + n = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, addr); /* flush cache after read */ flush_cache((ulong)addr, cnt * 512); /* FIXME */ printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR"); 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[]) + int argc, char *const argv[]) { struct mmc *mmc; u32 blk, cnt, n; @@ -378,13 +326,14 @@ static int do_mmc_write(cmd_tbl_t *cmdtp, int flag, printf("Error: card is write protected!\n"); return CMD_RET_FAILURE; } - n = blk_dwrite(&mmc->block_dev, blk, cnt, addr); + n = blk_dwrite(mmc_get_blk_desc(mmc), blk, cnt, addr); printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR"); 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[]) + int argc, char *const argv[]) { struct mmc *mmc; u32 blk, cnt, n; @@ -406,33 +355,35 @@ static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag, printf("Error: card is write protected!\n"); return CMD_RET_FAILURE; } - n = blk_derase(&mmc->block_dev, blk, cnt); + n = blk_derase(mmc_get_blk_desc(mmc), blk, cnt); printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR"); 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[]) + int argc, char *const argv[]) { - struct mmc *mmc; + struct mmc *mmc = init_mmc_device(curr_device, true); - mmc = init_mmc_device(curr_device, true); if (!mmc) return CMD_RET_FAILURE; return CMD_RET_SUCCESS; } + static int do_mmc_part(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) + int argc, char *const argv[]) { struct blk_desc *mmc_dev; - struct mmc *mmc; + struct mmc *mmc = init_mmc_device(curr_device, false); - mmc = init_mmc_device(curr_device, false); if (!mmc) return CMD_RET_FAILURE; - mmc_dev = mmc_get_dev(curr_device); + mmc_dev = blk_get_devnum_by_type(IF_TYPE_MMC, curr_device); +printf("%s@%d: curr_device=%u mmc_dev=%p type=%08x\n", __func__, __LINE__, + curr_device, mmc_dev, mmc_dev ? mmc_dev->type : -1); if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) { part_print(mmc_dev); return CMD_RET_SUCCESS; @@ -441,8 +392,9 @@ 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[]) + int argc, char *const argv[]) { int dev, part = 0, ret; struct mmc *mmc; @@ -467,7 +419,7 @@ static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag, if (!mmc) return CMD_RET_FAILURE; - ret = mmc_select_hwpart(dev, part); + ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part); printf("switch to partitions #%d, %s\n", part, (!ret) ? "OK" : "ERROR"); if (ret) @@ -478,19 +430,20 @@ static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag, printf("mmc%d is current device\n", curr_device); else printf("mmc%d(part %d) is current device\n", - curr_device, mmc->block_dev.hwpart); + curr_device, mmc_get_blk_desc(mmc)->hwpart); return CMD_RET_SUCCESS; } + static int do_mmc_list(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) + 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 argc, char *const argv[]) { int i = 0; @@ -524,7 +477,7 @@ static int parse_hwpart_user(struct mmc_hwpart_conf *pconf, } static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx, - int argc, char * const argv[]) + int argc, char *const argv[]) { int i; @@ -532,6 +485,7 @@ static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx, if (1 >= argc) return -1; + pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10); i = 1; @@ -558,7 +512,7 @@ static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx, } static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) + int argc, char *const argv[]) { struct mmc *mmc; struct mmc_hwpart_conf pconf = { }; @@ -641,7 +595,7 @@ static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag, #ifdef CONFIG_SUPPORT_EMMC_BOOT static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) + int argc, char *const argv[]) { int dev; struct mmc *mmc; @@ -649,6 +603,7 @@ static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag, 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); @@ -666,8 +621,9 @@ static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag, /* acknowledge to be sent during boot operation */ return mmc_set_boot_bus_width(mmc, width, reset, mode); } + static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) + int argc, char *const argv[]) { int dev; struct mmc *mmc; @@ -697,8 +653,9 @@ 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 argc, char *const argv[]) { int dev; struct mmc *mmc; @@ -724,8 +681,9 @@ 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); } + static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag, - int argc, char * const argv[]) + int argc, char *const argv[]) { int dev; struct mmc *mmc; @@ -759,8 +717,9 @@ 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[]) + int argc, char *const argv[]) { struct mmc *mmc; u32 val; @@ -768,6 +727,7 @@ static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag, if (argc != 2) return CMD_RET_USAGE; + val = simple_strtoul(argv[2], NULL, 16); mmc = find_mmc_device(curr_device); @@ -809,11 +769,9 @@ static cmd_tbl_t cmd_mmc[] = { U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""), }; -static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { - cmd_tbl_t *cp; - - cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc)); + cmd_tbl_t *cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc)); /* Drop the mmc command */ argc--; @@ -879,5 +837,3 @@ U_BOOT_CMD( "display MMC info", "- display info of the current MMC device" ); - -#endif /* !CONFIG_GENERIC_MMC */