MdeModulePkg/EmmcDxe: Don't expose BlockIo interface for RPMB partition

This change is to avoid UEFI SCT failure as UEFI SCT has no knowledge
about how to accessing a EMMC RPMB partition.

The user needs to access RPMB partition should get access through
EFI_SD_MMC_PASS_THRU protocol with authentication key & mac.

Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
index d3602a5..5040882 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
@@ -443,77 +443,60 @@
     //

     // Install BlkIo/BlkIo2/Ssp for the specified partition

     //

-    Status = gBS->InstallMultipleProtocolInterfaces (

-                    &Partition->Handle,

-                    &gEfiDevicePathProtocolGuid,

-                    Partition->DevicePath,

-                    &gEfiBlockIoProtocolGuid,

-                    &Partition->BlockIo,

-                    &gEfiBlockIo2ProtocolGuid,

-                    &Partition->BlockIo2,

-                    NULL

-                    );

-    if (EFI_ERROR (Status)) {

-      goto Error;

-    }

-

     if (Partition->PartitionType != EmmcPartitionRPMB) {

-      Status = gBS->InstallProtocolInterface (

+      Status = gBS->InstallMultipleProtocolInterfaces (

                       &Partition->Handle,

+                      &gEfiDevicePathProtocolGuid,

+                      Partition->DevicePath,

+                      &gEfiBlockIoProtocolGuid,

+                      &Partition->BlockIo,

+                      &gEfiBlockIo2ProtocolGuid,

+                      &Partition->BlockIo2,

                       &gEfiEraseBlockProtocolGuid,

-                      EFI_NATIVE_INTERFACE,

-                      &Partition->EraseBlock

+                      &Partition->EraseBlock,

+                      NULL

                       );

       if (EFI_ERROR (Status)) {

-        gBS->UninstallMultipleProtocolInterfaces (

-               &Partition->Handle,

-               &gEfiDevicePathProtocolGuid,

-               Partition->DevicePath,

-               &gEfiBlockIoProtocolGuid,

-               &Partition->BlockIo,

-               &gEfiBlockIo2ProtocolGuid,

-               &Partition->BlockIo2,

-               NULL

-               );

         goto Error;

       }

-    }

 

-    if (((Partition->PartitionType == EmmcPartitionUserData) ||

-        (Partition->PartitionType == EmmcPartitionBoot1) ||

-        (Partition->PartitionType == EmmcPartitionBoot2)) &&

-        ((Device->Csd.Ccc & BIT10) != 0)) {

-      Status = gBS->InstallProtocolInterface (

-                      &Partition->Handle,

-                      &gEfiStorageSecurityCommandProtocolGuid,

-                      EFI_NATIVE_INTERFACE,

-                      &Partition->StorageSecurity

-                      );

-      if (EFI_ERROR (Status)) {

-        gBS->UninstallMultipleProtocolInterfaces (

-               &Partition->Handle,

-               &gEfiDevicePathProtocolGuid,

-               Partition->DevicePath,

-               &gEfiBlockIoProtocolGuid,

-               &Partition->BlockIo,

-               &gEfiBlockIo2ProtocolGuid,

-               &Partition->BlockIo2,

-               &gEfiEraseBlockProtocolGuid,

-               &Partition->EraseBlock,

-               NULL

-               );

-        goto Error;

+      if (((Partition->PartitionType == EmmcPartitionUserData) ||

+          (Partition->PartitionType == EmmcPartitionBoot1) ||

+          (Partition->PartitionType == EmmcPartitionBoot2)) &&

+          ((Device->Csd.Ccc & BIT10) != 0)) {

+        Status = gBS->InstallProtocolInterface (

+                        &Partition->Handle,

+                        &gEfiStorageSecurityCommandProtocolGuid,

+                        EFI_NATIVE_INTERFACE,

+                        &Partition->StorageSecurity

+                        );

+        if (EFI_ERROR (Status)) {

+          gBS->UninstallMultipleProtocolInterfaces (

+                 &Partition->Handle,

+                 &gEfiDevicePathProtocolGuid,

+                 Partition->DevicePath,

+                 &gEfiBlockIoProtocolGuid,

+                 &Partition->BlockIo,

+                 &gEfiBlockIo2ProtocolGuid,

+                 &Partition->BlockIo2,

+                 &gEfiEraseBlockProtocolGuid,

+                 &Partition->EraseBlock,

+                 NULL

+                 );

+          goto Error;

+        }

       }

+

+      gBS->OpenProtocol (

+             Device->Private->Controller,

+             &gEfiSdMmcPassThruProtocolGuid,

+             (VOID **) &(Device->Private->PassThru),

+             Device->Private->DriverBindingHandle,

+             Partition->Handle,

+             EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER

+             );    

     }

 

-    gBS->OpenProtocol (

-           Device->Private->Controller,

-           &gEfiSdMmcPassThruProtocolGuid,

-           (VOID **) &(Device->Private->PassThru),

-           Device->Private->DriverBindingHandle,

-           Partition->Handle,

-           EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER

-           );

   } else {

     Status = EFI_INVALID_PARAMETER;

   }

@@ -993,7 +976,6 @@
   EFI_BLOCK_IO_PROTOCOL                  *BlockIo;

   EFI_BLOCK_IO2_PROTOCOL                 *BlockIo2;

   EFI_STORAGE_SECURITY_COMMAND_PROTOCOL  *StorageSecurity;

-  EFI_ERASE_BLOCK_PROTOCOL               *EraseBlock;

   LIST_ENTRY                             *Link;

   LIST_ENTRY                             *NextLink;

   EMMC_REQUEST                           *Request;

@@ -1120,6 +1102,8 @@
                     &Partition->BlockIo,

                     &gEfiBlockIo2ProtocolGuid,

                     &Partition->BlockIo2,

+                    &gEfiEraseBlockProtocolGuid,

+                    &Partition->EraseBlock,

                     NULL

                     );

     if (EFI_ERROR (Status)) {

@@ -1136,38 +1120,6 @@
     }

 

     //

-    // If Erase Block Protocol is installed, then uninstall this protocol.

-    //

-    Status = gBS->OpenProtocol (

-                    ChildHandleBuffer[Index],

-                    &gEfiEraseBlockProtocolGuid,

-                    (VOID **) &EraseBlock,

-                    This->DriverBindingHandle,

-                    Controller,

-                    EFI_OPEN_PROTOCOL_GET_PROTOCOL

-                    );

-

-    if (!EFI_ERROR (Status)) {

-      Status = gBS->UninstallProtocolInterface (

-                      ChildHandleBuffer[Index],

-                      &gEfiEraseBlockProtocolGuid,

-                      &Partition->EraseBlock

-                      );

-      if (EFI_ERROR (Status)) {

-        gBS->OpenProtocol (

-          Controller,

-          &gEfiSdMmcPassThruProtocolGuid,

-          (VOID **) &Partition->Device->Private->PassThru,

-          This->DriverBindingHandle,

-          ChildHandleBuffer[Index],

-          EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER

-          );

-        AllChildrenStopped = FALSE;

-        continue;

-      }

-    }

-

-    //

     // If Storage Security Command Protocol is installed, then uninstall this protocol.

     //

     Status = gBS->OpenProtocol (