* [PATCH 0/2] smc91111 mac address and cfi flash fixes @ 2010-02-01 10:31 Marc Kleine-Budde 2010-02-01 10:31 ` [PATCH 1/2] smc91111: fix odering of mac address read from EEPROM Marc Kleine-Budde 2010-02-01 15:31 ` [PATCH 0/2] smc91111 mac address and cfi flash fixes Sascha Hauer 0 siblings, 2 replies; 5+ messages in thread From: Marc Kleine-Budde @ 2010-02-01 10:31 UTC (permalink / raw) To: barebox; +Cc: sha Hello, although these two patches are not related, I'm sending them as a series :) Our Admin discovered that the MAC address read from the smc91111 eeprom is bytewrapped. (Thanks to Jochen). The second patch addresses an aligment problem found in the cfi_flash driver. The patch reduces the access width to fix the problem. Thanks to Uwe for finding a nice way to figure out the minimum alignment. However the cfi_flash_new driver has the same problem. Which should be fixed, too. Please review and consider to apply. cheers, Marc. For you convenience you can pull....: The following changes since commit c68c06cb0e5f9913473ab9cfbf7c48af79582c99: Sascha Hauer (1): barebox-2009.12.0 are available in the git repository at: git://git.pengutronix.de/git/mkl/barebox.git for-sha Marc Kleine-Budde (2): smc91111: fix odering of mac address read from EEPROM cfi_flash: fix alignment problem drivers/net/smc91111.c | 23 +++++++++-------------- drivers/nor/cfi_flash.c | 10 +++++++--- 2 files changed, 16 insertions(+), 17 deletions(-) _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] smc91111: fix odering of mac address read from EEPROM 2010-02-01 10:31 [PATCH 0/2] smc91111 mac address and cfi flash fixes Marc Kleine-Budde @ 2010-02-01 10:31 ` Marc Kleine-Budde 2010-02-01 10:31 ` [PATCH 2/2] cfi_flash: fix alignment problem Marc Kleine-Budde 2010-02-01 15:31 ` [PATCH 0/2] smc91111 mac address and cfi flash fixes Sascha Hauer 1 sibling, 1 reply; 5+ messages in thread From: Marc Kleine-Budde @ 2010-02-01 10:31 UTC (permalink / raw) To: barebox; +Cc: sha On my little endian PXA270, the ethernet address is byte swapped: correct ethernet address: 00:50:c2:80:a7:bd broken ethernet address: 50:00:80:c2:bd:a7 The correct value is what the sticker on the baoard and the linux driver says. This patch fixes the problem by reading the ethaddr byte-wise from the eeprom. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> --- drivers/net/smc91111.c | 23 +++++++++-------------- 1 files changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/net/smc91111.c b/drivers/net/smc91111.c index 0df664a..9b41c67 100644 --- a/drivers/net/smc91111.c +++ b/drivers/net/smc91111.c @@ -1166,22 +1166,17 @@ static int smc91c111_eth_rx(struct eth_device *edev) static int smc91c111_get_ethaddr(struct eth_device *edev, unsigned char *m) { struct smc91c111_priv *priv = (struct smc91c111_priv *)edev->priv; - unsigned address[3]; + int valid = 0; + int i; SMC_SELECT_BANK(priv, 1); - address[0] = SMC_inw(priv, ADDR0_REG); - address[1] = SMC_inw(priv, ADDR0_REG + 2); - address[2] = SMC_inw(priv, ADDR0_REG + 4); - - if (address[0] + address[1] + address[2] == 0) - return -1; /* no eeprom, no mac */ - - m[0] = address[0] >> 8; - m[1] = address[0]; - m[2] = address[1] >> 8; - m[3] = address[1]; - m[4] = address[2] >> 8; - m[5] = address[2]; + + for (i = 0; i < 6; ++i) + valid += m[i] = SMC_inb(priv, (ADDR0_REG + i)); + + /* no eeprom, no mac */ + if (!valid) + return -1; return 0; } -- 1.6.6.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] cfi_flash: fix alignment problem 2010-02-01 10:31 ` [PATCH 1/2] smc91111: fix odering of mac address read from EEPROM Marc Kleine-Budde @ 2010-02-01 10:31 ` Marc Kleine-Budde 0 siblings, 0 replies; 5+ messages in thread From: Marc Kleine-Budde @ 2010-02-01 10:31 UTC (permalink / raw) To: barebox; +Cc: sha 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> --- 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 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] smc91111 mac address and cfi flash fixes 2010-02-01 10:31 [PATCH 0/2] smc91111 mac address and cfi flash fixes Marc Kleine-Budde 2010-02-01 10:31 ` [PATCH 1/2] smc91111: fix odering of mac address read from EEPROM Marc Kleine-Budde @ 2010-02-01 15:31 ` Sascha Hauer 1 sibling, 0 replies; 5+ messages in thread From: Sascha Hauer @ 2010-02-01 15:31 UTC (permalink / raw) To: Marc Kleine-Budde; +Cc: barebox On Mon, Feb 01, 2010 at 11:31:01AM +0100, Marc Kleine-Budde wrote: > Hello, > > although these two patches are not related, > I'm sending them as a series :) > > Our Admin discovered that the MAC address read from the smc91111 > eeprom is bytewrapped. (Thanks to Jochen). > > The second patch addresses an aligment problem found in the cfi_flash driver. > The patch reduces the access width to fix the problem. Thanks to Uwe for > finding a nice way to figure out the minimum alignment. > > However the cfi_flash_new driver has the same problem. > Which should be fixed, too. > > Please review and consider to apply. > cheers, Marc. Ok, applied to master, though after the release. Sascha > > For you convenience you can pull....: > > The following changes since commit c68c06cb0e5f9913473ab9cfbf7c48af79582c99: > Sascha Hauer (1): > barebox-2009.12.0 > > are available in the git repository at: > > git://git.pengutronix.de/git/mkl/barebox.git for-sha > > Marc Kleine-Budde (2): > smc91111: fix odering of mac address read from EEPROM > cfi_flash: fix alignment problem > > drivers/net/smc91111.c | 23 +++++++++-------------- > drivers/nor/cfi_flash.c | 10 +++++++--- > 2 files changed, 16 insertions(+), 17 deletions(-) > > > > _______________________________________________ > barebox mailing list > barebox@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/barebox > -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* cfi driver fixes @ 2012-04-05 8:59 Sascha Hauer 2012-04-05 8:59 ` [PATCH 2/2] cfi flash: Fix alignment problem Sascha Hauer 0 siblings, 1 reply; 5+ messages in thread From: Sascha Hauer @ 2012-04-05 8:59 UTC (permalink / raw) To: barebox The following fixes some problems with the cfi flash driver for 32 bit flashes. ---------------------------------------------------------------- Sascha Hauer (2): cfi flash: Fix loop count calculation cfi flash: Fix alignment problem drivers/nor/cfi_flash_intel.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] cfi flash: Fix alignment problem 2012-04-05 8:59 cfi driver fixes Sascha Hauer @ 2012-04-05 8:59 ` Sascha Hauer 0 siblings, 0 replies; 5+ messages in thread From: Sascha Hauer @ 2012-04-05 8:59 UTC (permalink / raw) To: barebox The intel cfi buffer write has a problem with writing when the alignment of the buffer in memory is smaller than the flash bus width. 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 aligned (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-aligned address with a 32 bit pointer. This patch fixes the problem by reducing the access width if an aligment problem between source and destination is found. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> --- drivers/nor/cfi_flash_intel.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/nor/cfi_flash_intel.c b/drivers/nor/cfi_flash_intel.c index f0cbf72..32e581a 100644 --- a/drivers/nor/cfi_flash_intel.c +++ b/drivers/nor/cfi_flash_intel.c @@ -57,6 +57,9 @@ static int intel_flash_write_cfibuffer (struct flash_info *info, ulong dest, con int retcode; void *src = (void*)cp; void *dst = (void *)dest; + /* reduce width due to possible alignment problems */ + const unsigned long ptr = (unsigned long)dest | (unsigned long)cp | info->portwidth; + const int width = ptr & -ptr; sector = find_sector (info, dest); flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS); @@ -70,20 +73,25 @@ static int intel_flash_write_cfibuffer (struct flash_info *info, ulong dest, con /* reduce the number of loops by the width of the port */ cnt = len / width; - flash_write_cmd(info, sector, 0, (u32)cnt - 1); + flash_write_cmd(info, sector, 0, cnt - 1); while (cnt-- > 0) { - if (bankwidth_is_1(info)) { + switch (width) { + case 1: flash_write8(flash_read8(src), dst); src += 1, dst += 1; - } else if (bankwidth_is_2(info)) { + break; + case 2: flash_write16(flash_read16(src), dst); src += 2, dst += 2; - } else if (bankwidth_is_4(info)) { + break; + case 4: flash_write32(flash_read32(src), dst); src += 4, dst += 4; - } else if (bankwidth_is_8(info)) { + break; + case 8: flash_write64(flash_read64(src), dst); src += 8, dst += 8; + break; } } -- 1.7.9.5 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-04-05 8:59 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-02-01 10:31 [PATCH 0/2] smc91111 mac address and cfi flash fixes Marc Kleine-Budde 2010-02-01 10:31 ` [PATCH 1/2] smc91111: fix odering of mac address read from EEPROM Marc Kleine-Budde 2010-02-01 10:31 ` [PATCH 2/2] cfi_flash: fix alignment problem Marc Kleine-Budde 2010-02-01 15:31 ` [PATCH 0/2] smc91111 mac address and cfi flash fixes Sascha Hauer 2012-04-05 8:59 cfi driver fixes Sascha Hauer 2012-04-05 8:59 ` [PATCH 2/2] cfi flash: Fix alignment problem Sascha Hauer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox