2010-11-16 23:36:37 +01:00
|
|
|
/** @file
|
|
|
|
Main file for Comp shell Debug1 function.
|
|
|
|
|
2014-06-06 00:02:12 +02:00
|
|
|
Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
2010-11-16 23:36:37 +01:00
|
|
|
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
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "UefiShellDebug1CommandsLib.h"
|
|
|
|
|
2011-03-25 22:22:20 +01:00
|
|
|
/**
|
|
|
|
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).
|
|
|
|
**/
|
2010-11-16 23:36:37 +01:00
|
|
|
SHELL_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ShellCommandRunComp (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
LIST_ENTRY *Package;
|
|
|
|
CHAR16 *ProblemParam;
|
|
|
|
SHELL_STATUS ShellStatus;
|
|
|
|
UINTN LoopVar;
|
|
|
|
SHELL_FILE_HANDLE FileHandle1;
|
|
|
|
SHELL_FILE_HANDLE FileHandle2;
|
|
|
|
UINT8 ErrorCount;
|
|
|
|
UINT64 Size1;
|
|
|
|
UINT64 Size2;
|
|
|
|
UINT8 DataFromFile1;
|
|
|
|
UINT8 DataFromFile2;
|
|
|
|
UINT8 ADF_File11;
|
|
|
|
UINT8 ADF_File12;
|
|
|
|
UINT8 ADF_File13;
|
|
|
|
UINT8 ADF_File21;
|
|
|
|
UINT8 ADF_File22;
|
|
|
|
UINT8 ADF_File23;
|
|
|
|
UINTN DataSizeFromFile1;
|
|
|
|
UINTN DataSizeFromFile2;
|
|
|
|
CHAR16 *FileName1;
|
|
|
|
CHAR16 *FileName2;
|
2011-10-10 22:32:17 +02:00
|
|
|
CONST CHAR16 *TempParam;
|
2014-06-06 00:02:12 +02:00
|
|
|
UINTN ErrorAddress;
|
2010-11-16 23:36:37 +01:00
|
|
|
|
|
|
|
ErrorCount = 0;
|
|
|
|
ShellStatus = SHELL_SUCCESS;
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
FileName1 = NULL;
|
|
|
|
FileName2 = NULL;
|
|
|
|
FileHandle1 = NULL;
|
|
|
|
FileHandle2 = NULL;
|
|
|
|
Size1 = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// initialize the shell lib (we must be in non-auto-init...)
|
|
|
|
//
|
|
|
|
Status = ShellInitialize();
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
|
|
|
|
Status = CommandInit();
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// parse the command line
|
|
|
|
//
|
|
|
|
Status = ShellCommandLineParse (EmptyParamList, &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);
|
|
|
|
FreePool(ProblemParam);
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
ASSERT(FALSE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ShellCommandLineGetCount(Package) > 3) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else if (ShellCommandLineGetCount(Package) < 3) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
|
|
|
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
|
|
|
} else {
|
2011-10-10 22:32:17 +02:00
|
|
|
TempParam = ShellCommandLineGetRawValue(Package, 1);
|
|
|
|
ASSERT(TempParam != NULL);
|
|
|
|
FileName1 = ShellFindFilePath(TempParam);
|
2011-03-25 22:22:20 +01:00
|
|
|
if (FileName1 == NULL) {
|
2011-10-10 22:32:17 +02:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam);
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_NOT_FOUND;
|
2011-03-25 22:22:20 +01:00
|
|
|
} else {
|
|
|
|
Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);
|
|
|
|
if (EFI_ERROR(Status)) {
|
2011-10-10 22:32:17 +02:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, TempParam, Status);
|
2011-03-25 22:22:20 +01:00
|
|
|
ShellStatus = SHELL_NOT_FOUND;
|
|
|
|
}
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
2011-10-10 22:32:17 +02:00
|
|
|
TempParam = ShellCommandLineGetRawValue(Package, 2);
|
|
|
|
ASSERT(TempParam != NULL);
|
|
|
|
FileName2 = ShellFindFilePath(TempParam);
|
2011-03-25 22:22:20 +01:00
|
|
|
if (FileName2 == NULL) {
|
2011-10-10 22:32:17 +02:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam);
|
2010-11-16 23:36:37 +01:00
|
|
|
ShellStatus = SHELL_NOT_FOUND;
|
2011-03-25 22:22:20 +01:00
|
|
|
} else {
|
|
|
|
Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);
|
|
|
|
if (EFI_ERROR(Status)) {
|
2011-10-10 22:32:17 +02:00
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, TempParam, Status);
|
2011-03-25 22:22:20 +01:00
|
|
|
ShellStatus = SHELL_NOT_FOUND;
|
|
|
|
}
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
|
|
|
if (ShellStatus == SHELL_SUCCESS) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_HEADER), gShellDebug1HiiHandle, FileName1, FileName2);
|
|
|
|
Status = gEfiShellProtocol->GetFileSize(FileHandle1, &Size1);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
Status = gEfiShellProtocol->GetFileSize(FileHandle2, &Size2);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
if (Size1 != Size2) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_SIZE_FAIL), gShellDebug1HiiHandle);
|
|
|
|
ErrorCount++;
|
|
|
|
ShellStatus = SHELL_NOT_EQUAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ShellStatus == SHELL_SUCCESS) {
|
|
|
|
for (LoopVar = 0 ; LoopVar < Size1 && ErrorCount <= 10 ; LoopVar++) {
|
|
|
|
DataSizeFromFile1 = 1;
|
|
|
|
DataSizeFromFile2 = 1;
|
|
|
|
Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &DataFromFile1);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &DataFromFile2);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
if (DataFromFile1 != DataFromFile2) {
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress = LoopVar;
|
2010-11-16 23:36:37 +01:00
|
|
|
ADF_File11 = 0;
|
|
|
|
ADF_File12 = 0;
|
|
|
|
ADF_File13 = 0;
|
|
|
|
ADF_File21 = 0;
|
|
|
|
ADF_File22 = 0;
|
|
|
|
ADF_File23 = 0;
|
2014-06-06 00:02:12 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Now check the next 3 bytes if possible. This will make output
|
|
|
|
// cleaner when there are a sequence of differences.
|
|
|
|
//
|
2010-11-16 23:36:37 +01:00
|
|
|
if (LoopVar + 1 < Size1) {
|
|
|
|
LoopVar++;
|
|
|
|
DataSizeFromFile1 = 1;
|
|
|
|
DataSizeFromFile2 = 1;
|
|
|
|
Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File11);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File21);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
if (LoopVar + 1 < Size1) {
|
|
|
|
LoopVar++;
|
|
|
|
DataSizeFromFile1 = 1;
|
|
|
|
DataSizeFromFile2 = 1;
|
|
|
|
Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File12);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File22);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
if (LoopVar + 1 < Size1) {
|
|
|
|
LoopVar++;
|
|
|
|
DataSizeFromFile1 = 1;
|
|
|
|
DataSizeFromFile2 = 1;
|
|
|
|
Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File13);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File23);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-06 00:02:12 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Print out based on highest of the 4 bytes that are different.
|
|
|
|
//
|
2010-11-16 23:36:37 +01:00
|
|
|
if (ADF_File13 != ADF_File23) {
|
|
|
|
ShellPrintHiiEx(
|
|
|
|
-1,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
STRING_TOKEN (STR_COMP_SPOT_FAIL4),
|
|
|
|
gShellDebug1HiiHandle,
|
|
|
|
++ErrorCount,
|
|
|
|
FileName1,
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress,
|
2010-11-16 23:36:37 +01:00
|
|
|
DataFromFile1, ADF_File11, ADF_File12, ADF_File13,
|
|
|
|
DataFromFile1, ADF_File11, ADF_File12, ADF_File13,
|
|
|
|
FileName2,
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress,
|
2010-11-16 23:36:37 +01:00
|
|
|
DataFromFile2, ADF_File21, ADF_File22, ADF_File23,
|
|
|
|
DataFromFile2, ADF_File21, ADF_File22, ADF_File23
|
|
|
|
);
|
|
|
|
} else if (ADF_File12 != ADF_File22) {
|
|
|
|
ShellPrintHiiEx(
|
|
|
|
-1,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
STRING_TOKEN (STR_COMP_SPOT_FAIL3),
|
|
|
|
gShellDebug1HiiHandle,
|
|
|
|
++ErrorCount,
|
|
|
|
FileName1,
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress,
|
2010-11-16 23:36:37 +01:00
|
|
|
DataFromFile1, ADF_File11, ADF_File12,
|
|
|
|
DataFromFile1, ADF_File11, ADF_File12,
|
|
|
|
FileName2,
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress,
|
2010-11-16 23:36:37 +01:00
|
|
|
DataFromFile2, ADF_File21, ADF_File22,
|
|
|
|
DataFromFile2, ADF_File21, ADF_File22
|
|
|
|
);
|
|
|
|
} else if (ADF_File11 != ADF_File21) {
|
|
|
|
ShellPrintHiiEx(
|
|
|
|
-1,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
STRING_TOKEN (STR_COMP_SPOT_FAIL2),
|
|
|
|
gShellDebug1HiiHandle,
|
|
|
|
++ErrorCount,
|
|
|
|
FileName1,
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress,
|
2010-11-16 23:36:37 +01:00
|
|
|
DataFromFile1, ADF_File11,
|
|
|
|
DataFromFile1, ADF_File11,
|
|
|
|
FileName2,
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress,
|
2010-11-16 23:36:37 +01:00
|
|
|
DataFromFile2, ADF_File21,
|
|
|
|
DataFromFile2, ADF_File21
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ShellPrintHiiEx(
|
|
|
|
-1,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
STRING_TOKEN (STR_COMP_SPOT_FAIL1),
|
|
|
|
gShellDebug1HiiHandle,
|
|
|
|
++ErrorCount,
|
|
|
|
FileName1,
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress,
|
2010-11-16 23:36:37 +01:00
|
|
|
DataFromFile1,
|
|
|
|
DataFromFile1,
|
|
|
|
FileName2,
|
2014-06-06 00:02:12 +02:00
|
|
|
ErrorAddress,
|
2010-11-16 23:36:37 +01:00
|
|
|
DataFromFile2,
|
|
|
|
DataFromFile2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
ShellStatus = SHELL_NOT_EQUAL;
|
|
|
|
}
|
|
|
|
}
|
2011-03-25 22:22:20 +01:00
|
|
|
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);
|
|
|
|
}
|
2010-11-16 23:36:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShellCommandLineFreeVarList (Package);
|
|
|
|
}
|
2011-03-25 22:22:20 +01:00
|
|
|
SHELL_FREE_NON_NULL(FileName1);
|
|
|
|
SHELL_FREE_NON_NULL(FileName2);
|
|
|
|
|
2010-11-16 23:36:37 +01:00
|
|
|
if (FileHandle1 != NULL) {
|
|
|
|
gEfiShellProtocol->CloseFile(FileHandle1);
|
|
|
|
}
|
|
|
|
if (FileHandle2 != NULL) {
|
|
|
|
gEfiShellProtocol->CloseFile(FileHandle2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ShellStatus);
|
|
|
|
}
|