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