/** @file
Main file for DrvCfg shell Driver1 function.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "UefiShellDriver1CommandsLib.h"
#include <Protocol/HiiConfigAccess.h>
#include <Protocol/HiiDatabase.h>
STATIC CONST EFI_GUID *CfgGuidList[] = {&gEfiDriverConfigurationProtocolGuid, &gEfiDriverConfiguration2ProtocolGuid, NULL};
/**
Find the EFI_HII_HANDLE by device path.
@param[in] DevPath1 The Device Path to match.
@param[out] HiiHandle The EFI_HII_HANDLE after the converstion.
@param[in] HiiDb The Hii database protocol
@retval EFI_SUCCESS The operation was successful.
@retval EFI_NOT_FOUND There was no EFI_HII_HANDLE found for that deviec path.
**/
)
{
HandleBufferSize = 0;
HandleBuffer = NULL;
Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
Status = HiiDb->ListPackageLists(HiiDb, EFI_HII_PACKAGE_DEVICE_PATH, NULL, &HandleBufferSize, HandleBuffer);
}
return (Status);
}
if (HandleBuffer == NULL) {
return EFI_NOT_FOUND;
}
for (LoopVariable = 0 ; LoopVariable < (HandleBufferSize/sizeof(HandleBuffer[0])) && *HiiHandle == NULL ; LoopVariable++) {
MainBufferSize = 0;
MainBuffer = NULL;
if (Status == EFI_BUFFER_TOO_SMALL) {
}
//
// Enumerate through the block of returned memory.
// This should actually be a small block, but we need to be sure.
//
; PackageListHeader != NULL && ((CHAR8*)PackageListHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && *HiiHandle == NULL
; PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) {
for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER))
; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END && *HiiHandle == NULL
break;
}
}
}
}
}
return (EFI_NOT_FOUND);
}
return (EFI_SUCCESS);
}
/**
Convert a EFI_HANDLE to a EFI_HII_HANDLE.
@param[in] Handle The EFI_HANDLE to convert.
@param[out] HiiHandle The EFI_HII_HANDLE after the converstion.
@param[in] HiiDb The Hii database protocol
@retval EFI_SUCCESS The operation was successful.
**/
)
{
return (EFI_INVALID_PARAMETER);
}
return (EFI_SUCCESS);
}
Status = gBS->OpenProtocol(Handle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath1, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
return (EFI_NOT_FOUND);
}
}
/**
Function to print out all HII configuration information to a file.
@param[in] Handle The handle to get info on. NULL to do all handles.
@param[in] FileName The filename to rwite the info to.
**/
)
{
HiiDatabase = NULL;
MainBufferSize = 0;
MainBuffer = NULL;
FileHandle = NULL;
Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
-1,
-1,
NULL,
Status);
return (SHELL_DEVICE_ERROR);
}
//
// Locate HII Database protocol
//
NULL,
(VOID **) &HiiDatabase
);
-1,
-1,
NULL,
L"EfiHiiDatabaseProtocol",
return (SHELL_NOT_FOUND);
}
-1,
-1,
NULL,
L"Device");
return (SHELL_DEVICE_ERROR);
}
if (Status == EFI_BUFFER_TOO_SMALL) {
}
-1,
-1,
NULL,
Status);
return (SHELL_DEVICE_ERROR);
}
-1,
-1,
NULL,
return (SHELL_SUCCESS);
}
/**
Function to read in HII configuration information from a file.
@param[in] Handle The handle to get info for.
@param[in] FileName The filename to read the info from.
**/
)
{
HiiDatabase = NULL;
MainBufferSize = 0;
MainBuffer = NULL;
FileHandle = NULL;
-1,
-1,
NULL,
Status);
return (SHELL_DEVICE_ERROR);
}
//
// Locate HII Database protocol
//
NULL,
(VOID **) &HiiDatabase
);
-1,
-1,
NULL,
L"EfiHiiDatabaseProtocol",
return (SHELL_NOT_FOUND);
}
-1,
-1,
NULL,
Status);
return (SHELL_DEVICE_ERROR);
}
-1,
-1,
NULL,
return (SHELL_DEVICE_ERROR);
}
-1,
-1,
NULL,
Status);
return (SHELL_DEVICE_ERROR);
}
//
// User override in place. Just do it.
//
-1,
-1,
NULL,
L"Device");
return (SHELL_DEVICE_ERROR);
}
-1,
-1,
NULL,
L"HiiDatabase->UpdatePackageList",
Status);
return (SHELL_DEVICE_ERROR);
}
} else {
//
// we need to parse the buffer and try to match the device paths for each item to try to find it's device path.
//
; PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) {
for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER))
; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END
Status = FindHiiHandleViaDevPath((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), &HiiHandle, HiiDatabase);
//
// print out an error.
//
TempDevPathString = gDevPathToText->ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), TRUE, TRUE);
-1,
-1,
NULL,
} else {
-1,
-1,
NULL,
L"HiiDatabase->UpdatePackageList",
Status);
return (SHELL_DEVICE_ERROR);
} else {
-1,
-1,
NULL,
}
}
}
}
}
}
-1,
-1,
NULL,
return (SHELL_SUCCESS);
}
/**
Present a requested action to the user.
@param[in] DriverImageHandle The handle for the driver to configure.
@param[in] ControllerHandle The handle of the device being managed by the Driver specified.
@param[in] ChildHandle The handle of a child device of the specified device.
@param[in] ActionRequired The required HII action.
@retval SHELL_INVALID_PARAMETER A parameter has a invalid value.
**/
)
{
switch (ActionRequired) {
break;
ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"stop controller");
break;
ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_RESTART_S), gShellDriver1HiiHandle, L"controller");
ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"restart controller");
break;
ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_RESTART_S), gShellDriver1HiiHandle, L"platform");
ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_DRVCFG_ENTER_S), gShellDriver1HiiHandle, L"restart platform");
break;
default:
return (EFI_INVALID_PARAMETER);
break;
}
return EFI_SUCCESS;
}
/**
Do the configuration in an environment without HII.
@param[in] Language The language code.
@param[in] ForceDefaults TRUE to force defaults, FALSE otherwise.
@param[in] DefaultType If ForceDefaults is TRUE, specifies the default type.
@param[in] AllChildren TRUE to configure all children, FALSE otherwise.
@param[in] ValidateOptions TRUE to validate existing options, FALSE otherwise.
@param[in] SetOptions TRUE to set options, FALSE otherwise.
@param[in] DriverImageHandle The handle for the driver to configure.
@param[in] DeviceHandle The handle of the device being managed by the Driver specified.
@param[in] ChildHandle The handle of a child device of the specified device.
@retval SHELL_NOT_FOUND A specified handle could not be found.
@retval SHELL_INVALID_PARAMETER A parameter has a invalid value.
**/
)
{
SetOptions = FALSE;
}
if (ForceDefaults) {
-1,
-1,
NULL,
} else if (ValidateOptions) {
-1,
-1,
NULL,
} else if (SetOptions) {
-1,
-1,
NULL,
}
if (DriverImageHandle == 0) {
if (DriverImageHandleBuffer == NULL) {
goto Done;
}
for (
; HandleBuffer++,DriverImageHandleCount++);
} else {
//
// Allocate buffer to hold the image handle so as to
// keep consistent with the above clause
//
}
(VOID **) &DriverConfiguration,
NULL,
NULL,
);
(VOID **) &DriverConfiguration,
NULL,
NULL,
);
}
// ShellPrintHiiEx(
// -1,
// -1,
// NULL,
// STRING_TOKEN (STR_DRVCFG_NOT_SUPPORT),
// gShellDriver1HiiHandle,
// ConvertHandleToHandleIndex (DriverImageHandleBuffer[OuterLoopCounter])
// );
continue;
}
);
if (BestLanguage == NULL) {
-1,
-1,
NULL,
L"-l"
);
continue;
}
NULL,
);
continue;
}
NULL,
NULL,
);
-1,
-1,
NULL,
);
-1,
-1,
NULL,
NULL,
);
}
}
} else {
-1,
-1,
NULL,
Status);
}
continue;
}
continue;
}
continue;
}
if (ChildHandle == NULL) {
-1,
-1,
NULL,
);
if (ForceDefaults) {
NULL,
);
-1,
-1,
NULL,
NULL,
);
} else {
-1,
-1,
NULL,
Status);
}
} else if (ValidateOptions) {
);
-1,
-1,
NULL,
} else {
-1,
-1,
NULL,
Status);
}
} else if (SetOptions) {
NULL,
);
-1,
-1,
NULL,
);
-1,
-1,
NULL,
NULL,
);
} else {
-1,
-1,
NULL,
Status);
}
} else {
Print (L"\n");
}
}
continue;
}
);
continue;
}
continue;
}
continue;
}
-1,
-1,
NULL,
if (ForceDefaults) {
);
-1,
-1,
NULL,
);
} else {
-1,
-1,
NULL,
Status);
}
} else if (ValidateOptions) {
);
-1,
-1,
NULL,
} else {
-1,
-1,
NULL,
Status);
}
} else if (SetOptions) {
);
-1,
-1,
NULL,
);
-1,
-1,
NULL,
);
} else {
-1,
-1,
NULL,
Status);
}
} else {
Print (L"\n");
}
}
}
}
}
Done:
return ShellStatus;
}
/**
Function to print out configuration information on all configurable handles.
@param[in] ChildrenToo TRUE to tewst for children.
@param[in] Language ASCII string for language code.
@param[in] UseHii TRUE to check for Hii and DPC, FALSE for DCP only.
@retval SHELL_SUCCESS The operation was successful.
**/
)
{
HandleList = NULL;
if (UseHii) {
//
// HII method
//
for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL; CurrentHandle++){
-1,
-1,
NULL,
);
}
}
if (PreHiiDrvCfg (
0,
0,
0,
0) == SHELL_SUCCESS) {
}
if (!Found) {
return (SHELL_SUCCESS);
}
return (SHELL_SUCCESS);
}
{L"-s", TypeFlag},
{L"-l", TypeValue},
{L"-f", TypeValue},
{L"-o", TypeValue},
{L"-i", TypeValue},
};
{L"-c", TypeFlag},
{L"-s", TypeFlag},
{L"-v", TypeFlag},
{L"-l", TypeValue},
{L"-f", TypeValue},
};
/**
Function for 'drvcfg' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
)
{
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
Status = CommandInit();
//
// parse the command line
//
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
goto Done;
} else {
}
}
}
if (ShellStatus == SHELL_SUCCESS) {
goto Done;
}
if (OutToFile) {
} else if (InFromFile) {
} else {
}
goto Done;
}
goto Done;
}
goto Done;
}
if (Force) {
goto Done;
}
} else {
ForceType = 0;
}
if (HandleIndex1 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex1, &Intermediate, TRUE, FALSE))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex1);
goto Done;
}
}
if (HandleIndex2 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex2, &Intermediate, TRUE, FALSE))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex2);
goto Done;
}
}
if (HandleIndex3 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex3, &Intermediate, TRUE, FALSE))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex3);
goto Done;
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, InFromFile?L"-i":L"-o");
} else {
}
goto Done;
}
if (InFromFile) {
goto Done;
}
if (OutToFile) {
goto Done;
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-v", L"-f");
goto Done;
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-v", L"-s");
goto Done;
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-s", L"-f");
goto Done;
}
if (OutToFile && InFromFile) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-i", L"-o");
goto Done;
}
//
// We do HII first.
//
if (UseHii) {
if (Handle1 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
//
// no HII on this handle.
//
} else if (Validate) {
} else if (Force) {
} else if (Set) {
} else if (InFromFile) {
goto Done;
}
} else if (OutToFile) {
goto Done;
}
} else if (HandleIndex1 == NULL) {
//
// display all that are configurable
//
goto Done;
} else {
if (!EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
-1,
-1,
NULL,
);
goto Done;
}
}
}
//
// We allways need to do this one since it does both by default.
//
if (!InFromFile && !OutToFile) {
Set,
Handle3);
}
if (ShellStatus == SHELL_UNSUPPORTED) {
-1,
-1,
NULL,
);
}
}
Done:
return (ShellStatus);
}