summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2010-02-01 11:31:03 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2010-02-01 16:27:35 +0100
commit1e658639f1f8ebd2862964ebc50ee0bd122633f4 (patch)
treefbc831389ca3974690c27092da43e0cd4696c793 /drivers
parent4903636f98fd19ae343b0494bad7b9d3b0c3cdaf (diff)
downloadbarebox-1e658639f1f8ebd2862964ebc50ee0bd122633f4.tar.gz
barebox-1e658639f1f8ebd2862964ebc50ee0bd122633f4.tar.xz
cfi_flash: fix alignment problem
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@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/nor/cfi_flash.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index 938e2cb7bb..1d8ed2d6e5 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -1337,6 +1337,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:
@@ -1348,7 +1352,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;
@@ -1367,7 +1371,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;
@@ -1402,7 +1406,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);