Remove probe for removable media from FileLib, it was getting called way too much. Now it is in the EBL shell device command. Cleanup some spacing issues in the lib code.


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10454 6f19259b-4bc3-4df7-8a09-765794883524
diff --git a/EmbeddedPkg/Ebl/Ebl.h b/EmbeddedPkg/Ebl/Ebl.h
index b1931a4..04f75d0 100644
--- a/EmbeddedPkg/Ebl/Ebl.h
+++ b/EmbeddedPkg/Ebl/Ebl.h
@@ -51,6 +51,7 @@
 #include <Library/DevicePathLib.h>
 #include <Library/UefiLib.h>
 #include <Library/EblNetworkLib.h>
+#include <Library/TimerLib.h>
 
 #include <IndustryStandard/Pci.h>
 
diff --git a/EmbeddedPkg/Ebl/EfiDevice.c b/EmbeddedPkg/Ebl/EfiDevice.c
index 9b08fda..70ba703 100644
--- a/EmbeddedPkg/Ebl/EfiDevice.c
+++ b/EmbeddedPkg/Ebl/EfiDevice.c
@@ -210,12 +210,34 @@
   UINTN         Index;

   UINTN         CurrentRow;

   UINTN         Max;

+  EFI_OPEN_FILE *File;

 

   CurrentRow = 0;

   

   // Need to call here to make sure Device Counts are valid

   EblUpdateDeviceLists ();

 

+  //

+  // Probe for media insertion/removal in removable media devices

+  //

+  Max = EfiGetDeviceCounts (EfiOpenBlockIo);

+  if (Max != 0) {

+    for (Index = 0; Index < Max; Index++) {

+      File = EfiDeviceOpenByType (EfiOpenBlockIo, Index);

+      if (File != NULL) {

+        if (File->FsBlockIoMedia->RemovableMedia) {

+          if (File->FsBlockIoMedia->MediaPresent) {

+            gBS->DisconnectController (File->EfiHandle, NULL, NULL);

+          }

+          gBS->ConnectController (File->EfiHandle, NULL, NULL, TRUE);

+        }

+        EfiClose (File);

+      }

+    }

+  }

+

+  // Now we can print out the info...

+

   Max = EfiGetDeviceCounts (EfiOpenFirmwareVolume);

   if (Max != 0) {

     AsciiPrint ("Firmware Volume Devices:\n");

@@ -730,7 +752,7 @@
   UINTN         Size;

   UINTN         Offset;

   UINTN         Chunk = FILE_COPY_CHUNK;

-  

+

   if (Argc < 3) {

     return EFI_INVALID_PARAMETER;

   }

@@ -759,13 +781,13 @@
     

     Status = EfiRead(Source, Buffer, &Chunk);

     if (EFI_ERROR(Status)) {

-      AsciiPrint("Read file error\n");

+      AsciiPrint("Read file error %r\n", Status);

       goto Exit;

     }

 

     Status = EfiWrite(Destination, Buffer, &Chunk);

     if (EFI_ERROR(Status)) {

-      AsciiPrint("Write file error\n");

+      AsciiPrint("Write file error %r\n", Status);

       goto Exit;

     }    

   }

@@ -776,17 +798,18 @@
     

     Status = EfiRead(Source, Buffer, &Chunk);

     if (EFI_ERROR(Status)) {

-      AsciiPrint("Read file error\n");

+      AsciiPrint("Read file error %r\n", Status);

       goto Exit;

     }

 

     Status = EfiWrite(Destination, Buffer, &Chunk);

     if (EFI_ERROR(Status)) {

-      AsciiPrint("Write file error\n");

+      AsciiPrint("Write file error %r\n", Status);

       goto Exit;

     }    

   }

 

+

 Exit:

   if (Source != NULL) {

     Status = EfiClose(Source);

@@ -794,7 +817,6 @@
       AsciiPrint("Source close error %r\n", Status);

     }

   }

-  

   if (Destination != NULL) {

     Status = EfiClose(Destination);

     if (EFI_ERROR(Status)) {

diff --git a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c b/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c
index 8ef0790..1db7d7d 100644
--- a/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c
+++ b/EmbeddedPkg/Library/EfiFileLib/EfiFileLib.c
@@ -100,8 +100,8 @@
 **/
 BOOLEAN
 FileHandleValid (
-                 IN EFI_OPEN_FILE  *File
-                 )
+  IN EFI_OPEN_FILE  *File
+  )
 {
   EFI_OPEN_FILE_GUARD  *GuardFile;
 
@@ -123,8 +123,8 @@
 **/
 VOID
 EblFreePool (
-             IN  VOID  *Buffer
-             )
+  IN  VOID  *Buffer
+  )
 {
   if (Buffer != NULL) {
     FreePool (Buffer);
@@ -137,45 +137,20 @@
 **/
 VOID
 EblUpdateDeviceLists (
-                      VOID
-                      )
+  VOID
+  )
 {
   EFI_STATUS                        Status;
   UINTN                             Size;
   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Fs;
-  EFI_BLOCK_IO_PROTOCOL             *BlkIo;
   EFI_FILE_HANDLE                   Root;
   UINTN                             Index;
-  BOOLEAN                           Update;
 
   if (mBlkIo != NULL) {
     FreePool (mBlkIo);
   }
   gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);
 
-  //
-  // This is a trick to trigger the gBS->ReinstallProtocolInterface () in a removable media 
-  // device to make a filesystem layer on. Probing devices will detect if media has been 
-  // inserted and create 
-  //
-  for (Index =0, Update = FALSE; Index < mBlkIoCount; Index++) {
-    Status = gBS->HandleProtocol (mBlkIo[Index], &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);
-    if (!EFI_ERROR (Status)) {
-      if (BlkIo->Media->RemovableMedia) {
-        gBS->DisconnectController (mBlkIo[Index], NULL, NULL);
-        gBS->ConnectController (mBlkIo[Index], NULL, NULL, TRUE);
-        Update = TRUE;
-      }
-    }
-  }
-
-  if (Update) {
-    // In case we caused media to be detected that contains a partition (SD Card, ...) rescan
-    if (mBlkIo != NULL) {
-      FreePool (mBlkIo);
-    }
-    gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);
-  }
 
 
   if (mFv != NULL) {
@@ -248,10 +223,10 @@
 **/
 BOOLEAN
 EblMatchVolumeName (
-                    IN  CHAR8   *PathName,
-                    IN  UINTN   FileStart,
-                    OUT UINTN   *MatchIndex
-                    )
+  IN  CHAR8   *PathName,
+  IN  UINTN   FileStart,
+  OUT UINTN   *MatchIndex
+  )
 {
   UINTN   Index;
   UINTN   Compare;
@@ -297,8 +272,8 @@
 **/
 UINTN
 EfiGetDeviceCounts (
-                    IN  EFI_OPEN_FILE_TYPE     DeviceType
-                    )
+  IN  EFI_OPEN_FILE_TYPE     DeviceType
+  )
 {
   switch (DeviceType) {
   case EfiOpenLoadFile:
@@ -316,9 +291,9 @@
 
 EFI_STATUS
 ConvertIpStringToEfiIp (
-                        IN  CHAR8           *PathName, 
-                        OUT EFI_IP_ADDRESS  *ServerIp
-                        )
+  IN  CHAR8           *PathName, 
+  OUT EFI_IP_ADDRESS  *ServerIp
+  )
 {
   CHAR8     *Str;
 
@@ -362,8 +337,8 @@
 **/
 UINTN
 EblConvertDevStringToNumber (
-                             IN  CHAR8   *Str
-                             )
+  IN  CHAR8   *Str
+  )
 {
   UINTN   Max;
   UINTN   Index;
@@ -392,10 +367,10 @@
 **/
 EFI_STATUS
 EblFileDevicePath (
-                   IN OUT EFI_OPEN_FILE  *File,
-                   IN  CHAR8             *FileName,
-                   IN  CONST UINT64      OpenMode
-                   )
+  IN OUT EFI_OPEN_FILE  *File,
+  IN  CHAR8             *FileName,
+  IN  CONST UINT64      OpenMode
+  )
 {
   EFI_STATUS                        Status;
   UINTN                             Size;
@@ -481,9 +456,9 @@
 
 EFI_STATUS
 CompareGuidToString (
-                     IN  EFI_GUID    *Guid,
-                     IN  CHAR8       *String
-                     )
+  IN  EFI_GUID    *Guid,
+  IN  CHAR8       *String
+  )
 {
   CHAR8       AsciiGuid[64];
   CHAR8       *StringPtr;
@@ -528,10 +503,10 @@
 **/
 EFI_STATUS
 EblFvFileDevicePath (
-                     IN OUT EFI_OPEN_FILE  *File,
-                     IN  CHAR8             *FileName,
-                     IN  CONST UINT64      OpenMode
-                     )
+  IN OUT EFI_OPEN_FILE  *File,
+  IN  CHAR8             *FileName,
+  IN  CONST UINT64      OpenMode
+  )
 {
   EFI_STATUS                          Status;
   EFI_STATUS                          GetNextFileStatus;
@@ -678,10 +653,10 @@
 **/
 EFI_OPEN_FILE *
 EfiOpen (
-         IN        CHAR8               *PathName,
-         IN  CONST UINT64              OpenMode,
-         IN  CONST EFI_SECTION_TYPE    SectionType
-         )
+  IN        CHAR8               *PathName,
+  IN  CONST UINT64              OpenMode,
+  IN  CONST EFI_SECTION_TYPE    SectionType
+  )
 {
   EFI_STATUS                Status;
   EFI_OPEN_FILE             *File;
@@ -937,9 +912,9 @@
 
 EFI_STATUS
 EfiCopyFile (
-             IN        CHAR8               *DestinationFile,
-             IN        CHAR8               *SourceFile
-             )
+  IN        CHAR8               *DestinationFile,
+  IN        CHAR8               *SourceFile
+  )
 {
   EFI_OPEN_FILE *Source      = NULL;
   EFI_OPEN_FILE *Destination = NULL;
@@ -976,13 +951,13 @@
 
     Status = EfiRead(Source, Buffer, &Chunk);
     if (EFI_ERROR(Status)) {
-      AsciiPrint("Read file error\n");
+      AsciiPrint("Read file error %r\n", Status);
       goto Exit;
     }
 
     Status = EfiWrite(Destination, Buffer, &Chunk);
     if (EFI_ERROR(Status)) {
-      AsciiPrint("Write file error\n");
+      AsciiPrint("Write file error %r\n", Status);
       goto Exit;
     }    
   }
@@ -1038,9 +1013,9 @@
 **/
 EFI_OPEN_FILE  *
 EfiDeviceOpenByType (
-                     IN  EFI_OPEN_FILE_TYPE    DeviceType,
-                     IN  UINTN                 Index
-                     )
+  IN  EFI_OPEN_FILE_TYPE    DeviceType,
+  IN  UINTN                 Index
+  )
 {
   CHAR8   *DevStr;
   CHAR8   Path[MAX_CMD_LINE];
@@ -1083,8 +1058,8 @@
 **/
 EFI_STATUS
 EfiClose (
-          IN  EFI_OPEN_FILE     *File
-          )
+  IN  EFI_OPEN_FILE     *File
+  )
 {
   EFI_STATUS          Status;
   UINT64              TftpBufferSize;
@@ -1117,21 +1092,21 @@
   if ((File->Type == EfiOpenLoadFile) || 
     ((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) ||
     ((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) {
-      EblFreePool(File->Buffer);
-    }
+    EblFreePool(File->Buffer);
+  }
 
-    EblFreePool (File->DevicePath);
-    EblFreePool (File->DeviceName);
-    EblFreePool (File->FsFileInfo);
-    EblFreePool (File->FsInfo);
+  EblFreePool (File->DevicePath);
+  EblFreePool (File->DeviceName);
+  EblFreePool (File->FsFileInfo);
+  EblFreePool (File->FsInfo);
 
-    if (File->FsFileHandle != NULL) {
-      File->FsFileHandle->Close (File->FsFileHandle);
-    }
+  if (File->FsFileHandle != NULL) {
+    File->FsFileHandle->Close (File->FsFileHandle);
+  }
 
-    // Need to free File and it's Guard structures
-    EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));
-    return EFI_SUCCESS;
+  // Need to free File and it's Guard structures
+  EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));
+  return EFI_SUCCESS;
 }
 
 
@@ -1147,9 +1122,9 @@
 **/
 UINTN
 EfiTell (
-         IN  EFI_OPEN_FILE     *File,
-         OUT EFI_LBA           *CurrentPosition    OPTIONAL
-         )
+  IN  EFI_OPEN_FILE     *File,
+  OUT EFI_LBA           *CurrentPosition    OPTIONAL
+  )
 {
   EFI_STATUS Status;
   UINT64     BufferSize = 0;
@@ -1221,10 +1196,10 @@
 **/
 EFI_STATUS
 EfiSeek (
-         IN  EFI_OPEN_FILE     *File,
-         IN  EFI_LBA           Offset,
-         IN  EFI_SEEK_TYPE     SeekType
-         )
+  IN  EFI_OPEN_FILE     *File,
+  IN  EFI_LBA           Offset,
+  IN  EFI_SEEK_TYPE     SeekType
+  )
 {
   EFI_STATUS    Status;
   UINT64        CurrentPosition;
@@ -1280,8 +1255,8 @@
 
 EFI_STATUS
 CacheTftpFile (
-               IN OUT  EFI_OPEN_FILE *File
-               )
+  IN OUT  EFI_OPEN_FILE *File
+  )
 {
   EFI_STATUS          Status;
   UINT64              TftpBufferSize;
@@ -1341,10 +1316,10 @@
 **/
 EFI_STATUS
 EfiRead (
-         IN  EFI_OPEN_FILE       *File,
-         OUT VOID                *Buffer,
-         OUT UINTN               *BufferSize
-         )
+  IN  EFI_OPEN_FILE       *File,
+  OUT VOID                *Buffer,
+  OUT UINTN               *BufferSize
+  )
 {
   EFI_STATUS            Status;
   UINT32                AuthenticationStatus;
@@ -1472,10 +1447,10 @@
 **/
 EFI_STATUS
 EfiReadAllocatePool (
-                     IN  EFI_OPEN_FILE     *File,
-                     OUT VOID              **Buffer,
-                     OUT UINTN             *BufferSize
-                     )
+  IN  EFI_OPEN_FILE     *File,
+  OUT VOID              **Buffer,
+  OUT UINTN             *BufferSize
+  )
 {
   if (!FileHandleValid (File)) {
     return EFI_INVALID_PARAMETER;
@@ -1511,10 +1486,10 @@
 **/
 EFI_STATUS
 EfiWrite (
-          IN  EFI_OPEN_FILE   *File,
-          OUT VOID            *Buffer,
-          OUT UINTN           *BufferSize
-          )
+  IN  EFI_OPEN_FILE   *File,
+  OUT VOID            *Buffer,
+  OUT UINTN           *BufferSize
+  )
 {
   EFI_STATUS              Status;
   EFI_FV_WRITE_FILE_DATA  FileData;
@@ -1628,9 +1603,9 @@
 **/
 CHAR8 *
 ExpandPath (
-            IN CHAR8    *Cwd,
-            IN CHAR8    *Path
-            )
+  IN CHAR8    *Cwd,
+  IN CHAR8    *Path
+  )
 {
   CHAR8   *NewPath;
   CHAR8   *Work, *Start, *End;
@@ -1705,8 +1680,8 @@
 **/
 EFI_STATUS
 EfiSetCwd (
-           IN  CHAR8   *Cwd
-           ) 
+  IN  CHAR8   *Cwd
+  ) 
 {
   EFI_OPEN_FILE *File;
   UINTN         Len;
@@ -1781,8 +1756,8 @@
 **/
 CHAR8 *
 EfiGetCwd (
-           VOID
-           )
+  VOID
+  )
 {
   if (gCwd == NULL) {
     return "";