#include <mmc.h>
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)
{
}
}
}
+
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;
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;
}
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);
}
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;
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;
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;
}
};
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++;
return CMD_RET_FAILURE;
}
/* Switch to the RPMB partition */
- original_part = mmc->block_dev.part_num;
- if (mmc_select_hwpart(curr_device, MMC_PART_RPMB) != 0)
+ original_part = mmc->block_dev.hwpart;
+ 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;
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;
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;
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;
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;
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)
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;
}
static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
- int argc, char * const argv[])
+ int argc, char *const argv[])
{
int i;
if (1 >= argc)
return -1;
+
pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10);
i = 1;
}
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 = { };
#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;
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);
/* 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;
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;
/* 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;
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;
if (argc != 2)
return CMD_RET_USAGE;
+
val = simple_strtoul(argv[2], NULL, 16);
mmc = find_mmc_device(curr_device);
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--;
"display MMC info",
"- display info of the current MMC device"
);
-
-#endif /* !CONFIG_GENERIC_MMC */