]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BootMaint / BBSsupport.c
index db0fed5834d512b415784f86e537d6f745ef131c..7ba4fa2ab84f0f1e84813bf7230be6abccd46b6f 100644 (file)
@@ -3,14 +3,8 @@
   and manage the legacy boot option, all legacy boot option is getting from\r
   the legacy BBS table.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<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) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -53,9 +47,9 @@ OrderLegacyBootOption4SameType (
   UINTN                    BootOrderSize;\r
   UINTN                    Index;\r
   UINTN                    StartPosition;\r
-  \r
+\r
   BDS_COMMON_OPTION        *BootOption;\r
-  \r
+\r
   CHAR16                   OptionName[sizeof ("Boot####")];\r
   UINT16                   *BbsIndexArray;\r
   UINT16                   *DeviceTypeArray;\r
@@ -82,12 +76,12 @@ OrderLegacyBootOption4SameType (
   ASSERT (*DisBootOption != NULL);\r
 \r
   for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
-  \r
+\r
     UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]);\r
     InitializeListHead (&List);\r
     BootOption = BdsLibVariableToOption (&List, OptionName);\r
     ASSERT (BootOption != NULL);\r
-    \r
+\r
     if ((DevicePathType (BootOption->DevicePath) == BBS_DEVICE_PATH) &&\r
         (DevicePathSubType (BootOption->DevicePath) == BBS_BBS_DP)) {\r
       //\r
@@ -119,7 +113,7 @@ OrderLegacyBootOption4SameType (
       if (BbsIndexArray[Index] == (DevOrder[DevOrderCount] & 0xFF)) {\r
         StartPosition = MIN (StartPosition, Index);\r
         NewBootOption[DevOrderCount] = BootOrder[Index];\r
-        \r
+\r
         if ((DevOrder[DevOrderCount] & 0xFF00) == 0xFF00) {\r
           (*DisBootOption)[*DisBootOptionCount] = BootOrder[Index];\r
           (*DisBootOptionCount)++;\r
@@ -143,17 +137,21 @@ OrderLegacyBootOption4SameType (
                   BootOrderSize,\r
                   BootOrder\r
                   );\r
+  //\r
+  // Changing content without increasing its size with current variable implementation shouldn't fail.\r
+  //\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   FreePool (NewBootOption);\r
   FreePool (DeviceTypeArray);\r
   FreePool (BbsIndexArray);\r
+  FreePool (BootOrder);\r
 }\r
 \r
 /**\r
   Group the legacy boot options in the BootOption.\r
 \r
-  The routine assumes the boot options in the beginning that covers all the device \r
+  The routine assumes the boot options in the beginning that covers all the device\r
   types are ordered properly and re-position the following boot options just after\r
   the corresponding boot options with the same device type.\r
   For example:\r
@@ -171,6 +169,7 @@ GroupMultipleLegacyBootOption4SameType (
   VOID\r
   )\r
 {\r
+  EFI_STATUS                   Status;\r
   UINTN                        Index;\r
   UINTN                        DeviceIndex;\r
   UINTN                        DeviceTypeIndex[7];\r
@@ -201,7 +200,7 @@ GroupMultipleLegacyBootOption4SameType (
       //\r
       // Legacy Boot Option\r
       //\r
-      ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption->DevicePath)->DeviceType & 0xF) < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]));\r
+      ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption->DevicePath)->DeviceType & 0xF) < ARRAY_SIZE (DeviceTypeIndex));\r
       NextIndex = &DeviceTypeIndex[((BBS_BBS_DEVICE_PATH *) BootOption->DevicePath)->DeviceType & 0xF];\r
 \r
       if (*NextIndex == (UINTN) -1) {\r
@@ -220,7 +219,7 @@ GroupMultipleLegacyBootOption4SameType (
         //\r
         // Update the DeviceTypeIndex array to reflect the right shift operation\r
         //\r
-        for (DeviceIndex = 0; DeviceIndex < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]); DeviceIndex++) {\r
+        for (DeviceIndex = 0; DeviceIndex < ARRAY_SIZE (DeviceTypeIndex); DeviceIndex++) {\r
           if (DeviceTypeIndex[DeviceIndex] != (UINTN) -1 && DeviceTypeIndex[DeviceIndex] >= *NextIndex) {\r
             DeviceTypeIndex[DeviceIndex]++;\r
           }\r
@@ -233,13 +232,17 @@ GroupMultipleLegacyBootOption4SameType (
     FreePool (BootOption);\r
   }\r
 \r
-  gRT->SetVariable (\r
-         L"BootOrder",\r
-         &gEfiGlobalVariableGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-         BootOrderSize,\r
-         BootOrder\r
-         );\r
+  Status = gRT->SetVariable (\r
+                  L"BootOrder",\r
+                  &gEfiGlobalVariableGuid,\r
+                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                  BootOrderSize,\r
+                  BootOrder\r
+                  );\r
+  //\r
+  // Changing content without increasing its size with current variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
   FreePool (BootOrder);\r
 }\r
 \r