]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootMenu.c
Check in binaries for EBC/IA32/X64/IPF built from MdePkg and BaseTools (r16700),...
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootMenu.c
index 42212385a860fcd13e6714a8b613fe705aa230e9..3676bf02459471f26a5bc82d4db750f2701dd7c5 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011 - 2015, 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
@@ -15,6 +15,7 @@
 #include "BdsInternal.h"\r
 \r
 #include <Guid/ArmGlobalVariableHob.h>\r
+#include <Guid/ArmPlatformEvents.h>\r
 \r
 extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;\r
 \r
@@ -341,6 +342,9 @@ BootMenuAddBootOption (
       if (InitrdPathNodes != NULL) {\r
         // Append the Device Path to the selected device path\r
         InitrdPath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r
+        // Free the InitrdPathNodes created by Support->CreateDevicePathNode()\r
+        FreePool (InitrdPathNodes);\r
+\r
         if (InitrdPath == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
           goto EXIT;\r
@@ -540,6 +544,8 @@ BootMenuUpdateBootOption (
           // Append the Device Path to the selected device path\r
           InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r
           FreePool (TempInitrdPath);\r
+          // Free the InitrdPathNodes created by Support->CreateDevicePathNode()\r
+          FreePool (InitrdPathNodes);\r
           if (InitrdPath == NULL) {\r
             Status = EFI_OUT_OF_RESOURCES;\r
             goto EXIT;\r
@@ -555,7 +561,8 @@ BootMenuUpdateBootOption (
 \r
     Print(L"Arguments to pass to the binary: ");\r
     if (CmdLineSize > 0) {\r
-      AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
+      AsciiStrnCpy (CmdLine, (CONST CHAR8*)(LinuxArguments + 1), sizeof (CmdLine));\r
+      CmdLine[sizeof (CmdLine) - 1] = '\0';\r
     } else {\r
       CmdLine[0] = '\0';\r
     }\r
@@ -581,10 +588,29 @@ BootMenuUpdateBootOption (
     if (BootOption->OptionalDataSize > 0) {\r
       IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode);\r
       if (IsPrintable) {\r
+          //\r
+          // The size in bytes of the string, final zero included, should\r
+          // be equal to or at least lower than "BootOption->OptionalDataSize"\r
+          // and the "IsPrintableString()" has already tested that the length\r
+          // in number of characters is smaller than BOOT_DEVICE_OPTION_MAX,\r
+          // final '\0' included. We can thus copy the string for editing\r
+          // using "CopyMem()". Furthermore, note that in the case of an Unicode\r
+          // string "StrnCpy()" and "StrCpy()" can not be used to copy the\r
+          // string because the data pointed to by "BootOption->OptionalData"\r
+          // is not necessarily 2-byte aligned.\r
+          //\r
         if (IsUnicode) {\r
-          StrnCpy (UnicodeCmdLine, BootOption->OptionalData, BootOption->OptionalDataSize / 2);\r
+          CopyMem (\r
+            UnicodeCmdLine, BootOption->OptionalData,\r
+            MIN (sizeof (UnicodeCmdLine),\r
+                 BootOption->OptionalDataSize)\r
+            );\r
         } else {\r
-          AsciiStrnCpy (CmdLine, BootOption->OptionalData, BootOption->OptionalDataSize);\r
+          CopyMem (\r
+            CmdLine, BootOption->OptionalData,\r
+            MIN (sizeof (CmdLine),\r
+                 BootOption->OptionalDataSize)\r
+            );\r
         }\r
       }\r
     } else {\r
@@ -691,6 +717,7 @@ BootMenuReorderBootOptions (
     }\r
 \r
     SelectedEntry = &BootOptionEntry->Link;\r
+    SecondEntry = NULL;\r
     // Note down the previous entry in the list to be able to cancel changes\r
     PrevEntry = GetPreviousNode (BootOptionsList, SelectedEntry);\r
 \r
@@ -739,7 +766,9 @@ BootMenuReorderBootOptions (
       } while ((!Move) && (!Save) && (!Cancel));\r
 \r
       if (Move) {\r
-        SwapListEntries (SelectedEntry, SecondEntry);\r
+        if ((SelectedEntry != NULL) && (SecondEntry != NULL)) {\r
+          SwapListEntries (SelectedEntry, SecondEntry);\r
+        }\r
       } else {\r
         if (Save) {\r
           Status = GetGlobalEnvironmentVariable (\r
@@ -806,6 +835,7 @@ UpdateFdtPath (
   BDS_SUPPORTED_DEVICE      *SupportedBootDevice;\r
   EFI_DEVICE_PATH_PROTOCOL  *FdtDevicePathNodes;\r
   EFI_DEVICE_PATH_PROTOCOL  *FdtDevicePath;\r
+  EFI_EVENT                 UpdateFdtEvent;\r
 \r
   Status = SelectBootDevice (&SupportedBootDevice);\r
   if (EFI_ERROR(Status)) {\r
@@ -823,6 +853,8 @@ UpdateFdtPath (
   if (FdtDevicePathNodes != NULL) {\r
     // Append the Device Path node to the select device path\r
     FdtDevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNodes);\r
+    // Free the FdtDevicePathNodes created by Support->CreateDevicePathNode()\r
+    FreePool (FdtDevicePathNodes);\r
     FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);\r
     Status = gRT->SetVariable (\r
                     (CHAR16*)L"Fdt",\r
@@ -833,7 +865,7 @@ UpdateFdtPath (
                     );\r
     ASSERT_EFI_ERROR(Status);\r
   } else {\r
-    gRT->SetVariable (\r
+    Status = gRT->SetVariable (\r
            (CHAR16*)L"Fdt",\r
            &gArmGlobalVariableGuid,\r
            EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
@@ -843,6 +875,23 @@ UpdateFdtPath (
     ASSERT_EFI_ERROR(Status);\r
   }\r
 \r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Signal FDT has been updated\r
+    //\r
+    Status = gBS->CreateEventEx (\r
+        EVT_NOTIFY_SIGNAL,\r
+        TPL_NOTIFY,\r
+        EmptyCallbackFunction,\r
+        NULL,\r
+        &gArmPlatformUpdateFdtEventGuid,\r
+        &UpdateFdtEvent\r
+        );\r
+    if (!EFI_ERROR (Status)) {\r
+      gBS->SignalEvent (UpdateFdtEvent);\r
+    }\r
+  }\r
+\r
 EXIT:\r
   if (Status == EFI_ABORTED) {\r
     Print(L"\n");\r