[U-Boot] [U-BOOT][PATCH 3/3] mflash : Improve mg_disk_read(write) sector count calculation

unsik Kim donari75 at gmail.com
Tue Feb 17 08:10:29 CET 2009


Signed-off-by: unsik Kim <donari75 at gmail.com>
---
  drivers/block/mg_disk.c |   16 ++++------------
  1 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index 2eb461d..bbfeeda 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -382,12 +382,8 @@ unsigned int mg_disk_read (u32 addr, u8 *buff, u32 len)

  	if (cur_addr < end_addr) {
  		sect_num = cur_addr >> MG_SECTOR_SIZE_SHIFT;
-		next_sec_addr = cur_addr + MG_SECTOR_SIZE;
-
-		while (next_sec_addr <= end_addr) {
-			cnt++;
-			next_sec_addr += MG_SECTOR_SIZE;
-		}
+		cnt = ((end_addr & MG_SECTOR_SIZE_MASK) - cur_addr) >>
+			MG_SECTOR_SIZE_SHIFT;

  		if (cnt)
  			err = mg_disk_read_sects(buff_ptr, sect_num, cnt);
@@ -524,12 +520,8 @@ unsigned int mg_disk_write(u32 addr, u8 *buff, u32 len)
  	if (cur_addr < end_addr) {

  		sect_num = cur_addr >> MG_SECTOR_SIZE_SHIFT;
-		next_sec_addr = cur_addr + MG_SECTOR_SIZE;
-
-		while (next_sec_addr <= end_addr) {
-			cnt++;
-			next_sec_addr += MG_SECTOR_SIZE;
-		}
+		cnt = ((end_addr & MG_SECTOR_SIZE_MASK) - cur_addr) >>
+			MG_SECTOR_SIZE_SHIFT;

  		if (cnt)
  			err = mg_disk_write_sects(buff_ptr, sect_num, cnt);
-- 
1.5.6.6


More information about the U-Boot mailing list