]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/FileExplorer.c
Support RouteConfig function for BdsDxe driver.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BootMaint / FileExplorer.c
1 /** @file
2 File explorer related functions.
3
4 Copyright (c) 2004 - 2014, 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
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "BootMaint.h"
16
17 /**
18 Update the File Explore page.
19
20 @param CallbackData The BMM context data.
21 @param MenuOption Pointer to menu options to display.
22
23 **/
24 VOID
25 UpdateFileExplorePage (
26 IN BMM_CALLBACK_DATA *CallbackData,
27 BM_MENU_OPTION *MenuOption
28 )
29 {
30 UINTN Index;
31 BM_MENU_ENTRY *NewMenuEntry;
32 BM_FILE_CONTEXT *NewFileContext;
33 EFI_FORM_ID FormId;
34
35 NewMenuEntry = NULL;
36 NewFileContext = NULL;
37 FormId = 0;
38
39 RefreshUpdateData ();
40 mStartLabel->Number = FORM_FILE_EXPLORER_ID;
41
42 for (Index = 0; Index < MenuOption->MenuNumber; Index++) {
43 NewMenuEntry = BOpt_GetMenuEntry (MenuOption, Index);
44 NewFileContext = (BM_FILE_CONTEXT *) NewMenuEntry->VariableContext;
45
46 if (NewFileContext->IsBootLegacy) {
47 continue;
48 }
49
50 if ((NewFileContext->IsDir) || (FileExplorerStateBootFromFile == CallbackData->FeCurrentState)) {
51 //
52 // Create Text opcode for directory, also create Text opcode for file in FileExplorerStateBootFromFile.
53 //
54 HiiCreateActionOpCode (
55 mStartOpCodeHandle,
56 (UINT16) (FILE_OPTION_OFFSET + Index),
57 NewMenuEntry->DisplayStringToken,
58 STRING_TOKEN (STR_NULL_STRING),
59 EFI_IFR_FLAG_CALLBACK,
60 0
61 );
62 } else {
63 //
64 // Create Goto opcode for file in FileExplorerStateAddBootOption or FileExplorerStateAddDriverOptionState.
65 //
66 if (FileExplorerStateAddBootOption == CallbackData->FeCurrentState) {
67 FormId = FORM_BOOT_ADD_DESCRIPTION_ID;
68 } else if (FileExplorerStateAddDriverOptionState == CallbackData->FeCurrentState) {
69 FormId = FORM_DRIVER_ADD_FILE_DESCRIPTION_ID;
70 }
71
72 HiiCreateGotoOpCode (
73 mStartOpCodeHandle,
74 FormId,
75 NewMenuEntry->DisplayStringToken,
76 STRING_TOKEN (STR_NULL_STRING),
77 EFI_IFR_FLAG_CALLBACK,
78 (UINT16) (FILE_OPTION_GOTO_OFFSET + Index)
79 );
80 }
81 }
82
83 HiiUpdateForm (
84 CallbackData->FeHiiHandle,
85 &gFileExploreFormSetGuid,
86 FORM_FILE_EXPLORER_ID,
87 mStartOpCodeHandle, // Label FORM_FILE_EXPLORER_ID
88 mEndOpCodeHandle // LABEL_END
89 );
90 }
91
92 /**
93 Update the file explower page with the refershed file system.
94
95
96 @param CallbackData BMM context data
97 @param KeyValue Key value to identify the type of data to expect.
98
99 @retval TRUE Inform the caller to create a callback packet to exit file explorer.
100 @retval FALSE Indicate that there is no need to exit file explorer.
101
102 **/
103 BOOLEAN
104 UpdateFileExplorer (
105 IN BMM_CALLBACK_DATA *CallbackData,
106 IN UINT16 KeyValue
107 )
108 {
109 UINT16 FileOptionMask;
110 BM_MENU_ENTRY *NewMenuEntry;
111 BM_FILE_CONTEXT *NewFileContext;
112 EFI_FORM_ID FormId;
113 BOOLEAN ExitFileExplorer;
114 EFI_STATUS Status;
115
116 NewMenuEntry = NULL;
117 NewFileContext = NULL;
118 ExitFileExplorer = FALSE;
119
120 FileOptionMask = (UINT16) (FILE_OPTION_MASK & KeyValue);
121
122 if (FileExplorerDisplayUnknown == CallbackData->FeDisplayContext) {
123 //
124 // First in, display file system.
125 //
126 BOpt_FreeMenu (&FsOptionMenu);
127 BOpt_FindFileSystem (CallbackData);
128 CreateMenuStringToken (CallbackData, CallbackData->FeHiiHandle, &FsOptionMenu);
129
130 UpdateFileExplorePage (CallbackData, &FsOptionMenu);
131
132 CallbackData->FeDisplayContext = FileExplorerDisplayFileSystem;
133 } else {
134 if (FileExplorerDisplayFileSystem == CallbackData->FeDisplayContext) {
135 NewMenuEntry = BOpt_GetMenuEntry (&FsOptionMenu, FileOptionMask);
136 } else if (FileExplorerDisplayDirectory == CallbackData->FeDisplayContext) {
137 NewMenuEntry = BOpt_GetMenuEntry (&DirectoryMenu, FileOptionMask);
138 }
139
140 NewFileContext = (BM_FILE_CONTEXT *) NewMenuEntry->VariableContext;
141
142 if (NewFileContext->IsDir ) {
143 CallbackData->FeDisplayContext = FileExplorerDisplayDirectory;
144
145 RemoveEntryList (&NewMenuEntry->Link);
146 BOpt_FreeMenu (&DirectoryMenu);
147 Status = BOpt_FindFiles (CallbackData, NewMenuEntry);
148 if (EFI_ERROR (Status)) {
149 ExitFileExplorer = TRUE;
150 goto exit;
151 }
152 CreateMenuStringToken (CallbackData, CallbackData->FeHiiHandle, &DirectoryMenu);
153 BOpt_DestroyMenuEntry (NewMenuEntry);
154
155 UpdateFileExplorePage (CallbackData, &DirectoryMenu);
156
157 } else {
158 switch (CallbackData->FeCurrentState) {
159 case FileExplorerStateBootFromFile:
160 //
161 // Restore to original mode before launching boot option.
162 //
163 BdsSetConsoleMode (FALSE);
164
165 //
166 // Here boot from file
167 //
168 BootThisFile (NewFileContext);
169 //
170 // Set proper video resolution and text mode for setup.
171 //
172 BdsSetConsoleMode (TRUE);
173 ExitFileExplorer = TRUE;
174 break;
175
176 case FileExplorerStateAddBootOption:
177 case FileExplorerStateAddDriverOptionState:
178 if (FileExplorerStateAddBootOption == CallbackData->FeCurrentState) {
179 FormId = FORM_BOOT_ADD_DESCRIPTION_ID;
180 } else {
181 FormId = FORM_DRIVER_ADD_FILE_DESCRIPTION_ID;
182 }
183
184 CallbackData->MenuEntry = NewMenuEntry;
185 CallbackData->LoadContext->FilePathList = ((BM_FILE_CONTEXT *) (CallbackData->MenuEntry->VariableContext))->DevicePath;
186
187 //
188 // Create Subtitle op-code for the display string of the option.
189 //
190 RefreshUpdateData ();
191 mStartLabel->Number = FormId;
192
193 HiiCreateSubTitleOpCode (
194 mStartOpCodeHandle,
195 NewMenuEntry->DisplayStringToken,
196 0,
197 0,
198 0
199 );
200
201 HiiUpdateForm (
202 CallbackData->FeHiiHandle,
203 &gFileExploreFormSetGuid,
204 FormId,
205 mStartOpCodeHandle, // Label FormId
206 mEndOpCodeHandle // LABEL_END
207 );
208 break;
209
210 default:
211 break;
212 }
213 }
214 }
215 exit:
216 return ExitFileExplorer;
217 }
218
219 /**
220 This function applies changes in a driver's configuration.
221 Input is a Configuration, which has the routing data for this
222 driver followed by name / value configuration pairs. The driver
223 must apply those pairs to its configurable storage. If the
224 driver's configuration is stored in a linear block of data
225 and the driver's name / value pairs are in <BlockConfig>
226 format, it may use the ConfigToBlock helper function (above) to
227 simplify the job. Currently not implemented.
228
229 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
230 @param[in] Configuration A null-terminated Unicode string in
231 <ConfigString> format.
232 @param[out] Progress A pointer to a string filled in with the
233 offset of the most recent '&' before the
234 first failing name / value pair (or the
235 beginn ing of the string if the failure
236 is in the first name / value pair) or
237 the terminating NULL if all was
238 successful.
239
240 @retval EFI_SUCCESS The results have been distributed or are
241 awaiting distribution.
242 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
243 parts of the results that must be
244 stored awaiting possible future
245 protocols.
246 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
247 Results parameter would result
248 in this type of error.
249 @retval EFI_NOT_FOUND Target for the specified routing data
250 was not found.
251 **/
252 EFI_STATUS
253 EFIAPI
254 FileExplorerRouteConfig (
255 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
256 IN CONST EFI_STRING Configuration,
257 OUT EFI_STRING *Progress
258 )
259 {
260 EFI_STATUS Status;
261 UINTN BufferSize;
262 EFI_HII_CONFIG_ROUTING_PROTOCOL *ConfigRouting;
263 FILE_EXPLORER_NV_DATA *FeData;
264 BMM_CALLBACK_DATA *Private;
265
266 if (Progress == NULL) {
267 return EFI_INVALID_PARAMETER;
268 }
269 *Progress = Configuration;
270
271 if (Configuration == NULL) {
272 return EFI_INVALID_PARAMETER;
273 }
274
275 //
276 // Check routing data in <ConfigHdr>.
277 // Note: there is no name for Name/Value storage, only GUID will be checked
278 //
279 if (!HiiIsConfigHdrMatch (Configuration, &gFileExploreFormSetGuid, mFileExplorerStorageName)) {
280 return EFI_NOT_FOUND;
281 }
282
283 Status = gBS->LocateProtocol (
284 &gEfiHiiConfigRoutingProtocolGuid,
285 NULL,
286 &ConfigRouting
287 );
288 if (EFI_ERROR (Status)) {
289 return Status;
290 }
291
292 Private = FE_CALLBACK_DATA_FROM_THIS (This);
293 //
294 // Get Buffer Storage data from EFI variable
295 //
296 BufferSize = sizeof (FILE_EXPLORER_NV_DATA );
297 FeData = &Private->FeFakeNvData;
298
299 //
300 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
301 //
302 Status = ConfigRouting->ConfigToBlock (
303 ConfigRouting,
304 Configuration,
305 (UINT8 *) FeData,
306 &BufferSize,
307 Progress
308 );
309 ASSERT_EFI_ERROR (Status);
310
311 if (FeData->BootDescriptionData[0] != 0x00 || FeData->BootOptionalData[0] != 0x00) {
312 Status = Var_UpdateBootOption (Private, FeData);
313 if (EFI_ERROR (Status)) {
314 return Status;
315 }
316
317 BOpt_GetBootOptions (Private);
318 CreateMenuStringToken (Private, Private->FeHiiHandle, &BootOptionMenu);
319 }
320
321 if (FeData->DriverDescriptionData[0] != 0x00 || FeData->DriverOptionalData[0] != 0x00) {
322 Status = Var_UpdateDriverOption (
323 Private,
324 Private->FeHiiHandle,
325 FeData->DriverDescriptionData,
326 FeData->DriverOptionalData,
327 FeData->ForceReconnect
328 );
329 if (EFI_ERROR (Status)) {
330 return Status;
331 }
332
333 BOpt_GetDriverOptions (Private);
334 CreateMenuStringToken (Private, Private->FeHiiHandle, &DriverOptionMenu);
335 }
336
337 return EFI_SUCCESS;
338 }
339
340 /**
341 This function processes the results of changes in configuration.
342 When user select a interactive opcode, this callback will be triggered.
343 Based on the Question(QuestionId) that triggers the callback, the corresponding
344 actions is performed. It handles:
345
346 1) the addition of boot option.
347 2) the addition of driver option.
348 3) exit from file browser
349 4) update of file content if a dir is selected.
350 5) boot the file if a file is selected in "boot from file"
351
352
353 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
354 @param Action Specifies the type of action taken by the browser.
355 @param QuestionId A unique value which is sent to the original exporting driver
356 so that it can identify the type of data to expect.
357 @param Type The type of value for the question.
358 @param Value A pointer to the data being sent to the original exporting driver.
359 @param ActionRequest On return, points to the action requested by the callback function.
360
361 @retval EFI_SUCCESS The callback successfully handled the action.
362 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
363 @retval EFI_DEVICE_ERROR The variable could not be saved.
364 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
365 @retval EFI_INVALID_PARAMETER If paramter Value or ActionRequest is NULL.
366 **/
367 EFI_STATUS
368 EFIAPI
369 FileExplorerCallback (
370 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
371 IN EFI_BROWSER_ACTION Action,
372 IN EFI_QUESTION_ID QuestionId,
373 IN UINT8 Type,
374 IN EFI_IFR_TYPE_VALUE *Value,
375 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
376 )
377 {
378 BMM_CALLBACK_DATA *Private;
379 FILE_EXPLORER_NV_DATA *NvRamMap;
380 EFI_STATUS Status;
381
382 if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED) {
383 //
384 // All other action return unsupported.
385 //
386 return EFI_UNSUPPORTED;
387 }
388
389 Status = EFI_SUCCESS;
390 Private = FE_CALLBACK_DATA_FROM_THIS (This);
391
392 //
393 // Retrieve uncommitted data from Form Browser
394 //
395 NvRamMap = &Private->FeFakeNvData;
396 HiiGetBrowserData (&gFileExploreFormSetGuid, mFileExplorerStorageName, sizeof (FILE_EXPLORER_NV_DATA), (UINT8 *) NvRamMap);
397
398 if (Action == EFI_BROWSER_ACTION_CHANGED) {
399 if ((Value == NULL) || (ActionRequest == NULL)) {
400 return EFI_INVALID_PARAMETER;
401 }
402
403 if (QuestionId == KEY_VALUE_SAVE_AND_EXIT_BOOT || QuestionId == KEY_VALUE_SAVE_AND_EXIT_DRIVER) {
404 //
405 // Apply changes and exit formset
406 //
407 if (FileExplorerStateAddBootOption == Private->FeCurrentState) {
408 Status = Var_UpdateBootOption (Private, NvRamMap);
409 if (EFI_ERROR (Status)) {
410 return Status;
411 }
412
413 BOpt_GetBootOptions (Private);
414 CreateMenuStringToken (Private, Private->FeHiiHandle, &BootOptionMenu);
415 } else if (FileExplorerStateAddDriverOptionState == Private->FeCurrentState) {
416 Status = Var_UpdateDriverOption (
417 Private,
418 Private->FeHiiHandle,
419 NvRamMap->DriverDescriptionData,
420 NvRamMap->DriverOptionalData,
421 NvRamMap->ForceReconnect
422 );
423 if (EFI_ERROR (Status)) {
424 return Status;
425 }
426
427 BOpt_GetDriverOptions (Private);
428 CreateMenuStringToken (Private, Private->FeHiiHandle, &DriverOptionMenu);
429 }
430
431 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
432 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER) {
433 //
434 // Discard changes and exit formset
435 //
436 NvRamMap->DriverOptionalData[0] = 0x0000;
437 NvRamMap->DriverDescriptionData[0] = 0x0000;
438 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
439 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_BOOT) {
440 //
441 // Discard changes and exit formset
442 //
443 NvRamMap->BootOptionalData[0] = 0x0000;
444 NvRamMap->BootDescriptionData[0] = 0x0000;
445 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
446 }else if (QuestionId < FILE_OPTION_OFFSET) {
447 //
448 // Exit File Explorer formset
449 //
450 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
451 } else if (QuestionId >= FILE_OPTION_OFFSET && QuestionId < FILE_OPTION_GOTO_OFFSET) {
452 //
453 // Update forms may return TRUE or FALSE, need to check here.
454 //
455 if (UpdateFileExplorer (Private, QuestionId)) {
456 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
457 }
458 }
459 } else if (Action == EFI_BROWSER_ACTION_CHANGING) {
460 if (Value == NULL) {
461 return EFI_INVALID_PARAMETER;
462 }
463
464 if (QuestionId >= FILE_OPTION_GOTO_OFFSET) {
465 //
466 // function will always return FALSE, no need to check here.
467 //
468 UpdateFileExplorer (Private, QuestionId);
469 }
470 }
471
472 return Status;
473 }