* [U-Boot] [PATCH 1/5] mmc: clean up help texts
@ 2009-04-05 8:00 Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 2/5] mmc: check find_mmc_device return value Rabin Vincent
2009-04-16 16:52 ` [U-Boot] [PATCH 1/5] mmc: clean up help texts Rabin Vincent
0 siblings, 2 replies; 7+ messages in thread
From: Rabin Vincent @ 2009-04-05 8:00 UTC (permalink / raw)
To: u-boot
Remove some repeated words and superfluous newlines in the mmc command
help entries.
Signed-off-by: Rabin Vincent <rabin@rab.in>
---
common/cmd_mmc.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index f1fa32f..bd55ff1 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -135,8 +135,9 @@ int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
return 0;
}
-U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo, "mmcinfo <dev num>-- display MMC info\n",
- NULL);
+U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo,
+ "print MMC information",
+ "<dev num>\n");
int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
@@ -218,8 +219,8 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
U_BOOT_CMD(
mmc, 6, 1, do_mmcops,
"MMC sub system",
- "mmc read <device num> addr blk# cnt\n"
+ "read <device num> addr blk# cnt\n"
"mmc write <device num> addr blk# cnt\n"
"mmc rescan <device num>\n"
- "mmc list - lists available devices\n");
+ "mmc list - list available devices\n");
#endif
--
1.6.2.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH 2/5] mmc: check find_mmc_device return value
2009-04-05 8:00 [U-Boot] [PATCH 1/5] mmc: clean up help texts Rabin Vincent
@ 2009-04-05 8:00 ` Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 3/5] mmc: use lldiv to fix arm eabi build Rabin Vincent
2009-04-16 16:52 ` [U-Boot] [PATCH 1/5] mmc: clean up help texts Rabin Vincent
1 sibling, 1 reply; 7+ messages in thread
From: Rabin Vincent @ 2009-04-05 8:00 UTC (permalink / raw)
To: u-boot
find_mmc_device returns NULL if an invalid device number is specified.
Check for this to avoid dereferencing NULL pointers.
Signed-off-by: Rabin Vincent <rabin@rab.in>
---
common/cmd_mmc.c | 9 +++++++++
drivers/mmc/mmc.c | 2 +-
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index bd55ff1..039fe59 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -149,6 +149,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int dev = simple_strtoul(argv[2], NULL, 10);
struct mmc *mmc = find_mmc_device(dev);
+ if (!mmc)
+ return 1;
+
mmc_init(mmc);
return 0;
@@ -175,6 +178,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
u32 blk = simple_strtoul(argv[4], NULL, 16);
struct mmc *mmc = find_mmc_device(dev);
+ if (!mmc)
+ return 1;
+
printf("\nMMC read: dev # %d, block # %d, count %d ... ",
dev, blk, cnt);
@@ -197,6 +203,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int blk = simple_strtoul(argv[4], NULL, 16);
+ if (!mmc)
+ return 1;
+
printf("\nMMC write: dev # %d, block # %d, count %d ... ",
dev, blk, cnt);
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 96186d9..50c197a 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -846,7 +846,7 @@ block_dev_desc_t *mmc_get_dev(int dev)
{
struct mmc *mmc = find_mmc_device(dev);
- return &mmc->block_dev;
+ return mmc ? &mmc->block_dev : NULL;
}
int mmc_init(struct mmc *mmc)
--
1.6.2.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH 3/5] mmc: use lldiv to fix arm eabi build
2009-04-05 8:00 ` [U-Boot] [PATCH 2/5] mmc: check find_mmc_device return value Rabin Vincent
@ 2009-04-05 8:00 ` Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 4/5] mmc: fix response decoding on little endian Rabin Vincent
0 siblings, 1 reply; 7+ messages in thread
From: Rabin Vincent @ 2009-04-05 8:00 UTC (permalink / raw)
To: u-boot
The generic MMC core uses direct long long divisions, which do not build
with ARM EABI toolchains. Use lldiv() instead, which works everywhere.
Signed-off-by: Rabin Vincent <rabin@rab.in>
---
drivers/mmc/mmc.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 50c197a..b50c255 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -31,6 +31,7 @@
#include <malloc.h>
#include <linux/list.h>
#include <mmc.h>
+#include <div64.h>
static struct list_head mmc_devices;
static int cur_dev_num = -1;
@@ -155,8 +156,8 @@ int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size)
char *buffer;
int i;
int blklen = mmc->read_bl_len;
- int startblock = src / blklen;
- int endblock = (src + size - 1) / blklen;
+ int startblock = lldiv(src, mmc->read_bl_len);
+ int endblock = lldiv(src + size - 1, mmc->read_bl_len);
int err = 0;
/* Make a buffer big enough to hold all the blocks we might read */
@@ -789,7 +790,7 @@ int mmc_startup(struct mmc *mmc)
mmc->block_dev.lun = 0;
mmc->block_dev.type = 0;
mmc->block_dev.blksz = mmc->read_bl_len;
- mmc->block_dev.lba = mmc->capacity/mmc->read_bl_len;
+ mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
sprintf(mmc->block_dev.vendor,"Man %02x%02x%02x Snr %02x%02x%02x%02x",
mmc->cid[0], mmc->cid[1], mmc->cid[2],
mmc->cid[9], mmc->cid[10], mmc->cid[11], mmc->cid[12]);
--
1.6.2.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH 4/5] mmc: fix response decoding on little endian
2009-04-05 8:00 ` [U-Boot] [PATCH 3/5] mmc: use lldiv to fix arm eabi build Rabin Vincent
@ 2009-04-05 8:00 ` Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 5/5] mmc: drop unnecessary casts Rabin Vincent
0 siblings, 1 reply; 7+ messages in thread
From: Rabin Vincent @ 2009-04-05 8:00 UTC (permalink / raw)
To: u-boot
The mmc code defines the response as an array of chars. However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars. The former case is used more
often, including by the driver when it assigns the response.
The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.
This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.
Signed-off-by: Rabin Vincent <rabin@rab.in>
---
drivers/mmc/mmc.c | 20 ++++++++++----------
include/mmc.h | 6 +++---
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index b50c255..1c83cc7 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -651,7 +651,7 @@ int mmc_startup(struct mmc *mmc)
mmc->csd[3] = ((uint *)(cmd.response))[3];
if (mmc->version == MMC_VERSION_UNKNOWN) {
- int version = (cmd.response[0] >> 2) & 0xf;
+ int version = (cmd.response[0] >> 26) & 0xf;
switch (version) {
case 0:
@@ -676,8 +676,8 @@ int mmc_startup(struct mmc *mmc)
}
/* divide frequency by 10, since the mults are 10x bigger */
- freq = fbase[(cmd.response[3] & 0x7)];
- mult = multipliers[((cmd.response[3] >> 3) & 0xf)];
+ freq = fbase[(cmd.response[0] & 0x7)];
+ mult = multipliers[((cmd.response[0] >> 3) & 0xf)];
mmc->tran_speed = freq * mult;
@@ -791,13 +791,13 @@ int mmc_startup(struct mmc *mmc)
mmc->block_dev.type = 0;
mmc->block_dev.blksz = mmc->read_bl_len;
mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
- sprintf(mmc->block_dev.vendor,"Man %02x%02x%02x Snr %02x%02x%02x%02x",
- mmc->cid[0], mmc->cid[1], mmc->cid[2],
- mmc->cid[9], mmc->cid[10], mmc->cid[11], mmc->cid[12]);
- sprintf(mmc->block_dev.product,"%c%c%c%c%c", mmc->cid[3],
- mmc->cid[4], mmc->cid[5], mmc->cid[6], mmc->cid[7]);
- sprintf(mmc->block_dev.revision,"%d.%d", mmc->cid[8] >> 4,
- mmc->cid[8] & 0xf);
+ sprintf(mmc->block_dev.vendor, "Man %06x Snr %08x", mmc->cid[0] >> 8,
+ (mmc->cid[2] << 8) | (mmc->cid[3] >> 24));
+ sprintf(mmc->block_dev.product, "%c%c%c%c%c", mmc->cid[0] & 0xff,
+ (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
+ (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
+ sprintf(mmc->block_dev.revision, "%d.%d", mmc->cid[2] >> 28,
+ (mmc->cid[2] >> 24) & 0xf);
init_part(&mmc->block_dev);
return 0;
diff --git a/include/mmc.h b/include/mmc.h
index b9b27ba..229d494 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -91,7 +91,7 @@
#define MMC_HS_TIMING 0x00000100
#define MMC_HS_52MHZ 0x2
-#define OCR_BUSY 0x80
+#define OCR_BUSY 0x80000000
#define OCR_HCS 0x40000000
#define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
@@ -223,7 +223,7 @@ struct mmc_cmd {
ushort cmdidx;
uint resp_type;
uint cmdarg;
- char response[18];
+ uint response[4];
uint flags;
};
@@ -253,7 +253,7 @@ struct mmc {
uint ocr;
uint scr[2];
uint csd[4];
- char cid[16];
+ uint cid[4];
ushort rca;
uint tran_speed;
uint read_bl_len;
--
1.6.2.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH 5/5] mmc: drop unnecessary casts
2009-04-05 8:00 ` [U-Boot] [PATCH 4/5] mmc: fix response decoding on little endian Rabin Vincent
@ 2009-04-05 8:00 ` Rabin Vincent
0 siblings, 0 replies; 7+ messages in thread
From: Rabin Vincent @ 2009-04-05 8:00 UTC (permalink / raw)
To: u-boot
Now that response is a uint, we can drop all the casts.
Signed-off-by: Rabin Vincent <rabin@rab.in>
---
drivers/mmc/fsl_esdhc.c | 10 +++++-----
drivers/mmc/mmc.c | 20 ++++++++++----------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index 0ba45cd..8274af5 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -206,12 +206,12 @@ esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
cmdrsp2 = in_be32(®s->cmdrsp2);
cmdrsp1 = in_be32(®s->cmdrsp1);
cmdrsp0 = in_be32(®s->cmdrsp0);
- ((uint *)(cmd->response))[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
- ((uint *)(cmd->response))[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
- ((uint *)(cmd->response))[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
- ((uint *)(cmd->response))[3] = (cmdrsp0 << 8);
+ cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
+ cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
+ cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
+ cmd->response[3] = (cmdrsp0 << 8);
} else
- ((uint *)(cmd->response))[0] = in_be32(®s->cmdrsp0);
+ cmd->response[0] = in_be32(®s->cmdrsp0);
/* Wait until all of the blocks are transferred */
if (data) {
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 1c83cc7..b4814d2 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -292,7 +292,7 @@ sd_send_op_cond(struct mmc *mmc)
if (mmc->version != SD_VERSION_2)
mmc->version = SD_VERSION_1_0;
- mmc->ocr = ((uint *)(cmd.response))[0];
+ mmc->ocr = cmd.response[0];
mmc->high_capacity = ((mmc->ocr & OCR_HCS) == OCR_HCS);
mmc->rca = 0;
@@ -327,7 +327,7 @@ int mmc_send_op_cond(struct mmc *mmc)
return UNUSABLE_ERR;
mmc->version = MMC_VERSION_UNKNOWN;
- mmc->ocr = ((uint *)(cmd.response))[0];
+ mmc->ocr = cmd.response[0];
mmc->high_capacity = ((mmc->ocr & OCR_HCS) == OCR_HCS);
mmc->rca = 0;
@@ -632,7 +632,7 @@ int mmc_startup(struct mmc *mmc)
return err;
if (IS_SD(mmc))
- mmc->rca = (((uint *)(cmd.response))[0] >> 16) & 0xffff;
+ mmc->rca = (cmd.response[0] >> 16) & 0xffff;
/* Get the Card-Specific Data */
cmd.cmdidx = MMC_CMD_SEND_CSD;
@@ -645,10 +645,10 @@ int mmc_startup(struct mmc *mmc)
if (err)
return err;
- mmc->csd[0] = ((uint *)(cmd.response))[0];
- mmc->csd[1] = ((uint *)(cmd.response))[1];
- mmc->csd[2] = ((uint *)(cmd.response))[2];
- mmc->csd[3] = ((uint *)(cmd.response))[3];
+ mmc->csd[0] = cmd.response[0];
+ mmc->csd[1] = cmd.response[1];
+ mmc->csd[2] = cmd.response[2];
+ mmc->csd[3] = cmd.response[3];
if (mmc->version == MMC_VERSION_UNKNOWN) {
int version = (cmd.response[0] >> 26) & 0xf;
@@ -681,12 +681,12 @@ int mmc_startup(struct mmc *mmc)
mmc->tran_speed = freq * mult;
- mmc->read_bl_len = 1 << ((((uint *)(cmd.response))[1] >> 16) & 0xf);
+ mmc->read_bl_len = 1 << ((cmd.response[1] >> 16) & 0xf);
if (IS_SD(mmc))
mmc->write_bl_len = mmc->read_bl_len;
else
- mmc->write_bl_len = 1 << ((((uint *)(cmd.response))[3] >> 22) & 0xf);
+ mmc->write_bl_len = 1 << ((cmd.response[3] >> 22) & 0xf);
if (mmc->high_capacity) {
csize = (mmc->csd[1] & 0x3f) << 16
@@ -819,7 +819,7 @@ int mmc_send_if_cond(struct mmc *mmc)
if (err)
return err;
- if ((((uint *)(cmd.response))[0] & 0xff) != 0xaa)
+ if ((cmd.response[0] & 0xff) != 0xaa)
return UNUSABLE_ERR;
else
mmc->version = SD_VERSION_2;
--
1.6.2.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH 1/5] mmc: clean up help texts
2009-04-05 8:00 [U-Boot] [PATCH 1/5] mmc: clean up help texts Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 2/5] mmc: check find_mmc_device return value Rabin Vincent
@ 2009-04-16 16:52 ` Rabin Vincent
2009-04-16 23:33 ` Andy Fleming
1 sibling, 1 reply; 7+ messages in thread
From: Rabin Vincent @ 2009-04-16 16:52 UTC (permalink / raw)
To: u-boot
Andy,
On Sun, Apr 05, 2009 at 01:30:52PM +0530, Rabin Vincent wrote:
> Remove some repeated words and superfluous newlines in the mmc command
> help entries.
>
> Signed-off-by: Rabin Vincent <rabin@rab.in>
Any comments on this set of patches?
Rabin
^ permalink raw reply [flat|nested] 7+ messages in thread
* [U-Boot] [PATCH 1/5] mmc: clean up help texts
2009-04-16 16:52 ` [U-Boot] [PATCH 1/5] mmc: clean up help texts Rabin Vincent
@ 2009-04-16 23:33 ` Andy Fleming
0 siblings, 0 replies; 7+ messages in thread
From: Andy Fleming @ 2009-04-16 23:33 UTC (permalink / raw)
To: u-boot
On Thu, Apr 16, 2009 at 11:52 AM, Rabin Vincent <rabin@rab.in> wrote:
> Andy,
>
> On Sun, Apr 05, 2009 at 01:30:52PM +0530, Rabin Vincent wrote:
>> Remove some repeated words and superfluous newlines in the mmc command
>> help entries.
>>
>> Signed-off-by: Rabin Vincent <rabin@rab.in>
>
> Any comments on this set of patches?
They look good. I've applied them, but I won't push them till I can
test them on a board tomorrow. Just want to make sure you didn't
break my system. :)
Andy
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-04-16 23:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-05 8:00 [U-Boot] [PATCH 1/5] mmc: clean up help texts Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 2/5] mmc: check find_mmc_device return value Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 3/5] mmc: use lldiv to fix arm eabi build Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 4/5] mmc: fix response decoding on little endian Rabin Vincent
2009-04-05 8:00 ` [U-Boot] [PATCH 5/5] mmc: drop unnecessary casts Rabin Vincent
2009-04-16 16:52 ` [U-Boot] [PATCH 1/5] mmc: clean up help texts Rabin Vincent
2009-04-16 23:33 ` Andy Fleming
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox