ShellPkg: Fix build failure in VS2015.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDriver1CommandsLib / DrvCfg.c
CommitLineData
4ba49616 1/** @file\r
2 Main file for DrvCfg shell Driver1 function.\r
3\r
c011b6c9 4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
eff60c11 5 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
4ba49616 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "UefiShellDriver1CommandsLib.h"\r
17#include <Protocol/HiiConfigAccess.h>\r
18#include <Protocol/HiiDatabase.h>\r
19\r
4880c2c9 20STATIC CONST EFI_GUID *CfgGuidList[] = {&gEfiDriverConfigurationProtocolGuid, &gEfiDriverConfiguration2ProtocolGuid, NULL};\r
21\r
4ba49616 22/**\r
4880c2c9 23 Find the EFI_HII_HANDLE by device path.\r
4ba49616 24\r
4880c2c9 25 @param[in] DevPath1 The Device Path to match.\r
26 @param[out] HiiHandle The EFI_HII_HANDLE after the converstion.\r
27 @param[in] HiiDb The Hii database protocol\r
4ba49616 28\r
4880c2c9 29 @retval EFI_SUCCESS The operation was successful.\r
30 @retval EFI_NOT_FOUND There was no EFI_HII_HANDLE found for that deviec path.\r
4ba49616 31**/\r
32EFI_STATUS\r
33EFIAPI\r
4880c2c9 34FindHiiHandleViaDevPath(\r
35 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath1,\r
36 OUT EFI_HII_HANDLE *HiiHandle,\r
37 IN EFI_HII_DATABASE_PROTOCOL *HiiDb\r
4ba49616 38 )\r
39{\r
4880c2c9 40 EFI_HII_HANDLE *HandleBuffer;\r
41 UINTN HandleBufferSize;\r
42 VOID *MainBuffer;\r
43 UINTN MainBufferSize;\r
44 EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r
45 EFI_HII_PACKAGE_HEADER *PackageHeader;\r
46 UINTN LoopVariable;\r
47 EFI_DEVICE_PATH_PROTOCOL *DevPath2;\r
48 EFI_STATUS Status;\r
4ba49616 49\r
4880c2c9 50 ASSERT(DevPath1 != NULL);\r
51 ASSERT(HiiHandle != NULL);\r
52 ASSERT(*HiiHandle == NULL);\r
53 ASSERT(HiiDb != NULL);\r
4ba49616 54\r
4880c2c9 55 HandleBufferSize = 0;\r
56 HandleBuffer = NULL;\r
57 Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);\r
4ba49616 58 if (Status == EFI_BUFFER_TOO_SMALL) {\r
4880c2c9 59 HandleBuffer = AllocateZeroPool(HandleBufferSize);\r
cd8462ea 60 ASSERT (HandleBuffer != NULL);\r
4880c2c9 61 Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);\r
4ba49616 62 }\r
63 if (EFI_ERROR(Status)) {\r
4880c2c9 64 SHELL_FREE_NON_NULL(HandleBuffer);\r
4ba49616 65 return (Status);\r
66 }\r
67\r
72c8a89a
ED
68 if (HandleBuffer == NULL) {\r
69 return EFI_NOT_FOUND;\r
70 }\r
71\r
4880c2c9 72 for (LoopVariable = 0 ; LoopVariable < (HandleBufferSize/sizeof(HandleBuffer[0])) && *HiiHandle == NULL ; LoopVariable++) {\r
73 MainBufferSize = 0;\r
74 MainBuffer = NULL;\r
75 Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer);\r
76 if (Status == EFI_BUFFER_TOO_SMALL) {\r
77 MainBuffer = AllocateZeroPool(MainBufferSize);\r
cd8462ea 78 ASSERT (MainBuffer != NULL);\r
4880c2c9 79 Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer);\r
80 }\r
81 //\r
82 // Enumerate through the block of returned memory.\r
83 // This should actually be a small block, but we need to be sure.\r
84 //\r
85 for (PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)MainBuffer\r
86 ; PackageListHeader != NULL && ((CHAR8*)PackageListHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && *HiiHandle == NULL\r
87 ; PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) {\r
88 for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER))\r
89 ; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END && *HiiHandle == NULL\r
90 ; PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageHeader))+PackageHeader->Length)) {\r
91 if (PackageHeader->Type == EFI_HII_PACKAGE_DEVICE_PATH) {\r
92 DevPath2 = (EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER));\r
93 if (DevicePathCompare(&DevPath1, &DevPath2) == 0) {\r
94 *HiiHandle = HandleBuffer[LoopVariable];\r
95 break;\r
96 }\r
97 }\r
98 }\r
4ba49616 99 }\r
4880c2c9 100 SHELL_FREE_NON_NULL(MainBuffer);\r
4ba49616 101 }\r
4880c2c9 102 SHELL_FREE_NON_NULL(HandleBuffer);\r
4ba49616 103\r
4880c2c9 104 if (*HiiHandle == NULL) {\r
105 return (EFI_NOT_FOUND);\r
106 }\r
107 return (EFI_SUCCESS);\r
108}\r
4ba49616 109\r
4880c2c9 110/**\r
111 Convert a EFI_HANDLE to a EFI_HII_HANDLE.\r
4ba49616 112\r
4880c2c9 113 @param[in] Handle The EFI_HANDLE to convert.\r
114 @param[out] HiiHandle The EFI_HII_HANDLE after the converstion.\r
115 @param[in] HiiDb The Hii database protocol\r
4ba49616 116\r
4880c2c9 117 @retval EFI_SUCCESS The operation was successful.\r
118**/\r
119EFI_STATUS\r
120EFIAPI\r
121ConvertHandleToHiiHandle(\r
122 IN CONST EFI_HANDLE Handle,\r
123 OUT EFI_HII_HANDLE *HiiHandle,\r
124 IN EFI_HII_DATABASE_PROTOCOL *HiiDb\r
125 )\r
126{\r
127 EFI_STATUS Status;\r
128 EFI_DEVICE_PATH_PROTOCOL *DevPath1;\r
4ba49616 129\r
4880c2c9 130 if (HiiHandle == NULL || HiiDb == NULL) {\r
131 return (EFI_INVALID_PARAMETER);\r
132 }\r
133 *HiiHandle = NULL;\r
134\r
135 if (Handle == NULL) {\r
136 return (EFI_SUCCESS);\r
137 }\r
138\r
139 DevPath1 = NULL;\r
140 Status = gBS->OpenProtocol(Handle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath1, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
141 if (EFI_ERROR(Status) || DevPath1 == NULL) {\r
142 return (EFI_NOT_FOUND);\r
143 }\r
144\r
145 return (FindHiiHandleViaDevPath(DevPath1, HiiHandle, HiiDb));\r
4ba49616 146}\r
147\r
148/**\r
4880c2c9 149 Function to print out all HII configuration information to a file.\r
4ba49616 150\r
4880c2c9 151 @param[in] Handle The handle to get info on. NULL to do all handles.\r
152 @param[in] FileName The filename to rwite the info to.\r
4ba49616 153**/\r
154SHELL_STATUS\r
155EFIAPI\r
4880c2c9 156ConfigToFile(\r
157 IN CONST EFI_HANDLE Handle,\r
158 IN CONST CHAR16 *FileName\r
4ba49616 159 )\r
160{\r
4880c2c9 161 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;\r
162 EFI_STATUS Status;\r
163 VOID *MainBuffer;\r
164 UINTN MainBufferSize;\r
165 EFI_HII_HANDLE HiiHandle;\r
166 SHELL_FILE_HANDLE FileHandle;\r
4ba49616 167\r
4880c2c9 168 HiiDatabase = NULL;\r
169 MainBufferSize = 0;\r
170 MainBuffer = NULL;\r
171 FileHandle = NULL;\r
4ba49616 172\r
4880c2c9 173 Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);\r
4ba49616 174 if (EFI_ERROR(Status)) {\r
4880c2c9 175 ShellPrintHiiEx(\r
176 -1,\r
177 -1,\r
178 NULL,\r
bc280720
TS
179 STRING_TOKEN(STR_GEN_FILE_OPEN_FAIL),\r
180 gShellDriver1HiiHandle,\r
181 L"drvcfg",\r
4880c2c9 182 FileName, \r
183 Status);\r
184 return (SHELL_DEVICE_ERROR);\r
4ba49616 185 }\r
186\r
4ba49616 187 //\r
4880c2c9 188 // Locate HII Database protocol\r
4ba49616 189 //\r
4880c2c9 190 Status = gBS->LocateProtocol (\r
191 &gEfiHiiDatabaseProtocolGuid,\r
192 NULL,\r
193 (VOID **) &HiiDatabase\r
194 );\r
195\r
196 if (EFI_ERROR(Status) || HiiDatabase == NULL) {\r
197 ShellPrintHiiEx(\r
198 -1, \r
199 -1, \r
200 NULL,\r
201 STRING_TOKEN(STR_GEN_PROTOCOL_NF), \r
bc280720
TS
202 gShellDriver1HiiHandle,\r
203 L"drvcfg",\r
4880c2c9 204 L"EfiHiiDatabaseProtocol", \r
205 &gEfiHiiDatabaseProtocolGuid);\r
206 ShellCloseFile(&FileHandle);\r
207 return (SHELL_NOT_FOUND);\r
4ba49616 208 }\r
4ba49616 209\r
eff60c11 210 HiiHandle = NULL;\r
4880c2c9 211 Status = ConvertHandleToHiiHandle(Handle, &HiiHandle, HiiDatabase);\r
212 if (EFI_ERROR(Status)) {\r
213 ShellPrintHiiEx(\r
214 -1, \r
215 -1, \r
216 NULL, \r
217 STRING_TOKEN(STR_GEN_HANDLE_NOT), \r
bc280720
TS
218 gShellDriver1HiiHandle,\r
219 L"drvcfg",\r
4880c2c9 220 ConvertHandleToHandleIndex(Handle), \r
221 L"Device");\r
222 ShellCloseFile(&FileHandle);\r
223 return (SHELL_DEVICE_ERROR); \r
4ba49616 224 }\r
225\r
4880c2c9 226 Status = HiiDatabase->ExportPackageLists(HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer);\r
227 if (Status == EFI_BUFFER_TOO_SMALL) {\r
228 MainBuffer = AllocateZeroPool(MainBufferSize);\r
229 Status = HiiDatabase->ExportPackageLists(HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer);\r
4ba49616 230 }\r
231\r
4880c2c9 232 Status = ShellWriteFile(FileHandle, &MainBufferSize, MainBuffer);\r
233\r
234 ShellCloseFile(&FileHandle);\r
235 SHELL_FREE_NON_NULL(MainBuffer);\r
236\r
237 if (EFI_ERROR(Status)) {\r
238 ShellPrintHiiEx(\r
239 -1, \r
240 -1,\r
241 NULL,\r
242 STRING_TOKEN(STR_FILE_WRITE_FAIL), \r
bc280720
TS
243 gShellDriver1HiiHandle,\r
244 L"drvcfg",\r
245 FileName);\r
4880c2c9 246 return (SHELL_DEVICE_ERROR); \r
247 }\r
248 ShellPrintHiiEx(\r
249 -1, \r
250 -1,\r
251 NULL,\r
252 STRING_TOKEN(STR_DRVCFG_COMP), \r
253 gShellDriver1HiiHandle);\r
254\r
255 return (SHELL_SUCCESS);\r
4ba49616 256}\r
257\r
258/**\r
4880c2c9 259 Function to read in HII configuration information from a file.\r
4ba49616 260\r
4880c2c9 261 @param[in] Handle The handle to get info for.\r
262 @param[in] FileName The filename to read the info from.\r
4ba49616 263**/\r
264SHELL_STATUS\r
265EFIAPI\r
4880c2c9 266ConfigFromFile(\r
267 IN EFI_HANDLE Handle,\r
268 IN CONST CHAR16 *FileName\r
4ba49616 269 )\r
270{\r
4880c2c9 271 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;\r
272 EFI_STATUS Status;\r
273 VOID *MainBuffer;\r
274 UINT64 Temp;\r
275 UINTN MainBufferSize;\r
276 EFI_HII_HANDLE HiiHandle;\r
277 SHELL_FILE_HANDLE FileHandle;\r
278 CHAR16 *TempDevPathString;\r
279 EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r
280 EFI_HII_PACKAGE_HEADER *PackageHeader;\r
281 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
282 UINTN HandleIndex;\r
283\r
284 HiiDatabase = NULL;\r
285 MainBufferSize = 0;\r
286 MainBuffer = NULL;\r
287 FileHandle = NULL;\r
288\r
289 Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ, 0);\r
290 if (EFI_ERROR(Status)) {\r
291 ShellPrintHiiEx(\r
292 -1,\r
293 -1,\r
294 NULL,\r
bc280720 295 STRING_TOKEN(STR_GEN_FILE_OPEN_FAIL),\r
4880c2c9 296 gShellDriver1HiiHandle, \r
bc280720 297 L"drvcfg",\r
4880c2c9 298 FileName, \r
299 Status);\r
300 return (SHELL_DEVICE_ERROR);\r
301 }\r
302\r
303 //\r
304 // Locate HII Database protocol\r
305 //\r
306 Status = gBS->LocateProtocol (\r
307 &gEfiHiiDatabaseProtocolGuid,\r
308 NULL,\r
309 (VOID **) &HiiDatabase\r
310 );\r
4ba49616 311\r
4880c2c9 312 if (EFI_ERROR(Status) || HiiDatabase == NULL) {\r
313 ShellPrintHiiEx(\r
314 -1, \r
315 -1, \r
316 NULL,\r
317 STRING_TOKEN(STR_GEN_PROTOCOL_NF), \r
318 gShellDriver1HiiHandle, \r
bc280720 319 L"drvcfg",\r
4880c2c9 320 L"EfiHiiDatabaseProtocol", \r
321 &gEfiHiiDatabaseProtocolGuid);\r
322 ShellCloseFile(&FileHandle);\r
323 return (SHELL_NOT_FOUND);\r
324 }\r
4ba49616 325\r
4880c2c9 326 Status = ShellGetFileSize(FileHandle, &Temp);\r
327 MainBufferSize = (UINTN)Temp;\r
328 if (EFI_ERROR(Status)) {\r
4ba49616 329 ShellPrintHiiEx(\r
330 -1, \r
331 -1, \r
332 NULL, \r
4880c2c9 333 STRING_TOKEN(STR_FILE_READ_FAIL), \r
bc280720
TS
334 gShellDriver1HiiHandle,\r
335 L"drvcfg",\r
336 FileName);\r
337\r
4880c2c9 338 ShellCloseFile(&FileHandle);\r
339 return (SHELL_DEVICE_ERROR); \r
340 }\r
341 MainBuffer = AllocateZeroPool((UINTN)MainBufferSize); \r
342 if (EFI_ERROR(Status)) {\r
343 ShellPrintHiiEx(\r
344 -1, \r
345 -1, \r
346 NULL, \r
347 STRING_TOKEN(STR_GEN_OUT_MEM), \r
bc280720 348 gShellDriver1HiiHandle, L"drvcfg");\r
4880c2c9 349 ShellCloseFile(&FileHandle);\r
350 return (SHELL_DEVICE_ERROR); \r
4ba49616 351 }\r
4880c2c9 352 Status = ShellReadFile(FileHandle, &MainBufferSize, MainBuffer);\r
353 if (EFI_ERROR(Status)) {\r
354 ShellPrintHiiEx(\r
355 -1, \r
356 -1, \r
357 NULL, \r
358 STRING_TOKEN(STR_FILE_READ_FAIL), \r
359 gShellDriver1HiiHandle, \r
bc280720
TS
360 L"drvcfg",\r
361 FileName);\r
362\r
4880c2c9 363 ShellCloseFile(&FileHandle);\r
364 SHELL_FREE_NON_NULL(MainBuffer);\r
365 return (SHELL_DEVICE_ERROR); \r
366 }\r
367\r
368 ShellCloseFile(&FileHandle);\r
369\r
370 if (Handle != NULL) {\r
371 //\r
372 // User override in place. Just do it.\r
373 //\r
374 HiiHandle = NULL;\r
375 Status = ConvertHandleToHiiHandle(Handle, &HiiHandle, HiiDatabase);\r
376 if (EFI_ERROR(Status)) {\r
4ba49616 377 ShellPrintHiiEx(\r
378 -1, \r
379 -1, \r
380 NULL, \r
4880c2c9 381 STRING_TOKEN(STR_GEN_HANDLE_NOT), \r
bc280720 382 gShellDriver1HiiHandle, L"drvcfg",\r
4880c2c9 383 ConvertHandleToHandleIndex(Handle), \r
384 L"Device");\r
385 ShellCloseFile(&FileHandle);\r
386 return (SHELL_DEVICE_ERROR); \r
387 }\r
388 Status = HiiDatabase->UpdatePackageList(HiiDatabase, HiiHandle, MainBuffer);\r
389 if (EFI_ERROR(Status)) {\r
390 ShellPrintHiiEx(\r
391 -1, \r
392 -1, \r
393 NULL, \r
bc280720
TS
394 STRING_TOKEN(STR_GEN_UEFI_FUNC_WARN),\r
395 gShellDriver1HiiHandle,\r
396 L"drvcfg",\r
4880c2c9 397 L"HiiDatabase->UpdatePackageList", \r
398 Status);\r
399 return (SHELL_DEVICE_ERROR); \r
400 }\r
401 } else {\r
402 //\r
403 // we need to parse the buffer and try to match the device paths for each item to try to find it's device path.\r
404 //\r
405\r
406 for (PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)MainBuffer\r
407 ; PackageListHeader != NULL && ((CHAR8*)PackageListHeader) < (((CHAR8*)MainBuffer)+MainBufferSize)\r
408 ; PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) {\r
409 for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER))\r
410 ; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END\r
411 ; PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageHeader))+PackageHeader->Length)) {\r
412 if (PackageHeader->Type == EFI_HII_PACKAGE_DEVICE_PATH) {\r
413 HiiHandle = NULL;\r
414 Status = FindHiiHandleViaDevPath((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), &HiiHandle, HiiDatabase);\r
415 if (EFI_ERROR(Status)) {\r
416 //\r
417 // print out an error.\r
418 //\r
863986b3 419 TempDevPathString = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), TRUE, TRUE);\r
4880c2c9 420 ShellPrintHiiEx(\r
421 -1, \r
422 -1, \r
423 NULL, \r
424 STRING_TOKEN(STR_DRVCFG_IN_FILE_NF), \r
425 gShellDriver1HiiHandle, \r
426 TempDevPathString);\r
427 SHELL_FREE_NON_NULL(TempDevPathString);\r
428 } else {\r
429 Status = HiiDatabase->UpdatePackageList(HiiDatabase, HiiHandle, PackageListHeader);\r
430 if (EFI_ERROR(Status)) {\r
431 ShellPrintHiiEx(\r
432 -1, \r
433 -1, \r
434 NULL, \r
bc280720 435 STRING_TOKEN(STR_GEN_UEFI_FUNC_WARN),\r
4880c2c9 436 gShellDriver1HiiHandle, \r
bc280720 437 L"drvcfg",\r
4880c2c9 438 L"HiiDatabase->UpdatePackageList", \r
439 Status);\r
440 return (SHELL_DEVICE_ERROR);\r
441 } else {\r
442 DevPath = (EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER));\r
443 gBS->LocateDevicePath(&gEfiHiiConfigAccessProtocolGuid, &DevPath, &Handle);\r
444 HandleIndex = ConvertHandleToHandleIndex(Handle);\r
445 ShellPrintHiiEx(\r
446 -1, \r
447 -1, \r
448 NULL, \r
449 STRING_TOKEN(STR_DRVCFG_DONE_HII), \r
450 gShellDriver1HiiHandle, \r
451 HandleIndex);\r
452 }\r
453 } \r
454 }\r
455 }\r
4ba49616 456 }\r
457 }\r
4880c2c9 458\r
459 SHELL_FREE_NON_NULL(MainBuffer);\r
460\r
461\r
462 ShellPrintHiiEx(\r
463 -1, \r
464 -1,\r
465 NULL,\r
466 STRING_TOKEN(STR_DRVCFG_COMP), \r
467 gShellDriver1HiiHandle);\r
4ba49616 468 return (SHELL_SUCCESS);\r
469}\r
470\r
6a5aa4d6 471/**\r
472 Present a requested action to the user.\r
473\r
474 @param[in] DriverImageHandle The handle for the driver to configure.\r
475 @param[in] ControllerHandle The handle of the device being managed by the Driver specified.\r
476 @param[in] ChildHandle The handle of a child device of the specified device.\r
477 @param[in] ActionRequired The required HII action.\r
478\r
479 @retval SHELL_INVALID_PARAMETER A parameter has a invalid value.\r
480**/\r
4880c2c9 481EFI_STATUS\r
482EFIAPI\r
483ShellCmdDriverConfigurationProcessActionRequired (\r
484 EFI_HANDLE DriverImageHandle,\r
485 EFI_HANDLE ControllerHandle,\r
486 EFI_HANDLE ChildHandle,\r
487 EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED ActionRequired\r
488 )\r
489{\r
490 EFI_HANDLE ConnectControllerContextOverride[2];\r
491\r
492 switch (ActionRequired) {\r
493 case EfiDriverConfigurationActionNone:\r
494 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle);\r
495 break;\r
496\r
497 case EfiDriverConfigurationActionStopController:\r
498 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_STOP), gShellDriver1HiiHandle);\r
499 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"stop controller");\r
500 ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL);\r
501\r
502 gBS->DisconnectController (ControllerHandle, DriverImageHandle, ChildHandle);\r
503 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_CTLR_S), gShellDriver1HiiHandle, L"stopped");\r
504 break;\r
505\r
506 case EfiDriverConfigurationActionRestartController:\r
507 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_RESTART_S), gShellDriver1HiiHandle, L"controller");\r
508 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"restart controller");\r
509 ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL);\r
510\r
511 gBS->DisconnectController (ControllerHandle, DriverImageHandle, ChildHandle);\r
512 ConnectControllerContextOverride[0] = DriverImageHandle;\r
513 ConnectControllerContextOverride[1] = NULL;\r
514 gBS->ConnectController (ControllerHandle, ConnectControllerContextOverride, NULL, TRUE);\r
515 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_CTLR_S), gShellDriver1HiiHandle, L"restarted");\r
516 break;\r
517\r
518 case EfiDriverConfigurationActionRestartPlatform:\r
519 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_RESTART_S), gShellDriver1HiiHandle, L"platform");\r
520 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"restart platform");\r
521 ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL);\r
522\r
523 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
524 break;\r
525\r
526 default:\r
527 return (EFI_INVALID_PARAMETER);\r
4880c2c9 528 }\r
529\r
530 return EFI_SUCCESS;\r
531}\r
532\r
6a5aa4d6 533/**\r
534 Do the configuration in an environment without HII.\r
535\r
536 @param[in] Language The language code.\r
537 @param[in] ForceDefaults TRUE to force defaults, FALSE otherwise.\r
538 @param[in] DefaultType If ForceDefaults is TRUE, specifies the default type.\r
539 @param[in] AllChildren TRUE to configure all children, FALSE otherwise.\r
540 @param[in] ValidateOptions TRUE to validate existing options, FALSE otherwise.\r
541 @param[in] SetOptions TRUE to set options, FALSE otherwise.\r
542 @param[in] DriverImageHandle The handle for the driver to configure.\r
543 @param[in] DeviceHandle The handle of the device being managed by the Driver specified.\r
544 @param[in] ChildHandle The handle of a child device of the specified device.\r
545\r
546 @retval SHELL_NOT_FOUND A specified handle could not be found.\r
547 @retval SHELL_INVALID_PARAMETER A parameter has a invalid value.\r
548**/\r
4880c2c9 549SHELL_STATUS\r
550EFIAPI\r
551PreHiiDrvCfg (\r
552 IN CONST CHAR8 *Language,\r
553 IN BOOLEAN ForceDefaults,\r
554 IN UINT32 DefaultType,\r
555 IN BOOLEAN AllChildren,\r
556 IN BOOLEAN ValidateOptions,\r
557 IN BOOLEAN SetOptions,\r
558 IN EFI_HANDLE DriverImageHandle,\r
559 IN EFI_HANDLE DeviceHandle,\r
560 IN EFI_HANDLE ChildHandle\r
561 )\r
562{\r
563 EFI_STATUS Status;\r
564 SHELL_STATUS ShellStatus;\r
565 UINTN OuterLoopCounter;\r
566 CHAR8 *BestLanguage;\r
567 UINTN DriverImageHandleCount;\r
568 EFI_HANDLE *DriverImageHandleBuffer;\r
569 UINTN HandleCount;\r
570 EFI_HANDLE *HandleBuffer;\r
571 UINTN *HandleType;\r
572 UINTN LoopCounter;\r
573 UINTN ChildIndex;\r
574 UINTN ChildHandleCount;\r
575 EFI_HANDLE *ChildHandleBuffer;\r
576 UINTN *ChildHandleType;\r
577 EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED ActionRequired;\r
578 EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration;\r
579 BOOLEAN Iso639Language;\r
580 UINTN HandleIndex1;\r
581 UINTN HandleIndex2;\r
582 UINTN HandleIndex3;\r
583\r
584 ShellStatus = SHELL_SUCCESS;\r
585\r
586 if (ChildHandle == NULL && AllChildren) {\r
587 SetOptions = FALSE;\r
588 }\r
589\r
590 if (ForceDefaults) {\r
591 ShellPrintHiiEx(\r
592 -1,\r
593 -1,\r
594 NULL,\r
595 STRING_TOKEN (STR_DRVCFG_FORCE_D), \r
596 gShellDriver1HiiHandle, \r
597 DefaultType);\r
598 } else if (ValidateOptions) {\r
599 ShellPrintHiiEx(\r
600 -1,\r
601 -1,\r
602 NULL,\r
603 STRING_TOKEN (STR_DRVCFG_VALIDATE), \r
604 gShellDriver1HiiHandle);\r
605 } else if (SetOptions) {\r
606 ShellPrintHiiEx(\r
607 -1,\r
608 -1,\r
609 NULL,\r
610 STRING_TOKEN (STR_DRVCFG_SET), \r
611 gShellDriver1HiiHandle);\r
612 }\r
613\r
614 if (DriverImageHandle == 0) {\r
615 DriverImageHandleBuffer = GetHandleListByProtocolList(CfgGuidList);\r
616 if (DriverImageHandleBuffer == NULL) {\r
617 ShellStatus = SHELL_NOT_FOUND;\r
618 goto Done;\r
619 }\r
620 for (\r
621 HandleBuffer = DriverImageHandleBuffer, DriverImageHandleCount = 0 \r
622 ; HandleBuffer != NULL && *HandleBuffer != NULL \r
623 ; HandleBuffer++,DriverImageHandleCount++);\r
624 } else {\r
625 DriverImageHandleCount = 1;\r
626 //\r
627 // Allocate buffer to hold the image handle so as to\r
628 // keep consistent with the above clause\r
629 //\r
630 DriverImageHandleBuffer = AllocatePool (sizeof (EFI_HANDLE));\r
631 ASSERT (DriverImageHandleBuffer);\r
632 DriverImageHandleBuffer[0] = DriverImageHandle;\r
633 }\r
634\r
635 for (OuterLoopCounter = 0; OuterLoopCounter < DriverImageHandleCount; OuterLoopCounter++) {\r
636 Iso639Language = FALSE;\r
637 Status = gBS->OpenProtocol (\r
638 DriverImageHandleBuffer[OuterLoopCounter],\r
639 &gEfiDriverConfiguration2ProtocolGuid,\r
640 (VOID **) &DriverConfiguration,\r
641 NULL,\r
642 NULL,\r
643 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
644 );\r
645 if (EFI_ERROR (Status)) {\r
646 Iso639Language = TRUE;\r
647 Status = gBS->OpenProtocol (\r
648 DriverImageHandleBuffer[OuterLoopCounter],\r
649 &gEfiDriverConfigurationProtocolGuid,\r
650 (VOID **) &DriverConfiguration,\r
651 NULL,\r
652 NULL,\r
653 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
654 );\r
655 }\r
656 if (EFI_ERROR (Status)) {\r
657// ShellPrintHiiEx(\r
658// -1,\r
659// -1,\r
660// NULL,\r
661// STRING_TOKEN (STR_DRVCFG_NOT_SUPPORT),\r
662// gShellDriver1HiiHandle,\r
663// ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter])\r
664// );\r
665 ShellStatus = SHELL_UNSUPPORTED;\r
666 continue;\r
667 }\r
668 \r
669 BestLanguage = GetBestLanguage (\r
670 DriverConfiguration->SupportedLanguages,\r
671 Iso639Language,\r
672 Language!=NULL?Language:"",\r
673 DriverConfiguration->SupportedLanguages,\r
674 NULL\r
675 );\r
676 if (BestLanguage == NULL) {\r
677 ShellPrintHiiEx(\r
678 -1,\r
679 -1,\r
680 NULL,\r
bc280720 681 STRING_TOKEN (STR_GEN_NO_VALUE),\r
4880c2c9 682 gShellDriver1HiiHandle,\r
bc280720 683 L"drvcfg",\r
4880c2c9 684 L"-l"\r
685 );\r
686 ShellStatus = SHELL_INVALID_PARAMETER;\r
687 continue;\r
688 }\r
689\r
690 Status = ParseHandleDatabaseByRelationshipWithType (\r
691 DriverImageHandleBuffer[OuterLoopCounter],\r
692 NULL,\r
693 &HandleCount,\r
694 &HandleBuffer,\r
695 &HandleType\r
696 );\r
697 if (EFI_ERROR (Status)) {\r
698 continue;\r
699 }\r
700\r
701 if (SetOptions && DeviceHandle == NULL) {\r
702\r
703 gST->ConOut->ClearScreen (gST->ConOut);\r
704 Status = DriverConfiguration->SetOptions (\r
705 DriverConfiguration,\r
706 NULL,\r
707 NULL,\r
708 BestLanguage,\r
709 &ActionRequired\r
710 );\r
711 gST->ConOut->ClearScreen (gST->ConOut);\r
712\r
713 ShellPrintHiiEx(\r
714 -1,\r
715 -1,\r
716 NULL,\r
717 STRING_TOKEN (STR_DRVCFG_ALL_LANG),\r
718 gShellDriver1HiiHandle,\r
719 ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]),\r
720 DriverConfiguration->SupportedLanguages\r
721 );\r
722 if (!EFI_ERROR (Status)) {\r
723 ShellPrintHiiEx(\r
724 -1,\r
725 -1,\r
726 NULL,\r
727 STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), \r
728 gShellDriver1HiiHandle);\r
729 for (LoopCounter = 0; LoopCounter < HandleCount; LoopCounter++) {\r
730 if ((HandleType[LoopCounter] & HR_CONTROLLER_HANDLE) == HR_CONTROLLER_HANDLE) {\r
731 ShellCmdDriverConfigurationProcessActionRequired (\r
732 DriverImageHandleBuffer[OuterLoopCounter],\r
733 HandleBuffer[LoopCounter],\r
734 NULL,\r
735 ActionRequired\r
736 );\r
737 }\r
738 }\r
739 } else {\r
740 ShellPrintHiiEx(\r
741 -1,\r
742 -1,\r
743 NULL,\r
744 STRING_TOKEN (STR_DRVCFG_NOT_SET), \r
745 gShellDriver1HiiHandle, \r
746 Status);\r
747 }\r
748 continue;\r
749 }\r
750\r
751 for (LoopCounter = 0; LoopCounter < HandleCount; LoopCounter++) {\r
752 if ((HandleType[LoopCounter] & HR_CONTROLLER_HANDLE) != HR_CONTROLLER_HANDLE) {\r
753 continue;\r
754 }\r
755 if (DeviceHandle != NULL && DeviceHandle != HandleBuffer[LoopCounter]) {\r
756 continue;\r
757 }\r
758 if (ChildHandle == NULL) {\r
759 HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]);\r
760 HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]);\r
761 ShellPrintHiiEx(\r
762 -1,\r
763 -1,\r
764 NULL,\r
765 STRING_TOKEN (STR_DRVCFG_CTRL_LANG),\r
766 gShellDriver1HiiHandle,\r
767 HandleIndex1,\r
768 HandleIndex2,\r
769 DriverConfiguration->SupportedLanguages\r
770 );\r
771\r
772 if (ForceDefaults) {\r
773 Status = DriverConfiguration->ForceDefaults (\r
774 DriverConfiguration,\r
775 HandleBuffer[LoopCounter],\r
776 NULL,\r
777 DefaultType,\r
778 &ActionRequired\r
779 );\r
780\r
781 if (!EFI_ERROR (Status)) {\r
782 ShellPrintHiiEx(\r
783 -1,\r
784 -1,\r
785 NULL,\r
786 STRING_TOKEN (STR_DRVCFG_DEF_FORCED), \r
787 gShellDriver1HiiHandle);\r
788 ShellCmdDriverConfigurationProcessActionRequired (\r
789 DriverImageHandleBuffer[OuterLoopCounter],\r
790 HandleBuffer[LoopCounter],\r
791 NULL,\r
792 ActionRequired\r
793 );\r
794 } else {\r
795 ShellPrintHiiEx(\r
796 -1,\r
797 -1,\r
798 NULL,\r
799 STRING_TOKEN (STR_DRVCFG_FORCE_FAILED), \r
800 gShellDriver1HiiHandle, \r
801 Status);\r
802 ShellStatus = SHELL_DEVICE_ERROR;\r
803 }\r
804 } else if (ValidateOptions) {\r
805 Status = DriverConfiguration->OptionsValid (\r
806 DriverConfiguration,\r
807 HandleBuffer[LoopCounter],\r
808 NULL\r
809 );\r
810\r
811 if (!EFI_ERROR (Status)) {\r
812 ShellPrintHiiEx(\r
813 -1,\r
814 -1,\r
815 NULL,\r
816 STRING_TOKEN (STR_DRVCFG_OPTIONS_VALID), \r
817 gShellDriver1HiiHandle);\r
818 } else {\r
819 ShellPrintHiiEx(\r
820 -1,\r
821 -1,\r
822 NULL,\r
823 STRING_TOKEN (STR_DRVCFG_OPTIONS_INV), \r
824 gShellDriver1HiiHandle, \r
825 Status);\r
826 ShellStatus = SHELL_DEVICE_ERROR;\r
827 }\r
828 } else if (SetOptions) {\r
829 gST->ConOut->ClearScreen (gST->ConOut);\r
830 Status = DriverConfiguration->SetOptions (\r
831 DriverConfiguration,\r
832 HandleBuffer[LoopCounter],\r
833 NULL,\r
834 BestLanguage,\r
835 &ActionRequired\r
836 );\r
837 gST->ConOut->ClearScreen (gST->ConOut);\r
838 HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]);\r
839 HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]);\r
840 ShellPrintHiiEx(\r
841 -1,\r
842 -1,\r
843 NULL,\r
844 STRING_TOKEN (STR_DRVCFG_CTRL_LANG),\r
845 gShellDriver1HiiHandle,\r
846 HandleIndex1,\r
847 HandleIndex2,\r
848 DriverConfiguration->SupportedLanguages\r
849 );\r
850 if (!EFI_ERROR (Status)) {\r
851 ShellPrintHiiEx(\r
852 -1,\r
853 -1,\r
854 NULL,\r
855 STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), \r
856 gShellDriver1HiiHandle);\r
857\r
858 ShellCmdDriverConfigurationProcessActionRequired (\r
859 DriverImageHandleBuffer[OuterLoopCounter],\r
860 HandleBuffer[LoopCounter],\r
861 NULL,\r
862 ActionRequired\r
863 );\r
864\r
865 } else {\r
866 ShellPrintHiiEx(\r
867 -1,\r
868 -1,\r
869 NULL,\r
870 STRING_TOKEN (STR_DRVCFG_NOT_SET), \r
871 gShellDriver1HiiHandle, \r
872 Status);\r
873 ShellStatus = SHELL_DEVICE_ERROR;\r
874 }\r
875 } else {\r
876 Print (L"\n");\r
877 }\r
878 }\r
879\r
880 if (ChildHandle == NULL && !AllChildren) {\r
881 continue;\r
882 }\r
883\r
884 Status = ParseHandleDatabaseByRelationshipWithType (\r
885 DriverImageHandleBuffer[OuterLoopCounter],\r
886 HandleBuffer[LoopCounter],\r
887 &ChildHandleCount,\r
888 &ChildHandleBuffer,\r
889 &ChildHandleType\r
890 );\r
891 if (EFI_ERROR (Status)) {\r
892 continue;\r
893 }\r
894\r
895 for (ChildIndex = 0; ChildIndex < ChildHandleCount; ChildIndex++) {\r
896\r
897 if ((ChildHandleType[ChildIndex] & HR_CHILD_HANDLE) != HR_CHILD_HANDLE) {\r
898 continue;\r
899 }\r
900\r
901 if (ChildHandle != NULL && ChildHandle != ChildHandleBuffer[ChildIndex]) {\r
902 continue;\r
903 }\r
904\r
905 HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]);\r
906 HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]);\r
907 HandleIndex3 = ConvertHandleToHandleIndex (ChildHandleBuffer[ChildIndex]);\r
908 ShellPrintHiiEx(\r
909 -1,\r
910 -1,\r
911 NULL,\r
912 STRING_TOKEN (STR_DRVCFG_CHILD_LANG),\r
913 gShellDriver1HiiHandle,\r
914 HandleIndex1,\r
915 HandleIndex2,\r
916 HandleIndex3,\r
917 DriverConfiguration->SupportedLanguages);\r
918\r
919 if (ForceDefaults) {\r
920 Status = DriverConfiguration->ForceDefaults (\r
921 DriverConfiguration,\r
922 HandleBuffer[LoopCounter],\r
923 ChildHandleBuffer[ChildIndex],\r
924 DefaultType,\r
925 &ActionRequired\r
926 );\r
927\r
928 if (!EFI_ERROR (Status)) {\r
929 ShellPrintHiiEx(\r
930 -1,\r
931 -1,\r
932 NULL,\r
933 STRING_TOKEN (STR_DRVCFG_DEF_FORCED), \r
934 gShellDriver1HiiHandle);\r
935\r
936 ShellCmdDriverConfigurationProcessActionRequired (\r
937 DriverImageHandleBuffer[OuterLoopCounter],\r
938 HandleBuffer[LoopCounter],\r
939 ChildHandleBuffer[ChildIndex],\r
940 ActionRequired\r
941 );\r
942\r
943 } else {\r
944 ShellPrintHiiEx(\r
945 -1,\r
946 -1,\r
947 NULL,\r
948 STRING_TOKEN (STR_DRVCFG_FORCE_FAILED), \r
949 gShellDriver1HiiHandle, \r
950 Status);\r
951 ShellStatus = SHELL_DEVICE_ERROR;\r
952 }\r
953 } else if (ValidateOptions) {\r
954 Status = DriverConfiguration->OptionsValid (\r
955 DriverConfiguration,\r
956 HandleBuffer[LoopCounter],\r
957 ChildHandleBuffer[ChildIndex]\r
958 );\r
959\r
960 if (!EFI_ERROR (Status)) {\r
961 ShellPrintHiiEx(\r
962 -1,\r
963 -1,\r
964 NULL,\r
965 STRING_TOKEN (STR_DRVCFG_OPTIONS_VALID), \r
966 gShellDriver1HiiHandle);\r
967 } else {\r
968 ShellPrintHiiEx(\r
969 -1,\r
970 -1,\r
971 NULL,\r
972 STRING_TOKEN (STR_DRVCFG_OPTIONS_INV), \r
973 gShellDriver1HiiHandle, \r
974 Status);\r
975 ShellStatus = SHELL_DEVICE_ERROR;\r
976 }\r
977 } else if (SetOptions) {\r
978 gST->ConOut->ClearScreen (gST->ConOut);\r
979 Status = DriverConfiguration->SetOptions (\r
980 DriverConfiguration,\r
981 HandleBuffer[LoopCounter],\r
982 ChildHandleBuffer[ChildIndex],\r
983 BestLanguage,\r
984 &ActionRequired\r
985 );\r
986 gST->ConOut->ClearScreen (gST->ConOut);\r
987 HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]);\r
988 HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]);\r
989 HandleIndex3 = ConvertHandleToHandleIndex (ChildHandleBuffer[ChildIndex]);\r
990 ShellPrintHiiEx(\r
991 -1,\r
992 -1,\r
993 NULL,\r
994 STRING_TOKEN (STR_DRVCFG_CHILD_LANG),\r
995 gShellDriver1HiiHandle,\r
996 HandleIndex1,\r
997 HandleIndex2,\r
998 HandleIndex3,\r
999 DriverConfiguration->SupportedLanguages\r
1000 );\r
1001 if (!EFI_ERROR (Status)) {\r
1002 ShellPrintHiiEx(\r
1003 -1,\r
1004 -1,\r
1005 NULL,\r
1006 STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), \r
1007 gShellDriver1HiiHandle);\r
1008\r
1009 ShellCmdDriverConfigurationProcessActionRequired (\r
1010 DriverImageHandleBuffer[OuterLoopCounter],\r
1011 HandleBuffer[LoopCounter],\r
1012 ChildHandleBuffer[ChildIndex],\r
1013 ActionRequired\r
1014 );\r
1015\r
1016 } else {\r
1017 ShellPrintHiiEx(\r
1018 -1,\r
1019 -1,\r
1020 NULL,\r
1021 STRING_TOKEN (STR_DRVCFG_NOT_SET), \r
1022 gShellDriver1HiiHandle, \r
1023 Status);\r
1024 ShellStatus = SHELL_DEVICE_ERROR;\r
1025 }\r
1026 } else {\r
1027 Print (L"\n");\r
1028 }\r
1029 }\r
1030\r
1031 FreePool (ChildHandleBuffer);\r
1032 FreePool (ChildHandleType);\r
1033 }\r
1034\r
1035 FreePool (BestLanguage);\r
1036 FreePool (HandleBuffer);\r
1037 FreePool (HandleType);\r
1038 }\r
1039\r
1040 if (DriverImageHandle != NULL && DriverImageHandleCount != 0) {\r
1041 FreePool (DriverImageHandleBuffer);\r
1042 }\r
1043\r
1044Done:\r
1045 return ShellStatus;\r
1046}\r
1047\r
4ba49616 1048/**\r
1049 Function to print out configuration information on all configurable handles.\r
1050\r
1051 @param[in] ChildrenToo TRUE to tewst for children.\r
4880c2c9 1052 @param[in] Language ASCII string for language code.\r
1053 @param[in] UseHii TRUE to check for Hii and DPC, FALSE for DCP only.\r
4ba49616 1054\r
1055 @retval SHELL_SUCCESS The operation was successful.\r
1056**/\r
1057SHELL_STATUS\r
1058EFIAPI\r
1059PrintConfigInfoOnAll(\r
4880c2c9 1060 IN CONST BOOLEAN ChildrenToo,\r
1061 IN CONST CHAR8 *Language,\r
1062 IN CONST BOOLEAN UseHii\r
4ba49616 1063 )\r
1064{\r
4ba49616 1065 EFI_HANDLE *HandleList;\r
1066 EFI_HANDLE *CurrentHandle;\r
4ba49616 1067 BOOLEAN Found;\r
4880c2c9 1068 UINTN Index2;\r
1069\r
4ba49616 1070\r
1071 Found = FALSE;\r
4ba49616 1072 HandleList = NULL;\r
1073 CurrentHandle = NULL;\r
4ba49616 1074\r
4880c2c9 1075 if (UseHii) {\r
1076 //\r
1077 // HII method\r
1078 //\r
1079 HandleList = GetHandleListByProtocol(&gEfiHiiConfigAccessProtocolGuid);\r
1080 for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL; CurrentHandle++){\r
1081 Found = TRUE;\r
1082 Index2 = *CurrentHandle == NULL ? 0 : ConvertHandleToHandleIndex(*CurrentHandle);\r
1083 ShellPrintHiiEx(\r
1084 -1, \r
1085 -1, \r
1086 NULL, \r
1087 STRING_TOKEN (STR_DRVCFG_LINE_HII), \r
1088 gShellDriver1HiiHandle, \r
1089 Index2\r
1090 );\r
4ba49616 1091 }\r
4880c2c9 1092 SHELL_FREE_NON_NULL(HandleList);\r
4ba49616 1093 }\r
4ba49616 1094\r
4880c2c9 1095 if (PreHiiDrvCfg (\r
1096 Language,\r
1097 FALSE,\r
1098 0,\r
1099 ChildrenToo,\r
1100 FALSE,\r
1101 FALSE,\r
1102 0,\r
1103 0,\r
1104 0) == SHELL_SUCCESS) {\r
1105 Found = TRUE;\r
4ba49616 1106 }\r
4880c2c9 1107\r
4ba49616 1108 if (!Found) {\r
885f7fd0 1109 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE_FOUND), gShellDriver1HiiHandle);\r
4ba49616 1110 return (SHELL_SUCCESS);\r
1111 }\r
4880c2c9 1112\r
1113 return (SHELL_SUCCESS);\r
4ba49616 1114}\r
1115\r
4880c2c9 1116STATIC CONST SHELL_PARAM_ITEM ParamListHii[] = {\r
4ba49616 1117 {L"-s", TypeFlag},\r
4ba49616 1118 {L"-l", TypeValue},\r
1119 {L"-f", TypeValue},\r
1120 {L"-o", TypeValue},\r
1121 {L"-i", TypeValue},\r
1122 {NULL, TypeMax}\r
1123 };\r
4880c2c9 1124STATIC CONST SHELL_PARAM_ITEM ParamListPreHii[] = {\r
1125 {L"-c", TypeFlag},\r
1126 {L"-s", TypeFlag},\r
1127 {L"-v", TypeFlag},\r
1128 {L"-l", TypeValue},\r
1129 {L"-f", TypeValue},\r
1130 {NULL, TypeMax}\r
1131 };\r
4ba49616 1132\r
361a8267 1133/**\r
1134 Function for 'drvcfg' command.\r
1135\r
1136 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
1137 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
1138**/\r
4ba49616 1139SHELL_STATUS\r
1140EFIAPI\r
1141ShellCommandRunDrvCfg (\r
1142 IN EFI_HANDLE ImageHandle,\r
1143 IN EFI_SYSTEM_TABLE *SystemTable\r
1144 )\r
1145{\r
1146 EFI_STATUS Status;\r
1147 LIST_ENTRY *Package;\r
1148 CHAR16 *ProblemParam;\r
1149 SHELL_STATUS ShellStatus;\r
1150 CHAR8 *Language;\r
1151 CONST CHAR16 *Lang;\r
4880c2c9 1152 CONST CHAR16 *HandleIndex1;\r
1153 CONST CHAR16 *HandleIndex2;\r
1154 CONST CHAR16 *HandleIndex3;\r
1155 CONST CHAR16 *ForceTypeString;\r
1156 BOOLEAN Force;\r
1157 BOOLEAN Set;\r
1158 BOOLEAN Validate;\r
1159 BOOLEAN InFromFile;\r
1160 BOOLEAN OutToFile;\r
1161 BOOLEAN AllChildren;\r
1162 BOOLEAN UseHii;\r
1163 UINT32 ForceType;\r
1164 UINT64 Intermediate;\r
1165 EFI_HANDLE Handle1;\r
1166 EFI_HANDLE Handle2;\r
1167 EFI_HANDLE Handle3;\r
1168 CONST CHAR16 *FileName;\r
4ba49616 1169\r
1170 ShellStatus = SHELL_SUCCESS;\r
1171 Status = EFI_SUCCESS;\r
1172 Language = NULL;\r
4880c2c9 1173 UseHii = TRUE;\r
4ba49616 1174\r
1175 //\r
1176 // initialize the shell lib (we must be in non-auto-init...)\r
1177 //\r
1178 Status = ShellInitialize();\r
1179 ASSERT_EFI_ERROR(Status);\r
1180\r
1181 Status = CommandInit();\r
1182 ASSERT_EFI_ERROR(Status);\r
1183\r
1184 //\r
1185 // parse the command line\r
1186 //\r
4880c2c9 1187 Status = ShellCommandLineParse (ParamListHii, &Package, &ProblemParam, TRUE);\r
1188 if (EFI_ERROR(Status) || ShellCommandLineGetCount(Package) > 2) {\r
1189 UseHii = FALSE;\r
1190 if (Package != NULL) {\r
1191 ShellCommandLineFreeVarList (Package);\r
4ba49616 1192 }\r
4880c2c9 1193 SHELL_FREE_NON_NULL(ProblemParam);\r
1194 Status = ShellCommandLineParse (ParamListPreHii, &Package, &ProblemParam, TRUE);\r
1195 if (EFI_ERROR(Status)) {\r
1196 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
bc280720 1197 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"drvcfg", ProblemParam);\r
4880c2c9 1198 FreePool(ProblemParam);\r
1199 ShellStatus = SHELL_INVALID_PARAMETER;\r
1200 goto Done;\r
1201 } else {\r
1202 ASSERT(FALSE);\r
1203 }\r
1204 }\r
1205 } \r
1206 if (ShellStatus == SHELL_SUCCESS) {\r
4ba49616 1207 Lang = ShellCommandLineGetValue(Package, L"-l");\r
1208 if (Lang != NULL) {\r
1209 Language = AllocateZeroPool(StrSize(Lang));\r
1210 AsciiSPrint(Language, StrSize(Lang), "%S", Lang);\r
4880c2c9 1211 } else if (ShellCommandLineGetFlag(Package, L"-l")){\r
bc280720 1212 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"drvcfg", L"-l");\r
4880c2c9 1213 ShellStatus = SHELL_INVALID_PARAMETER;\r
1214 goto Done;\r
1215 }\r
1216 Set = ShellCommandLineGetFlag (Package, L"-s");\r
1217 Validate = ShellCommandLineGetFlag (Package, L"-v");\r
1218 InFromFile = ShellCommandLineGetFlag (Package, L"-i");\r
1219 OutToFile = ShellCommandLineGetFlag (Package, L"-o");\r
1220 AllChildren = ShellCommandLineGetFlag (Package, L"-c");\r
1221 Force = ShellCommandLineGetFlag (Package, L"-f");\r
1222 ForceTypeString = ShellCommandLineGetValue(Package, L"-f");\r
1223\r
1224 if (OutToFile) {\r
1225 FileName = ShellCommandLineGetValue(Package, L"-o");\r
1226 } else if (InFromFile) {\r
1227 FileName = ShellCommandLineGetValue(Package, L"-i");\r
1228 } else {\r
1229 FileName = NULL;\r
1230 }\r
1231\r
1232 if (InFromFile && EFI_ERROR(ShellFileExists(FileName))) {\r
bc280720 1233 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FIND_FAIL), gShellDriver1HiiHandle, L"drvcfg", FileName); \r
4880c2c9 1234 ShellStatus = SHELL_INVALID_PARAMETER;\r
1235 goto Done; \r
1236 }\r
1237 if (OutToFile && !EFI_ERROR(ShellFileExists(FileName))) {\r
bc280720 1238 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_EXIST), gShellDriver1HiiHandle, L"drvcfg", FileName); \r
4880c2c9 1239 ShellStatus = SHELL_INVALID_PARAMETER;\r
1240 goto Done; \r
1241 }\r
1242 if (Force && ForceTypeString == NULL) {\r
bc280720 1243 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"drvcfg", L"-f"); \r
4880c2c9 1244 ShellStatus = SHELL_INVALID_PARAMETER;\r
1245 goto Done;\r
1246 } \r
1247 if (Force) {\r
1248 Status = ShellConvertStringToUint64(ForceTypeString, &Intermediate, FALSE, FALSE);\r
1249 if (EFI_ERROR(Status)) {\r
bc280720 1250 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDriver1HiiHandle, L"drvcfg", ForceTypeString, L"-f"); \r
4880c2c9 1251 ShellStatus = SHELL_INVALID_PARAMETER;\r
1252 goto Done;\r
1253 }\r
1254 ForceType = (UINT32)Intermediate;\r
1255 } else {\r
1256 ForceType = 0;\r
1257 }\r
1258 HandleIndex1 = ShellCommandLineGetRawValue(Package, 1);\r
1259 Handle1 = NULL;\r
1260 if (HandleIndex1 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex1, &Intermediate, TRUE, FALSE))) {\r
1261 Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate);\r
1262 if (Handle1 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) {\r
bc280720 1263 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"drvcfg", HandleIndex1); \r
4880c2c9 1264 ShellStatus = SHELL_INVALID_PARAMETER;\r
1265 goto Done;\r
1266 }\r
1267 }\r
1268 HandleIndex2 = ShellCommandLineGetRawValue(Package, 2);\r
1269 Handle2 = NULL;\r
1270 if (HandleIndex2 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex2, &Intermediate, TRUE, FALSE))) {\r
1271 Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate);\r
1272 if (Handle2 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) {\r
bc280720 1273 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"drvcfg", HandleIndex2); \r
4880c2c9 1274 ShellStatus = SHELL_INVALID_PARAMETER;\r
1275 goto Done;\r
1276 }\r
1277 }\r
1278 HandleIndex3 = ShellCommandLineGetRawValue(Package, 3);\r
1279 Handle3 = NULL;\r
1280 if (HandleIndex3 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex3, &Intermediate, TRUE, FALSE))) {\r
1281 Handle3 = ConvertHandleIndexToHandle((UINTN)Intermediate);\r
1282 if (Handle3 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) {\r
bc280720 1283 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"drvcfg", HandleIndex3); \r
4880c2c9 1284 ShellStatus = SHELL_INVALID_PARAMETER;\r
1285 goto Done;\r
1286 }\r
1287 }\r
1288\r
1289 if ((InFromFile || OutToFile) && (FileName == NULL)) {\r
1290 if (FileName == NULL) {\r
bc280720 1291 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"drvcfg", InFromFile?L"-i":L"-o"); \r
4880c2c9 1292 } else {\r
bc280720 1293 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_REQ), gShellDriver1HiiHandle, L"drvcfg"); \r
4880c2c9 1294 }\r
1295 ShellStatus = SHELL_INVALID_PARAMETER;\r
1296 goto Done;\r
1297 }\r
1298 if (!UseHii && (InFromFile || OutToFile)) {\r
1299 if (InFromFile) {\r
bc280720 1300 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDriver1HiiHandle, L"drvcfg", L"-i"); \r
4880c2c9 1301 ShellStatus = SHELL_INVALID_PARAMETER;\r
1302 goto Done;\r
1303 } \r
1304 if (OutToFile) {\r
bc280720 1305 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDriver1HiiHandle, L"drvcfg", L"-o"); \r
4880c2c9 1306 ShellStatus = SHELL_INVALID_PARAMETER;\r
1307 goto Done;\r
1308 }\r
1309 }\r
1310 if (Validate && Force) {\r
bc280720 1311 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDriver1HiiHandle, L"drvcfg", L"-v", L"-f"); \r
4880c2c9 1312 ShellStatus = SHELL_INVALID_PARAMETER;\r
1313 goto Done;\r
1314 } \r
1315 if (Validate && Set) {\r
bc280720 1316 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDriver1HiiHandle, L"drvcfg", L"-v", L"-s"); \r
4880c2c9 1317 ShellStatus = SHELL_INVALID_PARAMETER;\r
1318 goto Done;\r
1319 } \r
1320 if (Set && Force) {\r
bc280720 1321 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDriver1HiiHandle, L"drvcfg", L"-s", L"-f"); \r
4880c2c9 1322 ShellStatus = SHELL_INVALID_PARAMETER;\r
1323 goto Done;\r
1324 }\r
1325 if (OutToFile && InFromFile) {\r
bc280720 1326 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDriver1HiiHandle, L"drvcfg", L"-i", L"-o"); \r
4880c2c9 1327 ShellStatus = SHELL_INVALID_PARAMETER;\r
1328 goto Done;\r
4ba49616 1329 }\r
1330\r
1331 //\r
4880c2c9 1332 // We do HII first.\r
4ba49616 1333 //\r
4880c2c9 1334 if (UseHii) {\r
1335 if (Handle1 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {\r
4ba49616 1336 //\r
4880c2c9 1337 // no HII on this handle.\r
4ba49616 1338 //\r
4880c2c9 1339 ShellStatus = SHELL_UNSUPPORTED;\r
1340 } else if (Validate) {\r
1341 } else if (Force) {\r
1342 } else if (Set) {\r
1343 } else if (InFromFile) {\r
1344 ShellStatus = ConfigFromFile(Handle1, FileName);\r
1345 if (Handle1 != NULL && ShellStatus == SHELL_SUCCESS) {\r
1346 goto Done;\r
1347 }\r
1348 } else if (OutToFile) {\r
1349 ShellStatus = ConfigToFile(Handle1, FileName);\r
1350 if (Handle1 != NULL && ShellStatus == SHELL_SUCCESS) {\r
1351 goto Done;\r
1352 }\r
1353 } else if (HandleIndex1 == NULL) {\r
1354 //\r
1355 // display all that are configurable\r
1356 //\r
1357 ShellStatus = PrintConfigInfoOnAll(AllChildren, Language, UseHii);\r
1358 goto Done;\r
1359 } else {\r
1360 if (!EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {\r
1361 ShellPrintHiiEx(\r
1362 -1, \r
1363 -1, \r
1364 NULL, \r
1365 STRING_TOKEN (STR_DRVCFG_LINE_HII), \r
1366 gShellDriver1HiiHandle, \r
1367 ConvertHandleToHandleIndex(Handle1)\r
1368 );\r
1369 goto Done;\r
4ba49616 1370 }\r
1371 }\r
4880c2c9 1372 }\r
1373\r
1374 //\r
1375 // We allways need to do this one since it does both by default.\r
1376 //\r
1377 if (!InFromFile && !OutToFile) {\r
1378 ShellStatus = PreHiiDrvCfg (\r
1379 Language,\r
1380 Force,\r
1381 ForceType,\r
1382 AllChildren,\r
1383 Validate,\r
1384 Set,\r
1385 Handle1,\r
1386 Handle2,\r
1387 Handle3);\r
1388 }\r
1389\r
1390 if (ShellStatus == SHELL_UNSUPPORTED) {\r
1391 ShellPrintHiiEx(\r
1392 -1,\r
1393 -1,\r
1394 NULL,\r
1395 STRING_TOKEN (STR_DRVCFG_NOT_SUPPORT),\r
1396 gShellDriver1HiiHandle, \r
1397 ConvertHandleToHandleIndex(Handle1)\r
1398 );\r
4ba49616 1399 }\r
1400 }\r
4880c2c9 1401\r
1402Done:\r
4ba49616 1403 ShellCommandLineFreeVarList (Package);\r
1404 SHELL_FREE_NON_NULL(Language);\r
1405 return (ShellStatus);\r
1406}\r