mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 22:51:37 +00:00
MMC: unify mmc read and write operation
mmc read and write command has so many in common, unfiy those two to force consistency across the those two. Signed-off-by: Lei Wen <leiwen@marvell.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Acked-by: Andy Fleming <afleming@freescale.com>
This commit is contained in:
parent
83800959a8
commit
6be95ccf9f
1 changed files with 36 additions and 33 deletions
|
@ -87,6 +87,11 @@ U_BOOT_CMD(
|
||||||
);
|
);
|
||||||
#else /* !CONFIG_GENERIC_MMC */
|
#else /* !CONFIG_GENERIC_MMC */
|
||||||
|
|
||||||
|
enum mmc_state {
|
||||||
|
MMC_INVALID,
|
||||||
|
MMC_READ,
|
||||||
|
MMC_WRITE,
|
||||||
|
};
|
||||||
static void print_mmcinfo(struct mmc *mmc)
|
static void print_mmcinfo(struct mmc *mmc)
|
||||||
{
|
{
|
||||||
printf("Device: %s\n", mmc->name);
|
printf("Device: %s\n", mmc->name);
|
||||||
|
@ -144,6 +149,8 @@ U_BOOT_CMD(
|
||||||
|
|
||||||
int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
|
enum mmc_state state;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return cmd_usage(cmdtp);
|
return cmd_usage(cmdtp);
|
||||||
|
|
||||||
|
@ -239,53 +246,49 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
curr_device, mmc->part_num);
|
curr_device, mmc->part_num);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (strcmp(argv[1], "read") == 0) {
|
}
|
||||||
|
|
||||||
|
if (strcmp(argv[1], "read") == 0)
|
||||||
|
state = MMC_READ;
|
||||||
|
else if (strcmp(argv[1], "write") == 0)
|
||||||
|
state = MMC_WRITE;
|
||||||
|
else
|
||||||
|
state = MMC_INVALID;
|
||||||
|
|
||||||
|
if (state != MMC_INVALID) {
|
||||||
|
struct mmc *mmc = find_mmc_device(curr_device);
|
||||||
void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
|
void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
|
||||||
|
u32 blk = simple_strtoul(argv[3], NULL, 16);
|
||||||
u32 cnt = simple_strtoul(argv[4], NULL, 16);
|
u32 cnt = simple_strtoul(argv[4], NULL, 16);
|
||||||
u32 n;
|
u32 n;
|
||||||
u32 blk = simple_strtoul(argv[3], NULL, 16);
|
|
||||||
struct mmc *mmc = find_mmc_device(curr_device);
|
|
||||||
|
|
||||||
if (!mmc) {
|
if (!mmc) {
|
||||||
printf("no mmc device at slot %x\n", curr_device);
|
printf("no mmc device at slot %x\n", curr_device);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nMMC read: dev # %d, block # %d, count %d ... ",
|
printf("\nMMC %s: dev # %d, block # %d, count %d ... ",
|
||||||
curr_device, blk, cnt);
|
argv[1], curr_device, blk, cnt);
|
||||||
|
|
||||||
mmc_init(mmc);
|
mmc_init(mmc);
|
||||||
|
|
||||||
n = mmc->block_dev.block_read(curr_device, blk, cnt, addr);
|
switch (state) {
|
||||||
|
case MMC_READ:
|
||||||
|
n = mmc->block_dev.block_read(curr_device, blk,
|
||||||
|
cnt, addr);
|
||||||
/* flush cache after read */
|
/* flush cache after read */
|
||||||
flush_cache((ulong)addr, cnt * 512); /* FIXME */
|
flush_cache((ulong)addr, cnt * 512); /* FIXME */
|
||||||
|
break;
|
||||||
printf("%d blocks read: %s\n",
|
case MMC_WRITE:
|
||||||
n, (n==cnt) ? "OK" : "ERROR");
|
n = mmc->block_dev.block_write(curr_device, blk,
|
||||||
return (n == cnt) ? 0 : 1;
|
cnt, addr);
|
||||||
} else if (strcmp(argv[1], "write") == 0) {
|
break;
|
||||||
void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
|
default:
|
||||||
u32 cnt = simple_strtoul(argv[4], NULL, 16);
|
BUG();
|
||||||
u32 n;
|
|
||||||
struct mmc *mmc = find_mmc_device(curr_device);
|
|
||||||
|
|
||||||
int blk = simple_strtoul(argv[3], NULL, 16);
|
|
||||||
|
|
||||||
if (!mmc) {
|
|
||||||
printf("no mmc device at slot %x\n", curr_device);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nMMC write: dev # %d, block # %d, count %d ... ",
|
printf("%d blocks %s: %s\n",
|
||||||
curr_device, blk, cnt);
|
n, argv[1], (n == cnt) ? "OK" : "ERROR");
|
||||||
|
|
||||||
mmc_init(mmc);
|
|
||||||
|
|
||||||
n = mmc->block_dev.block_write(curr_device, blk, cnt, addr);
|
|
||||||
|
|
||||||
printf("%d blocks written: %s\n",
|
|
||||||
n, (n == cnt) ? "OK" : "ERROR");
|
|
||||||
return (n == cnt) ? 0 : 1;
|
return (n == cnt) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue