[U-Boot-Users] [PATCH] cfi_flash: fix flash on BE machines with CFG_WRITE_SWAPPED_DATA

Sebastian Siewior bigeasy at linutronix.de
Tue Jul 15 23:12:40 CEST 2008


This got broken by commits 93c56f212c
 [cfi_flash: support of long cmd in U-boot.]

That command needs to be in little endian format on BE machines
with CFG_WRITE_SWAPPED_DATA. Without this patch, the command 0xf0
gets saved on stack as 0x00 00 00 f0 and 0x00 gets written into
the cmdbuf in case portwidth = chipwidth = 8

Cc: Alexey Korolev <akorolev at infradead.org>
Cc: Vasiliy Leonenko <vasiliy.leonenko at mail.ru>
Signed-off-by: Sebastian Siewior <bigeasy at linutronix.de>
---
Stefan, this is on top of my previous patch. I don't touch the 
BE + !CFG_WRITE_SWAPPED_DATA because it worked before. What I'm
not 100% sure is whether LE + CFG_WRITE_SWAPPED_DATA still works....

 drivers/mtd/cfi_flash.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 4340b1b..a85e0ff 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -306,16 +306,21 @@ static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf)
 	int i;
 	int cword_offset;
 	int cp_offset;
+	int cmd_le;
 	uchar val;
 	uchar *cp = (uchar *) cmdbuf;
 
+	cmd_le = cpu_to_le32(cmd);
 	for (i = info->portwidth; i > 0; i--){
 		cword_offset = (info->portwidth-i)%info->chipwidth;
 #if defined(__LITTLE_ENDIAN) || defined(CFG_WRITE_SWAPPED_DATA)
 		cp_offset = info->portwidth - i;
-		val = *((uchar*)&cmd + cword_offset);
+		val = *((uchar*)&cmd_le + cword_offset);
 #else
 		cp_offset = i - 1;
+		/* we rely here on the fact, that cmd _has_ to be in BE
+		 * order because we are not __LITTLE_ENDIAN
+		 */
 		val = *((uchar*)&cmd + sizeof(u32) - cword_offset - 1);
 #endif
 		cp[cp_offset] = (cword_offset >= sizeof(u32)) ? 0x00 : val;
-- 
1.5.5.2





More information about the U-Boot mailing list