[edk2] [PATCH] MdeModulePkg/UsbStorage: Fix "map -r" cannot detect media change

Ruiyu Ni posted 1 patch 6 years, 2 months ago
Failed in applying to current master (apply log)
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
[edk2] [PATCH] MdeModulePkg/UsbStorage: Fix "map -r" cannot detect media change
Posted by Ruiyu Ni 6 years, 2 months ago
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>
Cc: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] MdeModulePkg/UsbStorage: Fix "map -r" cannot detect media change
Posted by Zeng, Star 6 years, 2 months ago
Reviewed-by: Star Zeng <star.zeng@intel.com>

Thanks,
Star
-----Original Message-----
From: Ni, Ruiyu 
Sent: Friday, January 19, 2018 3:05 PM
To: edk2-devel@lists.01.org
Cc: Tian, Feng <feng.tian@intel.com>; Zeng, Star <star.zeng@intel.com>
Subject: [PATCH] MdeModulePkg/UsbStorage: Fix "map -r" cannot detect media change

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>
Cc: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel