]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Ebl/EfiDevice.c
Fix bug in LoadFv command. Don't free the buffer the file was loaded into as the...
[mirror_edk2.git] / EmbeddedPkg / Ebl / EfiDevice.c
index 7633d669345c49207dce32cee2c77c4a56bfd412..dafe0c9a05935b1a4eedfd0039e00e2bd0645e36 100644 (file)
@@ -1,10 +1,10 @@
 /** @file\r
   EBL commands for EFI and PI Devices\r
 \r
-  Copyright (c) 2007, Intel Corporation<BR>\r
-  Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
+  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 \r
-  All rights reserved. This program and the accompanying materials\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
   http://opensource.org/licenses/bsd-license.php\r
@@ -31,13 +31,22 @@ EblPrintFsInfo (
   IN  EFI_OPEN_FILE   *File\r
   )\r
 {\r
+  CHAR16 *Str;\r
+\r
   if (File == NULL) {\r
     return;\r
   }\r
 \r
   AsciiPrint ("  %a: ", File->DeviceName);\r
   if (File->FsInfo != NULL) {\r
-    AsciiPrint ("%s: ", File->FsInfo->VolumeLabel);\r
+    for (Str = File->FsInfo->VolumeLabel; *Str != '\0'; Str++) {\r
+      if (*Str == ' ') {\r
+        // UI makes you enter _ for space, so make the printout match that\r
+        *Str = '_';\r
+      }\r
+      AsciiPrint ("%c", *Str);\r
+    }\r
+    AsciiPrint (":");\r
     if (File->FsInfo->ReadOnly) {\r
       AsciiPrint ("ReadOnly");\r
     }\r
@@ -81,29 +90,48 @@ EblPrintBlkIoInfo (
   )\r
 {\r
   UINT64                    DeviceSize;\r
-\r
+  UINTN                     Index;\r
+  UINTN                     Max;\r
+  EFI_OPEN_FILE             *FsFile;\r
 \r
   if (File == NULL) {\r
     return;\r
   }\r
 \r
   AsciiPrint ("  %a: ", File->DeviceName);\r
-  if (File->FsBlockIoMedia.RemovableMedia) {\r
-    AsciiPrint ("Removable ");\r
+\r
+  // print out name of file system, if any, on this block device\r
+  Max = EfiGetDeviceCounts (EfiOpenFileSystem);\r
+  if (Max != 0) {\r
+    for (Index = 0; Index < Max; Index++) {\r
+      FsFile = EfiDeviceOpenByType (EfiOpenFileSystem, Index);\r
+      if (FsFile != NULL) {\r
+        if (FsFile->EfiHandle == File->EfiHandle) {\r
+          AsciiPrint ("fs%d: ", Index);\r
+          EfiClose (FsFile);\r
+          break;\r
+        }\r
+        EfiClose (FsFile);\r
+      }\r
+    }\r
   }\r
-  if (!File->FsBlockIoMedia.MediaPresent) {\r
-    AsciiPrint ("No Media ");\r
+\r
+  // Print out useful Block IO media properties\r
+  if (File->FsBlockIoMedia->RemovableMedia) {\r
+    AsciiPrint ("Removable ");\r
   }\r
-  if (File->FsBlockIoMedia.LogicalPartition) {\r
-    AsciiPrint ("Partition ");\r
+  if (!File->FsBlockIoMedia->MediaPresent) {\r
+    AsciiPrint ("No Media\n");\r
+  } else {\r
+    if (File->FsBlockIoMedia->LogicalPartition) {\r
+      AsciiPrint ("Partition ");\r
+    }\r
+    DeviceSize = MultU64x32 (File->FsBlockIoMedia->LastBlock + 1, File->FsBlockIoMedia->BlockSize);\r
+    AsciiPrint ("Size = 0x%lX\n", DeviceSize);\r
   }\r
-  DeviceSize = MultU64x32 (File->FsBlockIoMedia.LastBlock + 1, File->FsBlockIoMedia.BlockSize);\r
-  AsciiPrint ("Size = 0x%lX\n", DeviceSize);\r
-\r
   EfiClose (File);\r
 }\r
 \r
-\r
  /**\r
   Print information about the Load File devices.\r
   If the device supports PXE dump out extra information\r
@@ -184,10 +212,11 @@ EblDeviceCmd (
   UINTN         Max;\r
 \r
   CurrentRow = 0;\r
-  \r
+\r
   // Need to call here to make sure Device Counts are valid\r
   EblUpdateDeviceLists ();\r
 \r
+  // Now we can print out the info...\r
   Max = EfiGetDeviceCounts (EfiOpenFirmwareVolume);\r
   if (Max != 0) {\r
     AsciiPrint ("Firmware Volume Devices:\n");\r
@@ -374,7 +403,9 @@ EblLoadFvCmd (
     }\r
       \r
     Status = gDS->ProcessFirmwareVolume (FvStart, FvSize, &FvHandle);\r
-    FreePool (FvStart);\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (FvStart);\r
+    } \r
   }\r
   return Status;\r
 }\r
@@ -702,7 +733,7 @@ EblFileCopyCmd (
   UINTN         Size;\r
   UINTN         Offset;\r
   UINTN         Chunk = FILE_COPY_CHUNK;\r
-  \r
+\r
   if (Argc < 3) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -731,13 +762,13 @@ EblFileCopyCmd (
     \r
     Status = EfiRead(Source, Buffer, &Chunk);\r
     if (EFI_ERROR(Status)) {\r
-      AsciiPrint("Read file error\n");\r
+      AsciiPrint("Read file error %r\n", Status);\r
       goto Exit;\r
     }\r
 \r
     Status = EfiWrite(Destination, Buffer, &Chunk);\r
     if (EFI_ERROR(Status)) {\r
-      AsciiPrint("Write file error\n");\r
+      AsciiPrint("Write file error %r\n", Status);\r
       goto Exit;\r
     }    \r
   }\r
@@ -748,17 +779,18 @@ EblFileCopyCmd (
     \r
     Status = EfiRead(Source, Buffer, &Chunk);\r
     if (EFI_ERROR(Status)) {\r
-      AsciiPrint("Read file error\n");\r
+      AsciiPrint("Read file error %r\n", Status);\r
       goto Exit;\r
     }\r
 \r
     Status = EfiWrite(Destination, Buffer, &Chunk);\r
     if (EFI_ERROR(Status)) {\r
-      AsciiPrint("Write file error\n");\r
+      AsciiPrint("Write file error %r\n", Status);\r
       goto Exit;\r
     }    \r
   }\r
 \r
+\r
 Exit:\r
   if (Source != NULL) {\r
     Status = EfiClose(Source);\r
@@ -766,7 +798,6 @@ Exit:
       AsciiPrint("Source close error %r\n", Status);\r
     }\r
   }\r
-  \r
   if (Destination != NULL) {\r
     Status = EfiClose(Destination);\r
     if (EFI_ERROR(Status)) {\r