public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: unsik Kim <donari75@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [U-BOOT][PATCH 3/3] Fix miscalculated total sectors
Date: Fri, 13 Feb 2009 20:05:57 +0900	[thread overview]
Message-ID: <49955415.8080109@gmail.com> (raw)

When using CONFIG_MG_DISK_RES, total sectors should be
recalculated.

Signed-off-by: unsik Kim <donari75@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

             reply	other threads:[~2009-02-13 11:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-13 11:05 unsik Kim [this message]
2009-02-14 11:53 ` [U-Boot] [U-BOOT][PATCH 3/3] Fix miscalculated total sectors Jean-Christophe PLAGNIOL-VILLARD

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=49955415.8080109@gmail.com \
    --to=donari75@gmail.com \
    --cc=u-boot@lists.denx.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