]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | The entry of the embedded BDS. This BDS does not follow the Boot Manager requirements \r | |
3 | of the UEFI specification as it is designed to implement an embedded systmes \r | |
4 | propriatary boot scheme.\r | |
5 | \r | |
6 | This template assume a DXE driver produces a SerialIo protocol not using the EFI \r | |
7 | driver module and it will attempt to connect a console on top of this.\r | |
8 | \r | |
9 | \r | |
10 | Copyright (c) 2009, Apple Inc. All rights reserved.<BR>\r | |
11 | \r | |
12 | This program and the accompanying materials\r | |
13 | are licensed and made available under the terms and conditions of the BSD License\r | |
14 | which accompanies this distribution. The full text of the license may be found at\r | |
15 | http://opensource.org/licenses/bsd-license.php\r | |
16 | \r | |
17 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
18 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
19 | \r | |
20 | **/\r | |
21 | \r | |
22 | #include "BdsEntry.h"\r | |
23 | \r | |
24 | \r | |
25 | EFI_STATUS\r | |
26 | FindApplicationMatchingUiSection (\r | |
27 | IN CHAR16 *UiString,\r | |
28 | OUT EFI_HANDLE *FvHandle,\r | |
29 | OUT EFI_GUID *NameGuid\r | |
30 | )\r | |
31 | {\r | |
32 | EFI_STATUS Status;\r | |
33 | EFI_STATUS NextStatus;\r | |
34 | UINTN NoHandles;\r | |
35 | EFI_HANDLE *Buffer;\r | |
36 | UINTN Index;\r | |
37 | EFI_FV_FILETYPE FileType;\r | |
38 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r | |
39 | VOID *Key;\r | |
40 | EFI_FV_FILE_ATTRIBUTES Attributes;\r | |
41 | UINTN Size;\r | |
42 | UINTN UiStringLen;\r | |
43 | CHAR16 *UiSection;\r | |
44 | UINT32 Authentication;\r | |
45 | \r | |
46 | \r | |
47 | UiStringLen = 0;\r | |
48 | if (UiString != NULL) {\r | |
49 | DEBUG ((DEBUG_ERROR, "UiString %s\n", UiString));\r | |
50 | UiStringLen = StrLen (UiString);\r | |
51 | }\r | |
52 | \r | |
53 | Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Buffer);\r | |
54 | if (!EFI_ERROR (Status)) {\r | |
55 | for (Index = 0; Index < NoHandles; Index++) {\r | |
56 | Status = gBS->HandleProtocol (Buffer[Index], &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);\r | |
57 | if (!EFI_ERROR (Status)) {\r | |
58 | Key = AllocatePool (Fv->KeySize);\r | |
59 | ASSERT (Key != NULL);\r | |
60 | ZeroMem (Key, Fv->KeySize);\r | |
61 | \r | |
62 | FileType = EFI_FV_FILETYPE_APPLICATION;\r | |
63 | \r | |
64 | do {\r | |
65 | NextStatus = Fv->GetNextFile (Fv, Key, &FileType, NameGuid, &Attributes, &Size);\r | |
66 | if (!EFI_ERROR (NextStatus)) {\r | |
67 | if (UiString == NULL) {\r | |
68 | //\r | |
69 | // If UiString is NULL match first application we find.\r | |
70 | //\r | |
71 | *FvHandle = Buffer[Index];\r | |
72 | FreePool (Key);\r | |
73 | return Status;\r | |
74 | }\r | |
75 | \r | |
76 | UiSection = NULL;\r | |
77 | Status = Fv->ReadSection (\r | |
78 | Fv, \r | |
79 | NameGuid, \r | |
80 | EFI_SECTION_USER_INTERFACE, \r | |
81 | 0,\r | |
82 | (VOID **)&UiSection,\r | |
83 | &Size,\r | |
84 | &Authentication\r | |
85 | );\r | |
86 | if (!EFI_ERROR (Status)) {\r | |
87 | if (StrnCmp (UiString, UiSection, UiStringLen) == 0) {\r | |
88 | //\r | |
89 | // We found a UiString match. \r | |
90 | //\r | |
91 | *FvHandle = Buffer[Index];\r | |
92 | FreePool (Key);\r | |
93 | FreePool (UiSection);\r | |
94 | return Status;\r | |
95 | }\r | |
96 | FreePool (UiSection);\r | |
97 | }\r | |
98 | }\r | |
99 | } while (!EFI_ERROR (NextStatus));\r | |
100 | \r | |
101 | FreePool (Key);\r | |
102 | }\r | |
103 | }\r | |
104 | \r | |
105 | FreePool (Buffer);\r | |
106 | }\r | |
107 | \r | |
108 | return EFI_NOT_FOUND;\r | |
109 | }\r | |
110 | \r | |
111 | \r | |
112 | EFI_DEVICE_PATH *\r | |
113 | FvFileDevicePath (\r | |
114 | IN EFI_HANDLE FvHandle,\r | |
115 | IN EFI_GUID *NameGuid\r | |
116 | )\r | |
117 | { \r | |
118 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
119 | MEDIA_FW_VOL_FILEPATH_DEVICE_PATH NewNode;\r | |
120 | \r | |
121 | DevicePath = DevicePathFromHandle (FvHandle);\r | |
122 | \r | |
123 | EfiInitializeFwVolDevicepathNode (&NewNode, NameGuid);\r | |
124 | \r | |
125 | return AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&NewNode);\r | |
126 | }\r | |
127 | \r | |
128 | \r | |
129 | \r | |
130 | EFI_STATUS\r | |
131 | LoadPeCoffSectionFromFv (\r | |
132 | IN EFI_HANDLE FvHandle, \r | |
133 | IN EFI_GUID *NameGuid\r | |
134 | )\r | |
135 | {\r | |
136 | EFI_STATUS Status;\r | |
137 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
138 | EFI_HANDLE ImageHandle;\r | |
139 | \r | |
140 | DevicePath = FvFileDevicePath (FvHandle, NameGuid);\r | |
141 | \r | |
142 | Status = gBS->LoadImage (TRUE, gImageHandle, DevicePath, NULL, 0, &ImageHandle);\r | |
143 | if (!EFI_ERROR (Status)) {\r | |
144 | PERF_END (NULL, "BDS", NULL, 0);\r | |
145 | Status = gBS->StartImage (ImageHandle, NULL, NULL);\r | |
146 | }\r | |
147 | \r | |
148 | return Status;\r | |
149 | }\r | |
150 | \r |