]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c
Nt32Pkg: Add PlatformBootManagerLib to Nt32 platform.
[mirror_edk2.git] / Nt32Pkg / Library / PlatformBootManagerLib / PlatformBootManager.c
... / ...
CommitLineData
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
18\r
19EFI_GUID mUefiShellFileGuid = { 0x7C04A583, 0x9E3E, 0x4f1c, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 };\r
20\r
21/**\r
22 Return the index of the load option in the load option array.\r
23\r
24 The function consider two load options are equal when the \r
25 OptionType, Attributes, Description, FilePath and OptionalData are equal.\r
26\r
27 @param Key Pointer to the load option to be found.\r
28 @param Array Pointer to the array of load options to be found.\r
29 @param Count Number of entries in the Array.\r
30\r
31 @retval -1 Key wasn't found in the Array.\r
32 @retval 0 ~ Count-1 The index of the Key in the Array.\r
33**/\r
34INTN\r
35PlatformFindLoadOption (\r
36 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,\r
37 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,\r
38 IN UINTN Count\r
39 )\r
40{\r
41 UINTN Index;\r
42\r
43 for (Index = 0; Index < Count; Index++) {\r
44 if ((Key->OptionType == Array[Index].OptionType) &&\r
45 (Key->Attributes == Array[Index].Attributes) &&\r
46 (StrCmp (Key->Description, Array[Index].Description) == 0) &&\r
47 (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) &&\r
48 (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&\r
49 (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) {\r
50 return (INTN) Index;\r
51 }\r
52 }\r
53\r
54 return -1;\r
55}\r
56\r
57VOID\r
58PlatformRegisterFvBootOption (\r
59 EFI_GUID *FileGuid,\r
60 CHAR16 *Description,\r
61 UINT32 Attributes\r
62 )\r
63{\r
64 EFI_STATUS Status;\r
65 UINTN OptionIndex;\r
66 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;\r
67 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
68 UINTN BootOptionCount;\r
69 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;\r
70 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
71 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
72\r
73 Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);\r
74 ASSERT_EFI_ERROR (Status);\r
75\r
76 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
77 DevicePath = AppendDevicePathNode (\r
78 DevicePathFromHandle (LoadedImage->DeviceHandle),\r
79 (EFI_DEVICE_PATH_PROTOCOL *) &FileNode\r
80 );\r
81\r
82 Status = EfiBootManagerInitializeLoadOption (\r
83 &NewOption,\r
84 LoadOptionNumberUnassigned,\r
85 LoadOptionTypeBoot,\r
86 Attributes,\r
87 Description,\r
88 DevicePath,\r
89 NULL,\r
90 0\r
91 );\r
92 if (!EFI_ERROR (Status)) {\r
93 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
94\r
95 OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount);\r
96\r
97 if (OptionIndex == -1) {\r
98 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);\r
99 ASSERT_EFI_ERROR (Status);\r
100 }\r
101 EfiBootManagerFreeLoadOption (&NewOption);\r
102 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
103 }\r
104}\r
105\r
106/**\r
107 Do the platform specific action before the console is connected.\r
108\r
109 Such as:\r
110 Update console variable;\r
111 Register new Driver#### or Boot####;\r
112 Signal ReadyToLock event.\r
113**/\r
114VOID\r
115EFIAPI\r
116PlatformBootManagerBeforeConsole (\r
117 VOID\r
118 )\r
119{\r
120 UINTN Index;\r
121 EFI_STATUS Status;\r
122 WIN_NT_SYSTEM_CONFIGURATION *Configuration;\r
123 EFI_INPUT_KEY Enter;\r
124 EFI_INPUT_KEY F2;\r
125 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
126\r
127 GetVariable2 (L"Setup", &gEfiWinNtSystemConfigGuid, (VOID **) &Configuration, NULL);\r
128 if (Configuration != NULL) {\r
129 //\r
130 // SetupVariable is corrupt\r
131 //\r
132 Configuration->ConOutRow = PcdGet32 (PcdConOutColumn);\r
133 Configuration->ConOutColumn = PcdGet32 (PcdConOutRow);\r
134\r
135 Status = gRT->SetVariable (\r
136 L"Setup",\r
137 &gEfiWinNtSystemConfigGuid,\r
138 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
139 sizeof (WIN_NT_SYSTEM_CONFIGURATION),\r
140 Configuration\r
141 );\r
142 if (EFI_ERROR (Status)) {\r
143 DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));\r
144 }\r
145 FreePool (Configuration);\r
146 }\r
147\r
148 //\r
149 // Update the ocnsole variables.\r
150 //\r
151 for (Index = 0; gPlatformConsole[Index].DevicePath != NULL; Index++) {\r
152 if ((gPlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
153 EfiBootManagerUpdateConsoleVariable (ConIn, gPlatformConsole[Index].DevicePath, NULL);\r
154 }\r
155\r
156 if ((gPlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
157 EfiBootManagerUpdateConsoleVariable (ConOut, gPlatformConsole[Index].DevicePath, NULL);\r
158 }\r
159\r
160 if ((gPlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
161 EfiBootManagerUpdateConsoleVariable (ErrOut, gPlatformConsole[Index].DevicePath, NULL);\r
162 }\r
163 }\r
164\r
165 //\r
166 // Register ENTER as CONTINUE key\r
167 //\r
168 Enter.ScanCode = SCAN_NULL;\r
169 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
170 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);\r
171 //\r
172 // Map F2 to Boot Manager Menu\r
173 //\r
174 F2.ScanCode = SCAN_F2;\r
175 F2.UnicodeChar = CHAR_NULL;\r
176 EfiBootManagerGetBootManagerMenu (&BootOption);\r
177 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);\r
178 //\r
179 // Register UEFI Shell\r
180 //\r
181 PlatformRegisterFvBootOption (&mUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE);\r
182}\r
183\r
184/**\r
185 Do the platform specific action after the console is connected.\r
186\r
187 Such as:\r
188 Dynamically switch output mode;\r
189 Signal console ready platform customized event;\r
190 Run diagnostics like memory testing;\r
191 Connect certain devices;\r
192 Dispatch aditional option roms.\r
193**/\r
194VOID\r
195EFIAPI\r
196PlatformBootManagerAfterConsole (\r
197 VOID\r
198 )\r
199{\r
200 Print (\r
201 L"\n"\r
202 L"F2 to enter Boot Manager Menu.\n"\r
203 L"Enter to boot directly.\n"\r
204 L"\n"\r
205 );\r
206}\r
207\r
208/**\r
209 This function is called each second during the boot manager waits the timeout.\r
210\r
211 @param TimeoutRemain The remaining timeout.\r
212**/\r
213VOID\r
214EFIAPI\r
215PlatformBootManagerWaitCallback (\r
216 UINT16 TimeoutRemain\r
217 )\r
218{\r
219 Print (L"\r%-2d seconds remained...", TimeoutRemain);\r
220}\r