1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/** @file
Main file for Comp shell Debug1 function.
Copyright (c) 2010 - 2014, 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
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"
/**
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 (
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;
CONST CHAR16 *TempParam;
UINTN ErrorAddress;
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 {
TempParam = ShellCommandLineGetRawValue(Package, 1);
ASSERT(TempParam != NULL);
FileName1 = ShellFindFilePath(TempParam);
if (FileName1 == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam);
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, TempParam, Status);
ShellStatus = SHELL_NOT_FOUND;
}
}
TempParam = ShellCommandLineGetRawValue(Package, 2);
ASSERT(TempParam != NULL);
FileName2 = ShellFindFilePath(TempParam);
if (FileName2 == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam);
ShellStatus = SHELL_NOT_FOUND;
} 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, TempParam, Status);
ShellStatus = SHELL_NOT_FOUND;
}
}
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) {
ErrorAddress = LoopVar;
ADF_File11 = 0;
ADF_File12 = 0;
ADF_File13 = 0;
ADF_File21 = 0;
ADF_File22 = 0;
ADF_File23 = 0;
//
// Now check the next 3 bytes if possible. This will make output
// cleaner when there are a sequence of differences.
//
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);
}
}
}
//
// Print out based on highest of the 4 bytes that are different.
//
if (ADF_File13 != ADF_File23) {
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_COMP_SPOT_FAIL4),
gShellDebug1HiiHandle,
++ErrorCount,
FileName1,
ErrorAddress,
DataFromFile1, ADF_File11, ADF_File12, ADF_File13,
DataFromFile1, ADF_File11, ADF_File12, ADF_File13,
FileName2,
ErrorAddress,
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,
ErrorAddress,
DataFromFile1, ADF_File11, ADF_File12,
DataFromFile1, ADF_File11, ADF_File12,
FileName2,
ErrorAddress,
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,
ErrorAddress,
DataFromFile1, ADF_File11,
DataFromFile1, ADF_File11,
FileName2,
ErrorAddress,
DataFromFile2, ADF_File21,
DataFromFile2, ADF_File21
);
} else {
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_COMP_SPOT_FAIL1),
gShellDebug1HiiHandle,
++ErrorCount,
FileName1,
ErrorAddress,
DataFromFile1,
DataFromFile1,
FileName2,
ErrorAddress,
DataFromFile2,
DataFromFile2
);
}
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);
}
}
}
ShellCommandLineFreeVarList (Package);
}
SHELL_FREE_NON_NULL(FileName1);
SHELL_FREE_NON_NULL(FileName2);
if (FileHandle1 != NULL) {
gEfiShellProtocol->CloseFile(FileHandle1);
}
if (FileHandle2 != NULL) {
gEfiShellProtocol->CloseFile(FileHandle2);
}
return (ShellStatus);
}
|