]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UsbStorage: Fix "map -r" cannot detect media change
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 19 Jan 2018 07:04:24 +0000 (15:04 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 22 Jan 2018 02:18:04 +0000 (10:18 +0800)
When system boots to Shell without CDROM in the USB CDROM drive,
and then user inserts one CDROM with Eltorito file system,
"map -r" cannot show the the new Eltorito file system.

The root cause is when "map" command probes the media change
by calling dummy ReadBlockIo(), UsbMassStorage ReadBlockIo()
contains a bug that ignores the media change status:
UsbBootDetectMedia() ignores the EFI_MEDIA_CHANGED status
returned from UsbBootIsUnitReady(), in consequence, the
BlockIo protocol re-installation logic doesn't run.

By checking the code change history, below commit
SHA-1: 19bc85276559ae01996fa0918ec3f6495e7aaa69
* remove unnecessary retry logic from usb mass storage driver.
adds the code to skip EFI_MEDIA_CHANGED status.

Talking with the original committer Tian Feng, he said the
change was just a code cleanup, not for a special bug fix.
So I revert part of the patch, only keep the change that
removes unnecessary retry logic. It can fix this bug.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c

index a8b6a1c5f13c9cca81490650ddb6c0a5ca013fa5..613008bde76837f174b37335c5a7e47d4bdae30f 100644 (file)
@@ -2,7 +2,7 @@
   Implementation of the command set of USB Mass Storage Specification\r
   for Bootability, Revision 1.0.\r
 \r
   Implementation of the command set of USB Mass Storage Specification\r
   for Bootability, Revision 1.0.\r
 \r
-Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -630,8 +630,10 @@ UsbBootGetParams (
 {\r
   EFI_BLOCK_IO_MEDIA          *Media;\r
   EFI_STATUS                  Status;\r
 {\r
   EFI_BLOCK_IO_MEDIA          *Media;\r
   EFI_STATUS                  Status;\r
+  UINT8                       CmdSet;\r
 \r
   Media  = &(UsbMass->BlockIoMedia);\r
 \r
   Media  = &(UsbMass->BlockIoMedia);\r
+  CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *) (UsbMass->Context))->InterfaceSubClass;\r
 \r
   Status = UsbBootInquiry (UsbMass);\r
   if (EFI_ERROR (Status)) {\r
 \r
   Status = UsbBootInquiry (UsbMass);\r
   if (EFI_ERROR (Status)) {\r
@@ -666,9 +668,18 @@ UsbBootGetParams (
     Media->BlockSize        = 0x0800;\r
   }\r
 \r
     Media->BlockSize        = 0x0800;\r
   }\r
 \r
-  Status = UsbBootDetectMedia (UsbMass);\r
+  if ((UsbMass->Pdt != USB_PDT_CDROM) && (CmdSet == USB_MASS_STORE_SCSI)) {\r
+    //\r
+    // ModeSense is required for the device with PDT of 0x00/0x07/0x0E,\r
+    // which is from [MassStorageBootabilitySpec-Page7].\r
+    // ModeSense(10) is useless here, while ModeSense(6) defined in SCSI\r
+    // could get the information of WriteProtected.\r
+    // Since not all device support this command, so skip if fail.\r
+    //\r
+    UsbScsiModeSense (UsbMass);\r
+  }\r
 \r
 \r
-  return Status;\r
+  return UsbBootReadCapacity (UsbMass);\r
 }\r
 \r
 \r
 }\r
 \r
 \r
@@ -699,7 +710,7 @@ UsbBootDetectMedia (
   CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *) (UsbMass->Context))->InterfaceSubClass;\r
 \r
   Status = UsbBootIsUnitReady (UsbMass);\r
   CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *) (UsbMass->Context))->InterfaceSubClass;\r
 \r
   Status = UsbBootIsUnitReady (UsbMass);\r
-  if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {\r
+  if (EFI_ERROR (Status)) {\r
     goto ON_ERROR;\r
   }\r
 \r
     goto ON_ERROR;\r
   }\r
 \r