Skip to contentSkip to conversation

MPC5200 + LocalPlus Bus + memcpy

DISCUSSION Sascha Hauer 2 participants 4 messages Apr 5, 2006 – Apr 7, 2006 Journalling flash file system V2 (JFFS2)

lore
Share & tools
lore
#0 lore raw

Hi all,

I try to use jffs2 on a flash device connected to the mpc5200 LocalPlus Bus. This bus does not allow misaligned accesses. The jffs2 code uses memcpy to copy from a word aligned address to an odd address. The ppc memcpy implementation first copies three bytes to get the target address word aligned, but then the source address is on an odd address. The following word accesses on this unaligned address fail badly.

I have fixed my problem by modifying the physmap mtd driver, but some day someone wants to connect SRAM to the LocalPlus Bus and I guess he will expect memcpy to work.

(BTW the arm implementation of memcpy seems to work around this problem)

Sascha

#1 lore raw

Hello, Sascha.

Quoted 9 lines · Sascha Hauer

Hi all,

I try to use jffs2 on a flash device connected to the mpc5200 LocalPlus Bus. This bus does not allow misaligned accesses. The jffs2 code uses memcpy to copy from a word aligned address to an odd address. The ppc memcpy implementation first copies three bytes to get the target address word aligned, but then the source address is on an odd address. The following word accesses on this unaligned address fail badly.

Invalid crc on 'name' field ;)?

Quoted 3 lines

I have fixed my problem by modifying the physmap mtd driver, but some day someone wants to connect SRAM to the LocalPlus Bus and I guess he will expect memcpy to work.

Heh, I'll have same problem. Patch (dirty hack)
attached (vs head of vanilla 2.6. tree)

Quoted 1 line

(BTW the arm implementation of memcpy seems to work around this problem)

Wrong, memcpy to/from SDRAM _may_ be unaligned, only memcpy_fromio/memcpy_toio _must_ be aligned to even addresses.

P.S.
Paul, Sylvain, any suggestions to fix it? AFAIK, memcpy_to/from_io must be it string.s, isn't it?

P.P.S Sacha if you start to write mscan driver, then please wait a week, I planned to send my work to can-socket at next Friday.

Signature · 2 lines
Regards,
Andrey Volkov
fs/jffs2/scan.c +1 -1
index cf55b22..3bf61d6 100644
@@ -831,7 +831,7 @@ static int jffs2_scan_dirent_node(struct
 	if (!fd) {
 		return -ENOMEM;
 	}
-	memcpy(&fd->name, rd->name, rd->nsize);
+	memcpy_fromio(&fd->name, rd->name, rd->nsize);
 	fd->name[rd->nsize] = 0;
 
 	crc = crc32(0, fd->name, rd->nsize);
include/asm-ppc/io.h +23 -0
index b919d8f..c2f173a 100644
@@ -354,6 +354,29 @@ extern void _outsl_ns(volatile u32 __iom
 #define memset_io(a,b,c)       memset((void *)(a),(b),(c))
 #define memcpy_fromio(a,b,c)   memcpy((a),(void *)(b),(c))
 #define memcpy_toio(a,b,c)     memcpy((void *)(a),(b),(c))
+#elif defined (CONFIG_PPC_MPC52xx)
+static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
+{
+	volatile u8 __iomem *addr_u8 = addr;
+	for(;count>0;count--)
+		*addr_u8++ = val;
+}
+
+static inline void memcpy_fromio(void *dst,const volatile void __iomem *src, int count)
+{
+	const volatile u8 __iomem *src_u8 = src;
+	u8 *dst_u8 = dst;
+	for(;count>0;count--)
+		*dst_u8++ = *src_u8++;
+}
+
+static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
+{
+	const u8 *src_u8 = src;
+	volatile u8 __iomem *dst_u8 = dst;
+	for(;count>0;count--)
+		*dst_u8++ = *src_u8++;
+}
 #else
 static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
 {
#2 lore raw

Hello,

Quoted 6 lines · Andrey Volkov

Hello, Sascha.

Quoted 1 line · Sascha Hauer

Hi all,

Quoted 8 lines
Quoted 7 lines

I try to use jffs2 on a flash device connected to the mpc5200 LocalPlus Bus. This bus does not allow misaligned accesses. The jffs2 code uses memcpy to copy from a word aligned address to an odd address. The ppc memcpy implementation first copies three bytes to get the target address word aligned, but then the source address is on an odd address. The following word accesses on this unaligned address fail badly.

Invalid crc on 'name' field ;)?

Yes, exactly ;)

Quoted 10 lines
Quoted 4 lines

I have fixed my problem by modifying the physmap mtd driver, but some day someone wants to connect SRAM to the LocalPlus Bus and I guess he will expect memcpy to work.

Heh, I'll have same problem. Patch (dirty hack)
attached (vs head of vanilla 2.6. tree)

Quoted 1 line

(BTW the arm implementation of memcpy seems to work around this problem)

Wrong, memcpy to/from SDRAM _may_ be unaligned, only memcpy_fromio/memcpy_toio _must_ be aligned to even addresses.

Hm, then a proper fix would be:
- implement an optimized version of memcpy_fromio/memcpy_toio, this could be a version of memcpy which only alignes on the io side
- use memcpy_fromio/memcpy_toio in jffs2 code

Do I see this right?

Is SRAM considered io? I know (Arm-)Boards which do not have SDRAM, they run completely from SRAM.

Quoted 7 lines

P.S.
Paul, Sylvain, any suggestions to fix it? AFAIK, memcpy_to/from_io must be it string.s, isn't it?

P.P.S Sacha if you start to write mscan driver, then please wait a week, I planned to send my work to can-socket at next Friday.

No I haven't started yet, and I will happily wait another week ;)

Sascha

#3 lore raw

Hello, Sascha.

Quoted 16 lines · Sascha Hauer

Hello,

Quoted 13 lines · Andrey Volkov

Hello, Sascha.

Quoted 9 lines · Sascha Hauer

Hi all,

I try to use jffs2 on a flash device connected to the mpc5200 LocalPlus Bus. This bus does not allow misaligned accesses. The jffs2 code uses memcpy to copy from a word aligned address to an odd address. The ppc memcpy implementation first copies three bytes to get the target address word aligned, but then the source address is on an odd address. The following word accesses on this unaligned address fail badly.

Quoted 3 lines
Quoted 1 line

Invalid crc on 'name' field ;)?

Yes, exactly ;)

:)

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

I have fixed my problem by modifying the physmap mtd driver, but some day someone wants to connect SRAM to the LocalPlus Bus and I guess he will expect memcpy to work.

Heh, I'll have same problem. Patch (dirty hack)
attached (vs head of vanilla 2.6. tree)

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

(BTW the arm implementation of memcpy seems to work around this problem)

Wrong, memcpy to/from SDRAM _may_ be unaligned, only memcpy_fromio/memcpy_toio _must_ be aligned to even addresses.

Hm, then a proper fix would be:
- implement an optimized version of memcpy_fromio/memcpy_toio, this could be a version of memcpy which only alignes on the io side

Yes.

Quoted 1 line

- use memcpy_fromio/memcpy_toio in jffs2 code

They already use it (from jffs2_read/write), only scan.c doesn't calling this fns.

Quoted 1 line

Do I see this right?

Yes.

Quoted 2 lines

Is SRAM considered io? I know (Arm-)Boards which do not have SDRAM, they run completely from SRAM.

Only LBP demand alignment, SDRAM/DDR and internal SRAM didn't.

Signature · 2 lines
Regards,
Andrey Volkov