diff options
| author | Jung-uk Kim <jkim@FreeBSD.org> | 2012-11-14 22:20:16 +0000 |
|---|---|---|
| committer | Jung-uk Kim <jkim@FreeBSD.org> | 2012-11-14 22:20:16 +0000 |
| commit | c2463a8709e5b3a5ce54c09d35b4820a756b0fc5 (patch) | |
| tree | 2ffc551e57f0545a17c165d729c1438a26236f60 /source/tools | |
| parent | 31aa864e8c068201d58aad3a8f82ddb51df11015 (diff) | |
Notes
Diffstat (limited to 'source/tools')
| -rw-r--r-- | source/tools/acpibin/abcompare.c | 100 | ||||
| -rw-r--r-- | source/tools/acpibin/abmain.c | 4 | ||||
| -rw-r--r-- | source/tools/acpibin/acpibin.h | 15 | ||||
| -rw-r--r-- | source/tools/acpisrc/acpisrc.h | 30 | ||||
| -rw-r--r-- | source/tools/acpisrc/asfile.c | 58 | ||||
| -rw-r--r-- | source/tools/acpixtract/acpixtract.c | 10 |
6 files changed, 116 insertions, 101 deletions
diff --git a/source/tools/acpibin/abcompare.c b/source/tools/acpibin/abcompare.c index a0b241f5c4fd..5cbc80f18258 100644 --- a/source/tools/acpibin/abcompare.c +++ b/source/tools/acpibin/abcompare.c @@ -48,7 +48,6 @@ FILE *File1; FILE *File2; ACPI_TABLE_HEADER Header1; ACPI_TABLE_HEADER Header2; -struct stat Gbl_StatBuf; #define BUFFER_SIZE 256 char Buffer[BUFFER_SIZE]; @@ -74,6 +73,11 @@ static void AbPrintHeaderInfo ( ACPI_TABLE_HEADER *Header); +static void +AbPrintHeadersInfo ( + ACPI_TABLE_HEADER *Header, + ACPI_TABLE_HEADER *Header2); + ACPI_PHYSICAL_ADDRESS AeLocalGetRootPointer ( void); @@ -233,6 +237,26 @@ AbPrintHeaderInfo ( printf ("\n"); } +static void +AbPrintHeadersInfo ( + ACPI_TABLE_HEADER *Header, + ACPI_TABLE_HEADER *Header2) +{ + + /* Display header information for both headers */ + + printf ("Signature %8.4s : %4.4s\n", Header->Signature, Header2->Signature); + printf ("Length %8.8X : %8.8X\n", Header->Length, Header2->Length); + printf ("Revision %8.2X : %2.2X\n", Header->Revision, Header2->Revision); + printf ("Checksum %8.2X : %2.2X\n", Header->Checksum, Header2->Checksum); + printf ("OEM ID %8.6s : %6.6s\n", Header->OemId, Header2->OemId); + printf ("OEM Table ID %8.8s : %8.8s\n", Header->OemTableId, Header2->OemTableId); + printf ("OEM Revision %8.8X : %8.8X\n", Header->OemRevision, Header2->OemRevision); + printf ("ASL Compiler ID %8.4s : %4.4s\n", Header->AslCompilerId, Header2->AslCompilerId); + printf ("Compiler Revision %8.8X : %8.8X\n", Header->AslCompilerRevision, Header2->AslCompilerRevision); + printf ("\n"); +} + /****************************************************************************** * @@ -246,7 +270,7 @@ void AbDisplayHeader ( char *File1Path) { - UINT32 Actual1; + UINT32 Actual; File1 = fopen (File1Path, "rb"); @@ -256,8 +280,8 @@ AbDisplayHeader ( return; } - Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); - if (Actual1 < sizeof (ACPI_TABLE_HEADER)) + Actual = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); + if (Actual != sizeof (ACPI_TABLE_HEADER)) { printf ("File %s does not contain an ACPI table header\n", File1Path); return; @@ -284,7 +308,7 @@ void AbComputeChecksum ( char *File1Path) { - UINT32 Actual1; + UINT32 Actual; ACPI_TABLE_HEADER *Table; UINT8 Checksum; @@ -296,8 +320,8 @@ AbComputeChecksum ( return; } - Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); - if (Actual1 < sizeof (ACPI_TABLE_HEADER)) + Actual = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); + if (Actual < sizeof (ACPI_TABLE_HEADER)) { printf ("File %s does not contain an ACPI table header\n", File1Path); return; @@ -325,10 +349,10 @@ AbComputeChecksum ( /* Read the entire table, including header */ fseek (File1, 0, SEEK_SET); - Actual1 = fread (Table, 1, Header1.Length, File1); - if (Actual1 < Header1.Length) + Actual = fread (Table, 1, Header1.Length, File1); + if (Actual != Header1.Length) { - printf ("could not read table\n"); + printf ("could not read table, length %u\n", Header1.Length); return; } @@ -359,8 +383,8 @@ AbComputeChecksum ( Header1.Checksum = Checksum; - Actual1 = fwrite (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); - if (Actual1 < sizeof (ACPI_TABLE_HEADER)) + Actual = fwrite (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); + if (Actual != sizeof (ACPI_TABLE_HEADER)) { printf ("Could not write updated table header\n"); return; @@ -410,14 +434,14 @@ AbCompareAmlFiles ( /* Read the ACPI header from each file */ Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); - if (Actual1 < sizeof (ACPI_TABLE_HEADER)) + if (Actual1 != sizeof (ACPI_TABLE_HEADER)) { printf ("File %s does not contain an ACPI table header\n", File1Path); return (-1); } Actual2 = fread (&Header2, 1, sizeof (ACPI_TABLE_HEADER), File2); - if (Actual2 < sizeof (ACPI_TABLE_HEADER)) + if (Actual2 != sizeof (ACPI_TABLE_HEADER)) { printf ("File %s does not contain an ACPI table header\n", File2Path); return (-1); @@ -441,8 +465,7 @@ AbCompareAmlFiles ( { /* Display header information */ - AbPrintHeaderInfo (&Header1); - AbPrintHeaderInfo (&Header2); + AbPrintHeadersInfo (&Header1, &Header2); } if (memcmp (&Header1, &Header2, sizeof (ACPI_TABLE_HEADER))) @@ -457,7 +480,7 @@ AbCompareAmlFiles ( Actual2 = fread (&Char2, 1, 1, File2); Offset = sizeof (ACPI_TABLE_HEADER); - while (Actual1 && Actual2) + while ((Actual1 == 1) && (Actual2 == 1)) { if (Char1 != Char2) { @@ -505,7 +528,7 @@ AbCompareAmlFiles ( /****************************************************************************** * - * FUNCTION: AsGetFile + * FUNCTION: AbGetFile * * DESCRIPTION: Open a file and read it entirely into a new buffer * @@ -516,31 +539,37 @@ AbGetFile ( char *Filename, UINT32 *FileSize) { - int FileHandle; + FILE *File; UINT32 Size; char *Buffer = NULL; + int Seek1; + int Seek2; + size_t Actual; /* Binary mode does not alter CR/LF pairs */ - FileHandle = open (Filename, O_BINARY | O_RDONLY); - if (!FileHandle) + File = fopen (Filename, "rb"); + if (!File) { - printf ("Could not open %s\n", Filename); + printf ("Could not open file %s\n", Filename); return (NULL); } /* Need file size to allocate a buffer */ - if (fstat (FileHandle, &Gbl_StatBuf)) + Seek1 = fseek (File, 0L, SEEK_END); + Size = ftell (File); + Seek2 = fseek (File, 0L, SEEK_SET); + + if (Seek1 || Seek2 || (Size == -1)) { - printf ("Could not get file status for %s\n", Filename); + printf ("Could not get file size (seek) for %s\n", Filename); goto ErrorExit; } /* Allocate a buffer for the entire file */ - Size = Gbl_StatBuf.st_size; Buffer = calloc (Size, 1); if (!Buffer) { @@ -550,8 +579,8 @@ AbGetFile ( /* Read the entire file */ - Size = read (FileHandle, Buffer, Size); - if (Size == -1) + Actual = fread (Buffer, 1, Size, File); + if (Actual != Size) { printf ("Could not read the input file %s\n", Filename); free (Buffer); @@ -562,8 +591,7 @@ AbGetFile ( *FileSize = Size; ErrorExit: - close (FileHandle); - + fclose (File); return (Buffer); } @@ -594,7 +622,7 @@ AbDumpAmlFile ( FileOutHandle = fopen (File2Path, "wb"); if (!FileOutHandle) { - printf ("Could not open %s\n", File2Path); + printf ("Could not open file %s\n", File2Path); return (-1); } @@ -608,7 +636,9 @@ AbDumpAmlFile ( AcpiGbl_DebugFile = FileOutHandle; AcpiGbl_DbOutputFlags = ACPI_DB_REDIRECTABLE_OUTPUT; - AcpiOsPrintf ("%4.4s\n", ((ACPI_TABLE_HEADER *) FileBuffer)->Signature); + AcpiOsPrintf ("%4.4s @ 0x%8.8X\n", + ((ACPI_TABLE_HEADER *) FileBuffer)->Signature, 0); + AcpiDbgLevel = ACPI_UINT32_MAX; AcpiUtDebugDumpBuffer ((UINT8 *) FileBuffer, FileSize, DB_BYTE_DISPLAY, ACPI_UINT32_MAX); @@ -622,7 +652,7 @@ AbDumpAmlFile ( * FUNCTION: AbExtractAmlFile * * DESCRIPTION: Extract a binary AML file from a text file (as produced by the - * DumpAmlFile procedure or the "acpidmp" table utility. + * DumpAmlFile procedure or the "acpidump" table utility. * ******************************************************************************/ @@ -646,14 +676,14 @@ AbExtractAmlFile ( FileHandle = fopen (File1Path, "rt"); if (!FileHandle) { - printf ("Could not open %s\n", File1Path); + printf ("Could not open file %s\n", File1Path); return (-1); } FileOutHandle = fopen (File2Path, "w+b"); if (!FileOutHandle) { - printf ("Could not open %s\n", File2Path); + printf ("Could not open file %s\n", File2Path); return (-1); } @@ -709,7 +739,7 @@ AbExtractAmlFile ( /* Write the converted (binary) byte */ - if (fwrite (&Value, 1, 1, FileOutHandle) < 1) + if (fwrite (&Value, 1, 1, FileOutHandle) != 1) { printf ("Error writing byte %u to output file: %s\n", Count, File2Path); diff --git a/source/tools/acpibin/abmain.c b/source/tools/acpibin/abmain.c index b09ab846747f..c022688f66b6 100644 --- a/source/tools/acpibin/abmain.c +++ b/source/tools/acpibin/abmain.c @@ -73,9 +73,9 @@ AbDisplayUsage ( ACPI_USAGE_HEADER ("acpibin [options]"); - ACPI_OPTION ("-c <File1><File2>", "Compare two AML files"); + ACPI_OPTION ("-c <File1><File2>", "Compare two binary AML files"); ACPI_OPTION ("-d <In><Out>", "Dump AML binary to text file"); - ACPI_OPTION ("-e <Sig><In><Out>", "Extract binary AML table from AcpiDmp file"); + ACPI_OPTION ("-e <Sig><In><Out>", "Extract binary AML table from AcpiDump file"); ACPI_OPTION ("-h <File>", "Display table header for binary AML file"); ACPI_OPTION ("-s <File>", "Update checksum for binary AML file"); ACPI_OPTION ("-t", "Terse mode"); diff --git a/source/tools/acpibin/acpibin.h b/source/tools/acpibin/acpibin.h index e831f5109873..abb8f210d791 100644 --- a/source/tools/acpibin/acpibin.h +++ b/source/tools/acpibin/acpibin.h @@ -45,30 +45,15 @@ #include "accommon.h" #include <stdio.h> -#include <sys/stat.h> -#include <sys/types.h> #include <fcntl.h> -#include <ctype.h> #include <errno.h> -#ifdef WIN32 -#include <stdlib.h> -#include <io.h> -#include <direct.h> -#endif - -/* O_BINARY is not always defined */ -#ifndef O_BINARY -#define O_BINARY 0x0 -#endif - #define DB_CONSOLE_OUTPUT 0x02 #define ACPI_DB_REDIRECTABLE_OUTPUT 0x01 /* * Global variables. Defined in main.c only, externed in all other files */ - #ifdef _DECLARE_GLOBALS #define EXTERN #define INIT_GLOBAL(a,b) a=b diff --git a/source/tools/acpisrc/acpisrc.h b/source/tools/acpisrc/acpisrc.h index 1d2e8dc50124..e628f34ae702 100644 --- a/source/tools/acpisrc/acpisrc.h +++ b/source/tools/acpisrc/acpisrc.h @@ -41,35 +41,19 @@ * POSSIBILITY OF SUCH DAMAGES. */ - -#define LINES_IN_LEGAL_HEADER 105 /* See above */ -#define LEGAL_HEADER_SIGNATURE " * 2.1. This is your license from Intel Corp. under its intellectual property" -#define LINES_IN_LINUX_HEADER 34 -#define LINUX_HEADER_SIGNATURE " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS" -#define LINES_IN_ASL_HEADER 29 /* Header as output from disassembler */ - #include "acpi.h" #include "accommon.h" #include <stdio.h> #include <sys/stat.h> -#include <sys/types.h> -#include <fcntl.h> -#include <ctype.h> -#ifdef WIN32 -#include <io.h> -#include <direct.h> -#endif #include <errno.h> +/* mkdir/strlwr support */ -/* O_BINARY is not always defined */ -#ifndef O_BINARY -#define O_BINARY 0x0 -#endif +#ifdef WIN32 +#include <direct.h> -/* Fixups for non-Win32 compilation */ -#ifndef WIN32 +#else #define mkdir(x) mkdir(x, 0770) char * strlwr(char* str); #endif @@ -77,6 +61,12 @@ char * strlwr(char* str); /* Constants */ +#define LINES_IN_LEGAL_HEADER 105 /* See above */ +#define LEGAL_HEADER_SIGNATURE " * 2.1. This is your license from Intel Corp. under its intellectual property" +#define LINES_IN_LINUX_HEADER 34 +#define LINUX_HEADER_SIGNATURE " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS" +#define LINES_IN_ASL_HEADER 29 /* Header as output from disassembler */ + #define ASRC_MAX_FILE_SIZE (1024 * 100) #define FILE_TYPE_SOURCE 1 diff --git a/source/tools/acpisrc/asfile.c b/source/tools/acpisrc/asfile.c index 70be229928ea..f5b09338e5ec 100644 --- a/source/tools/acpisrc/asfile.c +++ b/source/tools/acpisrc/asfile.c @@ -698,24 +698,32 @@ AsGetFile ( char **FileBuffer, UINT32 *FileSize) { - - int FileHandle; + FILE *File; UINT32 Size; char *Buffer; + int Seek1; + int Seek2; + size_t Actual; /* Binary mode leaves CR/LF pairs */ - FileHandle = open (Filename, O_BINARY | O_RDONLY); - if (!FileHandle) + File = fopen (Filename, "rb"); + if (!File) { - printf ("Could not open %s\n", Filename); + printf ("Could not open file %s\n", Filename); return (-1); } - if (fstat (FileHandle, &Gbl_StatBuf)) + /* Need file size to allocate a buffer */ + + Seek1 = fseek (File, 0L, SEEK_END); + Size = ftell (File); + Seek2 = fseek (File, 0L, SEEK_SET); + + if (Seek1 || Seek2 || (Size == -1)) { - printf ("Could not get file status for %s\n", Filename); + printf ("Could not get file size for %s\n", Filename); goto ErrorExit; } @@ -723,7 +731,6 @@ AsGetFile ( * Create a buffer for the entire file * Add plenty extra buffer to accommodate string replacements */ - Size = Gbl_StatBuf.st_size; Gbl_TotalSize += Size; Buffer = calloc (Size * 2, 1); @@ -735,15 +742,16 @@ AsGetFile ( /* Read the entire file */ - Size = read (FileHandle, Buffer, Size); - if (Size == -1) + Actual = fread (Buffer, 1, Size, File); + if (Actual != Size) { - printf ("Could not read the input file %s\n", Filename); + printf ("Could not read the input file %s (%u bytes)\n", + Filename, Size); goto ErrorExit; } Buffer [Size] = 0; /* Null terminate the buffer */ - close (FileHandle); + fclose (File); /* Check for unix contamination */ @@ -757,13 +765,12 @@ AsGetFile ( *FileBuffer = Buffer; *FileSize = Size; - return (0); ErrorExit: - close (FileHandle); + fclose (File); return (-1); } @@ -783,15 +790,14 @@ AsPutFile ( char *FileBuffer, UINT32 SystemFlags) { + FILE *File; UINT32 FileSize; - int DestHandle; - int OpenFlags; + size_t Actual; + int Status = 0; /* Create the target file */ - OpenFlags = O_TRUNC | O_CREAT | O_WRONLY | O_BINARY; - if (!(SystemFlags & FLG_NO_CARRIAGE_RETURNS)) { /* Put back the CR before each LF */ @@ -799,8 +805,8 @@ AsPutFile ( AsInsertCarriageReturns (FileBuffer); } - DestHandle = open (Pathname, OpenFlags, S_IREAD | S_IWRITE); - if (DestHandle == -1) + File = fopen (Pathname, "w+b"); + if (!File) { perror ("Could not create destination file"); printf ("Could not create destination file \"%s\"\n", Pathname); @@ -810,9 +816,13 @@ AsPutFile ( /* Write the buffer to the file */ FileSize = strlen (FileBuffer); - write (DestHandle, FileBuffer, FileSize); - - close (DestHandle); + Actual = fwrite (FileBuffer, 1, FileSize, File); + if (Actual != FileSize) + { + printf ("Error writing output file \"%s\"\n", Pathname); + Status = -1; + } - return (0); + fclose (File); + return (Status); } diff --git a/source/tools/acpixtract/acpixtract.c b/source/tools/acpixtract/acpixtract.c index ef5b28a1d91b..e7a60dc20dde 100644 --- a/source/tools/acpixtract/acpixtract.c +++ b/source/tools/acpixtract/acpixtract.c @@ -335,7 +335,7 @@ AxCountTableInstances ( InputFile = fopen (InputPathname, "rt"); if (!InputFile) { - printf ("Could not open %s\n", InputPathname); + printf ("Could not open file %s\n", InputPathname); return (0); } @@ -465,7 +465,7 @@ AxExtractTables ( InputFile = fopen (InputPathname, "rt"); if (!InputFile) { - printf ("Could not open %s\n", InputPathname); + printf ("Could not open file %s\n", InputPathname); return (-1); } @@ -560,7 +560,7 @@ AxExtractTables ( OutputFile = fopen (Filename, "w+b"); if (!OutputFile) { - printf ("Could not open %s\n", Filename); + printf ("Could not open file %s\n", Filename); Status = -1; goto CleanupAndExit; } @@ -595,7 +595,7 @@ AxExtractTables ( BytesWritten = fwrite (Data, 1, BytesConverted, OutputFile); if (BytesWritten != BytesConverted) { - printf ("Write error on %s\n", Filename); + printf ("Error when writing file %s\n", Filename); fclose (OutputFile); OutputFile = NULL; Status = -1; @@ -665,7 +665,7 @@ AxListTables ( InputFile = fopen (InputPathname, "rt"); if (!InputFile) { - printf ("Could not open %s\n", InputPathname); + printf ("Could not open file %s\n", InputPathname); return (-1); } |
