diff options
Diffstat (limited to 'ShellPkg')
23 files changed, 2452 insertions, 1746 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c index 4c2eb3c1a8..73e8c57637 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c @@ -1,7 +1,7 @@ /** @file
- Main file for bcfg shell install1 function.
+ Main file for bcfg shell Debug1 function.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -19,20 +19,20 @@ #include <Library/DevicePathLib.h>
typedef enum {
- BCFG_TARGET_BOOT_ORDER = 0,
- BCFG_TARGET_DRIVER_ORDER = 1,
- BCFG_TARGET_MAX = 2
+ BcfgTargetBootOrder = 0,
+ BcfgTargetDriverOrder = 1,
+ BcfgTargetMax = 2
} BCFG_OPERATION_TARGET;
typedef enum {
- BCFG_TYPE_DUMP = 0,
- BCFG_TYPE_ADD = 1,
- BCFG_TYPE_ADDP = 2,
- BCFG_TYPE_ADDH = 3,
- BCFG_TYPE_RM = 4,
- BCFG_TYPE_MV = 5,
- BCFG_TYPE_OPT = 6,
- BCFG_TYPE_MAX = 7
+ BcfgTypeDump = 0,
+ BcfgTypeAdd = 1,
+ BcfgTypeAddp = 2,
+ BcfgTypeAddh = 3,
+ BcfgTypeRm = 4,
+ BcfgTypeMv = 5,
+ BcfgTypeOpt = 6,
+ BcfgTypeMax = 7
} BCFG_OPERATION_TYPE;
typedef struct {
@@ -47,9 +47,25 @@ typedef struct { CONST CHAR16 *OptData;
} BGFG_OPERATION;
+/**
+ 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.
+**/
SHELL_STATUS
EFIAPI
-BcfgAdd (
+BcfgAddDebug1(
IN UINTN Position,
IN CONST CHAR16 *File,
IN CONST CHAR16 *Desc,
@@ -62,10 +78,14 @@ BcfgAdd ( )
{
EFI_STATUS Status;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath, *FilePath, *FileNode, *DevPath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *FilePath;
+ EFI_DEVICE_PATH_PROTOCOL *FileNode;
+ EFI_DEVICE_PATH_PROTOCOL *DevPath;
CHAR16 *Str;
- CONST CHAR16 *p;
- UINT8 *p8;
+ CONST CHAR16 *StringWalker;
+ UINT8 *TempByteBuffer;
+ UINT8 *TempByteStart;
EFI_SHELL_FILE_INFO *Arg;
EFI_SHELL_FILE_INFO *FileList;
CHAR16 OptionStr[40];
@@ -80,15 +100,21 @@ BcfgAdd ( UINTN ChildControllerHandleCount;
SHELL_STATUS ShellStatus;
UINT16 *NewOrder;
+ UINT64 Intermediate;
if (!UseHandle) {
- ASSERT(File != NULL);
- ASSERT(Desc != NULL);
+ if (File == NULL || Desc == NULL) {
+ return (SHELL_INVALID_PARAMETER);
+ }
} else {
- ASSERT(HandleNumber != 0);
+ if (HandleNumber == 0) {
+ return (SHELL_INVALID_PARAMETER);
+ }
}
- ASSERT(Position <= (OrderCount+1));
+ if (Position > OrderCount) {
+ Position = OrderCount;
+ }
Str = NULL;
FilePath = NULL;
@@ -98,13 +124,10 @@ BcfgAdd ( ShellStatus = SHELL_SUCCESS;
TargetLocation = 0xFFFF;
-// if (Position > 0) {
-// Position--;
-// }
-
if (UseHandle) {
- CurHandle = ConvertHandleIndexToHandle(StrHexToUintn(File));
- if (CurHandle == NULL) {
+ Status = ShellConvertStringToUint64(File, &Intermediate, TRUE, FALSE);
+ CurHandle = ConvertHandleIndexToHandle((UINTN)Intermediate);
+ if (CurHandle == NULL || EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, File);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
@@ -136,7 +159,7 @@ BcfgAdd ( (VOID**)&FilePath);
}
if (EFI_ERROR (Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_HANDLE), gShellDebug1HiiHandle, StrHexToUintn(File));
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_HANDLE), gShellDebug1HiiHandle, Intermediate);
ShellStatus = SHELL_INVALID_PARAMETER;
}
}
@@ -146,10 +169,16 @@ BcfgAdd ( //
ShellOpenFileMetaArg ((CHAR16*)File, EFI_FILE_MODE_READ, &FileList);
- //
- // If filename expanded to multiple names, fail
- //
- if (FileList == NULL || FileList->Link.ForwardLink != FileList->Link.BackLink) {
+ if (FileList == NULL) {
+ //
+ // If filename matched nothing fail
+ //
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else if (FileList->Link.ForwardLink != FileList->Link.BackLink) {
+ //
+ // If filename expanded to multiple names, fail
+ //
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE), gShellDebug1HiiHandle, File);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
@@ -166,7 +195,7 @@ BcfgAdd ( // get the device path
//
DevicePath = mEfiShellProtocol->GetDevicePathFromFilePath(Arg->FullName);
- if (DevicePath != NULL) {
+ if (DevicePath == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_FILE_DP), gShellDebug1HiiHandle, Arg->FullName);
ShellStatus = SHELL_UNSUPPORTED;
} else {
@@ -187,8 +216,8 @@ BcfgAdd ( //
// append the file
//
- for(p=Arg->FullName; *p != CHAR_NULL && *p != ':'; p++);
- FileNode = FileDevicePath(NULL, p+1);
+ for(StringWalker=Arg->FullName; *StringWalker != CHAR_NULL && *StringWalker != ':'; StringWalker++);
+ FileNode = FileDevicePath(NULL, StringWalker+1);
FilePath = AppendDevicePath(DevicePath, FileNode);
FreePool(FileNode);
} else {
@@ -207,7 +236,7 @@ BcfgAdd ( // Find a free target ,a brute force implementation
//
Found = FALSE;
- for (TargetLocation=1; TargetLocation < 0xFFFF; TargetLocation++) {
+ for (TargetLocation=0; TargetLocation < 0xFFFF; TargetLocation++) {
Found = TRUE;
for (Index=0; Index < OrderCount; Index++) {
if (CurrentOrder[Index] == TargetLocation) {
@@ -235,32 +264,33 @@ BcfgAdd ( DescSize = StrSize(Desc);
FilePathSize = GetDevicePathSize (FilePath);
- p8 = AllocatePool(sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize);
- *((UINT32 *) p8) = LOAD_OPTION_ACTIVE; // Attributes
- p8 += sizeof (UINT32);
+ TempByteBuffer = AllocateZeroPool(sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize);
+ TempByteStart = TempByteBuffer;
+ *((UINT32 *) TempByteBuffer) = LOAD_OPTION_ACTIVE; // Attributes
+ TempByteBuffer += sizeof (UINT32);
- *((UINT16 *) p8) = (UINT16)FilePathSize; // FilePathListLength
- p8 += sizeof (UINT16);
+ *((UINT16 *) TempByteBuffer) = (UINT16)FilePathSize; // FilePathListLength
+ TempByteBuffer += sizeof (UINT16);
- CopyMem (p8, Desc, DescSize);
- p8 += DescSize;
- CopyMem (p8, FilePath, FilePathSize);
+ CopyMem (TempByteBuffer, Desc, DescSize);
+ TempByteBuffer += DescSize;
+ CopyMem (TempByteBuffer, FilePath, FilePathSize);
- UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BCFG_TARGET_BOOT_ORDER?L"Boot":L"Driver", TargetLocation);
+ UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation);
Status = gRT->SetVariable (
OptionStr,
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize,
- p8
+ TempByteStart
);
- FreePool(p8);
+ FreePool(TempByteStart);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, OptionStr, Status);
} else {
- NewOrder = AllocatePool((OrderCount+1)*sizeof(NewOrder[0]));
+ NewOrder = AllocateZeroPool((OrderCount+1)*sizeof(NewOrder[0]));
ASSERT(NewOrder != NULL);
CopyMem(NewOrder, CurrentOrder, (OrderCount)*sizeof(NewOrder[0]));
@@ -273,7 +303,7 @@ BcfgAdd ( NewOrder[Position] = (UINT16) TargetLocation;
Status = gRT->SetVariable (
- Target == BCFG_TARGET_BOOT_ORDER?L"BootOrder":L"DriverOrder",
+ Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,
(OrderCount+1) * sizeof(UINT16),
@@ -283,7 +313,7 @@ BcfgAdd ( FreePool(NewOrder);
if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BCFG_TARGET_BOOT_ORDER?L"BootOrder":L"DriverOrder", Status);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BcfgTargetBootOrder?L"BootOrder":L"DriverOrder", Status);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Print (L"bcfg: Add %s as %x\n", OptionStr, Position);
@@ -317,9 +347,20 @@ BcfgAdd ( 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.
+**/
SHELL_STATUS
EFIAPI
-BcfgRemove(
+BcfgRemoveDebug1(
IN CONST BCFG_OPERATION_TARGET Target,
IN CONST UINT16 *CurrentOrder,
IN CONST UINTN OrderCount,
@@ -332,7 +373,7 @@ BcfgRemove( UINTN LoopVar;
UINTN NewCount;
- UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BCFG_TARGET_BOOT_ORDER?L"Boot":L"Driver", Location);
+ UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", Location);
Status = gRT->SetVariable(
VariableName,
(EFI_GUID*)&gEfiGlobalVariableGuid,
@@ -343,7 +384,7 @@ BcfgRemove( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, VariableName, Status);
return (SHELL_INVALID_PARAMETER);
}
- NewOrder = AllocatePool(OrderCount*sizeof(CurrentOrder[0]));
+ NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));
NewCount = OrderCount;
CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0]));
for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++){
@@ -353,7 +394,7 @@ BcfgRemove( }
}
Status = gRT->SetVariable(
- Target == BCFG_TARGET_BOOT_ORDER?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
+ Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
(EFI_GUID*)&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,
NewCount*sizeof(NewOrder[0]),
@@ -361,15 +402,27 @@ BcfgRemove( FreePool(NewOrder);
if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BCFG_TARGET_BOOT_ORDER?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, 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.
+**/
SHELL_STATUS
EFIAPI
-BcfgMove(
+BcfgMoveDebug1(
IN CONST BCFG_OPERATION_TARGET Target,
IN CONST UINT16 *CurrentOrder,
IN CONST UINTN OrderCount,
@@ -381,7 +434,7 @@ BcfgMove( EFI_STATUS Status;
UINT16 Temp;
- NewOrder = AllocatePool(OrderCount*sizeof(CurrentOrder[0]));
+ NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));
ASSERT(NewOrder != NULL);
Temp = CurrentOrder[OldLocation];
@@ -392,7 +445,7 @@ BcfgMove( Status = gRT->SetVariable(
- Target == BCFG_TARGET_BOOT_ORDER?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
+ Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
(EFI_GUID*)&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,
OrderCount*sizeof(CurrentOrder[0]),
@@ -401,7 +454,7 @@ BcfgMove( FreePool(NewOrder);
if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BCFG_TARGET_BOOT_ORDER?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);
return (SHELL_INVALID_PARAMETER);
}
return (SHELL_SUCCESS);
@@ -409,9 +462,32 @@ BcfgMove( SHELL_STATUS
EFIAPI
-BcfgDisplayDump(
+BcfgAddOptDebug1(
+ IN CONST CHAR16 *OptData,
+ IN CONST BCFG_OPERATION_TARGET Target
+ )
+{
+ ASSERT(OptData != NULL);
+ 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.
+**/
+SHELL_STATUS
+EFIAPI
+BcfgDisplayDumpDebug1(
IN CONST CHAR16 *Op,
- IN CONST UINTN OrderCount,
+ IN CONST UINTN OrderCount,
+ IN CONST UINT16 *CurrentOrder,
IN CONST BOOLEAN VerboseOutput
)
{
@@ -424,10 +500,15 @@ BcfgDisplayDump( CHAR16 *DevPathString;
VOID *DevPath;
+ if (OrderCount == 0) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_BCFG_NONE), gShellDebug1HiiHandle);
+ return (SHELL_SUCCESS);
+ }
+
for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++) {
Buffer = NULL;
BufferSize = 0;
- UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Op, LoopVar);
+ UnicodeSPrint(VariableName, sizeof(VariableName), L"%s%04x", Op, CurrentOrder[LoopVar]);
Status = gRT->GetVariable(
VariableName,
@@ -436,7 +517,7 @@ BcfgDisplayDump( &BufferSize,
Buffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
- Buffer = AllocatePool(BufferSize);
+ Buffer = AllocateZeroPool(BufferSize);
Status = gRT->GetVariable(
VariableName,
(EFI_GUID*)&gEfiGlobalVariableGuid,
@@ -450,7 +531,7 @@ BcfgDisplayDump( return (SHELL_INVALID_PARAMETER);
}
- DevPath = AllocatePool(*(UINT16*)(Buffer+4));
+ DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));
CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE);
ShellPrintHiiEx(
@@ -459,6 +540,7 @@ BcfgDisplayDump( NULL,
STRING_TOKEN(STR_BCFG_LOAD_OPTIONS),
gShellDebug1HiiHandle,
+ LoopVar,
VariableName,
(CHAR16*)(Buffer+6),
DevPathString,
@@ -492,15 +574,20 @@ BcfgDisplayDump( return (SHELL_SUCCESS);
}
+/**
+ Function to initialize the BCFG operation structure.
+
+ @param[in] Struct The stuct to initialize.
+**/
VOID
EFIAPI
-InitBcfgStruct(
+InitBcfgStructDebug1(
IN BGFG_OPERATION *Struct
)
{
ASSERT(Struct != NULL);
- Struct->Target = BCFG_TARGET_MAX;
- Struct->Type = BCFG_TYPE_MAX;
+ Struct->Target = BcfgTargetMax;
+ Struct->Type = BcfgTypeMax;
Struct->Number1 = 0;
Struct->Number2 = 0;
Struct->HandleIndex = 0;
@@ -538,13 +625,14 @@ ShellCommandRunBcfg ( CONST CHAR16 *CurrentParam;
BGFG_OPERATION CurrentOperation;
UINTN Length;
+ UINT64 Intermediate;
Length = 0;
ProblemParam = NULL;
Package = NULL;
ShellStatus = SHELL_SUCCESS;
- InitBcfgStruct(&CurrentOperation);
+ InitBcfgStructDebug1(&CurrentOperation);
//
// initialize the shell lib (we must be in non-auto-init...)
@@ -569,43 +657,50 @@ ShellCommandRunBcfg ( }
} else {
//
+ // Read in if we are doing -OPT
+ //
+ if (ShellCommandLineGetFlag(Package, L"-opt")) {
+ CurrentOperation.OptData = ShellCommandLineGetValue(Package, L"-opt");
+ if (CurrentOperation.OptData == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"-opt");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ CurrentOperation.Type = BcfgTypeOpt;
+ }
+
+ //
// small block to read the target of the operation
//
- if (ShellCommandLineGetCount(Package) < 3) {
+ if ((ShellCommandLineGetCount(Package) < 3 && CurrentOperation.Type != BcfgTypeOpt) ||
+ (ShellCommandLineGetCount(Package) < 2 && CurrentOperation.Type == BcfgTypeOpt)
+ ){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)ShellCommandLineGetRawValue(Package, 1), L"driver") == 0) {
- CurrentOperation.Target = BCFG_TARGET_DRIVER_ORDER;
+ CurrentOperation.Target = BcfgTargetDriverOrder;
} else if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)ShellCommandLineGetRawValue(Package, 1), L"boot") == 0) {
- CurrentOperation.Target = BCFG_TARGET_BOOT_ORDER;
+ CurrentOperation.Target = BcfgTargetBootOrder;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_DRIVER_BOOT), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
- //
- // Read in if we are doing -OPT
- //
- if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BCFG_TARGET_MAX && ShellCommandLineGetFlag(Package, L"-opt")) {
- CurrentOperation.OptData = ShellCommandLineGetValue(Package, L"-opt");
- CurrentOperation.Type = BCFG_TYPE_OPT;
- }
//
// Read in the boot or driver order environment variable (not needed for opt)
//
- if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BCFG_TARGET_MAX && CurrentOperation.Type != BCFG_TYPE_OPT) {
+ if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax && CurrentOperation.Type != BcfgTypeOpt) {
Length = 0;
Status = gRT->GetVariable(
- CurrentOperation.Target == BCFG_TARGET_BOOT_ORDER?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
+ CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
(EFI_GUID*)&gEfiGlobalVariableGuid,
NULL,
&Length,
CurrentOperation.Order);
if (Status == EFI_BUFFER_TOO_SMALL) {
- CurrentOperation.Order = AllocatePool(Length+(4*sizeof(CurrentOperation.Order[0])));
+ CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));
Status = gRT->GetVariable(
- CurrentOperation.Target == BCFG_TARGET_BOOT_ORDER?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
+ CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
(EFI_GUID*)&gEfiGlobalVariableGuid,
NULL,
&Length,
@@ -616,11 +711,11 @@ ShellCommandRunBcfg ( //
// large block to read the type of operation and verify parameter types for the info.
//
- if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BCFG_TARGET_MAX) {
+ if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax) {
for (ParamNumber = 2 ; ParamNumber < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS; ParamNumber++) {
CurrentParam = ShellCommandLineGetRawValue(Package, ParamNumber);
if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)CurrentParam, L"dump") == 0) {
- CurrentOperation.Type = BCFG_TYPE_DUMP;
+ CurrentOperation.Type = BcfgTypeDump;
} else if (ShellCommandLineGetFlag(Package, L"-v")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"-v (without dump)");
ShellStatus = SHELL_INVALID_PARAMETER;
@@ -629,13 +724,14 @@ ShellCommandRunBcfg ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
- CurrentOperation.Type = BCFG_TYPE_ADD;
+ CurrentOperation.Type = BcfgTypeAdd;
CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);
if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- CurrentOperation.Number1 = (UINT16)StrHexToUintn(CurrentParam);
+ Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
+ CurrentOperation.Number1 = (UINT16)Intermediate;
ASSERT(CurrentOperation.FileName == NULL);
CurrentOperation.FileName = StrnCatGrow(&CurrentOperation.FileName , NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);
ASSERT(CurrentOperation.Description == NULL);
@@ -646,13 +742,14 @@ ShellCommandRunBcfg ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
- CurrentOperation.Type = BCFG_TYPE_ADDP;
+ CurrentOperation.Type = BcfgTypeAddp;
CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);
if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- CurrentOperation.Number1 = (UINT16)StrHexToUintn(CurrentParam);
+ Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
+ CurrentOperation.Number1 = (UINT16)Intermediate;
ASSERT(CurrentOperation.FileName == NULL);
CurrentOperation.FileName = StrnCatGrow(&CurrentOperation.FileName , NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);
ASSERT(CurrentOperation.Description == NULL);
@@ -663,19 +760,21 @@ ShellCommandRunBcfg ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
- CurrentOperation.Type = BCFG_TYPE_ADDH;
+ CurrentOperation.Type = BcfgTypeAddh;
CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);
if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- CurrentOperation.Number1 = (UINT16)StrHexToUintn(CurrentParam);
+ Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
+ CurrentOperation.Number1 = (UINT16)Intermediate;
CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);
if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- CurrentOperation.HandleIndex = (UINT16)StrHexToUintn(CurrentParam);
+ Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
+ CurrentOperation.HandleIndex = (UINT16)Intermediate;
ASSERT(CurrentOperation.Description == NULL);
CurrentOperation.Description = StrnCatGrow(&CurrentOperation.Description, NULL, ShellCommandLineGetRawValue(Package, ++ParamNumber), 0);
}
@@ -685,13 +784,14 @@ ShellCommandRunBcfg ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
- CurrentOperation.Type = BCFG_TYPE_RM;
+ CurrentOperation.Type = BcfgTypeRm;
CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);
if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- CurrentOperation.Number1 = (UINT16)StrHexToUintn(CurrentParam);
+ Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
+ CurrentOperation.Number1 = (UINT16)Intermediate;
if (CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
ShellStatus = SHELL_INVALID_PARAMETER;
@@ -702,13 +802,14 @@ ShellCommandRunBcfg ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
- CurrentOperation.Type = BCFG_TYPE_MV;
+ CurrentOperation.Type = BcfgTypeMv;
CurrentParam = ShellCommandLineGetRawValue(Package, ++ParamNumber);
if (CurrentParam == NULL || !ShellIsHexOrDecimalNumber(CurrentParam, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- CurrentOperation.Number1 = (UINT16)StrHexToUintn(CurrentParam);
+ Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
+ CurrentOperation.Number1 = (UINT16)Intermediate;
if (CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_NUMB_RANGE), gShellDebug1HiiHandle, Length / sizeof(CurrentOperation.Order[0]));
ShellStatus = SHELL_INVALID_PARAMETER;
@@ -718,7 +819,8 @@ ShellCommandRunBcfg ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, CurrentParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- CurrentOperation.Number2 = (UINT16)StrHexToUintn(CurrentParam);
+ Status = ShellConvertStringToUint64(CurrentParam, &Intermediate, TRUE, FALSE);
+ CurrentOperation.Number2 = (UINT16)Intermediate;
}
if (CurrentOperation.Number2 == CurrentOperation.Number1
||CurrentOperation.Number1 > (Length / sizeof(CurrentOperation.Order[0]))
@@ -734,47 +836,52 @@ ShellCommandRunBcfg ( }
}
}
- if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BCFG_TARGET_MAX && CurrentOperation.Type < BCFG_TYPE_MAX) {
+ if (ShellStatus == SHELL_SUCCESS && CurrentOperation.Target < BcfgTargetMax && CurrentOperation.Type < BcfgTypeMax) {
//
// we have all the info. Do the work
//
switch (CurrentOperation.Type) {
- case BCFG_TYPE_DUMP:
- ShellStatus = BcfgDisplayDump(
- CurrentOperation.Target == BCFG_TARGET_BOOT_ORDER?L"Boot":L"Driver",
+ case BcfgTypeDump:
+ ShellStatus = BcfgDisplayDumpDebug1(
+ CurrentOperation.Target == BcfgTargetBootOrder?L"Boot":L"Driver",
Length / sizeof(CurrentOperation.Order[0]),
+ CurrentOperation.Order,
ShellCommandLineGetFlag(Package, L"-v"));
break;
- case BCFG_TYPE_MV:
- ShellStatus = BcfgMove(
+ case BcfgTypeMv:
+ ShellStatus = BcfgMoveDebug1(
CurrentOperation.Target,
CurrentOperation.Order,
Length / sizeof(CurrentOperation.Order[0]),
CurrentOperation.Number1,
CurrentOperation.Number2);
break;
- case BCFG_TYPE_RM:
- ShellStatus = BcfgRemove(
+ case BcfgTypeRm:
+ ShellStatus = BcfgRemoveDebug1(
CurrentOperation.Target,
CurrentOperation.Order,
Length / sizeof(CurrentOperation.Order[0]),
CurrentOperation.Number1);
break;
- case BCFG_TYPE_ADD:
- case BCFG_TYPE_ADDP:
- case BCFG_TYPE_ADDH:
- ShellStatus = BcfgAdd(
+ case BcfgTypeAdd:
+ case BcfgTypeAddp:
+ case BcfgTypeAddh:
+ ShellStatus = BcfgAddDebug1(
CurrentOperation.Number1,
CurrentOperation.FileName,
CurrentOperation.Description,
CurrentOperation.Order,
- Length,
+ Length / sizeof(CurrentOperation.Order[0]),
CurrentOperation.Target,
- (BOOLEAN)(CurrentOperation.Type == BCFG_TYPE_ADDH),
- (BOOLEAN)(CurrentOperation.Type == BCFG_TYPE_ADDP),
+ (BOOLEAN)(CurrentOperation.Type == BcfgTypeAddh),
+ (BOOLEAN)(CurrentOperation.Type == BcfgTypeAddp),
CurrentOperation.HandleIndex);
break;
- case BCFG_TYPE_OPT:
+ case BcfgTypeOpt:
+ ShellStatus = BcfgAddOptDebug1(
+ CurrentOperation.OptData,
+ CurrentOperation.Target);
+ break;
default:
ASSERT(FALSE);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c index c6933e6095..b59ef31682 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c @@ -1,7 +1,7 @@ /** @file
Main file for Comp shell Debug1 function.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -14,6 +14,12 @@ #include "UefiShellDebug1CommandsLib.h"
+/**
+ Function for 'comp' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunComp (
@@ -83,24 +89,26 @@ ShellCommandRunComp ( ShellStatus = SHELL_INVALID_PARAMETER;
} else {
FileName1 = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 1));
- FileName2 = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 2));
- Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);
+ if (FileName1 == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_NOT_FOUND;
+ } else {
+ Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);
+ ShellStatus = SHELL_NOT_FOUND;
+ }
}
- Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
+ FileName2 = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 2));
+ if (FileName2 == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2));
ShellStatus = SHELL_NOT_FOUND;
- }
- if (FileHandleIsDirectory(FileHandle1) == EFI_SUCCESS){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, FileName1);
- ShellStatus = SHELL_INVALID_PARAMETER;
- }
- if (FileHandleIsDirectory(FileHandle2) == EFI_SUCCESS){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, FileName2);
- ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
+ ShellStatus = SHELL_NOT_FOUND;
+ }
}
if (ShellStatus == SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_HEADER), gShellDebug1HiiHandle, FileName1, FileName2);
@@ -228,22 +236,19 @@ ShellCommandRunComp ( ShellStatus = SHELL_NOT_EQUAL;
}
}
- }
- if (ErrorCount == 0) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle);
- } else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle);
+ if (ErrorCount == 0) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle);
+ }
}
}
ShellCommandLineFreeVarList (Package);
}
- if (FileName1 != NULL) {
- FreePool(FileName1);
- }
- if (FileName2 != NULL) {
- FreePool(FileName2);
- }
+ SHELL_FREE_NON_NULL(FileName1);
+ SHELL_FREE_NON_NULL(FileName2);
+
if (FileHandle1 != NULL) {
gEfiShellProtocol->CloseFile(FileHandle1);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c index 9e880e6d6b..870335b9a1 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c @@ -7,7 +7,7 @@ This sequence is further divided into Blocks and Huffman codings
are applied to each Block.
- Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2007 - 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
@@ -39,9 +39,9 @@ typedef INT16 NODE; #define CODE_BIT 16
#define NIL 0
#define MAX_HASH_VAL (3 * WNDSIZ + (WNDSIZ / 512 + 1) * UINT8_MAX)
-#define HASH(p, c) ((p) + ((c) << (WNDBIT - 9)) + WNDSIZ * 2)
+#define HASH(LoopVar7, LoopVar5) ((LoopVar7) + ((LoopVar5) << (WNDBIT - 9)) + WNDSIZ * 2)
#define CRCPOLY 0xA001
-#define UPDATE_CRC(c) mCrc = mCrcTable[(mCrc ^ (c)) & 0xFF] ^ (mCrc >> UINT8_BIT)
+#define UPDATE_CRC(LoopVar5) mCrc = mCrcTable[(mCrc ^ (LoopVar5)) & 0xFF] ^ (mCrc >> UINT8_BIT)
//
// C: the Char&Len Set; P: the Position Set; T: the exTra Set
@@ -72,287 +72,85 @@ PutDword( IN UINT32 Data
);
-EFI_STATUS
-EFIAPI
-AllocateMemory (
- VOID
- );
-
-VOID
-EFIAPI
-FreeMemory (
- VOID
- );
-
-VOID
-EFIAPI
-InitSlide (
- VOID
- );
-
-NODE
-EFIAPI
-Child (
- IN NODE q,
- IN UINT8 c
- );
-
-VOID
-EFIAPI
-MakeChild (
- IN NODE q,
- IN UINT8 c,
- IN NODE r
- );
-
-VOID
-EFIAPI
-Split (
- IN NODE Old
- );
-
-VOID
-EFIAPI
-InsertNode (
- VOID
- );
-
-VOID
-EFIAPI
-DeleteNode (
- VOID
- );
-
-VOID
-EFIAPI
-GetNextMatch (
- VOID
- );
-
-EFI_STATUS
-EFIAPI
-Encode (
- VOID
- );
-
-VOID
-EFIAPI
-CountTFreq (
- VOID
- );
-
-VOID
-EFIAPI
-WritePTLen (
- IN INT32 n,
- IN INT32 nbit,
- IN INT32 Special
- );
-
-VOID
-EFIAPI
-WriteCLen (
- VOID
- );
-
-VOID
-EFIAPI
-EncodeC (
- IN INT32 c
- );
-
-VOID
-EFIAPI
-EncodeP (
- IN UINT32 p
- );
-
-VOID
-EFIAPI
-SendBlock (
- VOID
- );
-
-VOID
-EFIAPI
-CompressOutput (
- IN UINT32 c,
- IN UINT32 p
- );
-
-VOID
-EFIAPI
-HufEncodeStart (
- VOID
- );
-
-VOID
-EFIAPI
-HufEncodeEnd (
- VOID
- );
-
-VOID
-EFIAPI
-MakeCrcTable (
- VOID
- );
-
-VOID
-EFIAPI
-PutBits (
- IN INT32 n,
- IN UINT32 x
- );
-
-INT32
-EFIAPI
-FreadCrc (
- OUT UINT8 *p,
- IN INT32 n
- );
-
-VOID
-EFIAPI
-InitPutBits (
- VOID
- );
-
-VOID
-EFIAPI
-CountLen (
- IN INT32 i
- );
-
-VOID
-EFIAPI
-MakeLen (
- IN INT32 Root
- );
-
-VOID
-EFIAPI
-DownHeap (
- IN INT32 i
- );
-
-VOID
-EFIAPI
-MakeCode (
- IN INT32 n,
- IN UINT8 Len[ ],
- OUT UINT16 Code[ ]
- );
-
-INT32
-EFIAPI
-MakeTree (
- IN INT32 NParm,
- IN UINT16 FreqParm[ ],
- OUT UINT8 LenParm[ ],
- OUT UINT16 CodeParm[ ]
- );
-
//
// Global Variables
//
-STATIC UINT8 *mSrc, *mDst, *mSrcUpperLimit, *mDstUpperLimit;
-
-STATIC UINT8 *mLevel, *mText, *mChildCount, *mBuf, mCLen[NC], mPTLen[NPT], *mLen;
+STATIC UINT8 *mSrc;
+STATIC UINT8 *mDst;
+STATIC UINT8 *mSrcUpperLimit;
+STATIC UINT8 *mDstUpperLimit;
+
+STATIC UINT8 *mLevel;
+STATIC UINT8 *mText;
+STATIC UINT8 *mChildCount;
+STATIC UINT8 *mBuf;
+STATIC UINT8 mCLen[NC];
+STATIC UINT8 mPTLen[NPT];
+STATIC UINT8 *mLen;
STATIC INT16 mHeap[NC + 1];
-STATIC INT32 mRemainder, mMatchLen, mBitCount, mHeapSize, mN;
-STATIC UINT32 mBufSiz = 0, mOutputPos, mOutputMask, mSubBitBuf, mCrc;
-STATIC UINT32 mCompSize, mOrigSize;
-
-STATIC UINT16 *mFreq, *mSortPtr, mLenCnt[17], mLeft[2 * NC - 1], mRight[2 * NC - 1],
- mCrcTable[UINT8_MAX + 1], mCFreq[2 * NC - 1], mCTable[4096], mCCode[NC],
- mPFreq[2 * NP - 1], mPTCode[NPT], mTFreq[2 * NT - 1];
+STATIC INT32 mRemainder;
+STATIC INT32 mMatchLen;
+STATIC INT32 mBitCount;
+STATIC INT32 mHeapSize;
+STATIC INT32 mTempInt32;
+STATIC UINT32 mBufSiz = 0;
+STATIC UINT32 mOutputPos;
+STATIC UINT32 mOutputMask;
+STATIC UINT32 mSubBitBuf;
+STATIC UINT32 mCrc;
+STATIC UINT32 mCompSize;
+STATIC UINT32 mOrigSize;
+
+STATIC UINT16 *mFreq;
+STATIC UINT16 *mSortPtr;
+STATIC UINT16 mLenCnt[17];
+STATIC UINT16 mLeft[2 * NC - 1];
+STATIC UINT16 mRight[2 * NC - 1];
+STATIC UINT16 mCrcTable[UINT8_MAX + 1];
+STATIC UINT16 mCFreq[2 * NC - 1];
+STATIC UINT16 mCTable[4096];
+STATIC UINT16 mCCode[NC];
+STATIC UINT16 mPFreq[2 * NP - 1];
+STATIC UINT16 mPTCode[NPT];
+STATIC UINT16 mTFreq[2 * NT - 1];
+
+STATIC NODE mPos;
+STATIC NODE mMatchPos;
+STATIC NODE mAvail;
+STATIC NODE *mPosition;
+STATIC NODE *mParent;
+STATIC NODE *mPrev;
+STATIC NODE *mNext = NULL;
+INT32 mHuffmanDepth = 0;
-STATIC NODE mPos, mMatchPos, mAvail, *mPosition, *mParent, *mPrev, *mNext = NULL;
-
-//
-// functions
-//
/**
- The compression routine.
+ Make a CRC table.
- @param[in] SrcBuffer The buffer containing the source data.
- @param[in] SrcSizae Number of bytes in SrcBuffer.
- @param[in] DstBuffer The buffer to put the compressed image in.
- @param[in,out] DstSize On input the size (in bytes) of DstBuffer, on
- return the number of bytes placed in DstBuffer.
-
- @retval EFI_SUCCESS The compression was sucessful.
- @retval EFI_BUFFER_TOO_SMALL The buffer was too small. DstSize is required.
**/
-EFI_STATUS
+VOID
EFIAPI
-Compress (
- IN VOID *SrcBuffer,
- IN UINT64 SrcSize,
- IN VOID *DstBuffer,
- IN OUT UINT64 *DstSize
+MakeCrcTable (
+ VOID
)
{
- EFI_STATUS Status;
-
- //
- // Initializations
- //
- mBufSiz = 0;
- mBuf = NULL;
- mText = NULL;
- mLevel = NULL;
- mChildCount = NULL;
- mPosition = NULL;
- mParent = NULL;
- mPrev = NULL;
- mNext = NULL;
+ UINT32 LoopVar1;
- mSrc = SrcBuffer;
- mSrcUpperLimit = mSrc + SrcSize;
- mDst = DstBuffer;
- mDstUpperLimit = mDst +*DstSize;
+ UINT32 LoopVar2;
- PutDword (0L);
- PutDword (0L);
-
- MakeCrcTable ();
-
- mOrigSize = mCompSize = 0;
- mCrc = INIT_CRC;
+ UINT32 LoopVar4;
- //
- // Compress it
- //
- Status = Encode ();
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
- //
- // Null terminate the compressed data
- //
- if (mDst < mDstUpperLimit) {
- *mDst++ = 0;
- }
- //
- // Fill in compressed size and original size
- //
- mDst = DstBuffer;
- PutDword (mCompSize + 1);
- PutDword (mOrigSize);
+ for (LoopVar1 = 0; LoopVar1 <= UINT8_MAX; LoopVar1++) {
+ LoopVar4 = LoopVar1;
+ for (LoopVar2 = 0; LoopVar2 < UINT8_BIT; LoopVar2++) {
+ if ((LoopVar4 & 1) != 0) {
+ LoopVar4 = (LoopVar4 >> 1) ^ CRCPOLY;
+ } else {
+ LoopVar4 >>= 1;
+ }
+ }
- //
- // Return
- //
- if (mCompSize + 1 + 8 > *DstSize) {
- *DstSize = mCompSize + 1 + 8;
- return EFI_BUFFER_TOO_SMALL;
- } else {
- *DstSize = mCompSize + 1 + 8;
- return EFI_SUCCESS;
+ mCrcTable[LoopVar1] = (UINT16) LoopVar4;
}
-
}
/**
@@ -383,45 +181,35 @@ PutDword ( }
}
+/**
+ Allocate memory spaces for data structures used in compression process.
+
+ @retval EFI_SUCCESS Memory was allocated successfully.
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
+**/
EFI_STATUS
EFIAPI
AllocateMemory (
VOID
)
-/*++
-
-Routine Description:
-
- Allocate memory spaces for data structures used in compression process
-
-Arguments:
-
- None
-
-Returns:
-
- EFI_SUCCESS - Memory is allocated successfully
- EFI_OUT_OF_RESOURCES - Allocation fails
-
-**/
{
mText = AllocateZeroPool (WNDSIZ * 2 + MAXMATCH);
- mLevel = AllocatePool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mLevel));
- mChildCount = AllocatePool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mChildCount));
- mPosition = AllocatePool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mPosition));
- mParent = AllocatePool (WNDSIZ * 2 * sizeof (*mParent));
- mPrev = AllocatePool (WNDSIZ * 2 * sizeof (*mPrev));
- mNext = AllocatePool ((MAX_HASH_VAL + 1) * sizeof (*mNext));
+ mLevel = AllocateZeroPool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mLevel));
+ mChildCount = AllocateZeroPool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mChildCount));
+ mPosition = AllocateZeroPool ((WNDSIZ + UINT8_MAX + 1) * sizeof (*mPosition));
+ mParent = AllocateZeroPool (WNDSIZ * 2 * sizeof (*mParent));
+ mPrev = AllocateZeroPool (WNDSIZ * 2 * sizeof (*mPrev));
+ mNext = AllocateZeroPool ((MAX_HASH_VAL + 1) * sizeof (*mNext));
mBufSiz = BLKSIZ;
- mBuf = AllocatePool (mBufSiz);
+ mBuf = AllocateZeroPool (mBufSiz);
while (mBuf == NULL) {
mBufSiz = (mBufSiz / 10U) * 9U;
if (mBufSiz < 4 * 1024U) {
return EFI_OUT_OF_RESOURCES;
}
- mBuf = AllocatePool (mBufSiz);
+ mBuf = AllocateZeroPool (mBufSiz);
}
mBuf[0] = 0;
@@ -429,22 +217,15 @@ Returns: return EFI_SUCCESS;
}
+/**
+ Called when compression is completed to free memory previously allocated.
+
+**/
VOID
EFIAPI
FreeMemory (
VOID
)
-/*++
-
-Routine Description:
-
- Called when compression is completed to free memory previously allocated.
-
-Arguments: (VOID)
-
-Returns: (VOID)
-
-**/
{
SHELL_FREE_NON_NULL (mText);
SHELL_FREE_NON_NULL (mLevel);
@@ -456,24 +237,17 @@ Returns: (VOID) SHELL_FREE_NON_NULL (mBuf);
}
+/**
+ Initialize String Info Log data structures
+
+**/
VOID
EFIAPI
InitSlide (
VOID
)
-/*++
-
-Routine Description:
-
- Initialize String Info Log data structures
-
-Arguments: (VOID)
-
-Returns: (VOID)
-
-**/
{
- NODE i;
+ NODE LoopVar1;
SetMem (mLevel + WNDSIZ, (UINT8_MAX + 1) * sizeof (UINT8), 1);
SetMem (mPosition + WNDSIZ, (UINT8_MAX + 1) * sizeof (NODE), 0);
@@ -481,117 +255,95 @@ Returns: (VOID) SetMem (mParent + WNDSIZ, WNDSIZ * sizeof (NODE), 0);
mAvail = 1;
- for (i = 1; i < WNDSIZ - 1; i++) {
- mNext[i] = (NODE) (i + 1);
+ for (LoopVar1 = 1; LoopVar1 < WNDSIZ - 1; LoopVar1++) {
+ mNext[LoopVar1] = (NODE) (LoopVar1 + 1);
}
mNext[WNDSIZ - 1] = NIL;
SetMem (mNext + WNDSIZ * 2, (MAX_HASH_VAL - WNDSIZ * 2 + 1) * sizeof (NODE), 0);
}
-NODE
-EFIAPI
-Child (
- IN NODE q,
- IN UINT8 c
- )
-/*++
-
-Routine Description:
-
+/**
Find child node given the parent node and the edge character
-Arguments:
-
- q - the parent node
- c - the edge character
-
-Returns:
+ @param[in] LoopVar6 The parent node.
+ @param[in] LoopVar5 The edge character.
- The child node (NIL if not found)
+ @return The child node.
+ @retval NIL(Zero) No child could be found.
**/
+NODE
+EFIAPI
+Child (
+ IN NODE LoopVar6,
+ IN UINT8 LoopVar5
+ )
{
- NODE r;
+ NODE LoopVar4;
- r = mNext[HASH (q, c)];
- mParent[NIL] = q; /* sentinel */
- while (mParent[r] != q) {
- r = mNext[r];
+ LoopVar4 = mNext[HASH (LoopVar6, LoopVar5)];
+ mParent[NIL] = LoopVar6; /* sentinel */
+ while (mParent[LoopVar4] != LoopVar6) {
+ LoopVar4 = mNext[LoopVar4];
}
- return r;
+ return LoopVar4;
}
+/**
+ Create a new child for a given parent node.
+
+ @param[in] LoopVar6 The parent node.
+ @param[in] LoopVar5 The edge character.
+ @param[in] LoopVar4 The child node.
+**/
VOID
EFIAPI
MakeChild (
- IN NODE q,
- IN UINT8 c,
- IN NODE r
+ IN NODE LoopVar6,
+ IN UINT8 LoopVar5,
+ IN NODE LoopVar4
)
-/*++
-
-Routine Description:
-
- Create a new child for a given parent node.
-
-Arguments:
-
- q - the parent node
- c - the edge character
- r - the child node
-
-Returns: (VOID)
-
-**/
{
- NODE h;
-
- NODE t;
-
- h = (NODE) HASH (q, c);
- t = mNext[h];
- mNext[h] = r;
- mNext[r] = t;
- mPrev[t] = r;
- mPrev[r] = h;
- mParent[r] = q;
- mChildCount[q]++;
+ NODE LoopVar12;
+
+ NODE LoopVar10;
+
+ LoopVar12 = (NODE) HASH (LoopVar6, LoopVar5);
+ LoopVar10 = mNext[LoopVar12];
+ mNext[LoopVar12] = LoopVar4;
+ mNext[LoopVar4] = LoopVar10;
+ mPrev[LoopVar10] = LoopVar4;
+ mPrev[LoopVar4] = LoopVar12;
+ mParent[LoopVar4] = LoopVar6;
+ mChildCount[LoopVar6]++;
}
+/**
+ Split a node.
+
+ @param[in] Old The node to split.
+**/
VOID
EFIAPI
Split (
- NODE Old
+ IN NODE Old
)
-/*++
-
-Routine Description:
-
- Split a node.
-
-Arguments:
-
- Old - the node to split
-
-Returns: (VOID)
-
-**/
{
NODE New;
- NODE t;
+ NODE LoopVar10;
New = mAvail;
mAvail = mNext[New];
mChildCount[New] = 0;
- t = mPrev[Old];
- mPrev[New] = t;
- mNext[t] = New;
- t = mNext[Old];
- mNext[New] = t;
- mPrev[t] = New;
+ LoopVar10 = mPrev[Old];
+ mPrev[New] = LoopVar10;
+ mNext[LoopVar10] = New;
+ LoopVar10 = mNext[Old];
+ mNext[New] = LoopVar10;
+ mPrev[LoopVar10] = New;
mParent[New] = mParent[Old];
mLevel[New] = (UINT8) mMatchLen;
mPosition[New] = mPos;
@@ -599,33 +351,26 @@ Returns: (VOID) MakeChild (New, mText[mPos + mMatchLen], mPos);
}
+/**
+ Insert string info for current position into the String Info Log.
+
+**/
VOID
EFIAPI
InsertNode (
VOID
)
-/*++
-
-Routine Description:
-
- Insert string info for current position into the String Info Log
-
-Arguments: (VOID)
-
-Returns: (VOID)
-
-**/
{
- NODE q;
+ NODE LoopVar6;
- NODE r;
+ NODE LoopVar4;
- NODE j;
+ NODE LoopVar2;
- NODE t;
- UINT8 c;
- UINT8 *t1;
- UINT8 *t2;
+ NODE LoopVar10;
+ UINT8 LoopVar5;
+ UINT8 *TempString3;
+ UINT8 *TempString2;
if (mMatchLen >= 4) {
//
@@ -636,36 +381,36 @@ Returns: (VOID) // in DeleteNode() later.
//
mMatchLen--;
- r = (NODE) ((mMatchPos + 1) | WNDSIZ);
- q = mParent[r];
- while (q == NIL) {
- r = mNext[r];
- q = mParent[r];
+ LoopVar4 = (NODE) ((mMatchPos + 1) | WNDSIZ);
+ LoopVar6 = mParent[LoopVar4];
+ while (LoopVar6 == NIL) {
+ LoopVar4 = mNext[LoopVar4];
+ LoopVar6 = mParent[LoopVar4];
}
- while (mLevel[q] >= mMatchLen) {
- r = q;
- q = mParent[q];
+ while (mLevel[LoopVar6] >= mMatchLen) {
+ LoopVar4 = LoopVar6;
+ LoopVar6 = mParent[LoopVar6];
}
- t = q;
- while (mPosition[t] < 0) {
- mPosition[t] = mPos;
- t = mParent[t];
+ LoopVar10 = LoopVar6;
+ while (mPosition[LoopVar10] < 0) {
+ mPosition[LoopVar10] = mPos;
+ LoopVar10 = mParent[LoopVar10];
}
- if (t < WNDSIZ) {
- mPosition[t] = (NODE) (mPos | PERC_FLAG);
+ if (LoopVar10 < WNDSIZ) {
+ mPosition[LoopVar10] = (NODE) (mPos | PERC_FLAG);
}
} else {
//
// Locate the target tree
//
- q = (NODE) (mText[mPos] + WNDSIZ);
- c = mText[mPos + 1];
- r = Child (q, c);
- if (r == NIL) {
- MakeChild (q, c, mPos);
+ LoopVar6 = (NODE) (mText[mPos] + WNDSIZ);
+ LoopVar5 = mText[mPos + 1];
+ LoopVar4 = Child (LoopVar6, LoopVar5);
+ if (LoopVar4 == NIL) {
+ MakeChild (LoopVar6, LoopVar5, mPos);
mMatchLen = 1;
return ;
}
@@ -678,191 +423,211 @@ Returns: (VOID) // Node split or creation is involved.
//
for (;;) {
- if (r >= WNDSIZ) {
- j = MAXMATCH;
- mMatchPos = r;
+ if (LoopVar4 >= WNDSIZ) {
+ LoopVar2 = MAXMATCH;
+ mMatchPos = LoopVar4;
} else {
- j = mLevel[r];
- mMatchPos = (NODE) (mPosition[r] & ~PERC_FLAG);
+ LoopVar2 = mLevel[LoopVar4];
+ mMatchPos = (NODE) (mPosition[LoopVar4] & ~PERC_FLAG);
}
if (mMatchPos >= mPos) {
mMatchPos -= WNDSIZ;
}
- t1 = &mText[mPos + mMatchLen];
- t2 = &mText[mMatchPos + mMatchLen];
- while (mMatchLen < j) {
- if (*t1 != *t2) {
- Split (r);
+ TempString3 = &mText[mPos + mMatchLen];
+ TempString2 = &mText[mMatchPos + mMatchLen];
+ while (mMatchLen < LoopVar2) {
+ if (*TempString3 != *TempString2) {
+ Split (LoopVar4);
return ;
}
mMatchLen++;
- t1++;
- t2++;
+ TempString3++;
+ TempString2++;
}
if (mMatchLen >= MAXMATCH) {
break;
}
- mPosition[r] = mPos;
- q = r;
- r = Child (q, *t1);
- if (r == NIL) {
- MakeChild (q, *t1, mPos);
+ mPosition[LoopVar4] = mPos;
+ LoopVar6 = LoopVar4;
+ LoopVar4 = Child (LoopVar6, *TempString3);
+ if (LoopVar4 == NIL) {
+ MakeChild (LoopVar6, *TempString3, mPos);
return ;
}
mMatchLen++;
}
- t = mPrev[r];
- mPrev[mPos] = t;
- mNext[t] = mPos;
- t = mNext[r];
- mNext[mPos] = t;
- mPrev[t] = mPos;
- mParent[mPos] = q;
- mParent[r] = NIL;
+ LoopVar10 = mPrev[LoopVar4];
+ mPrev[mPos] = LoopVar10;
+ mNext[LoopVar10] = mPos;
+ LoopVar10 = mNext[LoopVar4];
+ mNext[mPos] = LoopVar10;
+ mPrev[LoopVar10] = mPos;
+ mParent[mPos] = LoopVar6;
+ mParent[LoopVar4] = NIL;
//
// Special usage of 'next'
//
- mNext[r] = mPos;
+ mNext[LoopVar4] = mPos;
}
+/**
+ Delete outdated string info. (The Usage of PERC_FLAG
+ ensures a clean deletion).
+
+**/
VOID
EFIAPI
DeleteNode (
VOID
)
-/*++
-
-Routine Description:
-
- Delete outdated string info. (The Usage of PERC_FLAG
- ensures a clean deletion)
-
-Arguments: (VOID)
-
-Returns: (VOID)
-
-**/
{
- NODE q;
+ NODE LoopVar6;
- NODE r;
+ NODE LoopVar4;
- NODE s;
+ NODE LoopVar11;
- NODE t;
+ NODE LoopVar10;
- NODE u;
+ NODE LoopVar9;
if (mParent[mPos] == NIL) {
return ;
}
- r = mPrev[mPos];
- s = mNext[mPos];
- mNext[r] = s;
- mPrev[s] = r;
- r = mParent[mPos];
+ LoopVar4 = mPrev[mPos];
+ LoopVar11 = mNext[mPos];
+ mNext[LoopVar4] = LoopVar11;
+ mPrev[LoopVar11] = LoopVar4;
+ LoopVar4 = mParent[mPos];
mParent[mPos] = NIL;
- if (r >= WNDSIZ) {
+ if (LoopVar4 >= WNDSIZ) {
return ;
}
- mChildCount[r]--;
- if (mChildCount[r] > 1) {
+ mChildCount[LoopVar4]--;
+ if (mChildCount[LoopVar4] > 1) {
return ;
}
- t = (NODE) (mPosition[r] & ~PERC_FLAG);
- if (t >= mPos) {
- t -= WNDSIZ;
+ LoopVar10 = (NODE) (mPosition[LoopVar4] & ~PERC_FLAG);
+ if (LoopVar10 >= mPos) {
+ LoopVar10 -= WNDSIZ;
}
- s = t;
- q = mParent[r];
- u = mPosition[q];
- while ((u & PERC_FLAG) != 0){
- u &= ~PERC_FLAG;
- if (u >= mPos) {
- u -= WNDSIZ;
+ LoopVar11 = LoopVar10;
+ LoopVar6 = mParent[LoopVar4];
+ LoopVar9 = mPosition[LoopVar6];
+ while ((LoopVar9 & PERC_FLAG) != 0){
+ LoopVar9 &= ~PERC_FLAG;
+ if (LoopVar9 >= mPos) {
+ LoopVar9 -= WNDSIZ;
}
- if (u > s) {
- s = u;
+ if (LoopVar9 > LoopVar11) {
+ LoopVar11 = LoopVar9;
}
- mPosition[q] = (NODE) (s | WNDSIZ);
- q = mParent[q];
- u = mPosition[q];
+ mPosition[LoopVar6] = (NODE) (LoopVar11 | WNDSIZ);
+ LoopVar6 = mParent[LoopVar6];
+ LoopVar9 = mPosition[LoopVar6];
}
- if (q < WNDSIZ) {
- if (u >= mPos) {
- u -= WNDSIZ;
+ if (LoopVar6 < WNDSIZ) {
+ if (LoopVar9 >= mPos) {
+ LoopVar9 -= WNDSIZ;
}
- if (u > s) {
- s = u;
+ if (LoopVar9 > LoopVar11) {
+ LoopVar11 = LoopVar9;
}
- mPosition[q] = (NODE) (s | WNDSIZ | PERC_FLAG);
+ mPosition[LoopVar6] = (NODE) (LoopVar11 | WNDSIZ | PERC_FLAG);
}
- s = Child (r, mText[t + mLevel[r]]);
- t = mPrev[s];
- u = mNext[s];
- mNext[t] = u;
- mPrev[u] = t;
- t = mPrev[r];
- mNext[t] = s;
- mPrev[s] = t;
- t = mNext[r];
- mPrev[t] = s;
- mNext[s] = t;
- mParent[s] = mParent[r];
- mParent[r] = NIL;
- mNext[r] = mAvail;
- mAvail = r;
+ LoopVar11 = Child (LoopVar4, mText[LoopVar10 + mLevel[LoopVar4]]);
+ LoopVar10 = mPrev[LoopVar11];
+ LoopVar9 = mNext[LoopVar11];
+ mNext[LoopVar10] = LoopVar9;
+ mPrev[LoopVar9] = LoopVar10;
+ LoopVar10 = mPrev[LoopVar4];
+ mNext[LoopVar10] = LoopVar11;
+ mPrev[LoopVar11] = LoopVar10;
+ LoopVar10 = mNext[LoopVar4];
+ mPrev[LoopVar10] = LoopVar11;
+ mNext[LoopVar11] = LoopVar10;
+ mParent[LoopVar11] = mParent[LoopVar4];
+ mParent[LoopVar4] = NIL;
+ mNext[LoopVar4] = mAvail;
+ mAvail = LoopVar4;
}
-VOID
+/**
+ Read in source data
+
+ @param[out] LoopVar7 The buffer to hold the data.
+ @param[in] LoopVar8 The number of bytes to read.
+
+ @return The number of bytes actually read.
+**/
+INT32
EFIAPI
-GetNextMatch (
- VOID
+FreadCrc (
+ OUT UINT8 *LoopVar7,
+ IN INT32 LoopVar8
)
-/*++
+{
+ INT32 LoopVar1;
-Routine Description:
+ for (LoopVar1 = 0; mSrc < mSrcUpperLimit && LoopVar1 < LoopVar8; LoopVar1++) {
+ *LoopVar7++ = *mSrc++;
+ }
- Advance the current position (read in new data if needed).
- Delete outdated string info. Find a match string for current position.
+ LoopVar8 = LoopVar1;
+
+ LoopVar7 -= LoopVar8;
+ mOrigSize += LoopVar8;
+ LoopVar1--;
+ while (LoopVar1 >= 0) {
+ UPDATE_CRC (*LoopVar7++);
+ LoopVar1--;
+ }
-Arguments: (VOID)
+ return LoopVar8;
+}
-Returns: (VOID)
+/**
+ Advance the current position (read in new data if needed).
+ Delete outdated string info. Find a match string for current position.
**/
+VOID
+EFIAPI
+GetNextMatch (
+ VOID
+ )
{
- INT32 n;
+ INT32 LoopVar8;
VOID *Temp;
mRemainder--;
mPos++;
if (mPos == WNDSIZ * 2) {
- Temp = AllocatePool (WNDSIZ + MAXMATCH);
+ Temp = AllocateZeroPool (WNDSIZ + MAXMATCH);
CopyMem (Temp, &mText[WNDSIZ], WNDSIZ + MAXMATCH);
CopyMem (&mText[0], Temp, WNDSIZ + MAXMATCH);
FreePool (Temp);
- n = FreadCrc (&mText[WNDSIZ + MAXMATCH], WNDSIZ);
- mRemainder += n;
+ LoopVar8 = FreadCrc (&mText[WNDSIZ + MAXMATCH], WNDSIZ);
+ mRemainder += LoopVar8;
mPos = WNDSIZ;
}
@@ -870,128 +635,350 @@ Returns: (VOID) InsertNode ();
}
-EFI_STATUS
+/**
+ Send entry LoopVar1 down the queue.
+
+ @param[in] LoopVar1 The index of the item to move.
+**/
+VOID
EFIAPI
-Encode (
- VOID
+DownHeap (
+ IN INT32 i
)
-/*++
+{
+ INT32 LoopVar1;
-Routine Description:
+ INT32 LoopVar2;
- The main controlling routine for compression process.
+ //
+ // priority queue: send i-th entry down heap
+ //
+ LoopVar2 = mHeap[i];
+ LoopVar1 = 2 * i;
+ while (LoopVar1 <= mHeapSize) {
+ if (LoopVar1 < mHeapSize && mFreq[mHeap[LoopVar1]] > mFreq[mHeap[LoopVar1 + 1]]) {
+ LoopVar1++;
+ }
-Arguments: (VOID)
+ if (mFreq[LoopVar2] <= mFreq[mHeap[LoopVar1]]) {
+ break;
+ }
-Returns:
+ mHeap[i] = mHeap[LoopVar1];
+ i = LoopVar1;
+ LoopVar1 = 2 * i;
+ }
- EFI_SUCCESS - The compression is successful
- EFI_OUT_0F_RESOURCES - Not enough memory for compression process
+ mHeap[i] = (INT16) LoopVar2;
+}
+/**
+ Count the number of each code length for a Huffman tree.
+
+ @param[in] LoopVar1 The top node.
**/
+VOID
+EFIAPI
+CountLen (
+ IN INT32 LoopVar1
+ )
{
- EFI_STATUS Status;
- INT32 LastMatchLen;
- NODE LastMatchPos;
+ if (LoopVar1 < mTempInt32) {
+ mLenCnt[(mHuffmanDepth < 16) ? mHuffmanDepth : 16]++;
+ } else {
+ mHuffmanDepth++;
+ CountLen (mLeft[LoopVar1]);
+ CountLen (mRight[LoopVar1]);
+ mHuffmanDepth--;
+ }
+}
- Status = AllocateMemory ();
- if (EFI_ERROR (Status)) {
- FreeMemory ();
- return Status;
+/**
+ Create code length array for a Huffman tree.
+
+ @param[in] Root The root of the tree.
+**/
+VOID
+EFIAPI
+MakeLen (
+ IN INT32 Root
+ )
+{
+ INT32 LoopVar1;
+
+ INT32 LoopVar2;
+ UINT32 Cum;
+
+ for (LoopVar1 = 0; LoopVar1 <= 16; LoopVar1++) {
+ mLenCnt[LoopVar1] = 0;
}
- InitSlide ();
+ CountLen (Root);
- HufEncodeStart ();
+ //
+ // Adjust the length count array so that
+ // no code will be generated longer than its designated length
+ //
+ Cum = 0;
+ for (LoopVar1 = 16; LoopVar1 > 0; LoopVar1--) {
+ Cum += mLenCnt[LoopVar1] << (16 - LoopVar1);
+ }
- mRemainder = FreadCrc (&mText[WNDSIZ], WNDSIZ + MAXMATCH);
+ while (Cum != (1U << 16)) {
+ mLenCnt[16]--;
+ for (LoopVar1 = 15; LoopVar1 > 0; LoopVar1--) {
+ if (mLenCnt[LoopVar1] != 0) {
+ mLenCnt[LoopVar1]--;
+ mLenCnt[LoopVar1 + 1] += 2;
+ break;
+ }
+ }
- mMatchLen = 0;
- mPos = WNDSIZ;
- InsertNode ();
- if (mMatchLen > mRemainder) {
- mMatchLen = mRemainder;
+ Cum--;
}
- while (mRemainder > 0) {
- LastMatchLen = mMatchLen;
- LastMatchPos = mMatchPos;
- GetNextMatch ();
- if (mMatchLen > mRemainder) {
- mMatchLen = mRemainder;
+ for (LoopVar1 = 16; LoopVar1 > 0; LoopVar1--) {
+ LoopVar2 = mLenCnt[LoopVar1];
+ LoopVar2--;
+ while (LoopVar2 >= 0) {
+ mLen[*mSortPtr++] = (UINT8) LoopVar1;
+ LoopVar2--;
}
+ }
+}
- if (mMatchLen > LastMatchLen || LastMatchLen < THRESHOLD) {
- //
- // Not enough benefits are gained by outputting a pointer,
- // so just output the original character
- //
- CompressOutput(mText[mPos - 1], 0);
+/**
+ Assign code to each symbol based on the code length array.
+
+ @param[in] LoopVar8 The number of symbols.
+ @param[in] Len The code length array.
+ @param[out] Code The stores codes for each symbol.
+**/
+VOID
+EFIAPI
+MakeCode (
+ IN INT32 LoopVar8,
+ IN UINT8 Len[ ],
+ OUT UINT16 Code[ ]
+ )
+{
+ INT32 LoopVar1;
+ UINT16 Start[18];
+
+ Start[1] = 0;
+ for (LoopVar1 = 1; LoopVar1 <= 16; LoopVar1++) {
+ Start[LoopVar1 + 1] = (UINT16) ((Start[LoopVar1] + mLenCnt[LoopVar1]) << 1);
+ }
+
+ for (LoopVar1 = 0; LoopVar1 < LoopVar8; LoopVar1++) {
+ Code[LoopVar1] = Start[Len[LoopVar1]]++;
+ }
+}
+
+/**
+ Generates Huffman codes given a frequency distribution of symbols.
+
+ @param[in] NParm The number of symbols.
+ @param[in] FreqParm The frequency of each symbol.
+ @param[out] LenParm The code length for each symbol.
+ @param[out] CodeParm The code for each symbol.
+
+ @return The root of the Huffman tree.
+**/
+INT32
+EFIAPI
+MakeTree (
+ IN INT32 NParm,
+ IN UINT16 FreqParm[ ],
+ OUT UINT8 LenParm[ ],
+ OUT UINT16 CodeParm[ ]
+ )
+{
+ INT32 LoopVar1;
+
+ INT32 LoopVar2;
+
+ INT32 LoopVar3;
+
+ INT32 Avail;
+
+ //
+ // make tree, calculate len[], return root
+ //
+ mTempInt32 = NParm;
+ mFreq = FreqParm;
+ mLen = LenParm;
+ Avail = mTempInt32;
+ mHeapSize = 0;
+ mHeap[1] = 0;
+ for (LoopVar1 = 0; LoopVar1 < mTempInt32; LoopVar1++) {
+ mLen[LoopVar1] = 0;
+ if ((mFreq[LoopVar1]) != 0) {
+ mHeapSize++;
+ mHeap[mHeapSize] = (INT16) LoopVar1;
+ }
+ }
+
+ if (mHeapSize < 2) {
+ CodeParm[mHeap[1]] = 0;
+ return mHeap[1];
+ }
+
+ for (LoopVar1 = mHeapSize / 2; LoopVar1 >= 1; LoopVar1--) {
+ //
+ // make priority queue
+ //
+ DownHeap (LoopVar1);
+ }
+
+ mSortPtr = CodeParm;
+ do {
+ LoopVar1 = mHeap[1];
+ if (LoopVar1 < mTempInt32) {
+ *mSortPtr++ = (UINT16) LoopVar1;
+ }
+
+ mHeap[1] = mHeap[mHeapSize--];
+ DownHeap (1);
+ LoopVar2 = mHeap[1];
+ if (LoopVar2 < mTempInt32) {
+ *mSortPtr++ = (UINT16) LoopVar2;
+ }
+
+ LoopVar3 = Avail++;
+ mFreq[LoopVar3] = (UINT16) (mFreq[LoopVar1] + mFreq[LoopVar2]);
+ mHeap[1] = (INT16) LoopVar3;
+ DownHeap (1);
+ mLeft[LoopVar3] = (UINT16) LoopVar1;
+ mRight[LoopVar3] = (UINT16) LoopVar2;
+ } while (mHeapSize > 1);
+
+ mSortPtr = CodeParm;
+ MakeLen (LoopVar3);
+ MakeCode (NParm, LenParm, CodeParm);
+
+ //
+ // return root
+ //
+ return LoopVar3;
+}
+
+/**
+ Outputs rightmost LoopVar8 bits of x
+
+ @param[in] LoopVar8 The rightmost LoopVar8 bits of the data is used.
+ @param[in] x The data.
+**/
+VOID
+EFIAPI
+PutBits (
+ IN INT32 LoopVar8,
+ IN UINT32 x
+ )
+{
+ UINT8 Temp;
+
+ if (LoopVar8 < mBitCount) {
+ mSubBitBuf |= x << (mBitCount -= LoopVar8);
+ } else {
+
+ Temp = (UINT8)(mSubBitBuf | (x >> (LoopVar8 -= mBitCount)));
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = Temp;
+ }
+ mCompSize++;
+
+ if (LoopVar8 < UINT8_BIT) {
+ mSubBitBuf = x << (mBitCount = UINT8_BIT - LoopVar8);
} else {
- //
- // Outputting a pointer is beneficial enough, do it.
- //
- CompressOutput(LastMatchLen + (UINT8_MAX + 1 - THRESHOLD),
- (mPos - LastMatchPos - 2) & (WNDSIZ - 1));
- LastMatchLen--;
- while (LastMatchLen > 0) {
- GetNextMatch ();
- LastMatchLen--;
+ Temp = (UINT8)(x >> (LoopVar8 - UINT8_BIT));
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = Temp;
}
+ mCompSize++;
- if (mMatchLen > mRemainder) {
- mMatchLen = mRemainder;
- }
+ mSubBitBuf = x << (mBitCount = 2 * UINT8_BIT - LoopVar8);
}
}
+}
- HufEncodeEnd ();
- FreeMemory ();
- return EFI_SUCCESS;
+/**
+ Encode a signed 32 bit number.
+
+ @param[in] LoopVar5 The number to encode.
+**/
+VOID
+EFIAPI
+EncodeC (
+ IN INT32 LoopVar5
+ )
+{
+ PutBits (mCLen[LoopVar5], mCCode[LoopVar5]);
}
+/**
+ Encode a unsigned 32 bit number.
+
+ @param[in] LoopVar7 The number to encode.
+**/
VOID
EFIAPI
-CountTFreq (
- VOID
+EncodeP (
+ IN UINT32 LoopVar7
)
-/*++
+{
+ UINT32 LoopVar5;
-Routine Description:
+ UINT32 LoopVar6;
- Count the frequencies for the Extra Set
+ LoopVar5 = 0;
+ LoopVar6 = LoopVar7;
+ while (LoopVar6 != 0) {
+ LoopVar6 >>= 1;
+ LoopVar5++;
+ }
-Arguments: (VOID)
+ PutBits (mPTLen[LoopVar5], mPTCode[LoopVar5]);
+ if (LoopVar5 > 1) {
+ PutBits(LoopVar5 - 1, LoopVar7 & (0xFFFFU >> (17 - LoopVar5)));
+ }
+}
-Returns: (VOID)
+/**
+ Count the frequencies for the Extra Set.
**/
+VOID
+EFIAPI
+CountTFreq (
+ VOID
+ )
{
- INT32 i;
+ INT32 LoopVar1;
- INT32 k;
+ INT32 LoopVar3;
- INT32 n;
+ INT32 LoopVar8;
INT32 Count;
- for (i = 0; i < NT; i++) {
- mTFreq[i] = 0;
+ for (LoopVar1 = 0; LoopVar1 < NT; LoopVar1++) {
+ mTFreq[LoopVar1] = 0;
}
- n = NC;
- while (n > 0 && mCLen[n - 1] == 0) {
- n--;
+ LoopVar8 = NC;
+ while (LoopVar8 > 0 && mCLen[LoopVar8 - 1] == 0) {
+ LoopVar8--;
}
- i = 0;
- while (i < n) {
- k = mCLen[i++];
- if (k == 0) {
+ LoopVar1 = 0;
+ while (LoopVar1 < LoopVar8) {
+ LoopVar3 = mCLen[LoopVar1++];
+ if (LoopVar3 == 0) {
Count = 1;
- while (i < n && mCLen[i] == 0) {
- i++;
+ while (LoopVar1 < LoopVar8 && mCLen[LoopVar1] == 0) {
+ LoopVar1++;
Count++;
}
@@ -1006,106 +993,92 @@ Returns: (VOID) mTFreq[2]++;
}
} else {
- ASSERT((k+2)<(2 * NT - 1));
- mTFreq[k + 2]++;
+ ASSERT((LoopVar3+2)<(2 * NT - 1));
+ mTFreq[LoopVar3 + 2]++;
}
}
}
+/**
+ Outputs the code length array for the Extra Set or the Position Set.
+
+ @param[in] LoopVar8 The number of symbols.
+ @param[in] nbit The number of bits needed to represent 'LoopVar8'.
+ @param[in] Special The special symbol that needs to be take care of.
+
+**/
VOID
EFIAPI
WritePTLen (
- IN INT32 n,
+ IN INT32 LoopVar8,
IN INT32 nbit,
IN INT32 Special
)
-/*++
-
-Routine Description:
-
- Outputs the code length array for the Extra Set or the Position Set.
-
-Arguments:
-
- n - the number of symbols
- nbit - the number of bits needed to represent 'n'
- Special - the special symbol that needs to be take care of
-
-Returns: (VOID)
-
-**/
{
- INT32 i;
+ INT32 LoopVar1;
- INT32 k;
+ INT32 LoopVar3;
- while (n > 0 && mPTLen[n - 1] == 0) {
- n--;
+ while (LoopVar8 > 0 && mPTLen[LoopVar8 - 1] == 0) {
+ LoopVar8--;
}
- PutBits (nbit, n);
- i = 0;
- while (i < n) {
- k = mPTLen[i++];
- if (k <= 6) {
- PutBits (3, k);
+ PutBits (nbit, LoopVar8);
+ LoopVar1 = 0;
+ while (LoopVar1 < LoopVar8) {
+ LoopVar3 = mPTLen[LoopVar1++];
+ if (LoopVar3 <= 6) {
+ PutBits (3, LoopVar3);
} else {
- PutBits (k - 3, (1U << (k - 3)) - 2);
+ PutBits (LoopVar3 - 3, (1U << (LoopVar3 - 3)) - 2);
}
- if (i == Special) {
- while (i < 6 && mPTLen[i] == 0) {
- i++;
+ if (LoopVar1 == Special) {
+ while (LoopVar1 < 6 && mPTLen[LoopVar1] == 0) {
+ LoopVar1++;
}
- PutBits (2, (i - 3) & 3);
+ PutBits (2, (LoopVar1 - 3) & 3);
}
}
}
+/**
+ Outputs the code length array for Char&Length Set
+
+**/
VOID
EFIAPI
WriteCLen (
VOID
)
-/*++
-
-Routine Description:
-
- Outputs the code length array for Char&Length Set
-
-Arguments: (VOID)
-
-Returns: (VOID)
-
-**/
{
- INT32 i;
+ INT32 LoopVar1;
- INT32 k;
+ INT32 LoopVar3;
- INT32 n;
+ INT32 LoopVar8;
INT32 Count;
- n = NC;
- while (n > 0 && mCLen[n - 1] == 0) {
- n--;
+ LoopVar8 = NC;
+ while (LoopVar8 > 0 && mCLen[LoopVar8 - 1] == 0) {
+ LoopVar8--;
}
- PutBits (CBIT, n);
- i = 0;
- while (i < n) {
- k = mCLen[i++];
- if (k == 0) {
+ PutBits (CBIT, LoopVar8);
+ LoopVar1 = 0;
+ while (LoopVar1 < LoopVar8) {
+ LoopVar3 = mCLen[LoopVar1++];
+ if (LoopVar3 == 0) {
Count = 1;
- while (i < n && mCLen[i] == 0) {
- i++;
+ while (LoopVar1 < LoopVar8 && mCLen[LoopVar1] == 0) {
+ LoopVar1++;
Count++;
}
if (Count <= 2) {
- for (k = 0; k < Count; k++) {
+ for (LoopVar3 = 0; LoopVar3 < Count; LoopVar3++) {
PutBits (mPTLen[0], mPTCode[0]);
}
} else if (Count <= 18) {
@@ -1120,68 +1093,25 @@ Returns: (VOID) PutBits (CBIT, Count - 20);
}
} else {
- ASSERT((k+2)<NPT);
- PutBits (mPTLen[k + 2], mPTCode[k + 2]);
+ ASSERT((LoopVar3+2)<NPT);
+ PutBits (mPTLen[LoopVar3 + 2], mPTCode[LoopVar3 + 2]);
}
}
}
-VOID
-EFIAPI
-EncodeC (
- IN INT32 c
- )
-{
- PutBits (mCLen[c], mCCode[c]);
-}
-
-VOID
-EFIAPI
-EncodeP (
- IN UINT32 p
- )
-{
- UINT32 c;
-
- UINT32 q;
-
- c = 0;
- q = p;
- while (q != 0) {
- q >>= 1;
- c++;
- }
-
- PutBits (mPTLen[c], mPTCode[c]);
- if (c > 1) {
- PutBits(c - 1, p & (0xFFFFU >> (17 - c)));
- }
-}
+/**
+ Huffman code the block and output it.
+**/
VOID
EFIAPI
SendBlock (
VOID
)
-/*++
-
-Routine Description:
-
- Huffman code the block and output it.
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
-**/
{
- UINT32 i;
+ UINT32 LoopVar1;
- UINT32 k;
+ UINT32 LoopVar3;
UINT32 Flags;
@@ -1222,18 +1152,18 @@ Returns: }
Pos = 0;
- for (i = 0; i < Size; i++) {
- if (i % UINT8_BIT == 0) {
+ for (LoopVar1 = 0; LoopVar1 < Size; LoopVar1++) {
+ if (LoopVar1 % UINT8_BIT == 0) {
Flags = mBuf[Pos++];
} else {
Flags <<= 1;
}
if ((Flags & (1U << (UINT8_BIT - 1))) != 0){
EncodeC(mBuf[Pos++] + (1U << UINT8_BIT));
- k = mBuf[Pos++] << UINT8_BIT;
- k += mBuf[Pos++];
+ LoopVar3 = mBuf[Pos++] << UINT8_BIT;
+ LoopVar3 += mBuf[Pos++];
- EncodeP (k);
+ EncodeP (LoopVar3);
} else {
EncodeC (mBuf[Pos++]);
}
@@ -1243,26 +1173,38 @@ Returns: SetMem (mPFreq, NP * sizeof (UINT16), 0);
}
+/**
+ Start the huffman encoding.
+
+**/
VOID
EFIAPI
-CompressOutput (
- IN UINT32 c,
- IN UINT32 p
+HufEncodeStart (
+ VOID
)
-/*++
-
-Routine Description:
-
- Outputs an Original Character or a Pointer
+{
+ SetMem (mCFreq, NC * sizeof (UINT16), 0);
+ SetMem (mPFreq, NP * sizeof (UINT16), 0);
-Arguments:
+ mOutputPos = mOutputMask = 0;
- c - The original character or the 'String Length' element of a Pointer
- p - The 'Position' field of a Pointer
+ mBitCount = UINT8_BIT;
+ mSubBitBuf = 0;
+}
-Returns: (VOID)
+/**
+ Outputs an Original Character or a Pointer.
+ @param[in] LoopVar5 The original character or the 'String Length' element of
+ a Pointer.
+ @param[in] LoopVar7 The 'Position' field of a Pointer.
**/
+VOID
+EFIAPI
+CompressOutput (
+ IN UINT32 LoopVar5,
+ IN UINT32 LoopVar7
+ )
{
STATIC UINT32 CPos;
@@ -1276,35 +1218,25 @@ Returns: (VOID) CPos = mOutputPos++;
mBuf[CPos] = 0;
}
- mBuf[mOutputPos++] = (UINT8) c;
- mCFreq[c]++;
- if (c >= (1U << UINT8_BIT)) {
+ mBuf[mOutputPos++] = (UINT8) LoopVar5;
+ mCFreq[LoopVar5]++;
+ if (LoopVar5 >= (1U << UINT8_BIT)) {
mBuf[CPos] = (UINT8)(mBuf[CPos]|mOutputMask);
- mBuf[mOutputPos++] = (UINT8)(p >> UINT8_BIT);
- mBuf[mOutputPos++] = (UINT8) p;
- c = 0;
- while (p!=0) {
- p >>= 1;
- c++;
+ mBuf[mOutputPos++] = (UINT8)(LoopVar7 >> UINT8_BIT);
+ mBuf[mOutputPos++] = (UINT8) LoopVar7;
+ LoopVar5 = 0;
+ while (LoopVar7!=0) {
+ LoopVar7 >>= 1;
+ LoopVar5++;
}
- mPFreq[c]++;
+ mPFreq[LoopVar5]++;
}
}
-VOID
-EFIAPI
-HufEncodeStart (
- VOID
- )
-{
- SetMem (mCFreq, NC * sizeof (UINT16), 0);
- SetMem (mPFreq, NP * sizeof (UINT16), 0);
-
- mOutputPos = mOutputMask = 0;
- InitPutBits ();
- return ;
-}
+/**
+ End the huffman encoding.
+**/
VOID
EFIAPI
HufEncodeEnd (
@@ -1317,395 +1249,160 @@ HufEncodeEnd ( // Flush remaining bits
//
PutBits (UINT8_BIT - 1, 0);
-
- return ;
}
-VOID
+/**
+ The main controlling routine for compression process.
+
+ @retval EFI_SUCCESS The compression is successful.
+ @retval EFI_OUT_0F_RESOURCES Not enough memory for compression process.
+**/
+EFI_STATUS
EFIAPI
-MakeCrcTable (
+Encode (
VOID
)
{
- UINT32 i;
-
- UINT32 j;
-
- UINT32 r;
-
- for (i = 0; i <= UINT8_MAX; i++) {
- r = i;
- for (j = 0; j < UINT8_BIT; j++) {
- if ((r & 1) != 0) {
- r = (r >> 1) ^ CRCPOLY;
- } else {
- r >>= 1;
- }
- }
+ EFI_STATUS Status;
+ INT32 LastMatchLen;
+ NODE LastMatchPos;
- mCrcTable[i] = (UINT16) r;
+ Status = AllocateMemory ();
+ if (EFI_ERROR (Status)) {
+ FreeMemory ();
+ return Status;
}
-}
-VOID
-EFIAPI
-PutBits (
- IN INT32 n,
- IN UINT32 x
- )
-/*++
-
-Routine Description:
-
- Outputs rightmost n bits of x
-
-Arguments:
-
- n - the rightmost n bits of the data is used
- x - the data
-
-Returns:
+ InitSlide ();
- None
+ HufEncodeStart ();
-**/
-{
- UINT8 Temp;
+ mRemainder = FreadCrc (&mText[WNDSIZ], WNDSIZ + MAXMATCH);
- if (n < mBitCount) {
- mSubBitBuf |= x << (mBitCount -= n);
- } else {
+ mMatchLen = 0;
+ mPos = WNDSIZ;
+ InsertNode ();
+ if (mMatchLen > mRemainder) {
+ mMatchLen = mRemainder;
+ }
- Temp = (UINT8)(mSubBitBuf | (x >> (n -= mBitCount)));
- if (mDst < mDstUpperLimit) {
- *mDst++ = Temp;
+ while (mRemainder > 0) {
+ LastMatchLen = mMatchLen;
+ LastMatchPos = mMatchPos;
+ GetNextMatch ();
+ if (mMatchLen > mRemainder) {
+ mMatchLen = mRemainder;
}
- mCompSize++;
- if (n < UINT8_BIT) {
- mSubBitBuf = x << (mBitCount = UINT8_BIT - n);
+ if (mMatchLen > LastMatchLen || LastMatchLen < THRESHOLD) {
+ //
+ // Not enough benefits are gained by outputting a pointer,
+ // so just output the original character
+ //
+ CompressOutput(mText[mPos - 1], 0);
} else {
+ //
+ // Outputting a pointer is beneficial enough, do it.
+ //
- Temp = (UINT8)(x >> (n - UINT8_BIT));
- if (mDst < mDstUpperLimit) {
- *mDst++ = Temp;
+ CompressOutput(LastMatchLen + (UINT8_MAX + 1 - THRESHOLD),
+ (mPos - LastMatchPos - 2) & (WNDSIZ - 1));
+ LastMatchLen--;
+ while (LastMatchLen > 0) {
+ GetNextMatch ();
+ LastMatchLen--;
}
- mCompSize++;
- mSubBitBuf = x << (mBitCount = 2 * UINT8_BIT - n);
+ if (mMatchLen > mRemainder) {
+ mMatchLen = mRemainder;
+ }
}
}
-}
-
-INT32
-EFIAPI
-FreadCrc (
- OUT UINT8 *p,
- IN INT32 n
- )
-/*++
-
-Routine Description:
-
- Read in source data
-
-Arguments:
-
- p - the buffer to hold the data
- n - number of bytes to read
-
-Returns:
-
- number of bytes actually read
-
-**/
-{
- INT32 i;
-
- for (i = 0; mSrc < mSrcUpperLimit && i < n; i++) {
- *p++ = *mSrc++;
- }
-
- n = i;
- p -= n;
- mOrigSize += n;
- i--;
- while (i >= 0) {
- UPDATE_CRC (*p++);
- i--;
- }
-
- return n;
-}
-
-VOID
-EFIAPI
-InitPutBits (
- VOID
- )
-{
- mBitCount = UINT8_BIT;
- mSubBitBuf = 0;
+ HufEncodeEnd ();
+ FreeMemory ();
+ return EFI_SUCCESS;
}
-VOID
-EFIAPI
-CountLen (
- IN INT32 i
- )
-/*++
-
-Routine Description:
-
- Count the number of each code length for a Huffman tree.
-
-Arguments:
-
- i - the top node
+/**
+ The compression routine.
-Returns: (VOID)
+ @param[in] SrcBuffer The buffer containing the source data.
+ @param[in] SrcSize The number of bytes in SrcBuffer.
+ @param[in] DstBuffer The buffer to put the compressed image in.
+ @param[in,out] DstSize On input the size (in bytes) of DstBuffer, on
+ return the number of bytes placed in DstBuffer.
+ @retval EFI_SUCCESS The compression was sucessful.
+ @retval EFI_BUFFER_TOO_SMALL The buffer was too small. DstSize is required.
**/
-{
- STATIC INT32 Depth = 0;
-
- if (i < mN) {
- mLenCnt[(Depth < 16) ? Depth : 16]++;
- } else {
- Depth++;
- CountLen (mLeft[i]);
- CountLen (mRight[i]);
- Depth--;
- }
-}
-
-VOID
+EFI_STATUS
EFIAPI
-MakeLen (
- IN INT32 Root
+Compress (
+ IN VOID *SrcBuffer,
+ IN UINT64 SrcSize,
+ IN VOID *DstBuffer,
+ IN OUT UINT64 *DstSize
)
-/*++
-
-Routine Description:
-
- Create code length array for a Huffman tree
-
-Arguments:
-
- Root - the root of the tree
-
-Returns:
-
- None
-
-**/
{
- INT32 i;
-
- INT32 k;
- UINT32 Cum;
-
- for (i = 0; i <= 16; i++) {
- mLenCnt[i] = 0;
- }
-
- CountLen (Root);
+ EFI_STATUS Status;
//
- // Adjust the length count array so that
- // no code will be generated longer than its designated length
+ // Initializations
//
- Cum = 0;
- for (i = 16; i > 0; i--) {
- Cum += mLenCnt[i] << (16 - i);
- }
-
- while (Cum != (1U << 16)) {
- mLenCnt[16]--;
- for (i = 15; i > 0; i--) {
- if (mLenCnt[i] != 0) {
- mLenCnt[i]--;
- mLenCnt[i + 1] += 2;
- break;
- }
- }
+ mBufSiz = 0;
+ mBuf = NULL;
+ mText = NULL;
+ mLevel = NULL;
+ mChildCount = NULL;
+ mPosition = NULL;
+ mParent = NULL;
+ mPrev = NULL;
+ mNext = NULL;
- Cum--;
- }
+ mSrc = SrcBuffer;
+ mSrcUpperLimit = mSrc + SrcSize;
+ mDst = DstBuffer;
+ mDstUpperLimit = mDst +*DstSize;
- for (i = 16; i > 0; i--) {
- k = mLenCnt[i];
- k--;
- while (k >= 0) {
- mLen[*mSortPtr++] = (UINT8) i;
- k--;
- }
- }
-}
+ PutDword (0L);
+ PutDword (0L);
-VOID
-EFIAPI
-DownHeap (
- IN INT32 i
- )
-{
- INT32 j;
+ MakeCrcTable ();
- INT32 k;
+ mOrigSize = mCompSize = 0;
+ mCrc = INIT_CRC;
//
- // priority queue: send i-th entry down heap
+ // Compress it
//
- k = mHeap[i];
- j = 2 * i;
- while (j <= mHeapSize) {
- if (j < mHeapSize && mFreq[mHeap[j]] > mFreq[mHeap[j + 1]]) {
- j++;
- }
-
- if (mFreq[k] <= mFreq[mHeap[j]]) {
- break;
- }
-
- mHeap[i] = mHeap[j];
- i = j;
- j = 2 * i;
- }
-
- mHeap[i] = (INT16) k;
-}
-
-VOID
-EFIAPI
-MakeCode (
- IN INT32 n,
- IN UINT8 Len[ ],
- OUT UINT16 Code[ ]
- )
-/*++
-
-Routine Description:
-
- Assign code to each symbol based on the code length array
-
-Arguments:
-
- n - number of symbols
- Len - the code length array
- Code - stores codes for each symbol
-
-Returns:
-
- None
-
-**/
-{
- INT32 i;
- UINT16 Start[18];
-
- Start[1] = 0;
- for (i = 1; i <= 16; i++) {
- Start[i + 1] = (UINT16) ((Start[i] + mLenCnt[i]) << 1);
- }
-
- for (i = 0; i < n; i++) {
- Code[i] = Start[Len[i]]++;
+ Status = Encode ();
+ if (EFI_ERROR (Status)) {
+ return EFI_OUT_OF_RESOURCES;
}
-}
-
-INT32
-EFIAPI
-MakeTree (
- IN INT32 NParm,
- IN UINT16 FreqParm[ ],
- OUT UINT8 LenParm[ ],
- OUT UINT16 CodeParm[ ]
- )
-/*++
-
-Routine Description:
-
- Generates Huffman codes given a frequency distribution of symbols
-
-Arguments:
-
- NParm - number of symbols
- FreqParm - frequency of each symbol
- LenParm - code length for each symbol
- CodeParm - code for each symbol
-
-Returns:
-
- Root of the Huffman tree.
-
-**/
-{
- INT32 i;
-
- INT32 j;
-
- INT32 k;
-
- INT32 Avail;
-
//
- // make tree, calculate len[], return root
+ // Null terminate the compressed data
//
- mN = NParm;
- mFreq = FreqParm;
- mLen = LenParm;
- Avail = mN;
- mHeapSize = 0;
- mHeap[1] = 0;
- for (i = 0; i < mN; i++) {
- mLen[i] = 0;
- if ((mFreq[i]) != 0) {
- mHeapSize++;
- mHeap[mHeapSize] = (INT16) i;
- }
- }
-
- if (mHeapSize < 2) {
- CodeParm[mHeap[1]] = 0;
- return mHeap[1];
- }
-
- for (i = mHeapSize / 2; i >= 1; i--) {
- //
- // make priority queue
- //
- DownHeap (i);
+ if (mDst < mDstUpperLimit) {
+ *mDst++ = 0;
}
-
- mSortPtr = CodeParm;
- do {
- i = mHeap[1];
- if (i < mN) {
- *mSortPtr++ = (UINT16) i;
- }
-
- mHeap[1] = mHeap[mHeapSize--];
- DownHeap (1);
- j = mHeap[1];
- if (j < mN) {
- *mSortPtr++ = (UINT16) j;
- }
-
- k = Avail++;
- mFreq[k] = (UINT16) (mFreq[i] + mFreq[j]);
- mHeap[1] = (INT16) k;
- DownHeap (1);
- mLeft[k] = (UINT16) i;
- mRight[k] = (UINT16) j;
- } while (mHeapSize > 1);
-
- mSortPtr = CodeParm;
- MakeLen (k);
- MakeCode (NParm, LenParm, CodeParm);
+ //
+ // Fill in compressed size and original size
+ //
+ mDst = DstBuffer;
+ PutDword (mCompSize + 1);
+ PutDword (mOrigSize);
//
- // return root
+ // Return
//
- return k;
+ if (mCompSize + 1 + 8 > *DstSize) {
+ *DstSize = mCompSize + 1 + 8;
+ return EFI_BUFFER_TOO_SMALL;
+ } else {
+ *DstSize = mCompSize + 1 + 8;
+ return EFI_SUCCESS;
+ }
+
}
+
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.h index 29f0a53fe3..64e339cf97 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.h +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.h @@ -1,7 +1,7 @@ /** @file
Header file for compression routine.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -19,7 +19,7 @@ The compression routine.
@param[in] SrcBuffer The buffer containing the source data.
- @param[in] SrcSizae Number of bytes in SrcBuffer.
+ @param[in] SrcSize Number of bytes in SrcBuffer.
@param[in] DstBuffer The buffer to put the compressed image in.
@param[in,out] DstSize On input the size (in bytes) of DstBuffer, on
return the number of bytes placed in DstBuffer.
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c index 96da304483..4e49d2120b 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c @@ -1,7 +1,7 @@ /** @file
Main file for Dblk shell Debug1 function.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -15,6 +15,15 @@ #include "UefiShellDebug1CommandsLib.h"
#include <Protocol/BlockIo.h>
+/**
+ Display blocks to the screen.
+
+ @param[in] DevPath The device path to get the blocks from.
+ @param[in] Lba The Lba number to start from.
+ @param[in] BlockCount How many blocks to display.
+
+ @retval SHELL_SUCCESS The display was successful.
+**/
SHELL_STATUS
EFIAPI
DisplayTheBlocks(
@@ -24,7 +33,6 @@ DisplayTheBlocks( )
{
EFI_BLOCK_IO_PROTOCOL *BlockIo;
- EFI_DEVICE_PATH_PROTOCOL *Copy;
EFI_HANDLE BlockIoHandle;
EFI_STATUS Status;
SHELL_STATUS ShellStatus;
@@ -32,23 +40,38 @@ DisplayTheBlocks( UINTN BufferSize;
ShellStatus = SHELL_SUCCESS;
- Copy = (EFI_DEVICE_PATH_PROTOCOL *)DevPath;
- Status = gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid, &Copy, &BlockIoHandle);
- ASSERT_EFI_ERROR(Status);
+ Status = gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid, &((EFI_DEVICE_PATH_PROTOCOL *)DevPath), &BlockIoHandle);
+ if (EFI_ERROR(Status)) {
+ return (SHELL_NOT_FOUND);
+ }
Status = gBS->OpenProtocol(BlockIoHandle, &gEfiBlockIoProtocolGuid, (VOID**)&BlockIo, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status)) {
+ return (SHELL_NOT_FOUND);
+ }
BufferSize = BlockIo->Media->BlockSize * BlockCount;
if (BufferSize > 0) {
- Buffer = AllocatePool(BufferSize);
+ Buffer = AllocateZeroPool(BufferSize);
} else {
+ ShellPrintEx(-1,-1,L" BlockSize: 0x%08x, BlockCount: 0x%08x\r\n", BlockIo->Media->BlockSize, BlockCount);
Buffer = NULL;
}
Status = BlockIo->ReadBlocks(BlockIo, BlockIo->Media->MediaId, Lba, BufferSize, Buffer);
if (!EFI_ERROR(Status) && Buffer != NULL) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_DBLK_HEADER),
+ gShellDebug1HiiHandle,
+ Lba,
+ BufferSize,
+ BlockIo
+ );
+
DumpHex(2,0,BufferSize,Buffer);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_READ_FAIL), gShellDebug1HiiHandle, L"BlockIo", Status);
@@ -63,6 +86,12 @@ DisplayTheBlocks( return (ShellStatus);
}
+/**
+ Function for 'dblk' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunDblk (
@@ -70,15 +99,16 @@ ShellCommandRunDblk ( IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Package;
- CHAR16 *ProblemParam;
- SHELL_STATUS ShellStatus;
- CONST CHAR16 *BlockName;
- CONST CHAR16 *LbaString;
- CONST CHAR16 *BlockCountString;
- UINT64 Lba;
- UINT8 BlockCount;
+ EFI_STATUS Status;
+ LIST_ENTRY *Package;
+ CHAR16 *ProblemParam;
+ SHELL_STATUS ShellStatus;
+ CONST CHAR16 *BlockName;
+ CONST CHAR16 *LbaString;
+ CONST CHAR16 *BlockCountString;
+ UINT64 Lba;
+ UINT64 BlockCount;
+ EFI_DEVICE_PATH_PROTOCOL *DevPath;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
@@ -122,26 +152,45 @@ ShellCommandRunDblk ( if (LbaString == NULL) {
Lba = 0;
} else {
- Lba = (UINT64)StrHexToUintn(LbaString);
+ if (!ShellIsHexOrDecimalNumber(LbaString, TRUE, FALSE)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, LbaString);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ ShellConvertStringToUint64(LbaString, &Lba, TRUE, FALSE);
}
if (BlockCountString == NULL) {
BlockCount = 1;
} else {
- BlockCount = (UINT8)StrHexToUintn(BlockCountString);
+ if (!ShellIsHexOrDecimalNumber(BlockCountString, TRUE, FALSE)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, BlockCountString);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ ShellConvertStringToUint64(BlockCountString, &BlockCount, TRUE, FALSE);
if (BlockCount > 0x10) {
BlockCount = 0x10;
+ } else if (BlockCount == 0) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, BlockCountString);
+ ShellStatus = SHELL_INVALID_PARAMETER;
}
}
-
- //
- // do the work if we have a valid block identifier
- //
- if (mEfiShellProtocol->GetDevicePathFromMap(BlockName) == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, BlockName);
- ShellStatus = SHELL_INVALID_PARAMETER;
- } else {
- ShellStatus = DisplayTheBlocks(mEfiShellProtocol->GetDevicePathFromMap(BlockName), Lba, BlockCount);
+
+ if (ShellStatus == SHELL_SUCCESS) {
+ //
+ // do the work if we have a valid block identifier
+ //
+ if (mEfiShellProtocol->GetDevicePathFromMap(BlockName) == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, BlockName);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ DevPath = (EFI_DEVICE_PATH_PROTOCOL*)mEfiShellProtocol->GetDevicePathFromMap(BlockName);
+ if (gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid, &DevPath, NULL) == EFI_NOT_FOUND) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MAP_PROTOCOL), gShellDebug1HiiHandle, BlockName, L"BlockIo");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ ShellStatus = DisplayTheBlocks(mEfiShellProtocol->GetDevicePathFromMap(BlockName), Lba, (UINT8)BlockCount);
+ }
+ }
}
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c index b8ab9c69e6..0229450528 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c @@ -1,7 +1,7 @@ /** @file
Main file for Dmem shell Debug1 function.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -14,8 +14,22 @@ #include "UefiShellDebug1CommandsLib.h"
#include <Protocol/PciRootBridgeIo.h>
+#include <Guid/Acpi.h>
+#include <Guid/Mps.h>
+#include <Guid/SmBios.h>
+#include <Guid/SalSystemTable.h>
+/**
+ Make a printable character.
+
+ If Char is printable then return it, otherwise return a question mark.
+
+ @param[in] Char The character to make printable.
+
+ @return A printable character representing Char.
+**/
CHAR16
+EFIAPI
MakePrintable(
IN CONST CHAR16 Char
)
@@ -26,6 +40,12 @@ MakePrintable( return (Char);
}
+/**
+ Display some Memory-Mapped-IO memory.
+
+ @param[in] Address The starting address to display.
+ @param[in] Size The length of memory to display.
+**/
SHELL_STATUS
EFIAPI
DisplayMmioMemory(
@@ -66,6 +86,12 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { {NULL, TypeMax}
};
+/**
+ Function for 'dmem' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunDmem (
@@ -78,8 +104,14 @@ ShellCommandRunDmem ( CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
VOID *Address;
- UINTN Size;
+ UINT64 Size;
CONST CHAR16 *Temp1;
+ UINT64 AcpiTableAddress;
+ UINT64 Acpi20TableAddress;
+ UINT64 SalTableAddress;
+ UINT64 SmbiosTableAddress;
+ UINT64 MpsTableAddress;
+ UINTN TableWalker;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
@@ -108,26 +140,27 @@ ShellCommandRunDmem ( ASSERT(FALSE);
}
} else {
- Temp1 = ShellCommandLineGetRawValue(Package, 1);
- if (Temp1 == NULL) {
- Address = gST;
- Size = 512;
+ if (ShellCommandLineGetCount(Package) > 3) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- if (!ShellIsHexOrDecimalNumber(Temp1, TRUE, FALSE)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp1);
- ShellStatus = SHELL_INVALID_PARAMETER;
- } else {
- Address = (VOID*)StrHexToUintn(Temp1);
- }
- Temp1 = ShellCommandLineGetRawValue(Package, 2);
+ Temp1 = ShellCommandLineGetRawValue(Package, 1);
if (Temp1 == NULL) {
+ Address = gST;
Size = 512;
} else {
- if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE)) {
+ if (!ShellIsHexOrDecimalNumber(Temp1, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp1, (UINT64*)&Address, TRUE, FALSE))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp1);
ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ Temp1 = ShellCommandLineGetRawValue(Package, 2);
+ if (Temp1 == NULL) {
+ Size = 512;
} else {
- Size = ShellStrToUintn(Temp1);
+ if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp1, &Size, TRUE, FALSE))) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp1);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
}
}
}
@@ -135,9 +168,54 @@ ShellCommandRunDmem ( if (ShellStatus == SHELL_SUCCESS) {
if (!ShellCommandLineGetFlag(Package, L"-mmio")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)Address, Size);
- DumpHex(2,0,Size,Address);
+ DumpHex(2,0,(UINTN)Size,Address);
+ if (Address == (VOID*)gST) {
+ Acpi20TableAddress = 0;
+ AcpiTableAddress = 0;
+ SalTableAddress = 0;
+ SmbiosTableAddress = 0;
+ MpsTableAddress = 0;
+ for (TableWalker = 0 ; TableWalker < gST->NumberOfTableEntries ; TableWalker++) {
+ if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi20TableGuid)) {
+ Acpi20TableAddress = (UINT64)gST->ConfigurationTable[TableWalker].VendorTable;
+ continue;
+ }
+ if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi10TableGuid)) {
+ AcpiTableAddress = (UINT64)gST->ConfigurationTable[TableWalker].VendorTable;
+ continue;
+ }
+ if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSalSystemTableGuid)) {
+ SalTableAddress = (UINT64)gST->ConfigurationTable[TableWalker].VendorTable;
+ continue;
+ }
+ if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSmbiosTableGuid)) {
+ SmbiosTableAddress = (UINT64)gST->ConfigurationTable[TableWalker].VendorTable;
+ continue;
+ }
+ if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiMpsTableGuid)) {
+ MpsTableAddress = (UINT64)gST->ConfigurationTable[TableWalker].VendorTable;
+ continue;
+ }
+ }
+
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_SYSTEM_TABLE), gShellDebug1HiiHandle,
+ (UINT64)Address,
+ gST->Hdr.HeaderSize,
+ gST->Hdr.Revision,
+ (UINT64)gST->ConIn,
+ (UINT64)gST->ConOut,
+ (UINT64)gST->StdErr,
+ (UINT64)gST->RuntimeServices,
+ (UINT64)gST->BootServices,
+ SalTableAddress,
+ AcpiTableAddress,
+ Acpi20TableAddress,
+ MpsTableAddress,
+ SmbiosTableAddress
+ );
+ }
} else {
- ShellStatus = DisplayMmioMemory(Address, Size);
+ ShellStatus = DisplayMmioMemory(Address, (UINTN)Size);
}
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c index 0a586591be..60ced4ee73 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c @@ -1,7 +1,7 @@ /** @file
Main file for DmpStore shell Debug1 function.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -25,6 +25,19 @@ STATIC CHAR16 *AttrType[] = { L"NV+RT+BS", // 111
};
+/**
+ Function to display or delete variables.
+
+ @param[in] VariableName The variable name of the EFI variable (or NULL).
+ @param[in] Guid The GUID of the variable set (or NULL).
+ @param[in] Delete TRUE to delete, FALSE otherwise.
+
+ @retval SHELL_SUCCESS The operation was successful.
+ @retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
+ @retval SHELL_ABORTED The abort message was received.
+ @retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
+ @retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
+**/
SHELL_STATUS
EFIAPI
ProcessVariables (
@@ -44,21 +57,26 @@ ProcessVariables ( UINTN DataSize;
UINT32 Atts;
SHELL_STATUS ShellStatus;
+ BOOLEAN Found;
+
+ Status = gRT->QueryVariableInfo(EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS|EFI_VARIABLE_NON_VOLATILE, &MaxStorSize, &RemStorSize, &MaxVarSize);
+ if (EFI_ERROR(Status)) {
+ return (SHELL_DEVICE_ERROR);
+ }
+ Found = FALSE;
ShellStatus = SHELL_SUCCESS;
Size = PcdGet16(PcdShellFileOperationSize);
- FoundVarName = AllocatePool(Size);
+ FoundVarName = AllocateZeroPool(Size);
if (FoundVarName == NULL) {
return (SHELL_OUT_OF_RESOURCES);
}
FoundVarName[0] = CHAR_NULL;
- Status = gRT->QueryVariableInfo(EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS|EFI_VARIABLE_NON_VOLATILE, &MaxStorSize, &RemStorSize, &MaxVarSize);
- ASSERT_EFI_ERROR(Status);
DataSize = (UINTN)MaxVarSize;
- DataBuffer = AllocatePool(DataSize);
+ DataBuffer = AllocateZeroPool(DataSize);
if (DataBuffer == NULL) {
FreePool(FoundVarName);
return (SHELL_OUT_OF_RESOURCES);
@@ -98,6 +116,7 @@ ProcessVariables ( //
// do the print or delete
//
+ Found = TRUE;
if (!Delete) {
ShellPrintHiiEx(
-1,
@@ -135,8 +154,19 @@ ProcessVariables ( if (DataBuffer != NULL) {
FreePool(DataBuffer);
}
-
- return (SHELL_UNSUPPORTED);
+ if (!Found) {
+ if (VariableName != NULL && Guid == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, VariableName);
+ } else if (VariableName != NULL && Guid != NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, Guid, VariableName);
+ } else if (VariableName == NULL && Guid == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle);
+ } else if (VariableName == NULL && Guid != NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, Guid);
+ }
+ return (SHELL_NOT_FOUND);
+ }
+ return (SHELL_SUCCESS);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
@@ -148,6 +178,12 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { {NULL, TypeMax}
};
+/**
+ Function for 'dmpstore' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunDmpStore (
@@ -177,10 +213,7 @@ ShellCommandRunDmpStore ( ASSERT(FALSE);
}
} else {
- if (ShellCommandLineGetCount(Package) < 1) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
- ShellStatus = SHELL_INVALID_PARAMETER;
- } else if (ShellCommandLineGetCount(Package) > 2) {
+ if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetFlag(Package, L"-all") && ShellCommandLineGetFlag(Package, L"-guid")) {
@@ -195,14 +228,14 @@ ShellCommandRunDmpStore ( if (Temp != NULL) {
Status = ConvertStringToGuid(Temp, &GuidData);
if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"-guid");
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
ShellStatus = SHELL_INVALID_PARAMETER;
}
Guid = &GuidData;
} else {
Guid = &gEfiGlobalVariableGuid;
}
- VariableName = ShellCommandLineGetRawValue(Package, 2);
+ VariableName = ShellCommandLineGetRawValue(Package, 1);
} else {
VariableName = NULL;
Guid = NULL;
@@ -210,9 +243,8 @@ ShellCommandRunDmpStore ( if (ShellStatus == SHELL_SUCCESS) {
if (ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) {
///@todo fix this after Jordan makes lib...
- ShellPrintEx(-1, -1, L"Not implemeneted yet (ASSERT follows).\r\n");
- ShellStatus = SHELL_INVALID_PARAMETER;
- ASSERT(FALSE);
+ ShellPrintEx(-1, -1, L"Not implemeneted yet.\r\n");
+ ShellStatus = SHELL_UNSUPPORTED;
} else {
ShellStatus = ProcessVariables (VariableName, Guid, ShellCommandLineGetFlag(Package, L"-d"));
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index 8d5aabdafc..3f27d1ae0d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -1,7 +1,7 @@ /** @file
Main file for EfiCompress shell Debug1 function.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -15,6 +15,12 @@ #include "UefiShellDebug1CommandsLib.h"
#include "Compress.h"
+/**
+ Function for 'compress' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunEfiCompress (
@@ -76,65 +82,68 @@ ShellCommandRunEfiCompress ( } else {
InFileName = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 1));
OutFileName = ShellCommandLineGetRawValue(Package, 2);
- Status = ShellOpenFileByName(InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);
- ShellStatus = SHELL_NOT_FOUND;
- }
- Status = ShellOpenFileByName(OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
+ if (InFileName == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_NOT_FOUND;
- }
- if (FileHandleIsDirectory(InShellFileHandle) == EFI_SUCCESS){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, InFileName);
- ShellStatus = SHELL_INVALID_PARAMETER;
- }
- if (FileHandleIsDirectory(OutShellFileHandle) == EFI_SUCCESS){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, OutFileName);
- ShellStatus = SHELL_INVALID_PARAMETER;
- }
- Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize);
- ASSERT_EFI_ERROR(Status);
- InBuffer = AllocateZeroPool((UINTN)InSize);
- ASSERT(InBuffer != NULL);
- Status = gEfiShellProtocol->ReadFile(InShellFileHandle, &((UINTN)InSize), InBuffer);
- ASSERT_EFI_ERROR(Status);
- Status = Compress(InBuffer, InSize, OutBuffer, &OutSize);
- if (Status == EFI_BUFFER_TOO_SMALL) {
- OutBuffer = AllocateZeroPool((UINTN)OutSize);
- ASSERT(OutBuffer != NULL);
- Status = Compress(InBuffer, InSize, OutBuffer, &OutSize);
- }
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status);
- ShellStatus = SHELL_DEVICE_ERROR;
} else {
- Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &((UINTN)OutSize), OutBuffer);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status);
- ShellStatus = SHELL_DEVICE_ERROR;
+ if (ShellIsDirectory(InFileName) == EFI_SUCCESS){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, InFileName);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ if (ShellIsDirectory(OutFileName) == EFI_SUCCESS){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, OutFileName);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ if (ShellStatus == SHELL_SUCCESS) {
+ Status = ShellOpenFileByName(InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);
+ ShellStatus = SHELL_NOT_FOUND;
+ }
+ Status = ShellOpenFileByName(OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
+ ShellStatus = SHELL_NOT_FOUND;
+ }
+ }
+ if (ShellStatus == SHELL_SUCCESS) {
+ Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize);
+ ASSERT_EFI_ERROR(Status);
+ InBuffer = AllocateZeroPool((UINTN)InSize);
+ ASSERT(InBuffer != NULL);
+ Status = gEfiShellProtocol->ReadFile(InShellFileHandle, &((UINTN)InSize), InBuffer);
+ ASSERT_EFI_ERROR(Status);
+ Status = Compress(InBuffer, InSize, OutBuffer, &OutSize);
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ OutBuffer = AllocateZeroPool((UINTN)OutSize);
+ ASSERT(OutBuffer != NULL);
+ Status = Compress(InBuffer, InSize, OutBuffer, &OutSize);
+ }
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status);
+ ShellStatus = SHELL_DEVICE_ERROR;
+ } else {
+ Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &((UINTN)OutSize), OutBuffer);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status);
+ ShellStatus = SHELL_DEVICE_ERROR;
+ }
+ }
}
}
}
ShellCommandLineFreeVarList (Package);
}
- if (InFileName != NULL) {
- FreePool(InFileName);
- }
if (InShellFileHandle != NULL) {
gEfiShellProtocol->CloseFile(InShellFileHandle);
}
if (OutShellFileHandle != NULL) {
gEfiShellProtocol->CloseFile(OutShellFileHandle);
}
- if (InBuffer != NULL) {
- FreePool(InBuffer);
- }
- if (OutBuffer != NULL) {
- FreePool(OutBuffer);
- }
+ SHELL_FREE_NON_NULL(InFileName);
+ SHELL_FREE_NON_NULL(InBuffer);
+ SHELL_FREE_NON_NULL(OutBuffer);
return (ShellStatus);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c index 3d01515f05..4b4671b455 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c @@ -16,6 +16,12 @@ #include <Protocol/Decompress.h>
+/**
+ Function for 'decompress' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunEfiDecompress (
@@ -27,8 +33,8 @@ ShellCommandRunEfiDecompress ( LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
- SHELL_FILE_HANDLE InFileHandle;
- SHELL_FILE_HANDLE OutFileHandle;
+ SHELL_FILE_HANDLE InFileHandle;
+ SHELL_FILE_HANDLE OutFileHandle;
UINT32 OutSize;
UINTN OutSizeTemp;
VOID *OutBuffer;
@@ -36,7 +42,7 @@ ShellCommandRunEfiDecompress ( VOID *InBuffer;
CHAR16 *InFileName;
CONST CHAR16 *OutFileName;
- UINT64 temp;
+ UINT64 Temp64Bit;
UINT32 ScratchSize;
VOID *ScratchBuffer;
EFI_DECOMPRESS_PROTOCOL *Decompress;
@@ -83,81 +89,84 @@ ShellCommandRunEfiDecompress ( } else {
InFileName = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 1));
OutFileName = ShellCommandLineGetRawValue(Package, 2);
- Status = ShellOpenFileByName(InFileName, &InFileHandle, EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);
- ShellStatus = SHELL_NOT_FOUND;
- }
- Status = ShellOpenFileByName(OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
+ if (InFileName == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_NOT_FOUND;
- }
- if (FileHandleIsDirectory(InFileHandle) == EFI_SUCCESS){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, InFileName);
- ShellStatus = SHELL_INVALID_PARAMETER;
- }
- if (FileHandleIsDirectory(OutFileHandle) == EFI_SUCCESS){
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, OutFileName);
- ShellStatus = SHELL_INVALID_PARAMETER;
- }
- Status = FileHandleGetSize(InFileHandle, &temp);
- ASSERT(temp <= (UINT32)(-1));
- InSize = (UINTN)temp;
- ASSERT_EFI_ERROR(Status);
- InBuffer = AllocatePool(InSize);
- ASSERT(InBuffer != NULL);
- Status = gEfiShellProtocol->ReadFile(InFileHandle, &InSize, InBuffer);
- ASSERT_EFI_ERROR(Status);
-
- Status = gBS->LocateProtocol(&gEfiDecompressProtocolGuid, NULL, (VOID**)&Decompress);
- ASSERT_EFI_ERROR(Status);
-
- Status = Decompress->GetInfo(Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize);
- ASSERT_EFI_ERROR(Status);
-
- OutBuffer = AllocatePool(OutSize);
- ScratchBuffer = AllocatePool(ScratchSize);
- ASSERT(OutBuffer != NULL);
- ASSERT(ScratchBuffer != NULL);
-
- Status = Decompress->Decompress(Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
- ASSERT_EFI_ERROR(Status);
-
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
- ShellStatus = SHELL_DEVICE_ERROR;
} else {
- OutSizeTemp = OutSize;
- Status = gEfiShellProtocol->WriteFile(OutFileHandle, &OutSizeTemp, OutBuffer);
- OutSize = (UINT32)OutSizeTemp;
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status);
- ShellStatus = SHELL_DEVICE_ERROR;
+ if (ShellIsDirectory(InFileName) == EFI_SUCCESS){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, InFileName);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ if (ShellIsDirectory(OutFileName) == EFI_SUCCESS){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, OutFileName);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ if (ShellStatus == SHELL_SUCCESS) {
+ Status = ShellOpenFileByName(InFileName, &InFileHandle, EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);
+ ShellStatus = SHELL_NOT_FOUND;
+ }
+ Status = ShellOpenFileByName(OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
+ ShellStatus = SHELL_NOT_FOUND;
+ }
+ }
+
+ if (ShellStatus == SHELL_SUCCESS) {
+ Status = FileHandleGetSize(InFileHandle, &Temp64Bit);
+ ASSERT(Temp64Bit <= (UINT32)(-1));
+ InSize = (UINTN)Temp64Bit;
+ ASSERT_EFI_ERROR(Status);
+ InBuffer = AllocateZeroPool(InSize);
+ ASSERT(InBuffer != NULL);
+ Status = gEfiShellProtocol->ReadFile(InFileHandle, &InSize, InBuffer);
+ ASSERT_EFI_ERROR(Status);
+
+ Status = gBS->LocateProtocol(&gEfiDecompressProtocolGuid, NULL, (VOID**)&Decompress);
+ ASSERT_EFI_ERROR(Status);
+
+ Status = Decompress->GetInfo(Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize);
+ ASSERT_EFI_ERROR(Status);
+
+ OutBuffer = AllocateZeroPool(OutSize);
+ ScratchBuffer = AllocateZeroPool(ScratchSize);
+ ASSERT(OutBuffer != NULL);
+ ASSERT(ScratchBuffer != NULL);
+
+ Status = Decompress->Decompress(Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
+ ASSERT_EFI_ERROR(Status);
+
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
+ ShellStatus = SHELL_DEVICE_ERROR;
+ } else {
+ OutSizeTemp = OutSize;
+ Status = gEfiShellProtocol->WriteFile(OutFileHandle, &OutSizeTemp, OutBuffer);
+ OutSize = (UINT32)OutSizeTemp;
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status);
+ ShellStatus = SHELL_DEVICE_ERROR;
+ }
+ }
}
}
}
ShellCommandLineFreeVarList (Package);
}
- if (InFileName != NULL) {
- FreePool(InFileName);
- }
if (InFileHandle != NULL) {
gEfiShellProtocol->CloseFile(InFileHandle);
}
if (OutFileHandle != NULL) {
gEfiShellProtocol->CloseFile(OutFileHandle);
}
- if (InBuffer != NULL) {
- FreePool(InBuffer);
- }
- if (OutBuffer != NULL) {
- FreePool(OutBuffer);
- }
- if (ScratchBuffer != NULL) {
- FreePool(ScratchBuffer);
- }
+
+ SHELL_FREE_NON_NULL(InFileName);
+ SHELL_FREE_NON_NULL(InBuffer);
+ SHELL_FREE_NON_NULL(OutBuffer);
+ SHELL_FREE_NON_NULL(ScratchBuffer);
return (ShellStatus);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c index 0084f87ca1..8f10158000 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c @@ -1,7 +1,7 @@ /** @file
Main file for LoadPciRom shell Debug1 function.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -18,19 +18,31 @@ #include <IndustryStandard/PeImage.h>
#include <Protocol/Decompress.h>
+/**
+ Connects all available drives and controllers.
+
+ @retval EFI_SUCCESS The operation was successful.
+ @retval EFI_ABORTED The abort mechanism was received.
+**/
EFI_STATUS
EFIAPI
LoadPciRomConnectAllDriversToAllControllers (
VOID
);
-EFI_STATUS
-EFIAPI
-InitializeLoadPciRom (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- );
+/**
+ Command entry point.
+ @param[in] RomBar The Rom Base address.
+ @param[in] RomSize The Rom size.
+ @param[in] FileName The file name.
+
+ @retval EFI_SUCCESS The command completed successfully.
+ @retval EFI_INVALID_PARAMETER Command usage error.
+ @retval EFI_UNSUPPORTED Protocols unsupported.
+ @retval EFI_OUT_OF_RESOURCES Out of memory.
+ @retval Other value Unknown error.
+**/
EFI_STATUS
EFIAPI
LoadEfiDriversFromRomImage (
@@ -44,6 +56,12 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { {NULL, TypeMax}
};
+/**
+ Function for 'loadpcirom' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunLoadPciRom (
@@ -83,11 +101,11 @@ ShellCommandRunLoadPciRom ( ASSERT(FALSE);
}
} else {
- if (ShellCommandLineGetCount(Package) < 1) {
+ if (ShellCommandLineGetCount(Package) < 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- if (!ShellCommandLineGetFlag(Package, L"-nc")) {
+ if (ShellCommandLineGetFlag(Package, L"-nc")) {
Connect = FALSE;
} else {
Connect = TRUE;
@@ -103,15 +121,12 @@ ShellCommandRunLoadPciRom ( ){
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, Param, Status);
ShellStatus = SHELL_ACCESS_DENIED;
break;
}
}
- if (FileList == NULL || IsListEmpty(&FileList->Link)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle);
- } else if (ShellStatus == SHELL_SUCCESS) {
-
-
+ if (ShellStatus == SHELL_SUCCESS && FileList != NULL) {
//
// loop through the list and make sure we are not aborting...
//
@@ -130,7 +145,7 @@ ShellCommandRunLoadPciRom ( continue;
}
SourceSize = (UINTN) Node->Info->FileSize;
- File1Buffer = AllocatePool (SourceSize);
+ File1Buffer = AllocateZeroPool (SourceSize);
ASSERT(File1Buffer != NULL);
Status = gEfiShellProtocol->ReadFile(Node->Handle, &SourceSize, File1Buffer);
if (EFI_ERROR(Status)) {
@@ -147,6 +162,9 @@ ShellCommandRunLoadPciRom ( }
FreePool(File1Buffer);
}
+ } else if (ShellStatus == SHELL_SUCCESS) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_NOT_FOUND;
}
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
Status = ShellCloseFileMetaArg(&FileList);
@@ -162,31 +180,27 @@ ShellCommandRunLoadPciRom ( return (ShellStatus);
}
+/**
+ Command entry point.
+
+ @param[in] RomBar The Rom Base address.
+ @param[in] RomSize The Rom size.
+ @param[in] FileName The file name.
+
+ @retval EFI_SUCCESS The command completed successfully.
+ @retval EFI_INVALID_PARAMETER Command usage error.
+ @retval EFI_UNSUPPORTED Protocols unsupported.
+ @retval EFI_OUT_OF_RESOURCES Out of memory.
+ @retval Other value Unknown error.
+**/
EFI_STATUS
+EFIAPI
LoadEfiDriversFromRomImage (
VOID *RomBar,
UINTN RomSize,
CONST CHAR16 *FileName
)
-/*++
-
-Routine Description:
- Command entry point.
-Arguments:
-
- RomBar - Rom
- RomSize - Rom size
- FileName - The file name
-
-Returns:
- EFI_SUCCESS - The command completed successfully
- EFI_INVALID_PARAMETER - Command usage error
- EFI_UNSUPPORTED - Protocols unsupported
- EFI_OUT_OF_RESOURCES - Out of memory
- Other value - Unknown error
-
-**/
{
EFI_PCI_EXPANSION_ROM_HEADER *EfiRomHeader;
PCI_DATA_STRUCTURE *Pcir;
@@ -196,7 +210,7 @@ Returns: UINT16 ImageOffset;
EFI_HANDLE ImageHandle;
EFI_STATUS Status;
- EFI_STATUS retStatus;
+ EFI_STATUS ReturnStatus;
CHAR16 RomFileName[280];
EFI_DEVICE_PATH_PROTOCOL *FilePath;
BOOLEAN SkipImage;
@@ -209,7 +223,7 @@ Returns: EFI_DECOMPRESS_PROTOCOL *Decompress;
ImageIndex = 0;
- retStatus = EFI_NOT_FOUND;
+ ReturnStatus = EFI_NOT_FOUND;
RomBarOffset = (UINTN) RomBar;
do {
@@ -219,7 +233,7 @@ Returns: if (EfiRomHeader->Signature != 0xaa55) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_CORRUPT), gShellDebug1HiiHandle, FileName, ImageIndex);
// PrintToken (STRING_TOKEN (STR_LOADPCIROM_IMAGE_CORRUPT), HiiHandle, ImageIndex);
- return retStatus;
+ return ReturnStatus;
}
Pcir = (PCI_DATA_STRUCTURE *) (UINTN) (RomBarOffset + EfiRomHeader->PcirOffset);
@@ -262,9 +276,9 @@ Returns: &ScratchSize
);
if (!EFI_ERROR (Status)) {
- DecompressedImageBuffer = AllocatePool (DestinationSize);
+ DecompressedImageBuffer = AllocateZeroPool (DestinationSize);
if (ImageBuffer != NULL) {
- Scratch = AllocatePool (ScratchSize);
+ Scratch = AllocateZeroPool (ScratchSize);
if (Scratch != NULL) {
Status = Decompress->Decompress (
Decompress,
@@ -312,7 +326,7 @@ Returns: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_START_FAIL), gShellDebug1HiiHandle, FileName, ImageIndex, Status);
// PrintToken (STRING_TOKEN (STR_LOADPCIROM_START_IMAGE), HiiHandle, ImageIndex, Status);
} else {
- retStatus = Status;
+ ReturnStatus = Status;
}
}
}
@@ -328,10 +342,17 @@ Returns: ImageIndex++;
} while (((Pcir->Indicator & 0x80) == 0x00) && ((RomBarOffset - (UINTN) RomBar) < RomSize));
- return retStatus;
+ return ReturnStatus;
}
+/**
+ Connects all available drives and controllers.
+
+ @retval EFI_SUCCESS The operation was successful.
+ @retval EFI_ABORTED The abort mechanism was received.
+**/
EFI_STATUS
+EFIAPI
LoadPciRomConnectAllDriversToAllControllers (
VOID
)
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c index 653c7f2d9e..59900d3256 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c @@ -1,7 +1,7 @@ /** @file
Main file for Mode shell Debug1 function.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the acModeanying materials
are licensed and made available under the terms and conditions of the BSD License
which acModeanies this distribution. The full text of the license may be found at
@@ -12,23 +12,29 @@ **/
-STATIC CONST CHAR16 strNameEfiReservedMemoryType[] = L"Reserved";
-STATIC CONST CHAR16 strNameEfiLoaderCode[] = L"LoadCode";
-STATIC CONST CHAR16 strNameEfiLoaderData[] = L"LoadData";
-STATIC CONST CHAR16 strNameEfiBootServicesCode[] = L"BSCode";
-STATIC CONST CHAR16 strNameEfiBootServicesData[] = L"BSData";
-STATIC CONST CHAR16 strNameEfiRuntimeServicesCode[] = L"RTCode";
-STATIC CONST CHAR16 strNameEfiRuntimeServicesData[] = L"RTData";
-STATIC CONST CHAR16 strNameEfiConventionalMemory[] = L"Conv";
-STATIC CONST CHAR16 strNameEfiUnusableMemory[] = L"Unusable";
-STATIC CONST CHAR16 strNameEfiACPIReclaimMemory[] = L"ACPIRec";
-STATIC CONST CHAR16 strNameEfiACPIMemoryNVS[] = L"ACPI_NVS";
-STATIC CONST CHAR16 strNameEfiMemoryMappedIO[] = L"MMIO";
-STATIC CONST CHAR16 strNameEfiMemoryMappedIOPortSpace[] = L"MMIOPort";
-STATIC CONST CHAR16 strNameEfiPalCode[] = L"PalCode";
+STATIC CONST CHAR16 NameEfiReservedMemoryType[] = L"Reserved";
+STATIC CONST CHAR16 NameEfiLoaderCode[] = L"LoaderCode";
+STATIC CONST CHAR16 NameEfiLoaderData[] = L"LoaderData";
+STATIC CONST CHAR16 NameEfiBootServicesCode[] = L"BS_Code";
+STATIC CONST CHAR16 NameEfiBootServicesData[] = L"BS_Data";
+STATIC CONST CHAR16 NameEfiRuntimeServicesCode[] = L"RT_Code";
+STATIC CONST CHAR16 NameEfiRuntimeServicesData[] = L"RT_Data";
+STATIC CONST CHAR16 NameEfiConventionalMemory[] = L"Available";
+STATIC CONST CHAR16 NameEfiUnusableMemory[] = L"Unusable";
+STATIC CONST CHAR16 NameEfiACPIReclaimMemory[] = L"ACPIRec";
+STATIC CONST CHAR16 NameEfiACPIMemoryNVS[] = L"ACPI_NVS";
+STATIC CONST CHAR16 NameEfiMemoryMappedIO[] = L"MMIO";
+STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpace[] = L"MMIOPort";
+STATIC CONST CHAR16 NameEfiPalCode[] = L"PalCode";
#include "UefiShellDebug1CommandsLib.h"
+/**
+ Function for 'memmap' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunMemMap (
@@ -64,8 +70,17 @@ ShellCommandRunMemMap ( UINT64 RTCodePagesSize;
UINT64 AvailPagesSize;
UINT64 TotalPagesSize;
+ UINT64 AcpiReclaimPages;
+ UINT64 AcpiNvsPages;
+ UINT64 MmioSpacePages;
+ UINT64 AcpiReclaimPagesSize;
+ UINT64 AcpiNvsPagesSize;
+ UINT64 MmioSpacePagesSize;
BOOLEAN Sfo;
+ AcpiReclaimPages = 0;
+ AcpiNvsPages = 0;
+ MmioSpacePages = 0;
TotalPages = 0;
ReservedPages = 0;
LoadCodePages = 0;
@@ -109,7 +124,7 @@ ShellCommandRunMemMap ( Status = gBS->GetMemoryMap(&Size, Buffer, &MapKey, &ItemSize, &Version);
if (Status == EFI_BUFFER_TOO_SMALL){
Size += SIZE_1KB;
- Buffer = AllocatePool(Size);
+ Buffer = AllocateZeroPool(Size);
Status = gBS->GetMemoryMap(&Size, Buffer, &MapKey, &ItemSize, &Version);
}
if (EFI_ERROR(Status)) {
@@ -123,67 +138,70 @@ ShellCommandRunMemMap ( switch (((EFI_MEMORY_DESCRIPTOR*)Walker)->Type) {
// replaced ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages) with 0000
case EfiReservedMemoryType:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiReservedMemoryType, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiReservedMemoryType, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
ReservedPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiLoaderCode:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiLoaderCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiLoaderCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
LoadCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiLoaderData:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiLoaderData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiLoaderData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
LoadDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiBootServicesCode:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiBootServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiBootServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
BSCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiBootServicesData:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiBootServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiBootServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
BSDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiRuntimeServicesCode:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiRuntimeServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiRuntimeServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
RTCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiRuntimeServicesData:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiRuntimeServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiRuntimeServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
RTDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiConventionalMemory:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiConventionalMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiConventionalMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
AvailPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiUnusableMemory:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiUnusableMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiUnusableMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiACPIReclaimMemory:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiACPIReclaimMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiACPIReclaimMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ AcpiReclaimPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiACPIMemoryNVS:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiACPIMemoryNVS, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiACPIMemoryNVS, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ AcpiNvsPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiMemoryMappedIO:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiMemoryMappedIO, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiMemoryMappedIO, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
+ MmioSpacePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiMemoryMappedIOPortSpace:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiMemoryMappedIOPortSpace, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiMemoryMappedIOPortSpace, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
case EfiPalCode:
- ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, strNameEfiPalCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages), ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
+ ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiPalCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
break;
default:
@@ -202,6 +220,9 @@ ShellCommandRunMemMap ( RTCodePagesSize = MultU64x64(SIZE_4KB,RTCodePages);
AvailPagesSize = MultU64x64(SIZE_4KB,AvailPages);
TotalPagesSize = MultU64x64(SIZE_4KB,TotalPages);
+ AcpiReclaimPagesSize = MultU64x64(SIZE_4KB,AcpiReclaimPages);
+ AcpiNvsPagesSize = MultU64x64(SIZE_4KB,AcpiNvsPages);
+ MmioSpacePagesSize = MultU64x64(SIZE_4KB,MmioSpacePages);
if (!Sfo) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_SUMM), gShellDebug1HiiHandle,
ReservedPages, ReservedPagesSize,
@@ -209,7 +230,11 @@ ShellCommandRunMemMap ( LoadDataPages, LoadDataPagesSize,
BSCodePages, BSCodePagesSize,
BSDataPages, BSDataPagesSize,
+ RTCodePages, RTCodePagesSize,
RTDataPages, RTDataPagesSize,
+ AcpiReclaimPages, AcpiReclaimPagesSize,
+ AcpiNvsPages, AcpiNvsPagesSize,
+ MmioSpacePages, MmioSpacePagesSize,
AvailPages, AvailPagesSize,
DivU64x32(MultU64x64(SIZE_4KB,TotalPages), SIZE_1MB), TotalPagesSize
);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c index a9be4950c8..ad1e9d09b4 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c @@ -1,7 +1,7 @@ /** @file
Main file for Mm shell Debug1 function.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -25,22 +25,69 @@ typedef enum { EfiPciEConfig
} EFI_ACCESS_TYPE;
-EFI_STATUS
-EFIAPI
-DumpIoModify (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- );
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
+ {L"-mmio", TypeFlag},
+ {L"-mem", TypeFlag},
+ {L"-io", TypeFlag},
+ {L"-pci", TypeFlag},
+ {L"-pcie", TypeFlag},
+ {L"-n", TypeFlag},
+ {L"-w", TypeValue},
+ {NULL, TypeMax}
+ };
+
+STATIC CONST UINT64 MaxNum[9] = { 0xff, 0xffff, 0xffffffff, 0xffffffffffffffff };
+
+/**
+ Read some data into a buffer from memory.
+ @param[in] Width The width of each read.
+ @param[in] Addresss The memory location to start reading at.
+ @param[in] Size The size of Buffer in Width sized units.
+ @param[out] Buffer The buffer to read into.
+**/
VOID
EFIAPI
ReadMem (
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Size,
- IN VOID *Buffer
- );
+ OUT VOID *Buffer
+ )
+{
+ //
+ // This function is defective. This ASSERT prevents the defect from affecting anything.
+ //
+ ASSERT(Size == 1);
+ do {
+ if (Width == EfiPciWidthUint8) {
+ *(UINT8 *) Buffer = *(UINT8 *) (UINTN) Address;
+ Address -= 1;
+ } else if (Width == EfiPciWidthUint16) {
+ *(UINT16 *) Buffer = *(UINT16 *) (UINTN) Address;
+ Address -= 2;
+ } else if (Width == EfiPciWidthUint32) {
+ *(UINT32 *) Buffer = *(UINT32 *) (UINTN) Address;
+ Address -= 4;
+ } else if (Width == EfiPciWidthUint64) {
+ *(UINT64 *) Buffer = *(UINT64 *) (UINTN) Address;
+ Address -= 8;
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_READ_ERROR), gShellDebug1HiiHandle);
+ break;
+ }
+ Size--;
+ } while (Size > 0);
+}
+
+/**
+ Write some data to memory.
+ @param[in] Width The width of each write.
+ @param[in] Addresss The memory location to start writing at.
+ @param[in] Size The size of Buffer in Width sized units.
+ @param[in] Buffer The buffer to write from.
+**/
VOID
EFIAPI
WriteMem (
@@ -48,27 +95,84 @@ WriteMem ( IN UINT64 Address,
IN UINTN Size,
IN VOID *Buffer
- );
+ )
+{
+ //
+ // This function is defective. This ASSERT prevents the defect from affecting anything.
+ //
+ ASSERT(Size == 1);
+ do {
+ if (Width == EfiPciWidthUint8) {
+ *(UINT8 *) (UINTN) Address = *(UINT8 *) Buffer;
+ Address += 1;
+ } else if (Width == EfiPciWidthUint16) {
+ *(UINT16 *) (UINTN) Address = *(UINT16 *) Buffer;
+ Address += 2;
+ } else if (Width == EfiPciWidthUint32) {
+ *(UINT32 *) (UINTN) Address = *(UINT32 *) Buffer;
+ Address += 4;
+ } else if (Width == EfiPciWidthUint64) {
+ *(UINT64 *) (UINTN) Address = *(UINT64 *) Buffer;
+ Address += 8;
+ } else {
+ ASSERT (FALSE);
+ }
+ //
+ //
+ //
+ Size--;
+ } while (Size > 0);
+}
+/**
+ Convert a string to it's hex data.
+
+ @param[in] str The pointer to the string of hex data.
+ @param[out] data The pointer to the buffer to fill. Valid upon a TRUE return.
+
+ @retval TRUE The conversion was successful.
+ @retval FALSE The conversion failed.
+**/
BOOLEAN
EFIAPI
GetHex (
IN UINT16 *str,
OUT UINT64 *data
- );
+ )
+{
+ UINTN TempUint;
+ CHAR16 TempChar;
+ BOOLEAN Find;
-STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
- {L"-mmio", TypeFlag},
- {L"-mem", TypeFlag},
- {L"-io", TypeFlag},
- {L"-pci", TypeFlag},
- {L"-pcie", TypeFlag},
- {L"-n", TypeFlag},
- {L"-w", TypeValue},
- {NULL, TypeMax}
- };
+ Find = FALSE;
+ //
+ // convert hex digits
+ //
+ TempUint = 0;
+ TempChar = *(str++);
+ while (TempChar != CHAR_NULL) {
+ if (TempChar >= 'a' && TempChar <= 'f') {
+ TempChar -= 'a' - 'A';
+ }
-STATIC CONST UINT64 MaxNum[9] = { 0xff, 0xffff, 0xffffffff, 0xffffffffffffffff };
+ if (TempChar == ' ') {
+ break;
+ }
+
+ if ((TempChar >= '0' && TempChar <= '9') || (TempChar >= 'A' && TempChar <= 'F')) {
+ TempUint = TempUint << 4 | TempChar - (TempChar >= 'A' ? 'A' - 10 : '0');
+
+ Find = TRUE;
+ } else {
+ return FALSE;
+ }
+
+ TempChar = *(str++);
+ }
+
+ *data = TempUint;
+ return Find;
+}
/**
Get the PCI-E Address from a PCI address format 0x0000ssbbddffrrr
@@ -157,7 +261,7 @@ ShellCommandRunMm ( ASSERT(FALSE);
}
} else {
- if (ShellCommandLineGetCount(Package) < 1) {
+ if (ShellCommandLineGetCount(Package) < 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
goto Done;
@@ -165,15 +269,49 @@ ShellCommandRunMm ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
goto Done;
+ } else if (ShellCommandLineGetFlag(Package, L"-w") && ShellCommandLineGetValue(Package, L"-w") == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-w");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
} else {
if (ShellCommandLineGetFlag(Package, L"-mmio")) {
AccessType = EFIMemoryMappedIo;
+ if (ShellCommandLineGetFlag(Package, L"-mem")
+ ||ShellCommandLineGetFlag(Package, L"-io")
+ ||ShellCommandLineGetFlag(Package, L"-pci")
+ ||ShellCommandLineGetFlag(Package, L"-pcie")
+ ){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
} else if (ShellCommandLineGetFlag(Package, L"-mem")) {
AccessType = EfiMemory;
+ if (ShellCommandLineGetFlag(Package, L"-io")
+ ||ShellCommandLineGetFlag(Package, L"-pci")
+ ||ShellCommandLineGetFlag(Package, L"-pcie")
+ ){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
} else if (ShellCommandLineGetFlag(Package, L"-io")) {
AccessType = EfiIo;
+ if (ShellCommandLineGetFlag(Package, L"-pci")
+ ||ShellCommandLineGetFlag(Package, L"-pcie")
+ ){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
} else if (ShellCommandLineGetFlag(Package, L"-pci")) {
AccessType = EfiPciConfig;
+ if (ShellCommandLineGetFlag(Package, L"-pcie")
+ ){
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
} else if (ShellCommandLineGetFlag(Package, L"-pcie")) {
AccessType = EfiPciEConfig;
}
@@ -185,7 +323,7 @@ ShellCommandRunMm ( Temp = ShellCommandLineGetValue(Package, L"-w");
if (Temp != NULL) {
- ItemValue = StrDecimalToUintn (Temp);
+ ItemValue = ShellStrToUintn (Temp);
switch (ItemValue) {
case 1:
@@ -209,20 +347,26 @@ ShellCommandRunMm ( break;
default:
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"-w");
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"-w");
ShellStatus = SHELL_INVALID_PARAMETER;
goto Done;
}
}
Temp = ShellCommandLineGetRawValue(Package, 1);
- if (Temp != NULL) {
- Address = StrHexToUint64(Temp);
+ if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, (UINT64*)&Address, TRUE, FALSE))) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
}
Temp = ShellCommandLineGetRawValue(Package, 2);
if (Temp != NULL) {
- Value = StrHexToUint64(Temp);
+ if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, &Value, TRUE, FALSE))) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
switch (Size) {
case 1:
if (Value > 0xFF) {
@@ -304,7 +448,6 @@ ShellCommandRunMm ( }
}
if (IoDev == NULL) {
- // TODO add token
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_SEGMENT_NOT_FOUND), gShellDebug1HiiHandle, SegmentNumber);
ShellStatus = SHELL_INVALID_PARAMETER;
goto Done;
@@ -357,10 +500,10 @@ ShellCommandRunMm ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle);
IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer);
} else if (AccessType == EfiPciEConfig) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);
IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer);
} else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);
ReadMem (Width, Address, 1, &Buffer);
}
@@ -387,68 +530,59 @@ ShellCommandRunMm ( do {
if (AccessType == EfiIo && Address + Size > 0x10000) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE2), gShellDebug1HiiHandle);
- // PrintToken (STRING_TOKEN (STR_IOMOD_IO_ADDRESS_2), HiiHandle, L"mm");
break;
}
Buffer = 0;
if (AccessType == EFIMemoryMappedIo) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle);
- // PrintToken (STRING_TOKEN (STR_IOMOD_HMMIO), HiiHandle);
IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer);
} else if (AccessType == EfiIo) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle);
- // PrintToken (STRING_TOKEN (STR_IOMOD_HIO), HiiHandle);
IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer);
} else if (AccessType == EfiPciConfig) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle);
- // PrintToken (STRING_TOKEN (STR_IOMOD_HPCI), HiiHandle);
IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer);
} else if (AccessType == EfiPciEConfig) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);
- // PrintToken (STRING_TOKEN (STR_IOMOD_HPCIE), HiiHandle);
IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);
- // PrintToken (STRING_TOKEN (STR_IOMOD_HMEM), HiiHandle);
ReadMem (Width, Address, 1, &Buffer);
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address);
- // PrintToken (STRING_TOKEN (STR_IOMOD_ADDRESS), HiiHandle, Address);
if (Size == 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, Buffer);
- // PrintToken (STRING_TOKEN (STR_IOMOD_BUFFER_2), HiiHandle, Buffer);
} else if (Size == 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, Buffer);
- // PrintToken (STRING_TOKEN (STR_IOMOD_BUFFER_4), HiiHandle, Buffer);
} else if (Size == 4) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, Buffer);
- // PrintToken (STRING_TOKEN (STR_IOMOD_BUFFER_8), HiiHandle, Buffer);
} else if (Size == 8) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer);
- // PrintToken (STRING_TOKEN (STR_IOMOD_BUFFER_16), HiiHandle, Buffer);
}
+ ShellPrintEx(-1, -1, L" > ");
//
// wait user input to modify
//
if (InputStr != NULL) {
FreePool(InputStr);
+ InputStr = NULL;
}
ShellPromptForResponse(ShellPromptResponseTypeFreeform, NULL, (VOID**)&InputStr);
//
// skip space characters
//
- for (Index = 0; InputStr[Index] == ' '; Index++);
+ for (Index = 0; InputStr != NULL && InputStr[Index] == ' '; Index++);
//
// parse input string
//
- if (InputStr[Index] == '.' || InputStr[Index] == 'q' || InputStr[Index] == 'Q') {
+ if (InputStr != NULL && (InputStr[Index] == '.' || InputStr[Index] == 'q' || InputStr[Index] == 'Q')) {
Complete = TRUE;
- } else if (InputStr[Index] == CHAR_NULL) {
+ } else if (InputStr == NULL || InputStr[Index] == CHAR_NULL) {
//
// Continue to next address
//
@@ -466,8 +600,8 @@ ShellCommandRunMm ( }
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ERROR), gShellDebug1HiiHandle);
- // PrintToken (STRING_TOKEN (STR_IOMOD_ERROR), HiiHandle);
continue;
+ // PrintToken (STRING_TOKEN (STR_IOMOD_ERROR), HiiHandle);
}
Address += Size;
@@ -492,111 +626,3 @@ Done: }
return ShellStatus;
}
-
-
-VOID
-EFIAPI
-ReadMem (
- IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
- IN UINT64 Address,
- IN UINTN Size,
- IN VOID *Buffer
- )
-{
- do {
- if (Width == EfiPciWidthUint8) {
- *(UINT8 *) Buffer = *(UINT8 *) (UINTN) Address;
- Address -= 1;
- } else if (Width == EfiPciWidthUint16) {
- *(UINT16 *) Buffer = *(UINT16 *) (UINTN) Address;
- Address -= 2;
- } else if (Width == EfiPciWidthUint32) {
- *(UINT32 *) Buffer = *(UINT32 *) (UINTN) Address;
- Address -= 4;
- } else if (Width == EfiPciWidthUint64) {
- *(UINT64 *) Buffer = *(UINT64 *) (UINTN) Address;
- Address -= 8;
- } else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_READ_ERROR), gShellDebug1HiiHandle);
-// PrintToken (STRING_TOKEN (STR_IOMOD_READ_MEM_ERROR), HiiHandle);
- break;
- }
- //
- //
- //
- Size--;
- } while (Size > 0);
-}
-
-VOID
-EFIAPI
-WriteMem (
- IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
- IN UINT64 Address,
- IN UINTN Size,
- IN VOID *Buffer
- )
-{
- do {
- if (Width == EfiPciWidthUint8) {
- *(UINT8 *) (UINTN) Address = *(UINT8 *) Buffer;
- Address += 1;
- } else if (Width == EfiPciWidthUint16) {
- *(UINT16 *) (UINTN) Address = *(UINT16 *) Buffer;
- Address += 2;
- } else if (Width == EfiPciWidthUint32) {
- *(UINT32 *) (UINTN) Address = *(UINT32 *) Buffer;
- Address += 4;
- } else if (Width == EfiPciWidthUint64) {
- *(UINT64 *) (UINTN) Address = *(UINT64 *) Buffer;
- Address += 8;
- } else {
- ASSERT (FALSE);
- }
- //
- //
- //
- Size--;
- } while (Size > 0);
-}
-
-BOOLEAN
-EFIAPI
-GetHex (
- IN UINT16 *str,
- OUT UINT64 *data
- )
-{
- UINTN u;
- CHAR16 c;
- BOOLEAN Find;
-
- Find = FALSE;
- //
- // convert hex digits
- //
- u = 0;
- c = *(str++);
- while (c != CHAR_NULL) {
- if (c >= 'a' && c <= 'f') {
- c -= 'a' - 'A';
- }
-
- if (c == ' ') {
- break;
- }
-
- if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
- u = u << 4 | c - (c >= 'A' ? 'A' - 10 : '0');
-
- Find = TRUE;
- } else {
- return FALSE;
- }
-
- c = *(str++);
- }
-
- *data = u;
- return Find;
-}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c index 53ba0b6cd4..d2b67d5760 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c @@ -1,7 +1,7 @@ /** @file
Main file for Mode shell Debug1 function.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the acModeanying materials
are licensed and made available under the terms and conditions of the BSD License
which acModeanies this distribution. The full text of the license may be found at
@@ -14,6 +14,12 @@ #include "UefiShellDebug1CommandsLib.h"
+/**
+ Function for 'mode' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunMode (
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index 56d5f7fd6f..d3a33e207c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -1,7 +1,7 @@ /** @file
Main file for Pci shell Debug1 function.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -1938,14 +1938,29 @@ ShellCommandRunPci ( }
} else {
+ if (ShellCommandLineGetCount(Package) == 2) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
+ if (ShellCommandLineGetCount(Package) > 4) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
+ if (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetValue(Package, L"-s") == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-s");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
//
// Get all instances of PciRootBridgeIo. Allocate space for 1 EFI_HANDLE and
// call LibLocateHandle(), if EFI_BUFFER_TOO_SMALL is returned, allocate enough
// space for handles and call it again.
//
HandleBufSize = sizeof (EFI_HANDLE);
- HandleBuf = (EFI_HANDLE *) AllocatePool (HandleBufSize);
+ HandleBuf = (EFI_HANDLE *) AllocateZeroPool (HandleBufSize);
if (HandleBuf == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);
ShellStatus = SHELL_OUT_OF_RESOURCES;
@@ -1987,7 +2002,7 @@ ShellCommandRunPci ( //
// Argument Count == 1(no other argument): enumerate all pci functions
//
- if (ShellCommandLineGetCount(Package) == 0) {
+ if (ShellCommandLineGetCount(Package) == 1) {
gST->ConOut->QueryMode (
gST->ConOut,
gST->ConOut->Mode->Mode,
@@ -2134,20 +2149,6 @@ ShellCommandRunPci ( goto Done;
}
- if (ShellCommandLineGetCount(Package) == 1) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
- }
- //
- // Arg count >= 3, dump binary of specified function, interpret if necessary
- //
- if (ShellCommandLineGetCount(Package) > 3) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
- ShellStatus = SHELL_INVALID_PARAMETER;
- goto Done;
- }
-
ExplainData = FALSE;
Segment = 0;
Bus = 0;
@@ -2159,7 +2160,7 @@ ShellCommandRunPci ( Temp = ShellCommandLineGetValue(Package, L"-s");
if (Temp != NULL) {
- Segment = (UINT16) StrHexToUintn (Temp);
+ Segment = (UINT16) ShellStrToUintn (Temp);
}
//
@@ -2168,7 +2169,7 @@ ShellCommandRunPci ( //
Temp = ShellCommandLineGetRawValue(Package, 1);
if (Temp != NULL) {
- Bus = (UINT16)StrHexToUintn(Temp);
+ Bus = (UINT16)ShellStrToUintn(Temp);
if (Bus > MAX_BUS_NUMBER) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
ShellStatus = SHELL_INVALID_PARAMETER;
@@ -2177,7 +2178,7 @@ ShellCommandRunPci ( }
Temp = ShellCommandLineGetRawValue(Package, 2);
if (Temp != NULL) {
- Device = (UINT16) StrHexToUintn(Temp);
+ Device = (UINT16) ShellStrToUintn(Temp);
if (Device > MAX_DEVICE_NUMBER){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
ShellStatus = SHELL_INVALID_PARAMETER;
@@ -2187,7 +2188,7 @@ ShellCommandRunPci ( Temp = ShellCommandLineGetRawValue(Package, 3);
if (Temp != NULL) {
- Func = (UINT16) StrHexToUintn(Temp);
+ Func = (UINT16) ShellStrToUintn(Temp);
if (Func > MAX_FUNCTION_NUMBER){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
ShellStatus = SHELL_INVALID_PARAMETER;
@@ -2469,21 +2470,22 @@ Returns: // if a bus typed one is found and its bus range covers bus, this handle
// is the handle we are looking for.
//
- if ((*Descriptors)->Desc == ACPI_END_TAG_DESCRIPTOR) {
- *IsEnd = TRUE;
- }
while ((*Descriptors)->Desc != ACPI_END_TAG_DESCRIPTOR) {
if ((*Descriptors)->ResType == ACPI_ADDRESS_SPACE_TYPE_BUS) {
*MinBus = (UINT16) (*Descriptors)->AddrRangeMin;
*MaxBus = (UINT16) (*Descriptors)->AddrRangeMax;
(*Descriptors)++;
- break;
+ return (EFI_SUCCESS);
}
(*Descriptors)++;
}
+ if ((*Descriptors)->Desc == ACPI_END_TAG_DESCRIPTOR) {
+ *IsEnd = TRUE;
+ }
+
return EFI_SUCCESS;
}
@@ -4496,7 +4498,7 @@ PciExplainPciExpress ( ExtendRegSize = 0x1000 - 0x100;
- ExRegBuffer = (UINT8 *) AllocatePool (ExtendRegSize);
+ ExRegBuffer = (UINT8 *) AllocateZeroPool (ExtendRegSize);
//
// PciRootBridgeIo protocol should support pci express extend space IO
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c index 52612283a2..e464d57fe4 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c @@ -1,7 +1,7 @@ /** @file
Main file for SerMode shell Debug1 function.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -16,9 +16,20 @@ #include <Library/ShellLib.h>
#include <Protocol/SerialIo.h>
+/**
+ Display information about a serial device by it's handle.
+
+ If HandleValid is FALSE, do all devices.
+
+ @param[in] HandleIdx The handle index for the device.
+ @param[in] HandleValid TRUE if HandleIdx is valid.
+
+ @retval SHELL_INVALID_PARAMETER A parameter was invalid.
+ @retval SHELL_SUCCESS The operation was successful.
+**/
SHELL_STATUS
EFIAPI
-iDisplaySettings (
+DisplaySettings (
IN UINTN HandleIdx,
IN BOOLEAN HandleValid
)
@@ -147,6 +158,12 @@ iDisplaySettings ( return ShellStatus;
}
+/**
+ Function for 'sermode' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunSerMode (
@@ -169,6 +186,7 @@ ShellCommandRunSerMode ( LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *Temp;
+ UINT64 Intermediate;
ShellStatus = SHELL_SUCCESS;
HandleIdx = 0;
@@ -188,28 +206,29 @@ ShellCommandRunSerMode ( ASSERT(FALSE);
}
} else {
- if (ShellCommandLineGetCount(Package) < 5 && ShellCommandLineGetCount(Package) > 1) {
+ if (ShellCommandLineGetCount(Package) < 6 && ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
- } else if (ShellCommandLineGetCount(Package) > 5) {
+ } else if (ShellCommandLineGetCount(Package) > 6) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Temp = ShellCommandLineGetRawValue(Package, 1);
if (Temp != NULL) {
- HandleIdx = StrHexToUintn(Temp);
+ Status = ShellConvertStringToUint64(Temp, &Intermediate, TRUE, FALSE);
+ HandleIdx = (UINTN)Intermediate;
Temp = ShellCommandLineGetRawValue(Package, 2);
if (Temp == NULL) {
- ShellStatus = iDisplaySettings (HandleIdx, TRUE);
+ ShellStatus = DisplaySettings (HandleIdx, TRUE);
goto Done;
}
} else {
- ShellStatus = iDisplaySettings (0, FALSE);
+ ShellStatus = DisplaySettings (0, FALSE);
goto Done;
}
Temp = ShellCommandLineGetRawValue(Package, 2);
if (Temp != NULL) {
- BaudRate = StrHexToUintn(Temp);
+ BaudRate = ShellStrToUintn(Temp);
} else {
ASSERT(FALSE);
BaudRate = 0;
@@ -252,7 +271,7 @@ ShellCommandRunSerMode ( }
Temp = ShellCommandLineGetRawValue(Package, 4);
if (Temp != NULL) {
- DataBits = StrHexToUintn(Temp);
+ DataBits = ShellStrToUintn(Temp);
} else {
//
// make sure this is some number not in the list below.
@@ -270,7 +289,7 @@ ShellCommandRunSerMode ( goto Done;
}
Temp = ShellCommandLineGetRawValue(Package, 5);
- Value = StrHexToUintn(Temp);
+ Value = ShellStrToUintn(Temp);
switch (Value) {
case 0:
StopBits = DefaultStopBits;
@@ -328,7 +347,7 @@ ShellCommandRunSerMode ( }
}
- if (Index == NoHandles) {
+ if (ShellStatus == SHELL_SUCCESS && Index == NoHandles) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_BAD_HANDLE), gShellDebug1HiiHandle, HandleIdx);
ShellStatus = SHELL_INVALID_PARAMETER;
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c index 30a382fb04..24200320fc 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c @@ -1,7 +1,7 @@ /** @file
Main file for SetSize shell Debug1 function.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -14,6 +14,12 @@ #include "UefiShellDebug1CommandsLib.h"
+/**
+ Function for 'setsize' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunSetSize (
@@ -55,20 +61,31 @@ ShellCommandRunSetSize ( ASSERT(FALSE);
}
} else {
- Temp1 = ShellCommandLineGetRawValue(Package, 1);
- if (Temp1 == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle);
+ if (ShellCommandLineGetCount(Package) < 3) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
NewSize = 0;
} else {
- NewSize = ShellStrToUintn(Temp1);
+ Temp1 = ShellCommandLineGetRawValue(Package, 1);
+ if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ NewSize = 0;
+ } else {
+ NewSize = ShellStrToUintn(Temp1);
+ }
}
for (LoopVar = 2 ; LoopVar < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS ; LoopVar++) {
- Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
+ Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
+ if (EFI_ERROR(Status)) {
+ Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
+ }
if (EFI_ERROR(Status) && LoopVar == 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, LoopVar), Status);
+ ShellStatus = SHELL_INVALID_PARAMETER;
break;
} else {
Status = FileHandleSetSize(FileHandle, NewSize);
@@ -78,6 +95,8 @@ ShellCommandRunSetSize ( } else if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, LoopVar), Status);
ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_DONE), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, LoopVar));
}
ShellCloseFile(&FileHandle);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c index f8c6dd2e30..324db922e6 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -1,7 +1,7 @@ /** @file
Main file for SetVar shell Debug1 function.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -22,6 +22,12 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = { {NULL, TypeMax}
};
+/**
+ Function for 'setvar' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
SHELL_STATUS
EFIAPI
ShellCommandRunSetVar (
@@ -38,6 +44,7 @@ ShellCommandRunSetVar ( EFI_GUID Guid;
CONST CHAR16 *StringGuid;
UINT32 Attributes;
+ UINT32 Attributes2;
VOID *Buffer;
UINTN Size;
UINTN LoopVar;
@@ -88,7 +95,8 @@ ShellCommandRunSetVar ( StringGuid = ShellCommandLineGetValue(Package, L"-guid");
Status = ConvertStringToGuid(StringGuid, &Guid);
if (EFI_ERROR(Status)) {
- ShellStatus = SHELL_NOT_FOUND;
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, StringGuid);
+ ShellStatus = SHELL_INVALID_PARAMETER;
}
}
if (Data == NULL) {
@@ -97,7 +105,7 @@ ShellCommandRunSetVar ( //
Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, &Size, Buffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
- Buffer = AllocatePool(Size);
+ Buffer = AllocateZeroPool(Size);
Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, &Size, Buffer);
}
if (!EFI_ERROR(Status)&& Buffer != NULL) {
@@ -138,22 +146,36 @@ ShellCommandRunSetVar ( Attributes |= EFI_VARIABLE_NON_VOLATILE;
}
if (ShellIsHexOrDecimalNumber(Data, TRUE, FALSE)) {
- //
- // arbitrary buffer
- //
- Buffer = AllocateZeroPool((StrLen(Data) / 2));
- for (LoopVar = 0 ; LoopVar < (StrLen(Data) / 2) ; LoopVar++) {
- ((UINT8*)Buffer)[LoopVar] = (UINT8)(HexCharToUintn(Data[LoopVar*2]) * 16);
- ((UINT8*)Buffer)[LoopVar] = (UINT8)(((UINT8*)Buffer)[LoopVar] + HexCharToUintn(Data[LoopVar*2+1]));
- }
- Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrLen(Data) / 2, Buffer);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);
- ShellStatus = SHELL_ACCESS_DENIED;
+ if (StrLen(Data) % 2 != 0) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, Data);
+ ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- ASSERT(ShellStatus == SHELL_SUCCESS);
+ //
+ // arbitrary buffer
+ //
+ Buffer = AllocateZeroPool((StrLen(Data) / 2));
+ for (LoopVar = 0 ; LoopVar < (StrLen(Data) / 2) ; LoopVar++) {
+ ((UINT8*)Buffer)[LoopVar] = (UINT8)(HexCharToUintn(Data[LoopVar*2]) * 16);
+ ((UINT8*)Buffer)[LoopVar] = (UINT8)(((UINT8*)Buffer)[LoopVar] + HexCharToUintn(Data[LoopVar*2+1]));
+ }
+ Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrLen(Data) / 2, Buffer);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);
+ ShellStatus = SHELL_ACCESS_DENIED;
+ } else {
+ ASSERT(ShellStatus == SHELL_SUCCESS);
+ }
}
} else if (StrnCmp(Data, L"\"", 1) == 0) {
+ Size = 0;
+ Attributes2 = 0;
+ Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes2, &Size, Buffer);
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ Buffer = AllocateZeroPool(Size);
+ Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes2, &Size, Buffer);
+ FreePool(Buffer);
+ Attributes = Attributes2;
+ }
//
// ascii text
//
@@ -162,6 +184,7 @@ ShellCommandRunSetVar ( AsciiSPrint(Buffer, StrSize(Data) / 2, "%s", Data);
((CHAR8*)Buffer)[AsciiStrLen(Buffer)-1] = CHAR_NULL;
+
Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, AsciiStrSize(Buffer)-sizeof(CHAR8), Buffer);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c index b9ff013d60..a45a721df3 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c @@ -1,7 +1,7 @@ /** @file
Tools of clarify the content of the smbios table.
- Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2005 - 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
@@ -52,7 +52,7 @@ ShellCommandRunSmbiosView ( Package = NULL;
ShellStatus = SHELL_SUCCESS;
- Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
+ Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
@@ -65,11 +65,21 @@ ShellCommandRunSmbiosView ( if (ShellCommandLineGetCount(Package) > 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
+ } else if (
+ (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-h")) ||
+ (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-s")) ||
+ (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-a")) ||
+ (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-s")) ||
+ (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-a")) ||
+ (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-a"))
+ ) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
+ ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// Init Lib
- //
+
Status = LibSmbiosInit ();
if (EFI_ERROR (Status)) {
ShellStatus = SHELL_NOT_FOUND;
@@ -370,7 +380,7 @@ InitSmbiosTableStatistics ( mStatisticsTable = NULL;
}
- mStatisticsTable = (STRUCTURE_STATISTICS *) AllocatePool (SMBiosTable->NumberOfSmbiosStructures * sizeof (STRUCTURE_STATISTICS));
+ mStatisticsTable = (STRUCTURE_STATISTICS *) AllocateZeroPool (SMBiosTable->NumberOfSmbiosStructures * sizeof (STRUCTURE_STATISTICS));
if (mStatisticsTable == NULL) {
ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_OUT_OF_MEM), gShellDebug1HiiHandle);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni Binary files differindex b9d2aea3ce..c63001a90e 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c index 094e429fed..226dd90397 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c @@ -1,7 +1,7 @@ /** @file
Main file for NULL named library for debug1 profile shell command functions.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -21,6 +21,12 @@ CONST EFI_GUID gShellDebug1HiiGuid = \ 0x25f200aa, 0xd3cb, 0x470a, { 0xbf, 0x51, 0xe7, 0xd1, 0x62, 0xd2, 0x2e, 0x6f } \
};
+/**
+ Gets the debug file name. This will be used if HII is not working.
+
+ @retval NULL No file is available.
+ @return The NULL-terminated filename to get help from.
+**/
CONST CHAR16*
EFIAPI
ShellCommandGetManFileNameDebug1 (
@@ -64,21 +70,23 @@ UefiShellDebug1CommandsLibConstructor ( //
// install our shell command handlers that are always installed
//
- ShellCommandRegisterCommandName(L"SetSize", ShellCommandRunSetSize , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETSIZE) );
+ ShellCommandRegisterCommandName(L"setsize", ShellCommandRunSetSize , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETSIZE) );
ShellCommandRegisterCommandName(L"comp", ShellCommandRunComp , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_COMP) );
ShellCommandRegisterCommandName(L"mode", ShellCommandRunMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MODE) );
ShellCommandRegisterCommandName(L"memmap", ShellCommandRunMemMap , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MEMMAP) );
ShellCommandRegisterCommandName(L"eficompress", ShellCommandRunEfiCompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFICOMPRESS) );
ShellCommandRegisterCommandName(L"efidecompress", ShellCommandRunEfiDecompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFIDCOMPRESS) );
ShellCommandRegisterCommandName(L"dmem", ShellCommandRunDmem , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMEM) );
- ShellCommandRegisterCommandName(L"LoadPciRom", ShellCommandRunLoadPciRom , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD_PCI_ROM) );
+ ShellCommandRegisterCommandName(L"loadpcirom", ShellCommandRunLoadPciRom , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD_PCI_ROM) );
ShellCommandRegisterCommandName(L"mm", ShellCommandRunMm , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MM) );
- ShellCommandRegisterCommandName(L"SetVar", ShellCommandRunSetVar , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETVAR) );
- ShellCommandRegisterCommandName(L"SerMode", ShellCommandRunSerMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SERMODE) );
- ShellCommandRegisterCommandName(L"Pci", ShellCommandRunPci , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_PCI) );
+ ShellCommandRegisterCommandName(L"setvar", ShellCommandRunSetVar , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETVAR) );
+ ShellCommandRegisterCommandName(L"sermode", ShellCommandRunSerMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SERMODE) );
+ ShellCommandRegisterCommandName(L"pci", ShellCommandRunPci , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_PCI) );
ShellCommandRegisterCommandName(L"smbiosview", ShellCommandRunSmbiosView , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SMBIOSVIEW) );
ShellCommandRegisterCommandName(L"dmpstore", ShellCommandRunDmpStore , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMPSTORE) );
ShellCommandRegisterCommandName(L"dblk", ShellCommandRunDblk , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DBLK) );
+ ShellCommandRegisterCommandName(L"edit", ShellCommandRunEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EDIT) );
+ ShellCommandRegisterCommandName(L"hexedit", ShellCommandRunHexEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT) );
//
// check install profile bit of the profiles mask is set
@@ -87,10 +95,8 @@ UefiShellDebug1CommandsLibConstructor ( ShellCommandRegisterCommandName(L"bcfg", ShellCommandRunBcfg , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_BCFG) );
}
-/*
- ShellCommandRegisterCommandName(L"hexedit", ShellCommandRunHexEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT );
- ShellCommandRegisterCommandName(L"edit", ShellCommandRunEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EDIT) );
-*/
+
+
ShellCommandRegisterAlias(L"dmem", L"mem");
@@ -99,6 +105,9 @@ UefiShellDebug1CommandsLibConstructor ( /**
Destructor for the library. free any resources.
+
+ @param ImageHandle The image handle of the process.
+ @param SystemTable The EFI System Table pointer.
**/
EFI_STATUS
EFIAPI
@@ -132,6 +141,14 @@ STATIC CONST CHAR8 Hex[] = { 'F'
};
+/**
+ Dump some hexadecimal data to the screen.
+
+ @param[in] Indent How many spaces to indent the output.
+ @param[in] Offset The offset of the printing.
+ @param[in] DataSize The size in bytes of UserData.
+ @param[in] UserData The data to print out.
+**/
VOID
EFIAPI
DumpHex (
@@ -147,12 +164,10 @@ DumpHex ( CHAR8 Str[20];
- UINT8 c;
+ UINT8 TempByte;
UINTN Size;
UINTN Index;
- ASSERT (UserData != NULL);
-
Data = UserData;
while (DataSize != 0) {
Size = 16;
@@ -161,11 +176,11 @@ DumpHex ( }
for (Index = 0; Index < Size; Index += 1) {
- c = Data[Index];
- Val[Index * 3 + 0] = Hex[c >> 4];
- Val[Index * 3 + 1] = Hex[c & 0xF];
+ TempByte = Data[Index];
+ Val[Index * 3 + 0] = Hex[TempByte >> 4];
+ Val[Index * 3 + 1] = Hex[TempByte & 0xF];
Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' ');
- Str[Index] = (CHAR8) ((c < ' ' || c > 'z') ? '.' : c);
+ Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);
}
Val[Index * 3] = 0;
@@ -213,7 +228,7 @@ CharToUpper ( EFI System Table based on the provided GUID.
@param[in] TableGuid A pointer to the table's GUID type.
- @param[out] Table On exit, a pointer to a system configuration table.
+ @param[in,out] Table On exit, a pointer to a system configuration table.
@retval EFI_SUCCESS A configuration table matching TableGuid was found.
@retval EFI_NOT_FOUND A configuration table matching TableGuid was not found.
@@ -229,7 +244,7 @@ GetSystemConfigurationTable ( ASSERT (Table != NULL);
for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
- if (CompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid)) == 0) {
+ if (CompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {
*Table = gST->ConfigurationTable[Index].VendorTable;
return EFI_SUCCESS;
}
@@ -264,6 +279,15 @@ HexCharToUintn ( return (UINTN) (10 + CharToUpper (Char) - L'A');
}
+/**
+ Convert a string representation of a guid to a Guid value.
+
+ @param[in] StringGuid The pointer to the string of a guid.
+ @param[in,out] Guid The pointer to the GUID structure to populate.
+
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
+ @retval EFI_SUCCESS The conversion was successful.
+**/
EFI_STATUS
EFIAPI
ConvertStringToGuid (
@@ -271,39 +295,399 @@ ConvertStringToGuid ( IN OUT EFI_GUID *Guid
)
{
- if (StrLen(StringGuid) != 35) {
+ CHAR16 *TempCopy;
+ CHAR16 *TempSpot;
+ CHAR16 *Walker;
+ UINT64 TempVal;
+ EFI_STATUS Status;
+
+ if (StringGuid == NULL) {
+ return (EFI_INVALID_PARAMETER);
+ } else if (StrLen(StringGuid) != 36) {
return (EFI_INVALID_PARAMETER);
+ }
+ TempCopy = NULL;
+ TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);
+ Walker = TempCopy;
+ TempSpot = StrStr(Walker, L"-");
+ *TempSpot = CHAR_NULL;
+ Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
+ if (EFI_ERROR(Status)) {
+ FreePool(TempCopy);
+ return (Status);
+ }
+ Guid->Data1 = (UINT32)TempVal;
+ Walker += 9;
+ TempSpot = StrStr(Walker, L"-");
+ *TempSpot = CHAR_NULL;
+ Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
+ if (EFI_ERROR(Status)) {
+ FreePool(TempCopy);
+ return (Status);
+ }
+ Guid->Data2 = (UINT16)TempVal;
+ Walker += 5;
+ TempSpot = StrStr(Walker, L"-");
+ *TempSpot = CHAR_NULL;
+ Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
+ if (EFI_ERROR(Status)) {
+ FreePool(TempCopy);
+ return (Status);
+ }
+ Guid->Data3 = (UINT16)TempVal;
+ Walker += 5;
+ Guid->Data4[0] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[1] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 3;
+ Guid->Data4[2] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[3] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[4] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[5] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[6] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[7] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[7] = (UINT8)(Guid->Data4[7] + (UINT8)HexCharToUintn(Walker[1]));
+ FreePool(TempCopy);
+ return (EFI_SUCCESS);
+}
+
+CHAR16 TempBufferCatSPrint[1000];
+/**
+ Appends a formatted Unicode string to a Null-terminated Unicode string
+
+ This function appends a formatted Unicode string to the Null-terminated
+ Unicode string specified by String. String is optional and may be NULL.
+ Storage for the formatted Unicode string returned is allocated using
+ AllocateZeroPool(). The pointer to the appended string is returned. The caller
+ is responsible for freeing the returned string.
+
+ If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().
+ If Format is NULL, then ASSERT().
+ If Format is not aligned on a 16-bit boundary, then ASSERT().
+
+ @param String A null-terminated Unicode string.
+ @param FormatString A null-terminated Unicode format string.
+ @param ... The variable argument list whose contents are accessed based
+ on the format string specified by Format.
+
+ @retval NULL There was not enough available memory.
+ @return Null terminated Unicode string is that is the formatted
+ string appended to String.
+ @sa CatVSPrint
+**/
+CHAR16*
+EFIAPI
+CatSPrint (
+ IN CONST CHAR16 *String OPTIONAL,
+ IN CONST CHAR16 *FormatString,
+ ...
+ )
+{
+ VA_LIST Marker;
+ UINTN StringLength;
+ if (String != NULL) {
+ StrCpy(TempBufferCatSPrint, String);
+ } else {
+ *TempBufferCatSPrint = CHAR_NULL;
+ }
+ VA_START (Marker, FormatString);
+ StringLength = StrLen(TempBufferCatSPrint);
+
+ UnicodeVSPrint(TempBufferCatSPrint+StrLen(TempBufferCatSPrint), 1000-StringLength, FormatString, Marker);
+ return (AllocateCopyPool(StrSize(TempBufferCatSPrint), TempBufferCatSPrint));
+}
+
+/**
+ Clear the line at the specified Row.
+
+ @param[in] Row The row number to be cleared ( start from 1 )
+ @param[in] LastCol The last printable column.
+ @param[in] LastRow The last printable row.
+**/
+VOID
+EFIAPI
+EditorClearLine (
+ IN UINTN Row,
+ IN UINTN LastCol,
+ IN UINTN LastRow
+ )
+{
+ CHAR16 Line[200];
+
+ if (Row == 0) {
+ Row = 1;
+ }
+
+ //
+ // prepare a blank line
+ //
+ SetMem16(Line, LastCol*sizeof(CHAR16), L' ');
+
+ if (Row == LastRow) {
+ //
+ // if CHAR_NULL is still at position 80, it will cause first line error
+ //
+ Line[LastCol - 1] = CHAR_NULL;
} else {
- Guid->Data1 = (UINT32)StrHexToUintn(StringGuid);
- StringGuid += 9;
- Guid->Data2 = (UINT16)StrHexToUintn(StringGuid);
- StringGuid += 5;
- Guid->Data3 = (UINT16)StrHexToUintn(StringGuid);
- StringGuid += 5;
- Guid->Data4[0] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[1] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[2] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[3] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[4] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[5] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[6] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[7] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[7] = (UINT8)(Guid->Data4[7] = (UINT8)HexCharToUintn(StringGuid[1]));
- return (EFI_SUCCESS);
+ Line[LastCol] = CHAR_NULL;
+ }
+
+ //
+ // print out the blank line
+ //
+ ShellPrintEx (0, ((INT32)Row) - 1, Line);
+}
+
+/**
+ Determine if the character is valid for a filename.
+
+ @param[in] Ch The character to test.
+
+ @retval TRUE The character is valid.
+ @retval FALSE The character is not valid.
+**/
+BOOLEAN
+EFIAPI
+IsValidFileNameChar (
+ IN CONST CHAR16 Ch
+ )
+{
+ //
+ // See if there are any illegal characters within the name
+ //
+ if (Ch < 0x20 || Ch == L'\"' || Ch == L'*' || Ch == L'/' || Ch == L'<' || Ch == L'>' || Ch == L'?' || Ch == L'|' || Ch == L' ') {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ Check if file name has illegal characters.
+
+ @param Name The filename to check.
+
+ @retval TRUE The filename is ok.
+ @retval FALSE The filename is not ok.
+**/
+BOOLEAN
+EFIAPI
+IsValidFileName (
+ IN CONST CHAR16 *Name
+ )
+{
+
+ UINTN Index;
+ UINTN Len;
+
+ //
+ // check the length of Name
+ //
+ for (Len = 0, Index = StrLen (Name) - 1; Index + 1 != 0; Index--, Len++) {
+ if (Name[Index] == '\\' || Name[Index] == ':') {
+ break;
+ }
+ }
+
+ if (Len == 0 || Len > 255) {
+ return FALSE;
+ }
+ //
+ // check whether any char in Name not appears in valid file name char
+ //
+ for (Index = 0; Index < StrLen (Name); Index++) {
+ if (!IsValidFileNameChar (Name[Index])) {
+ return FALSE;
+ }
}
+
+ return TRUE;
+}
+
+/**
+ Find a filename that is valid (not taken) with the given extension.
+
+ @param[in] Extension The file extension.
+
+ @retval NULL Something went wrong.
+ @return the valid filename.
+**/
+CHAR16 *
+EFIAPI
+EditGetDefaultFileName (
+ IN CONST CHAR16 *Extension
+ )
+{
+ EFI_STATUS Status;
+ UINTN Suffix;
+ BOOLEAN FoundNewFile;
+ CHAR16 *FileNameTmp;
+
+ Suffix = 0;
+ FoundNewFile = FALSE;
+
+ do {
+ FileNameTmp = CatSPrint (NULL, L"NewFile%d.%s", Suffix, Extension);
+
+ //
+ // after that filename changed to path
+ //
+ Status = ShellFileExists (FileNameTmp);
+
+ if (Status == EFI_NOT_FOUND) {
+ return FileNameTmp;
+ }
+
+ FreePool (FileNameTmp);
+ FileNameTmp = NULL;
+ Suffix++;
+ } while (Suffix != 0);
+
+ FreePool (FileNameTmp);
+ return NULL;
}
+/**
+ Read a file into an allocated buffer. The buffer is the responsibility
+ of the caller to free.
+
+ @param[in] FileName The filename of the file to open.
+ @param[out] Buffer Upon successful return, the pointer to the
+ address of the allocated buffer.
+ @param[out] BufferSize If not NULL, then the pointer to the size
+ of the allocated buffer.
+ @param[out] ReadOnly Upon successful return TRUE if the file is
+ read only. FALSE otherwise.
+
+ @retval EFI_NOT_FOUND The filename did not represent a file in the
+ file system.
+ @retval EFI_SUCCESS The file was read into the buffer.
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
+ @retval EFI_LOAD_ERROR The file read operation failed.
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
+ @retval EFI_INVALID_PARAMETER FileName was NULL.
+ @retval EFI_INVALID_PARAMETER FileName was a directory.
+**/
+EFI_STATUS
+EFIAPI
+ReadFileIntoBuffer (
+ IN CONST CHAR16 *FileName,
+ OUT VOID **Buffer,
+ OUT UINTN *BufferSize OPTIONAL,
+ OUT BOOLEAN *ReadOnly
+ )
+{
+ VOID *InternalBuffer;
+ UINTN FileSize;
+ SHELL_FILE_HANDLE FileHandle;
+ BOOLEAN CreateFile;
+ EFI_STATUS Status;
+ EFI_FILE_INFO *Info;
+
+ InternalBuffer = NULL;
+ FileSize = 0;
+ FileHandle = NULL;
+ CreateFile = FALSE;
+ Status = EFI_SUCCESS;
+ Info = NULL;
+
+ if (FileName == NULL || Buffer == NULL || ReadOnly == NULL) {
+ return (EFI_INVALID_PARAMETER);
+ }
+
+ //
+ // try to open the file
+ //
+ Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
+
+ if (!EFI_ERROR(Status)) {
+ ASSERT(CreateFile == FALSE);
+ if (FileHandle == NULL) {
+ return EFI_LOAD_ERROR;
+ }
+
+ Info = ShellGetFileInfo(FileHandle);
+
+ if (Info->Attribute & EFI_FILE_DIRECTORY) {
+ FreePool (Info);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Info->Attribute & EFI_FILE_READ_ONLY) {
+ *ReadOnly = TRUE;
+ } else {
+ *ReadOnly = FALSE;
+ }
+ //
+ // get file size
+ //
+ FileSize = (UINTN) Info->FileSize;
+
+ FreePool (Info);
+ } else if (Status == EFI_NOT_FOUND) {
+ //
+ // file not exists. add create and try again
+ //
+ Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ } else {
+ //
+ // it worked. now delete it and move on with the name (now validated)
+ //
+ Status = ShellDeleteFile (&FileHandle);
+ if (Status == EFI_WARN_DELETE_FAILURE) {
+ Status = EFI_ACCESS_DENIED;
+ }
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+ //
+ // file doesn't exist, so set CreateFile to TRUE and can't be read-only
+ //
+ CreateFile = TRUE;
+ *ReadOnly = FALSE;
+ }
+
+ //
+ // the file exists
+ //
+ if (!CreateFile) {
+ //
+ // allocate buffer to read file
+ //
+ InternalBuffer = AllocateZeroPool (FileSize);
+ if (InternalBuffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ //
+ // read file into InternalBuffer
+ //
+ Status = ShellReadFile (FileHandle, &FileSize, InternalBuffer);
+ ShellCloseFile(&FileHandle);
+ FileHandle = NULL;
+ if (EFI_ERROR (Status)) {
+ SHELL_FREE_NON_NULL (InternalBuffer);
+ return EFI_LOAD_ERROR;
+ }
+ }
+ *Buffer = InternalBuffer;
+ if (BufferSize != NULL) {
+ *BufferSize = FileSize;
+ }
+ return (EFI_SUCCESS);
+
+}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h index f34889f76d..de754e8bc7 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h @@ -1,7 +1,7 @@ /** @file
Main file for NULL named library for Profile1 shell command functions.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -12,12 +12,16 @@ **/
+#if !defined (_UEFI_SHELL_DEBUG1_COMMANDS_LIB_H_)
+#define _UEFI_SHELL_DEBUG1_COMMANDS_LIB_H_
+
#include <Uefi.h>
#include <ShellBase.h>
#include <Guid/GlobalVariable.h>
#include <Guid/ConsoleInDevice.h>
#include <Guid/ConsoleOutDevice.h>
+#include <Guid/FileSystemInfo.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
@@ -34,6 +38,8 @@ #include <Protocol/DriverFamilyOverride.h>
#include <Protocol/DriverHealth.h>
#include <Protocol/DevicePathFromText.h>
+#include <Protocol/SimplePointer.h>
+#include <Protocol/PciRootBridgeIo.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
@@ -77,7 +83,7 @@ DumpHex ( EFI System Table based on the provided GUID.
@param[in] TableGuid A pointer to the table's GUID type.
- @param[out] Table On exit, a pointer to a system configuration table.
+ @param[in,out] Table On exit, a pointer to a system configuration table.
@retval EFI_SUCCESS A configuration table matching TableGuid was found.
@retval EFI_NOT_FOUND A configuration table matching TableGuid was not found.
@@ -329,4 +335,135 @@ ShellCommandRunDblk ( IN EFI_SYSTEM_TABLE *SystemTable
);
+/**
+ Function for 'edit' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
+SHELL_STATUS
+EFIAPI
+ShellCommandRunEdit (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+ Function for 'hexedit' command.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
+SHELL_STATUS
+EFIAPI
+ShellCommandRunHexEdit (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+ Appends a formatted Unicode string to a Null-terminated Unicode string
+
+ This function appends a formatted Unicode string to the Null-terminated
+ Unicode string specified by String. String is optional and may be NULL.
+ Storage for the formatted Unicode string returned is allocated using
+ AllocateZeroPool(). The pointer to the appended string is returned. The caller
+ is responsible for freeing the returned string.
+
+ If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().
+ If Format is NULL, then ASSERT().
+ If Format is not aligned on a 16-bit boundary, then ASSERT().
+
+ @param String A null-terminated Unicode string.
+ @param FormatString A null-terminated Unicode format string.
+ @param ... The variable argument list whose contents are accessed based
+ on the format string specified by Format.
+
+ @retval NULL There was not enough available memory.
+ @return Null terminated Unicode string is that is the formatted
+ string appended to String.
+ @sa CatVSPrint
+**/
+CHAR16*
+EFIAPI
+CatSPrint (
+ IN CONST CHAR16 *String OPTIONAL,
+ IN CONST CHAR16 *FormatString,
+ ...
+ );
+
+/**
+ Clear the line at the specified Row.
+
+ @param[in] Row The row number to be cleared ( start from 1 )
+ @param[in] LastCol The last printable column.
+ @param[in] LastRow The last printable row.
+**/
+VOID
+EFIAPI
+EditorClearLine (
+ IN UINTN Row,
+ IN UINTN LastCol,
+ IN UINTN LastRow
+ );
+
+/**
+ Check if file name has illegal characters.
+
+ @param Name The filename to check.
+
+ @retval TRUE The filename is ok.
+ @retval FALSE The filename is not ok.
+**/
+BOOLEAN
+EFIAPI
+IsValidFileName (
+ IN CONST CHAR16 *Name
+ );
+
+/**
+ Find a filename that is valid (not taken) with the given extension.
+
+ @param[in] Extension The file extension.
+
+ @retval NULL Something went wrong.
+ @return the valid filename.
+**/
+CHAR16 *
+EFIAPI
+EditGetDefaultFileName (
+ IN CONST CHAR16 *Extension
+ );
+
+/**
+ Read a file into an allocated buffer. The buffer is the responsibility
+ of the caller to free.
+
+ @param[in] FileName The filename of the file to open.
+ @param[out] Buffer Upon successful return, the pointer to the
+ address of the allocated buffer.
+ @param[out] BufferSize If not NULL, then the pointer to the size
+ of the allocated buffer.
+ @param[out] ReadOnly Upon successful return TRUE if the file is
+ read only. FALSE otherwise.
+
+ @retval EFI_NOT_FOUND The filename did not represent a file in the
+ file system. Directories cannot be read with
+ this method.
+ @retval EFI_SUCCESS The file was read into the buffer.
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
+ @retval EFI_LOAD_ERROR The file read operation failed.
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
+ @retval EFI_INVALID_PARAMETER FileName was NULL.
+ @retval EFI_INVALID_PARAMETER FileName was a directory.
+**/
+EFI_STATUS
+EFIAPI
+ReadFileIntoBuffer (
+ IN CONST CHAR16 *FileName,
+ OUT VOID **Buffer,
+ OUT UINTN *BufferSize OPTIONAL,
+ OUT BOOLEAN *ReadOnly
+ );
+#endif
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf index e04c29b6ff..f83785b071 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf @@ -52,6 +52,48 @@ UefiShellDebug1CommandsLib.h
UefiShellDebug1CommandsLib.uni
+## Files shared by both editors
+ EditTitleBar.h
+ EditTitleBar.c
+ EditInputBar.h
+ EditInputBar.c
+ EditStatusBar.h
+ EditStatusBar.c
+ EditMenuBar.h
+ EditMenuBar.c
+
+## Files specific to the text editor
+ ./Edit/Edit.c
+ ./Edit/TextEditor.h
+ ./Edit/TextEditorTypes.h
+ ./Edit/FileBuffer.h
+ ./Edit/FileBuffer.c
+ ./Edit/MainTextEditor.h
+ ./Edit/MainTextEditor.c
+ ./Edit/Misc.h
+ ./Edit/Misc.c
+ ./Edit/TextEditStrings.uni
+
+## Files specific to the HEX editor
+ ./HexEdit/BufferImage.h
+ ./HexEdit/BufferImage.c
+ ./HexEdit/Clipboard.h
+ ./HexEdit/Clipboard.c
+ ./HexEdit/DiskImage.h
+ ./HexEdit/DiskImage.c
+ ./HexEdit/FileImage.h
+ ./HexEdit/FileImage.c
+ ./HexEdit/HexEdit.c
+ ./HexEdit/HexEditor.h
+ ./HexEdit/HexEditorTypes.h
+ ./HexEdit/HexeditStrings.uni
+ ./HexEdit/MainHexEditor.h
+ ./HexEdit/MainHexEditor.c
+ ./HexEdit/MemImage.h
+ ./HexEdit/MemImage.c
+ ./HexEdit/Misc.h
+ ./HexEdit/Misc.c
+
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
@@ -71,14 +113,20 @@ PrintLib
[Pcd]
- gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask # ALWAYS_CONSUMED
- gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize # ALWAYS_CONSUMED
+ gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask # ALWAYS_CONSUMED
+ gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize # ALWAYS_CONSUMED
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength # ALWAYS_CONSUMED
[Protocols]
gEfiPciRootBridgeIoProtocolGuid
gEfiBlockIoProtocolGuid
+ gEfiSimplePointerProtocolGuid
[Guids]
gEfiGlobalVariableGuid
gEfiSmbiosTableGuid
+ gEfiMpsTableGuid
+ gEfiSalSystemTableGuid
+ gEfiAcpi10TableGuid
+ gEfiAcpi20TableGuid
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni Binary files differindex 925bf849f4..733ff4d105 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni |