2 This file include all platform action which can be customized
5 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "PlatformBootManager.h"
19 EFI_GUID mUefiShellFileGuid
= { 0x7C04A583, 0x9E3E, 0x4f1c, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 };
22 Return the index of the load option in the load option array.
24 The function consider two load options are equal when the
25 OptionType, Attributes, Description, FilePath and OptionalData are equal.
27 @param Key Pointer to the load option to be found.
28 @param Array Pointer to the array of load options to be found.
29 @param Count Number of entries in the Array.
31 @retval -1 Key wasn't found in the Array.
32 @retval 0 ~ Count-1 The index of the Key in the Array.
35 PlatformFindLoadOption (
36 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Key
,
37 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Array
,
43 for (Index
= 0; Index
< Count
; Index
++) {
44 if ((Key
->OptionType
== Array
[Index
].OptionType
) &&
45 (Key
->Attributes
== Array
[Index
].Attributes
) &&
46 (StrCmp (Key
->Description
, Array
[Index
].Description
) == 0) &&
47 (CompareMem (Key
->FilePath
, Array
[Index
].FilePath
, GetDevicePathSize (Key
->FilePath
)) == 0) &&
48 (Key
->OptionalDataSize
== Array
[Index
].OptionalDataSize
) &&
49 (CompareMem (Key
->OptionalData
, Array
[Index
].OptionalData
, Key
->OptionalDataSize
) == 0)) {
58 PlatformRegisterFvBootOption (
66 EFI_BOOT_MANAGER_LOAD_OPTION NewOption
;
67 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
;
68 UINTN BootOptionCount
;
69 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode
;
70 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
71 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
73 Status
= gBS
->HandleProtocol (gImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
74 ASSERT_EFI_ERROR (Status
);
76 EfiInitializeFwVolDevicepathNode (&FileNode
, FileGuid
);
77 DevicePath
= AppendDevicePathNode (
78 DevicePathFromHandle (LoadedImage
->DeviceHandle
),
79 (EFI_DEVICE_PATH_PROTOCOL
*) &FileNode
82 Status
= EfiBootManagerInitializeLoadOption (
84 LoadOptionNumberUnassigned
,
92 if (!EFI_ERROR (Status
)) {
93 BootOptions
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
95 OptionIndex
= PlatformFindLoadOption (&NewOption
, BootOptions
, BootOptionCount
);
97 if (OptionIndex
== -1) {
98 Status
= EfiBootManagerAddLoadOptionVariable (&NewOption
, (UINTN
) -1);
99 ASSERT_EFI_ERROR (Status
);
101 EfiBootManagerFreeLoadOption (&NewOption
);
102 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
107 Do the platform specific action before the console is connected.
110 Update console variable;
111 Register new Driver#### or Boot####;
112 Signal ReadyToLock event.
116 PlatformBootManagerBeforeConsole (
122 WIN_NT_SYSTEM_CONFIGURATION
*Configuration
;
125 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
127 GetVariable2 (L
"Setup", &gEfiWinNtSystemConfigGuid
, (VOID
**) &Configuration
, NULL
);
128 if (Configuration
!= NULL
) {
130 // SetupVariable is corrupt
132 Configuration
->ConOutRow
= PcdGet32 (PcdConOutColumn
);
133 Configuration
->ConOutColumn
= PcdGet32 (PcdConOutRow
);
135 Status
= gRT
->SetVariable (
137 &gEfiWinNtSystemConfigGuid
,
138 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
139 sizeof (WIN_NT_SYSTEM_CONFIGURATION
),
142 if (EFI_ERROR (Status
)) {
143 DEBUG ((EFI_D_ERROR
, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status
));
145 FreePool (Configuration
);
149 // Update the ocnsole variables.
151 for (Index
= 0; gPlatformConsole
[Index
].DevicePath
!= NULL
; Index
++) {
152 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
153 EfiBootManagerUpdateConsoleVariable (ConIn
, gPlatformConsole
[Index
].DevicePath
, NULL
);
156 if ((gPlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
157 EfiBootManagerUpdateConsoleVariable (ConOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
160 if ((gPlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
161 EfiBootManagerUpdateConsoleVariable (ErrOut
, gPlatformConsole
[Index
].DevicePath
, NULL
);
166 // Register ENTER as CONTINUE key
168 Enter
.ScanCode
= SCAN_NULL
;
169 Enter
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
170 EfiBootManagerRegisterContinueKeyOption (0, &Enter
, NULL
);
172 // Map F2 to Boot Manager Menu
174 F2
.ScanCode
= SCAN_F2
;
175 F2
.UnicodeChar
= CHAR_NULL
;
176 EfiBootManagerGetBootManagerMenu (&BootOption
);
177 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &F2
, NULL
);
179 // Register UEFI Shell
181 PlatformRegisterFvBootOption (&mUefiShellFileGuid
, L
"UEFI Shell", LOAD_OPTION_ACTIVE
);
185 Do the platform specific action after the console is connected.
188 Dynamically switch output mode;
189 Signal console ready platform customized event;
190 Run diagnostics like memory testing;
191 Connect certain devices;
192 Dispatch aditional option roms.
196 PlatformBootManagerAfterConsole (
200 EfiBootManagerConnectAll ();
201 EfiBootManagerRefreshAllBootOption ();
204 L
"F2 to enter Boot Manager Menu.\n"
205 L
"Enter to boot directly.\n"
211 This function is called each second during the boot manager waits the timeout.
213 @param TimeoutRemain The remaining timeout.
217 PlatformBootManagerWaitCallback (
221 Print (L
"\r%-2d seconds remained...", TimeoutRemain
);