]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmRealViewEbPkg/Bds/FirmwareVolume.c
Remove ArmEbPkg and replace with ArmRealViewEbPkg. Ported ArmRealViewEbPkg to have...
[mirror_edk2.git] / ArmRealViewEbPkg / Bds / FirmwareVolume.c
diff --git a/ArmRealViewEbPkg/Bds/FirmwareVolume.c b/ArmRealViewEbPkg/Bds/FirmwareVolume.c
new file mode 100755 (executable)
index 0000000..142095f
--- /dev/null
@@ -0,0 +1,150 @@
+/** @file\r
+  The entry of the embedded BDS. This BDS does not follow the Boot Manager requirements \r
+  of the UEFI specification as it is designed to implement an embedded systmes \r
+  propriatary boot scheme.\r
+\r
+  This template assume a DXE driver produces a SerialIo protocol not using the EFI \r
+  driver module and it will attempt to connect a console on top of this.\r
+\r
+  \r
+  Copyright (c) 2009, Apple Inc. All rights reserved.<BR>\r
+  \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
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "BdsEntry.h"\r
+\r
+\r
+EFI_STATUS\r
+FindApplicationMatchingUiSection (\r
+  IN  CHAR16      *UiString,\r
+  OUT EFI_HANDLE  *FvHandle,\r
+  OUT EFI_GUID    *NameGuid\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_STATUS                    NextStatus;\r
+  UINTN                         NoHandles;\r
+  EFI_HANDLE                    *Buffer;\r
+  UINTN                         Index;\r
+  EFI_FV_FILETYPE               FileType;\r
+  EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
+  VOID                          *Key;\r
+  EFI_FV_FILE_ATTRIBUTES        Attributes;\r
+  UINTN                         Size;\r
+  UINTN                         UiStringLen;\r
+  CHAR16                        *UiSection;\r
+  UINT32                        Authentication;\r
+  \r
+  \r
+  UiStringLen = 0;\r
+  if (UiString != NULL) {\r
+    DEBUG ((DEBUG_ERROR, "UiString %s\n", UiString));\r
+    UiStringLen = StrLen (UiString);\r
+  }\r
+  \r
+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Buffer);\r
+  if (!EFI_ERROR (Status)) {\r
+    for (Index = 0; Index < NoHandles; Index++) {\r
+      Status = gBS->HandleProtocol (Buffer[Index], &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);\r
+      if (!EFI_ERROR (Status)) {\r
+        Key = AllocatePool (Fv->KeySize);\r
+        ASSERT (Key != NULL);\r
+        ZeroMem (Key, Fv->KeySize);\r
+        \r
+        FileType = EFI_FV_FILETYPE_APPLICATION;\r
+        \r
+        do {\r
+          NextStatus = Fv->GetNextFile (Fv, Key, &FileType, NameGuid, &Attributes, &Size);\r
+          if (!EFI_ERROR (NextStatus)) {\r
+            if (UiString == NULL) {\r
+              //\r
+              // If UiString is NULL match first application we find.\r
+              //\r
+              *FvHandle = Buffer[Index];\r
+              FreePool (Key);\r
+              return Status;\r
+            }\r
+            \r
+            UiSection = NULL;\r
+            Status = Fv->ReadSection (\r
+                          Fv, \r
+                          NameGuid, \r
+                          EFI_SECTION_USER_INTERFACE, \r
+                          0,\r
+                          (VOID **)&UiSection,\r
+                          &Size,\r
+                          &Authentication\r
+                          );\r
+            if (!EFI_ERROR (Status)) {\r
+              if (StrnCmp (UiString, UiSection, UiStringLen) == 0) {\r
+                //\r
+                // We found a UiString match. \r
+                //\r
+                *FvHandle = Buffer[Index];\r
+                FreePool (Key);\r
+                FreePool (UiSection);\r
+                return Status;\r
+              }\r
+              FreePool (UiSection);\r
+            }\r
+          }\r
+        } while (!EFI_ERROR (NextStatus));\r
+        \r
+        FreePool (Key);\r
+      }\r
+    }\r
+    \r
+    FreePool (Buffer);\r
+   }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+\r
+EFI_DEVICE_PATH *\r
+FvFileDevicePath (\r
+  IN  EFI_HANDLE   FvHandle,\r
+  IN  EFI_GUID     *NameGuid\r
+  )\r
+{ \r
+  EFI_DEVICE_PATH_PROTOCOL          *DevicePath;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH NewNode;\r
+\r
+  DevicePath = DevicePathFromHandle (FvHandle);\r
+\r
+  EfiInitializeFwVolDevicepathNode (&NewNode, NameGuid);\r
+  \r
+  return AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&NewNode);\r
+}\r
+\r
+\r
+\r
+EFI_STATUS\r
+LoadPeCoffSectionFromFv (\r
+ IN  EFI_HANDLE   FvHandle,  \r
+ IN  EFI_GUID     *NameGuid\r
+ )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+  EFI_HANDLE                    ImageHandle;\r
+\r
+  DevicePath = FvFileDevicePath (FvHandle, NameGuid);\r
+    \r
+  Status = gBS->LoadImage (TRUE, gImageHandle, DevicePath, NULL, 0, &ImageHandle);\r
+  if (!EFI_ERROR (Status)) {\r
+    PERF_END (NULL, "BDS", NULL, 0);\r
+    Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
+  }\r
+  \r
+  return Status;\r
+}\r
\r