]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/FileExplorer.c
Per UEFI spec, on CallBack action EFI_BROWSER_ACTION_CHANGING, the return value of...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BootMaint / FileExplorer.c
... / ...
CommitLineData
1/** @file\r
2 File explorer related functions.\r
3\r
4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
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
40 mStartLabel->Number = FORM_FILE_EXPLORER_ID;\r
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
50 if ((NewFileContext->IsDir) || (FileExplorerStateBootFromFile == CallbackData->FeCurrentState)) {\r
51 //\r
52 // Create Text opcode for directory, also create Text opcode for file in FileExplorerStateBootFromFile.\r
53 //\r
54 HiiCreateActionOpCode (\r
55 mStartOpCodeHandle,\r
56 (UINT16) (FILE_OPTION_OFFSET + Index),\r
57 NewMenuEntry->DisplayStringToken,\r
58 STRING_TOKEN (STR_NULL_STRING),\r
59 EFI_IFR_FLAG_CALLBACK,\r
60 0\r
61 );\r
62 } else {\r
63 //\r
64 // Create Goto opcode for file in FileExplorerStateAddBootOption or FileExplorerStateAddDriverOptionState.\r
65 //\r
66 if (FileExplorerStateAddBootOption == CallbackData->FeCurrentState) {\r
67 FormId = FORM_BOOT_ADD_DESCRIPTION_ID;\r
68 } else if (FileExplorerStateAddDriverOptionState == CallbackData->FeCurrentState) {\r
69 FormId = FORM_DRIVER_ADD_FILE_DESCRIPTION_ID;\r
70 }\r
71\r
72 HiiCreateGotoOpCode (\r
73 mStartOpCodeHandle,\r
74 FormId,\r
75 NewMenuEntry->DisplayStringToken,\r
76 STRING_TOKEN (STR_NULL_STRING),\r
77 EFI_IFR_FLAG_CALLBACK,\r
78 (UINT16) (FILE_OPTION_OFFSET + Index)\r
79 );\r
80 }\r
81 }\r
82\r
83 HiiUpdateForm (\r
84 CallbackData->FeHiiHandle,\r
85 &gFileExploreFormSetGuid,\r
86 FORM_FILE_EXPLORER_ID,\r
87 mStartOpCodeHandle, // Label FORM_FILE_EXPLORER_ID\r
88 mEndOpCodeHandle // LABEL_END\r
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
122 if (FileExplorerDisplayUnknown == CallbackData->FeDisplayContext) {\r
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
132 CallbackData->FeDisplayContext = FileExplorerDisplayFileSystem;\r
133 } else {\r
134 if (FileExplorerDisplayFileSystem == CallbackData->FeDisplayContext) {\r
135 NewMenuEntry = BOpt_GetMenuEntry (&FsOptionMenu, FileOptionMask);\r
136 } else if (FileExplorerDisplayDirectory == CallbackData->FeDisplayContext) {\r
137 NewMenuEntry = BOpt_GetMenuEntry (&DirectoryMenu, FileOptionMask);\r
138 }\r
139\r
140 NewFileContext = (BM_FILE_CONTEXT *) NewMenuEntry->VariableContext;\r
141\r
142 if (NewFileContext->IsDir ) {\r
143 CallbackData->FeDisplayContext = FileExplorerDisplayDirectory;\r
144\r
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
159 case FileExplorerStateBootFromFile:\r
160 //\r
161 // Here boot from file\r
162 //\r
163 BootThisFile (NewFileContext);\r
164 //\r
165 // Set proper video resolution and text mode for setup.\r
166 //\r
167 ChangeModeForSetup ();\r
168 ExitFileExplorer = TRUE;\r
169 break;\r
170\r
171 case FileExplorerStateAddBootOption:\r
172 case FileExplorerStateAddDriverOptionState:\r
173 if (FileExplorerStateAddBootOption == CallbackData->FeCurrentState) {\r
174 FormId = FORM_BOOT_ADD_DESCRIPTION_ID;\r
175 } else {\r
176 FormId = FORM_DRIVER_ADD_FILE_DESCRIPTION_ID;\r
177 }\r
178\r
179 CallbackData->MenuEntry = NewMenuEntry;\r
180 CallbackData->LoadContext->FilePathList = ((BM_FILE_CONTEXT *) (CallbackData->MenuEntry->VariableContext))->DevicePath;\r
181\r
182 //\r
183 // Create Subtitle op-code for the display string of the option.\r
184 //\r
185 RefreshUpdateData ();\r
186 mStartLabel->Number = FormId;\r
187\r
188 HiiCreateSubTitleOpCode (\r
189 mStartOpCodeHandle,\r
190 NewMenuEntry->DisplayStringToken,\r
191 0,\r
192 0,\r
193 0\r
194 );\r
195\r
196 HiiUpdateForm (\r
197 CallbackData->FeHiiHandle,\r
198 &gFileExploreFormSetGuid,\r
199 FormId,\r
200 mStartOpCodeHandle, // Label FormId\r
201 mEndOpCodeHandle // LABEL_END\r
202 );\r
203 break;\r
204\r
205 default:\r
206 break;\r
207 }\r
208 }\r
209 }\r
210 exit:\r
211 return ExitFileExplorer;\r
212}\r
213\r
214/**\r
215 This function processes the results of changes in configuration.\r
216 When user select a interactive opcode, this callback will be triggered.\r
217 Based on the Question(QuestionId) that triggers the callback, the corresponding\r
218 actions is performed. It handles:\r
219\r
220 1) the addition of boot option.\r
221 2) the addition of driver option.\r
222 3) exit from file browser\r
223 4) update of file content if a dir is selected.\r
224 5) boot the file if a file is selected in "boot from file"\r
225\r
226\r
227 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
228 @param Action Specifies the type of action taken by the browser.\r
229 @param QuestionId A unique value which is sent to the original exporting driver\r
230 so that it can identify the type of data to expect.\r
231 @param Type The type of value for the question.\r
232 @param Value A pointer to the data being sent to the original exporting driver.\r
233 @param ActionRequest On return, points to the action requested by the callback function.\r
234\r
235 @retval EFI_SUCCESS The callback successfully handled the action.\r
236 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
237 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
238 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.\r
239 @retval EFI_INVALID_PARAMETER If paramter Value or ActionRequest is NULL.\r
240**/\r
241EFI_STATUS\r
242EFIAPI\r
243FileExplorerCallback (\r
244 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
245 IN EFI_BROWSER_ACTION Action,\r
246 IN EFI_QUESTION_ID QuestionId,\r
247 IN UINT8 Type,\r
248 IN EFI_IFR_TYPE_VALUE *Value,\r
249 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
250 )\r
251{\r
252 BMM_CALLBACK_DATA *Private;\r
253 FILE_EXPLORER_NV_DATA *NvRamMap;\r
254 EFI_STATUS Status;\r
255\r
256 if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
257 if ((Value == NULL) || (ActionRequest == NULL)) {\r
258 return EFI_INVALID_PARAMETER;\r
259 }\r
260\r
261 Status = EFI_SUCCESS;\r
262 Private = FE_CALLBACK_DATA_FROM_THIS (This);\r
263 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
264\r
265 //\r
266 // Retrieve uncommitted data from Form Browser\r
267 //\r
268 NvRamMap = &Private->FeFakeNvData;\r
269 HiiGetBrowserData (&gFileExploreFormSetGuid, mFileExplorerStorageName, sizeof (FILE_EXPLORER_NV_DATA), (UINT8 *) NvRamMap);\r
270\r
271 if (QuestionId == KEY_VALUE_SAVE_AND_EXIT_BOOT || QuestionId == KEY_VALUE_SAVE_AND_EXIT_DRIVER) {\r
272 //\r
273 // Apply changes and exit formset\r
274 //\r
275 if (FileExplorerStateAddBootOption == Private->FeCurrentState) {\r
276 Status = Var_UpdateBootOption (Private, NvRamMap);\r
277 if (EFI_ERROR (Status)) {\r
278 return Status;\r
279 }\r
280\r
281 BOpt_GetBootOptions (Private);\r
282 CreateMenuStringToken (Private, Private->FeHiiHandle, &BootOptionMenu);\r
283 } else if (FileExplorerStateAddDriverOptionState == Private->FeCurrentState) {\r
284 Status = Var_UpdateDriverOption (\r
285 Private,\r
286 Private->FeHiiHandle,\r
287 NvRamMap->DescriptionData,\r
288 NvRamMap->OptionalData,\r
289 NvRamMap->ForceReconnect\r
290 );\r
291 if (EFI_ERROR (Status)) {\r
292 return Status;\r
293 }\r
294\r
295 BOpt_GetDriverOptions (Private);\r
296 CreateMenuStringToken (Private, Private->FeHiiHandle, &DriverOptionMenu);\r
297 }\r
298\r
299 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
300 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_BOOT || QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER) {\r
301 //\r
302 // Discard changes and exit formset\r
303 //\r
304 NvRamMap->OptionalData[0] = 0x0000;\r
305 NvRamMap->DescriptionData[0] = 0x0000;\r
306 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
307 } else if (QuestionId < FILE_OPTION_OFFSET) {\r
308 //\r
309 // Exit File Explorer formset\r
310 //\r
311 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
312 } else {\r
313 if (UpdateFileExplorer (Private, QuestionId)) {\r
314 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
315 }\r
316 }\r
317\r
318 return Status;\r
319 }\r
320 //\r
321 // All other action return unsupported.\r
322 //\r
323 return EFI_UNSUPPORTED;\r
324}\r