]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
Code scrub for BdsDxe module.
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BootMaint / BBSsupport.c
index 4d5a4580c68448beba770fad4dc19dfd34d6ff20..e11e279247315b0f3b90734a0c67b6b3d5ecea2d 100644 (file)
@@ -25,11 +25,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 \r
   @param AStr               Pointer to input Ascii string.\r
-  @param Size            The number of characters to translate.\r
+  @param Size               The number of characters to translate.\r
   @param UStr               Pointer to output Unicode string buffer.\r
 \r
-  @return None\r
-\r
 **/\r
 VOID\r
 AsciiToUnicodeSize (\r
@@ -52,38 +50,6 @@ AsciiToUnicodeSize (
   UStr[Idx] = 0;\r
 }\r
 \r
-/**\r
-\r
-  change a Unicode string t ASCII string\r
-\r
-\r
-  @param UStr            Unicode string\r
-                         Lenght - most possible length of AStr\r
-  @param Length          The length of UStr.\r
-  @param AStr            ASCII string to pass out\r
-\r
-  @return Actual length\r
-\r
-**/\r
-UINTN\r
-UnicodeToAscii (\r
-  IN  CHAR16  *UStr,\r
-  IN  UINTN   Length,\r
-  OUT CHAR8   *AStr\r
-  )\r
-{\r
-  UINTN Index;\r
-\r
-  //\r
-  // just buffer copy, not character copy\r
-  //\r
-  for (Index = 0; Index < Length; Index++) {\r
-    *AStr++ = (CHAR8) *UStr++;\r
-  }\r
-\r
-  return Index;\r
-}\r
-\r
 /**\r
   Build Legacy Device Name String according.\r
 \r
@@ -92,15 +58,13 @@ UnicodeToAscii (
   @param BufSize         The buffer size.\r
   @param BootString      The output string.\r
 \r
-  @return VOID           No output.\r
-\r
 **/\r
 VOID\r
 BdsBuildLegacyDevNameString (\r
-  IN BBS_TABLE                 *CurBBSEntry,\r
-  IN UINTN                     Index,\r
-  IN UINTN                     BufSize,\r
-  OUT CHAR16                   *BootString\r
+  IN  BBS_TABLE                 *CurBBSEntry,\r
+  IN  UINTN                     Index,\r
+  IN  UINTN                     BufSize,\r
+  OUT CHAR16                    *BootString\r
   )\r
 {\r
   CHAR16  *Fmt;\r
@@ -248,7 +212,7 @@ BdsCreateLegacyBootOption (
   BOOLEAN              IndexNotFound;\r
   BBS_BBS_DEVICE_PATH  *NewBbsDevPathNode;\r
 \r
-  if (NULL == (*BootOrderList)) {\r
+  if ((*BootOrderList) == NULL) {\r
     CurrentBootOptionNo = 0;\r
   } else {\r
     for (ArrayIndex = 0; ArrayIndex < (UINTN) (*BootOrderListSize / sizeof (UINT16)); ArrayIndex++) {\r
@@ -282,7 +246,8 @@ BdsCreateLegacyBootOption (
   //\r
   // Create new BBS device path node with description string\r
   //\r
-  UnicodeToAscii (BootDesc, StrSize (BootDesc), HelpString);\r
+  UnicodeStrToAsciiStr ((CONST CHAR16*)&BootDesc, (CHAR8*)&HelpString);\r
+\r
   StringLen = AsciiStrLen (HelpString);\r
   NewBbsDevPathNode = AllocateZeroPool (sizeof (BBS_BBS_DEVICE_PATH) + StringLen);\r
   if (NewBbsDevPathNode == NULL) {\r
@@ -431,8 +396,6 @@ BdsIsLegacyBootOption (
 /**\r
   Delete all the invalid legacy boot options.\r
 \r
-  \r
-\r
   @retval EFI_SUCCESS             All invalide legacy boot options are deleted.\r
   @retval EFI_OUT_OF_RESOURCES    Fail to allocate necessary memory.\r
   @retval EFI_NOT_FOUND           Fail to retrive variable of boot order.\r
@@ -502,7 +465,10 @@ BdsDeleteAllInvalidLegacyBootOptions (
       SafeFreePool (BootOrder);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-\r
+  \r
+    //\r
+    // Skip Non-Legacy boot options\r
+    // \r
     if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, &BbsIndex)) {\r
       SafeFreePool (BootOptionVar);\r
       Index++;\r
@@ -544,6 +510,9 @@ BdsDeleteAllInvalidLegacyBootOptions (
       );\r
   }\r
 \r
+  //\r
+  // Adjust the number of boot options.\r
+  //\r
   if (BootOrderSize != 0) {\r
     Status = gRT->SetVariable (\r
                     L"BootOrder",\r
@@ -600,6 +569,9 @@ BdsFindLegacyBootOptionByDevType (
     return Found;\r
   }\r
 \r
+  //\r
+  // Loop all boot option from variable\r
+  //\r
   for (BootOrderIndex = 0; BootOrderIndex < BootOptionNum; BootOrderIndex++) {\r
     Index = (UINTN) BootOrder[BootOrderIndex];\r
     UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", Index);\r
@@ -612,6 +584,9 @@ BdsFindLegacyBootOptionByDevType (
       continue;\r
     }\r
 \r
+    //\r
+    // Skip Non-legacy boot option\r
+    //\r
     if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, BbsIndex)) {\r
       SafeFreePool (BootOptionVar);\r
       continue;\r
@@ -659,6 +634,9 @@ BdsCreateOneLegacyBootOption (
 \r
   DevPath                       = NULL;\r
 \r
+  //\r
+  // Create device path node.\r
+  //\r
   BbsDevPathNode.Header.Type    = BBS_DEVICE_PATH;\r
   BbsDevPathNode.Header.SubType = BBS_BBS_DP;\r
   SetDevicePathNodeLength (&BbsDevPathNode.Header, sizeof (BBS_BBS_DEVICE_PATH));\r
@@ -691,8 +669,6 @@ BdsCreateOneLegacyBootOption (
 \r
   Add the legacy boot options from BBS table if they do not exist.\r
 \r
-  \r
-\r
   @retval EFI_SUCCESS       The boot options are added successfully \r
                             or they are already in boot options.\r
 \r
@@ -876,6 +852,9 @@ BdsCreateDevOrder (
   Ptr         = NULL;\r
   Status      = EFI_SUCCESS;\r
 \r
+  //\r
+  // Count all boot devices\r
+  //\r
   for (Index = 0; Index < BbsCount; Index++) {\r
     if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {\r
       continue;\r
@@ -913,6 +892,9 @@ BdsCreateDevOrder (
   TotalSize += (HeaderSize + sizeof (UINT16) * NETCount);\r
   TotalSize += (HeaderSize + sizeof (UINT16) * BEVCount);\r
 \r
+  //\r
+  // Create buffer to hold all boot device order\r
+  //\r
   DevOrder = AllocateZeroPool (TotalSize);\r
   if (NULL == DevOrder) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -960,6 +942,9 @@ BdsCreateDevOrder (
     Ptr = (UINT8 *) BdsFillDevOrderBuf (BbsTable, BBS_BEV_DEVICE, BbsCount, (UINT16 *) Ptr);\r
   }\r
 \r
+  //\r
+  // Save device order for legacy boot device to variable.\r
+  //\r
   Status = gRT->SetVariable (\r
                   VAR_LEGACY_DEV_ORDER,\r
                   &EfiLegacyDevOrderGuid,\r
@@ -1535,7 +1520,7 @@ PrintBbsTable (
   @param  Entry             The boot option is to be checked for refresh BBS table.\r
   \r
   @retval EFI_SUCCESS       The boot priority for BBS entries is refreshed successfully.\r
-\r
+  @return status of BdsSetBootPriority4SameTypeDev()\r
 **/\r
 EFI_STATUS\r
 BdsRefreshBbsTableForBoot (\r