/** @file
Main file for bcfg shell Install1 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 "UefiShellInstall1CommandsLib.h"
#include <Guid/GlobalVariable.h>
#include <Library/PrintLib.h>
#include <Library/HandleParsingLib.h>
#include <Library/DevicePathLib.h>
typedef enum {
BcfgTargetBootOrder = 0,
typedef enum {
BcfgTypeDump = 0,
typedef struct {
/**
This function will populate the device path protocol parameter based on TheHandle.
@param[in] TheHandle Driver handle.
@param[in, out] FilePath On a sucessful return the device path to the handle.
@retval EFI_SUCCESS The device path was sucessfully returned.
@retval other A error from gBS->HandleProtocol.
@sa HandleProtocol
**/
)
{
(VOID**)&LoadedImage,
NULL,
);
(VOID**)&ImageDevicePath,
NULL,
);
// *DevPath = DuplicateDevicePath (ImageDevicePath);
// *FilePath = DuplicateDevicePath (LoadedImage->FilePath);
NULL);
}
NULL);
}
return (Status);
}
/**
Function to add a option.
@param[in] Position The position to add Target at.
@param[in] File The file to make the target.
@param[in] Desc The description text.
@param[in] CurrentOrder The pointer to the current order of items.
@param[in] OrderCount The number if items in CurrentOrder.
@param[in] Target The info on the option to add.
@param[in] UseHandle TRUE to use HandleNumber, FALSE to use File and Desc.
@param[in] UsePath TRUE to convert to devicepath.
@param[in] HandleNumber The handle number to add.
@retval SHELL_SUCCESS The operation was successful.
@retval SHELL_INVALID_PARAMETER A parameter was invalid.
**/
)
{
// EFI_DEVICE_PATH_PROTOCOL *DevPath;
// CONST CHAR16 *StringWalker;
if (!UseHandle) {
return (SHELL_INVALID_PARAMETER);
}
} else {
if (HandleNumber == 0) {
return (SHELL_INVALID_PARAMETER);
}
}
if (Position > OrderCount) {
}
TargetLocation = 0xFFFF;
if (UseHandle) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, L"Handle Number");
} else {
if (Target == BcfgTargetBootOrder) {
//
//Make sure that the handle should point to a real controller
//
NULL);
NULL);
NULL);
if (DriverBindingHandleCount > 0
|| ParentControllerHandleCount > 0
|| ChildControllerHandleCount > 0) {
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_HANDLE), gShellInstall1HiiHandle, HandleNumber);
}
} else {
//
//Make sure that the handle should point to driver, not a controller.
//
NULL);
NULL);
NULL);
if (DriverBindingHandleCount > 0
|| ParentControllerHandleCount > 0
|| ChildControllerHandleCount > 0
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, L"Handle Number");
} else {
//
// Get the DevicePath from the loaded image information.
//
}
}
}
} else {
//
// Get file info
//
//
// If filename matched nothing fail
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellInstall1HiiHandle, File);
//
// If filename expanded to multiple names, fail
//
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_OPEN), gShellInstall1HiiHandle, File, Arg->Status);
} else {
//
// Build FilePath to the filename
//
//
// get the device path
//
if (DevicePath == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellInstall1HiiHandle, Arg->FullName);
} else {
/*
if (UsePath) {
DevPath = DevicePath;
while (!IsDevicePathEnd(DevPath)) {
if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&
(DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {
//
// If we find it use it instead
//
DevicePath = DevPath;
break;
}
DevPath = NextDevicePathNode(DevPath);
}
//
// append the file
//
for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);
FileNode = FileDevicePath(NULL, StringWalker+1);
FilePath = AppendDevicePath(DevicePath, FileNode);
FreePool(FileNode);
} else {
*/
/*
}
*/
}
}
}
}
if (ShellStatus == SHELL_SUCCESS) {
//
// Find a free target ,a brute force implementation
//
break;
}
}
if (Found) {
break;
}
}
if (TargetLocation == 0xFFFF) {
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_TARGET), gShellInstall1HiiHandle, TargetLocation);
}
}
if (ShellStatus == SHELL_SUCCESS) {
//
// Add the option
//
if (TempByteBuffer != NULL) {
TempByteBuffer += sizeof (UINT32);
TempByteBuffer += sizeof (UINT16);
UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation);
);
} else {
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellInstall1HiiHandle, OptionStr, Status);
} else {
//
// Insert target into order list
//
}
);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellInstall1HiiHandle, Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder", Status);
} else {
}
}
}
//
//If always Free FilePath, will free devicepath in system when use "addh"
//
}
}
}
}
return (ShellStatus);
}
/**
Funciton to remove an item.
@param[in] Target The target item to move.
@param[in] CurrentOrder The pointer to the current order of items.
@param[in] OrderCount The number if items in CurrentOrder.
@param[in] Location The current location of the Target.
@retval SHELL_SUCCESS The operation was successful.
@retval SHELL_INVALID_PARAMETER A parameter was invalid.
**/
)
{
UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", CurrentOrder[Location]);
0,
NULL);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellInstall1HiiHandle, VariableName, Status);
return (SHELL_INVALID_PARAMETER);
}
CopyMem(NewOrder+Location, NewOrder+Location+1, (OrderCount - Location - 1)*sizeof(CurrentOrder[0]));
NewCount--;
NewOrder);
} else {
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellInstall1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);
return (SHELL_INVALID_PARAMETER);
}
return (SHELL_SUCCESS);
}
/**
Funciton to move a item to another location.
@param[in] Target The target item to move.
@param[in] CurrentOrder The pointer to the current order of items.
@param[in] OrderCount The number if items in CurrentOrder.
@param[in] OldLocation The current location of the Target.
@param[in] NewLocation The desired location of the Target.
@retval SHELL_SUCCESS The operation was successful.
@retval SHELL_INVALID_PARAMETER A parameter was invalid.
**/
)
{
CopyMem(NewOrder+OldLocation, NewOrder+OldLocation+1, (OrderCount - OldLocation - 1)*sizeof(CurrentOrder[0]));
CopyMem(NewOrder+NewLocation+1, NewOrder+NewLocation, (OrderCount - NewLocation - 1)*sizeof(CurrentOrder[0]));
OrderCount*sizeof(CurrentOrder[0]),
NewOrder);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellInstall1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);
return (SHELL_INVALID_PARAMETER);
}
return (SHELL_SUCCESS);
}
/**
Function to add optional data to an option.
@param[in] OptData The optional data to add.
@param[in] Target The target of the operation.
@retval SHELL_SUCCESS The operation was succesful.
**/
)
{
return SHELL_SUCCESS;
}
/**
Function to dump the Bcfg information.
@param[in] Op The operation.
@param[in] OrderCount How many to dump.
@param[in] CurrentOrder The pointer to the current order of items.
@param[in] VerboseOutput TRUE for extra output. FALSE otherwise.
@retval SHELL_SUCCESS The dump was successful.
@retval SHELL_INVALID_PARAMETER A parameter was invalid.
**/
)
{
if (OrderCount == 0) {
return (SHELL_SUCCESS);
}
BufferSize = 0;
NULL,
Buffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
NULL,
Buffer);
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_READ_FAIL), gShellInstall1HiiHandle, VariableName, Status);
return (SHELL_INVALID_PARAMETER);
}
} else {
}
-1,
-1,
NULL,
if (VerboseOutput) {
for (LoopVar2 = (StrSize((CHAR16*)(Buffer+6)) + *(UINT16*)(Buffer+4) + 6);LoopVar2<BufferSize;LoopVar2++){
-1,
-1,
NULL,
L"%02x",
}
-1,
-1,
NULL,
L"\r\n");
}
}
}
if (DevPathString != NULL) {
}
}
return (SHELL_SUCCESS);
}
/**
Function to initialize the BCFG operation structure.
@param[in] Struct The stuct to initialize.
**/
)
{
Struct->HandleIndex = 0;
}
{L"-v", TypeFlag},
{L"-opt", TypeMaxValue},
};
/**
Function for 'bcfg' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
)
{
Length = 0;
ProblemParam = NULL;
//
// 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), gShellInstall1HiiHandle, ProblemParam);
} else {
}
} else {
//
// Read in if we are doing -OPT
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellInstall1HiiHandle, L"-opt");
}
}
//
// small block to read the target of the operation
//
){
} else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)ShellCommandLineGetRawValue(Package, 1), L"driver") == 0) {
} else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)ShellCommandLineGetRawValue(Package, 1), L"boot") == 0) {
} else {
}
//
// Read in the boot or driver order environment variable (not needed for opt)
//
if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax && CurrentOperation.Type != BcfgTypeOpt) {
Length = 0;
NULL,
&Length,
if (Status == EFI_BUFFER_TOO_SMALL) {
NULL,
&Length,
}
}
//
// large block to read the type of operation and verify parameter types for the info.
//
for (ParamNumber = 2 ; ParamNumber < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS; ParamNumber++) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, L"-v (without dump)");
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, CurrentParam);
} else {
CurrentOperation.FileName = StrnCatGrow(&CurrentOperation.FileName , NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);
CurrentOperation.Description = StrnCatGrow(&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, CurrentParam);
} else {
CurrentOperation.FileName = StrnCatGrow(&CurrentOperation.FileName , NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);
CurrentOperation.Description = StrnCatGrow(&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, CurrentParam);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, CurrentParam);
} else {
CurrentOperation.Description = StrnCatGrow(&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);
}
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, CurrentParam);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellInstall1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
}
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, CurrentParam);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellInstall1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, CurrentParam);
} else {
}
){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellInstall1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
}
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellInstall1HiiHandle, CurrentParam);
}
}
}
if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax && CurrentOperation.Type < BcfgTypeMax) {
//
// we have all the info. Do the work
//
switch (CurrentOperation.Type) {
case BcfgTypeDump:
break;
case BcfgTypeMv:
break;
case BcfgTypeRm:
break;
case BcfgTypeAdd:
case BcfgTypeAddp:
case BcfgTypeAddh:
break;
case BcfgTypeOpt:
break;
default:
}
}
}
}
}
}
}
return (ShellStatus);
}