]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c
Nt32Pkg: Make Shell as the first boot option
[mirror_edk2.git] / Nt32Pkg / Library / PlatformBootManagerLib / PlatformBootManager.c
1 /** @file
2 This file include all platform action which can be customized
3 by IBV/OEM.
4
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
10
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.
13
14 **/
15
16 #include "PlatformBootManager.h"
17
18 /**
19 Perform the platform diagnostic, such like test memory. OEM/IBV also
20 can customize this function to support specific platform diagnostic.
21
22 @param MemoryTestLevel The memory test intensive level
23 @param QuietBoot Indicate if need to enable the quiet boot
24
25 **/
26 VOID
27 PlatformBootManagerDiagnostics (
28 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
29 IN BOOLEAN QuietBoot
30 )
31 {
32 EFI_STATUS Status;
33
34 //
35 // Here we can decide if we need to show
36 // the diagnostics screen
37 // Notes: this quiet boot code should be remove
38 // from the graphic lib
39 //
40 if (QuietBoot) {
41 BootLogoEnableLogo (ImageFormatBmp, PcdGetPtr(PcdLogoFile), EdkiiPlatformLogoDisplayAttributeCenter, 0, 0);
42
43 //
44 // Perform system diagnostic
45 //
46 Status = PlatformBootManagerMemoryTest (MemoryTestLevel);
47 if (EFI_ERROR (Status)) {
48 BootLogoDisableLogo ();
49 }
50
51 return;
52 }
53
54 //
55 // Perform system diagnostic
56 //
57 Status = PlatformBootManagerMemoryTest (MemoryTestLevel);
58 }
59
60 /**
61 Do the platform specific action before the console is connected.
62
63 Such as:
64 Update console variable;
65 Register new Driver#### or Boot####;
66 Signal ReadyToLock event.
67 **/
68 VOID
69 EFIAPI
70 PlatformBootManagerBeforeConsole (
71 VOID
72 )
73 {
74 UINTN Index;
75 EFI_STATUS Status;
76 WIN_NT_SYSTEM_CONFIGURATION *Configuration;
77
78 GetVariable2 (L"Setup", &gEfiWinNtSystemConfigGuid, (VOID **) &Configuration, NULL);
79 if (Configuration != NULL) {
80 //
81 // SetupVariable is corrupt
82 //
83 Configuration->ConOutRow = PcdGet32 (PcdConOutColumn);
84 Configuration->ConOutColumn = PcdGet32 (PcdConOutRow);
85
86 Status = gRT->SetVariable (
87 L"Setup",
88 &gEfiWinNtSystemConfigGuid,
89 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
90 sizeof (WIN_NT_SYSTEM_CONFIGURATION),
91 Configuration
92 );
93 if (EFI_ERROR (Status)) {
94 DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));
95 }
96 FreePool (Configuration);
97 }
98
99 //
100 // Update the ocnsole variables.
101 //
102 for (Index = 0; gPlatformConsole[Index].DevicePath != NULL; Index++) {
103 if ((gPlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
104 EfiBootManagerUpdateConsoleVariable (ConIn, gPlatformConsole[Index].DevicePath, NULL);
105 }
106
107 if ((gPlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
108 EfiBootManagerUpdateConsoleVariable (ConOut, gPlatformConsole[Index].DevicePath, NULL);
109 }
110
111 if ((gPlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
112 EfiBootManagerUpdateConsoleVariable (ErrOut, gPlatformConsole[Index].DevicePath, NULL);
113 }
114 }
115 }
116
117 /**
118 Returns the priority number.
119
120 @param BootOption
121 **/
122 UINTN
123 BootOptionPriority (
124 CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
125 )
126 {
127 //
128 // Make sure Shell is first
129 //
130 if (StrCmp (BootOption->Description, L"UEFI Shell") == 0) {
131 return 0;
132 }
133 return 100;
134 }
135
136 INTN
137 EFIAPI
138 CompareBootOption (
139 CONST EFI_BOOT_MANAGER_LOAD_OPTION *Left,
140 CONST EFI_BOOT_MANAGER_LOAD_OPTION *Right
141 )
142 {
143 return BootOptionPriority (Left) - BootOptionPriority (Right);
144 }
145
146 /**
147 Do the platform specific action after the console is connected.
148
149 Such as:
150 Dynamically switch output mode;
151 Signal console ready platform customized event;
152 Run diagnostics like memory testing;
153 Connect certain devices;
154 Dispatch aditional option roms.
155 **/
156 VOID
157 EFIAPI
158 PlatformBootManagerAfterConsole (
159 VOID
160 )
161 {
162 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;
163 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;
164 EFI_INPUT_KEY Enter;
165 EFI_INPUT_KEY F2;
166 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
167
168 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;
169 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;
170
171 EfiBootManagerConnectAll ();
172 EfiBootManagerRefreshAllBootOption ();
173
174 //
175 // Register ENTER as CONTINUE key
176 //
177 Enter.ScanCode = SCAN_NULL;
178 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
179 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
180 //
181 // Map F2 to Boot Manager Menu
182 //
183 F2.ScanCode = SCAN_F2;
184 F2.UnicodeChar = CHAR_NULL;
185 EfiBootManagerGetBootManagerMenu (&BootOption);
186 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);
187
188 //
189 // Make Shell as the first boot option
190 //
191 EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, (SORT_COMPARE) CompareBootOption);
192
193 PlatformBootManagerDiagnostics (QUICK, TRUE);
194
195 PrintXY (10, 10, &White, &Black, L"F2 to enter Boot Manager Menu. ");
196 PrintXY (10, 30, &White, &Black, L"Enter to boot directly.");
197 }
198
199 /**
200 This function is called each second during the boot manager waits the timeout.
201
202 @param TimeoutRemain The remaining timeout.
203 **/
204 VOID
205 EFIAPI
206 PlatformBootManagerWaitCallback (
207 UINT16 TimeoutRemain
208 )
209 {
210 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;
211 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;
212 UINT16 Timeout;
213
214 Timeout = PcdGet16 (PcdPlatformBootTimeOut);
215
216 Black.Raw = 0x00000000;
217 White.Raw = 0x00FFFFFF;
218
219 BootLogoUpdateProgress (
220 White.Pixel,
221 Black.Pixel,
222 L"Start boot option",
223 White.Pixel,
224 (Timeout - TimeoutRemain) * 100 / Timeout,
225 0
226 );
227 }