[U-Boot] [U-BOOT][PATCH 3/3] Fix miscalculated total sectors

unsik Kim donari75 at gmail.com
Fri Feb 13 12:05:57 CET 2009


When using CONFIG_MG_DISK_RES, total sectors should be
recalculated.

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

diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index e1b1a68..193a441 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -174,7 +174,7 @@ static int mg_get_disk_id (void)
 {
 	u32 iobuf[(MG_SECTOR_SIZE / sizeof(u32))];
 	hd_driveid_t *iop = (hd_driveid_t *)iobuf;
-	u32 i, err;
+	u32 i, err, res;
 	u16 *buff = (u16 *)iobuf;
 
 	writeb(MG_CMD_ID, MG_BASE + MG_REG_COMMAND);
@@ -214,11 +214,21 @@ static int mg_get_disk_id (void)
 #endif /* __LITTLE_ENDIAN */
 
 #ifdef __BIG_ENDIAN
-	mg_disk_dev.lba = (iop->lba_capacity << 16) | (iop->lba_capacity >> 16);
-#else	/* ! __BIG_ENDIAN */
-	mg_disk_dev.lba = iop->lba_capacity;
+	iop->lba_capacity = (iop->lba_capacity << 16) |
+		(iop->lba_capacity >> 16);
 #endif /* __BIG_ENDIAN */
 
+	if (MG_RES_SEC) {
+		MG_DBG("MG_RES_SEC=%d\n", MG_RES_SEC);
+		iop->cyls = (iop->lba_capacity - MG_RES_SEC) /
+			iop->sectors / iop->heads;
+		res = iop->lba_capacity -
+			iop->cyls * iop->heads * iop->sectors;
+		iop->lba_capacity -= res;
+		printf("mg_disk: %d sectors reserved\n", res);
+	}
+
+	mg_disk_dev.lba = iop->lba_capacity;
 	return MG_ERR_NONE;
 }
 
-- 
1.5.6.6


More information about the U-Boot mailing list