[PATCH 08/12] cfi flash: fix flash_make_cmd for big endian access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is broken on big endian systems since:

943b271 cfi_flash: support of u32 cmd

I looked over it and I *think* that the function was correct
for both big and little endian systems before this patch.
To support u32 cmd we only have to change the data type of
the command from u8 to u32.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
Cc: Teresa Gámez <t.gamez@xxxxxxxxx>
---
 drivers/nor/cfi_flash.c |   24 +++++-------------------
 1 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index f9b96c5..654e647 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -822,26 +822,12 @@ int flash_generic_status_check (struct flash_info *info, flash_sect_t sector,
  */
 void flash_make_cmd(struct flash_info *info, u32 cmd, cfiword_t *cmdbuf)
 {
-	int i;
-	int cp_offset;
-	int cword_offset;
-	uchar val;
-	uchar *cp;
-
-	*cmdbuf = 0;
-	cp = (uchar *)cmdbuf;
+	cfiword_t result = 0;
+	int i = info->portwidth / info->chipwidth;
 
-	for (i = info->portwidth; i > 0; i--) {
-		cword_offset = (info->portwidth-i) % info->chipwidth;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-		cp_offset = info->portwidth - i;
-		val = *((uchar *)&cmd + cword_offset);
-#else
-		cp_offset = i - 1;
-		val = *((uchar *)&cmd + sizeof(u32) - cword_offset - 1);
-#endif
-	cp[cp_offset] = (cword_offset >= sizeof(u32)) ? 0x00 : val;
-	}
+	while (i--)
+		result = (result << (8 * info->chipwidth)) | cmd;
+	*cmdbuf = result;
 }
 
 /*
-- 
1.7.6.3


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux