summaryrefslogtreecommitdiff
path: root/drivers/mtd
diff options
context:
space:
mode:
authorStefan Roese <sr@denx.de>2007-12-27 07:50:54 +0100
committerStefan Roese <sr@denx.de>2007-12-27 07:50:54 +0100
commit0dc80e2759fba859ccc4cdadc633577ca2971f3e (patch)
tree462d51af6b15c7f8cdc14cbde27bd35b72de6ea7 /drivers/mtd
parent0dcfe3a225a9436fc514f374a19242c672f1172b (diff)
downloadu-boot-imx-0dc80e2759fba859ccc4cdadc633577ca2971f3e.zip
u-boot-imx-0dc80e2759fba859ccc4cdadc633577ca2971f3e.tar.gz
u-boot-imx-0dc80e2759fba859ccc4cdadc633577ca2971f3e.tar.bz2
cfi_flash: Add missing check for erased dest to flash_write_cfibuffer()
The check for an sufficiently erased destination was missing in the buffered write function of the cfi flash driver (when CFG_FLASH_USE_BUFFER_WRITE is defined). This patch adds this check to that writing to such a region will fail with the currect error message. Signed-off-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/cfi_flash.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index f370e4f..d1124d3 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -769,7 +769,7 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
}
if (!flag) {
unmap_physmem(dstaddr, info->portwidth);
- return 2;
+ return ERR_NOT_ERASED;
}
/* Disable interrupts which might cause a timeout here */
@@ -826,7 +826,57 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp,
int retcode;
void *src = cp;
void *dst = map_physmem(dest, len, MAP_NOCACHE);
+ void *dst2 = dst;
+ int flag = 0;
+ switch (info->portwidth) {
+ case FLASH_CFI_8BIT:
+ cnt = len;
+ break;
+ case FLASH_CFI_16BIT:
+ cnt = len >> 1;
+ break;
+ case FLASH_CFI_32BIT:
+ cnt = len >> 2;
+ break;
+ case FLASH_CFI_64BIT:
+ cnt = len >> 3;
+ break;
+ default:
+ retcode = ERR_INVAL;
+ goto out_unmap;
+ }
+
+ while ((cnt-- > 0) && (flag == 0)) {
+ switch (info->portwidth) {
+ case FLASH_CFI_8BIT:
+ flag = ((flash_read8(dst2) & flash_read8(src)) ==
+ flash_read8(src));
+ src += 1, dst2 += 1;
+ break;
+ case FLASH_CFI_16BIT:
+ flag = ((flash_read16(dst2) & flash_read16(src)) ==
+ flash_read16(src));
+ src += 2, dst2 += 2;
+ break;
+ case FLASH_CFI_32BIT:
+ flag = ((flash_read32(dst2) & flash_read32(src)) ==
+ flash_read32(src));
+ src += 4, dst2 += 4;
+ break;
+ case FLASH_CFI_64BIT:
+ flag = ((flash_read64(dst2) & flash_read64(src)) ==
+ flash_read64(src));
+ src += 8, dst2 += 8;
+ break;
+ }
+ }
+ if (!flag) {
+ retcode = ERR_NOT_ERASED;
+ goto out_unmap;
+ }
+
+ src = cp;
sector = find_sector (info, dest);
switch (info->vendor) {