]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c
MdeModulePkg/UefiBootManagerLib: Generate boot description for NVME
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmLoadOption.c
index 999647cfac198eb141bc0a866f21551dd843c844..116cf28fe388ddf24c1094071645463819626af3 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Load option library functions which relate with creating and processing load options.\r
 \r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
+Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<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
@@ -564,7 +564,6 @@ EfiBootManagerDeleteLoadOptionVariable (
 {\r
   UINT16                            *OptionOrder;\r
   UINTN                             OptionOrderSize;\r
-  EFI_STATUS                        Status;\r
   UINTN                             Index;\r
   CHAR16                            OptionName[BM_OPTION_NAME_LEN];\r
 \r
@@ -572,11 +571,10 @@ EfiBootManagerDeleteLoadOptionVariable (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Status = EFI_NOT_FOUND;\r
-\r
   if (OptionType == LoadOptionTypeDriver || OptionType == LoadOptionTypeSysPrep || OptionType == LoadOptionTypeBoot) {\r
     //\r
-    // If the associated *Order exists, just remove the reference in *Order.\r
+    // If the associated *Order exists, firstly remove the reference in *Order for\r
+    //  Driver####, SysPrep#### and Boot####.\r
     //\r
     GetEfiGlobalVariable2 (mBmLoadOptionOrderName[OptionType], (VOID **) &OptionOrder, &OptionOrderSize);\r
     ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0));\r
@@ -585,34 +583,32 @@ EfiBootManagerDeleteLoadOptionVariable (
       if (OptionOrder[Index] == OptionNumber) {\r
         OptionOrderSize -= sizeof (UINT16);\r
         CopyMem (&OptionOrder[Index], &OptionOrder[Index + 1], OptionOrderSize - Index * sizeof (UINT16));\r
-        Status = gRT->SetVariable (\r
-          mBmLoadOptionOrderName[OptionType],\r
-          &gEfiGlobalVariableGuid,\r
-          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-          OptionOrderSize,\r
-          OptionOrder\r
-          );\r
+        gRT->SetVariable (\r
+               mBmLoadOptionOrderName[OptionType],\r
+               &gEfiGlobalVariableGuid,\r
+               EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+               OptionOrderSize,\r
+               OptionOrder\r
+               );\r
         break;\r
       }\r
     }\r
     if (OptionOrder != NULL) {\r
       FreePool (OptionOrder);\r
     }\r
-  } else if (OptionType == LoadOptionTypePlatformRecovery) {\r
-    //\r
-    // PlatformRecovery#### doesn't have assiciated PlatformRecoveryOrder, remove the PlatformRecovery#### itself.\r
-    //\r
-    UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[OptionType], OptionNumber);\r
-    Status = gRT->SetVariable (\r
-                    OptionName,\r
-                    &gEfiGlobalVariableGuid,\r
-                    0,\r
-                    0,\r
-                    NULL\r
-                    );\r
   }\r
 \r
-  return Status;\r
+  //\r
+  // Remove the Driver####, SysPrep####, Boot#### or PlatformRecovery#### itself.\r
+  //\r
+  UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[OptionType], OptionNumber);\r
+  return gRT->SetVariable (\r
+                OptionName,\r
+                &gEfiGlobalVariableGuid,\r
+                0,\r
+                0,\r
+                NULL\r
+                );\r
 }\r
 \r
 /**\r
@@ -779,23 +775,28 @@ BmValidateOption (
   @retval FALSE The variable name is NOT valid.\r
 **/\r
 BOOLEAN\r
-BmIsValidLoadOptionVariableName (\r
+EFIAPI\r
+EfiBootManagerIsValidLoadOptionVariableName (\r
   IN CHAR16                             *VariableName,\r
-  OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE *OptionType,\r
-  OUT UINT16                            *OptionNumber\r
+  OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE *OptionType   OPTIONAL,\r
+  OUT UINT16                            *OptionNumber OPTIONAL\r
   )\r
 {\r
   UINTN                             VariableNameLen;\r
   UINTN                             Index;\r
   UINTN                             Uint;\r
 \r
+  if (VariableName == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
   VariableNameLen = StrLen (VariableName);\r
 \r
   if (VariableNameLen <= 4) {\r
     return FALSE;\r
   }\r
 \r
-  for (Index = 0; Index < sizeof (mBmLoadOptionName) / sizeof (mBmLoadOptionName[0]); Index++) {\r
+  for (Index = 0; Index < ARRAY_SIZE (mBmLoadOptionName); Index++) {\r
     if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[Index])) &&\r
         (StrnCmp (VariableName, mBmLoadOptionName[Index], VariableNameLen - 4) == 0)\r
         ) {\r
@@ -803,18 +804,23 @@ BmIsValidLoadOptionVariableName (
     }\r
   }\r
 \r
-  if (Index == sizeof (mBmLoadOptionName) / sizeof (mBmLoadOptionName[0])) {\r
+  if (Index == ARRAY_SIZE (mBmLoadOptionName)) {\r
     return FALSE;\r
   }\r
 \r
-  *OptionType = (EFI_BOOT_MANAGER_LOAD_OPTION_TYPE) Index;\r
-  *OptionNumber = 0;\r
-  for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {\r
-    Uint = BmCharToUint (VariableName[Index]);\r
-    if (Uint == -1) {\r
-      break;\r
-    } else {\r
-      *OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;\r
+  if (OptionType != NULL) {\r
+    *OptionType = (EFI_BOOT_MANAGER_LOAD_OPTION_TYPE) Index;\r
+  }\r
+\r
+  if (OptionNumber != NULL) {\r
+    *OptionNumber = 0;\r
+    for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {\r
+      Uint = BmCharToUint (VariableName[Index]);\r
+      if (Uint == -1) {\r
+        break;\r
+      } else {\r
+        *OptionNumber = (UINT16) Uint + *OptionNumber * 0x10;\r
+      }\r
     }\r
   }\r
 \r
@@ -857,7 +863,7 @@ EfiBootManagerVariableToLoadOptionEx (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (!BmIsValidLoadOptionVariableName (VariableName, &OptionType, &OptionNumber)) {\r
+  if (!EfiBootManagerIsValidLoadOptionVariableName (VariableName, &OptionType, &OptionNumber)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -906,7 +912,7 @@ EfiBootManagerVariableToLoadOptionEx (
   FilePath = (EFI_DEVICE_PATH_PROTOCOL *) VariablePtr;\r
   VariablePtr += FilePathSize;\r
 \r
-  OptionalDataSize = (UINT32) (VariableSize - (UINTN) (VariablePtr - Variable));\r
+  OptionalDataSize = (UINT32) (VariableSize - ((UINTN) VariablePtr - (UINTN) Variable));\r
   if (OptionalDataSize == 0) {\r
     OptionalData = NULL;\r
   } else {\r
@@ -983,7 +989,7 @@ BmCollectLoadOptions (
 \r
   if (CompareGuid (Guid, Param->Guid) && (\r
       Param->OptionType == LoadOptionTypePlatformRecovery &&\r
-      BmIsValidLoadOptionVariableName (Name, &OptionType, &OptionNumber) &&\r
+      EfiBootManagerIsValidLoadOptionVariableName (Name, &OptionType, &OptionNumber) &&\r
       OptionType == LoadOptionTypePlatformRecovery\r
      )) {\r
     Status = EfiBootManagerVariableToLoadOptionEx (Name, Guid, &Option);\r
@@ -1271,11 +1277,12 @@ EfiBootManagerProcessLoadOption (
   // Load and start the load option.\r
   //\r
   DEBUG ((\r
-    DEBUG_INFO | DEBUG_LOAD, "Process Load Option (%s%04x) ...\n",\r
-    mBmLoadOptionName[LoadOption->OptionType], LoadOption->OptionNumber\r
+    DEBUG_INFO | DEBUG_LOAD, "Process %s%04x (%s) ...\n",\r
+    mBmLoadOptionName[LoadOption->OptionType], LoadOption->OptionNumber,\r
+    LoadOption->Description\r
     ));\r
   ImageHandle = NULL;\r
-  FileBuffer = BmGetLoadOptionBuffer (LoadOption->FilePath, &FilePath, &FileSize);\r
+  FileBuffer = EfiBootManagerGetLoadOptionBuffer (LoadOption->FilePath, &FilePath, &FileSize);\r
   DEBUG_CODE (\r
     if (FileBuffer != NULL && CompareMem (LoadOption->FilePath, FilePath, GetDevicePathSize (FilePath)) != 0) {\r
       DEBUG ((EFI_D_INFO, "[Bds] DevicePath expand: "));\r
@@ -1315,7 +1322,7 @@ EfiBootManagerProcessLoadOption (
 \r
     LoadOption->Status = gBS->StartImage (ImageHandle, &LoadOption->ExitDataSize, &LoadOption->ExitData);\r
     DEBUG ((\r
-      DEBUG_INFO | DEBUG_LOAD, "Load Option (%s%04x) Return Status = %r\n",\r
+      DEBUG_INFO | DEBUG_LOAD, "%s%04x Return Status = %r\n",\r
       mBmLoadOptionName[LoadOption->OptionType], LoadOption->OptionNumber, LoadOption->Status\r
       ));\r
 \r