1 /******************************************************************************
3 * Module Name: abcompare - compare AML files
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
48 ACPI_TABLE_HEADER Header1;
49 ACPI_TABLE_HEADER Header2;
51 #define BUFFER_SIZE 256
52 char Buffer[BUFFER_SIZE];
55 /* Local prototypes */
59 ACPI_TABLE_HEADER *Header);
73 ACPI_TABLE_HEADER *Header);
77 ACPI_TABLE_HEADER *Header,
78 ACPI_TABLE_HEADER *Header2);
81 /******************************************************************************
83 * FUNCTION: AbValidateHeader
85 * DESCRIPTION: Check for valid ACPI table header
87 ******************************************************************************/
91 ACPI_TABLE_HEADER *Header)
94 if (!AcpiUtValidAcpiName (Header->Signature))
96 printf ("Header signature is invalid\n");
104 /*******************************************************************************
106 * FUNCTION: AcpiTbSumTable
108 * PARAMETERS: Buffer - Buffer to checksum
109 * Length - Size of the buffer
111 * RETURNS 8 bit checksum of buffer
113 * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it.
115 ******************************************************************************/
127 if (Buffer && Length)
129 /* Buffer and Length are valid */
131 Limit = (UINT8 *) Buffer + Length;
133 for (Rover = Buffer; Rover < Limit; Rover++)
135 Sum = (UINT8) (Sum + *Rover);
143 /*******************************************************************************
145 * FUNCTION: AbPrintHeaderInfo
147 * PARAMETERS: Header - An ACPI table header
151 * DESCRIPTION: Format and display header contents.
153 ******************************************************************************/
157 ACPI_TABLE_HEADER *Header)
160 /* Display header information */
162 printf ("Signature : %4.4s\n", Header->Signature);
163 printf ("Length : %8.8X\n", Header->Length);
164 printf ("Revision : %2.2X\n", Header->Revision);
165 printf ("Checksum : %2.2X\n", Header->Checksum);
166 printf ("OEM ID : %.6s\n", Header->OemId);
167 printf ("OEM Table ID : %.8s\n", Header->OemTableId);
168 printf ("OEM Revision : %8.8X\n", Header->OemRevision);
169 printf ("ASL Compiler ID : %.4s\n", Header->AslCompilerId);
170 printf ("Compiler Revision : %8.8X\n", Header->AslCompilerRevision);
176 ACPI_TABLE_HEADER *Header,
177 ACPI_TABLE_HEADER *Header2)
180 /* Display header information for both headers */
182 printf ("Signature %8.4s : %4.4s\n", Header->Signature, Header2->Signature);
183 printf ("Length %8.8X : %8.8X\n", Header->Length, Header2->Length);
184 printf ("Revision %8.2X : %2.2X\n", Header->Revision, Header2->Revision);
185 printf ("Checksum %8.2X : %2.2X\n", Header->Checksum, Header2->Checksum);
186 printf ("OEM ID %8.6s : %.6s\n", Header->OemId, Header2->OemId);
187 printf ("OEM Table ID %8.8s : %.8s\n", Header->OemTableId, Header2->OemTableId);
188 printf ("OEM Revision %8.8X : %8.8X\n", Header->OemRevision, Header2->OemRevision);
189 printf ("ASL Compiler ID %8.4s : %.4s\n", Header->AslCompilerId, Header2->AslCompilerId);
190 printf ("Compiler Revision %8.8X : %8.8X\n", Header->AslCompilerRevision, Header2->AslCompilerRevision);
195 /******************************************************************************
197 * FUNCTION: AbDisplayHeader
199 * DESCRIPTION: Display an ACPI table header
201 ******************************************************************************/
211 File = fopen (FilePath, "rb");
214 printf ("Could not open file %s\n", FilePath);
218 Actual = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File);
221 if (Actual != sizeof (ACPI_TABLE_HEADER))
223 printf ("File %s does not contain a valid ACPI table header\n", FilePath);
227 if (!AbValidateHeader (&Header1))
232 AbPrintHeaderInfo (&Header1);
236 /******************************************************************************
238 * FUNCTION: AbComputeChecksum
240 * DESCRIPTION: Compute proper checksum for an ACPI table
242 ******************************************************************************/
249 ACPI_TABLE_HEADER *Table;
254 File = fopen (FilePath, "rb");
257 printf ("Could not open file %s\n", FilePath);
261 Actual = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File);
262 if (Actual < sizeof (ACPI_TABLE_HEADER))
264 printf ("File %s does not contain a valid ACPI table header\n", FilePath);
268 if (!AbValidateHeader (&Header1))
275 AbPrintHeaderInfo (&Header1);
278 /* Allocate a buffer to hold the entire table */
280 Table = AcpiOsAllocate (Header1.Length);
283 printf ("Could not allocate buffer for table\n");
287 /* Read the entire table, including header */
289 fseek (File, 0, SEEK_SET);
290 Actual = fread (Table, 1, Header1.Length, File);
291 if (Actual != Header1.Length)
293 printf ("Could not read table, length %u\n", Header1.Length);
297 /* Compute the checksum for the table */
301 Checksum = (UINT8) (0 - AcpiTbSumTable (Table, Table->Length));
302 printf ("Computed checksum: 0x%X\n\n", Checksum);
304 if (Header1.Checksum == Checksum)
306 printf ("Checksum OK in AML file, not updating\n");
310 /* Open the target file for writing, to update checksum */
313 File = fopen (FilePath, "r+b");
316 printf ("Could not open file %s for writing\n", FilePath);
320 /* Set the checksum, write the new header */
322 Header1.Checksum = Checksum;
324 Actual = fwrite (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File);
325 if (Actual != sizeof (ACPI_TABLE_HEADER))
327 printf ("Could not write updated table header\n");
331 printf ("Wrote new checksum\n");
345 /******************************************************************************
347 * FUNCTION: AbCompareAmlFiles
349 * DESCRIPTION: Compare two AML files
351 ******************************************************************************/
363 UINT8 Mismatches = 0;
364 BOOLEAN HeaderMismatch = FALSE;
370 File1 = fopen (File1Path, "rb");
373 printf ("Could not open file %s\n", File1Path);
377 File2 = fopen (File2Path, "rb");
380 printf ("Could not open file %s\n", File2Path);
384 /* Read the ACPI header from each file */
386 Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1);
387 if (Actual1 != sizeof (ACPI_TABLE_HEADER))
389 printf ("File %s does not contain an ACPI table header\n", File1Path);
393 Actual2 = fread (&Header2, 1, sizeof (ACPI_TABLE_HEADER), File2);
394 if (Actual2 != sizeof (ACPI_TABLE_HEADER))
396 printf ("File %s does not contain an ACPI table header\n", File2Path);
400 if ((!AbValidateHeader (&Header1)) ||
401 (!AbValidateHeader (&Header2)))
406 /* Table signatures must match */
408 if (*((UINT32 *) Header1.Signature) != *((UINT32 *) Header2.Signature))
410 printf ("Table signatures do not match\n");
416 /* Display header information */
418 AbPrintHeadersInfo (&Header1, &Header2);
421 if (memcmp (&Header1, &Header2, sizeof (ACPI_TABLE_HEADER)))
423 printf ("Headers do not match exactly\n");
424 HeaderMismatch = TRUE;
427 /* Do the byte-by-byte compare */
429 Actual1 = fread (&Char1, 1, 1, File1);
430 Actual2 = fread (&Char2, 1, 1, File2);
431 Offset = sizeof (ACPI_TABLE_HEADER);
433 while ((Actual1 == 1) && (Actual2 == 1))
437 printf ("Error - Byte mismatch at offset %8.8X: 0x%2.2X 0x%2.2X\n",
438 Offset, Char1, Char2);
440 if (Mismatches > 100)
442 printf ("100 Mismatches: Too many mismatches\n");
448 Actual1 = fread (&Char1, 1, 1, File1);
449 Actual2 = fread (&Char2, 1, 1, File2);
454 printf ("Error - file %s is longer than file %s\n", File1Path, File2Path);
459 printf ("Error - file %s is shorter than file %s\n", File1Path, File2Path);
462 else if (!Mismatches)
466 printf ("Files compare exactly after header\n");
470 printf ("Files compare exactly\n");
474 printf ("%u Mismatches found\n", Mismatches);
486 /******************************************************************************
488 * FUNCTION: AbGetFile
490 * DESCRIPTION: Open a file and read it entirely into a new buffer
492 ******************************************************************************/
505 /* Binary mode does not alter CR/LF pairs */
507 File = fopen (Filename, "rb");
510 printf ("Could not open file %s\n", Filename);
514 /* Need file size to allocate a buffer */
516 Size = CmGetFileSize (File);
517 if (Size == ACPI_UINT32_MAX)
519 printf ("Could not get file size (seek) for %s\n", Filename);
523 /* Allocate a buffer for the entire file */
525 Buffer = calloc (Size, 1);
528 printf ("Could not allocate buffer of size %u\n", Size);
532 /* Read the entire file */
534 Actual = fread (Buffer, 1, Size, File);
537 printf ("Could not read the input file %s\n", Filename);
551 /******************************************************************************
553 * FUNCTION: AbDumpAmlFile
555 * DESCRIPTION: Dump a binary AML file to a text file
557 ******************************************************************************/
570 /* Get the entire AML file, validate header */
572 FileBuffer = AbGetFile (File1Path, &FileSize);
578 printf ("Input file: %s contains %u (0x%X) bytes\n",
579 File1Path, FileSize, FileSize);
581 FileOutHandle = fopen (File2Path, "wb");
584 printf ("Could not open file %s\n", File2Path);
588 if (!AbValidateHeader ((ACPI_TABLE_HEADER *) FileBuffer))
593 /* Convert binary AML to text, using common dump buffer routine */
595 AcpiGbl_DebugFile = FileOutHandle;
596 AcpiGbl_DbOutputFlags = ACPI_DB_REDIRECTABLE_OUTPUT;
598 AcpiOsPrintf ("%4.4s @ 0x%8.8X\n",
599 ((ACPI_TABLE_HEADER *) FileBuffer)->Signature, 0);
601 AcpiUtDumpBuffer ((UINT8 *) FileBuffer, FileSize, DB_BYTE_DISPLAY, 0);
603 /* Summary for the output file */
605 FileSize = CmGetFileSize (FileOutHandle);
606 printf ("Output file: %s contains %u (0x%X) bytes\n\n",
607 File2Path, FileSize, FileSize);
612 fclose (FileOutHandle);
620 /******************************************************************************
624 * DESCRIPTION: For linkage
626 ******************************************************************************/