]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootOption.c
ArmPlatformPkg/Bds: Add support for 'BootCurrent'
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootOption.c
index d811c03ccc2030b7224a78601aedf278d9d2d725..289d36a50badb9f44726380a96b53953a9961993 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
 *\r
 *  This program and the accompanying materials\r
 *  are licensed and made available under the terms and conditions of the BSD License\r
@@ -32,6 +32,7 @@ BootOptionStart (
   UINTN                                 CmdLineSize;\r
   UINTN                                 InitrdSize;\r
   EFI_DEVICE_PATH*                      Initrd;\r
+  UINT16                                LoadOptionIndexSize;\r
 \r
   if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
     Status = EFI_UNSUPPORTED;\r
@@ -82,9 +83,23 @@ BootOptionStart (
                                 Initrd, // Initrd\r
                                 (CHAR8*)(LinuxArguments + 1),\r
                                 FdtDevicePath);\r
+\r
+      FreePool (FdtDevicePath);\r
     }\r
   } else {\r
+    // Set BootCurrent variable\r
+    LoadOptionIndexSize = sizeof(UINT16);\r
+    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+              LoadOptionIndexSize, &(BootOption->LoadOptionIndex));\r
+\r
     Status = BdsStartEfiApplication (mImageHandle, BootOption->FilePathList, BootOption->OptionalDataSize, BootOption->OptionalData);\r
+\r
+    // Clear BootCurrent variable\r
+    LoadOptionIndexSize = sizeof(UINT16);\r
+    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+              0, NULL);\r
   }\r
 \r
   return Status;\r
@@ -119,6 +134,8 @@ BootOptionList (
     }\r
   }\r
 \r
+  FreePool (BootOrder);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -290,6 +307,11 @@ BootOptionCreate (
       BootOrder\r
       );\r
 \r
+  // We only free it if the UEFI Variable 'BootOrder' was already existing\r
+  if (BootOrderSize > sizeof(UINT16)) {\r
+    FreePool (BootOrder);\r
+  }\r
+\r
   *BdsLoadOption = BootOption;\r
   return Status;\r
 }\r
@@ -361,5 +383,7 @@ BootOptionDelete (
         );\r
   }\r
 \r
+  FreePool (BootOrder);\r
+\r
   return EFI_SUCCESS;\r
 }\r