]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
MdeModulePkg/Bds: Support booting from remote file system.
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / InternalBm.h
CommitLineData
067ed98a
RN
1/** @file\r
2 BDS library definition, include the file and data structure\r
3\r
f5c12172 4Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
5d3a9896 5(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
067ed98a
RN
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#ifndef _INTERNAL_BM_H_\r
17#define _INTERNAL_BM_H_\r
18\r
19#include <PiDxe.h>\r
20\r
21#include <IndustryStandard/Pci.h>\r
22#include <IndustryStandard/PeImage.h>\r
23#include <IndustryStandard/Atapi.h>\r
24#include <IndustryStandard/Scsi.h>\r
25\r
26#include <Protocol/PciRootBridgeIo.h>\r
27#include <Protocol/BlockIo.h>\r
28#include <Protocol/LoadedImage.h>\r
29#include <Protocol/SimpleFileSystem.h>\r
30#include <Protocol/LoadFile.h>\r
31#include <Protocol/DevicePath.h>\r
32#include <Protocol/SimpleTextIn.h>\r
33#include <Protocol/SimpleTextInEx.h>\r
34#include <Protocol/SimpleTextOut.h>\r
35#include <Protocol/SimpleNetwork.h>\r
36#include <Protocol/FirmwareVolume2.h>\r
37#include <Protocol/PciIo.h>\r
38#include <Protocol/GraphicsOutput.h>\r
39#include <Protocol/UsbIo.h>\r
40#include <Protocol/DiskInfo.h>\r
41#include <Protocol/IdeControllerInit.h>\r
42#include <Protocol/BootLogo.h>\r
43#include <Protocol/DriverHealth.h>\r
44#include <Protocol/FormBrowser2.h>\r
780e05ca 45#include <Protocol/VariableLock.h>\r
067ed98a
RN
46\r
47#include <Guid/ZeroGuid.h>\r
48#include <Guid/MemoryTypeInformation.h>\r
49#include <Guid/FileInfo.h>\r
50#include <Guid/GlobalVariable.h>\r
51#include <Guid/Performance.h>\r
52#include <Guid/StatusCodeDataTypeVariable.h>\r
53\r
54#include <Library/PrintLib.h>\r
55#include <Library/DebugLib.h>\r
56#include <Library/BaseMemoryLib.h>\r
57#include <Library/UefiBootServicesTableLib.h>\r
58#include <Library/UefiRuntimeServicesTableLib.h>\r
59#include <Library/UefiLib.h>\r
60#include <Library/MemoryAllocationLib.h>\r
61#include <Library/DxeServicesTableLib.h>\r
62#include <Library/HobLib.h>\r
63#include <Library/BaseLib.h>\r
64#include <Library/DevicePathLib.h>\r
65#include <Library/PerformanceLib.h>\r
66#include <Library/PcdLib.h>\r
67#include <Library/PeCoffGetEntryPointLib.h>\r
68#include <Library/UefiBootManagerLib.h>\r
69#include <Library/TimerLib.h>\r
70#include <Library/DxeServicesLib.h>\r
71#include <Library/ReportStatusCodeLib.h>\r
72#include <Library/CapsuleLib.h>\r
73#include <Library/PerformanceLib.h>\r
74#include <Library/HiiLib.h>\r
75\r
76#if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)\r
77 #if defined (MDE_CPU_EBC)\r
78 //\r
79 // Uefi specification only defines the default boot file name for IA32, X64\r
80 // and IPF processor, so need define boot file name for EBC architecture here.\r
81 //\r
82 #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"\r
83 #else\r
84 #error "Can not determine the default boot file name for unknown processor type!"\r
85 #endif\r
86#endif\r
87\r
88typedef enum {\r
89 BmAcpiFloppyBoot,\r
90 BmHardwareDeviceBoot,\r
91 BmMessageAtapiBoot,\r
92 BmMessageSataBoot,\r
93 BmMessageUsbBoot,\r
94 BmMessageScsiBoot,\r
95 BmMessageNetworkBoot,\r
ebf735f1 96 BmMessageHttpBoot,\r
067ed98a
RN
97 BmMiscBoot\r
98} BM_BOOT_TYPE;\r
99\r
100typedef\r
101CHAR16 *\r
102(* BM_GET_BOOT_DESCRIPTION) (\r
103 IN EFI_HANDLE Handle\r
104 );\r
105\r
780e05ca
RN
106//\r
107// PlatformRecovery#### is the load option with the longest name\r
108//\r
109#define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")\r
067ed98a
RN
110extern CHAR16 *mBmLoadOptionName[];\r
111\r
d95ff8e8
RN
112/**\r
113 Visitor function to be called by BmForEachVariable for each variable\r
114 in variable storage.\r
115\r
116 @param Name Variable name.\r
117 @param Guid Variable GUID.\r
118 @param Context The same context passed to BmForEachVariable.\r
119**/\r
067ed98a
RN
120typedef\r
121VOID\r
d95ff8e8 122(*BM_VARIABLE_VISITOR) (\r
067ed98a
RN
123 CHAR16 *Name,\r
124 EFI_GUID *Guid,\r
125 VOID *Context\r
126 );\r
127\r
128/**\r
129 Call Visitor function for each variable in variable storage.\r
130\r
131 @param Visitor Visitor function.\r
132 @param Context The context passed to Visitor function.\r
133**/\r
134VOID\r
d95ff8e8
RN
135BmForEachVariable (\r
136 BM_VARIABLE_VISITOR Visitor,\r
067ed98a
RN
137 VOID *Context\r
138 );\r
139\r
f41c71d2
RN
140#define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')\r
141typedef struct {\r
142 UINT32 Signature;\r
143 LIST_ENTRY Link;\r
144 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler;\r
145} BM_BOOT_DESCRIPTION_ENTRY;\r
146\r
067ed98a
RN
147/**\r
148 Repair all the controllers according to the Driver Health status queried.\r
149**/\r
150VOID\r
151BmRepairAllControllers (\r
152 VOID\r
153 );\r
154\r
155#define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')\r
156typedef struct {\r
157 UINT32 Signature;\r
158 LIST_ENTRY Link;\r
159\r
160 BOOLEAN IsContinue;\r
161 UINT16 BootOption;\r
162 UINT8 CodeCount;\r
163 UINT8 WaitingKey;\r
164 EFI_KEY_DATA KeyData[3];\r
165} BM_HOTKEY;\r
166\r
167#define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)\r
168\r
169/**\r
170 Get the image file buffer data and buffer size by its device path. \r
171\r
172 @param FilePath On input, a pointer to an allocated buffer containing the device\r
173 path of the file.\r
174 On output the pointer could be NULL when the function fails to\r
175 load the boot option, or could point to an allocated buffer containing\r
176 the device path of the file.\r
177 It could be updated by either short-form device path expanding,\r
178 or default boot file path appending.\r
179 Caller is responsible to free it when it's non-NULL.\r
180 @param FileSize A pointer to the size of the file buffer.\r
181\r
182 @retval NULL File is NULL, or FileSize is NULL. Or, the file can't be found.\r
183 @retval other The file buffer. The caller is responsible to free the memory.\r
184**/\r
185VOID *\r
186BmLoadEfiBootOption (\r
187 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
188 OUT UINTN *FileSize\r
189 );\r
190\r
191/**\r
192 Get the Option Number that wasn't used.\r
193\r
194 @param LoadOptionType Load option type.\r
195 @param FreeOptionNumber To receive the minimal free option number.\r
196\r
197 @retval EFI_SUCCESS The option number is found\r
198 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.\r
199 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL\r
200\r
201**/\r
202EFI_STATUS\r
203BmGetFreeOptionNumber (\r
204 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,\r
205 OUT UINT16 *FreeOptionNumber\r
206 );\r
207\r
208/**\r
209\r
210 Writes performance data of booting into the allocated memory.\r
211 OS can process these records.\r
212\r
213 @param Event The triggered event.\r
214 @param Context Context for this event.\r
215\r
216**/\r
217VOID\r
218EFIAPI\r
219BmWriteBootToOsPerformanceData (\r
220 IN EFI_EVENT Event,\r
221 IN VOID *Context\r
222 );\r
223\r
224\r
225/**\r
226 Get the headers (dos, image, optional header) from an image\r
227\r
228 @param Device SimpleFileSystem device handle\r
229 @param FileName File name for the image\r
230 @param DosHeader Pointer to dos header\r
231 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.\r
232\r
233 @retval EFI_SUCCESS Successfully get the machine type.\r
234 @retval EFI_NOT_FOUND The file is not found.\r
235 @retval EFI_LOAD_ERROR File is not a valid image file.\r
236\r
237**/\r
238EFI_STATUS\r
239BmGetImageHeader (\r
240 IN EFI_HANDLE Device,\r
241 IN CHAR16 *FileName,\r
242 OUT EFI_IMAGE_DOS_HEADER *DosHeader,\r
243 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
244 );\r
245\r
246/**\r
247 This routine adjust the memory information for different memory type and \r
665b26ba
RN
248 save them into the variables for next boot. It resets the system when\r
249 memory information is updated and the current boot option belongs to\r
250 boot category instead of application category.\r
251\r
252 @param Boot TRUE if current boot option belongs to boot category instead of\r
253 application category.\r
067ed98a
RN
254**/\r
255VOID\r
256BmSetMemoryTypeInformationVariable (\r
665b26ba 257 IN BOOLEAN Boot\r
067ed98a
RN
258 );\r
259\r
260/**\r
261 Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r
262 instances, has the same partition node with HardDriveDevicePath device path\r
263\r
264 @param BlockIoDevicePath Multi device path instances which need to check\r
265 @param HardDriveDevicePath A device path which starts with a hard drive media\r
266 device path.\r
267\r
268 @retval TRUE There is a matched device path instance.\r
269 @retval FALSE There is no matched device path instance.\r
270\r
271**/\r
272BOOLEAN\r
273BmMatchPartitionDevicePathNode (\r
274 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,\r
275 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
276 );\r
277\r
278/**\r
279 Connect the specific Usb device which match the short form device path.\r
280\r
281 @param DevicePath A short-form device path that starts with the first\r
282 element being a USB WWID or a USB Class device\r
283 path\r
284\r
285 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.\r
286 DevicePath is not a USB device path.\r
287\r
288 @return EFI_SUCCESS Success to connect USB device\r
289 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.\r
290\r
291**/\r
292EFI_STATUS\r
293BmConnectUsbShortFormDevicePath (\r
294 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
295 );\r
296\r
297/**\r
298 Stop the hotkey processing.\r
299 \r
300 @param Event Event pointer related to hotkey service. \r
301 @param Context Context pass to this function. \r
302**/\r
303VOID\r
304EFIAPI\r
305BmStopHotkeyService (\r
306 IN EFI_EVENT Event,\r
307 IN VOID *Context\r
308 );\r
309\r
310/**\r
311 Set the variable and report the error through status code upon failure.\r
312\r
313 @param VariableName A Null-terminated string that is the name of the vendor's variable.\r
314 Each VariableName is unique for each VendorGuid. VariableName must\r
315 contain 1 or more characters. If VariableName is an empty string,\r
316 then EFI_INVALID_PARAMETER is returned.\r
317 @param VendorGuid A unique identifier for the vendor.\r
318 @param Attributes Attributes bitmask to set for the variable.\r
319 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
320 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
321 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
322 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
323 set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
324 the variable value (the timestamp associated with the variable may be updated however \r
325 even if no new data value is provided,see the description of the \r
326 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not \r
327 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). \r
328 @param Data The contents for the variable.\r
329\r
330 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r
331 defined by the Attributes.\r
332 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the\r
333 DataSize exceeds the maximum allowed.\r
334 @retval EFI_INVALID_PARAMETER VariableName is an empty string.\r
335 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
336 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r
337 @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r
338 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r
339 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
340 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
341 does NOT pass the validation check carried out by the firmware.\r
342\r
343 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
344**/\r
345EFI_STATUS\r
346BmSetVariableAndReportStatusCodeOnError (\r
347 IN CHAR16 *VariableName,\r
348 IN EFI_GUID *VendorGuid,\r
349 IN UINT32 Attributes,\r
350 IN UINTN DataSize,\r
351 IN VOID *Data\r
352 );\r
353\r
354/**\r
355 Get the load option by its device path.\r
356\r
357 @param FilePath The device path pointing to a load option.\r
358 It could be a short-form device path.\r
359 @param FullPath Return the full device path of the load option after\r
360 short-form device path expanding.\r
361 Caller is responsible to free it.\r
362 @param FileSize Return the load option size.\r
363\r
364 @return The load option buffer. Caller is responsible to free the memory.\r
365**/\r
366VOID *\r
367BmGetLoadOptionBuffer (\r
368 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
369 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
370 OUT UINTN *FileSize\r
371 );\r
372\r
373/**\r
374 Return whether the PE header of the load option is valid or not.\r
375\r
376 @param[in] Type The load option type.\r
377 @param[in] FileBuffer The PE file buffer of the load option.\r
378 @param[in] FileSize The size of the load option file.\r
379\r
380 @retval TRUE The PE header of the load option is valid.\r
381 @retval FALSE The PE header of the load option is not valid.\r
382**/\r
383BOOLEAN\r
384BmIsLoadOptionPeHeaderValid (\r
385 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,\r
386 IN VOID *FileBuffer,\r
387 IN UINTN FileSize\r
388 );\r
389\r
390/**\r
391 Function compares a device path data structure to that of all the nodes of a\r
392 second device path instance.\r
393\r
394 @param Multi A pointer to a multi-instance device path data\r
395 structure.\r
396 @param Single A pointer to a single-instance device path data\r
397 structure.\r
398\r
399 @retval TRUE If the Single device path is contained within Multi device path.\r
400 @retval FALSE The Single device path is not match within Multi device path.\r
401\r
402**/\r
403BOOLEAN\r
404BmMatchDevicePaths (\r
405 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
406 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
407 );\r
408\r
409/**\r
410 Delete the instance in Multi which matches partly with Single instance\r
411\r
412 @param Multi A pointer to a multi-instance device path data\r
413 structure.\r
414 @param Single A pointer to a single-instance device path data\r
415 structure.\r
416\r
417 @return This function will remove the device path instances in Multi which partly\r
418 match with the Single, and return the result device path. If there is no\r
419 remaining device path as a result, this function will return NULL.\r
420\r
421**/\r
422EFI_DEVICE_PATH_PROTOCOL *\r
423BmDelPartMatchInstance (\r
424 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
425 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
426 );\r
427\r
067ed98a
RN
428/**\r
429 Repair all the controllers according to the Driver Health status queried.\r
430**/\r
431VOID\r
432BmRepairAllControllers (\r
433 VOID\r
434 );\r
435\r
436/**\r
437 Print the device path info.\r
438\r
439 @param DevicePath The device path need to print.\r
440**/\r
441VOID\r
442BmPrintDp (\r
443 EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
444 );\r
445\r
418e8cd9
RN
446/**\r
447 Convert a single character to number.\r
448 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r
449\r
450 @param Char The input char which need to convert to int.\r
451\r
452 @return The converted 8-bit number or (UINTN) -1 if conversion failed.\r
453**/\r
454UINTN\r
455BmCharToUint (\r
456 IN CHAR16 Char\r
457 );\r
458\r
f5c12172
RN
459\r
460/**\r
461 Get the file buffer from the file system produced by Load File instance.\r
462\r
463 @param LoadFileHandle The handle of LoadFile instance.\r
464 @param FullPath Return the full device path pointing to the load option.\r
465 @param FileSize Return the size of the load option.\r
466\r
467 @return The load option buffer.\r
468**/\r
469VOID *\r
470BmGetFileBufferFromLoadFileFileSystem (\r
471 IN EFI_HANDLE LoadFileHandle,\r
472 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
473 OUT UINTN *FileSize\r
474 );\r
067ed98a 475#endif // _INTERNAL_BM_H_\r