]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
CorebootModulePkg: Add a library to parse platform specific info.
[mirror_edk2.git] / CorebootPayloadPkg / Library / PlatformBootManagerLib / PlatformBootManager.c
CommitLineData
42a8f2ce
MM
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#include "PlatformConsole.h"\r
18\r
19/**\r
20 Return the index of the load option in the load option array.\r
21\r
22 The function consider two load options are equal when the\r
23 OptionType, Attributes, Description, FilePath and OptionalData are equal.\r
24\r
25 @param Key Pointer to the load option to be found.\r
26 @param Array Pointer to the array of load options to be found.\r
27 @param Count Number of entries in the Array.\r
28\r
29 @retval -1 Key wasn't found in the Array.\r
30 @retval 0 ~ Count-1 The index of the Key in the Array.\r
31**/\r
32INTN\r
33PlatformFindLoadOption (\r
34 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,\r
35 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,\r
36 IN UINTN Count\r
37)\r
38{\r
39 UINTN Index;\r
40\r
41 for (Index = 0; Index < Count; Index++) {\r
42 if ((Key->OptionType == Array[Index].OptionType) &&\r
43 (Key->Attributes == Array[Index].Attributes) &&\r
44 (StrCmp (Key->Description, Array[Index].Description) == 0) &&\r
45 (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) &&\r
46 (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&\r
47 (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) {\r
48 return (INTN) Index;\r
49 }\r
50 }\r
51\r
52 return -1;\r
53}\r
54\r
55/**\r
56 Register a boot option using a file GUID in the FV.\r
57\r
58 @param FileGuid The file GUID name in FV.\r
59 @param Description The boot option description.\r
60 @param Attributes The attributes used for the boot option loading.\r
61**/\r
62VOID\r
63PlatformRegisterFvBootOption (\r
64 EFI_GUID *FileGuid,\r
65 CHAR16 *Description,\r
66 UINT32 Attributes\r
67)\r
68{\r
69 EFI_STATUS Status;\r
70 UINTN OptionIndex;\r
71 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;\r
72 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
73 UINTN BootOptionCount;\r
74 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;\r
75 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
76 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
77\r
78 Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);\r
79 ASSERT_EFI_ERROR (Status);\r
80\r
81 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
82 DevicePath = AppendDevicePathNode (\r
83 DevicePathFromHandle (LoadedImage->DeviceHandle),\r
84 (EFI_DEVICE_PATH_PROTOCOL *) &FileNode\r
85 );\r
86\r
87 Status = EfiBootManagerInitializeLoadOption (\r
88 &NewOption,\r
89 LoadOptionNumberUnassigned,\r
90 LoadOptionTypeBoot,\r
91 Attributes,\r
92 Description,\r
93 DevicePath,\r
94 NULL,\r
95 0\r
96 );\r
97 if (!EFI_ERROR (Status)) {\r
98 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
99\r
100 OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount);\r
101\r
102 if (OptionIndex == -1) {\r
103 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);\r
104 ASSERT_EFI_ERROR (Status);\r
105 }\r
106 EfiBootManagerFreeLoadOption (&NewOption);\r
107 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
108 }\r
109}\r
110\r
111/**\r
112 Do the platform specific action before the console is connected.\r
113\r
114 Such as:\r
115 Update console variable;\r
116 Register new Driver#### or Boot####;\r
117 Signal ReadyToLock event.\r
118**/\r
119VOID\r
120EFIAPI\r
121PlatformBootManagerBeforeConsole (\r
122 VOID\r
123)\r
124{\r
125 EFI_INPUT_KEY Enter;\r
126 EFI_INPUT_KEY F2;\r
127 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
128\r
129 PlatformConsoleInit ();\r
130\r
131 //\r
132 // Register ENTER as CONTINUE key\r
133 //\r
134 Enter.ScanCode = SCAN_NULL;\r
135 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
136 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);\r
137\r
138 //\r
139 // Map F2 to Boot Manager Menu\r
140 //\r
141 F2.ScanCode = SCAN_F2;\r
142 F2.UnicodeChar = CHAR_NULL;\r
143 EfiBootManagerGetBootManagerMenu (&BootOption);\r
144 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);\r
145\r
146 //\r
147 // Register UEFI Shell\r
148 //\r
149 PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE);\r
150}\r
151\r
152/**\r
153 Do the platform specific action after the console is connected.\r
154\r
155 Such as:\r
156 Dynamically switch output mode;\r
157 Signal console ready platform customized event;\r
158 Run diagnostics like memory testing;\r
159 Connect certain devices;\r
160 Dispatch aditional option roms.\r
161**/\r
162VOID\r
163EFIAPI\r
164PlatformBootManagerAfterConsole (\r
165 VOID\r
166)\r
167{\r
168 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;\r
169 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;\r
170\r
171 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;\r
172 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;\r
173\r
174 EfiBootManagerConnectAll ();\r
175 EfiBootManagerRefreshAllBootOption ();\r
176\r
177 Print (\r
178 L"\n"\r
179 L"F2 to enter Boot Manager Menu.\n"\r
180 L"ENTER to boot directly.\n"\r
181 L"\n"\r
182 );\r
183\r
184}\r
185\r
186/**\r
187 This function is called each second during the boot manager waits the timeout.\r
188\r
189 @param TimeoutRemain The remaining timeout.\r
190**/\r
191VOID\r
192EFIAPI\r
193PlatformBootManagerWaitCallback (\r
194 UINT16 TimeoutRemain\r
195)\r
196{\r
197 return;\r
198}\r