PlatformBootManager.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /** @file
  2. This file include all platform action which can be customized
  3. by IBV/OEM.
  4. Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
  5. This program and the accompanying materials
  6. are licensed and made available under the terms and conditions of the BSD License
  7. which accompanies this distribution. The full text of the license may be found at
  8. http://opensource.org/licenses/bsd-license.php
  9. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  11. **/
  12. #include "PlatformBootManager.h"
  13. #include "PlatformConsole.h"
  14. VOID
  15. InstallReadyToLock (
  16. VOID
  17. )
  18. {
  19. EFI_STATUS Status;
  20. EFI_HANDLE Handle;
  21. EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;
  22. DEBUG((DEBUG_INFO,"InstallReadyToLock entering......\n"));
  23. //
  24. // Inform the SMM infrastructure that we're entering BDS and may run 3rd party code hereafter
  25. // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth
  26. //
  27. EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
  28. DEBUG((DEBUG_INFO,"All EndOfDxe callbacks have returned successfully\n"));
  29. //
  30. // Install DxeSmmReadyToLock protocol in order to lock SMM
  31. //
  32. Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **) &SmmAccess);
  33. if (!EFI_ERROR (Status)) {
  34. Handle = NULL;
  35. Status = gBS->InstallProtocolInterface (
  36. &Handle,
  37. &gEfiDxeSmmReadyToLockProtocolGuid,
  38. EFI_NATIVE_INTERFACE,
  39. NULL
  40. );
  41. ASSERT_EFI_ERROR (Status);
  42. }
  43. DEBUG((DEBUG_INFO,"InstallReadyToLock end\n"));
  44. return;
  45. }
  46. /**
  47. Return the index of the load option in the load option array.
  48. The function consider two load options are equal when the
  49. OptionType, Attributes, Description, FilePath and OptionalData are equal.
  50. @param Key Pointer to the load option to be found.
  51. @param Array Pointer to the array of load options to be found.
  52. @param Count Number of entries in the Array.
  53. @retval -1 Key wasn't found in the Array.
  54. @retval 0 ~ Count-1 The index of the Key in the Array.
  55. **/
  56. INTN
  57. PlatformFindLoadOption (
  58. IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,
  59. IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,
  60. IN UINTN Count
  61. )
  62. {
  63. UINTN Index;
  64. for (Index = 0; Index < Count; Index++) {
  65. if ((Key->OptionType == Array[Index].OptionType) &&
  66. (Key->Attributes == Array[Index].Attributes) &&
  67. (StrCmp (Key->Description, Array[Index].Description) == 0) &&
  68. (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) &&
  69. (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&
  70. (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) {
  71. return (INTN) Index;
  72. }
  73. }
  74. return -1;
  75. }
  76. /**
  77. Register a boot option using a file GUID in the FV.
  78. @param FileGuid The file GUID name in FV.
  79. @param Description The boot option description.
  80. @param Attributes The attributes used for the boot option loading.
  81. **/
  82. VOID
  83. PlatformRegisterFvBootOption (
  84. EFI_GUID *FileGuid,
  85. CHAR16 *Description,
  86. UINT32 Attributes
  87. )
  88. {
  89. EFI_STATUS Status;
  90. UINTN OptionIndex;
  91. EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
  92. EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
  93. UINTN BootOptionCount;
  94. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;
  95. EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
  96. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  97. Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
  98. ASSERT_EFI_ERROR (Status);
  99. EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
  100. DevicePath = AppendDevicePathNode (
  101. DevicePathFromHandle (LoadedImage->DeviceHandle),
  102. (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
  103. );
  104. Status = EfiBootManagerInitializeLoadOption (
  105. &NewOption,
  106. LoadOptionNumberUnassigned,
  107. LoadOptionTypeBoot,
  108. Attributes,
  109. Description,
  110. DevicePath,
  111. NULL,
  112. 0
  113. );
  114. if (!EFI_ERROR (Status)) {
  115. BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
  116. OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount);
  117. if (OptionIndex == -1) {
  118. Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);
  119. ASSERT_EFI_ERROR (Status);
  120. }
  121. EfiBootManagerFreeLoadOption (&NewOption);
  122. EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
  123. }
  124. }
  125. /**
  126. Do the platform specific action before the console is connected.
  127. Such as:
  128. Update console variable;
  129. Register new Driver#### or Boot####;
  130. Signal ReadyToLock event.
  131. **/
  132. VOID
  133. EFIAPI
  134. PlatformBootManagerBeforeConsole (
  135. VOID
  136. )
  137. {
  138. EFI_INPUT_KEY Enter;
  139. EFI_INPUT_KEY F2;
  140. EFI_INPUT_KEY Down;
  141. EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
  142. PlatformConsoleInit ();
  143. //
  144. // Register ENTER as CONTINUE key
  145. //
  146. Enter.ScanCode = SCAN_NULL;
  147. Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
  148. EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
  149. //
  150. // Map F2 to Boot Manager Menu
  151. //
  152. F2.ScanCode = SCAN_F2;
  153. F2.UnicodeChar = CHAR_NULL;
  154. EfiBootManagerGetBootManagerMenu (&BootOption);
  155. EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);
  156. //
  157. // Also add Down key to Boot Manager Menu since some serial terminals don't support F2 key.
  158. //
  159. Down.ScanCode = SCAN_DOWN;
  160. Down.UnicodeChar = CHAR_NULL;
  161. EfiBootManagerGetBootManagerMenu (&BootOption);
  162. EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &Down, NULL);
  163. //
  164. // Install ready to lock.
  165. // This needs to be done before option rom dispatched.
  166. //
  167. InstallReadyToLock ();
  168. //
  169. // Dispatch deferred images after EndOfDxe event and ReadyToLock installation.
  170. //
  171. EfiBootManagerDispatchDeferredImages ();
  172. }
  173. /**
  174. Do the platform specific action after the console is connected.
  175. Such as:
  176. Dynamically switch output mode;
  177. Signal console ready platform customized event;
  178. Run diagnostics like memory testing;
  179. Connect certain devices;
  180. Dispatch additional option roms.
  181. **/
  182. VOID
  183. EFIAPI
  184. PlatformBootManagerAfterConsole (
  185. VOID
  186. )
  187. {
  188. EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;
  189. EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;
  190. Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;
  191. White.Blue = White.Green = White.Red = White.Reserved = 0xFF;
  192. EfiBootManagerConnectAll ();
  193. EfiBootManagerRefreshAllBootOption ();
  194. //
  195. // Register UEFI Shell
  196. //
  197. PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE);
  198. Print (
  199. L"\n"
  200. L"F2 or Down to enter Boot Manager Menu.\n"
  201. L"ENTER to boot directly.\n"
  202. L"\n"
  203. );
  204. }
  205. /**
  206. This function is called each second during the boot manager waits the timeout.
  207. @param TimeoutRemain The remaining timeout.
  208. **/
  209. VOID
  210. EFIAPI
  211. PlatformBootManagerWaitCallback (
  212. UINT16 TimeoutRemain
  213. )
  214. {
  215. return;
  216. }
  217. /**
  218. The function is called when no boot option could be launched,
  219. including platform recovery options and options pointing to applications
  220. built into firmware volumes.
  221. If this function returns, BDS attempts to enter an infinite loop.
  222. **/
  223. VOID
  224. EFIAPI
  225. PlatformBootManagerUnableToBoot (
  226. VOID
  227. )
  228. {
  229. return;
  230. }