]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
scsi: fix disk capacity too small by one sector
authorJulius Lehmann <lehmanju@devpi.de>
Sat, 26 Oct 2024 18:06:44 +0000 (20:06 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 1 Nov 2024 19:34:32 +0000 (13:34 -0600)
SCSI READ CAPACITY reports the address of the last block and the block
size. The total number of blocks is thus last block address plus one.

This also fixes the corresponding test case.

drivers/scsi/scsi.c
test/boot/bootdev.c

index 51cacf3479236be6c6ea3e7d15b87e03f10e7f3a..bcdeda95ed1514119057cc67974fec465cf5672c 100644 (file)
@@ -309,6 +309,7 @@ static int scsi_read_capacity(struct udevice *dev, struct scsi_cmd *pccb,
                         ((unsigned long)pccb->pdata[5] << 16) |
                         ((unsigned long)pccb->pdata[6] << 8)  |
                         ((unsigned long)pccb->pdata[7]);
+               *capacity += 1;
                return 0;
        }
 
@@ -332,6 +333,7 @@ static int scsi_read_capacity(struct udevice *dev, struct scsi_cmd *pccb,
                    ((uint64_t)pccb->pdata[5] << 16) |
                    ((uint64_t)pccb->pdata[6] << 8)  |
                    ((uint64_t)pccb->pdata[7]);
+       *capacity += 1;
 
        *blksz = ((uint64_t)pccb->pdata[8]  << 56) |
                 ((uint64_t)pccb->pdata[9]  << 48) |
index 369105ca4cfc33e370f4b1156c909333d48d9223..369c611d924b5c07378bdcc8ad97f929beb76c02 100644 (file)
@@ -630,7 +630,7 @@ static int bootdev_test_next_label(struct unit_test_state *uts)
        ut_assertok(bootdev_next_label(&iter, &dev, &mflags));
        ut_assert_nextline("scanning bus for devices...");
        ut_assert_skip_to_line(
-               "            Capacity: 1.9 MB = 0.0 GB (4095 x 512)");
+               "            Capacity: 2.0 MB = 0.0 GB (4096 x 512)");
        ut_assert_console_end();
        ut_assertnonnull(dev);
        ut_asserteq_str("scsi.id0lun0.bootdev", dev->name);