]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | *\r | |
3 | * Copyright (c) 2011 - 2015, ARM Limited. All rights reserved.\r | |
4 | *\r | |
5 | * This program and the accompanying materials\r | |
6 | * are licensed and made available under the terms and conditions of the BSD License\r | |
7 | * which accompanies this distribution. The full text of the license may be found at\r | |
8 | * http://opensource.org/licenses/bsd-license.php\r | |
9 | *\r | |
10 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | *\r | |
13 | **/\r | |
14 | \r | |
15 | #include "BdsInternal.h"\r | |
16 | \r | |
17 | // This GUID is defined in the INGF file of ArmPkg/Application/LinuxLoader\r | |
18 | CONST EFI_GUID mLinuxLoaderAppGuid = { 0x701f54f2, 0x0d70, 0x4b89, { 0xbc, 0x0a, 0xd9, 0xca, 0x25, 0x37, 0x90, 0x59 }};\r | |
19 | \r | |
20 | // Device path of the EFI Linux Loader in the Firmware Volume\r | |
21 | EFI_DEVICE_PATH* mLinuxLoaderDevicePath = NULL;\r | |
22 | \r | |
23 | STATIC\r | |
24 | BOOLEAN\r | |
25 | HasFilePathEfiExtension (\r | |
26 | IN CHAR16* FilePath\r | |
27 | )\r | |
28 | {\r | |
29 | return (StrCmp (FilePath + (StrSize (FilePath) / sizeof (CHAR16)) - 5, L".EFI") == 0) ||\r | |
30 | (StrCmp (FilePath + (StrSize (FilePath) / sizeof (CHAR16)) - 5, L".efi") == 0);\r | |
31 | }\r | |
32 | \r | |
33 | /**\r | |
34 | * This function check if the DevicePath defines an EFI binary\r | |
35 | *\r | |
36 | * This function is used when the BDS support Linux loader to\r | |
37 | * detect if the binary is an EFI application or potentially a\r | |
38 | * Linux kernel.\r | |
39 | */\r | |
40 | EFI_STATUS\r | |
41 | IsEfiBinary (\r | |
42 | IN EFI_DEVICE_PATH* DevicePath,\r | |
43 | OUT BOOLEAN *EfiBinary\r | |
44 | )\r | |
45 | {\r | |
46 | EFI_STATUS Status;\r | |
47 | CHAR16* FileName;\r | |
48 | EFI_DEVICE_PATH* PrevDevicePathNode;\r | |
49 | EFI_DEVICE_PATH* DevicePathNode;\r | |
50 | EFI_PHYSICAL_ADDRESS Image;\r | |
51 | UINTN FileSize;\r | |
52 | EFI_IMAGE_DOS_HEADER* DosHeader;\r | |
53 | UINTN PeCoffHeaderOffset;\r | |
54 | EFI_IMAGE_NT_HEADERS32* NtHeader;\r | |
55 | \r | |
56 | ASSERT (EfiBinary != NULL);\r | |
57 | \r | |
58 | //\r | |
59 | // Check if the last node of the device path is a FilePath node\r | |
60 | //\r | |
61 | PrevDevicePathNode = NULL;\r | |
62 | DevicePathNode = DevicePath;\r | |
63 | while ((DevicePathNode != NULL) && !IsDevicePathEnd (DevicePathNode)) {\r | |
64 | PrevDevicePathNode = DevicePathNode;\r | |
65 | DevicePathNode = NextDevicePathNode (DevicePathNode);\r | |
66 | }\r | |
67 | \r | |
68 | if ((PrevDevicePathNode != NULL) &&\r | |
69 | (PrevDevicePathNode->Type == MEDIA_DEVICE_PATH) &&\r | |
70 | (PrevDevicePathNode->SubType == MEDIA_FILEPATH_DP))\r | |
71 | {\r | |
72 | FileName = ((FILEPATH_DEVICE_PATH*)PrevDevicePathNode)->PathName;\r | |
73 | } else {\r | |
74 | FileName = NULL;\r | |
75 | }\r | |
76 | \r | |
77 | if (FileName == NULL) {\r | |
78 | Print (L"Is an EFI Application? ");\r | |
79 | Status = GetHIInputBoolean (EfiBinary);\r | |
80 | if (EFI_ERROR (Status)) {\r | |
81 | return EFI_ABORTED;\r | |
82 | }\r | |
83 | } else if (HasFilePathEfiExtension (FileName)) {\r | |
84 | *EfiBinary = TRUE;\r | |
85 | } else {\r | |
86 | // Check if the file exist\r | |
87 | Status = BdsLoadImage (DevicePath, AllocateAnyPages, &Image, &FileSize);\r | |
88 | if (!EFI_ERROR (Status)) {\r | |
89 | \r | |
90 | DosHeader = (EFI_IMAGE_DOS_HEADER *)(UINTN) Image;\r | |
91 | if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r | |
92 | //\r | |
93 | // DOS image header is present,\r | |
94 | // so read the PE header after the DOS image header.\r | |
95 | //\r | |
96 | PeCoffHeaderOffset = DosHeader->e_lfanew;\r | |
97 | } else {\r | |
98 | PeCoffHeaderOffset = 0;\r | |
99 | }\r | |
100 | \r | |
101 | //\r | |
102 | // Check PE/COFF image.\r | |
103 | //\r | |
104 | NtHeader = (EFI_IMAGE_NT_HEADERS32 *)(UINTN) (Image + PeCoffHeaderOffset);\r | |
105 | if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {\r | |
106 | *EfiBinary = FALSE;\r | |
107 | } else {\r | |
108 | *EfiBinary = TRUE;\r | |
109 | }\r | |
110 | \r | |
111 | // Free memory\r | |
112 | gBS->FreePages (Image, EFI_SIZE_TO_PAGES (FileSize));\r | |
113 | } else {\r | |
114 | // If we did not manage to open it then ask for the type\r | |
115 | Print (L"Is an EFI Application? ");\r | |
116 | Status = GetHIInputBoolean (EfiBinary);\r | |
117 | if (EFI_ERROR (Status)) {\r | |
118 | return EFI_ABORTED;\r | |
119 | }\r | |
120 | }\r | |
121 | }\r | |
122 | \r | |
123 | return EFI_SUCCESS;\r | |
124 | }\r |