jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 1 | /** @file
|
| 2 | Main file for Comp shell Debug1 function.
|
| 3 |
|
Tapan Shah | c011b6c | 2015-02-04 22:25:01 +0000 | [diff] [blame^] | 4 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 5 | Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 6 | This program and the accompanying materials
|
| 7 | are licensed and made available under the terms and conditions of the BSD License
|
| 8 | which accompanies this distribution. The full text of the license may be found at
|
| 9 | http://opensource.org/licenses/bsd-license.php
|
| 10 |
|
| 11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
| 12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
| 13 |
|
| 14 | **/
|
| 15 |
|
| 16 | #include "UefiShellDebug1CommandsLib.h"
|
| 17 |
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 18 | /**
|
| 19 | Function for 'comp' command.
|
| 20 |
|
| 21 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
| 22 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
| 23 | **/
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 24 | SHELL_STATUS
|
| 25 | EFIAPI
|
| 26 | ShellCommandRunComp (
|
| 27 | IN EFI_HANDLE ImageHandle,
|
| 28 | IN EFI_SYSTEM_TABLE *SystemTable
|
| 29 | )
|
| 30 | {
|
| 31 | EFI_STATUS Status;
|
| 32 | LIST_ENTRY *Package;
|
| 33 | CHAR16 *ProblemParam;
|
| 34 | SHELL_STATUS ShellStatus;
|
| 35 | UINTN LoopVar;
|
| 36 | SHELL_FILE_HANDLE FileHandle1;
|
| 37 | SHELL_FILE_HANDLE FileHandle2;
|
| 38 | UINT8 ErrorCount;
|
| 39 | UINT64 Size1;
|
| 40 | UINT64 Size2;
|
| 41 | UINT8 DataFromFile1;
|
| 42 | UINT8 DataFromFile2;
|
| 43 | UINT8 ADF_File11;
|
| 44 | UINT8 ADF_File12;
|
| 45 | UINT8 ADF_File13;
|
| 46 | UINT8 ADF_File21;
|
| 47 | UINT8 ADF_File22;
|
| 48 | UINT8 ADF_File23;
|
| 49 | UINTN DataSizeFromFile1;
|
| 50 | UINTN DataSizeFromFile2;
|
| 51 | CHAR16 *FileName1;
|
| 52 | CHAR16 *FileName2;
|
jcarsey | ecae511 | 2011-10-10 20:32:17 +0000 | [diff] [blame] | 53 | CONST CHAR16 *TempParam;
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 54 | UINTN ErrorAddress;
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 55 |
|
| 56 | ErrorCount = 0;
|
| 57 | ShellStatus = SHELL_SUCCESS;
|
| 58 | Status = EFI_SUCCESS;
|
| 59 | FileName1 = NULL;
|
| 60 | FileName2 = NULL;
|
| 61 | FileHandle1 = NULL;
|
| 62 | FileHandle2 = NULL;
|
| 63 | Size1 = 0;
|
| 64 |
|
| 65 | //
|
| 66 | // initialize the shell lib (we must be in non-auto-init...)
|
| 67 | //
|
| 68 | Status = ShellInitialize();
|
| 69 | ASSERT_EFI_ERROR(Status);
|
| 70 |
|
| 71 | Status = CommandInit();
|
| 72 | ASSERT_EFI_ERROR(Status);
|
| 73 |
|
| 74 | //
|
| 75 | // parse the command line
|
| 76 | //
|
| 77 | Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
| 78 | if (EFI_ERROR(Status)) {
|
| 79 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
Tapan Shah | 4092a8f | 2015-02-03 21:22:53 +0000 | [diff] [blame] | 80 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam);
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 81 | FreePool(ProblemParam);
|
| 82 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 83 | } else {
|
| 84 | ASSERT(FALSE);
|
| 85 | }
|
| 86 | } else {
|
| 87 | if (ShellCommandLineGetCount(Package) > 3) {
|
Tapan Shah | 4092a8f | 2015-02-03 21:22:53 +0000 | [diff] [blame] | 88 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp");
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 89 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 90 | } else if (ShellCommandLineGetCount(Package) < 3) {
|
Tapan Shah | 4092a8f | 2015-02-03 21:22:53 +0000 | [diff] [blame] | 91 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp");
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 92 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 93 | } else {
|
jcarsey | ecae511 | 2011-10-10 20:32:17 +0000 | [diff] [blame] | 94 | TempParam = ShellCommandLineGetRawValue(Package, 1);
|
| 95 | ASSERT(TempParam != NULL);
|
| 96 | FileName1 = ShellFindFilePath(TempParam);
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 97 | if (FileName1 == NULL) {
|
Tapan Shah | 4092a8f | 2015-02-03 21:22:53 +0000 | [diff] [blame] | 98 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 99 | ShellStatus = SHELL_NOT_FOUND;
|
| 100 | } else {
|
| 101 | Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);
|
| 102 | if (EFI_ERROR(Status)) {
|
Tapan Shah | 4092a8f | 2015-02-03 21:22:53 +0000 | [diff] [blame] | 103 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 104 | ShellStatus = SHELL_NOT_FOUND;
|
| 105 | }
|
| 106 | }
|
jcarsey | ecae511 | 2011-10-10 20:32:17 +0000 | [diff] [blame] | 107 | TempParam = ShellCommandLineGetRawValue(Package, 2);
|
| 108 | ASSERT(TempParam != NULL);
|
| 109 | FileName2 = ShellFindFilePath(TempParam);
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 110 | if (FileName2 == NULL) {
|
Tapan Shah | 4092a8f | 2015-02-03 21:22:53 +0000 | [diff] [blame] | 111 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 112 | ShellStatus = SHELL_NOT_FOUND;
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 113 | } else {
|
| 114 | Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);
|
| 115 | if (EFI_ERROR(Status)) {
|
Tapan Shah | 4092a8f | 2015-02-03 21:22:53 +0000 | [diff] [blame] | 116 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 117 | ShellStatus = SHELL_NOT_FOUND;
|
| 118 | }
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 119 | }
|
| 120 | if (ShellStatus == SHELL_SUCCESS) {
|
| 121 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_HEADER), gShellDebug1HiiHandle, FileName1, FileName2);
|
| 122 | Status = gEfiShellProtocol->GetFileSize(FileHandle1, &Size1);
|
| 123 | ASSERT_EFI_ERROR(Status);
|
| 124 | Status = gEfiShellProtocol->GetFileSize(FileHandle2, &Size2);
|
| 125 | ASSERT_EFI_ERROR(Status);
|
| 126 | if (Size1 != Size2) {
|
| 127 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_SIZE_FAIL), gShellDebug1HiiHandle);
|
| 128 | ErrorCount++;
|
| 129 | ShellStatus = SHELL_NOT_EQUAL;
|
| 130 | }
|
| 131 | }
|
| 132 | if (ShellStatus == SHELL_SUCCESS) {
|
| 133 | for (LoopVar = 0 ; LoopVar < Size1 && ErrorCount <= 10 ; LoopVar++) {
|
| 134 | DataSizeFromFile1 = 1;
|
| 135 | DataSizeFromFile2 = 1;
|
| 136 | Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &DataFromFile1);
|
| 137 | ASSERT_EFI_ERROR(Status);
|
| 138 | Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &DataFromFile2);
|
| 139 | ASSERT_EFI_ERROR(Status);
|
| 140 | if (DataFromFile1 != DataFromFile2) {
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 141 | ErrorAddress = LoopVar;
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 142 | ADF_File11 = 0;
|
| 143 | ADF_File12 = 0;
|
| 144 | ADF_File13 = 0;
|
| 145 | ADF_File21 = 0;
|
| 146 | ADF_File22 = 0;
|
| 147 | ADF_File23 = 0;
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 148 |
|
| 149 | //
|
| 150 | // Now check the next 3 bytes if possible. This will make output
|
| 151 | // cleaner when there are a sequence of differences.
|
| 152 | //
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 153 | if (LoopVar + 1 < Size1) {
|
| 154 | LoopVar++;
|
| 155 | DataSizeFromFile1 = 1;
|
| 156 | DataSizeFromFile2 = 1;
|
| 157 | Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File11);
|
| 158 | ASSERT_EFI_ERROR(Status);
|
| 159 | Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File21);
|
| 160 | ASSERT_EFI_ERROR(Status);
|
| 161 | if (LoopVar + 1 < Size1) {
|
| 162 | LoopVar++;
|
| 163 | DataSizeFromFile1 = 1;
|
| 164 | DataSizeFromFile2 = 1;
|
| 165 | Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File12);
|
| 166 | ASSERT_EFI_ERROR(Status);
|
| 167 | Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File22);
|
| 168 | ASSERT_EFI_ERROR(Status);
|
| 169 | if (LoopVar + 1 < Size1) {
|
| 170 | LoopVar++;
|
| 171 | DataSizeFromFile1 = 1;
|
| 172 | DataSizeFromFile2 = 1;
|
| 173 | Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File13);
|
| 174 | ASSERT_EFI_ERROR(Status);
|
| 175 | Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File23);
|
| 176 | ASSERT_EFI_ERROR(Status);
|
| 177 | }
|
| 178 | }
|
| 179 | }
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 180 |
|
| 181 | //
|
| 182 | // Print out based on highest of the 4 bytes that are different.
|
| 183 | //
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 184 | if (ADF_File13 != ADF_File23) {
|
| 185 | ShellPrintHiiEx(
|
| 186 | -1,
|
| 187 | -1,
|
| 188 | NULL,
|
| 189 | STRING_TOKEN (STR_COMP_SPOT_FAIL4),
|
| 190 | gShellDebug1HiiHandle,
|
| 191 | ++ErrorCount,
|
| 192 | FileName1,
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 193 | ErrorAddress,
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 194 | DataFromFile1, ADF_File11, ADF_File12, ADF_File13,
|
| 195 | DataFromFile1, ADF_File11, ADF_File12, ADF_File13,
|
| 196 | FileName2,
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 197 | ErrorAddress,
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 198 | DataFromFile2, ADF_File21, ADF_File22, ADF_File23,
|
| 199 | DataFromFile2, ADF_File21, ADF_File22, ADF_File23
|
| 200 | );
|
| 201 | } else if (ADF_File12 != ADF_File22) {
|
| 202 | ShellPrintHiiEx(
|
| 203 | -1,
|
| 204 | -1,
|
| 205 | NULL,
|
| 206 | STRING_TOKEN (STR_COMP_SPOT_FAIL3),
|
| 207 | gShellDebug1HiiHandle,
|
| 208 | ++ErrorCount,
|
| 209 | FileName1,
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 210 | ErrorAddress,
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 211 | DataFromFile1, ADF_File11, ADF_File12,
|
| 212 | DataFromFile1, ADF_File11, ADF_File12,
|
| 213 | FileName2,
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 214 | ErrorAddress,
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 215 | DataFromFile2, ADF_File21, ADF_File22,
|
| 216 | DataFromFile2, ADF_File21, ADF_File22
|
| 217 | );
|
| 218 | } else if (ADF_File11 != ADF_File21) {
|
| 219 | ShellPrintHiiEx(
|
| 220 | -1,
|
| 221 | -1,
|
| 222 | NULL,
|
| 223 | STRING_TOKEN (STR_COMP_SPOT_FAIL2),
|
| 224 | gShellDebug1HiiHandle,
|
| 225 | ++ErrorCount,
|
| 226 | FileName1,
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 227 | ErrorAddress,
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 228 | DataFromFile1, ADF_File11,
|
| 229 | DataFromFile1, ADF_File11,
|
| 230 | FileName2,
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 231 | ErrorAddress,
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 232 | DataFromFile2, ADF_File21,
|
| 233 | DataFromFile2, ADF_File21
|
| 234 | );
|
| 235 | } else {
|
| 236 | ShellPrintHiiEx(
|
| 237 | -1,
|
| 238 | -1,
|
| 239 | NULL,
|
| 240 | STRING_TOKEN (STR_COMP_SPOT_FAIL1),
|
| 241 | gShellDebug1HiiHandle,
|
| 242 | ++ErrorCount,
|
| 243 | FileName1,
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 244 | ErrorAddress,
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 245 | DataFromFile1,
|
| 246 | DataFromFile1,
|
| 247 | FileName2,
|
Jaben Carsey | 33eb033 | 2014-06-05 22:02:12 +0000 | [diff] [blame] | 248 | ErrorAddress,
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 249 | DataFromFile2,
|
| 250 | DataFromFile2
|
| 251 | );
|
| 252 | }
|
| 253 | ShellStatus = SHELL_NOT_EQUAL;
|
| 254 | }
|
| 255 | }
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 256 | if (ErrorCount == 0) {
|
| 257 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle);
|
| 258 | } else {
|
| 259 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle);
|
| 260 | }
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 261 | }
|
| 262 | }
|
| 263 |
|
| 264 | ShellCommandLineFreeVarList (Package);
|
| 265 | }
|
jcarsey | 3737ac2 | 2011-03-25 21:22:20 +0000 | [diff] [blame] | 266 | SHELL_FREE_NON_NULL(FileName1);
|
| 267 | SHELL_FREE_NON_NULL(FileName2);
|
| 268 |
|
jcarsey | 5d73d92 | 2010-11-16 22:36:37 +0000 | [diff] [blame] | 269 | if (FileHandle1 != NULL) {
|
| 270 | gEfiShellProtocol->CloseFile(FileHandle1);
|
| 271 | }
|
| 272 | if (FileHandle2 != NULL) {
|
| 273 | gEfiShellProtocol->CloseFile(FileHandle2);
|
| 274 | }
|
| 275 |
|
| 276 | return (ShellStatus);
|
| 277 | }
|