]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c
MdeModulePkg: Add BootLogoLib to provide interfaces about logo display.
[mirror_edk2.git] / Nt32Pkg / Library / PlatformBootManagerLib / PlatformBootManager.c
CommitLineData
123e9f62
RN
1/** @file\r
2 This file include all platform action which can be customized\r
3 by IBV/OEM.\r
4\r
5Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "PlatformBootManager.h"\r
17\r
8f227c2f 18/**\r
703da8b4
RN
19 Perform the platform diagnostic, such like test memory. OEM/IBV also\r
20 can customize this function to support specific platform diagnostic.\r
8f227c2f 21\r
703da8b4
RN
22 @param MemoryTestLevel The memory test intensive level\r
23 @param QuietBoot Indicate if need to enable the quiet boot\r
8f227c2f
RN
24\r
25**/\r
703da8b4
RN
26VOID\r
27PlatformBootManagerDiagnostics (\r
28 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,\r
29 IN BOOLEAN QuietBoot\r
8f227c2f
RN
30 )\r
31{\r
703da8b4
RN
32 EFI_STATUS Status;\r
33\r
34 //\r
35 // Here we can decide if we need to show\r
36 // the diagnostics screen\r
37 // Notes: this quiet boot code should be remove\r
38 // from the graphic lib\r
39 //\r
40 if (QuietBoot) {\r
41 PlatformBootManagerEnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
8f227c2f 42\r
8f227c2f 43 //\r
703da8b4 44 // Perform system diagnostic\r
8f227c2f 45 //\r
703da8b4
RN
46 Status = PlatformBootManagerMemoryTest (MemoryTestLevel);\r
47 if (EFI_ERROR (Status)) {\r
48 PlatformBootManagerDisableQuietBoot ();\r
8f227c2f 49 }\r
8f227c2f 50\r
703da8b4
RN
51 return;\r
52 }\r
8f227c2f 53\r
703da8b4
RN
54 //\r
55 // Perform system diagnostic\r
56 //\r
57 Status = PlatformBootManagerMemoryTest (MemoryTestLevel);\r
8f227c2f
RN
58}\r
59\r
123e9f62
RN
60/**\r
61 Return the index of the load option in the load option array.\r
62\r
63 The function consider two load options are equal when the \r
64 OptionType, Attributes, Description, FilePath and OptionalData are equal.\r
65\r
66 @param Key Pointer to the load option to be found.\r
67 @param Array Pointer to the array of load options to be found.\r
68 @param Count Number of entries in the Array.\r
69\r
70 @retval -1 Key wasn't found in the Array.\r
71 @retval 0 ~ Count-1 The index of the Key in the Array.\r
72**/\r
73INTN\r
74PlatformFindLoadOption (\r
75 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,\r
76 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,\r
77 IN UINTN Count\r
78 )\r
79{\r
80 UINTN Index;\r
81\r
82 for (Index = 0; Index < Count; Index++) {\r
83 if ((Key->OptionType == Array[Index].OptionType) &&\r
84 (Key->Attributes == Array[Index].Attributes) &&\r
85 (StrCmp (Key->Description, Array[Index].Description) == 0) &&\r
86 (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) &&\r
87 (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&\r
88 (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) {\r
89 return (INTN) Index;\r
90 }\r
91 }\r
92\r
93 return -1;\r
94}\r
95\r
96VOID\r
97PlatformRegisterFvBootOption (\r
98 EFI_GUID *FileGuid,\r
99 CHAR16 *Description,\r
100 UINT32 Attributes\r
101 )\r
102{\r
103 EFI_STATUS Status;\r
104 UINTN OptionIndex;\r
105 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;\r
106 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
107 UINTN BootOptionCount;\r
108 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;\r
109 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
110 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
111\r
112 Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);\r
113 ASSERT_EFI_ERROR (Status);\r
114\r
115 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
116 DevicePath = AppendDevicePathNode (\r
117 DevicePathFromHandle (LoadedImage->DeviceHandle),\r
118 (EFI_DEVICE_PATH_PROTOCOL *) &FileNode\r
119 );\r
120\r
121 Status = EfiBootManagerInitializeLoadOption (\r
122 &NewOption,\r
123 LoadOptionNumberUnassigned,\r
124 LoadOptionTypeBoot,\r
125 Attributes,\r
126 Description,\r
127 DevicePath,\r
128 NULL,\r
129 0\r
130 );\r
131 if (!EFI_ERROR (Status)) {\r
132 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
133\r
134 OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount);\r
135\r
136 if (OptionIndex == -1) {\r
137 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);\r
138 ASSERT_EFI_ERROR (Status);\r
139 }\r
140 EfiBootManagerFreeLoadOption (&NewOption);\r
141 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
142 }\r
143}\r
144\r
145/**\r
146 Do the platform specific action before the console is connected.\r
147\r
148 Such as:\r
149 Update console variable;\r
150 Register new Driver#### or Boot####;\r
151 Signal ReadyToLock event.\r
152**/\r
153VOID\r
154EFIAPI\r
155PlatformBootManagerBeforeConsole (\r
156 VOID\r
157 )\r
158{\r
159 UINTN Index;\r
160 EFI_STATUS Status;\r
161 WIN_NT_SYSTEM_CONFIGURATION *Configuration;\r
162 EFI_INPUT_KEY Enter;\r
163 EFI_INPUT_KEY F2;\r
164 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
165\r
166 GetVariable2 (L"Setup", &gEfiWinNtSystemConfigGuid, (VOID **) &Configuration, NULL);\r
167 if (Configuration != NULL) {\r
168 //\r
169 // SetupVariable is corrupt\r
170 //\r
171 Configuration->ConOutRow = PcdGet32 (PcdConOutColumn);\r
172 Configuration->ConOutColumn = PcdGet32 (PcdConOutRow);\r
173\r
174 Status = gRT->SetVariable (\r
175 L"Setup",\r
176 &gEfiWinNtSystemConfigGuid,\r
177 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
178 sizeof (WIN_NT_SYSTEM_CONFIGURATION),\r
179 Configuration\r
180 );\r
181 if (EFI_ERROR (Status)) {\r
182 DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));\r
183 }\r
184 FreePool (Configuration);\r
185 }\r
186\r
187 //\r
188 // Update the ocnsole variables.\r
189 //\r
190 for (Index = 0; gPlatformConsole[Index].DevicePath != NULL; Index++) {\r
191 if ((gPlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
192 EfiBootManagerUpdateConsoleVariable (ConIn, gPlatformConsole[Index].DevicePath, NULL);\r
193 }\r
194\r
195 if ((gPlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
196 EfiBootManagerUpdateConsoleVariable (ConOut, gPlatformConsole[Index].DevicePath, NULL);\r
197 }\r
198\r
199 if ((gPlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
200 EfiBootManagerUpdateConsoleVariable (ErrOut, gPlatformConsole[Index].DevicePath, NULL);\r
201 }\r
202 }\r
203\r
204 //\r
205 // Register ENTER as CONTINUE key\r
206 //\r
207 Enter.ScanCode = SCAN_NULL;\r
208 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
209 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);\r
210 //\r
211 // Map F2 to Boot Manager Menu\r
212 //\r
213 F2.ScanCode = SCAN_F2;\r
214 F2.UnicodeChar = CHAR_NULL;\r
215 EfiBootManagerGetBootManagerMenu (&BootOption);\r
216 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);\r
217 //\r
218 // Register UEFI Shell\r
219 //\r
14ae1b35 220 PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE);\r
123e9f62
RN
221}\r
222\r
223/**\r
224 Do the platform specific action after the console is connected.\r
225\r
226 Such as:\r
227 Dynamically switch output mode;\r
228 Signal console ready platform customized event;\r
229 Run diagnostics like memory testing;\r
230 Connect certain devices;\r
231 Dispatch aditional option roms.\r
232**/\r
233VOID\r
234EFIAPI\r
235PlatformBootManagerAfterConsole (\r
236 VOID\r
237 )\r
238{\r
703da8b4
RN
239 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;\r
240 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;\r
241\r
242 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;\r
243 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;\r
244\r
99eda885
ED
245 EfiBootManagerConnectAll ();\r
246 EfiBootManagerRefreshAllBootOption ();\r
703da8b4
RN
247\r
248 PlatformBootManagerDiagnostics (QUICK, TRUE);\r
249 \r
250 PrintXY (10, 10, &White, &Black, L"F2 to enter Boot Manager Menu. ");\r
251 PrintXY (10, 30, &White, &Black, L"Enter to boot directly.");\r
123e9f62
RN
252}\r
253\r
254/**\r
255 This function is called each second during the boot manager waits the timeout.\r
256\r
257 @param TimeoutRemain The remaining timeout.\r
258**/\r
259VOID\r
260EFIAPI\r
261PlatformBootManagerWaitCallback (\r
262 UINT16 TimeoutRemain\r
263 )\r
264{\r
703da8b4
RN
265 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;\r
266 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;\r
267 UINT16 Timeout;\r
268\r
269 Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r
270\r
271 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;\r
272 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;\r
273\r
274 PlatformBootManagerShowProgress (\r
275 White,\r
276 Black,\r
277 L"Start boot option",\r
278 White,\r
279 (Timeout - TimeoutRemain) * 100 / Timeout,\r
280 0\r
281 );\r
123e9f62 282}\r