]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
OvmfPkg/PlatformBootManagerLib: Remove PlatformBdsGetDriverOption()
[mirror_edk2.git] / OvmfPkg / Library / PlatformBootManagerLib / BdsPlatform.c
index 1988b3e04c3034f7f78971f9565fddac563728b0..9a1d7b164e6f366886631b0a6531fd33365da850 100644 (file)
@@ -14,7 +14,6 @@
 \r
 #include "BdsPlatform.h"\r
 #include <Guid/RootBridgesConnectedEventGroup.h>\r
-#include <Library/QemuBootOrderLib.h>\r
 \r
 \r
 //\r
@@ -88,6 +87,111 @@ InstallDevicePathCallback (
   VOID\r
   );\r
 \r
+VOID\r
+PlatformRegisterFvBootOption (\r
+  EFI_GUID                         *FileGuid,\r
+  CHAR16                           *Description,\r
+  UINT32                           Attributes\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  INTN                              OptionIndex;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION      NewOption;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION      *BootOptions;\r
+  UINTN                             BootOptionCount;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;\r
+  EFI_LOADED_IMAGE_PROTOCOL         *LoadedImage;\r
+  EFI_DEVICE_PATH_PROTOCOL          *DevicePath;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  gImageHandle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID **) &LoadedImage\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
+  DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);\r
+  ASSERT (DevicePath != NULL);\r
+  DevicePath = AppendDevicePathNode (\r
+                 DevicePath,\r
+                 (EFI_DEVICE_PATH_PROTOCOL *) &FileNode\r
+                 );\r
+  ASSERT (DevicePath != NULL);\r
+\r
+  Status = EfiBootManagerInitializeLoadOption (\r
+             &NewOption,\r
+             LoadOptionNumberUnassigned,\r
+             LoadOptionTypeBoot,\r
+             Attributes,\r
+             Description,\r
+             DevicePath,\r
+             NULL,\r
+             0\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+  FreePool (DevicePath);\r
+\r
+  BootOptions = EfiBootManagerGetLoadOptions (\r
+                  &BootOptionCount, LoadOptionTypeBoot\r
+                  );\r
+\r
+  OptionIndex = EfiBootManagerFindLoadOption (\r
+                  &NewOption, BootOptions, BootOptionCount\r
+                  );\r
+\r
+  if (OptionIndex == -1) {\r
+    Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+  EfiBootManagerFreeLoadOption (&NewOption);\r
+  EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
+}\r
+\r
+VOID\r
+PlatformRegisterOptionsAndKeys (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  EFI_INPUT_KEY                Enter;\r
+  EFI_INPUT_KEY                F2;\r
+  EFI_INPUT_KEY                Esc;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
+\r
+  //\r
+  // Register ENTER as CONTINUE key\r
+  //\r
+  Enter.ScanCode    = SCAN_NULL;\r
+  Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
+  Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Map F2 to Boot Manager Menu\r
+  //\r
+  F2.ScanCode     = SCAN_F2;\r
+  F2.UnicodeChar  = CHAR_NULL;\r
+  Esc.ScanCode    = SCAN_ESC;\r
+  Esc.UnicodeChar = CHAR_NULL;\r
+  Status = EfiBootManagerGetBootManagerMenu (&BootOption);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = EfiBootManagerAddKeyOptionVariable (\r
+             NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL\r
+             );\r
+  ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);\r
+  Status = EfiBootManagerAddKeyOptionVariable (\r
+             NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL\r
+             );\r
+  ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);\r
+  //\r
+  // Register UEFI Shell\r
+  //\r
+  PlatformRegisterFvBootOption (\r
+    PcdGetPtr (PcdShellFile), L"EFI Internal Shell", LOAD_OPTION_ACTIVE\r
+    );\r
+}\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 ConnectRootBridge (\r
@@ -164,6 +268,11 @@ Returns:
                   &gEfiDxeSmmReadyToLockProtocolGuid, EFI_NATIVE_INTERFACE,\r
                   NULL);\r
   ASSERT_EFI_ERROR (Status);\r
+\r
+  PlatformInitializeConsole (gPlatformConsole);\r
+  PcdSet16 (PcdPlatformBootTimeOut, GetFrontPageTimeoutFromQemu ());\r
+\r
+  PlatformRegisterOptionsAndKeys ();\r
 }\r
 \r
 \r
@@ -236,7 +345,7 @@ Returns:
   //\r
   DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnpPs2KeyboardDeviceNode);\r
 \r
-  BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL);\r
 \r
   //\r
   // Register COM1\r
@@ -251,7 +360,7 @@ Returns:
   //\r
   // Print Device Path\r
   //\r
-  DevPathStr = DevicePathToStr(DevicePath);\r
+  DevPathStr = ConvertDevicePathToText (DevicePath, FALSE, FALSE);\r
   if (DevPathStr != NULL) {\r
     DEBUG((\r
       EFI_D_INFO,\r
@@ -263,9 +372,9 @@ Returns:
     FreePool(DevPathStr);\r
   }\r
 \r
-  BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);\r
 \r
   //\r
   // Register COM2\r
@@ -280,7 +389,7 @@ Returns:
   //\r
   // Print Device Path\r
   //\r
-  DevPathStr = DevicePathToStr(DevicePath);\r
+  DevPathStr = ConvertDevicePathToText (DevicePath, FALSE, FALSE);\r
   if (DevPathStr != NULL) {\r
     DEBUG((\r
       EFI_D_INFO,\r
@@ -292,9 +401,9 @@ Returns:
     FreePool(DevPathStr);\r
   }\r
 \r
-  BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -374,8 +483,8 @@ GetGopDevicePath (
         // Delete the PCI device's path that added by GetPlugInPciVgaDevicePath()\r
         // Add the integrity GOP device path.\r
         //\r
-        BdsLibUpdateConsoleVariable (VarConsoleOutDev, NULL, PciDevicePath);\r
-        BdsLibUpdateConsoleVariable (VarConsoleOutDev, TempDevicePath, NULL);\r
+        EfiBootManagerUpdateConsoleVariable (ConOutDev, NULL, PciDevicePath);\r
+        EfiBootManagerUpdateConsoleVariable (ConOutDev, TempDevicePath, NULL);\r
       }\r
     }\r
     gBS->FreePool (GopHandleBuffer);\r
@@ -424,7 +533,7 @@ Returns:
   GetGopDevicePath (DevicePath, &GopDevicePath);\r
   DevicePath = GopDevicePath;\r
 \r
-  BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -467,9 +576,9 @@ Returns:
   DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r
   DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
 \r
-  BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
-  BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL);\r
+  EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -669,9 +778,9 @@ DetectAndPreparePlatformPciDevicePaths (
 }\r
 \r
 \r
-EFI_STATUS\r
-PlatformBdsConnectConsole (\r
-  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole\r
+VOID\r
+PlatformInitializeConsole (\r
+  IN PLATFORM_CONSOLE_CONNECT_ENTRY   *PlatformConsole\r
   )\r
 /*++\r
 \r
@@ -683,37 +792,17 @@ Routine Description:
 Arguments:\r
 \r
   PlatformConsole         - Predfined platform default console device array.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS             - Success connect at least one ConIn and ConOut\r
-                            device, there must have one ConOut device is\r
-                            active vga device.\r
-\r
-  EFI_STATUS              - Return the status of\r
-                            BdsLibConnectAllDefaultConsoles ()\r
-\r
 --*/\r
 {\r
-  EFI_STATUS                         Status;\r
   UINTN                              Index;\r
   EFI_DEVICE_PATH_PROTOCOL           *VarConout;\r
   EFI_DEVICE_PATH_PROTOCOL           *VarConin;\r
-  UINTN                              DevicePathSize;\r
 \r
   //\r
   // Connect RootBridge\r
   //\r
-  VarConout = BdsLibGetVariableAndSize (\r
-                VarConsoleOut,\r
-                &gEfiGlobalVariableGuid,\r
-                &DevicePathSize\r
-                );\r
-  VarConin = BdsLibGetVariableAndSize (\r
-               VarConsoleInp,\r
-               &gEfiGlobalVariableGuid,\r
-               &DevicePathSize\r
-               );\r
+  GetEfiGlobalVariable2 (EFI_CON_OUT_VARIABLE_NAME, (VOID **) &VarConout, NULL);\r
+  GetEfiGlobalVariable2 (EFI_CON_IN_VARIABLE_NAME, (VOID **) &VarConin, NULL);\r
 \r
   if (VarConout == NULL || VarConin == NULL) {\r
     //\r
@@ -731,13 +820,13 @@ Returns:
       // Update the console variable with the connect type\r
       //\r
       if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
-        BdsLibUpdateConsoleVariable (VarConsoleInp, PlatformConsole[Index].DevicePath, NULL);\r
+        EfiBootManagerUpdateConsoleVariable (ConIn, PlatformConsole[Index].DevicePath, NULL);\r
       }\r
       if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
-        BdsLibUpdateConsoleVariable (VarConsoleOut, PlatformConsole[Index].DevicePath, NULL);\r
+        EfiBootManagerUpdateConsoleVariable (ConOut, PlatformConsole[Index].DevicePath, NULL);\r
       }\r
       if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
-        BdsLibUpdateConsoleVariable (VarErrorOut, PlatformConsole[Index].DevicePath, NULL);\r
+        EfiBootManagerUpdateConsoleVariable (ErrOut, PlatformConsole[Index].DevicePath, NULL);\r
       }\r
     }\r
   } else {\r
@@ -746,16 +835,6 @@ Returns:
     //\r
     DetectAndPreparePlatformPciDevicePaths (TRUE);\r
   }\r
-\r
-  //\r
-  // Connect the all the default console with current cosole variable\r
-  //\r
-  Status = BdsLibConnectAllDefaultConsoles ();\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
 }\r
 \r
 \r
@@ -991,7 +1070,7 @@ ConnectRecursivelyIfPciMassStorage (
     //\r
     // Print Device Path\r
     //\r
-    DevPathStr = DevicePathToStr (DevicePath);\r
+    DevPathStr = ConvertDevicePathToText (DevicePath, FALSE, FALSE);\r
     if (DevPathStr != NULL) {\r
       DEBUG((\r
         EFI_D_INFO,\r
@@ -1080,7 +1159,6 @@ PlatformBdsRestoreNvVarsFromHardDisk (
 \r
 }\r
 \r
-\r
 VOID\r
 PlatformBdsConnectSequence (\r
   VOID\r
@@ -1117,14 +1195,15 @@ Returns:
     //\r
     // Build the platform boot option\r
     //\r
-    BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r
+    EfiBootManagerConnectDevicePath (gPlatformConnectSequence[Index], NULL);\r
     Index++;\r
   }\r
 \r
   //\r
   // Just use the simple policy to connect all devices\r
   //\r
-  BdsLibConnectAll ();\r
+  DEBUG ((EFI_D_INFO, "EfiBootManagerConnectAll\n"));\r
+  EfiBootManagerConnectAll ();\r
 \r
   PciAcpiInitialization ();\r
 \r
@@ -1134,31 +1213,6 @@ Returns:
   gST->ConOut->ClearScreen (gST->ConOut);\r
 }\r
 \r
-VOID\r
-PlatformBdsGetDriverOption (\r
-  IN OUT LIST_ENTRY              *BdsDriverLists\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Load the predefined driver option, OEM/IBV can customize this\r
-  to load their own drivers\r
-\r
-Arguments:\r
-\r
-  BdsDriverLists  - The header of the driver option link list.\r
-\r
-Returns:\r
-\r
-  None.\r
-\r
---*/\r
-{\r
-  DEBUG ((EFI_D_INFO, "PlatformBdsGetDriverOption\n"));\r
-  return;\r
-}\r
-\r
 VOID\r
 PlatformBdsDiagnostics (\r
   IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,\r
@@ -1278,11 +1332,6 @@ Routine Description:
     PlatformBdsRestoreNvVarsFromHardDisk ();\r
   }\r
 \r
-  //\r
-  // Load the driver option as the driver option list\r
-  //\r
-  PlatformBdsGetDriverOption (DriverOptionList);\r
-\r
   //\r
   // Get current Boot Mode\r
   //\r
@@ -1294,16 +1343,6 @@ Routine Description:
   // Notes: this part code can be change with the table policy\r
   //\r
   ASSERT (BootMode == BOOT_WITH_FULL_CONFIGURATION);\r
-  //\r
-  // Connect platform console\r
-  //\r
-  Status = PlatformBdsConnectConsole (gPlatformConsole);\r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // Here OEM/IBV can customize with defined action\r
-    //\r
-    PlatformBdsNoConsoleAction ();\r
-  }\r
 \r
   //\r
   // Memory test and Logo show\r
@@ -1320,139 +1359,11 @@ Routine Description:
   //\r
   TryRunningQemuKernel ();\r
 \r
-  DEBUG ((EFI_D_INFO, "BdsLibConnectAll\n"));\r
-  BdsLibConnectAll ();\r
-  BdsLibEnumerateAllBootOption (BootOptionList);\r
-\r
-  SetBootOrderFromQemu (BootOptionList);\r
-  //\r
-  // The BootOrder variable may have changed, reload the in-memory list with\r
-  // it.\r
-  //\r
-  BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
-\r
-  PlatformBdsEnterFrontPage (GetFrontPageTimeoutFromQemu(), TRUE);\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-PlatformBdsBootSuccess (\r
-  IN  BDS_COMMON_OPTION   *Option\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Hook point after a boot attempt succeeds. We don't expect a boot option to\r
-  return, so the EFI 1.0 specification defines that you will default to an\r
-  interactive mode and stop processing the BootOrder list in this case. This\r
-  is alos a platform implementation and can be customized by IBV/OEM.\r
-\r
-Arguments:\r
-\r
-  Option - Pointer to Boot Option that succeeded to boot.\r
-\r
-Returns:\r
-\r
-  None.\r
-\r
---*/\r
-{\r
-  CHAR16  *TmpStr;\r
+  EfiBootManagerRefreshAllBootOption ();\r
 \r
-  DEBUG ((EFI_D_INFO, "PlatformBdsBootSuccess\n"));\r
-  //\r
-  // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
-  // select loop then we need to pop up a UI and wait for user input.\r
-  //\r
-  TmpStr = Option->StatusString;\r
-  if (TmpStr != NULL) {\r
-    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
-    FreePool (TmpStr);\r
-  }\r
+  SetBootOrderFromQemu (NULL);\r
 }\r
 \r
-VOID\r
-EFIAPI\r
-PlatformBdsBootFail (\r
-  IN  BDS_COMMON_OPTION  *Option,\r
-  IN  EFI_STATUS         Status,\r
-  IN  CHAR16             *ExitData,\r
-  IN  UINTN              ExitDataSize\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Hook point after a boot attempt fails.\r
-\r
-Arguments:\r
-\r
-  Option - Pointer to Boot Option that failed to boot.\r
-\r
-  Status - Status returned from failed boot.\r
-\r
-  ExitData - Exit data returned from failed boot.\r
-\r
-  ExitDataSize - Exit data size returned from failed boot.\r
-\r
-Returns:\r
-\r
-  None.\r
-\r
---*/\r
-{\r
-  CHAR16  *TmpStr;\r
-\r
-  DEBUG ((EFI_D_INFO, "PlatformBdsBootFail\n"));\r
-\r
-  //\r
-  // If Boot returned with failed status then we need to pop up a UI and wait\r
-  // for user input.\r
-  //\r
-  TmpStr = Option->StatusString;\r
-  if (TmpStr != NULL) {\r
-    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
-    FreePool (TmpStr);\r
-  }\r
-}\r
-\r
-EFI_STATUS\r
-PlatformBdsNoConsoleAction (\r
-  VOID\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function is remained for IBV/OEM to do some platform action,\r
-  if there no console device can be connected.\r
-\r
-Arguments:\r
-\r
-  None.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS      - Direct return success now.\r
-\r
---*/\r
-{\r
-  DEBUG ((EFI_D_INFO, "PlatformBdsNoConsoleAction\n"));\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-PlatformBdsLockNonUpdatableFlash (\r
-  VOID\r
-  )\r
-{\r
-  DEBUG ((EFI_D_INFO, "PlatformBdsLockNonUpdatableFlash\n"));\r
-  return;\r
-}\r
-\r
-\r
 /**\r
   This notification function is invoked when an instance of the\r
   EFI_DEVICE_PATH_PROTOCOL is produced.\r
@@ -1566,23 +1477,3 @@ PlatformBootManagerWaitCallback (
 {\r
 }\r
 \r
-/**\r
-  Lock the ConsoleIn device in system table. All key\r
-  presses will be ignored until the Password is typed in. The only way to\r
-  disable the password is to type it in to a ConIn device.\r
-\r
-  @param  Password        Password used to lock ConIn device.\r
-\r
-  @retval EFI_SUCCESS     lock the Console In Spliter virtual handle successfully.\r
-  @retval EFI_UNSUPPORTED Password not found\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-LockKeyboards (\r
-  IN  CHAR16    *Password\r
-  )\r
-{\r
-    return EFI_UNSUPPORTED;\r
-}\r
-\r