]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkNt32Pkg/Dxe/PlatformBds/Generic/BootMaint/BBSsupport.c
1. Bug fix for "EDK GenericBds WriteBootToOsPerformanceData() uses AcpiReclaimMemory";
[mirror_edk2.git] / EdkNt32Pkg / Dxe / PlatformBds / Generic / BootMaint / BBSsupport.c
index a33be4b046f123cbc635aa178f8814fd7d2f3436..c9f2402eb140de7171062caf5b28cad425d20ba9 100644 (file)
@@ -36,6 +36,26 @@ AsciiToUnicodeSize (
   IN UINTN              Size,\r
   OUT UINT16            *u\r
   )\r
+/*++\r
+\r
+  Routine Description:\r
+\r
+    Translate the first n characters of an Ascii string to\r
+    Unicode characters. The count n is indicated by parameter\r
+    Size. If Size is greater than the length of string, then\r
+    the entire string is translated.\r
+\r
+  Arguments:\r
+\r
+    a         - Pointer to input Ascii string.\r
+    Size      - The number of characters to translate.\r
+    u         - Pointer to output Unicode string buffer.\r
+\r
+  Returns:\r
+\r
+    None\r
+\r
+--*/\r
 {\r
   UINTN i;\r
 \r
@@ -43,12 +63,12 @@ AsciiToUnicodeSize (
   while (a[i] != 0) {\r
     u[i] = (CHAR16) a[i];\r
     if (i == Size) {\r
-      u[i] = 0;\r
       break;\r
     }\r
 \r
     i++;\r
   }\r
+  u[i] = 0;\r
 }\r
 \r
 VOID\r
@@ -156,6 +176,32 @@ BdsCreateLegacyBootOption (
   IN OUT UINT16                       **BootOrderList,\r
   IN OUT UINTN                        *BootOrderListSize\r
   )\r
+/*++\r
+\r
+  Routine Description:\r
+\r
+    Create a legacy boot option for the specified entry of\r
+    BBS table, save it as variable, and append it to the boot\r
+    order list.\r
+\r
+  Arguments:\r
+\r
+    CurrentBbsEntry        - Pointer to current BBS table.\r
+    CurrentBbsDevPath      - Pointer to the Device Path Protocol instance of BBS\r
+    Index                  - Index of the specified entry in BBS table.\r
+    BootOrderList          - On input, the original boot order list.\r
+                             On output, the new boot order list attached with the\r
+                             created node.\r
+    BootOrderListSize      - On input, the original size of boot order list.\r
+                           - On output, the size of new boot order list.\r
+\r
+  Returns:\r
+\r
+    EFI_SUCCESS            - Boot Option successfully created.\r
+    EFI_OUT_OF_RESOURCES   - Fail to allocate necessary memory.\r
+    Other                  - Error occurs while setting variable.\r
+\r
+--*/\r
 {\r
   EFI_STATUS  Status;\r
   UINT16      CurrentBootOptionNo;\r
@@ -267,6 +313,8 @@ BdsCreateLegacyBootOption (
     CopyMem (NewBootOrderList, *BootOrderList, *BootOrderListSize);\r
   }\r
 \r
+  SafeFreePool (*BootOrderList);\r
+\r
   BootOrderLastIndex                    = (UINTN) (*BootOrderListSize / sizeof (UINT16));\r
   NewBootOrderList[BootOrderLastIndex]  = CurrentBootOptionNo;\r
   *BootOrderListSize += sizeof (UINT16);\r
@@ -352,6 +400,25 @@ EFI_STATUS
 BdsDeleteAllInvalidLegacyBootOptions (\r
   VOID\r
   )\r
+/*++\r
+\r
+  Routine Description:\r
+\r
+    Delete all the invalid legacy boot options.\r
+\r
+  Arguments:\r
+\r
+    None.\r
+\r
+  Returns:\r
+\r
+    EFI_SUCCESS            - All invalide legacy boot options are deleted.\r
+    EFI_OUT_OF_RESOURCES   - Fail to allocate necessary memory.\r
+    EFI_NOT_FOUND          - Fail to retrive variable of boot order.\r
+    Other                  - Error occurs while setting variable or locating\r
+                             protocol.\r
+\r
+--*/\r
 {\r
   UINT16                    *BootOrder;\r
   UINT8                     *BootOptionVar;\r
@@ -367,6 +434,8 @@ BdsDeleteAllInvalidLegacyBootOptions (
   EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;\r
   UINTN                     Index;\r
   UINT16                    BootOption[10];\r
+  UINT16                    BootDesc[100];\r
+  BOOLEAN                   DescStringMatch;\r
 \r
   Status        = EFI_SUCCESS;\r
   BootOrder     = NULL;\r
@@ -417,11 +486,28 @@ BdsDeleteAllInvalidLegacyBootOptions (
       Index++;\r
       continue;\r
     }\r
\r
+    //\r
+    // Check if BBS Description String is changed\r
+    //\r
+    DescStringMatch = FALSE;\r
+    \r
+    BdsBuildLegacyDevNameString (\r
+      &LocalBbsTable[BbsIndex], \r
+      BbsIndex, \r
+      sizeof(BootDesc), \r
+      BootDesc\r
+      );\r
+    \r
+    if (StrCmp (BootDesc, (UINT16*)(BootOptionVar + sizeof (UINT32) + sizeof (UINT16))) == 0) {\r
+      DescStringMatch = TRUE;\r
+    }\r
 \r
     if (!((LocalBbsTable[BbsIndex].BootPriority == BBS_IGNORE_ENTRY) ||\r
-        (LocalBbsTable[BbsIndex].BootPriority == BBS_DO_NOT_BOOT_FROM) ||\r
-         (LocalBbsTable[BbsIndex].BootPriority == BBS_LOWEST_PRIORITY)) &&\r
-         LocalBbsTable[BbsIndex].DeviceType == BbsEntry->DeviceType) {\r
+          (LocalBbsTable[BbsIndex].BootPriority == BBS_DO_NOT_BOOT_FROM) ||\r
+          (LocalBbsTable[BbsIndex].BootPriority == BBS_LOWEST_PRIORITY)) &&\r
+        (LocalBbsTable[BbsIndex].DeviceType == BbsEntry->DeviceType) &&\r
+        DescStringMatch) {\r
       Index++;\r
       continue;\r
     }\r