]>
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 | UINTN Index;\r | |
66 | EFI_HANDLE FvHandle;\r | |
67 | EFI_GUID *NameGuid;\r | |
68 | \r | |
69 | //\r | |
70 | // This code assumes that a DXE driver produces a SerialIo protocol not following the EFI\r | |
71 | // driver model. At a minimum we need to connect an EFI driver model terminal driver on top \r | |
72 | // of the serial driver. \r | |
73 | //\r | |
74 | Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Buffer);\r | |
75 | if (!EFI_ERROR (Status)) {\r | |
76 | for (Index = 0; Index < NoHandles; Index++) {\r | |
77 | // For every Serial IO protocol in the system connect EFI drivers to it.\r | |
78 | // This should cause the terminal driver to bind to the Serial IO protocol and produce a \r | |
79 | // child handle that produces SimpleTextOut & SImpleTextIn protocols\r | |
80 | gBS->ConnectController (Buffer[Index], NULL, NULL, TRUE);\r | |
81 | }\r | |
82 | \r | |
83 | FreePool (Buffer);\r | |
84 | }\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 | FreePool (Buffer);\r | |
102 | \r | |
103 | gConsolePresent = TRUE;\r | |
104 | }\r | |
105 | \r | |
106 | Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleTextInProtocolGuid, NULL, &NoHandles, &Buffer);\r | |
107 | if (!EFI_ERROR (Status)) {\r | |
108 | // Use the first SimpleTextIn we find and update the EFI System Table\r | |
109 | gST->ConsoleInHandle = Buffer[0];\r | |
110 | Status = gBS->HandleProtocol (Buffer[0], &gEfiSimpleTextInProtocolGuid, (VOID **)&gST->ConIn);\r | |
111 | ASSERT_EFI_ERROR (Status);\r | |
112 | \r | |
113 | FreePool (Buffer);\r | |
114 | }\r | |
115 | \r | |
116 | //\r | |
117 | // We now have EFI Consoles up and running. Print () will work now. DEBUG () and ASSERT () worked \r | |
118 | // prior to this point as they were configured to use a more primative output scheme.\r | |
119 | //\r | |
120 | \r | |
121 | \r | |
122 | //\r | |
123 | // Platform specific stuff goes here\r | |
124 | //\r | |
125 | \r | |
126 | \r | |
127 | //\r | |
128 | // Normal UEFI behavior is to process Globally Defined Variables as defined in Chapter 3 \r | |
129 | // (Boot Manager) of the UEFI specification. For this embedded system we don't do this.\r | |
130 | //\r | |
131 | \r | |
132 | //\r | |
133 | // Search all the FVs for an application with a UI Section of Ebl. A .FDF file can be used\r | |
134 | // to control the names of UI sections in an FV.\r | |
135 | //\r | |
136 | Status = FindApplicationMatchingUiSection (L"Ebl", &FvHandle, &NameGuid);\r | |
137 | if (EFI_ERROR (Status)) {\r | |
138 | //\r | |
139 | // Just load the first application we find reguardless of name.\r | |
140 | // This is the fallback path.\r | |
141 | //\r | |
142 | Status = FindApplicationMatchingUiSection (NULL, &FvHandle, &NameGuid);\r | |
143 | // Nothing to boot\r | |
144 | ASSERT_EFI_ERROR (Status);\r | |
145 | }\r | |
146 | \r | |
147 | Status = LoadPeCoffSectionFromFv (FvHandle, NameGuid);\r | |
148 | \r | |
149 | //\r | |
150 | // EFI does not define the bavior if all boot attemps fail and the last one returns. \r | |
151 | // So we make a policy choice to reset the system since this BDS does not have a UI.\r | |
152 | //\r | |
153 | gRT->ResetSystem (EfiResetCold, Status, 0, NULL);\r | |
154 | \r | |
155 | return ;\r | |
156 | }\r | |
157 | \r | |
158 | \r | |
159 | EFI_STATUS\r | |
160 | EFIAPI\r | |
161 | BdsInitialize (\r | |
162 | IN EFI_HANDLE ImageHandle,\r | |
163 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
164 | )\r | |
165 | {\r | |
166 | EFI_STATUS Status;\r | |
167 | \r | |
168 | mBdsImageHandle = ImageHandle;\r | |
169 | \r | |
170 | //\r | |
171 | // Install protocol interface\r | |
172 | //\r | |
173 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
174 | &mBdsImageHandle,\r | |
175 | &gEfiBdsArchProtocolGuid, &gBdsProtocol,\r | |
176 | NULL\r | |
177 | );\r | |
178 | ASSERT_EFI_ERROR (Status);\r | |
179 | \r | |
180 | return Status;\r | |
181 | }\r | |
182 | \r | |
183 | \r |