> > > > Heh, capacity is reported incorrectly, but it works am I'm able
> > > > to load kernel from there.
> > > The reason for this is that the multiplication 488397168 x 512 will
> > > overflow a 32 bit integer as used in "disk/part.c"; this shouldbe
> > > fixed...
> > 
> > This issue is still here:
> 
> Sorry for not being clear. What I meant was: this is a bug that needs
> to be fixed (patches welcome).

Oh, I've attached my solution.

> >     $sudo openocd -f /usr/share/openocd/scripts/board/sheevaplug.cfg
> >     Open On-Chip Debugger 0.5.0-dev-00466-g28ddefd (2010-08-06-22:54)
> > ...
> >     > reset
> 
> Hm... I am not sure what exactly the OpenOCD debugger does when you
> run the reset command; eventually it performs some initializations
> (defined in sheevaplug.cfg ?), and/or prevents others. The CPU may, or
> may not, be in the virgin state expected by U-Boot.
> 
> Detach the debugger, and perform a real hard reset instead. Or try to
> configure the debugger not to perform any initializations (i. e. the
> equivalent of the "reset run" command on BDI2000/30000).

Sheevaplug has reset button on the box.  So I've pushed it, no change.

sh-4.0# hdparm /dev/sda

/dev/sda:
 HDIO_DRIVE_CMD(identify) failed: Invalid exchange
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 30401/255/63, sectors = 488397168, start = 0
sh-4.0# 
sh-4.0# 

<pressed reset button>

U-Boot 2010.06-00267-gb1f95b4 (Aug 07 2010 - 15:30:45)
Marvell-Sheevaplug

SoC:   Kirkwood 88F6281_A0
DRAM:  512 MiB
NAND:  512 MiB
In:    serial
Out:   serial
Err:   serial
Net:   egiga0
88E1116 Initialized on egiga0
Hit any key to stop autoboot:  0 
Marvell>> usb start
(Re)start USB...
USB:   Register 10011 NbrPorts 1
USB EHCI 1.00
scanning bus for devices... 2 USB Device(s) found
       scanning bus for storage devices... 0 Storage Device(s) found

Kernel does not boot as well:
[   22.867512] Waiting for root device /dev/sda3...
[   22.973783] usb 1-1: device descriptor read/64, error -32
[   23.203774] usb 1-1: device descriptor read/64, error -32

-- 

  Sergei
From 0b68e3d10c82d942a9f068bcb8d7af7711daaf24 Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <sly...@gentoo.org>
Date: Sat, 7 Aug 2010 22:39:35 +0300
Subject: [PATCH] disk/part.c: 'usb storage' avoiding overflow when output capacity

Before:
    Marvell>> usb storage
      Device 0: Vendor: StoreJet Rev:  Prod:  Transcend
                Type: Hard Disk
                Capacity: 28759.9 MB = 28.0 GB (488397168 x 512)
After:
    Marvell>> usb storage
      Device 0: Vendor: StoreJet Rev:  Prod:  Transcend
                Type: Hard Disk
                Capacity: 238475.1 MB = 232.8 GB (488397168 x 512)

Signed-off-by: Sergei Trofimovich <sly...@gentoo.org>
---
 disk/part.c |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index b6bae17..ee5be2b 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -109,14 +109,31 @@ block_dev_desc_t *get_dev(char* ifname, int dev)
 /*
  * reports device info to the user
  */
-void dev_print (block_dev_desc_t *dev_desc)
-{
+
 #ifdef CONFIG_LBA48
-	uint64_t lba512; /* number of blocks if 512bytes block size */
+typedef uint64_t lba512_t;
 #else
-	lbaint_t lba512;
+typedef lbaint_t lba512_t;
 #endif
 
+/*
+ * Overflowless variant of (block_count * mul_by / div_by)
+ * when div_by > mul_by
+ */
+static lba512_t lba512_muldiv (lba512_t block_count, lba512_t mul_by, lba512_t div_by)
+{
+    lba512_t bc_quot, bc_rem;
+
+    /* x * m / d == x / d * m + (x % d) * m / d */
+    bc_quot = block_count / div_by;
+    bc_rem  = block_count - div_by * bc_quot;
+    return bc_quot * mul_by + (bc_rem * mul_by) / div_by;
+}
+
+void dev_print (block_dev_desc_t *dev_desc)
+{
+	lba512_t lba512; /* number of blocks if 512bytes block size */
+
 	if (dev_desc->type == DEV_TYPE_UNKNOWN) {
 		puts ("not available\n");
 		return;
@@ -184,8 +201,9 @@ void dev_print (block_dev_desc_t *dev_desc)
 		lba = dev_desc->lba;
 
 		lba512 = (lba * (dev_desc->blksz/512));
-		mb = (10 * lba512) / 2048;	/* 2048 = (1024 * 1024) / 512 MB */
 		/* round to 1 digit */
+		mb = lba512_muldiv(lba512, 10, 2048); /* 2048 = (1024 * 1024) / 512 MB */
+
 		mb_quot	= mb / 10;
 		mb_rem	= mb - (10 * mb_quot);
 
-- 
1.7.1

Attachment: signature.asc
Description: PGP signature

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to