[PATCH 2/2] cfi_flash: fix alignment problem
Marc Kleine-Budde
mkl at pengutronix.de
Mon Feb 1 05:31:03 EST 2010
This patch fixes a alignment problem which may show during this
scenario:
- 32 or 64 attached NOR flash
- flashing an image directly from network to the nor flash
The involved network driver is "smc9111.c".
The data that comes from the network stack and should be written into
the flash isn't 32 bit alligned (at least with this network driver).
This is probably due to the 48 bit wide ethernet addresses.
However the "cfi_flash.c" driver doesn't handle this situation, and
accesses the not-alligned address with a 32 bit pointer.
This patch fixes the problem by reducing the access width if an
alligment problem between source and destination is found.
Signed-off-by: Marc Kleine-Budde <mkl at pengutronix.de>
---
drivers/nor/cfi_flash.c | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index 37206d0..bdef856 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -1336,6 +1336,10 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, const uchar *
volatile cfiptr_t src;
volatile cfiptr_t dst;
+ /* reduce width due to possible alignment problems */
+ const unsigned long ptr = (unsigned long)dest | (unsigned long)cp | info->portwidth;
+ const int width = ptr & -ptr;
+
switch (info->vendor) {
case CFI_CMDSET_INTEL_STANDARD:
case CFI_CMDSET_INTEL_EXTENDED:
@@ -1347,7 +1351,7 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, const uchar *
if ((retcode = flash_status_check (info, sector, info->buffer_write_tout,
"write to buffer")) == ERR_OK) {
/* reduce the number of loops by the width of the port */
- switch (info->portwidth) {
+ switch (width) {
case FLASH_CFI_8BIT:
cnt = len;
break;
@@ -1366,7 +1370,7 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, const uchar *
}
flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
while (cnt-- > 0) {
- switch (info->portwidth) {
+ switch (width) {
case FLASH_CFI_8BIT:
*dst.cp++ = *src.cp++;
break;
@@ -1401,7 +1405,7 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, const uchar *
flash_unlock_seq(info,0);
flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_TO_BUFFER);
- switch (info->portwidth) {
+ switch (width) {
case FLASH_CFI_8BIT:
cnt = len;
flash_write_cmd (info, sector, 0, (uchar) cnt - 1);
--
1.6.6.1
More information about the barebox
mailing list