This is the simplest way to avoid breaking boot on USB sticks that stall when asked for the MODE SENSE page 4. Some old sticks do not support the MODE SENSE command at all and just return a "medium may have changed" unit attention condition when SeaBIOS sends it!
Reported-by: Dave Frodin dave@camp.se-eng.com Signed-off-by: Paolo Bonzini pbonzini@redhat.com --- src/blockcmd.c | 36 +++++++++++++++++++++++------------- 1 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/src/blockcmd.c b/src/blockcmd.c index 2769573..b4a1e37 100644 --- a/src/blockcmd.c +++ b/src/blockcmd.c @@ -139,19 +139,29 @@ scsi_init_drive(struct drive_s *drive, const char *s, int prio) dprintf(1, "%s blksize=%d sectors=%d\n" , s, drive->blksize, (unsigned)drive->sectors);
- struct cdbres_mode_sense_geom geomdata; - ret = cdb_mode_sense_geom(&dop, &geomdata); - if (ret == 0) { - u32 cylinders; - cylinders = geomdata.cyl[0] << 16; - cylinders |= geomdata.cyl[1] << 8; - cylinders |= geomdata.cyl[2]; - if (cylinders && geomdata.heads && - drive->sectors <= 0xFFFFFFFFULL && - ((u32)drive->sectors % (geomdata.heads * cylinders) == 0)) { - drive->pchs.cylinders = cylinders; - drive->pchs.heads = geomdata.heads; - drive->pchs.spt = (u32)drive->sectors / (geomdata.heads * cylinders); + // We do not recover from USB stalls, so try to be safe and avoid + // sending the command if the (obsolete, but still provided by QEMU) + // fixed disk geometry page may not be supported. + // + // We could also send the command only to small disks (e.g. <504MiB) + // but some old USB keys only support a very small subset of SCSI which + // does not even include the MODE SENSE command! + // + if (! CONFIG_COREBOOT && memcmp(vendor, "QEMU ", 8) == 0) { + struct cdbres_mode_sense_geom geomdata; + ret = cdb_mode_sense_geom(&dop, &geomdata); + if (ret == 0) { + u32 cylinders; + cylinders = geomdata.cyl[0] << 16; + cylinders |= geomdata.cyl[1] << 8; + cylinders |= geomdata.cyl[2]; + if (cylinders && geomdata.heads && + drive->sectors <= 0xFFFFFFFFULL && + ((u32)drive->sectors % (geomdata.heads * cylinders) == 0)) { + drive->pchs.cylinders = cylinders; + drive->pchs.heads = geomdata.heads; + drive->pchs.spt = (u32)drive->sectors / (geomdata.heads * cylinders); + } } }
Paolo, I tested your patch. It works with all 14 USB thumbdrives and with a USB-to-SATA adapter we dug up.
Dave
----- Original Message -----
From: "Paolo Bonzini" pbonzini@redhat.com To: seabios@seabios.org Cc: "Dave Frodin" dave@camp.se-eng.com Sent: Monday, March 5, 2012 4:29:12 AM Subject: [PATCH] scsi: do not send MODE SENSE except to QEMU disks
This is the simplest way to avoid breaking boot on USB sticks that stall when asked for the MODE SENSE page 4. Some old sticks do not support the MODE SENSE command at all and just return a "medium may have changed" unit attention condition when SeaBIOS sends it!
Reported-by: Dave Frodin dave@camp.se-eng.com Signed-off-by: Paolo Bonzini pbonzini@redhat.com
src/blockcmd.c | 36 +++++++++++++++++++++++------------- 1 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/src/blockcmd.c b/src/blockcmd.c index 2769573..b4a1e37 100644 --- a/src/blockcmd.c +++ b/src/blockcmd.c @@ -139,19 +139,29 @@ scsi_init_drive(struct drive_s *drive, const char *s, int prio) dprintf(1, "%s blksize=%d sectors=%d\n" , s, drive->blksize, (unsigned)drive->sectors);
- struct cdbres_mode_sense_geom geomdata;
- ret = cdb_mode_sense_geom(&dop, &geomdata);
- if (ret == 0) {
u32 cylinders;
cylinders = geomdata.cyl[0] << 16;
cylinders |= geomdata.cyl[1] << 8;
cylinders |= geomdata.cyl[2];
if (cylinders && geomdata.heads &&
drive->sectors <= 0xFFFFFFFFULL &&
((u32)drive->sectors % (geomdata.heads * cylinders) ==
0)) {
drive->pchs.cylinders = cylinders;
drive->pchs.heads = geomdata.heads;
drive->pchs.spt = (u32)drive->sectors / (geomdata.heads
- cylinders);
- // We do not recover from USB stalls, so try to be safe and
avoid
- // sending the command if the (obsolete, but still provided by
QEMU)
- // fixed disk geometry page may not be supported.
- //
- // We could also send the command only to small disks (e.g.
<504MiB)
- // but some old USB keys only support a very small subset of
SCSI which
- // does not even include the MODE SENSE command!
- //
- if (! CONFIG_COREBOOT && memcmp(vendor, "QEMU ", 8) == 0) {
struct cdbres_mode_sense_geom geomdata;
ret = cdb_mode_sense_geom(&dop, &geomdata);
if (ret == 0) {
u32 cylinders;
cylinders = geomdata.cyl[0] << 16;
cylinders |= geomdata.cyl[1] << 8;
cylinders |= geomdata.cyl[2];
if (cylinders && geomdata.heads &&
drive->sectors <= 0xFFFFFFFFULL &&
((u32)drive->sectors % (geomdata.heads * cylinders)
== 0)) {
drive->pchs.cylinders = cylinders;
drive->pchs.heads = geomdata.heads;
drive->pchs.spt = (u32)drive->sectors /
(geomdata.heads * cylinders);
}} }
-- 1.7.7.6
Signed-off-by: Dave Frodin dave@camp.se-eng.com
Paolo, Marc wanted me to request that this patch be included in the next stable SeaBIOS release.
Thanks again for your help on this. Dave
----- Original Message -----
From: "Paolo Bonzini" pbonzini@redhat.com To: seabios@seabios.org Cc: "Dave Frodin" dave@camp.se-eng.com Sent: Monday, March 5, 2012 4:29:12 AM Subject: [PATCH] scsi: do not send MODE SENSE except to QEMU disks
This is the simplest way to avoid breaking boot on USB sticks that stall when asked for the MODE SENSE page 4. Some old sticks do not support the MODE SENSE command at all and just return a "medium may have changed" unit attention condition when SeaBIOS sends it!
Reported-by: Dave Frodin dave@camp.se-eng.com Signed-off-by: Paolo Bonzini pbonzini@redhat.com
src/blockcmd.c | 36 +++++++++++++++++++++++------------- 1 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/src/blockcmd.c b/src/blockcmd.c index 2769573..b4a1e37 100644 --- a/src/blockcmd.c +++ b/src/blockcmd.c @@ -139,19 +139,29 @@ scsi_init_drive(struct drive_s *drive, const char *s, int prio) dprintf(1, "%s blksize=%d sectors=%d\n" , s, drive->blksize, (unsigned)drive->sectors);
- struct cdbres_mode_sense_geom geomdata;
- ret = cdb_mode_sense_geom(&dop, &geomdata);
- if (ret == 0) {
u32 cylinders;
cylinders = geomdata.cyl[0] << 16;
cylinders |= geomdata.cyl[1] << 8;
cylinders |= geomdata.cyl[2];
if (cylinders && geomdata.heads &&
drive->sectors <= 0xFFFFFFFFULL &&
((u32)drive->sectors % (geomdata.heads * cylinders) ==
0)) {
drive->pchs.cylinders = cylinders;
drive->pchs.heads = geomdata.heads;
drive->pchs.spt = (u32)drive->sectors / (geomdata.heads
- cylinders);
- // We do not recover from USB stalls, so try to be safe and
avoid
- // sending the command if the (obsolete, but still provided by
QEMU)
- // fixed disk geometry page may not be supported.
- //
- // We could also send the command only to small disks (e.g.
<504MiB)
- // but some old USB keys only support a very small subset of
SCSI which
- // does not even include the MODE SENSE command!
- //
- if (! CONFIG_COREBOOT && memcmp(vendor, "QEMU ", 8) == 0) {
struct cdbres_mode_sense_geom geomdata;
ret = cdb_mode_sense_geom(&dop, &geomdata);
if (ret == 0) {
u32 cylinders;
cylinders = geomdata.cyl[0] << 16;
cylinders |= geomdata.cyl[1] << 8;
cylinders |= geomdata.cyl[2];
if (cylinders && geomdata.heads &&
drive->sectors <= 0xFFFFFFFFULL &&
((u32)drive->sectors % (geomdata.heads * cylinders)
== 0)) {
drive->pchs.cylinders = cylinders;
drive->pchs.heads = geomdata.heads;
drive->pchs.spt = (u32)drive->sectors /
(geomdata.heads * cylinders);
}} }
-- 1.7.7.6
On Mon, Mar 05, 2012 at 12:29:12PM +0100, Paolo Bonzini wrote:
This is the simplest way to avoid breaking boot on USB sticks that stall when asked for the MODE SENSE page 4. Some old sticks do not support the MODE SENSE command at all and just return a "medium may have changed" unit attention condition when SeaBIOS sends it!
Thanks - I commited this change.
-Kevin