/** @file\r
Load option library functions which relate with creating and processing load options.\r
\r
-Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
-(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
OUT UINT16 *FreeOptionNumber\r
)\r
{\r
- \r
+\r
UINTN OptionNumber;\r
UINTN Index;\r
UINT16 *OptionOrder;\r
UINT16 *BootNext;\r
\r
ASSERT (FreeOptionNumber != NULL);\r
- ASSERT (LoadOptionType == LoadOptionTypeDriver || \r
+ ASSERT (LoadOptionType == LoadOptionTypeDriver ||\r
LoadOptionType == LoadOptionTypeBoot ||\r
LoadOptionType == LoadOptionTypeSysPrep);\r
\r
GetEfiGlobalVariable2 (L"BootNext", (VOID**) &BootNext, NULL);\r
}\r
\r
- for (OptionNumber = 0; \r
+ for (OptionNumber = 0;\r
OptionNumber < OptionOrderSize / sizeof (UINT16)\r
- + ((BootNext != NULL) ? 1 : 0); \r
+ + ((BootNext != NULL) ? 1 : 0);\r
OptionNumber++\r
) {\r
//\r
}\r
\r
//\r
- // We didn't find it in the ****Order array and it doesn't equal to BootNext \r
+ // We didn't find it in the ****Order array and it doesn't equal to BootNext\r
// Otherwise, OptionNumber equals to OptionOrderSize / sizeof (UINT16) + 1\r
//\r
- if ((Index == OptionOrderSize / sizeof (UINT16)) && \r
+ if ((Index == OptionOrderSize / sizeof (UINT16)) &&\r
((BootNext == NULL) || (OptionNumber != *BootNext))\r
) {\r
break;\r
EFI_DEVICE_PATH_PROTOCOL FilePathList[];\r
UINT8 OptionalData[];\r
TODO: FilePathList[] IS:\r
-A packed array of UEFI device paths. The first element of the \r
-array is a device path that describes the device and location of the \r
-Image for this load option. The FilePathList[0] is specific \r
-to the device type. Other device paths may optionally exist in the \r
-FilePathList, but their usage is OSV specific. Each element \r
-in the array is variable length, and ends at the device path end \r
+A packed array of UEFI device paths. The first element of the\r
+array is a device path that describes the device and location of the\r
+Image for this load option. The FilePathList[0] is specific\r
+to the device type. Other device paths may optionally exist in the\r
+FilePathList, but their usage is OSV specific. Each element\r
+in the array is variable length, and ends at the device path end\r
structure.\r
*/\r
VariableSize = sizeof (Option->Attributes)\r
VariableAttributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;\r
}\r
\r
- return gRT->SetVariable (\r
- OptionName,\r
- &gEfiGlobalVariableGuid,\r
- VariableAttributes,\r
- VariableSize,\r
- Variable\r
- );\r
+ Status = gRT->SetVariable (\r
+ OptionName,\r
+ &gEfiGlobalVariableGuid,\r
+ VariableAttributes,\r
+ VariableSize,\r
+ Variable\r
+ );\r
+ FreePool (Variable);\r
+\r
+ return Status;\r
}\r
\r
/**\r
This function will register the new Boot####, Driver#### or SysPrep#### option.\r
After the *#### is updated, the *Order will also be updated.\r
\r
- @param Option Pointer to load option to add.\r
+ @param Option Pointer to load option to add. If on input\r
+ Option->OptionNumber is LoadOptionNumberUnassigned,\r
+ then on output Option->OptionNumber is updated to\r
+ the number of the new Boot####,\r
+ Driver#### or SysPrep#### option.\r
@param Position Position of the new load option to put in the ****Order variable.\r
\r
@retval EFI_SUCCESS The *#### have been successfully registered.\r
Note: this API only adds new load option, no replacement support.\r
@retval EFI_OUT_OF_RESOURCES There is no free option number that can be used when the\r
option number specified in the Option is LoadOptionNumberUnassigned.\r
- @retval EFI_STATUS Return the status of gRT->SetVariable ().\r
+ @return Status codes of gRT->SetVariable ().\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
EfiBootManagerAddLoadOptionVariable (\r
- IN EFI_BOOT_MANAGER_LOAD_OPTION *Option,\r
- IN UINTN Position\r
+ IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option,\r
+ IN UINTN Position\r
)\r
{\r
EFI_STATUS Status;\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if (Option->OptionType != LoadOptionTypeDriver && \r
+ if (Option->OptionType != LoadOptionTypeDriver &&\r
Option->OptionType != LoadOptionTypeSysPrep &&\r
Option->OptionType != LoadOptionTypeBoot\r
) {\r
}\r
\r
/**\r
- Sort the load option. The DriverOrder or BootOrder will be re-created to \r
+ Sort the load option. The DriverOrder or BootOrder will be re-created to\r
reflect the new order.\r
\r
@param OptionType Load option type\r
/**\r
Return the index of the load option in the load option array.\r
\r
- The function consider two load options are equal when the \r
+ The function consider two load options are equal when the\r
OptionType, Attributes, Description, FilePath and OptionalData are equal.\r
\r
@param Key Pointer to the load option to be found.\r
/**\r
Returns the size of a device path in bytes.\r
\r
- This function returns the size, in bytes, of the device path data structure \r
- specified by DevicePath including the end of device path node. If DevicePath \r
+ This function returns the size, in bytes, of the device path data structure\r
+ specified by DevicePath including the end of device path node. If DevicePath\r
is NULL, then 0 is returned. If the length of the device path is bigger than\r
MaxSize, also return 0 to indicate this is an invalidate device path.\r
\r
@param DevicePath A pointer to a device path data structure.\r
- @param MaxSize Max valid device path size. If big than this size, \r
+ @param MaxSize Max valid device path size. If big than this size,\r
return error.\r
- \r
+\r
@retval 0 An invalid device path.\r
@retval Others The size of a device path in bytes.\r
\r
}\r
\r
/**\r
- Returns the length of a Null-terminated Unicode string. If the length is \r
- bigger than MaxStringLen, return length 0 to indicate that this is an \r
+ Returns the length of a Null-terminated Unicode string. If the length is\r
+ bigger than MaxStringLen, return length 0 to indicate that this is an\r
invalidate string.\r
\r
This function returns the number of Unicode characters in the Null-terminated\r
- Unicode string specified by String. \r
+ Unicode string specified by String.\r
\r
If String is NULL, then ASSERT().\r
If String is not aligned on a 16-bit boundary, then ASSERT().\r
@retval FALSE The variable data is corrupted.\r
\r
**/\r
-BOOLEAN \r
+BOOLEAN\r
BmValidateOption (\r
UINT8 *Variable,\r
UINTN VariableSize\r
UINTN VariableNameLen;\r
UINTN Index;\r
UINTN Uint;\r
+ EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LocalOptionType;\r
+ UINT16 LocalOptionNumber;\r
\r
if (VariableName == NULL) {\r
return FALSE;\r
\r
VariableNameLen = StrLen (VariableName);\r
\r
+ //\r
+ // Return FALSE when the variable name length is too small.\r
+ //\r
if (VariableNameLen <= 4) {\r
return FALSE;\r
}\r
\r
- for (Index = 0; Index < ARRAY_SIZE (mBmLoadOptionName); Index++) {\r
- if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[Index])) &&\r
- (StrnCmp (VariableName, mBmLoadOptionName[Index], VariableNameLen - 4) == 0)\r
+ //\r
+ // Return FALSE when the variable name doesn't start with Driver/SysPrep/Boot/PlatformRecovery.\r
+ //\r
+ for (LocalOptionType = 0; LocalOptionType < ARRAY_SIZE (mBmLoadOptionName); LocalOptionType++) {\r
+ if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[LocalOptionType])) &&\r
+ (StrnCmp (VariableName, mBmLoadOptionName[LocalOptionType], VariableNameLen - 4) == 0)\r
) {\r
break;\r
}\r
}\r
+ if (LocalOptionType == ARRAY_SIZE (mBmLoadOptionName)) {\r
+ return FALSE;\r
+ }\r
\r
- if (Index == ARRAY_SIZE (mBmLoadOptionName)) {\r
+ //\r
+ // Return FALSE when the last four characters are not hex digits.\r
+ //\r
+ LocalOptionNumber = 0;\r
+ for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {\r
+ Uint = BmCharToUint (VariableName[Index]);\r
+ if (Uint == -1) {\r
+ break;\r
+ } else {\r
+ LocalOptionNumber = (UINT16) Uint + LocalOptionNumber * 0x10;\r
+ }\r
+ }\r
+ if (Index != VariableNameLen) {\r
return FALSE;\r
}\r
\r
if (OptionType != NULL) {\r
- *OptionType = (EFI_BOOT_MANAGER_LOAD_OPTION_TYPE) Index;\r
+ *OptionType = LocalOptionType;\r
}\r
\r
if (OptionNumber != NULL) {\r
- *OptionNumber = 0;\r
- for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {\r
- Uint = BmCharToUint (VariableName[Index]);\r
- if (Uint == -1) {\r
- break;\r
- } else {\r
- *OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;\r
- }\r
- }\r
+ *OptionNumber = LocalOptionNumber;\r
}\r
\r
- return (BOOLEAN) (Index == VariableNameLen);\r
+ return TRUE;\r
}\r
\r
/**\r
EfiBootManagerVariableToLoadOptionEx (\r
IN CHAR16 *VariableName,\r
IN EFI_GUID *VendorGuid,\r
- IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option \r
+ IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option\r
)\r
{\r
EFI_STATUS Status;\r
/**\r
Returns an array of load options based on the EFI variable\r
L"BootOrder"/L"DriverOrder" and the L"Boot####"/L"Driver####" variables impled by it.\r
- #### is the hex value of the UINT16 in each BootOrder/DriverOrder entry. \r
+ #### is the hex value of the UINT16 in each BootOrder/DriverOrder entry.\r
\r
@param LoadOptionCount Returns number of entries in the array.\r
@param LoadOptionType The type of the load option.\r
\r
@param LoadOption Pointer to boot option to Free.\r
\r
- @return EFI_SUCCESS BootOption was freed \r
- @return EFI_NOT_FOUND BootOption == NULL \r
+ @return EFI_SUCCESS BootOption was freed\r
+ @return EFI_NOT_FOUND BootOption == NULL\r
\r
**/\r
EFI_STATUS\r
}\r
\r
/**\r
- Free an EFI_BOOT_MANGER_LOAD_OPTION array that was allocated by \r
+ Free an EFI_BOOT_MANGER_LOAD_OPTION array that was allocated by\r
EfiBootManagerGetLoadOptions().\r
\r
@param Option Pointer to boot option array to free.\r
@param OptionCount Number of array entries in BootOption\r
\r
- @return EFI_SUCCESS BootOption was freed \r
- @return EFI_NOT_FOUND BootOption == NULL \r
+ @return EFI_SUCCESS BootOption was freed\r
+ @return EFI_NOT_FOUND BootOption == NULL\r
\r
**/\r
EFI_STATUS\r
// Check PE32 or PE32+ magic, and machine type\r
//\r
OptionalHeader = (EFI_IMAGE_OPTIONAL_HEADER32 *) &PeHeader->Pe32.OptionalHeader;\r
- if ((OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC || \r
+ if ((OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ||\r
OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) &&\r
EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeHeader->Pe32.FileHeader.Machine)\r
) {\r
\r
@param LoadOption Pointer to the load option.\r
\r
- @retval EFI_INVALID_PARAMETER The load option type is invalid, \r
+ @retval EFI_INVALID_PARAMETER The load option type is invalid,\r
or the load option file path doesn't point to a valid file.\r
@retval EFI_UNSUPPORTED The load option type is of LoadOptionTypeBoot.\r
@retval EFI_SUCCESS The load option is inactive, or successfully loaded and executed.\r