MPC5200b jffs2 memcpy alignment problem

Stephan Gatzka stephan at gatzka.org
Sat Jun 30 15:16:40 EDT 2012


Hello!

First of all, please apologize my cross posting.

I have a problem running jffs2 on an MPC5200b board. I run kernel 3.4, 
but older kernels like 3.1.5 are also affected. Every time I mount 
jffs2, previously written content gets garbled.

The problem was nailed down to memcpy(&fd->name, rd->name, checkedlen); 
in jffs2_scan_dirent_node in fs/jffs2/scan.c.

This is a copy directly from the mapped flash.

memcpy from copy_32.S only ensures that the 32 bit stores to the 
destination ptr are aligned. And that's the problem with the MPC5200b 
because the user manual (Chapter 9.2, LocalPlus bus features) clearly 
states that unaligned access is not supported. But the code above 
results in unaligned loads from the LocalPlus bus.

I think there are two possible solutions:

1. Rewrite memcpy this way: Only if both src and dst are 32 bit aligned, 
use 32 bit load/store to copy, otherwise use byte load/store 
instructions. (btw. is there a reason for not to use the load multiple 
and store multiple instructions in memcpy?) This might be the best way 
to do because in my opinion the semantics of memcpy put no restrictions 
on the alignment of src and dst.

2. use memcpy_fromio in the jffs2 code. memcpy_fromio behaves exactly in 
the way I described above. This could be also a good solution because 
flash access via LocalPlus bus is clearly IO.

What is your opinion where to fix this problem?

Regards,

Stephan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4931 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.infradead.org/pipermail/linux-mtd/attachments/20120630/ba381b0d/attachment.p7s>


More information about the linux-mtd mailing list