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