]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootOptionSupport.c
ArmPlatformPkg: Print arguments for EFI Application
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootOptionSupport.c
index f16de7c82dc3df6877edca7db28deca91a8c9397..dc70dc4a1efbd22a9a6aebc41bbddc5d43fecf05 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
 *\r
 *  This program and the accompanying materials\r
 *  are licensed and made available under the terms and conditions of the BSD License\r
@@ -34,9 +34,8 @@ BdsLoadOptionFileSystemList (
 EFI_STATUS\r
 BdsLoadOptionFileSystemCreateDevicePath (\r
   IN CHAR16*                    FileName,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes,\r
+  OUT BOOLEAN                   *RequestBootType\r
   );\r
 \r
 EFI_STATUS\r
@@ -44,8 +43,7 @@ BdsLoadOptionFileSystemUpdateDevicePath (
   IN EFI_DEVICE_PATH            *OldDevicePath,\r
   IN CHAR16*                    FileName,\r
   OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT BOOLEAN                   *RequestBootType\r
   );\r
 \r
 BOOLEAN\r
@@ -61,9 +59,8 @@ BdsLoadOptionMemMapList (
 EFI_STATUS\r
 BdsLoadOptionMemMapCreateDevicePath (\r
   IN CHAR16*                    FileName,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes,\r
+  OUT BOOLEAN                   *RequestBootType\r
   );\r
 \r
 EFI_STATUS\r
@@ -71,8 +68,7 @@ BdsLoadOptionMemMapUpdateDevicePath (
   IN EFI_DEVICE_PATH            *OldDevicePath,\r
   IN CHAR16*                    FileName,\r
   OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT BOOLEAN                   *RequestBootType\r
   );\r
 \r
 BOOLEAN\r
@@ -88,9 +84,8 @@ BdsLoadOptionPxeList (
 EFI_STATUS\r
 BdsLoadOptionPxeCreateDevicePath (\r
   IN CHAR16*                    FileName,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes,\r
+  OUT BOOLEAN                   *RequestBootType\r
   );\r
 \r
 EFI_STATUS\r
@@ -98,8 +93,7 @@ BdsLoadOptionPxeUpdateDevicePath (
   IN EFI_DEVICE_PATH            *OldDevicePath,\r
   IN CHAR16*                    FileName,\r
   OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT BOOLEAN                   *RequestBootType\r
   );\r
 \r
 BOOLEAN\r
@@ -115,9 +109,8 @@ BdsLoadOptionTftpList (
 EFI_STATUS\r
 BdsLoadOptionTftpCreateDevicePath (\r
   IN CHAR16*                    FileName,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes,\r
+  OUT BOOLEAN                   *RequestBootType\r
   );\r
 \r
 EFI_STATUS\r
@@ -125,8 +118,7 @@ BdsLoadOptionTftpUpdateDevicePath (
   IN EFI_DEVICE_PATH            *OldDevicePath,\r
   IN CHAR16*                    FileName,\r
   OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT BOOLEAN                   *RequestBootType\r
   );\r
 \r
 BOOLEAN\r
@@ -222,18 +214,44 @@ BootDeviceGetDeviceSupport (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 BootDeviceGetType (\r
-  IN  CHAR16* FileName,\r
+  IN  EFI_DEVICE_PATH* DevicePath,\r
   OUT ARM_BDS_LOADER_TYPE *BootType,\r
   OUT UINT32 *Attributes\r
   )\r
 {\r
-  EFI_STATUS Status;\r
-  BOOLEAN IsEfiApp;\r
-  BOOLEAN IsBootLoader;\r
-  BOOLEAN     HasFDTSupport;\r
+  EFI_STATUS              Status;\r
+  BOOLEAN                 IsEfiApp;\r
+  BOOLEAN                 IsBootLoader;\r
+  BOOLEAN                 HasFDTSupport;\r
+  CHAR16*                 FileName;\r
+  EFI_DEVICE_PATH*        PrevDevicePathNode;\r
+  EFI_DEVICE_PATH*        DevicePathNode;\r
+  EFI_PHYSICAL_ADDRESS    Image;\r
+  UINTN                   FileSize;\r
+  EFI_IMAGE_DOS_HEADER*   DosHeader;\r
+  UINTN                   PeCoffHeaderOffset;\r
+  EFI_IMAGE_NT_HEADERS32* NtHeader;\r
+\r
+  //\r
+  // Check if the last node of the device path is a FilePath node\r
+  //\r
+  PrevDevicePathNode = NULL;\r
+  DevicePathNode = DevicePath;\r
+  while ((DevicePathNode != NULL) && !IsDevicePathEnd (DevicePathNode)) {\r
+    PrevDevicePathNode = DevicePathNode;\r
+    DevicePathNode = NextDevicePathNode (DevicePathNode);\r
+  }\r
+\r
+  if ((PrevDevicePathNode != NULL) &&\r
+      (PrevDevicePathNode->Type == MEDIA_DEVICE_PATH) &&\r
+      (PrevDevicePathNode->SubType == MEDIA_FILEPATH_DP))\r
+  {\r
+    FileName = ((FILEPATH_DEVICE_PATH*)PrevDevicePathNode)->PathName;\r
+  } else {\r
+    FileName = NULL;\r
+  }\r
 \r
   if (FileName == NULL) {\r
     Print(L"Is an EFI Application? ");\r
@@ -244,7 +262,41 @@ BootDeviceGetType (
   } else if (HasFilePathEfiExtension(FileName)) {\r
     IsEfiApp = TRUE;\r
   } else {\r
-    IsEfiApp = FALSE;\r
+    // Check if the file exist\r
+    Status = BdsLoadImage (DevicePath, AllocateAnyPages, &Image, &FileSize);\r
+    if (!EFI_ERROR (Status)) {\r
+\r
+      DosHeader = (EFI_IMAGE_DOS_HEADER *)(UINTN) Image;\r
+      if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+        //\r
+        // DOS image header is present,\r
+        // so read the PE header after the DOS image header.\r
+        //\r
+        PeCoffHeaderOffset = DosHeader->e_lfanew;\r
+      } else {\r
+        PeCoffHeaderOffset = 0;\r
+      }\r
+\r
+      //\r
+      // Check PE/COFF image.\r
+      //\r
+      NtHeader = (EFI_IMAGE_NT_HEADERS32 *)(UINTN) (Image + PeCoffHeaderOffset);\r
+      if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
+        IsEfiApp = FALSE;\r
+      } else {\r
+        IsEfiApp = TRUE;\r
+      }\r
+\r
+      // Free memory\r
+      gBS->FreePages (Image, EFI_SIZE_TO_PAGES(FileSize));\r
+    } else {\r
+      // If we did not manage to open it then ask for the type\r
+      Print(L"Is an EFI Application? ");\r
+      Status = GetHIInputBoolean (&IsEfiApp);\r
+      if (EFI_ERROR(Status)) {\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
   }\r
 \r
   if (IsEfiApp) {\r
@@ -332,9 +384,8 @@ BdsLoadOptionFileSystemList (
 EFI_STATUS\r
 BdsLoadOptionFileSystemCreateDevicePath (\r
   IN CHAR16*                    FileName,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes,\r
+  OUT BOOLEAN                   *RequestBootType\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -350,26 +401,18 @@ BdsLoadOptionFileSystemCreateDevicePath (
 \r
   BootFilePathSize = StrSize (BootFilePath);\r
   if (BootFilePathSize == 2) {\r
-    *DevicePathNode = NULL;\r
+    *DevicePathNodes = NULL;\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
   // Create the FilePath Device Path node\r
-  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);\r
+  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH);\r
   FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH;\r
   FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP;\r
   SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);\r
   CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize);\r
-\r
-  if (BootType != NULL || Attributes != NULL) {\r
-    Status = BootDeviceGetType (FilePathDevicePath->PathName, BootType, Attributes);\r
-  }\r
-\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool (FilePathDevicePath);\r
-  } else {\r
-    *DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath;\r
-  }\r
+  SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize));\r
+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath;\r
 \r
   return Status;\r
 }\r
@@ -379,8 +422,7 @@ BdsLoadOptionFileSystemUpdateDevicePath (
   IN EFI_DEVICE_PATH            *OldDevicePath,\r
   IN CHAR16*                    FileName,\r
   OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT BOOLEAN                   *RequestBootType\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -390,7 +432,7 @@ BdsLoadOptionFileSystemUpdateDevicePath (
   FILEPATH_DEVICE_PATH* FilePathDevicePath;\r
   EFI_DEVICE_PATH*  DevicePath;\r
 \r
-  DevicePath = DuplicateDevicePath(OldDevicePath);\r
+  DevicePath = DuplicateDevicePath (OldDevicePath);\r
 \r
   EndingDevicePath = (FILEPATH_DEVICE_PATH*)GetLastDevicePathNode (DevicePath);\r
  \r
@@ -419,10 +461,6 @@ BdsLoadOptionFileSystemUpdateDevicePath (
   *NewDevicePath = AppendDevicePathNode (DevicePath, (CONST EFI_DEVICE_PATH_PROTOCOL *)FilePathDevicePath);\r
   FreePool(DevicePath);\r
 \r
-  if (BootType != NULL || Attributes != NULL) {\r
-    return BootDeviceGetType (FilePathDevicePath->PathName, BootType, Attributes);\r
-  }\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -533,9 +571,8 @@ BdsLoadOptionMemMapList (
 EFI_STATUS\r
 BdsLoadOptionMemMapCreateDevicePath (\r
   IN CHAR16*                    FileName,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes,\r
+  OUT BOOLEAN                   *RequestBootType\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -566,16 +603,7 @@ BdsLoadOptionMemMapCreateDevicePath (
 \r
   // Set a Device Path End Node after the Memory Map Device Path Node\r
   SetDevicePathEndNode (MemMapDevicePath + 1);\r
-\r
-  if (BootType != NULL || Attributes != NULL) {\r
-    Status = BootDeviceGetType (NULL, BootType, Attributes);\r
-  }\r
-\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool (MemMapDevicePath);\r
-  } else {\r
-    *DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath;\r
-  }\r
+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath;\r
 \r
   return Status;\r
 }\r
@@ -585,8 +613,7 @@ BdsLoadOptionMemMapUpdateDevicePath (
   IN EFI_DEVICE_PATH            *OldDevicePath,\r
   IN CHAR16*                    FileName,\r
   OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT BOOLEAN                   *RequestBootType\r
   )\r
 {\r
   EFI_STATUS          Status;\r
@@ -615,10 +642,6 @@ BdsLoadOptionMemMapUpdateDevicePath (
   EndingDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress);\r
   EndingDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress);\r
 \r
-  if (BootType != NULL || Attributes != NULL) {\r
-    Status = BootDeviceGetType (NULL, BootType, Attributes);\r
-  }\r
-\r
   if (EFI_ERROR(Status)) {\r
     FreePool(DevicePath);\r
   } else {\r
@@ -691,14 +714,16 @@ BdsLoadOptionPxeList (
 EFI_STATUS\r
 BdsLoadOptionPxeCreateDevicePath (\r
   IN CHAR16*                    FileName,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes,\r
+  OUT BOOLEAN                   *RequestBootType\r
   )\r
 {\r
-  *DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);\r
-  SetDevicePathEndNode (*DevicePathNode);\r
-  *BootType = BDS_LOADER_EFI_APPLICATION;\r
+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);\r
+  SetDevicePathEndNode (*DevicePathNodes);\r
+\r
+  if (RequestBootType) {\r
+    *RequestBootType = FALSE;\r
+  }\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -707,12 +732,11 @@ BdsLoadOptionPxeUpdateDevicePath (
   IN EFI_DEVICE_PATH            *OldDevicePath,\r
   IN CHAR16*                    FileName,\r
   OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT BOOLEAN                   *RequestBootType\r
   )\r
 {\r
   ASSERT (0);\r
-  return EFI_SUCCESS;\r
+  return EFI_UNSUPPORTED;\r
 }\r
 \r
 BOOLEAN\r
@@ -778,7 +802,7 @@ BdsLoadOptionTftpList (
         Status = GenerateDeviceDescriptionName (HandleBuffer[Index], DeviceDescription);\r
         ASSERT_EFI_ERROR (Status);\r
       }\r
-      UnicodeSPrint (SupportedDevice->Description,BOOT_DEVICE_DESCRIPTION_MAX,L"TFP on %s",DeviceDescription);\r
+      UnicodeSPrint (SupportedDevice->Description,BOOT_DEVICE_DESCRIPTION_MAX,L"TFTP on %s",DeviceDescription);\r
 \r
       SupportedDevice->DevicePathProtocol = DevicePathProtocol;\r
       SupportedDevice->Support = &BdsLoadOptionSupportList[BDS_DEVICE_TFTP];\r
@@ -793,9 +817,8 @@ BdsLoadOptionTftpList (
 EFI_STATUS\r
 BdsLoadOptionTftpCreateDevicePath (\r
   IN CHAR16*                    FileName,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes,\r
+  OUT BOOLEAN                   *RequestBootType\r
   )\r
 {\r
   EFI_STATUS    Status;\r
@@ -839,7 +862,7 @@ BdsLoadOptionTftpCreateDevicePath (
   }\r
 \r
   // Allocate the memory for the IPv4 + File Path Device Path Nodes\r
-  IPv4DevicePathNode = (IPv4_DEVICE_PATH*)AllocatePool(sizeof(IPv4_DEVICE_PATH) + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);\r
+  IPv4DevicePathNode = (IPv4_DEVICE_PATH*)AllocatePool(sizeof(IPv4_DEVICE_PATH) + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH);\r
 \r
   // Create the IPv4 Device Path\r
   IPv4DevicePathNode->Header.Type    = MESSAGING_DEVICE_PATH;\r
@@ -859,15 +882,9 @@ BdsLoadOptionTftpCreateDevicePath (
   SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);\r
   CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize);\r
 \r
-  if (BootType != NULL || Attributes != NULL) {\r
-    Status = BootDeviceGetType (NULL, BootType, Attributes);\r
-  }\r
-\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool (IPv4DevicePathNode);\r
-  } else {\r
-    *DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL*)IPv4DevicePathNode;\r
-  }\r
+  // Set the End Device Path Node\r
+  SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize));\r
+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)IPv4DevicePathNode;\r
 \r
   return Status;\r
 }\r
@@ -877,12 +894,11 @@ BdsLoadOptionTftpUpdateDevicePath (
   IN EFI_DEVICE_PATH            *OldDevicePath,\r
   IN CHAR16*                    FileName,\r
   OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE       *BootType,\r
-  OUT UINT32                    *Attributes\r
+  OUT BOOLEAN                   *RequestBootType\r
   )\r
 {\r
   ASSERT (0);\r
-  return EFI_SUCCESS;\r
+  return EFI_UNSUPPORTED;\r
 }\r
 \r
 BOOLEAN\r