[U-Boot] [PATCH 1/3] mmc: limit block count for multi-block write commands
Lei Wen
leiwen at marvell.com
Tue Sep 7 14:32:07 CEST 2010
Signed-off-by: Lei Wen <leiwen at marvell.com>
---
drivers/mmc/mmc.c | 59 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index cf4ea16..5cc1904 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -77,29 +77,14 @@ struct mmc *find_mmc_device(int dev_num)
return NULL;
}
-static ulong
-mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
+int mmc_write_block(struct mmc *mmc, void *src, ulong start, uint blocknum)
{
- struct mmc_cmd cmd;
- struct mmc_data data;
- int err;
- int stoperr = 0;
- struct mmc *mmc = find_mmc_device(dev_num);
int blklen;
-
- if (!mmc)
- return -1;
-
blklen = mmc->write_bl_len;
- err = mmc_set_blocklen(mmc, mmc->write_bl_len);
-
- if (err) {
- printf("set write bl len failed\n\r");
- return err;
- }
-
- if (blkcnt > 1)
+ BUG_ON(blklen * blocknum > 524288);
+ BUG_ON(blocknum > 65535);
+ if (blocknum > 1)
cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK;
else
cmd.cmdidx = MMC_CMD_WRITE_SINGLE_BLOCK;
@@ -113,7 +98,7 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
cmd.flags = 0;
data.src = src;
- data.blocks = blkcnt;
+ data.blocks = blocknum;
data.blocksize = blklen;
data.flags = MMC_DATA_WRITE;
@@ -124,7 +109,7 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
return err;
}
- if (blkcnt > 1) {
+ if (blocknum > 1) {
cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
cmd.cmdarg = 0;
cmd.resp_type = MMC_RSP_R1b;
@@ -132,6 +117,38 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
stoperr = mmc_send_cmd(mmc, &cmd, NULL);
}
+ return blocknum;
+}
+
+static ulong
+mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
+{
+ struct mmc_cmd cmd;
+ struct mmc_data data;
+ int err;
+ int stoperr = 0;
+ struct mmc *mmc = find_mmc_device(dev_num);
+ unsigned int max;
+ lbaint_t tmp = blkcnt, cur;
+
+ if (!mmc)
+ return -1;
+
+ err = mmc_set_blocklen(mmc, mmc->write_bl_len);
+ if (err) {
+ printf("set write bl len failed\n\r");
+ return err;
+ }
+
+ max = 524288 / mmc->write_bl_len;
+ do {
+ cur = (tmp > max) ? max : tmp;
+ if(mmc_write_block(mmc, src, start, cur) != cur)
+ return -1;
+ tmp -= cur;
+ start += cur;
+ src += cur * mmc->write_bl_len;
+ } while (tmp > 0);
return blkcnt;
}
--
1.7.0.4
More information about the U-Boot
mailing list