EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c

Go to the documentation of this file.
00001 
00015 #include "UefiShellDriver1CommandsLib.h"
00016 #include <Protocol/HiiConfigAccess.h>
00017 #include <Protocol/HiiDatabase.h>
00018 
00019 STATIC CONST EFI_GUID *CfgGuidList[] = {&gEfiDriverConfigurationProtocolGuid, &gEfiDriverConfiguration2ProtocolGuid, NULL};
00020 
00031 EFI_STATUS
00032 EFIAPI
00033 FindHiiHandleViaDevPath(
00034   IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath1,
00035   OUT EFI_HII_HANDLE                *HiiHandle,
00036   IN EFI_HII_DATABASE_PROTOCOL      *HiiDb
00037   )
00038 {
00039   EFI_HII_HANDLE                *HandleBuffer;
00040   UINTN                         HandleBufferSize;
00041   VOID                          *MainBuffer;
00042   UINTN                         MainBufferSize;
00043   EFI_HII_PACKAGE_LIST_HEADER   *PackageListHeader;
00044   EFI_HII_PACKAGE_HEADER        *PackageHeader;
00045   UINTN                         LoopVariable;
00046   EFI_DEVICE_PATH_PROTOCOL      *DevPath2;
00047   EFI_STATUS                    Status;
00048 
00049   ASSERT(DevPath1 != NULL);
00050   ASSERT(HiiHandle != NULL);
00051   ASSERT(*HiiHandle == NULL);
00052   ASSERT(HiiDb != NULL);
00053 
00054   HandleBufferSize  = 0;
00055   HandleBuffer      = NULL;
00056   Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);
00057   if (Status == EFI_BUFFER_TOO_SMALL) {
00058     HandleBuffer = AllocateZeroPool(HandleBufferSize);
00059     ASSERT (HandleBuffer != NULL);
00060     Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);
00061   }
00062   if (EFI_ERROR(Status)) {
00063     SHELL_FREE_NON_NULL(HandleBuffer);
00064     return (Status);
00065   }
00066 
00067   if (HandleBuffer == NULL) {
00068     return EFI_NOT_FOUND;
00069   }
00070 
00071   for (LoopVariable = 0 ; LoopVariable < (HandleBufferSize/sizeof(HandleBuffer[0])) && *HiiHandle == NULL ; LoopVariable++) {
00072     MainBufferSize    = 0;
00073     MainBuffer        = NULL;
00074     Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer);
00075     if (Status == EFI_BUFFER_TOO_SMALL) {
00076       MainBuffer = AllocateZeroPool(MainBufferSize);
00077       ASSERT (MainBuffer != NULL);
00078       Status = HiiDb->ExportPackageLists(HiiDb, HandleBuffer[LoopVariable], &MainBufferSize, MainBuffer);
00079     }
00080     //
00081     // Enumerate through the block of returned memory.
00082     // This should actually be a small block, but we need to be sure.
00083     //
00084     for (PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)MainBuffer
00085       ;  PackageListHeader != NULL && ((CHAR8*)PackageListHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && *HiiHandle == NULL
00086       ;  PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) {
00087         for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER))
00088           ; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END && *HiiHandle == NULL
00089           ; PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageHeader))+PackageHeader->Length)) {
00090             if (PackageHeader->Type == EFI_HII_PACKAGE_DEVICE_PATH) {
00091               DevPath2 = (EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER));
00092               if (DevicePathCompare(&DevPath1, &DevPath2) == 0) {
00093                 *HiiHandle = HandleBuffer[LoopVariable];
00094                 break;
00095               }
00096             }
00097         }
00098     }
00099     SHELL_FREE_NON_NULL(MainBuffer);
00100   }
00101   SHELL_FREE_NON_NULL(HandleBuffer);
00102 
00103   if (*HiiHandle == NULL) {
00104     return (EFI_NOT_FOUND);
00105   }
00106   return (EFI_SUCCESS);
00107 }
00108 
00118 EFI_STATUS
00119 EFIAPI
00120 ConvertHandleToHiiHandle(
00121   IN CONST EFI_HANDLE           Handle,
00122   OUT EFI_HII_HANDLE            *HiiHandle,
00123   IN EFI_HII_DATABASE_PROTOCOL  *HiiDb
00124   )
00125 {
00126   EFI_STATUS                    Status;
00127   EFI_DEVICE_PATH_PROTOCOL      *DevPath1;
00128 
00129   if (HiiHandle == NULL || HiiDb == NULL) {
00130     return (EFI_INVALID_PARAMETER);
00131   }
00132   *HiiHandle = NULL;
00133 
00134   if (Handle == NULL) {
00135     return (EFI_SUCCESS);
00136   }
00137 
00138   DevPath1 = NULL;
00139   Status = gBS->OpenProtocol(Handle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath1, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
00140   if (EFI_ERROR(Status) || DevPath1 == NULL) {
00141     return (EFI_NOT_FOUND);
00142   }
00143 
00144   return (FindHiiHandleViaDevPath(DevPath1, HiiHandle, HiiDb));
00145 }
00146 
00153 SHELL_STATUS
00154 EFIAPI
00155 ConfigToFile(
00156   IN CONST EFI_HANDLE     Handle,
00157   IN CONST CHAR16         *FileName
00158   )
00159 {
00160   EFI_HII_DATABASE_PROTOCOL     *HiiDatabase;
00161   EFI_STATUS                    Status;
00162   VOID                          *MainBuffer;
00163   UINTN                         MainBufferSize;
00164   EFI_HII_HANDLE                HiiHandle;
00165   SHELL_FILE_HANDLE             FileHandle;
00166 
00167   HiiDatabase       = NULL;
00168   MainBufferSize    = 0;
00169   MainBuffer        = NULL;
00170   FileHandle        = NULL;
00171 
00172   Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
00173   if (EFI_ERROR(Status)) {
00174     ShellPrintHiiEx(
00175       -1,
00176       -1,
00177       NULL,
00178       STRING_TOKEN(STR_GEN_FILE_OPEN), 
00179       gShellDriver1HiiHandle, 
00180       FileName, 
00181       Status);
00182     return (SHELL_DEVICE_ERROR);
00183   }
00184 
00185   //
00186   // Locate HII Database protocol
00187   //
00188   Status = gBS->LocateProtocol (
00189                   &gEfiHiiDatabaseProtocolGuid,
00190                   NULL,
00191                   (VOID **) &HiiDatabase
00192                   );
00193 
00194   if (EFI_ERROR(Status) || HiiDatabase == NULL) {
00195     ShellPrintHiiEx(
00196       -1, 
00197       -1, 
00198       NULL,
00199       STRING_TOKEN(STR_GEN_PROTOCOL_NF), 
00200       gShellDriver1HiiHandle, 
00201       L"EfiHiiDatabaseProtocol", 
00202       &gEfiHiiDatabaseProtocolGuid);
00203     ShellCloseFile(&FileHandle);
00204     return (SHELL_NOT_FOUND);
00205   }
00206 
00207   Status = ConvertHandleToHiiHandle(Handle, &HiiHandle, HiiDatabase);
00208   if (EFI_ERROR(Status)) {
00209     ShellPrintHiiEx(
00210       -1, 
00211       -1, 
00212       NULL, 
00213       STRING_TOKEN(STR_GEN_HANDLE_NOT), 
00214       gShellDriver1HiiHandle, 
00215       ConvertHandleToHandleIndex(Handle), 
00216       L"Device");
00217     ShellCloseFile(&FileHandle);
00218     return (SHELL_DEVICE_ERROR);   
00219   }
00220 
00221   Status = HiiDatabase->ExportPackageLists(HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer);
00222   if (Status == EFI_BUFFER_TOO_SMALL) {
00223     MainBuffer = AllocateZeroPool(MainBufferSize);
00224     Status = HiiDatabase->ExportPackageLists(HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer);
00225   }
00226 
00227   Status = ShellWriteFile(FileHandle, &MainBufferSize, MainBuffer);
00228 
00229   ShellCloseFile(&FileHandle);
00230   SHELL_FREE_NON_NULL(MainBuffer);
00231 
00232   if (EFI_ERROR(Status)) {
00233     ShellPrintHiiEx(
00234       -1, 
00235       -1,
00236       NULL,
00237       STRING_TOKEN(STR_FILE_WRITE_FAIL), 
00238       gShellDriver1HiiHandle, 
00239       FileName, 
00240       Status);
00241     return (SHELL_DEVICE_ERROR);   
00242   }
00243   ShellPrintHiiEx(
00244     -1, 
00245     -1,
00246     NULL,
00247     STRING_TOKEN(STR_DRVCFG_COMP), 
00248     gShellDriver1HiiHandle);
00249 
00250   return (SHELL_SUCCESS);
00251 }
00252 
00259 SHELL_STATUS
00260 EFIAPI
00261 ConfigFromFile(
00262   IN       EFI_HANDLE     Handle,
00263   IN CONST CHAR16         *FileName
00264   )
00265 {
00266   EFI_HII_DATABASE_PROTOCOL     *HiiDatabase;
00267   EFI_STATUS                    Status;
00268   VOID                          *MainBuffer;
00269   UINT64                        Temp;
00270   UINTN                         MainBufferSize;
00271   EFI_HII_HANDLE                HiiHandle;
00272   SHELL_FILE_HANDLE             FileHandle;
00273   CHAR16                        *TempDevPathString;
00274   EFI_HII_PACKAGE_LIST_HEADER   *PackageListHeader;
00275   EFI_HII_PACKAGE_HEADER        *PackageHeader;
00276   EFI_DEVICE_PATH_PROTOCOL      *DevPath;
00277   UINTN                         HandleIndex;
00278 
00279   HiiDatabase       = NULL;
00280   MainBufferSize    = 0;
00281   MainBuffer        = NULL;
00282   FileHandle        = NULL;
00283 
00284   Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
00285   if (EFI_ERROR(Status)) {
00286     ShellPrintHiiEx(
00287       -1,
00288       -1,
00289       NULL,
00290       STRING_TOKEN(STR_GEN_FILE_OPEN), 
00291       gShellDriver1HiiHandle, 
00292       FileName, 
00293       Status);
00294     return (SHELL_DEVICE_ERROR);
00295   }
00296 
00297   //
00298   // Locate HII Database protocol
00299   //
00300   Status = gBS->LocateProtocol (
00301                   &gEfiHiiDatabaseProtocolGuid,
00302                   NULL,
00303                   (VOID **) &HiiDatabase
00304                   );
00305 
00306   if (EFI_ERROR(Status) || HiiDatabase == NULL) {
00307     ShellPrintHiiEx(
00308       -1, 
00309       -1, 
00310       NULL,
00311       STRING_TOKEN(STR_GEN_PROTOCOL_NF), 
00312       gShellDriver1HiiHandle, 
00313       L"EfiHiiDatabaseProtocol", 
00314       &gEfiHiiDatabaseProtocolGuid);
00315     ShellCloseFile(&FileHandle);
00316     return (SHELL_NOT_FOUND);
00317   }
00318 
00319   Status = ShellGetFileSize(FileHandle, &Temp);
00320   MainBufferSize = (UINTN)Temp;
00321   if (EFI_ERROR(Status)) {
00322     ShellPrintHiiEx(
00323       -1, 
00324       -1, 
00325       NULL, 
00326       STRING_TOKEN(STR_FILE_READ_FAIL), 
00327       gShellDriver1HiiHandle, 
00328       FileName,
00329       Status);
00330     ShellCloseFile(&FileHandle);
00331     return (SHELL_DEVICE_ERROR);   
00332   }
00333   MainBuffer = AllocateZeroPool((UINTN)MainBufferSize);  
00334   if (EFI_ERROR(Status)) {
00335     ShellPrintHiiEx(
00336       -1, 
00337       -1, 
00338       NULL, 
00339       STRING_TOKEN(STR_GEN_OUT_MEM), 
00340       gShellDriver1HiiHandle);
00341     ShellCloseFile(&FileHandle);
00342     return (SHELL_DEVICE_ERROR);   
00343   }
00344   Status = ShellReadFile(FileHandle, &MainBufferSize, MainBuffer);
00345   if (EFI_ERROR(Status)) {
00346     ShellPrintHiiEx(
00347       -1, 
00348       -1, 
00349       NULL, 
00350       STRING_TOKEN(STR_FILE_READ_FAIL), 
00351       gShellDriver1HiiHandle, 
00352       FileName,
00353       Status);
00354     ShellCloseFile(&FileHandle);
00355     SHELL_FREE_NON_NULL(MainBuffer);
00356     return (SHELL_DEVICE_ERROR);   
00357   }
00358 
00359   ShellCloseFile(&FileHandle);
00360 
00361   if (Handle != NULL) {
00362     //
00363     // User override in place.  Just do it.
00364     //
00365     HiiHandle         = NULL;
00366     Status = ConvertHandleToHiiHandle(Handle, &HiiHandle, HiiDatabase);
00367     if (EFI_ERROR(Status)) {
00368       ShellPrintHiiEx(
00369         -1, 
00370         -1, 
00371         NULL, 
00372         STRING_TOKEN(STR_GEN_HANDLE_NOT), 
00373         gShellDriver1HiiHandle, 
00374         ConvertHandleToHandleIndex(Handle), 
00375         L"Device");
00376       ShellCloseFile(&FileHandle);
00377       return (SHELL_DEVICE_ERROR);   
00378     }
00379     Status = HiiDatabase->UpdatePackageList(HiiDatabase, HiiHandle, MainBuffer);
00380     if (EFI_ERROR(Status)) {
00381       ShellPrintHiiEx(
00382         -1, 
00383         -1, 
00384         NULL, 
00385         STRING_TOKEN(STR_GEN_UEFI_FUNC_ERROR), 
00386         gShellDriver1HiiHandle, 
00387         L"HiiDatabase->UpdatePackageList", 
00388         Status);
00389       return (SHELL_DEVICE_ERROR);   
00390     }
00391   } else {
00392     //
00393     // we need to parse the buffer and try to match the device paths for each item to try to find it's device path.
00394     //
00395 
00396     for (PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)MainBuffer
00397       ;  PackageListHeader != NULL && ((CHAR8*)PackageListHeader) < (((CHAR8*)MainBuffer)+MainBufferSize)
00398       ;  PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) {
00399         for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER))
00400           ; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END
00401           ; PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageHeader))+PackageHeader->Length)) {
00402             if (PackageHeader->Type == EFI_HII_PACKAGE_DEVICE_PATH) {
00403               HiiHandle         = NULL;
00404               Status = FindHiiHandleViaDevPath((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), &HiiHandle, HiiDatabase);
00405               if (EFI_ERROR(Status)) {
00406                 //
00407                 // print out an error.
00408                 //
00409                 TempDevPathString = gDevPathToText->ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), TRUE, TRUE);
00410                 ShellPrintHiiEx(
00411                   -1, 
00412                   -1, 
00413                   NULL, 
00414                   STRING_TOKEN(STR_DRVCFG_IN_FILE_NF), 
00415                   gShellDriver1HiiHandle, 
00416                   TempDevPathString);
00417                 SHELL_FREE_NON_NULL(TempDevPathString);
00418              } else {
00419                 Status = HiiDatabase->UpdatePackageList(HiiDatabase, HiiHandle, PackageListHeader);
00420                 if (EFI_ERROR(Status)) {
00421                   ShellPrintHiiEx(
00422                     -1, 
00423                     -1, 
00424                     NULL, 
00425                     STRING_TOKEN(STR_GEN_UEFI_FUNC_ERROR), 
00426                     gShellDriver1HiiHandle, 
00427                     L"HiiDatabase->UpdatePackageList", 
00428                     Status);
00429                   return (SHELL_DEVICE_ERROR);
00430                 } else {
00431                   DevPath = (EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER));
00432                   gBS->LocateDevicePath(&gEfiHiiConfigAccessProtocolGuid, &DevPath, &Handle);
00433                   HandleIndex = ConvertHandleToHandleIndex(Handle);
00434                   ShellPrintHiiEx(
00435                     -1, 
00436                     -1, 
00437                     NULL, 
00438                     STRING_TOKEN(STR_DRVCFG_DONE_HII), 
00439                     gShellDriver1HiiHandle, 
00440                     HandleIndex);
00441                 }
00442               }              
00443             }
00444         }
00445     }
00446   }
00447 
00448   SHELL_FREE_NON_NULL(MainBuffer);
00449 
00450 
00451   ShellPrintHiiEx(
00452     -1, 
00453     -1,
00454     NULL,
00455     STRING_TOKEN(STR_DRVCFG_COMP), 
00456     gShellDriver1HiiHandle);
00457   return (SHELL_SUCCESS);
00458 }
00459 
00470 EFI_STATUS
00471 EFIAPI
00472 ShellCmdDriverConfigurationProcessActionRequired (
00473   EFI_HANDLE                                DriverImageHandle,
00474   EFI_HANDLE                                ControllerHandle,
00475   EFI_HANDLE                                ChildHandle,
00476   EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED  ActionRequired
00477   )
00478 {
00479   EFI_HANDLE  ConnectControllerContextOverride[2];
00480 
00481   switch (ActionRequired) {
00482   case EfiDriverConfigurationActionNone:
00483     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle);
00484     break;
00485 
00486   case EfiDriverConfigurationActionStopController:
00487     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_STOP), gShellDriver1HiiHandle);
00488     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"stop controller");
00489     ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL);
00490 
00491     gBS->DisconnectController (ControllerHandle, DriverImageHandle, ChildHandle);
00492     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_CTLR_S), gShellDriver1HiiHandle, L"stopped");
00493     break;
00494 
00495   case EfiDriverConfigurationActionRestartController:
00496     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_RESTART_S), gShellDriver1HiiHandle, L"controller");
00497     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"restart controller");
00498     ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL);
00499 
00500     gBS->DisconnectController (ControllerHandle, DriverImageHandle, ChildHandle);
00501     ConnectControllerContextOverride[0]  = DriverImageHandle;
00502     ConnectControllerContextOverride[1]  = NULL;
00503     gBS->ConnectController (ControllerHandle, ConnectControllerContextOverride, NULL, TRUE);
00504     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_CTLR_S), gShellDriver1HiiHandle, L"restarted");
00505     break;
00506 
00507   case EfiDriverConfigurationActionRestartPlatform:
00508     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_RESTART_S), gShellDriver1HiiHandle, L"platform");
00509     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"restart platform");
00510     ShellPromptForResponse(ShellPromptResponseTypeEnterContinue, NULL, NULL);
00511 
00512     gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
00513     break;
00514 
00515   default:
00516     return (EFI_INVALID_PARAMETER);
00517     break;
00518   }
00519 
00520   return EFI_SUCCESS;
00521 }
00522 
00539 SHELL_STATUS
00540 EFIAPI
00541 PreHiiDrvCfg (
00542   IN CONST CHAR8    *Language,
00543   IN BOOLEAN        ForceDefaults,
00544   IN UINT32         DefaultType,
00545   IN BOOLEAN        AllChildren,
00546   IN BOOLEAN        ValidateOptions,
00547   IN BOOLEAN        SetOptions,
00548   IN EFI_HANDLE     DriverImageHandle,
00549   IN EFI_HANDLE     DeviceHandle,
00550   IN EFI_HANDLE     ChildHandle
00551   )
00552 {
00553   EFI_STATUS                                Status;
00554   SHELL_STATUS                              ShellStatus;
00555   UINTN                                     OuterLoopCounter;
00556   CHAR8                                     *BestLanguage;
00557   UINTN                                     DriverImageHandleCount;
00558   EFI_HANDLE                                *DriverImageHandleBuffer;
00559   UINTN                                     HandleCount;
00560   EFI_HANDLE                                *HandleBuffer;
00561   UINTN                                     *HandleType;
00562   UINTN                                     LoopCounter;
00563   UINTN                                     ChildIndex;
00564   UINTN                                     ChildHandleCount;
00565   EFI_HANDLE                                *ChildHandleBuffer;
00566   UINTN                                     *ChildHandleType;
00567   EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED  ActionRequired;
00568   EFI_DRIVER_CONFIGURATION_PROTOCOL         *DriverConfiguration;
00569   BOOLEAN                                   Iso639Language;
00570   UINTN                                     HandleIndex1;
00571   UINTN                                     HandleIndex2;
00572   UINTN                                     HandleIndex3;
00573 
00574   ShellStatus = SHELL_SUCCESS;
00575 
00576   if (ChildHandle == NULL && AllChildren) {
00577     SetOptions = FALSE;
00578   }
00579 
00580   if (ForceDefaults) {
00581     ShellPrintHiiEx(
00582       -1,
00583       -1,
00584       NULL,
00585       STRING_TOKEN (STR_DRVCFG_FORCE_D), 
00586       gShellDriver1HiiHandle, 
00587       DefaultType);
00588   } else if (ValidateOptions) {
00589     ShellPrintHiiEx(
00590       -1,
00591       -1,
00592       NULL,
00593       STRING_TOKEN (STR_DRVCFG_VALIDATE), 
00594       gShellDriver1HiiHandle);
00595   } else if (SetOptions) {
00596     ShellPrintHiiEx(
00597       -1,
00598       -1,
00599       NULL,
00600       STRING_TOKEN (STR_DRVCFG_SET), 
00601       gShellDriver1HiiHandle);
00602   }
00603 
00604   if (DriverImageHandle == 0) {
00605     DriverImageHandleBuffer = GetHandleListByProtocolList(CfgGuidList);
00606     if (DriverImageHandleBuffer == NULL) {
00607       ShellStatus = SHELL_NOT_FOUND;
00608       goto Done;
00609     }
00610     for (
00611       HandleBuffer = DriverImageHandleBuffer, DriverImageHandleCount = 0 
00612       ; HandleBuffer != NULL && *HandleBuffer != NULL 
00613       ; HandleBuffer++,DriverImageHandleCount++);
00614   } else {
00615     DriverImageHandleCount = 1;
00616     //
00617     // Allocate buffer to hold the image handle so as to
00618     // keep consistent with the above clause
00619     //
00620     DriverImageHandleBuffer = AllocatePool (sizeof (EFI_HANDLE));
00621     ASSERT (DriverImageHandleBuffer);
00622     DriverImageHandleBuffer[0] = DriverImageHandle;
00623   }
00624 
00625   for (OuterLoopCounter = 0; OuterLoopCounter < DriverImageHandleCount; OuterLoopCounter++) {
00626     Iso639Language = FALSE;
00627     Status = gBS->OpenProtocol (
00628                   DriverImageHandleBuffer[OuterLoopCounter],
00629                   &gEfiDriverConfiguration2ProtocolGuid,
00630                   (VOID **) &DriverConfiguration,
00631                   NULL,
00632                   NULL,
00633                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
00634                   );
00635     if (EFI_ERROR (Status)) {
00636       Iso639Language = TRUE;
00637       Status = gBS->OpenProtocol (
00638                     DriverImageHandleBuffer[OuterLoopCounter],
00639                     &gEfiDriverConfigurationProtocolGuid,
00640                     (VOID **) &DriverConfiguration,
00641                     NULL,
00642                     NULL,
00643                     EFI_OPEN_PROTOCOL_GET_PROTOCOL
00644                     );
00645     }
00646     if (EFI_ERROR (Status)) {
00647 //      ShellPrintHiiEx(
00648 //        -1,
00649 //        -1,
00650 //        NULL,
00651 //        STRING_TOKEN (STR_DRVCFG_NOT_SUPPORT),
00652 //        gShellDriver1HiiHandle,
00653 //        ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter])
00654 //        );
00655       ShellStatus = SHELL_UNSUPPORTED;
00656       continue;
00657     }
00658     
00659     BestLanguage = GetBestLanguage (
00660                           DriverConfiguration->SupportedLanguages,
00661                           Iso639Language,
00662                           Language!=NULL?Language:"",
00663                           DriverConfiguration->SupportedLanguages,
00664                           NULL
00665                           );
00666     if (BestLanguage == NULL) {
00667       ShellPrintHiiEx(
00668         -1,
00669         -1,
00670         NULL,
00671         STRING_TOKEN (STR_GEN_PROBLEM_VAL),
00672         gShellDriver1HiiHandle,
00673         L"-l"
00674         );
00675       ShellStatus = SHELL_INVALID_PARAMETER;
00676       continue;
00677     }
00678 
00679     Status = ParseHandleDatabaseByRelationshipWithType (
00680               DriverImageHandleBuffer[OuterLoopCounter],
00681               NULL,
00682               &HandleCount,
00683               &HandleBuffer,
00684               &HandleType
00685               );
00686     if (EFI_ERROR (Status)) {
00687       continue;
00688     }
00689 
00690     if (SetOptions && DeviceHandle == NULL) {
00691 
00692       gST->ConOut->ClearScreen (gST->ConOut);
00693       Status = DriverConfiguration->SetOptions (
00694                                       DriverConfiguration,
00695                                       NULL,
00696                                       NULL,
00697                                       BestLanguage,
00698                                       &ActionRequired
00699                                       );
00700       gST->ConOut->ClearScreen (gST->ConOut);
00701 
00702       ShellPrintHiiEx(
00703         -1,
00704         -1,
00705         NULL,
00706         STRING_TOKEN (STR_DRVCFG_ALL_LANG),
00707         gShellDriver1HiiHandle,
00708         ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]),
00709         DriverConfiguration->SupportedLanguages
00710         );
00711       if (!EFI_ERROR (Status)) {
00712         ShellPrintHiiEx(
00713           -1,
00714           -1,
00715           NULL,
00716           STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), 
00717           gShellDriver1HiiHandle);
00718         for (LoopCounter = 0; LoopCounter < HandleCount; LoopCounter++) {
00719           if ((HandleType[LoopCounter] & HR_CONTROLLER_HANDLE) == HR_CONTROLLER_HANDLE) {
00720             ShellCmdDriverConfigurationProcessActionRequired (
00721               DriverImageHandleBuffer[OuterLoopCounter],
00722               HandleBuffer[LoopCounter],
00723               NULL,
00724               ActionRequired
00725               );
00726           }
00727         }
00728       } else {
00729         ShellPrintHiiEx(
00730           -1,
00731           -1,
00732           NULL,
00733           STRING_TOKEN (STR_DRVCFG_NOT_SET), 
00734           gShellDriver1HiiHandle, 
00735           Status);
00736       }
00737       continue;
00738     }
00739 
00740     for (LoopCounter = 0; LoopCounter < HandleCount; LoopCounter++) {
00741       if ((HandleType[LoopCounter] & HR_CONTROLLER_HANDLE) != HR_CONTROLLER_HANDLE) {
00742         continue;
00743       }
00744       if (DeviceHandle != NULL && DeviceHandle != HandleBuffer[LoopCounter]) {
00745         continue;
00746       }
00747       if (ChildHandle == NULL) {
00748         HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]);
00749         HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]);
00750         ShellPrintHiiEx(
00751           -1,
00752           -1,
00753           NULL,
00754           STRING_TOKEN (STR_DRVCFG_CTRL_LANG),
00755           gShellDriver1HiiHandle,
00756           HandleIndex1,
00757           HandleIndex2,
00758           DriverConfiguration->SupportedLanguages
00759           );
00760 
00761         if (ForceDefaults) {
00762           Status = DriverConfiguration->ForceDefaults (
00763                                           DriverConfiguration,
00764                                           HandleBuffer[LoopCounter],
00765                                           NULL,
00766                                           DefaultType,
00767                                           &ActionRequired
00768                                           );
00769 
00770           if (!EFI_ERROR (Status)) {
00771             ShellPrintHiiEx(
00772               -1,
00773               -1,
00774               NULL,
00775               STRING_TOKEN (STR_DRVCFG_DEF_FORCED), 
00776               gShellDriver1HiiHandle);
00777             ShellCmdDriverConfigurationProcessActionRequired (
00778               DriverImageHandleBuffer[OuterLoopCounter],
00779               HandleBuffer[LoopCounter],
00780               NULL,
00781               ActionRequired
00782               );
00783           } else {
00784             ShellPrintHiiEx(
00785               -1,
00786               -1,
00787               NULL,
00788               STRING_TOKEN (STR_DRVCFG_FORCE_FAILED), 
00789               gShellDriver1HiiHandle, 
00790               Status);
00791            ShellStatus = SHELL_DEVICE_ERROR;
00792          }
00793         } else if (ValidateOptions) {
00794           Status = DriverConfiguration->OptionsValid (
00795                                           DriverConfiguration,
00796                                           HandleBuffer[LoopCounter],
00797                                           NULL
00798                                           );
00799 
00800           if (!EFI_ERROR (Status)) {
00801             ShellPrintHiiEx(
00802               -1,
00803               -1,
00804               NULL,
00805               STRING_TOKEN (STR_DRVCFG_OPTIONS_VALID), 
00806               gShellDriver1HiiHandle);
00807           } else {
00808             ShellPrintHiiEx(
00809               -1,
00810               -1,
00811               NULL,
00812               STRING_TOKEN (STR_DRVCFG_OPTIONS_INV), 
00813               gShellDriver1HiiHandle, 
00814               Status);
00815             ShellStatus = SHELL_DEVICE_ERROR;
00816           }
00817         } else if (SetOptions) {
00818           gST->ConOut->ClearScreen (gST->ConOut);
00819           Status = DriverConfiguration->SetOptions (
00820                                           DriverConfiguration,
00821                                           HandleBuffer[LoopCounter],
00822                                           NULL,
00823                                           BestLanguage,
00824                                           &ActionRequired
00825                                           );
00826           gST->ConOut->ClearScreen (gST->ConOut);
00827           HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]);
00828           HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]);
00829           ShellPrintHiiEx(
00830             -1,
00831             -1,
00832             NULL,
00833             STRING_TOKEN (STR_DRVCFG_CTRL_LANG),
00834             gShellDriver1HiiHandle,
00835             HandleIndex1,
00836             HandleIndex2,
00837             DriverConfiguration->SupportedLanguages
00838             );
00839           if (!EFI_ERROR (Status)) {
00840             ShellPrintHiiEx(
00841               -1,
00842               -1,
00843               NULL,
00844               STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), 
00845               gShellDriver1HiiHandle);
00846 
00847             ShellCmdDriverConfigurationProcessActionRequired (
00848               DriverImageHandleBuffer[OuterLoopCounter],
00849               HandleBuffer[LoopCounter],
00850               NULL,
00851               ActionRequired
00852               );
00853 
00854           } else {
00855             ShellPrintHiiEx(
00856               -1,
00857               -1,
00858               NULL,
00859               STRING_TOKEN (STR_DRVCFG_NOT_SET), 
00860               gShellDriver1HiiHandle, 
00861               Status);
00862             ShellStatus = SHELL_DEVICE_ERROR;
00863           }
00864         } else {
00865           Print (L"\n");
00866         }
00867       }
00868 
00869       if (ChildHandle == NULL && !AllChildren) {
00870         continue;
00871       }
00872 
00873       Status = ParseHandleDatabaseByRelationshipWithType (
00874                 DriverImageHandleBuffer[OuterLoopCounter],
00875                 HandleBuffer[LoopCounter],
00876                 &ChildHandleCount,
00877                 &ChildHandleBuffer,
00878                 &ChildHandleType
00879                 );
00880       if (EFI_ERROR (Status)) {
00881         continue;
00882       }
00883 
00884       for (ChildIndex = 0; ChildIndex < ChildHandleCount; ChildIndex++) {
00885 
00886         if ((ChildHandleType[ChildIndex] & HR_CHILD_HANDLE) != HR_CHILD_HANDLE) {
00887           continue;
00888         }
00889 
00890         if (ChildHandle != NULL && ChildHandle != ChildHandleBuffer[ChildIndex]) {
00891           continue;
00892         }
00893 
00894         HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]);
00895         HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]);
00896         HandleIndex3 = ConvertHandleToHandleIndex (ChildHandleBuffer[ChildIndex]);
00897         ShellPrintHiiEx(
00898           -1,
00899           -1,
00900           NULL,
00901           STRING_TOKEN (STR_DRVCFG_CHILD_LANG),
00902           gShellDriver1HiiHandle,
00903           HandleIndex1,
00904           HandleIndex2,
00905           HandleIndex3,
00906           DriverConfiguration->SupportedLanguages);
00907 
00908         if (ForceDefaults) {
00909           Status = DriverConfiguration->ForceDefaults (
00910                                           DriverConfiguration,
00911                                           HandleBuffer[LoopCounter],
00912                                           ChildHandleBuffer[ChildIndex],
00913                                           DefaultType,
00914                                           &ActionRequired
00915                                           );
00916 
00917           if (!EFI_ERROR (Status)) {
00918             ShellPrintHiiEx(
00919               -1,
00920               -1,
00921               NULL,
00922               STRING_TOKEN (STR_DRVCFG_DEF_FORCED), 
00923               gShellDriver1HiiHandle);
00924 
00925             ShellCmdDriverConfigurationProcessActionRequired (
00926               DriverImageHandleBuffer[OuterLoopCounter],
00927               HandleBuffer[LoopCounter],
00928               ChildHandleBuffer[ChildIndex],
00929               ActionRequired
00930               );
00931 
00932           } else {
00933             ShellPrintHiiEx(
00934               -1,
00935               -1,
00936               NULL,
00937               STRING_TOKEN (STR_DRVCFG_FORCE_FAILED), 
00938               gShellDriver1HiiHandle, 
00939               Status);
00940             ShellStatus = SHELL_DEVICE_ERROR;
00941           }
00942         } else if (ValidateOptions) {
00943           Status = DriverConfiguration->OptionsValid (
00944                                           DriverConfiguration,
00945                                           HandleBuffer[LoopCounter],
00946                                           ChildHandleBuffer[ChildIndex]
00947                                           );
00948 
00949           if (!EFI_ERROR (Status)) {
00950             ShellPrintHiiEx(
00951               -1,
00952               -1,
00953               NULL,
00954               STRING_TOKEN (STR_DRVCFG_OPTIONS_VALID), 
00955               gShellDriver1HiiHandle);
00956           } else {
00957             ShellPrintHiiEx(
00958               -1,
00959               -1,
00960               NULL,
00961               STRING_TOKEN (STR_DRVCFG_OPTIONS_INV), 
00962               gShellDriver1HiiHandle, 
00963               Status);
00964             ShellStatus = SHELL_DEVICE_ERROR;
00965           }
00966         } else if (SetOptions) {
00967           gST->ConOut->ClearScreen (gST->ConOut);
00968           Status = DriverConfiguration->SetOptions (
00969                                           DriverConfiguration,
00970                                           HandleBuffer[LoopCounter],
00971                                           ChildHandleBuffer[ChildIndex],
00972                                           BestLanguage,
00973                                           &ActionRequired
00974                                           );
00975           gST->ConOut->ClearScreen (gST->ConOut);
00976           HandleIndex1 = ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter]);
00977           HandleIndex2 = ConvertHandleToHandleIndex (HandleBuffer[LoopCounter]);
00978           HandleIndex3 = ConvertHandleToHandleIndex (ChildHandleBuffer[ChildIndex]);
00979           ShellPrintHiiEx(
00980             -1,
00981             -1,
00982             NULL,
00983             STRING_TOKEN (STR_DRVCFG_CHILD_LANG),
00984             gShellDriver1HiiHandle,
00985             HandleIndex1,
00986             HandleIndex2,
00987             HandleIndex3,
00988             DriverConfiguration->SupportedLanguages
00989             );
00990           if (!EFI_ERROR (Status)) {
00991             ShellPrintHiiEx(
00992               -1,
00993               -1,
00994               NULL,
00995               STRING_TOKEN (STR_DRVCFG_OPTIONS_SET), 
00996               gShellDriver1HiiHandle);
00997 
00998             ShellCmdDriverConfigurationProcessActionRequired (
00999               DriverImageHandleBuffer[OuterLoopCounter],
01000               HandleBuffer[LoopCounter],
01001               ChildHandleBuffer[ChildIndex],
01002               ActionRequired
01003               );
01004 
01005           } else {
01006             ShellPrintHiiEx(
01007               -1,
01008               -1,
01009               NULL,
01010               STRING_TOKEN (STR_DRVCFG_NOT_SET), 
01011               gShellDriver1HiiHandle, 
01012               Status);
01013             ShellStatus = SHELL_DEVICE_ERROR;
01014           }
01015         } else {
01016           Print (L"\n");
01017         }
01018       }
01019 
01020       FreePool (ChildHandleBuffer);
01021       FreePool (ChildHandleType);
01022     }
01023 
01024     FreePool (BestLanguage);
01025     FreePool (HandleBuffer);
01026     FreePool (HandleType);
01027   }
01028 
01029   if (DriverImageHandle != NULL && DriverImageHandleCount != 0) {
01030     FreePool (DriverImageHandleBuffer);
01031   }
01032 
01033 Done:
01034   return ShellStatus;
01035 }
01036 
01046 SHELL_STATUS
01047 EFIAPI
01048 PrintConfigInfoOnAll(
01049   IN CONST BOOLEAN ChildrenToo,
01050   IN CONST CHAR8   *Language,
01051   IN CONST BOOLEAN UseHii
01052   )
01053 {
01054   EFI_HANDLE        *HandleList;
01055   EFI_HANDLE        *CurrentHandle;
01056   BOOLEAN           Found;
01057   UINTN             Index2;
01058 
01059 
01060   Found             = FALSE;
01061   HandleList        = NULL;
01062   CurrentHandle     = NULL;
01063 
01064   if (UseHii) {
01065     //
01066     // HII method
01067     //
01068     HandleList = GetHandleListByProtocol(&gEfiHiiConfigAccessProtocolGuid);
01069     for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL; CurrentHandle++){
01070       Found = TRUE;
01071       Index2 = *CurrentHandle == NULL ? 0 : ConvertHandleToHandleIndex(*CurrentHandle);
01072       ShellPrintHiiEx(
01073         -1, 
01074         -1, 
01075         NULL, 
01076         STRING_TOKEN (STR_DRVCFG_LINE_HII), 
01077         gShellDriver1HiiHandle, 
01078         Index2
01079         );
01080     }
01081     SHELL_FREE_NON_NULL(HandleList);
01082   }
01083 
01084   if (PreHiiDrvCfg (
01085     Language,
01086     FALSE,
01087     0,
01088     ChildrenToo,
01089     FALSE,
01090     FALSE,
01091     0,
01092     0,
01093     0) == SHELL_SUCCESS) {
01094       Found = TRUE;
01095   }
01096 
01097   if (!Found) {
01098     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle);
01099     return (SHELL_SUCCESS);
01100   }
01101 
01102   return (SHELL_SUCCESS);
01103 }
01104 
01105 STATIC CONST SHELL_PARAM_ITEM ParamListHii[] = {
01106   {L"-s", TypeFlag},
01107   {L"-l", TypeValue},
01108   {L"-f", TypeValue},
01109   {L"-o", TypeValue},
01110   {L"-i", TypeValue},
01111   {NULL, TypeMax}
01112   };
01113 STATIC CONST SHELL_PARAM_ITEM ParamListPreHii[] = {
01114   {L"-c", TypeFlag},
01115   {L"-s", TypeFlag},
01116   {L"-v", TypeFlag},
01117   {L"-l", TypeValue},
01118   {L"-f", TypeValue},
01119   {NULL, TypeMax}
01120   };
01121 
01128 SHELL_STATUS
01129 EFIAPI
01130 ShellCommandRunDrvCfg (
01131   IN EFI_HANDLE        ImageHandle,
01132   IN EFI_SYSTEM_TABLE  *SystemTable
01133   )
01134 {
01135   EFI_STATUS          Status;
01136   LIST_ENTRY          *Package;
01137   CHAR16              *ProblemParam;
01138   SHELL_STATUS        ShellStatus;
01139   CHAR8               *Language;
01140   CONST CHAR16        *Lang;
01141   CONST CHAR16        *HandleIndex1;
01142   CONST CHAR16        *HandleIndex2;
01143   CONST CHAR16        *HandleIndex3;
01144   CONST CHAR16        *ForceTypeString;
01145   BOOLEAN             Force;
01146   BOOLEAN             Set;
01147   BOOLEAN             Validate;
01148   BOOLEAN             InFromFile;
01149   BOOLEAN             OutToFile;
01150   BOOLEAN             AllChildren;
01151   BOOLEAN             UseHii;
01152   UINT32              ForceType;
01153   UINT64              Intermediate;
01154   EFI_HANDLE          Handle1;
01155   EFI_HANDLE          Handle2;
01156   EFI_HANDLE          Handle3;
01157   CONST CHAR16        *FileName;
01158 
01159   ShellStatus         = SHELL_SUCCESS;
01160   Status              = EFI_SUCCESS;
01161   Language            = NULL;
01162   UseHii              = TRUE;
01163 
01164   //
01165   // initialize the shell lib (we must be in non-auto-init...)
01166   //
01167   Status = ShellInitialize();
01168   ASSERT_EFI_ERROR(Status);
01169 
01170   Status = CommandInit();
01171   ASSERT_EFI_ERROR(Status);
01172 
01173   //
01174   // parse the command line
01175   //
01176   Status = ShellCommandLineParse (ParamListHii, &Package, &ProblemParam, TRUE);
01177   if (EFI_ERROR(Status) || ShellCommandLineGetCount(Package) > 2) {
01178     UseHii = FALSE;
01179     if (Package != NULL) {
01180       ShellCommandLineFreeVarList (Package);
01181     }
01182     SHELL_FREE_NON_NULL(ProblemParam);
01183     Status = ShellCommandLineParse (ParamListPreHii, &Package, &ProblemParam, TRUE);
01184     if (EFI_ERROR(Status)) {
01185       if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
01186         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
01187         FreePool(ProblemParam);
01188         ShellStatus = SHELL_INVALID_PARAMETER;
01189         goto Done;
01190       } else {
01191         ASSERT(FALSE);
01192       }
01193     }
01194   } 
01195   if (ShellStatus == SHELL_SUCCESS) {
01196     Lang = ShellCommandLineGetValue(Package, L"-l");
01197     if (Lang != NULL) {
01198       Language = AllocateZeroPool(StrSize(Lang));
01199       AsciiSPrint(Language, StrSize(Lang), "%S", Lang);
01200     } else if (ShellCommandLineGetFlag(Package, L"-l")){
01201       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l");
01202       ShellStatus = SHELL_INVALID_PARAMETER;
01203       goto Done;
01204     }
01205     Set                 = ShellCommandLineGetFlag (Package, L"-s");
01206     Validate            = ShellCommandLineGetFlag (Package, L"-v");
01207     InFromFile          = ShellCommandLineGetFlag (Package, L"-i");
01208     OutToFile           = ShellCommandLineGetFlag (Package, L"-o");
01209     AllChildren         = ShellCommandLineGetFlag (Package, L"-c");
01210     Force               = ShellCommandLineGetFlag (Package, L"-f");
01211     ForceTypeString     = ShellCommandLineGetValue(Package, L"-f");
01212 
01213     if (OutToFile) {
01214       FileName = ShellCommandLineGetValue(Package, L"-o");
01215     } else if (InFromFile) {
01216       FileName = ShellCommandLineGetValue(Package, L"-i");
01217     } else {
01218       FileName = NULL;
01219     }
01220 
01221     if (InFromFile && EFI_ERROR(ShellFileExists(FileName))) {
01222       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FIND_FAIL), gShellDriver1HiiHandle, FileName);
01223       ShellStatus = SHELL_INVALID_PARAMETER;
01224       goto Done;      
01225     }
01226     if (OutToFile && !EFI_ERROR(ShellFileExists(FileName))) {
01227       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_EXIST), gShellDriver1HiiHandle, FileName);
01228       ShellStatus = SHELL_INVALID_PARAMETER;
01229       goto Done;      
01230     }
01231     if (Force && ForceTypeString == NULL) {
01232       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-f");
01233       ShellStatus = SHELL_INVALID_PARAMETER;
01234       goto Done;
01235     } 
01236     if (Force) {
01237       Status = ShellConvertStringToUint64(ForceTypeString, &Intermediate, FALSE, FALSE);
01238       if (EFI_ERROR(Status)) {
01239         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDriver1HiiHandle, L"-f");
01240         ShellStatus = SHELL_INVALID_PARAMETER;
01241         goto Done;
01242       }
01243       ForceType = (UINT32)Intermediate;
01244     } else {
01245       ForceType = 0;
01246     }
01247     HandleIndex1        = ShellCommandLineGetRawValue(Package, 1);
01248     Handle1             = NULL;
01249     if (HandleIndex1 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex1, &Intermediate, TRUE, FALSE))) {
01250       Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate);
01251       if (Handle1 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) {
01252         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex1);
01253         ShellStatus = SHELL_INVALID_PARAMETER;
01254         goto Done;
01255       }
01256     }
01257     HandleIndex2        = ShellCommandLineGetRawValue(Package, 2);
01258     Handle2             = NULL;
01259     if (HandleIndex2 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex2, &Intermediate, TRUE, FALSE))) {
01260       Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate);
01261       if (Handle2 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) {
01262         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex2);
01263         ShellStatus = SHELL_INVALID_PARAMETER;
01264         goto Done;
01265       }
01266     }
01267     HandleIndex3        = ShellCommandLineGetRawValue(Package, 3);
01268     Handle3             = NULL;
01269     if (HandleIndex3 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex3, &Intermediate, TRUE, FALSE))) {
01270       Handle3 = ConvertHandleIndexToHandle((UINTN)Intermediate);
01271       if (Handle3 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) {
01272         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex3);
01273         ShellStatus = SHELL_INVALID_PARAMETER;
01274         goto Done;
01275       }
01276     }
01277 
01278     if ((InFromFile || OutToFile) && (FileName == NULL)) {
01279       if (FileName == NULL) {
01280         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, InFromFile?L"-i":L"-o");
01281       } else {
01282         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_REQ), gShellDriver1HiiHandle);
01283       }
01284       ShellStatus = SHELL_INVALID_PARAMETER;
01285       goto Done;
01286     }
01287     if (!UseHii && (InFromFile || OutToFile)) {
01288       if (InFromFile) {
01289         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"-i");
01290         ShellStatus = SHELL_INVALID_PARAMETER;
01291         goto Done;
01292       } 
01293       if (OutToFile) {
01294         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"-o");
01295         ShellStatus = SHELL_INVALID_PARAMETER;
01296         goto Done;
01297       }
01298     }
01299     if (Validate && Force) {
01300       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-v", L"-f");
01301       ShellStatus = SHELL_INVALID_PARAMETER;
01302       goto Done;
01303     } 
01304     if (Validate && Set) {
01305       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-v", L"-s");
01306       ShellStatus = SHELL_INVALID_PARAMETER;
01307       goto Done;
01308     } 
01309     if (Set && Force) {
01310       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-s", L"-f");
01311       ShellStatus = SHELL_INVALID_PARAMETER;
01312       goto Done;
01313     }
01314     if (OutToFile && InFromFile) {
01315       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-i", L"-o");
01316       ShellStatus = SHELL_INVALID_PARAMETER;
01317       goto Done;
01318     }
01319 
01320     //
01321     // We do HII first.
01322     //
01323     if (UseHii) {
01324       if (Handle1 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
01325         //
01326         // no HII on this handle.
01327         //
01328         ShellStatus = SHELL_UNSUPPORTED;
01329       } else if (Validate) {
01330       } else if (Force) {
01331       } else if (Set) {
01332       } else if (InFromFile) {
01333         ShellStatus = ConfigFromFile(Handle1, FileName);
01334         if (Handle1 != NULL && ShellStatus == SHELL_SUCCESS) {
01335           goto Done;
01336         }
01337       } else if (OutToFile) {
01338         ShellStatus = ConfigToFile(Handle1, FileName);
01339         if (Handle1 != NULL && ShellStatus == SHELL_SUCCESS) {
01340           goto Done;
01341         }
01342       } else if (HandleIndex1 == NULL) {
01343         //
01344         // display all that are configurable
01345         //
01346         ShellStatus = PrintConfigInfoOnAll(AllChildren, Language, UseHii);
01347         goto Done;
01348       } else {
01349         if (!EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
01350           ShellPrintHiiEx(
01351             -1, 
01352             -1, 
01353             NULL, 
01354             STRING_TOKEN (STR_DRVCFG_LINE_HII), 
01355             gShellDriver1HiiHandle, 
01356             ConvertHandleToHandleIndex(Handle1)
01357             );
01358           goto Done;
01359         }
01360       }
01361     }
01362 
01363     //
01364     // We allways need to do this one since it does both by default.
01365     //
01366     if (!InFromFile && !OutToFile) {
01367       ShellStatus = PreHiiDrvCfg (
01368         Language,
01369         Force,
01370         ForceType,
01371         AllChildren,
01372         Validate,
01373         Set,
01374         Handle1,
01375         Handle2,
01376         Handle3);
01377     }
01378 
01379     if (ShellStatus == SHELL_UNSUPPORTED) {
01380       ShellPrintHiiEx(
01381         -1,
01382         -1,
01383         NULL,
01384         STRING_TOKEN (STR_DRVCFG_NOT_SUPPORT),
01385         gShellDriver1HiiHandle, 
01386         ConvertHandleToHandleIndex(Handle1)
01387         );
01388     }
01389   }
01390 
01391 Done:
01392   ShellCommandLineFreeVarList (Package);
01393   SHELL_FREE_NON_NULL(Language);
01394   return (ShellStatus);
01395 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines