]> git.proxmox.com Git - mirror_edk2.git/blame - ArmEbPkg/Bds/BdsEntry.c
Report correct MediaPresentSupported value from Nt32 SNP mode data.
[mirror_edk2.git] / ArmEbPkg / Bds / BdsEntry.c
CommitLineData
b76848cb 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.<BR>\r
10 \r
11 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
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
77 PERF_END (NULL, "DXE", NULL, 0);\r
78 PERF_START (NULL, "BDS", NULL, 0);\r
79\r
80\r
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 EfiSignalEventReadyToBoot ();\r
154\r
155 //Locate handles for SimpleFileSystem protocol\r
156 Status = gBS->LocateHandleBuffer (\r
157 ByProtocol,\r
158 &gEfiSimpleFileSystemProtocolGuid,\r
159 NULL,\r
160 &HandleCount,\r
161 &HandleBuffer\r
162 );\r
163 if (!EFI_ERROR(Status)) {\r
164 for (Index = 0; Index < HandleCount; Index++) {\r
165 //Get the device path\r
166 FileSystemDevicePath = DevicePathFromHandle(HandleBuffer[Index]);\r
167 if (FileSystemDevicePath == NULL) {\r
168 continue;\r
169 }\r
170\r
171 //Check if UsbIo is on any handles in the device path.\r
172 Status = gBS->LocateDevicePath(&gEfiUsbIoProtocolGuid, &FileSystemDevicePath, &UsbDeviceHandle);\r
173 if (EFI_ERROR(Status)) {\r
174 continue;\r
175 }\r
176\r
177 //Check if Usb stick has a magic EBL file.\r
178 LoadImageDevicePath = FileDevicePath(HandleBuffer[Index], L"Ebl.efi");\r
179 Status = gBS->LoadImage (TRUE, gImageHandle, LoadImageDevicePath, NULL, 0, &ImageHandle);\r
180 if (EFI_ERROR(Status)) {\r
181 continue;\r
182 }\r
183\r
184 //Boot to Shell on USB stick.\r
185 Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
186 if (EFI_ERROR(Status)) {\r
187 continue;\r
188 }\r
189 }\r
190 }\r
191 \r
192 //\r
193 // Normal UEFI behavior is to process Globally Defined Variables as defined in Chapter 3 \r
194 // (Boot Manager) of the UEFI specification. For this embedded system we don't do this.\r
195 //\r
196\r
197 //\r
198 // Search all the FVs for an application with a UI Section of Ebl. A .FDF file can be used\r
199 // to control the names of UI sections in an FV.\r
200 //\r
201 Status = FindApplicationMatchingUiSection (L"Ebl", &FvHandle, &NameGuid);\r
202 if (!EFI_ERROR (Status)) {\r
203\r
204 //Boot to Shell.\r
205 Status = LoadPeCoffSectionFromFv (FvHandle, &NameGuid);\r
206\r
207 if (EFI_ERROR(Status)) {\r
208 DEBUG((EFI_D_ERROR, "Boot from Shell failed. Status: %r\n", Status));\r
209 }\r
210 }\r
211\r
212 //\r
213 // EFI does not define the behaviour if all boot attemps fail and the last one returns. \r
214 // So we make a policy choice to reset the system since this BDS does not have a UI.\r
215 //\r
216 gRT->ResetSystem (EfiResetShutdown, Status, 0, NULL);\r
217\r
218 return ;\r
219}\r
220\r
221\r
222EFI_STATUS\r
223EFIAPI\r
224BdsInitialize (\r
225 IN EFI_HANDLE ImageHandle,\r
226 IN EFI_SYSTEM_TABLE *SystemTable\r
227 )\r
228{\r
229 EFI_STATUS Status;\r
230\r
231 mBdsImageHandle = ImageHandle;\r
232\r
233 //\r
234 // Install protocol interface\r
235 //\r
236 Status = gBS->InstallMultipleProtocolInterfaces (\r
237 &mBdsImageHandle,\r
238 &gEfiBdsArchProtocolGuid, &gBdsProtocol,\r
239 NULL\r
240 );\r
241 ASSERT_EFI_ERROR (Status);\r
242\r
243 return Status;\r
244}\r
245\r
246\r