qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] hw/scsi-bus.c: Fix use of uninitialised variabl


From: Blue Swirl
Subject: Re: [Qemu-devel] [PATCH] hw/scsi-bus.c: Fix use of uninitialised variable
Date: Sat, 13 Aug 2011 17:29:40 +0000

On Fri, Aug 12, 2011 at 7:22 PM, Blue Swirl <address@hidden> wrote:
> On Fri, Aug 12, 2011 at 4:49 PM, Peter Maydell <address@hidden> wrote:
>> Don't use req before it has been initialised in scsi_req_new().
>> This fixes a compile failure due to gcc complaining about this.
>
> It fixes a crash if the warning is ignored:
> Configuration device id QEMU version 1 machine id 32
>
> Program received signal SIGSEGV, Segmentation fault.
> scsi_req_new (d=0x15e46b0, tag=0x0, lun=0x0, buf=0x7fffffffde41 "\022",
>    hba_private=<value optimized out>) at /src/qemu/hw/scsi-bus.c:375
> 375             if (req->cmd.lba != -1) {
> (gdb) bt
> #0  scsi_req_new (d=0x15e46b0, tag=0x0, lun=0x0, buf=0x7fffffffde41 "\022",
>    hba_private=<value optimized out>) at /src/qemu/hw/scsi-bus.c:375
> #1  0x000000000052c6ef in do_busid_cmd (s=0x15e2790, buf=0x0,
>    busid=<value optimized out>) at /src/qemu/hw/esp.c:247
> #2  0x000000000052cc5d in do_cmd (s=0x15e2790) at /src/qemu/hw/esp.c:270
> #3  handle_satn (s=0x15e2790) at /src/qemu/hw/esp.c:284
> #4  0x000000000052d174 in esp_mem_writeb (opaque=0x15e2790,
>    addr=<value optimized out>, val=0xc2) at /src/qemu/hw/esp.c:640
> #5  0x000000004003d1f5 in ?? ()
> #6  0x0000000001632330 in ?? ()
> #7  0x0000000001632280 in ?? ()
> #8  0x00007fffffffe180 in ?? ()
> #9  0x3d3d87e90d932400 in ?? ()
> #10 0x00007ffff7eefd00 in ?? ()
> #11 0x00000000004dc558 in tb_reset_jump_recursive2 (tb=0xffee100c)
>    at /src/qemu/exec.c:1389
> #12 tb_reset_jump_recursive (tb=0xffee100c) at /src/qemu/exec.c:1395
> #13 0x000000000040bdea in qemu_notify_event () at /src/qemu/cpus.c:616
> #14 <signal handler called>
> #15 0x00000000004de681 in cpu_sparc_exec (env=0x1059600)
>    at /src/qemu/cpu-exec.c:528
> #16 0x000000000040c1fc in tcg_cpu_exec () at /src/qemu/cpus.c:1064
> #17 cpu_exec_all () at /src/qemu/cpus.c:1105
> #18 0x0000000000519497 in main_loop (argc=<value optimized out>,
>    argv=<value optimized out>, envp=<value optimized out>)
>    at /src/qemu/vl.c:1392
> #19 main (argc=<value optimized out>, argv=<value optimized out>,
>    envp=<value optimized out>) at /src/qemu/vl.c:3356
> (gdb) p req
> $1 = <value optimized out>
> (gdb) p req->cmd
> Cannot access memory at address 0x28
> (gdb) p req->cmd.lba
> Cannot access memory at address 0x48
>
>> Signed-off-by: Peter Maydell <address@hidden>
>> ---
>>  hw/scsi-bus.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
>> index f2af6cd..559d5a4 100644
>> --- a/hw/scsi-bus.c
>> +++ b/hw/scsi-bus.c
>> @@ -372,7 +372,7 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, 
>> uint32_t lun,
>>     } else {
>>         trace_scsi_req_parsed(d->id, lun, tag, buf[0],
>>                               cmd.mode, cmd.xfer);
>> -        if (req->cmd.lba != -1) {
>> +        if (cmd.lba != -1) {
>>             trace_scsi_req_parsed_lba(d->id, lun, tag, buf[0],
>>                                       cmd.lba);
>>         }

Something is very wrong with SCSI. OpenBIOS can't boot anymore:
Configuration device id QEMU version 1 machine id 32
CPUs: 1 x FMI,MB86904
UUID: 00000000-0000-0000-0000-000000000000
Welcome to OpenBIOS v1.0 built on Jul 20 2011 21:16
  Type 'help' for detailed information
Trying cdrom:d...
Unhandled Exception 0x0000002a
PC = 0xffd10bdc NPC = 0xffd10be0
Stopping execution

This is due to division by zero in OpenBIOS drivers/esp.c. Bisecting
reveals that this is due to c7b488721d6aafe32994ac63f8d690ae6d4729fa,
SCSI devices now report Unit Attention status after reset. OpenBIOS
does not handle this case and fails (block size is 0).

First OpenBIOS issues Inquiry command, then if a device is present,
Read Capacity. I tried adding Request Sense command after Inquiry, but
then QEMU crashes:

Configuration device id QEMU version 1 machine id 32
Initializing SCSI...dma1: Revision 2
ESP at 0xffdaa230, buffer va 0xffdab000 dva 0xfe000000
done
Initializing SCSI devices...do_command: id 0, cmd[0] 0x80, status 0x80
do_command: id 1, cmd[0] 0x80, status 0x80
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
do_command: id 2, cmd[0] 0x80, status 0x93
request_sense id 2 failed
request_sense id 2 sense key 128
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
read_capacity id 2 bs 2048 sectors 1295228
do_command: id 2, cmd[0] 0x80, status 0x91
*** glibc detected ***
/src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc: double free or
corruption (out): 0x00000000016407e0 ***
======= Backtrace: =========
/lib/libc.so.6(+0x71ad6)[0x7ffff3de1ad6]
/lib/libc.so.6(cfree+0x6c)[0x7ffff3de684c]
/src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc[0x46b41e]
/src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc[0x46b7cf]
/src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc[0x46a037]
/src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc[0x46b4ad]
/src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc[0x52f057]
/src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc[0x52f331]
/src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc[0x52f95d]
[0x4004113b]
======= Memory map: ========
00400000-005fa000 r-xp 00000000 08:13 3827028
  /src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc
007fa000-0080f000 rw-p 001fa000 08:13 3827028
  /src/qemu/obj-amd64/sparc-softmmu/qemu-system-sparc
0080f000-00ff6000 rw-p 00000000 00:00 0
00ff6000-00ff7000 rwxp 00000000 00:00 0
00ff7000-01299000 rw-p 00000000 00:00 0                                  [heap]
01299000-0129a000 rw-p 00000000 00:00 0                                  [heap]
0129a000-012a0000 rw-p 00000000 00:00 0                                  [heap]
012a0000-012a1000 rw-p 00000000 00:00 0                                  [heap]
012a1000-01682000 rw-p 00000000 00:00 0                                  [heap]
40000000-40100000 rwxp 00000000 00:00 0
7fffe0000000-7fffe0021000 rw-p 00000000 00:00 0
7fffe0021000-7fffe4000000 ---p 00000000 00:00 0
7fffe708b000-7fffe70a1000 r-xp 00000000 08:11 89618
  /lib/libgcc_s.so.1
7fffe70a1000-7fffe72a0000 ---p 00016000 08:11 89618
  /lib/libgcc_s.so.1
7fffe72a0000-7fffe72a1000 rw-p 00015000 08:11 89618
  /lib/libgcc_s.so.1
7fffe72a1000-7fffe75a2000 rw-p 00000000 00:00 0
7fffe76cf000-7fffe76d0000 rw-p 00000000 00:00 0
7fffe76d0000-7fffe7fd0000 rw-p 00000000 00:00 0
7fffe7fd0000-7fffe7fd1000 rw-p 00000000 00:00 0
7fffe81b3000-7fffe81b4000 rw-p 00000000 00:00 0
7fffe81b4000-7fffe82b4000 rw-p 00000000 00:00 0
7fffe82b4000-7fffe82b6000 rw-p 00000000 00:00 0
7fffe82b6000-7ffff02b6000 rw-p 00000000 00:00 0
7ffff02b6000-7ffff02b7000 rw-p 00000000 00:00 0
7ffff02b7000-7ffff02b8000 ---p 00000000 00:00 0
7ffff02b8000-7ffff0ab8000 rw-p 00000000 00:00 0
7ffff0ab8000-7ffff0abd000 r-xp 00000000 08:11 316801
  /usr/lib/libXdmcp.so.6.0.0
7ffff0abd000-7ffff0cbc000 ---p 00005000 08:11 316801
  /usr/lib/libXdmcp.so.6.0.0
7ffff0cbc000-7ffff0cbd000 rw-p 00004000 08:11 316801
  /usr/lib/libXdmcp.so.6.0.0
7ffff0cbd000-7ffff0cbf000 r-xp 00000000 08:11 315723
  /usr/lib/libXau.so.6.0.0
7ffff0cbf000-7ffff0ebf000 ---p 00002000 08:11 315723
  /usr/lib/libXau.so.6.0.0
7ffff0ebf000-7ffff0ec0000 rw-p 00002000 08:11 315723
  /usr/lib/libXau.so.6.0.0
7ffff0ec0000-7ffff0edf000 r-xp 00000000 08:11 89944
  /lib/libx86.so.1
7ffff0edf000-7ffff10df000 ---p 0001f000 08:11 89944
  /lib/libx86.so.1
7ffff10df000-7ffff10e1000 rw-p 0001f000 08:11 89944
  /lib/libx86.so.1
7ffff10e1000-7ffff10e2000 rw-p 00000000 00:00 0
7ffff10e2000-7ffff10e5000 r-xp 00000000 08:11 312446
  /usr/lib/libgpg-error.so.0.4.0
7ffff10e5000-7ffff12e4000 ---p 00003000 08:11 312446
  /usr/lib/libgpg-error.so.0.4.0
7ffff12e4000-7ffff12e5000 rw-p 00002000 08:11 312446
  /usr/lib/libgpg-error.so.0.4.0
7ffff12e5000-7ffff12e7000 r-xp 00000000 08:11 89690
  /lib/libkeyutils.so.1.3
7ffff12e7000-7ffff14e6000 ---p 00002000 08:11 89690
  /lib/libkeyutils.so.1.3
7ffff14e6000-7ffff14e7000 rw-p 00001000 08:11 89690
  /lib/libkeyutils.so.1.3
7ffff14e7000-7ffff14ee000 r-xp 00000000 08:11 311226
  /usr/lib/libkrb5support.so.0.1
7ffff14ee000-7ffff16ee000 ---p 00007000 08:11 311226
  /usr/lib/libkrb5support.so.0.1
7ffff16ee000-7ffff16ef000 rw-p 00007000 08:11 311226
  /usr/lib/libkrb5support.so.0.1
7ffff16ef000-7ffff16f2000 r-xp 00000000 08:11 89655
  /lib/libcom_err.so.2.1
7ffff16f2000-7ffff18f1000 ---p 00003000 08:11 89655
  /lib/libcom_err.so.2.1
7ffff18f1000-7ffff18f2000 rw-p 00002000 08:11 89655
  /lib/libcom_err.so.2.1
7ffff18f2000-7ffff1917000 r-xp 00000000 08:11 311218
  /usr/lib/libk5crypto.so.3.1
7ffff1917000-7ffff1b16000 ---p 00025000 08:11 311218
  /usr/lib/libk5crypto.so.3.1
7ffff1b16000-7ffff1b18000 rw-p 00024000 08:11 311218
  /usr/lib/libk5crypto.so.3.1
7ffff1b18000-7ffff1bd6000 r-xp 00000000 08:11 311223
  /usr/lib/libkrb5.so.3.3
7ffff1bd6000-7ffff1dd5000 ---p 000be000 08:11 311223
  /usr/lib/libkrb5.so.3.3
7ffff1dd5000-7ffff1de0000 rw-p 000bd000 08:11 311223
  /usr/lib/libkrb5.so.3.3
7ffff1de0000-7ffff1dfc000 r-xp 00000000 08:11 312097
  /usr/lib/libxcb.so.1.1.0
7ffff1dfc000-7ffff1ffb000 ---p 0001c000 08:11 312097
  /usr/lib/libxcb.so.1.1.0
7ffff1ffb000-7ffff1ffc000 rw-p 0001b000 08:11 312097
  /usr/lib/libxcb.so.1.1.0
7ffff1ffc000-7ffff2049000 r-xp 00000000 08:11 203809
  /usr/lib/libvga.so.1.4.3
7ffff2049000-7ffff2248000 ---p 0004d000 08:11 203809
  /usr/lib/libvga.so.1.4.3
7ffff2248000-7ffff2251000 rw-p 0004c000 08:11 203809
  /usr/lib/libvga.so.1.4.3
7ffff2251000-7ffff225a000 rw-p 00000000 00:00 0
7ffff225a000-7ffff2270000 r-xp 00000000 08:11 311386
  /usr/lib/libdirect-1.2.so.9.0.1
7ffff2270000-7ffff246f000 ---p 00016000 08:11 311386
  /usr/lib/libdirect-1.2.so.9.0.1
7ffff246f000-7ffff2471000 rw-p 00015000 08:11 311386
  /usr/lib/libdirect-1.2.so.9.0.1
7ffff2471000-7ffff247a000 r-xp 00000000 08:11 311381
  /usr/lib/libfusion-1.2.so.9.0.1
7ffff247a000-7ffff267a000 ---p 00009000 08:11 311381
  /usr/lib/libfusion-1.2.so.9.0.1
7ffff267a000-7ffff267b000 rw-p 00009000 08:11 311381
  /usr/lib/libfusion-1.2.so.9.0.1
7ffff267b000-7ffff26fa000 r-xp 00000000 08:11 311384
  /usr/lib/libdirectfb-1.2.so.9.0.1
7ffff26fa000-7ffff28f9000 ---p 0007f000 08:11 311384
  /usr/lib/libdirectfb-1.2.so.9.0.1
7ffff28f9000-7ffff28fd000 rw-p 0007e000 08:11 311384
  /usr/lib/libdirectfb-1.2.so.9.0.1
Program received signal SIGABRT, Aborted.
0x00007ffff3da2165 in *__GI_raise (sig=<value optimized out>)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
        in ../nptl/sysdeps/unix/sysv/linux/raise.c
(gdb) bt
#0  0x00007ffff3da2165 in *__GI_raise (sig=<value optimized out>)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff3da4f70 in *__GI_abort () at abort.c:92
#2  0x00007ffff3dd827b in __libc_message (do_abort=<value optimized out>,
    fmt=<value optimized out>) at ../sysdeps/unix/sysv/linux/libc_fatal.c:189
#3  0x00007ffff3de1ad6 in malloc_printerr (action=0x3,
    str=0x7ffff3e98aa8 "double free or corruption (out)",
    ptr=<value optimized out>) at malloc.c:6267
#4  0x00007ffff3de684c in *__GI___libc_free (mem=<value optimized out>)
    at malloc.c:3739
#5  0x000000000046b41e in scsi_req_unref (req=0x16407e0)
    at /src/qemu/hw/scsi-bus.c:1017
#6  0x000000000046b7cf in scsi_req_complete (req=0x16407e0, status=0x0)
    at /src/qemu/hw/scsi-bus.c:1095
#7  0x000000000046a037 in scsi_target_read_data (req=0x16407e0)
    at /src/qemu/hw/scsi-bus.c:324
#8  0x000000000046b4ad in scsi_req_continue (req=0x16407e0)
    at /src/qemu/hw/scsi-bus.c:1029
#9  0x000000000052f057 in esp_do_dma (s=0x15e6220) at /src/qemu/hw/esp.c:385
#10 0x000000000052f331 in handle_ti (s=0x15e6220) at /src/qemu/hw/esp.c:458
#11 0x000000000052f95d in esp_mem_writeb (opaque=0x15e6220, addr=0xc, val=0x90)
    at /src/qemu/hw/esp.c:610
#12 0x000000004004113b in ?? ()
#13 0x00007ffff7f0f880 in ?? ()
#14 0x00000000004de6f8 in tb_reset_jump_recursive2 (tb=0xffee200c)
    at /src/qemu/exec.c:1389
#15 tb_reset_jump_recursive (tb=0xffee200c) at /src/qemu/exec.c:1395
#16 0x00000000004de6f8 in tb_reset_jump_recursive2 (tb=0x7ffff7f0f810)
    at /src/qemu/exec.c:1389
#17 tb_reset_jump_recursive (tb=0x7ffff7f0f810) at /src/qemu/exec.c:1395
#18 0x000000000040beba in qemu_notify_event () at /src/qemu/cpus.c:616
#19 <signal handler called>
#20 cpu_sparc_exec (env=0x105d0a0) at /src/qemu/cpu-exec.c:558
#21 0x000000000040c2cc in tcg_cpu_exec () at /src/qemu/cpus.c:1064
#22 cpu_exec_all () at /src/qemu/cpus.c:1105
#23 0x000000000051b637 in main_loop (argc=<value optimized out>,
    argv=<value optimized out>, envp=<value optimized out>)
    at /src/qemu/vl.c:1392
#24 main (argc=<value optimized out>, argv=<value optimized out>,
    envp=<value optimized out>) at /src/qemu/vl.c:3356
(gdb) up
#1  0x00007ffff3da4f70 in *__GI_abort () at abort.c:92
92      abort.c: No such file or directory.
        in abort.c
(gdb)
#2  0x00007ffff3dd827b in __libc_message (do_abort=<value optimized out>,
    fmt=<value optimized out>) at ../sysdeps/unix/sysv/linux/libc_fatal.c:189
189     ../sysdeps/unix/sysv/linux/libc_fatal.c: No such file or directory.
        in ../sysdeps/unix/sysv/linux/libc_fatal.c
(gdb)
#3  0x00007ffff3de1ad6 in malloc_printerr (action=0x3,
    str=0x7ffff3e98aa8 "double free or corruption (out)",
    ptr=<value optimized out>) at malloc.c:6267
6267    malloc.c: No such file or directory.
        in malloc.c
(gdb)
#4  0x00007ffff3de684c in *__GI___libc_free (mem=<value optimized out>)
    at malloc.c:3739
3739    in malloc.c
(gdb)
#5  0x000000000046b41e in scsi_req_unref (req=0x16407e0)
    at /src/qemu/hw/scsi-bus.c:1017
1017            qemu_free(req);
(gdb) p *req
$1 = {bus = 0x15e7888, dev = 0x15e8140, ops = 0x800f20, refcount = 0x0,
  tag = 0x0, lun = 0x0, status = 0x0, cmd = {
    buf = "\003\000\000\000\374\b\000\000\260\335\377\377\000\000\000",
    len = 0x6, xfer = 0xfc, lba = 0x0, mode = SCSI_XFER_FROM_DEV},
  aiocb = 0x0, sense = '\000' <repeats 95 times>, sense_len = 0x0,
  enqueued = 0x0, hba_private = 0x0, next = {tqe_next = 0x0,
    tqe_prev = 0x15e8250}}

The same patched OpenBIOS boots nicely with
4333979e3d8c129953bba36ed87ce543d33cbea1:

Configuration device id QEMU version 1 machine id 32
Initializing SCSI...dma1: Revision 2
ESP at 0xffdaa230, buffer va 0xffdab000 dva 0xfe000000
done
Initializing SCSI devices...do_command: id 0, cmd[0] 0x80, status 0x80
do_command: id 1, cmd[0] 0x80, status 0x80
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
request_sense id 2 sense key 240
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
read_capacity id 2 bs 2048 sectors 1295228
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
request_sense id 2 sense key 240
SCSI DRIVE @ffdaa2c0:
id: 2
media: cdrom
media: cd
model: QEMU CD-ROM
sectors: 1295228
present: 1
bs: 2048
do_command: id 3, cmd[0] 0x80, status 0x80
do_command: id 4, cmd[0] 0x80, status 0x80
do_command: id 5, cmd[0] 0x80, status 0x80
do_command: id 6, cmd[0] 0x80, status 0x80
do_command: id 7, cmd[0] 0x80, status 0x80
add_alias dev "/iommu/sbus/espdma/esp/address@hidden,0" = alias "cdrom"
add_alias dev "/iommu/sbus/espdma/esp/address@hidden,0" = alias "cd"
add_alias dev "/iommu/sbus/espdma/esp/address@hidden,0" = alias "cdrom0"
add_alias dev "/iommu/sbus/espdma/esp/address@hidden,0" = alias "cd0"
add_alias dev "/iommu/sbus/espdma/esp/address@hidden,0" = alias "sd(0,2,0)"
add_alias dev "/iommu/sbus/espdma/esp/address@hidden,0" = alias "sd(0,2,0)@0,0"
done
CPUs: 1 x FMI,MB86904
UUID: 00000000-0000-0000-0000-000000000000
Welcome to OpenBIOS v1.0 built on Jul 20 2011 21:16
  Type 'help' for detailed information
Trying cdrom:d...
opening drive 2 args d
ob_sd_read_blocks id 2 ffdefb60 block=0 n=1
ob_sd_read_sector id 2 sector=0
[New Thread 0x7fffe72a0700 (LWP 12653)]
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
ob_sd_read_blocks id 2 ffdefb60 block=0 n=1
ob_sd_read_sector id 2 sector=0
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
Trying cdrom...
opening drive 2 args <NULL>
ob_sd_read_blocks id 2 ffdefb60 block=0 n=1
ob_sd_read_sector id 2 sector=0
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
ob_sd_read_blocks id 2 ffdefb60 block=0 n=1
ob_sd_read_sector id 2 sector=0
do_command: id 2, cmd[0] 0x80, status 0x91
do_command_reply: status 0x93
ob_sd_read_blocks id 2 ffdc32c0 block=2 n=2
ob_sd_read_sector id 2 sector=0
etc.

Here's the patch (WIP) to OpenBIOS if someone wants to try:
diff --git a/drivers/esp.c b/drivers/esp.c
index 78478f6..2766e87 100644
--- a/drivers/esp.c
+++ b/drivers/esp.c
@@ -28,6 +28,7 @@

 #define BUFSIZE         4096

+#define CONFIG_DEBUG_ESP
 #ifdef CONFIG_DEBUG_ESP
 #define DPRINTF(fmt, args...)                   \
     do { printk(fmt , ##args); } while (0)
@@ -176,12 +177,14 @@ read_capacity(esp_private_t *esp, sd_private_t *sd)
     if (do_command(esp, sd, 11, 8)) {
         sd->sectors = 0;
         sd->bs = 0;
-
+        DPRINTF("read_capacity id %d failed\n", sd->id);
         return 0;
     }
     sd->bs = (esp->buffer[4] << 24) | (esp->buffer[5] << 16) |
(esp->buffer[6] << 8) | esp->buffer[7];
     sd->sectors = ((esp->buffer[0] << 24) | (esp->buffer[1] << 16) |
(esp->buffer[2] << 8) | esp->buffer[3]) * (sd->bs / 512);

+    DPRINTF("read_capacity id %d bs %d sectors %d\n", sd->id, sd->bs,
+            sd->sectors);
     return 1;
 }

@@ -224,6 +227,26 @@ inquiry(esp_private_t *esp, sd_private_t *sd)
 }


+static unsigned int
+request_sense(esp_private_t *esp, sd_private_t *sd)
+{
+    /* Setup command = Request Sense */
+    memset(esp->buffer, 0, 6);
+    esp->buffer[0] = 0x80;
+    esp->buffer[1] = REQUEST_SENSE;
+
+    esp->buffer[5] = 252;
+
+    if (do_command(esp, sd, 7, 252)) {
+        DPRINTF("request_sense id %d failed\n", sd->id);
+    DPRINTF("request_sense id %d sense key %d\n", sd->id, esp->buffer[0]);
+        return 0;
+    }
+
+    DPRINTF("request_sense id %d sense key %d\n", sd->id, esp->buffer[0]);
+    return 1;
+}
+
 static void
 ob_sd_read_blocks(sd_private_t **sd)
 {
@@ -478,7 +501,9 @@ ob_esp_init(unsigned int slot, uint64_t base,
unsigned long espoffset,
         esp->sd[id].id = id;
         if (!inquiry(esp, &esp->sd[id]))
             continue;
+        request_sense(esp, &esp->sd[id]);
         read_capacity(esp, &esp->sd[id]);
+        request_sense(esp, &esp->sd[id]);

 #ifdef CONFIG_DEBUG_ESP
         dump_drive(&esp->sd[id]);

Attachment: openbios-esp-request-sense.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]