diff packages/io/flash/current/src/flash.c @ 1730:3f6b1c304c7a

* src/flash.c: Offset into the block is not calculated correctly when the flash start is not aligned on a flash block. * src/legacy_dev.c (legacy_flash_read): Fixed typo.
author asl
date Thu, 30 Sep 2004 18:09:20 +0000
parents e290a0372578
children 9464c6747e99
line wrap: on
line diff
--- a/packages/io/flash/current/src/flash.c
+++ b/packages/io/flash/current/src/flash.c
@@ -514,7 +514,7 @@ cyg_flash_program(const cyg_flashaddr_t 
     if (size > block_size) size = block_size;
     
     // Writing from the middle of a block?
-    offset = (size_t)addr % block_size;
+    offset = (size_t)(addr - dev->start) % block_size;
     if (offset)
       size = MIN(block_size - offset, size);
     stat = dev->funs->flash_program(dev, addr, ram, size);
@@ -602,7 +602,7 @@ cyg_flash_read(cyg_flashaddr_t flash_bas
     if (size > block_size) size = block_size;
     
     // Reading from the middle of a block?
-    offset = (size_t)addr % block_size;
+    offset = (size_t)(addr - dev->start) % block_size;
     if (offset)
       size = MIN(block_size - offset, size);
     if (dev->funs->flash_read) {