]> git.proxmox.com Git - mirror_edk2.git/blame - BeagleBoardPkg/Bds/BdsEntry.c
Adding more DMA #defines to backup all the typing.
[mirror_edk2.git] / BeagleBoardPkg / Bds / BdsEntry.c
CommitLineData
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
1ebd6c11 9 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
2ef2b01e 10 \r
1ebd6c11 11 This program and the accompanying materials\r
2ef2b01e
A
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
24BOOLEAN gConsolePresent = FALSE;\r
25\r
26\r
27EFI_HANDLE mBdsImageHandle = NULL;\r
28EFI_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
56VOID\r
57EFIAPI\r
58BdsEntry (\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
d39eb83c 77 PERF_END (NULL, "DXE", NULL, 0);\r
78 PERF_START (NULL, "BDS", NULL, 0);\r
79\r
80\r
2ef2b01e
A
81 //\r
82 // Now do the EFI stuff\r
83 //\r
84 Size = 0x100;\r
85 gST->FirmwareVendor = AllocateRuntimePool (Size);\r
86 ASSERT (gST->FirmwareVendor != NULL);\r
87 \r
88 UnicodeSPrint (gST->FirmwareVendor, Size, L"BeagleBoard EFI %a %a", __DATE__, __TIME__);\r
89\r
90 //\r
91 // Now we need to setup the EFI System Table with information about the console devices.\r
92 // This code is normally in the console spliter driver on platforms that support multiple \r
93 // consoles at the same time\r
94 //\r
95 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleTextOutProtocolGuid, NULL, &NoHandles, &Buffer);\r
96 if (!EFI_ERROR (Status)) {\r
97 // Use the first SimpleTextOut we find and update the EFI System Table\r
98 gST->ConsoleOutHandle = Buffer[0];\r
99 gST->StandardErrorHandle = Buffer[0];\r
100 Status = gBS->HandleProtocol (Buffer[0], &gEfiSimpleTextOutProtocolGuid, (VOID **)&gST->ConOut);\r
101 ASSERT_EFI_ERROR (Status);\r
102 \r
103 gST->StdErr = gST->ConOut;\r
104 \r
105 gST->ConOut->OutputString (gST->ConOut, L"BDS: Console Started!!!!\n\r");\r
106 FreePool (Buffer);\r
107 \r
108 gConsolePresent = TRUE;\r
109 } \r
110 \r
111\r
112 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleTextInProtocolGuid, NULL, &NoHandles, &Buffer);\r
113 if (!EFI_ERROR (Status)) {\r
114 // Use the first SimpleTextIn we find and update the EFI System Table\r
115 gST->ConsoleInHandle = Buffer[0];\r
116 Status = gBS->HandleProtocol (Buffer[0], &gEfiSimpleTextInProtocolGuid, (VOID **)&gST->ConIn);\r
117 ASSERT_EFI_ERROR (Status);\r
118 \r
119 FreePool (Buffer);\r
120 }\r
121\r
122 //\r
123 // We now have EFI Consoles up and running. Print () will work now. DEBUG () and ASSERT () worked \r
124 // prior to this point as they were configured to use a more primative output scheme.\r
125 //\r
126\r
127 //\r
128 //Perform Connect\r
129 //\r
130 HandleCount = 0;\r
131 while (1) {\r
132 OldHandleCount = HandleCount;\r
133 Status = gBS->LocateHandleBuffer (\r
134 AllHandles,\r
135 NULL,\r
136 NULL,\r
137 &HandleCount,\r
138 &HandleBuffer\r
139 );\r
140 if (EFI_ERROR (Status)) {\r
141 break;\r
142 }\r
143 \r
144 if (HandleCount == OldHandleCount) {\r
145 break;\r
146 }\r
147\r
148 for (Index = 0; Index < HandleCount; Index++) {\r
149 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r
150 }\r
151 }\r
152\r
153 //Locate handles for SimpleFileSystem protocol\r
154 Status = gBS->LocateHandleBuffer (\r
155 ByProtocol,\r
156 &gEfiSimpleFileSystemProtocolGuid,\r
157 NULL,\r
158 &HandleCount,\r
159 &HandleBuffer\r
160 );\r
161 if (!EFI_ERROR(Status)) {\r
162 for (Index = 0; Index < HandleCount; Index++) {\r
163 //Get the device path\r
164 FileSystemDevicePath = DevicePathFromHandle(HandleBuffer[Index]);\r
165 if (FileSystemDevicePath == NULL) {\r
166 continue;\r
167 }\r
168\r
169 //Check if UsbIo is on any handles in the device path.\r
170 Status = gBS->LocateDevicePath(&gEfiUsbIoProtocolGuid, &FileSystemDevicePath, &UsbDeviceHandle);\r
171 if (EFI_ERROR(Status)) {\r
172 continue;\r
173 }\r
174\r
175 //Check if Usb stick has a magic EBL file.\r
176 LoadImageDevicePath = FileDevicePath(HandleBuffer[Index], L"Ebl.efi");\r
177 Status = gBS->LoadImage (TRUE, gImageHandle, LoadImageDevicePath, NULL, 0, &ImageHandle);\r
178 if (EFI_ERROR(Status)) {\r
179 continue;\r
180 }\r
181\r
182 //Boot to Shell on USB stick.\r
183 Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
184 if (EFI_ERROR(Status)) {\r
185 continue;\r
186 }\r
187 }\r
188 }\r
189 \r
190 //\r
191 // Normal UEFI behavior is to process Globally Defined Variables as defined in Chapter 3 \r
192 // (Boot Manager) of the UEFI specification. For this embedded system we don't do this.\r
193 //\r
194\r
195 //\r
196 // Search all the FVs for an application with a UI Section of Ebl. A .FDF file can be used\r
197 // to control the names of UI sections in an FV.\r
198 //\r
199 Status = FindApplicationMatchingUiSection (L"Ebl", &FvHandle, &NameGuid);\r
200 if (!EFI_ERROR (Status)) {\r
201\r
202 //Boot to Shell.\r
203 Status = LoadPeCoffSectionFromFv (FvHandle, &NameGuid);\r
204\r
205 if (EFI_ERROR(Status)) {\r
206 DEBUG((EFI_D_ERROR, "Boot from Shell failed. Status: %r\n", Status));\r
207 }\r
208 }\r
209\r
210 //\r
211 // EFI does not define the behaviour if all boot attemps fail and the last one returns. \r
212 // So we make a policy choice to reset the system since this BDS does not have a UI.\r
213 //\r
214 gRT->ResetSystem (EfiResetShutdown, Status, 0, NULL);\r
215\r
216 return ;\r
217}\r
218\r
219\r
220EFI_STATUS\r
221EFIAPI\r
222BdsInitialize (\r
223 IN EFI_HANDLE ImageHandle,\r
224 IN EFI_SYSTEM_TABLE *SystemTable\r
225 )\r
226{\r
227 EFI_STATUS Status;\r
228\r
229 mBdsImageHandle = ImageHandle;\r
230\r
231 //\r
232 // Install protocol interface\r
233 //\r
234 Status = gBS->InstallMultipleProtocolInterfaces (\r
235 &mBdsImageHandle,\r
236 &gEfiBdsArchProtocolGuid, &gBdsProtocol,\r
237 NULL\r
238 );\r
239 ASSERT_EFI_ERROR (Status);\r
240\r
241 return Status;\r
242}\r
243\r
244\r