]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/FileExplorer.c
Clean up the private GUID definition in module Level.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BootMaint / FileExplorer.c
CommitLineData
5c08e117 1/** @file\r
2 File explorer related functions.\r
3\r
d88f86f1 4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
180a5a35 5This program and the accompanying materials\r
5c08e117 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "BootMaint.h"\r
16\r
17/**\r
18 Update the File Explore page.\r
19\r
20 @param CallbackData The BMM context data.\r
21 @param MenuOption Pointer to menu options to display.\r
22\r
23**/\r
24VOID\r
25UpdateFileExplorePage (\r
26 IN BMM_CALLBACK_DATA *CallbackData,\r
27 BM_MENU_OPTION *MenuOption\r
28 )\r
29{\r
30 UINTN Index;\r
31 BM_MENU_ENTRY *NewMenuEntry;\r
32 BM_FILE_CONTEXT *NewFileContext;\r
33 EFI_FORM_ID FormId;\r
34\r
35 NewMenuEntry = NULL;\r
36 NewFileContext = NULL;\r
37 FormId = 0;\r
38\r
39 RefreshUpdateData ();\r
75bf9d0e 40 mStartLabel->Number = FORM_FILE_EXPLORER_ID;\r
5c08e117 41\r
42 for (Index = 0; Index < MenuOption->MenuNumber; Index++) {\r
43 NewMenuEntry = BOpt_GetMenuEntry (MenuOption, Index);\r
44 NewFileContext = (BM_FILE_CONTEXT *) NewMenuEntry->VariableContext;\r
45\r
46 if (NewFileContext->IsBootLegacy) {\r
47 continue;\r
48 }\r
49\r
13078b3f 50 if ((NewFileContext->IsDir) || (FileExplorerStateBootFromFile == CallbackData->FeCurrentState)) {\r
5c08e117 51 //\r
13078b3f 52 // Create Text opcode for directory, also create Text opcode for file in FileExplorerStateBootFromFile.\r
5c08e117 53 //\r
75bf9d0e
LG
54 HiiCreateActionOpCode (\r
55 mStartOpCodeHandle,\r
5c08e117 56 (UINT16) (FILE_OPTION_OFFSET + Index),\r
57 NewMenuEntry->DisplayStringToken,\r
58 STRING_TOKEN (STR_NULL_STRING),\r
59 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 60 0\r
5c08e117 61 );\r
62 } else {\r
63 //\r
13078b3f 64 // Create Goto opcode for file in FileExplorerStateAddBootOption or FileExplorerStateAddDriverOptionState.\r
5c08e117 65 //\r
13078b3f 66 if (FileExplorerStateAddBootOption == CallbackData->FeCurrentState) {\r
5c08e117 67 FormId = FORM_BOOT_ADD_DESCRIPTION_ID;\r
13078b3f 68 } else if (FileExplorerStateAddDriverOptionState == CallbackData->FeCurrentState) {\r
5c08e117 69 FormId = FORM_DRIVER_ADD_FILE_DESCRIPTION_ID;\r
70 }\r
71\r
75bf9d0e
LG
72 HiiCreateGotoOpCode (\r
73 mStartOpCodeHandle,\r
5c08e117 74 FormId,\r
75 NewMenuEntry->DisplayStringToken,\r
76 STRING_TOKEN (STR_NULL_STRING),\r
77 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 78 (UINT16) (FILE_OPTION_OFFSET + Index)\r
5c08e117 79 );\r
80 }\r
81 }\r
82\r
75bf9d0e 83 HiiUpdateForm (\r
5c08e117 84 CallbackData->FeHiiHandle,\r
e24fc103 85 &gFileExploreFormSetGuid,\r
5c08e117 86 FORM_FILE_EXPLORER_ID,\r
75bf9d0e
LG
87 mStartOpCodeHandle, // Label FORM_FILE_EXPLORER_ID\r
88 mEndOpCodeHandle // LABEL_END\r
5c08e117 89 );\r
90}\r
91\r
92/**\r
93 Update the file explower page with the refershed file system.\r
94\r
95\r
96 @param CallbackData BMM context data\r
97 @param KeyValue Key value to identify the type of data to expect.\r
98\r
99 @retval TRUE Inform the caller to create a callback packet to exit file explorer.\r
100 @retval FALSE Indicate that there is no need to exit file explorer.\r
101\r
102**/\r
103BOOLEAN\r
104UpdateFileExplorer (\r
105 IN BMM_CALLBACK_DATA *CallbackData,\r
106 IN UINT16 KeyValue\r
107 )\r
108{\r
109 UINT16 FileOptionMask;\r
110 BM_MENU_ENTRY *NewMenuEntry;\r
111 BM_FILE_CONTEXT *NewFileContext;\r
112 EFI_FORM_ID FormId;\r
113 BOOLEAN ExitFileExplorer;\r
114 EFI_STATUS Status;\r
115\r
116 NewMenuEntry = NULL;\r
117 NewFileContext = NULL;\r
118 ExitFileExplorer = FALSE;\r
119\r
120 FileOptionMask = (UINT16) (FILE_OPTION_MASK & KeyValue);\r
121\r
13078b3f 122 if (FileExplorerDisplayUnknown == CallbackData->FeDisplayContext) {\r
5c08e117 123 //\r
124 // First in, display file system.\r
125 //\r
126 BOpt_FreeMenu (&FsOptionMenu);\r
127 BOpt_FindFileSystem (CallbackData);\r
128 CreateMenuStringToken (CallbackData, CallbackData->FeHiiHandle, &FsOptionMenu);\r
129\r
130 UpdateFileExplorePage (CallbackData, &FsOptionMenu);\r
131\r
13078b3f 132 CallbackData->FeDisplayContext = FileExplorerDisplayFileSystem;\r
5c08e117 133 } else {\r
13078b3f 134 if (FileExplorerDisplayFileSystem == CallbackData->FeDisplayContext) {\r
5c08e117 135 NewMenuEntry = BOpt_GetMenuEntry (&FsOptionMenu, FileOptionMask);\r
13078b3f 136 } else if (FileExplorerDisplayDirectory == CallbackData->FeDisplayContext) {\r
5c08e117 137 NewMenuEntry = BOpt_GetMenuEntry (&DirectoryMenu, FileOptionMask);\r
138 }\r
139\r
a19ad64b 140 NewFileContext = (BM_FILE_CONTEXT *) NewMenuEntry->VariableContext;\r
5c08e117 141\r
5c08e117 142 if (NewFileContext->IsDir ) {\r
a19ad64b 143 CallbackData->FeDisplayContext = FileExplorerDisplayDirectory;\r
9ecbc654 144\r
5c08e117 145 RemoveEntryList (&NewMenuEntry->Link);\r
146 BOpt_FreeMenu (&DirectoryMenu);\r
147 Status = BOpt_FindFiles (CallbackData, NewMenuEntry);\r
148 if (EFI_ERROR (Status)) {\r
149 ExitFileExplorer = TRUE;\r
150 goto exit;\r
151 }\r
152 CreateMenuStringToken (CallbackData, CallbackData->FeHiiHandle, &DirectoryMenu);\r
153 BOpt_DestroyMenuEntry (NewMenuEntry);\r
154\r
155 UpdateFileExplorePage (CallbackData, &DirectoryMenu);\r
156\r
157 } else {\r
158 switch (CallbackData->FeCurrentState) {\r
13078b3f 159 case FileExplorerStateBootFromFile:\r
5c08e117 160 //\r
161 // Here boot from file\r
162 //\r
163 BootThisFile (NewFileContext);\r
164 ExitFileExplorer = TRUE;\r
165 break;\r
166\r
13078b3f 167 case FileExplorerStateAddBootOption:\r
168 case FileExplorerStateAddDriverOptionState:\r
169 if (FileExplorerStateAddBootOption == CallbackData->FeCurrentState) {\r
5c08e117 170 FormId = FORM_BOOT_ADD_DESCRIPTION_ID;\r
171 } else {\r
172 FormId = FORM_DRIVER_ADD_FILE_DESCRIPTION_ID;\r
173 }\r
174\r
175 CallbackData->MenuEntry = NewMenuEntry;\r
176 CallbackData->LoadContext->FilePathList = ((BM_FILE_CONTEXT *) (CallbackData->MenuEntry->VariableContext))->DevicePath;\r
177\r
178 //\r
179 // Create Subtitle op-code for the display string of the option.\r
180 //\r
181 RefreshUpdateData ();\r
75bf9d0e 182 mStartLabel->Number = FormId;\r
5c08e117 183\r
75bf9d0e
LG
184 HiiCreateSubTitleOpCode (\r
185 mStartOpCodeHandle,\r
5c08e117 186 NewMenuEntry->DisplayStringToken,\r
187 0,\r
188 0,\r
75bf9d0e 189 0\r
5c08e117 190 );\r
191\r
75bf9d0e 192 HiiUpdateForm (\r
5c08e117 193 CallbackData->FeHiiHandle,\r
e24fc103 194 &gFileExploreFormSetGuid,\r
5c08e117 195 FormId,\r
75bf9d0e
LG
196 mStartOpCodeHandle, // Label FormId\r
197 mEndOpCodeHandle // LABEL_END\r
5c08e117 198 );\r
199 break;\r
200\r
201 default:\r
202 break;\r
203 }\r
204 }\r
205 }\r
206 exit:\r
207 return ExitFileExplorer;\r
208}\r
209\r
210/**\r
211 This function processes the results of changes in configuration.\r
212 When user select a interactive opcode, this callback will be triggered.\r
213 Based on the Question(QuestionId) that triggers the callback, the corresponding\r
214 actions is performed. It handles:\r
215\r
216 1) the addition of boot option.\r
217 2) the addition of driver option.\r
218 3) exit from file browser\r
219 4) update of file content if a dir is selected.\r
220 5) boot the file if a file is selected in "boot from file"\r
221\r
222\r
223 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
224 @param Action Specifies the type of action taken by the browser.\r
225 @param QuestionId A unique value which is sent to the original exporting driver\r
226 so that it can identify the type of data to expect.\r
227 @param Type The type of value for the question.\r
228 @param Value A pointer to the data being sent to the original exporting driver.\r
229 @param ActionRequest On return, points to the action requested by the callback function.\r
230\r
231 @retval EFI_SUCCESS The callback successfully handled the action.\r
232 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
233 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
234 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.\r
235 @retval EFI_INVALID_PARAMETER If paramter Value or ActionRequest is NULL.\r
236**/\r
237EFI_STATUS\r
238EFIAPI\r
239FileExplorerCallback (\r
240 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
241 IN EFI_BROWSER_ACTION Action,\r
242 IN EFI_QUESTION_ID QuestionId,\r
243 IN UINT8 Type,\r
244 IN EFI_IFR_TYPE_VALUE *Value,\r
245 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
246 )\r
247{\r
248 BMM_CALLBACK_DATA *Private;\r
249 FILE_EXPLORER_NV_DATA *NvRamMap;\r
250 EFI_STATUS Status;\r
5c08e117 251\r
d88f86f1
ED
252 if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
253 if ((Value == NULL) || (ActionRequest == NULL)) {\r
254 return EFI_INVALID_PARAMETER;\r
255 }\r
256\r
257 Status = EFI_SUCCESS;\r
258 Private = FE_CALLBACK_DATA_FROM_THIS (This);\r
259 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
260\r
4548fc2a 261 //\r
d88f86f1 262 // Retrieve uncommitted data from Form Browser\r
4548fc2a 263 //\r
d88f86f1 264 NvRamMap = &Private->FeFakeNvData;\r
e24fc103 265 HiiGetBrowserData (&gFileExploreFormSetGuid, mFileExplorerStorageName, sizeof (FILE_EXPLORER_NV_DATA), (UINT8 *) NvRamMap);\r
4548fc2a 266\r
d88f86f1
ED
267 if (QuestionId == KEY_VALUE_SAVE_AND_EXIT_BOOT || QuestionId == KEY_VALUE_SAVE_AND_EXIT_DRIVER) {\r
268 //\r
269 // Apply changes and exit formset\r
270 //\r
271 if (FileExplorerStateAddBootOption == Private->FeCurrentState) {\r
272 Status = Var_UpdateBootOption (Private, NvRamMap);\r
273 if (EFI_ERROR (Status)) {\r
274 return Status;\r
275 }\r
5c08e117 276\r
d88f86f1
ED
277 BOpt_GetBootOptions (Private);\r
278 CreateMenuStringToken (Private, Private->FeHiiHandle, &BootOptionMenu);\r
279 } else if (FileExplorerStateAddDriverOptionState == Private->FeCurrentState) {\r
280 Status = Var_UpdateDriverOption (\r
281 Private,\r
282 Private->FeHiiHandle,\r
283 NvRamMap->DescriptionData,\r
284 NvRamMap->OptionalData,\r
285 NvRamMap->ForceReconnect\r
286 );\r
287 if (EFI_ERROR (Status)) {\r
288 return Status;\r
289 }\r
5c08e117 290\r
d88f86f1
ED
291 BOpt_GetDriverOptions (Private);\r
292 CreateMenuStringToken (Private, Private->FeHiiHandle, &DriverOptionMenu);\r
5c08e117 293 }\r
294\r
d88f86f1
ED
295 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
296 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_BOOT || QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER) {\r
297 //\r
298 // Discard changes and exit formset\r
299 //\r
300 NvRamMap->OptionalData[0] = 0x0000;\r
301 NvRamMap->DescriptionData[0] = 0x0000;\r
302 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
303 } else if (QuestionId < FILE_OPTION_OFFSET) {\r
304 //\r
305 // Exit File Explorer formset\r
306 //\r
307 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
308 } else {\r
309 if (UpdateFileExplorer (Private, QuestionId)) {\r
310 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
5c08e117 311 }\r
5c08e117 312 }\r
313\r
d88f86f1 314 return Status;\r
5c08e117 315 }\r
d88f86f1
ED
316 //\r
317 // All other action return unsupported.\r
318 //\r
319 return EFI_UNSUPPORTED;\r
5c08e117 320}\r