]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootOption.c
ArmPlatformPkg/Bds: Check if the assumed requirements are set before to use it
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootOption.c
index a8ba23fe739ce0e9ca83bbcc23526ed7c19c8e95..d3c7445fae3d7b463c965409bc5804eb4c1e5212 100644 (file)
@@ -258,8 +258,13 @@ BootOptionSetFields (
   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
@@ -341,20 +346,20 @@ BootOptionUpdate (
   )\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