From: Marc Kleine-Budde <mkl@pengutronix.de>
To: barebox@lists.infradead.org
Cc: sha@pengutronix.de
Subject: [PATCH 2/2] cfi_flash: fix alignment problem
Date: Mon, 1 Feb 2010 11:31:03 +0100 [thread overview]
Message-ID: <1265020263-21417-3-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1265020263-21417-2-git-send-email-mkl@pengutronix.de>
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
next prev parent reply other threads:[~2010-02-01 10:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Marc Kleine-Budde [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1265020263-21417-3-git-send-email-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=sha@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox