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;
if (mmc_legacy_init(dev) != 0) {
puts("No MMC card found\n");
- return 1;
+ return CMD_RET_FAILURE;
}
curr_device = dev;
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 {
return CMD_RET_USAGE;
}
- return 0;
+ return CMD_RET_SUCCESS;
}
U_BOOT_CMD(
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: ");
}
}
}
+
static struct mmc *init_mmc_device(int dev, bool force_init)
{
struct mmc *mmc;
return NULL;
return mmc;
}
+
static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
struct mmc *mmc;
curr_device = 0;
else {
puts("No MMC device available\n");
- return 1;
+ return CMD_RET_FAILURE;
}
}
puts("Authentication key programming aborted\n");
return 0;
}
+
static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
}
return CMD_RET_SUCCESS;
}
+
static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
return CMD_RET_FAILURE;
return CMD_RET_SUCCESS;
}
+
static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
return CMD_RET_FAILURE;
return CMD_RET_SUCCESS;
}
+
static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
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[])
{
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[])
{
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[])
{
return CMD_RET_SUCCESS;
}
+
static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
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[])
{
return CMD_RET_SUCCESS;
}
+
static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
if (!mmc_hwpart_config(mmc, &pconf, mode)) {
if (mode == MMC_HWPART_CONF_COMPLETE)
- puts("Partitioning successful, "
- "power-cycle to make effective\n");
+ puts("Partitioning successful, power-cycle to make effective\n");
return CMD_RET_SUCCESS;
} else {
puts("Failed!\n");
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;
}
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)
}
/* 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
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");
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) {