2 File explorer related functions.
4 Copyright (c) 2004 - 2011, 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
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.
20 @param CallbackData The BMM context data.
21 @param MenuOption Pointer to menu options to display.
25 UpdateFileExplorePage (
26 IN BMM_CALLBACK_DATA
*CallbackData
,
27 BM_MENU_OPTION
*MenuOption
31 BM_MENU_ENTRY
*NewMenuEntry
;
32 BM_FILE_CONTEXT
*NewFileContext
;
36 NewFileContext
= NULL
;
40 mStartLabel
->Number
= FORM_FILE_EXPLORER_ID
;
42 for (Index
= 0; Index
< MenuOption
->MenuNumber
; Index
++) {
43 NewMenuEntry
= BOpt_GetMenuEntry (MenuOption
, Index
);
44 NewFileContext
= (BM_FILE_CONTEXT
*) NewMenuEntry
->VariableContext
;
46 if (NewFileContext
->IsBootLegacy
) {
50 if ((NewFileContext
->IsDir
) || (FileExplorerStateBootFromFile
== CallbackData
->FeCurrentState
)) {
52 // Create Text opcode for directory, also create Text opcode for file in FileExplorerStateBootFromFile.
54 HiiCreateActionOpCode (
56 (UINT16
) (FILE_OPTION_OFFSET
+ Index
),
57 NewMenuEntry
->DisplayStringToken
,
58 STRING_TOKEN (STR_NULL_STRING
),
59 EFI_IFR_FLAG_CALLBACK
,
64 // Create Goto opcode for file in FileExplorerStateAddBootOption or FileExplorerStateAddDriverOptionState.
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
;
75 NewMenuEntry
->DisplayStringToken
,
76 STRING_TOKEN (STR_NULL_STRING
),
77 EFI_IFR_FLAG_CALLBACK
,
78 (UINT16
) (FILE_OPTION_OFFSET
+ Index
)
84 CallbackData
->FeHiiHandle
,
85 &gFileExploreFormSetGuid
,
86 FORM_FILE_EXPLORER_ID
,
87 mStartOpCodeHandle
, // Label FORM_FILE_EXPLORER_ID
88 mEndOpCodeHandle
// LABEL_END
93 Update the file explower page with the refershed file system.
96 @param CallbackData BMM context data
97 @param KeyValue Key value to identify the type of data to expect.
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.
105 IN BMM_CALLBACK_DATA
*CallbackData
,
109 UINT16 FileOptionMask
;
110 BM_MENU_ENTRY
*NewMenuEntry
;
111 BM_FILE_CONTEXT
*NewFileContext
;
113 BOOLEAN ExitFileExplorer
;
117 NewFileContext
= NULL
;
118 ExitFileExplorer
= FALSE
;
120 FileOptionMask
= (UINT16
) (FILE_OPTION_MASK
& KeyValue
);
122 if (FileExplorerDisplayUnknown
== CallbackData
->FeDisplayContext
) {
124 // First in, display file system.
126 BOpt_FreeMenu (&FsOptionMenu
);
127 BOpt_FindFileSystem (CallbackData
);
128 CreateMenuStringToken (CallbackData
, CallbackData
->FeHiiHandle
, &FsOptionMenu
);
130 UpdateFileExplorePage (CallbackData
, &FsOptionMenu
);
132 CallbackData
->FeDisplayContext
= FileExplorerDisplayFileSystem
;
134 if (FileExplorerDisplayFileSystem
== CallbackData
->FeDisplayContext
) {
135 NewMenuEntry
= BOpt_GetMenuEntry (&FsOptionMenu
, FileOptionMask
);
136 } else if (FileExplorerDisplayDirectory
== CallbackData
->FeDisplayContext
) {
137 NewMenuEntry
= BOpt_GetMenuEntry (&DirectoryMenu
, FileOptionMask
);
140 NewFileContext
= (BM_FILE_CONTEXT
*) NewMenuEntry
->VariableContext
;
142 if (NewFileContext
->IsDir
) {
143 CallbackData
->FeDisplayContext
= FileExplorerDisplayDirectory
;
145 RemoveEntryList (&NewMenuEntry
->Link
);
146 BOpt_FreeMenu (&DirectoryMenu
);
147 Status
= BOpt_FindFiles (CallbackData
, NewMenuEntry
);
148 if (EFI_ERROR (Status
)) {
149 ExitFileExplorer
= TRUE
;
152 CreateMenuStringToken (CallbackData
, CallbackData
->FeHiiHandle
, &DirectoryMenu
);
153 BOpt_DestroyMenuEntry (NewMenuEntry
);
155 UpdateFileExplorePage (CallbackData
, &DirectoryMenu
);
158 switch (CallbackData
->FeCurrentState
) {
159 case FileExplorerStateBootFromFile
:
161 // Here boot from file
163 BootThisFile (NewFileContext
);
165 // Set proper video resolution and text mode for setup.
167 ChangeModeForSetup ();
168 ExitFileExplorer
= TRUE
;
171 case FileExplorerStateAddBootOption
:
172 case FileExplorerStateAddDriverOptionState
:
173 if (FileExplorerStateAddBootOption
== CallbackData
->FeCurrentState
) {
174 FormId
= FORM_BOOT_ADD_DESCRIPTION_ID
;
176 FormId
= FORM_DRIVER_ADD_FILE_DESCRIPTION_ID
;
179 CallbackData
->MenuEntry
= NewMenuEntry
;
180 CallbackData
->LoadContext
->FilePathList
= ((BM_FILE_CONTEXT
*) (CallbackData
->MenuEntry
->VariableContext
))->DevicePath
;
183 // Create Subtitle op-code for the display string of the option.
185 RefreshUpdateData ();
186 mStartLabel
->Number
= FormId
;
188 HiiCreateSubTitleOpCode (
190 NewMenuEntry
->DisplayStringToken
,
197 CallbackData
->FeHiiHandle
,
198 &gFileExploreFormSetGuid
,
200 mStartOpCodeHandle
, // Label FormId
201 mEndOpCodeHandle
// LABEL_END
211 return ExitFileExplorer
;
215 This function processes the results of changes in configuration.
216 When user select a interactive opcode, this callback will be triggered.
217 Based on the Question(QuestionId) that triggers the callback, the corresponding
218 actions is performed. It handles:
220 1) the addition of boot option.
221 2) the addition of driver option.
222 3) exit from file browser
223 4) update of file content if a dir is selected.
224 5) boot the file if a file is selected in "boot from file"
227 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
228 @param Action Specifies the type of action taken by the browser.
229 @param QuestionId A unique value which is sent to the original exporting driver
230 so that it can identify the type of data to expect.
231 @param Type The type of value for the question.
232 @param Value A pointer to the data being sent to the original exporting driver.
233 @param ActionRequest On return, points to the action requested by the callback function.
235 @retval EFI_SUCCESS The callback successfully handled the action.
236 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
237 @retval EFI_DEVICE_ERROR The variable could not be saved.
238 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
239 @retval EFI_INVALID_PARAMETER If paramter Value or ActionRequest is NULL.
243 FileExplorerCallback (
244 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
245 IN EFI_BROWSER_ACTION Action
,
246 IN EFI_QUESTION_ID QuestionId
,
248 IN EFI_IFR_TYPE_VALUE
*Value
,
249 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
252 BMM_CALLBACK_DATA
*Private
;
253 FILE_EXPLORER_NV_DATA
*NvRamMap
;
256 if (Action
!= EFI_BROWSER_ACTION_CHANGING
&& Action
!= EFI_BROWSER_ACTION_CHANGED
) {
258 // All other action return unsupported.
260 return EFI_UNSUPPORTED
;
263 Status
= EFI_SUCCESS
;
264 Private
= FE_CALLBACK_DATA_FROM_THIS (This
);
267 // Retrieve uncommitted data from Form Browser
269 NvRamMap
= &Private
->FeFakeNvData
;
270 HiiGetBrowserData (&gFileExploreFormSetGuid
, mFileExplorerStorageName
, sizeof (FILE_EXPLORER_NV_DATA
), (UINT8
*) NvRamMap
);
272 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
273 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
274 return EFI_INVALID_PARAMETER
;
277 if (QuestionId
== KEY_VALUE_SAVE_AND_EXIT_BOOT
|| QuestionId
== KEY_VALUE_SAVE_AND_EXIT_DRIVER
) {
279 // Apply changes and exit formset
281 if (FileExplorerStateAddBootOption
== Private
->FeCurrentState
) {
282 Status
= Var_UpdateBootOption (Private
, NvRamMap
);
283 if (EFI_ERROR (Status
)) {
287 BOpt_GetBootOptions (Private
);
288 CreateMenuStringToken (Private
, Private
->FeHiiHandle
, &BootOptionMenu
);
289 } else if (FileExplorerStateAddDriverOptionState
== Private
->FeCurrentState
) {
290 Status
= Var_UpdateDriverOption (
292 Private
->FeHiiHandle
,
293 NvRamMap
->DescriptionData
,
294 NvRamMap
->OptionalData
,
295 NvRamMap
->ForceReconnect
297 if (EFI_ERROR (Status
)) {
301 BOpt_GetDriverOptions (Private
);
302 CreateMenuStringToken (Private
, Private
->FeHiiHandle
, &DriverOptionMenu
);
305 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
306 } else if (QuestionId
== KEY_VALUE_NO_SAVE_AND_EXIT_BOOT
|| QuestionId
== KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER
) {
308 // Discard changes and exit formset
310 NvRamMap
->OptionalData
[0] = 0x0000;
311 NvRamMap
->DescriptionData
[0] = 0x0000;
312 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
313 } else if (QuestionId
< FILE_OPTION_OFFSET
) {
315 // Exit File Explorer formset
317 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
319 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
321 return EFI_INVALID_PARAMETER
;
324 if (QuestionId
>= FILE_OPTION_OFFSET
) {
325 UpdateFileExplorer (Private
, QuestionId
);