2 File explorer related functions.
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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
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.
15 #include "BootMaint.h"
18 Update the File Explore page.
21 @param CallbackData The BMM context data.
22 @param MenuOption Pointer to menu options to display.
28 UpdateFileExplorePage (
29 IN BMM_CALLBACK_DATA
*CallbackData
,
30 BM_MENU_OPTION
*MenuOption
34 BM_MENU_ENTRY
*NewMenuEntry
;
35 BM_FILE_CONTEXT
*NewFileContext
;
39 NewFileContext
= NULL
;
44 for (Index
= 0; Index
< MenuOption
->MenuNumber
; Index
++) {
45 NewMenuEntry
= BOpt_GetMenuEntry (MenuOption
, Index
);
46 NewFileContext
= (BM_FILE_CONTEXT
*) NewMenuEntry
->VariableContext
;
48 if (NewFileContext
->IsBootLegacy
) {
52 if ((NewFileContext
->IsDir
) || (BOOT_FROM_FILE_STATE
== CallbackData
->FeCurrentState
)) {
54 // Create Text opcode for directory, also create Text opcode for file in BOOT_FROM_FILE_STATE.
57 (UINT16
) (FILE_OPTION_OFFSET
+ Index
),
58 NewMenuEntry
->DisplayStringToken
,
59 STRING_TOKEN (STR_NULL_STRING
),
60 EFI_IFR_FLAG_CALLBACK
,
66 // Create Goto opcode for file in ADD_BOOT_OPTION_STATE or ADD_DRIVER_OPTION_STATE.
68 if (ADD_BOOT_OPTION_STATE
== CallbackData
->FeCurrentState
) {
69 FormId
= FORM_BOOT_ADD_DESCRIPTION_ID
;
70 } else if (ADD_DRIVER_OPTION_STATE
== CallbackData
->FeCurrentState
) {
71 FormId
= FORM_DRIVER_ADD_FILE_DESCRIPTION_ID
;
76 NewMenuEntry
->DisplayStringToken
,
77 STRING_TOKEN (STR_NULL_STRING
),
78 EFI_IFR_FLAG_CALLBACK
,
79 (UINT16
) (FILE_OPTION_OFFSET
+ Index
),
86 CallbackData
->FeHiiHandle
,
88 FORM_FILE_EXPLORER_ID
,
89 FORM_FILE_EXPLORER_ID
,
96 Update the file explower page with the refershed file system.
99 @param CallbackData BMM context data
100 @param KeyValue Key value to identify the type of data to expect.
102 @retval TRUE Inform the caller to create a callback packet to exit file explorer.
103 @retval FALSE Indicate that there is no need to exit file explorer.
108 IN BMM_CALLBACK_DATA
*CallbackData
,
112 UINT16 FileOptionMask
;
113 BM_MENU_ENTRY
*NewMenuEntry
;
114 BM_FILE_CONTEXT
*NewFileContext
;
116 BOOLEAN ExitFileExplorer
;
120 NewFileContext
= NULL
;
121 ExitFileExplorer
= FALSE
;
123 FileOptionMask
= (UINT16
) (FILE_OPTION_MASK
& KeyValue
);
125 if (UNKNOWN_CONTEXT
== CallbackData
->FeDisplayContext
) {
127 // First in, display file system.
129 BOpt_FreeMenu (&FsOptionMenu
);
130 BOpt_FindFileSystem (CallbackData
);
131 CreateMenuStringToken (CallbackData
, CallbackData
->FeHiiHandle
, &FsOptionMenu
);
133 UpdateFileExplorePage (CallbackData
, &FsOptionMenu
);
135 CallbackData
->FeDisplayContext
= FILE_SYSTEM
;
137 if (FILE_SYSTEM
== CallbackData
->FeDisplayContext
) {
138 NewMenuEntry
= BOpt_GetMenuEntry (&FsOptionMenu
, FileOptionMask
);
139 } else if (DIRECTORY
== CallbackData
->FeDisplayContext
) {
140 NewMenuEntry
= BOpt_GetMenuEntry (&DirectoryMenu
, FileOptionMask
);
143 CallbackData
->FeDisplayContext
= DIRECTORY
;
145 NewFileContext
= (BM_FILE_CONTEXT
*) NewMenuEntry
->VariableContext
;
147 if (NewFileContext
->IsDir
) {
148 RemoveEntryList (&NewMenuEntry
->Link
);
149 BOpt_FreeMenu (&DirectoryMenu
);
150 Status
= BOpt_FindFiles (CallbackData
, NewMenuEntry
);
151 if (EFI_ERROR (Status
)) {
152 ExitFileExplorer
= TRUE
;
155 CreateMenuStringToken (CallbackData
, CallbackData
->FeHiiHandle
, &DirectoryMenu
);
156 BOpt_DestroyMenuEntry (NewMenuEntry
);
158 UpdateFileExplorePage (CallbackData
, &DirectoryMenu
);
161 switch (CallbackData
->FeCurrentState
) {
162 case BOOT_FROM_FILE_STATE
:
164 // Here boot from file
166 BootThisFile (NewFileContext
);
167 ExitFileExplorer
= TRUE
;
170 case ADD_BOOT_OPTION_STATE
:
171 case ADD_DRIVER_OPTION_STATE
:
172 if (ADD_BOOT_OPTION_STATE
== CallbackData
->FeCurrentState
) {
173 FormId
= FORM_BOOT_ADD_DESCRIPTION_ID
;
175 FormId
= FORM_DRIVER_ADD_FILE_DESCRIPTION_ID
;
178 CallbackData
->MenuEntry
= NewMenuEntry
;
179 CallbackData
->LoadContext
->FilePathList
= ((BM_FILE_CONTEXT
*) (CallbackData
->MenuEntry
->VariableContext
))->DevicePath
;
182 // Create Subtitle op-code for the display string of the option.
184 RefreshUpdateData ();
186 CreateSubTitleOpCode (
187 NewMenuEntry
->DisplayStringToken
,
195 CallbackData
->FeHiiHandle
,
210 return ExitFileExplorer
;
214 This function processes the results of changes in configuration.
215 When user select a interactive opcode, this callback will be triggered.
216 Based on the Question(QuestionId) that triggers the callback, the corresponding
217 actions is performed. It handles:
219 1) the addition of boot option.
220 2) the addition of driver option.
221 3) exit from file browser
222 4) update of file content if a dir is selected.
223 5) boot the file if a file is selected in "boot from file"
226 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
227 @param Action Specifies the type of action taken by the browser.
228 @param QuestionId A unique value which is sent to the original exporting driver
229 so that it can identify the type of data to expect.
230 @param Type The type of value for the question.
231 @param Value A pointer to the data being sent to the original exporting driver.
232 @param ActionRequest On return, points to the action requested by the callback function.
234 @retval EFI_SUCCESS The callback successfully handled the action.
235 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
236 @retval EFI_DEVICE_ERROR The variable could not be saved.
237 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
242 FileExplorerCallback (
243 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
244 IN EFI_BROWSER_ACTION Action
,
245 IN EFI_QUESTION_ID QuestionId
,
247 IN EFI_IFR_TYPE_VALUE
*Value
,
248 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
251 BMM_CALLBACK_DATA
*Private
;
252 FILE_EXPLORER_NV_DATA
*NvRamMap
;
256 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
257 return EFI_INVALID_PARAMETER
;
260 Status
= EFI_SUCCESS
;
261 Private
= FE_CALLBACK_DATA_FROM_THIS (This
);
262 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
265 // Retrive uncommitted data from Form Browser
267 NvRamMap
= &Private
->FeFakeNvData
;
268 BufferSize
= sizeof (FILE_EXPLORER_NV_DATA
);
269 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) NvRamMap
);
270 if (EFI_ERROR (Status
)) {
274 if (QuestionId
== KEY_VALUE_SAVE_AND_EXIT_BOOT
|| QuestionId
== KEY_VALUE_SAVE_AND_EXIT_DRIVER
) {
276 // Apply changes and exit formset
278 if (ADD_BOOT_OPTION_STATE
== Private
->FeCurrentState
) {
279 Status
= Var_UpdateBootOption (Private
, NvRamMap
);
280 if (EFI_ERROR (Status
)) {
284 BOpt_GetBootOptions (Private
);
285 CreateMenuStringToken (Private
, Private
->FeHiiHandle
, &BootOptionMenu
);
286 } else if (ADD_DRIVER_OPTION_STATE
== Private
->FeCurrentState
) {
287 Status
= Var_UpdateDriverOption (
289 Private
->FeHiiHandle
,
290 NvRamMap
->DescriptionData
,
291 NvRamMap
->OptionalData
,
292 NvRamMap
->ForceReconnect
294 if (EFI_ERROR (Status
)) {
298 BOpt_GetDriverOptions (Private
);
299 CreateMenuStringToken (Private
, Private
->FeHiiHandle
, &DriverOptionMenu
);
302 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
303 } else if (QuestionId
== KEY_VALUE_NO_SAVE_AND_EXIT_BOOT
|| QuestionId
== KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER
) {
305 // Discard changes and exit formset
307 NvRamMap
->OptionalData
[0] = 0x0000;
308 NvRamMap
->DescriptionData
[0] = 0x0000;
309 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
310 } else if (QuestionId
< FILE_OPTION_OFFSET
) {
312 // Exit File Explorer formset
314 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
316 if (UpdateFileExplorer (Private
, QuestionId
)) {
317 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;