CopyMem (&((BDS_LOADER_OPTIONAL_DATA*)EfiLoadOptionPtr)->Arguments, BootArguments, AsciiStrSize(BootArguments));\r
BootOption->OptionalData = (BDS_LOADER_OPTIONAL_DATA *)EfiLoadOptionPtr;\r
\r
+ // If this function is called at the creation of the Boot Device entry (not at the update) the\r
+ // BootOption->LoadOptionSize must be zero then we get a new BootIndex for this entry\r
+ if (BootOption->LoadOptionSize == 0) {\r
+ BootOption->LoadOptionIndex = BootOptionAllocateBootIndex();\r
+ }\r
+\r
// Fill the EFI Load option fields\r
- BootOption->LoadOptionIndex = BootOptionAllocateBootIndex();\r
BootOption->LoadOption = EfiLoadOption;\r
BootOption->LoadOptionSize = EfiLoadOptionSize;\r
\r
)\r
{\r
EFI_STATUS Status;\r
- BDS_LOAD_OPTION *BootOption;\r
CHAR16 BootVariableName[9];\r
\r
// Update the BDS Load Option structure\r
BootOptionSetFields (BdsLoadOption, Attributes, BootDescription, DevicePath, BootType, BootArguments);\r
\r
// Update the related environment variables\r
- UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOption->LoadOptionIndex);\r
+ UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BdsLoadOption->LoadOptionIndex);\r
+\r
Status = gRT->SetVariable (\r
BootVariableName,\r
&gEfiGlobalVariableGuid,\r
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
- BootOption->LoadOptionSize,\r
- BootOption->LoadOption\r
+ BdsLoadOption->LoadOptionSize,\r
+ BdsLoadOption->LoadOption\r
);\r
\r
return Status;\r