]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c
ArmVirtPkg/PlatformBootManagerLib: introduce the progress bar
[mirror_edk2.git] / ArmVirtPkg / Library / PlatformBootManagerLib / PlatformBm.c
index b114420fd020f5f2f7ce6b20f325e44ed6344c41..198d0602b3c08a741e16319dccf44bcdfa8cf0a0 100644 (file)
@@ -3,7 +3,7 @@
 \r
   Copyright (C) 2015-2016, Red Hat, Inc.\r
   Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
-  Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials are licensed and made available\r
   under the terms and conditions of the BSD License which accompanies this\r
 **/\r
 \r
 #include <IndustryStandard/Pci22.h>\r
+#include <Library/BootLogoLib.h>\r
 #include <Library/DevicePathLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/QemuBootOrderLib.h>\r
 #include <Library/UefiBootManagerLib.h>\r
 #include <Protocol/DevicePath.h>\r
 #include <Protocol/GraphicsOutput.h>\r
+#include <Protocol/LoadedImage.h>\r
 #include <Protocol/PciIo.h>\r
 #include <Protocol/PciRootBridgeIo.h>\r
 #include <Guid/EventGroup.h>\r
@@ -322,6 +324,114 @@ AddOutput (
     ReportText));\r
 }\r
 \r
+STATIC\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
+\r
+STATIC\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 and ESC 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
 \r
 //\r
 // BDS Platform Functions\r
@@ -395,6 +505,11 @@ PlatformBootManagerBeforeConsole (
   // Set the front page timeout from the QEMU configuration.\r
   //\r
   PcdSet16 (PcdPlatformBootTimeOut, GetFrontPageTimeoutFromQemu ());\r
+\r
+  //\r
+  // Register platform-specific boot options and keyboard shortcuts.\r
+  //\r
+  PlatformRegisterOptionsAndKeys ();\r
 }\r
 \r
 /**\r
@@ -417,12 +532,18 @@ PlatformBootManagerAfterConsole (
   //\r
   // Show the splash screen.\r
   //\r
-  EnableQuietBoot (PcdGetPtr (PcdLogoFile));\r
+  BootLogoEnableLogo (\r
+    ImageFormatBmp,                          // ImageFormat\r
+    PcdGetPtr (PcdLogoFile),                 // Logo\r
+    EdkiiPlatformLogoDisplayAttributeCenter, // Attribute\r
+    0,                                       // OffsetX\r
+    0                                        // OffsetY\r
+    );\r
 \r
   //\r
   // Connect the rest of the devices.\r
   //\r
-  BdsLibConnectAll ();\r
+  EfiBootManagerConnectAll ();\r
 \r
   //\r
   // Process QEMU's -kernel command line option. Note that the kernel booted\r
@@ -432,63 +553,12 @@ PlatformBootManagerAfterConsole (
   //\r
   TryRunningQemuKernel ();\r
 \r
-  BdsLibEnumerateAllBootOption (BootOptionList);\r
-  SetBootOrderFromQemu (BootOptionList);\r
   //\r
-  // The BootOrder variable may have changed, reload the in-memory list with\r
-  // it.\r
+  // Enumerate all possible boot options, then filter and reorder them based on\r
+  // the QEMU configuration.\r
   //\r
-  BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
-}\r
-\r
-/**\r
-  Hook point after a boot attempt succeeds. We don't expect a boot option to\r
-  return, so the UEFI 2.0 specification defines that you will default to an\r
-  interactive mode and stop processing the BootOrder list in this case. This\r
-  is also a platform implementation and can be customized by IBV/OEM.\r
-\r
-  @param  Option                  Pointer to Boot Option that succeeded to boot.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-PlatformBdsBootSuccess (\r
-  IN  BDS_COMMON_OPTION *Option\r
-  )\r
-{\r
-}\r
-\r
-/**\r
-  Hook point after a boot attempt fails.\r
-\r
-  @param  Option                  Pointer to Boot Option that failed to boot.\r
-  @param  Status                  Status returned from failed boot.\r
-  @param  ExitData                Exit data returned from failed boot.\r
-  @param  ExitDataSize            Exit data size returned from failed boot.\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
-\r
-/**\r
-  This function locks platform flash that is not allowed to be updated during normal boot path.\r
-  The flash layout is platform specific.\r
-**/\r
-VOID\r
-EFIAPI\r
-PlatformBdsLockNonUpdatableFlash (\r
-  VOID\r
-  )\r
-{\r
-  return;\r
+  EfiBootManagerRefreshAllBootOption ();\r
+  SetBootOrderFromQemu ();\r
 }\r
 \r
 /**\r
@@ -503,4 +573,21 @@ PlatformBootManagerWaitCallback (
   UINT16          TimeoutRemain\r
   )\r
 {\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;\r
+  UINT16                              Timeout;\r
+\r
+  Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r
+\r
+  Black.Raw = 0x00000000;\r
+  White.Raw = 0x00FFFFFF;\r
+\r
+  BootLogoUpdateProgress (\r
+    White.Pixel,\r
+    Black.Pixel,\r
+    L"Start boot option",\r
+    White.Pixel,\r
+    (Timeout - TimeoutRemain) * 100 / Timeout,\r
+    0\r
+    );\r
 }\r