]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c
Nt32Pkg PlatformBootManagerLib: Enable BootManagerMenuApp.
[mirror_edk2.git] / Nt32Pkg / Library / PlatformBootManagerLib / PlatformBootManager.c
index 4b23eb1602ef3138be07eaa3850f84a349d54c4c..dd67dab9ddb3be4dde6d46eada85889625d0e2d8 100644 (file)
@@ -15,6 +15,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "PlatformBootManager.h"\r
 \r
+EFI_GUID mBootMenuFile = {\r
+  0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D }\r
+};\r
+\r
 /**\r
   Perform the platform diagnostic, such like test memory. OEM/IBV also\r
   can customize this function to support specific platform diagnostic.\r
@@ -143,6 +147,154 @@ CompareBootOption (
   return BootOptionPriority (Left) - BootOptionPriority (Right);\r
 }\r
 \r
+/**\r
+  Generate device path include the input file guid info.\r
+\r
+  @param  FileGuid     Input file guid for the BootManagerMenuApp.\r
+\r
+  @retval DevicePath for BootManagerMenuApp.\r
+**/\r
+EFI_DEVICE_PATH *\r
+FvFilePath (\r
+  EFI_GUID                     *FileGuid\r
+  )\r
+{\r
+\r
+  EFI_STATUS                         Status;\r
+  EFI_LOADED_IMAGE_PROTOCOL          *LoadedImage;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  FileNode;\r
+\r
+  EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  gImageHandle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID **) &LoadedImage\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return AppendDevicePathNode (\r
+           DevicePathFromHandle (LoadedImage->DeviceHandle),\r
+           (EFI_DEVICE_PATH_PROTOCOL *) &FileNode\r
+           );\r
+}\r
+\r
+/**\r
+  Create one boot option for BootManagerMenuApp.\r
+\r
+  @param  FileGuid          Input file guid for the BootManagerMenuApp.\r
+  @param  Description       Description of the BootManagerMenuApp boot option.\r
+  @param  Position          Position of the new load option to put in the ****Order variable.\r
+  @param  IsBootCategory    Whether this is a boot category.\r
+\r
+\r
+  @retval OptionNumber      Return the option number info.\r
+\r
+**/\r
+UINTN\r
+RegisterBootManagerMenuAppBootOption (\r
+  EFI_GUID                         *FileGuid,\r
+  CHAR16                           *Description,\r
+  UINTN                            Position,\r
+  BOOLEAN                          IsBootCategory\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION     NewOption;\r
+  EFI_DEVICE_PATH_PROTOCOL         *DevicePath;\r
+  UINTN                            OptionNumber;\r
+\r
+  DevicePath = FvFilePath (FileGuid);\r
+  Status = EfiBootManagerInitializeLoadOption (\r
+             &NewOption,\r
+             LoadOptionNumberUnassigned,\r
+             LoadOptionTypeBoot,\r
+             IsBootCategory ? LOAD_OPTION_ACTIVE : LOAD_OPTION_CATEGORY_APP,\r
+             Description,\r
+             DevicePath,\r
+             NULL,\r
+             0\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+  FreePool (DevicePath);\r
+\r
+  Status = EfiBootManagerAddLoadOptionVariable (&NewOption, Position);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  OptionNumber = NewOption.OptionNumber;\r
+\r
+  EfiBootManagerFreeLoadOption (&NewOption);\r
+\r
+  return OptionNumber;\r
+}\r
+\r
+/**\r
+  Check if it's a Device Path pointing to BootManagerMenuApp.\r
+\r
+  @param  DevicePath     Input device path.\r
+\r
+  @retval TRUE   The device path is BootManagerMenuApp File Device Path.\r
+  @retval FALSE  The device path is NOT BootManagerMenuApp File Device Path.\r
+**/\r
+BOOLEAN\r
+IsBootManagerMenuAppFilePath (\r
+  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+)\r
+{\r
+  EFI_HANDLE                      FvHandle;\r
+  VOID                            *NameGuid;\r
+  EFI_STATUS                      Status;\r
+\r
+  Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &DevicePath, &FvHandle);\r
+  if (!EFI_ERROR (Status)) {\r
+    NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePath);\r
+    if (NameGuid != NULL) {\r
+      return CompareGuid (NameGuid, &mBootMenuFile);\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Return the boot option number to the BootManagerMenuApp.\r
+\r
+  If not found it in the current boot option, create a new one.\r
+\r
+  @retval OptionNumber   Return the boot option number to the BootManagerMenuApp.\r
+\r
+**/\r
+UINTN\r
+GetBootManagerMenuAppOption (\r
+  VOID\r
+  )\r
+{\r
+  UINTN                        BootOptionCount;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
+  UINTN                        Index;\r
+  UINTN                        OptionNumber;\r
+\r
+  BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
+\r
+  for (Index = 0; Index < BootOptionCount; Index++) {\r
+    if (IsBootManagerMenuAppFilePath (BootOptions[Index].FilePath)) {\r
+      OptionNumber = BootOptions[Index].OptionNumber;\r
+      break;\r
+    }\r
+  }\r
+\r
+  EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
+\r
+  if (Index >= BootOptionCount) {\r
+    //\r
+    // If not found the BootManagerMenuApp, create it.\r
+    //\r
+    OptionNumber = (UINT16) RegisterBootManagerMenuAppBootOption (&mBootMenuFile, L"UEFI BootManagerMenuApp", (UINTN) -1, FALSE);\r
+  }\r
+\r
+  return OptionNumber;\r
+}\r
+\r
 /**\r
   Do the platform specific action after the console is connected.\r
 \r
@@ -163,7 +315,9 @@ PlatformBootManagerAfterConsole (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL  White;\r
   EFI_INPUT_KEY                  Enter;\r
   EFI_INPUT_KEY                  F2;\r
+  EFI_INPUT_KEY                  F7;\r
   EFI_BOOT_MANAGER_LOAD_OPTION   BootOption;\r
+  UINTN                          OptionNumber;\r
 \r
   Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;\r
   White.Blue = White.Green = White.Red = White.Reserved = 0xFF;\r
@@ -185,15 +339,24 @@ PlatformBootManagerAfterConsole (
   EfiBootManagerGetBootManagerMenu (&BootOption);\r
   EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);\r
 \r
+  //\r
+  // 3. Boot Device List menu\r
+  //\r
+  F7.ScanCode     = SCAN_F7;\r
+  F7.UnicodeChar  = CHAR_NULL;\r
+  OptionNumber    = GetBootManagerMenuAppOption ();\r
+  EfiBootManagerAddKeyOptionVariable (NULL, (UINT16)OptionNumber, 0, &F7, NULL);\r
+\r
   //\r
   // Make Shell as the first boot option\r
   //\r
   EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, (SORT_COMPARE) CompareBootOption);\r
 \r
   PlatformBootManagerDiagnostics (QUICK, TRUE);\r
-  \r
-  PrintXY (10, 10, &White, &Black, L"F2    to enter Boot Manager Menu.                                            ");\r
-  PrintXY (10, 30, &White, &Black, L"Enter to boot directly.");\r
+\r
+  PrintXY (10, 10, &White, &Black, L"F2    to enter Setup.                              ");\r
+  PrintXY (10, 30, &White, &Black, L"F7    to enter Boot Manager Menu.");\r
+  PrintXY (10, 50, &White, &Black, L"Enter to boot directly.");\r
 }\r
 \r
 /**\r