]>
Commit | Line | Data |
---|---|---|
2ef2b01e A |
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 | Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r | |
10 | \r | |
11 | All rights reserved. This program and the accompanying materials\r | |
12 | are licensed and made available under the terms and conditions of the BSD License\r | |
13 | which accompanies this distribution. The full text of the license may be found at\r | |
14 | http://opensource.org/licenses/bsd-license.php\r | |
15 | \r | |
16 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
17 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
18 | \r | |
19 | **/\r | |
20 | \r | |
21 | #include "BdsEntry.h"\r | |
22 | \r | |
23 | \r | |
24 | BOOLEAN gConsolePresent = FALSE;\r | |
25 | \r | |
26 | \r | |
27 | EFI_HANDLE mBdsImageHandle = NULL;\r | |
28 | EFI_BDS_ARCH_PROTOCOL gBdsProtocol = {\r | |
29 | BdsEntry,\r | |
30 | };\r | |
31 | \r | |
32 | \r | |
33 | \r | |
34 | \r | |
35 | /**\r | |
36 | This function uses policy data from the platform to determine what operating \r | |
37 | system or system utility should be loaded and invoked. This function call \r | |
38 | also optionally make the use of user input to determine the operating system \r | |
39 | or system utility to be loaded and invoked. When the DXE Core has dispatched \r | |
40 | all the drivers on the dispatch queue, this function is called. This \r | |
41 | function will attempt to connect the boot devices required to load and invoke \r | |
42 | the selected operating system or system utility. During this process, \r | |
43 | additional firmware volumes may be discovered that may contain addition DXE \r | |
44 | drivers that can be dispatched by the DXE Core. If a boot device cannot be \r | |
45 | fully connected, this function calls the DXE Service Dispatch() to allow the \r | |
46 | DXE drivers from any newly discovered firmware volumes to be dispatched. \r | |
47 | Then the boot device connection can be attempted again. If the same boot \r | |
48 | device connection operation fails twice in a row, then that boot device has \r | |
49 | failed, and should be skipped. This function should never return.\r | |
50 | \r | |
51 | @param This The EFI_BDS_ARCH_PROTOCOL instance.\r | |
52 | \r | |
53 | @return None.\r | |
54 | \r | |
55 | **/\r | |
56 | VOID\r | |
57 | EFIAPI\r | |
58 | BdsEntry (\r | |
59 | IN EFI_BDS_ARCH_PROTOCOL *This\r | |
60 | )\r | |
61 | {\r | |
62 | EFI_STATUS Status;\r | |
63 | UINTN NoHandles;\r | |
64 | EFI_HANDLE *Buffer;\r | |
65 | EFI_HANDLE FvHandle;\r | |
66 | EFI_HANDLE ImageHandle;\r | |
67 | EFI_HANDLE UsbDeviceHandle;\r | |
68 | EFI_GUID NameGuid;\r | |
69 | UINTN Size;\r | |
70 | UINTN HandleCount;\r | |
71 | UINTN OldHandleCount;\r | |
72 | EFI_HANDLE *HandleBuffer;\r | |
73 | UINTN Index;\r | |
74 | EFI_DEVICE_PATH_PROTOCOL *LoadImageDevicePath;\r | |
75 | EFI_DEVICE_PATH_PROTOCOL *FileSystemDevicePath;\r | |
76 | \r | |
77 | //\r | |
78 | // Now do the EFI stuff\r | |
79 | //\r | |
80 | Size = 0x100;\r | |
81 | gST->FirmwareVendor = AllocateRuntimePool (Size);\r | |
82 | ASSERT (gST->FirmwareVendor != NULL);\r | |
83 | \r | |
84 | UnicodeSPrint (gST->FirmwareVendor, Size, L"BeagleBoard EFI %a %a", __DATE__, __TIME__);\r | |
85 | \r | |
86 | //\r | |
87 | // Now we need to setup the EFI System Table with information about the console devices.\r | |
88 | // This code is normally in the console spliter driver on platforms that support multiple \r | |
89 | // consoles at the same time\r | |
90 | //\r | |
91 | Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleTextOutProtocolGuid, NULL, &NoHandles, &Buffer);\r | |
92 | if (!EFI_ERROR (Status)) {\r | |
93 | // Use the first SimpleTextOut we find and update the EFI System Table\r | |
94 | gST->ConsoleOutHandle = Buffer[0];\r | |
95 | gST->StandardErrorHandle = Buffer[0];\r | |
96 | Status = gBS->HandleProtocol (Buffer[0], &gEfiSimpleTextOutProtocolGuid, (VOID **)&gST->ConOut);\r | |
97 | ASSERT_EFI_ERROR (Status);\r | |
98 | \r | |
99 | gST->StdErr = gST->ConOut;\r | |
100 | \r | |
101 | gST->ConOut->OutputString (gST->ConOut, L"BDS: Console Started!!!!\n\r");\r | |
102 | FreePool (Buffer);\r | |
103 | \r | |
104 | gConsolePresent = TRUE;\r | |
105 | } \r | |
106 | \r | |
107 | \r | |
108 | Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleTextInProtocolGuid, NULL, &NoHandles, &Buffer);\r | |
109 | if (!EFI_ERROR (Status)) {\r | |
110 | // Use the first SimpleTextIn we find and update the EFI System Table\r | |
111 | gST->ConsoleInHandle = Buffer[0];\r | |
112 | Status = gBS->HandleProtocol (Buffer[0], &gEfiSimpleTextInProtocolGuid, (VOID **)&gST->ConIn);\r | |
113 | ASSERT_EFI_ERROR (Status);\r | |
114 | \r | |
115 | FreePool (Buffer);\r | |
116 | }\r | |
117 | \r | |
118 | //\r | |
119 | // We now have EFI Consoles up and running. Print () will work now. DEBUG () and ASSERT () worked \r | |
120 | // prior to this point as they were configured to use a more primative output scheme.\r | |
121 | //\r | |
122 | \r | |
123 | //\r | |
124 | //Perform Connect\r | |
125 | //\r | |
126 | HandleCount = 0;\r | |
127 | while (1) {\r | |
128 | OldHandleCount = HandleCount;\r | |
129 | Status = gBS->LocateHandleBuffer (\r | |
130 | AllHandles,\r | |
131 | NULL,\r | |
132 | NULL,\r | |
133 | &HandleCount,\r | |
134 | &HandleBuffer\r | |
135 | );\r | |
136 | if (EFI_ERROR (Status)) {\r | |
137 | break;\r | |
138 | }\r | |
139 | \r | |
140 | if (HandleCount == OldHandleCount) {\r | |
141 | break;\r | |
142 | }\r | |
143 | \r | |
144 | for (Index = 0; Index < HandleCount; Index++) {\r | |
145 | gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r | |
146 | }\r | |
147 | }\r | |
148 | \r | |
149 | //Locate handles for SimpleFileSystem protocol\r | |
150 | Status = gBS->LocateHandleBuffer (\r | |
151 | ByProtocol,\r | |
152 | &gEfiSimpleFileSystemProtocolGuid,\r | |
153 | NULL,\r | |
154 | &HandleCount,\r | |
155 | &HandleBuffer\r | |
156 | );\r | |
157 | if (!EFI_ERROR(Status)) {\r | |
158 | for (Index = 0; Index < HandleCount; Index++) {\r | |
159 | //Get the device path\r | |
160 | FileSystemDevicePath = DevicePathFromHandle(HandleBuffer[Index]);\r | |
161 | if (FileSystemDevicePath == NULL) {\r | |
162 | continue;\r | |
163 | }\r | |
164 | \r | |
165 | //Check if UsbIo is on any handles in the device path.\r | |
166 | Status = gBS->LocateDevicePath(&gEfiUsbIoProtocolGuid, &FileSystemDevicePath, &UsbDeviceHandle);\r | |
167 | if (EFI_ERROR(Status)) {\r | |
168 | continue;\r | |
169 | }\r | |
170 | \r | |
171 | //Check if Usb stick has a magic EBL file.\r | |
172 | LoadImageDevicePath = FileDevicePath(HandleBuffer[Index], L"Ebl.efi");\r | |
173 | Status = gBS->LoadImage (TRUE, gImageHandle, LoadImageDevicePath, NULL, 0, &ImageHandle);\r | |
174 | if (EFI_ERROR(Status)) {\r | |
175 | continue;\r | |
176 | }\r | |
177 | \r | |
178 | //Boot to Shell on USB stick.\r | |
179 | Status = gBS->StartImage (ImageHandle, NULL, NULL);\r | |
180 | if (EFI_ERROR(Status)) {\r | |
181 | continue;\r | |
182 | }\r | |
183 | }\r | |
184 | }\r | |
185 | \r | |
186 | //\r | |
187 | // Normal UEFI behavior is to process Globally Defined Variables as defined in Chapter 3 \r | |
188 | // (Boot Manager) of the UEFI specification. For this embedded system we don't do this.\r | |
189 | //\r | |
190 | \r | |
191 | //\r | |
192 | // Search all the FVs for an application with a UI Section of Ebl. A .FDF file can be used\r | |
193 | // to control the names of UI sections in an FV.\r | |
194 | //\r | |
195 | Status = FindApplicationMatchingUiSection (L"Ebl", &FvHandle, &NameGuid);\r | |
196 | if (!EFI_ERROR (Status)) {\r | |
197 | \r | |
198 | //Boot to Shell.\r | |
199 | Status = LoadPeCoffSectionFromFv (FvHandle, &NameGuid);\r | |
200 | \r | |
201 | if (EFI_ERROR(Status)) {\r | |
202 | DEBUG((EFI_D_ERROR, "Boot from Shell failed. Status: %r\n", Status));\r | |
203 | }\r | |
204 | }\r | |
205 | \r | |
206 | //\r | |
207 | // EFI does not define the behaviour if all boot attemps fail and the last one returns. \r | |
208 | // So we make a policy choice to reset the system since this BDS does not have a UI.\r | |
209 | //\r | |
210 | gRT->ResetSystem (EfiResetShutdown, Status, 0, NULL);\r | |
211 | \r | |
212 | return ;\r | |
213 | }\r | |
214 | \r | |
215 | \r | |
216 | EFI_STATUS\r | |
217 | EFIAPI\r | |
218 | BdsInitialize (\r | |
219 | IN EFI_HANDLE ImageHandle,\r | |
220 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
221 | )\r | |
222 | {\r | |
223 | EFI_STATUS Status;\r | |
224 | \r | |
225 | mBdsImageHandle = ImageHandle;\r | |
226 | \r | |
227 | //\r | |
228 | // Install protocol interface\r | |
229 | //\r | |
230 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
231 | &mBdsImageHandle,\r | |
232 | &gEfiBdsArchProtocolGuid, &gBdsProtocol,\r | |
233 | NULL\r | |
234 | );\r | |
235 | ASSERT_EFI_ERROR (Status);\r | |
236 | \r | |
237 | return Status;\r | |
238 | }\r | |
239 | \r | |
240 | \r |