Re: [edk2] CD/DVD eject

Subject: Re: [edk2] CD/DVD eject

From: Sergey Isakov <isakov-sl@bk.ru>

To: edk2-devel@lists.sourceforge.net

Date: 2011-11-23 20:09:29

Hi all,

Thank to Jordan Justen for DxeServicesLib patch. With EDK2 rev12765 my issue seems to be resolved. My latest check shows  that CDROM is readable after disk change and new data is read.
I still have some issues but major one is gone.
Testing with Kubuntu v606LTS disk. It hangs the system in some sequence. In other sequence it readable. Looks like PartitionDxe/ElTorito has some problems with the structure. It is complex disk: partition for Windows and partition for Linux.
Something strange with handles. Previously I had two handles for CD
--------------------
Handle 7A (7E9A5390)
   Dpath (7E9A5490) 
      ACPI Device Path for Acpi
       HID PNP0A08, UID 0
      Hardware Device Path for PCI
       Function (1) Device (1F)
      Messaging Device Path for ATAPI
       ATAPI (Primary, Master) LUN (0)
      AsStr: 'PcieRoot(0x0)/Pci(0x1F,0x1)/Ata(Primary,Master,0x0)'
   DiskIo (7E99A998) 
   BlkIo (7ECB8A98) Removable MId:1 bsize 800, lblock 13BC7F (2,648,965,120), raw rw !cached
   ScsiIo (7E9A5518) 
   D432A67F-14DC-484B-B3BB-3F0291849327 (7ECB8B5C)
Handle 7B (7E99A490)
   Dpath (7E99A510) 
      ACPI Device Path for Acpi
       HID PNP0A08, UID 0
      Hardware Device Path for PCI
       Function (1) Device (1F)
      Messaging Device Path for ATAPI
       ATAPI (Primary, Master) LUN (0)
      Media Device Path for CD-ROM
       BootEntry (0) Start (000000000000009D) Size (0000000000000004)
      AsStr: 'PcieRoot(0x0)/Pci(0x1F,0x1)/Ata(Primary,Master,0x0)/CDROM(0x0,0x9D,0x4)'
   DiskIo (7E99A118) 
   BlkIo (7E9AA420) Removable MId:1 bsize 800, lblock 3 (8,192), partition rw !cached
-------------------
There is CDROM path! But the disk is not readable.
Now I have one handle
------------------
Handle 7A (7E9A5390)
   Dpath (7E9A5490) 
      ACPI Device Path for Acpi
       HID PNP0A08, UID 0
      Hardware Device Path for PCI
       Function (1) Device (1F)
      Messaging Device Path for ATAPI
       ATAPI (Primary, Master) LUN (0)
      AsStr: 'PcieRoot(0x0)/Pci(0x1F,0x1)/Ata(Primary,Master,0x0)'
   Fs (7D63AE98) 
   DiskIo (7E99A718) 
   BlkIo (7ECB8A98) Removable MId:1 bsize 800, lblock 13BC7F (2,648,965,120), raw rw !cached
   ScsiIo (7E9A5518) 
   D432A67F-14DC-484B-B3BB-3F0291849327 (7ECB8B5C)
------------------
No partition but there is Fs and this works!
What is mean? Bad Iso9660 driver that want to work out of partition? Exclude ElTorito driver?

Hope for some help,
Sergey

On 22.11.2011, at 20:37, Sergey Isakov wrote:

DuetPkg on real platform. Currently with GM965 chipset.
Don't know if I made a mistake. After some testing, debugging and comprehension I will report what is what.

On 22.11.2011, at 18:37, Carsey, Jaben wrote:

I found that sometimes it takes a while (up to a few minutes) to come back after that if I do not to a reconnect -all, but I have never found a permanent freeze state.

 

What platform are you using?

 

-Jaben

 


From: Sergey Isakov [mailto:isakov-sl@bk.ru]
Sent: Monday, November 21, 2011 10:07 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] CD/DVD eject

 

Hi Jaben,

 

Thank you for the interest to this issue. I made some tests to claim this but I am still not clear what is the reason of the problem.

I am not understanding what is happen with BlockIo, BlockIo2, DiskIo, SimpleFileSystem, UsbIo and ScsciIo when media change is occured.

It is very tangled chain of protocols and I also have issues with Sata so I think it is not hardware issue but protocols.

Continue testing.

 

You said it is never happen?! Insert USB stick with FAT32, read it, and then unplug. Shell.efi will hang. Always.

 

Sergey

 

On 22.11.2011, at 8:01, Carsey, Jaben wrote:



Can you explain this more?  I know that this has been tested and we didnt see this happen.

 

Thanks

 

-Jaben

It's a pity USB part is not working. It looks like missing some features in UsbMassStorageDxe or just the driver is wrong.

Plug/Unplug Usb stick causes hang of shell.efi. USB CDROM can read disk but until disk change. 

After disk change Hard Reset is required.

 

 


From: Sergey Isakov [mailto:isakov-sl@bk.ru]
Sent: Sunday, November 20, 2011 10:48 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] CD/DVD eject

 

Hi Suraj,

Here it is

--------------------------

VOID EjectVolume()

{

                        EFI_SCSI_IO_PROTOCOL                                                   *ScsiIo = NULL;

                        EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;

                        UINT64                          Lun;

                        UINT8                           *Target;

                        UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];

                        EFI_STATUS                      Status = EFI_UNSUPPORTED;

                        UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];

                        BOOTVOLUME_DATA*                                                                            volume = SelectedVolume();

                        USB_MASS_DEVICE                                                                                                           *UsbMass = NULL;

                        EFI_BLOCK_IO_PROTOCOL                                                                     *BlkIo             = NULL;

                        EFI_BLOCK_IO_MEDIA                                                                             *Media;

                        EFI_TPL                                                                                                                                                         OldTpl;

                        UINT32                Timeout;

                        UINT32                CmdResult;

 

                        //

                        // Initialize SCSI REQUEST_PACKET and 6-byte Cdb

                        //

                        ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));

                        ZeroMem (Cdb, sizeof (EFI_SCSI_OP_LENGTH_SIX));

                       

 

                        Status = gBootServices->HandleProtocol(volume->DeviceHandle, &gEfiScsiIoProtocolGuid, (VOID **) &ScsiIo);

                        if (ScsiIo) {

//                                              OldTpl  = gBootServices->RaiseTPL (TPL_NOTIFY);

                                                Target = &TargetArray[0];

                                                ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);

                                               

                                               

                                                Cdb[0]  = EFI_SCSI_OP_START_STOP_UNIT;

                                                Cdb[1]  = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);

                                                Cdb[1] |= 0x01;

                                                Cdb[4]  = 0x02; //eject command. NO DESCRIPTION IN HEADERS

                                                CommandPacket.Timeout = EFI_TIMER_PERIOD_SECONDS (3);

                                                CommandPacket.Cdb = Cdb;

                                                CommandPacket.CdbLength = (UINT8) sizeof (Cdb);

                                                                       

                                                Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);

//                                              gBootServices->RestoreTPL (OldTpl);

                        } else {

                                                Status = gBootServices->HandleProtocol(volume->DeviceHandle, &gEfiBlockIoProtocolGuid, (VOID **) &BlkIo);

                                                if (BlkIo) {

//                                                                      OldTpl  = gBootServices->RaiseTPL (TPL_NOTIFY);

                                                                        UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlkIo);

                                                                        if (!UsbMass) {

                                                                                                Print(L"no UsbMass\n");

                                                                                                Status = EFI_NOT_FOUND;

                                                                                                goto ON_EXIT;

                                                                        }

                                                                        Media   = &UsbMass->BlockIoMedia;

                                                                        if (!Media) {

                                                                                                Print(L"no BlockIoMedia\n");

                                                                                                Status = EFI_NO_MEDIA;

                                                                                                goto ON_EXIT;

                                                                        }

                                                                       

                                                                        //

                                                                        // If it is a removable media, such as CD-Rom or Usb-Floppy,

                                                                        // need to detect the media before each read/write. While some of

                                                                        // Usb-Flash is marked as removable media.

                                                                        //

                                                //TODO - DetectMedia will appear automatically. Do nothing?

                                                /*                     if (Media->RemovableMedia) {

                                                                                                Status = UsbBootDetectMedia (UsbMass);

                                                                                                if (EFI_ERROR (Status)) {

                                                                                                                        goto ON_EXIT;

                                                                                                }

                                                                        } */

                                                                       

                                                                        if (!(Media->MediaPresent)) {

                                                                                                Status = EFI_NO_MEDIA;

                                                                                                goto ON_EXIT;

                                                                        }

                        //TODO - remember previous state                                      

                        /*                                             if (MediaId != Media->MediaId) {

                                                                                                Status = EFI_MEDIA_CHANGED;

                                                                                                goto ON_EXIT;

                                                                        }*/

                                                                       

                                                                        Timeout = USB_BOOT_GENERAL_CMD_TIMEOUT;

                                                                        Cdb[0]  = EFI_SCSI_OP_START_STOP_UNIT;

                                                                        Cdb[1]  = (UINT8) (USB_BOOT_LUN(Lun) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);

                                                                        Cdb[1] |= 0x01;

                                                                        Cdb[4]  = 0x02; //eject command. NO DESCRIPTION IN HEADERS

                                                                        Status = EFI_UNSUPPORTED;

//TODO - it hangs                                                                  

/*                                                                     Status    = UsbMass->Transport->ExecCommand (

                                                                                                                                                                                                                        UsbMass->Context,

                                                                                                                                                                                                                        &Cdb,

                                                                                                                                                                                                                        sizeof(Cdb),

                                                                                                                                                                                                                        EfiUsbDataOut,

                                                                                                                                                                                                                        NULL, 0,

                                                                                                                                                                                                                        UsbMass->Lun,

                                                                                                                                                                                                                        Timeout,

                                                                                                                                                                                                                        &CmdResult

                                                                                                                                                                                                                        );

*/

//ON_EXIT:                                                   

//                                                                      gBootServices->RestoreTPL (OldTpl);

                                                }

                        }

ON_EXIT:

                        if (EFI_ERROR(Status)) {

                          Print(L"Can't eject, status=%r\n", Status);

                        }

}

 

-------------------------

It's a pity USB part is not working. It looks like missing some features in UsbMassStorageDxe or just the driver is wrong.

Plug/Unplug Usb stick causes hang of shell.efi. USB CDROM can read disk but until disk change. 

After disk change Hard Reset is required.

 

Sergey.

 

On 21.11.2011, at 9:14, Suraj Joshi wrote:




Hi Sergey,

 

Can you share complete code of below code snippet for better understanding?

 

I have used EFI_EXT_PASS_THRU_PROTOCOL for ejecting CD drive. Following is the packet structure of Pass thru protocol

 

 

   Packet.Timeout            = 100000;   // 100ns * 1000000 = 10s

    Packet.InDataBuffer       = NULL;

    Packet.OutDataBuffer      = Buffer;

    Packet.SenseData          = SenseData;

    Packet.Cdb                = Cdb;

    Packet.InTransferLength   = 0;

    Packet.OutTransferLength  = 2048;

    Packet.CdbLength          = 10;

    Packet.DataDirection      = 0;

    Packet.HostAdapterStatus  = 0;

    Packet.TargetStatus       = 0;

    Packet.SenseDataLength    = 252;

 

And cdb is as follows,

 

Cdb[0] = 0x1B;

    Cdb[1] = 0x01;

    Cdb[2] = 0;      // lba

    Cdb[3] = 0;      // lba

    Cdb[4] = 0x02;   // lba

    Cdb[5] = 0;      // lba

    Cdb[6] = 0;

    Cdb[7] = 0;

    Cdb[8] = 0;      // sect

    Cdb[9] = 0;

 

 

 

BR

Suraj Joshi

 

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Friday, November 18, 2011 6:48 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] Read data block from CD/DVD

 

Hi Suraj,

 

I am successful although this feature is not documented in EDK2 headers.

--------------------

                if (ScsiIo) {

                                //

                                // Initialize SCSI REQUEST_PACKET and 6-byte Cdb

                                //

                                ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));

                                ZeroMem (Cdb, sizeof (EFI_SCSI_OP_LENGTH_SIX));

                               

                                Target = &TargetArray[0];

                                ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);

                               

                               

                                Cdb[0]  = EFI_SCSI_OP_START_STOP_UNIT;

                                Cdb[1]  = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);

                                Cdb[1] |= 0x01;

                                Cdb[4]  = 0x02; //eject command. NO DESCRIPTION IN HEADERS

                                CommandPacket.Timeout = EFI_TIMER_PERIOD_SECONDS (3);

                                CommandPacket.Cdb = Cdb;

                                CommandPacket.CdbLength = (UINT8) sizeof (Cdb);

                                //  CommandPacket.InDataBuffer = &ScsiDiskDevice->IdentifyData;

                                //  CommandPacket.InTransferLength = 0;

                               

                                Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);

                }

 

-------------------

 

Regards

Sergey

 

 

On 18.11.2011, at 15:20, Sergey Isakov wrote:





Hi Suraj,

 

This is clear. I want to ask about the contents of the packet.

----

  /// A pointer to buffer that contains the Command Data Block to

  /// send to the SCSI device specified by Target and Lun.

  ///

  VOID   *Cdb;

 

---

 

Sergey

 

On 18.11.2011, at 14:00, Suraj Joshi wrote:





HI Sergey,

 

I used PassThru() method of  EFI_EXT_SCSI_PASS_THRU_PROTOCOL to perform eject command.

 

I am using EDK 1.06 source code as base version.

 

 

Thanks,

 

Suraj

 

 

 

 

 

 

 

 

 

From: Sergey Isakov [mailto:isakov-sl@bk.ru] 
Sent: Thursday, November 17, 2011 7:38 PM
To: edk2-devel@lists.sourceforge.net
Subject: Re: [edk2] Read data block from CD/DVD

 

Hi Suraj,

 

You can enter shell.efi and type here

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

 

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel