Skip to contentSkip to conversation

MMC and buffer alignment question

U-Boot Markus Niebel 3 participants 6 messages Mar 19, 2014

lore
Share & tools
lore
#0 lore raw

Hello Pantelis,

short question to the usage of the mmc command (and also the mmc driver API): is it intended that mmc read / write may fail when the supplied address in RAM is not aligned?

ARMV7 will give output like this:

U-Boot > mmc read 12000002 44 44

MMC read: dev # 0, block # 68, count 68 ... INFO: 24994 of 25000 loops left to DAT0 timeout
ERROR: v7_dcache_inval_range - start address is not aligned - 0x12000002
ERROR: v7_dcache_inval_range - stop address is not aligned - 0x12008802
68 blocks read: OK

On my platform (i.MX6 / Cortex A9) the alignment needed is 32 Byte.

Special commands inside the mmc drivers and in env_mmc implement the alignment magic. Shouldn't the mmc do the magic (and if neccesarry provide help using temp buffers if needed) so that all users outside can read / write without caring for special cases?

Markus

#1 lore raw

Hi Markus,

Quoted 6 lines · Markus Niebel

Hello Pantelis,

short question to the usage of the mmc command (and also the mmc driver API): is it intended that mmc read / write may fail when the supplied address in RAM is not aligned?

If not intended, it is known.

Quoted 4 lines

ARMV7 will give output like this:

U-Boot > mmc read 12000002 44 44

Why would you want to do this?

Quoted 5 lines

MMC read: dev # 0, block # 68, count 68 ... INFO: 24994 of 25000 loops left to DAT0 timeout
ERROR: v7_dcache_inval_range - start address is not aligned - 0x12000002
ERROR: v7_dcache_inval_range - stop address is not aligned - 0x12008802
68 blocks read: OK

Quoted 7 lines

On my platform (i.MX6 / Cortex A9) the alignment needed is 32 Byte.

Special commands inside the mmc drivers and in env_mmc implement the alignment magic. Shouldn't the mmc do the magic (and if neccesarry provide help using temp buffers if needed) so that all users outside can read / write without caring for special cases?

Is there a use case here? There are plenty of memory addresses that won't work with commands like "mmc read".

Is it worth **any** code to try and catch them?

Please advise,

Eric

#2 lore raw

Dear Eric Nelson,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 4 lines

short question to the usage of the mmc command (and also the mmc driver API): is it intended that mmc read / write may fail when the supplied address in RAM is not aligned?

If not intended, it is known.

I consider this a known bug.

Quoted 5 lines
Quoted 4 lines

ARMV7 will give output like this:

U-Boot > mmc read 12000002 44 44

Why would you want to do this?

For example, BMP images require loading on a +2 aligned address due to their stupid header format. I ran into this before myself: it is impossible to match both the alignment reuqirements of the bmp command and the mmc read command at the same time. One must manually copy the memory ragen again. This is a plain, stupid bug.

Quoted 7 lines
Quoted 4 lines

Special commands inside the mmc drivers and in env_mmc implement the alignment magic. Shouldn't the mmc do the magic (and if neccesarry provide help using temp buffers if needed) so that all users outside can read / write without caring for special cases?

Is there a use case here? There are plenty of memory addresses that won't work with commands like "mmc read".

"mmc read" and "mmc write" are operations that work on character buffers, like all other file IO ops. These should not require any specific alignment.

Quoted 1 line

Is it worth **any** code to try and catch them?

Definitely yes.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Real computer scientists despise the idea of actual  hardware.  Hard-
ware has limitations, software doesn't. It's a real shame that Turing
machines are so poor at I/O.
#3 lore raw

Am 19.03.2014 15:44, wrote Wolfgang Denk:

Quoted 16 lines

Dear Eric Nelson,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 4 lines

short question to the usage of the mmc command (and also the mmc driver API): is it intended that mmc read / write may fail when the supplied address in RAM is not aligned?

If not intended, it is known.

I consider this a known bug.

Quoted 4 lines
Quoted 4 lines

ARMV7 will give output like this:

U-Boot > mmc read 12000002 44 44

Quoted 8 lines
Quoted 1 line

Why would you want to do this?

For example, BMP images require loading on a +2 aligned address due to their stupid header format. I ran into this before myself: it is impossible to match both the alignment reuqirements of the bmp command and the mmc read command at the same time. One must manually copy the memory ragen again. This is a plain, stupid bug.

Exactly here it popped up ...

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Special commands inside the mmc drivers and in env_mmc implement the alignment magic. Shouldn't the mmc do the magic (and if neccesarry provide help using temp buffers if needed) so that all users outside can read / write without caring for special cases?

Is there a use case here? There are plenty of memory addresses that won't work with commands like "mmc read".

env_mmc needs to care for cache aligned buffers - This was fixed some time ago for the redundant env case

Quoted 8 lines

"mmc read" and "mmc write" are operations that work on character buffers, like all other file IO ops. These should not require any specific alignment.

Quoted 1 line

Is it worth **any** code to try and catch them?

Definitely yes.

So just as an idea - we could use a bounce buffer for mmc_bwrite / mmc_bread for the unaligned case. Is definitely slow but should work.

Quoted 4 lines

Best regards,

Wolfgang Denk

#4 lore raw

Hi Markus and Wolfgang,

Quoted 19 lines · Markus Niebel

Am 19.03.2014 15:44, wrote Wolfgang Denk:

Quoted 18 lines

Dear Eric Nelson,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 4 lines

short question to the usage of the mmc command (and also the mmc driver API): is it intended that mmc read / write may fail when the supplied address in RAM is not aligned?

If not intended, it is known.

I consider this a known bug.

Quoted 5 lines
Quoted 4 lines

ARMV7 will give output like this:

U-Boot > mmc read 12000002 44 44

Why would you want to do this?

Quoted 9 lines
Quoted 6 lines

For example, BMP images require loading on a +2 aligned address due to their stupid header format. I ran into this before myself: it is impossible to match both the alignment reuqirements of the bmp command and the mmc read command at the same time. One must manually copy the memory ragen again. This is a plain, stupid bug.

Exactly here it popped up ...

It seems to me that if you're resorting to using un-formatted storage space to store a broken data structure (the BMP header), you could just write it at an offset +2.

The BMP support is pretty difficult to use anyway (only supports BMPV3 headers), so asking the user to know about the offset doesn't seem onerous.

Also note that the patch I submitted recently handles the case for gzipped files for those using cfb_console.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Special commands inside the mmc drivers and in env_mmc implement the alignment magic. Shouldn't the mmc do the magic (and if neccesarry provide help using temp buffers if needed) so that all users outside can read / write without caring for special cases?

Quoted 15 lines
Quoted 3 lines
Quoted 2 lines

Is there a use case here? There are plenty of memory addresses that won't work with commands like "mmc read".

env_mmc needs to care for cache aligned buffers - This was fixed some time ago for the redundant env case

Quoted 8 lines

"mmc read" and "mmc write" are operations that work on character buffers, like all other file IO ops. These should not require any specific alignment.

Quoted 1 line

Is it worth **any** code to try and catch them?

Definitely yes.

IMHO, this seems like overkill. Should we also prevent over-writing the stack or heap?

Quoted 4 lines

So just as an idea - we could use a bounce buffer for mmc_bwrite / mmc_bread for the unaligned case. Is definitely slow but should work.

Note that "sata read/write" and "usb read/write" have the same issues.

Regards,

Eric

#5 lore raw

Dear Eric Nelson,

Quoted 3 lines · In message <[email protected]> you wrote:

IMHO, this seems like overkill. Should we also prevent over-writing the stack or heap?

No. But we should not add any specific alignment requirements to commands that transfer data to memory. If some driver has such needs internally, then it should be handled there, but in a way that is transparent to the user.

Quoted 1 line

Note that "sata read/write" and "usb read/write" have the same issues.

So these should be fixed, too. Patches welcome :-)

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"UNIX was not designed to stop you from doing stupid things,  because
that would also stop you from doing clever things."       - Doug Gwyn