[U-Boot-Users] [PATCH] drivers/cfi_flash.c Odd-Sized Buffered Writes

Michael Bendzick michaelb at logicpd.com
Thu Jul 15 17:32:28 CEST 2004


This patch takes care of a problem with function write_buff in
drivers/cfi_flash.c driver when the CFG_FLASH_USE_BUFFER_WRITE setting is
defined.

---------------------

Description of problem:
When writing to a flash buffer, only a multiple of the byte size of the
flash chip port width is written.  For example, if attempting to write 59
bytes when the port width is 16 bits, only 58 bytes get written to the
buffer.  The remaining byte is left to be handled as an individual byte
write.  However, the write_buff in cfi_flash.c did not take into account the
rounding down of the number of bytes written with the buffered write.  As a
result, the handling of unaligned tail bytes would see 0 in cnt and think
the full amount of data had been written.

---------------------

The fix:
The variable i is rounded down to the nearest multiple of the portwidth
before incrementing/decrementing the source/destination/size variables.

---------------------

Log Message:
* Patch by Michael Bendzick, 15 Jul 2004:
  Fixes to drivers/cfi_flash.c:
  - Handling of writes with sizes that are not multiples of the byte
    size of the flash chip port width when CFG_FLASH_USE_BUFFER_WRITE
    is defined.
  - Fix minor comment typo.

---------------------

The patch:

Index: CHANGELOG
===================================================================
RCS file: /cvsroot/u-boot/u-boot/CHANGELOG,v
retrieving revision 1.342
diff -p -u -r1.342 CHANGELOG
--- CHANGELOG	12 Jul 2004 22:34:51 -0000	1.342
+++ CHANGELOG	15 Jul 2004 15:26:24 -0000
@@ -2,6 +2,13 @@
 Changes since U-Boot 1.1.1:
 ======================================================================
 
+* Patch by Michael Bendzick, 15 Jul 2004:
+  Fixes to drivers/cfi_flash.c:
+  - Handling of writes with sizes that are not multiples of the byte
+    size of the flash chip port width when CFG_FLASH_USE_BUFFER_WRITE
+    is defined.
+  - Fix minor comment typo.
+
 * Patch by Michael Bendzick, 12 Jul 2004:
   fix output formatting in drivers/cfi_flash.c
 
Index: drivers/cfi_flash.c
===================================================================
RCS file: /cvsroot/u-boot/u-boot/drivers/cfi_flash.c,v
retrieving revision 1.10
diff -p -u -r1.10 cfi_flash.c
--- drivers/cfi_flash.c	12 Jul 2004 22:34:52 -0000	1.10
+++ drivers/cfi_flash.c	15 Jul 2004 15:26:37 -0000
@@ -517,6 +517,7 @@ int write_buff (flash_info_t * info, uch
 		i = buffered_size > cnt ? cnt : buffered_size;
 		if ((rc = flash_write_cfibuffer (info, wp, src, i)) !=
ERR_OK)
 			return rc;
+		i -= (i % info->portwidth);
 		wp += i;
 		src += i;
 		cnt -= i;
@@ -1231,5 +1232,5 @@ static int flash_write_cfibuffer (flash_
 	flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
 	return retcode;
 }
-#endif /* CFG_USE_FLASH_BUFFER_WRITE */
+#endif /* CFG_FLASH_USE_BUFFER_WRITE */
 #endif /* CFG_FLASH_CFI */

---------------------

Example output demonstrating the problem & solution:

(Tests performed on TI OMAP1510 Innovator, aka board/omap1510inn, with
U-Boot build modified to use the cfi_flash.c driver.  The file 59-bytes is
59 bytes grabbed from /dev/urandom.)

[Old Driver]
OMAP1510 Innovator # erase 1:2
Erase Flash Sectors 2-2 in Bank # 1
. done
OMAP1510 Innovator # tftp 10000000 59-bytes
TFTP from server 192.168.1.177; our IP address is 192.168.1.249
Filename '59-bytes'.
Load address: 0x10000000
Loading: #
done
Bytes transferred = 59 (3b hex)
OMAP1510 Innovator # cp.b 10000000 40000 $(filesize)
Copy to Flash... done
OMAP1510 Innovator # cmp.b 10000000 40000 $(filesize)
byte at 0x1000003a (0x17) != byte at 0x0004003a (0xff)
Total of 58 bytes were the same

[New Driver]
1510 Innov. JMP10a # erase 1:2
Erase Flash Sectors 2-2 in Bank # 1
. done
OMAP1510 Innovator # tftp 10000000 59-bytes
TFTP from server 192.168.1.177; our IP address is 192.168.1.249
Filename '59-bytes'.
Load address: 0x10000000
Loading: #
done
Bytes transferred = 59 (3b hex)
OMAP1510 Innovator # cp.b 10000000 40000 $(filesize)
Copy to Flash... done
OMAP1510 Innovator # cmpb. 10000000 40000 $(filesize)
Unknown command 'cmpb.' - try 'help'
OMAP1510 Innovator # cmp.b 10000000 40000 $(filesize)
Total of 59 bytes were the same

---------------------

Testing:
The following boards have CFG_FLASH_CFI_DRIVER and
CFG_FLASH_USE_BUFFER_WRITE defined, making them the only boards to be
affected by my patch.  "OK" below indicates that it compiled properly.  I
don't have actual hardware to test though.

assabet   OK
csb272    OK
csb472    OK
eXalion   Not even unpatched from CVS compiled for me
gcplus    OK
ppmc8260  OK
sbc8560   ELDK didn't appear to compile for PPC 85xx, so this board remains
untested.  If someone can point me to a pre-made 85xx toolchain, I would
gladly test it out.

-Michael Bendzick
Systems and Software Engineering
Logic Product Development
michael.b at logicpd.com
612-436-5122
www.logicpd.com





More information about the U-Boot mailing list