diff options
Diffstat (limited to 'source/tools/acpixtract/acpixtract.c')
-rw-r--r-- | source/tools/acpixtract/acpixtract.c | 682 |
1 files changed, 204 insertions, 478 deletions
diff --git a/source/tools/acpixtract/acpixtract.c b/source/tools/acpixtract/acpixtract.c index 373c9cd95bc7..4641c712a30e 100644 --- a/source/tools/acpixtract/acpixtract.c +++ b/source/tools/acpixtract/acpixtract.c @@ -41,579 +41,307 @@ * POSSIBILITY OF SUCH DAMAGES. */ -#include "acpi.h" -#include "accommon.h" -#include "acapps.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -/* Local prototypes */ - -static void -AxCheckAscii ( - char *Name, - int Count); - -static void -AxNormalizeSignature ( - char *Signature); - -static unsigned int -AxGetNextInstance ( - char *InputPathname, - char *Signature); - -static size_t -AxGetTableHeader ( - FILE *InputFile, - unsigned char *OutputData); - -static unsigned int -AxCountTableInstances ( - char *InputPathname, - char *Signature); - -int -AxExtractTables ( - char *InputPathname, - char *Signature, - unsigned int MinimumInstances); - -int -AxListTables ( - char *InputPathname); - -static size_t -AxConvertLine ( - char *InputLine, - unsigned char *OutputData); - -static int -AxIsEmptyLine ( - char *Buffer); - -typedef struct AxTableInfo -{ - UINT32 Signature; - unsigned int Instances; - unsigned int NextInstance; - struct AxTableInfo *Next; - -} AX_TABLE_INFO; - -/* Extraction states */ - -#define AX_STATE_FIND_HEADER 0 -#define AX_STATE_EXTRACT_DATA 1 - -/* Miscellaneous constants */ - -#define AX_LINE_BUFFER_SIZE 256 -#define AX_MIN_TABLE_NAME_LENGTH 6 /* strlen ("DSDT @") */ - - -static AX_TABLE_INFO *AxTableListHead = NULL; -static char Filename[16]; -static unsigned char Data[16]; -static char LineBuffer[AX_LINE_BUFFER_SIZE]; -static char HeaderBuffer[AX_LINE_BUFFER_SIZE]; -static char InstanceBuffer[AX_LINE_BUFFER_SIZE]; - - -/******************************************************************************* - * - * FUNCTION: AxCheckAscii - * - * PARAMETERS: Name - Ascii string, at least as long as Count - * Count - Number of characters to check - * - * RETURN: None - * - * DESCRIPTION: Ensure that the requested number of characters are printable - * Ascii characters. Sets non-printable and null chars to <space>. - * - ******************************************************************************/ - -static void -AxCheckAscii ( - char *Name, - int Count) -{ - int i; - - - for (i = 0; i < Count; i++) - { - if (!Name[i] || !isprint ((int) Name[i])) - { - Name[i] = ' '; - } - } -} +#include "acpixtract.h" /****************************************************************************** * - * FUNCTION: AxIsEmptyLine + * FUNCTION: AxExtractTables * - * PARAMETERS: Buffer - Line from input file + * PARAMETERS: InputPathname - Filename for input acpidump file + * Signature - Requested ACPI signature to extract. + * NULL means extract ALL tables. + * MinimumInstances - Min instances that are acceptable * - * RETURN: TRUE if line is empty (zero or more blanks only) + * RETURN: Status * - * DESCRIPTION: Determine if an input line is empty. + * DESCRIPTION: Convert text ACPI tables to binary * ******************************************************************************/ -static int -AxIsEmptyLine ( - char *Buffer) +int +AxExtractTables ( + char *InputPathname, + char *Signature, + unsigned int MinimumInstances) { + FILE *InputFile; + FILE *OutputFile = NULL; + unsigned int BytesConverted; + unsigned int ThisTableBytesWritten = 0; + unsigned int FoundTable = 0; + unsigned int Instances = 0; + unsigned int ThisInstance; + char ThisSignature[4]; + int Status = 0; + unsigned int State = AX_STATE_FIND_HEADER; - /* Skip all spaces */ - - while (*Buffer == ' ') - { - Buffer++; - } - /* If end-of-line, this line is empty */ + /* Open input in text mode, output is in binary mode */ - if (*Buffer == '\n') + InputFile = fopen (InputPathname, "rt"); + if (!InputFile) { - return (1); + printf ("Could not open input file %s\n", InputPathname); + return (-1); } - return (0); -} - - -/******************************************************************************* - * - * FUNCTION: AxNormalizeSignature - * - * PARAMETERS: Name - Ascii string containing an ACPI signature - * - * RETURN: None - * - * DESCRIPTION: Change "RSD PTR" to "RSDP" - * - ******************************************************************************/ - -static void -AxNormalizeSignature ( - char *Signature) -{ - - if (!strncmp (Signature, "RSD ", 4)) + if (Signature) { - Signature[3] = 'P'; - } -} - + /* Are there enough instances of the table to continue? */ -/****************************************************************************** - * - * FUNCTION: AxConvertLine - * - * PARAMETERS: InputLine - One line from the input acpidump file - * OutputData - Where the converted data is returned - * - * RETURN: The number of bytes actually converted - * - * DESCRIPTION: Convert one line of ascii text binary (up to 16 bytes) - * - ******************************************************************************/ + AxNormalizeSignature (Signature); -static size_t -AxConvertLine ( - char *InputLine, - unsigned char *OutputData) -{ - char *End; - int BytesConverted; - int Converted[16]; - int i; + Instances = AxCountTableInstances (InputPathname, Signature); + if (Instances < MinimumInstances) + { + printf ("Table [%s] was not found in %s\n", + Signature, InputPathname); + fclose (InputFile); + return (-1); + } + if (Instances == 0) + { + fclose (InputFile); + return (-1); + } + } - /* Terminate the input line at the end of the actual data (for sscanf) */ + /* Convert all instances of the table to binary */ - End = strstr (InputLine + 2, " "); - if (!End) + while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) { - return (0); /* Don't understand the format */ - } - *End = 0; - - /* - * Convert one line of table data, of the form: - * <offset>: <up to 16 bytes of hex data> <ASCII representation> <newline> - * - * Example: - * 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08 _SB_LNKD........ - */ - BytesConverted = sscanf (InputLine, - "%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", - &Converted[0], &Converted[1], &Converted[2], &Converted[3], - &Converted[4], &Converted[5], &Converted[6], &Converted[7], - &Converted[8], &Converted[9], &Converted[10], &Converted[11], - &Converted[12], &Converted[13], &Converted[14], &Converted[15]); - - /* Pack converted data into a byte array */ - - for (i = 0; i < BytesConverted; i++) - { - OutputData[i] = (unsigned char) Converted[i]; - } + switch (State) + { + case AX_STATE_FIND_HEADER: - return ((size_t) BytesConverted); -} + if (!AxIsDataBlockHeader ()) + { + continue; + } + ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer); + if (Signature) + { + /* Ignore signatures that don't match */ -/****************************************************************************** - * - * FUNCTION: AxGetTableHeader - * - * PARAMETERS: InputFile - Handle for the input acpidump file - * OutputData - Where the table header is returned - * - * RETURN: The actual number of bytes converted - * - * DESCRIPTION: Extract and convert an ACPI table header - * - ******************************************************************************/ + if (!ACPI_COMPARE_NAME (ThisSignature, Signature)) + { + continue; + } + } -static size_t -AxGetTableHeader ( - FILE *InputFile, - unsigned char *OutputData) -{ - size_t BytesConverted; - size_t TotalConverted = 0; - int i; + /* + * Get the instance number for this signature. Only the + * SSDT and PSDT tables can have multiple instances. + */ + ThisInstance = AxGetNextInstance (InputPathname, ThisSignature); + /* Build an output filename and create/open the output file */ - /* Get the full 36 byte ACPI table header, requires 3 input text lines */ + if (ThisInstance > 0) + { + /* Add instance number to the output filename */ - for (i = 0; i < 3; i++) - { - if (!fgets (HeaderBuffer, AX_LINE_BUFFER_SIZE, InputFile)) - { - return (TotalConverted); - } + sprintf (Gbl_OutputFilename, "%4.4s%u.dat", + ThisSignature, ThisInstance); + } + else + { + sprintf (Gbl_OutputFilename, "%4.4s.dat", + ThisSignature); + } - BytesConverted = AxConvertLine (HeaderBuffer, OutputData); - TotalConverted += BytesConverted; - OutputData += 16; + AcpiUtStrlwr (Gbl_OutputFilename); + OutputFile = fopen (Gbl_OutputFilename, "w+b"); + if (!OutputFile) + { + printf ("Could not open output file %s\n", + Gbl_OutputFilename); + fclose (InputFile); + return (-1); + } - if (BytesConverted != 16) - { - return (TotalConverted); - } - } + /* + * Toss this block header of the form "<sig> @ <addr>" line + * and move on to the actual data block + */ + Gbl_TableCount++; + FoundTable = 1; + ThisTableBytesWritten = 0; + State = AX_STATE_EXTRACT_DATA; + continue; - return (TotalConverted); -} + case AX_STATE_EXTRACT_DATA: + /* Empty line or non-data line terminates the data block */ -/****************************************************************************** - * - * FUNCTION: AxCountTableInstances - * - * PARAMETERS: InputPathname - Filename for acpidump file - * Signature - Requested signature to count - * - * RETURN: The number of instances of the signature - * - * DESCRIPTION: Count the instances of tables with the given signature within - * the input acpidump file. - * - ******************************************************************************/ + BytesConverted = AxProcessOneTextLine ( + OutputFile, ThisSignature, ThisTableBytesWritten); + switch (BytesConverted) + { + case 0: -static unsigned int -AxCountTableInstances ( - char *InputPathname, - char *Signature) -{ - FILE *InputFile; - unsigned int Instances = 0; + State = AX_STATE_FIND_HEADER; /* No more data block lines */ + continue; + case -1: - InputFile = fopen (InputPathname, "rt"); - if (!InputFile) - { - printf ("Could not open file %s\n", InputPathname); - return (0); - } + goto CleanupAndExit; /* There was a write error */ - /* Count the number of instances of this signature */ + default: /* Normal case, get next line */ - while (fgets (InstanceBuffer, AX_LINE_BUFFER_SIZE, InputFile)) - { - /* Ignore empty lines and lines that start with a space */ + ThisTableBytesWritten += BytesConverted; + continue; + } - if (AxIsEmptyLine (InstanceBuffer) || - (InstanceBuffer[0] == ' ')) - { - continue; - } + default: - AxNormalizeSignature (InstanceBuffer); - if (ACPI_COMPARE_NAME (InstanceBuffer, Signature)) - { - Instances++; + Status = -1; + goto CleanupAndExit; } } - fclose (InputFile); - return (Instances); -} - - -/****************************************************************************** - * - * FUNCTION: AxGetNextInstance - * - * PARAMETERS: InputPathname - Filename for acpidump file - * Signature - Requested ACPI signature - * - * RETURN: The next instance number for this signature. Zero if this - * is the first instance of this signature. - * - * DESCRIPTION: Get the next instance number of the specified table. If this - * is the first instance of the table, create a new instance - * block. Note: only SSDT and PSDT tables can have multiple - * instances. - * - ******************************************************************************/ + if (!FoundTable) + { + printf ("Table [%s] was not found in %s\n", + Signature, InputPathname); + } -static unsigned int -AxGetNextInstance ( - char *InputPathname, - char *Signature) -{ - AX_TABLE_INFO *Info; +CleanupAndExit: - Info = AxTableListHead; - while (Info) + if (State == AX_STATE_EXTRACT_DATA) { - if (*(UINT32 *) Signature == Info->Signature) - { - break; - } + /* Received an input file EOF while extracting data */ - Info = Info->Next; + printf (AX_TABLE_INFO_FORMAT, + ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename); } - if (!Info) + if (Gbl_TableCount > 1) { - /* Signature not found, create new table info block */ - - Info = malloc (sizeof (AX_TABLE_INFO)); - if (!Info) - { - printf ("Could not allocate memory\n"); - exit (0); - } - - Info->Signature = *(UINT32 *) Signature; - Info->Instances = AxCountTableInstances (InputPathname, Signature); - Info->NextInstance = 1; - Info->Next = AxTableListHead; - AxTableListHead = Info; + printf ("\n%d binary ACPI tables extracted\n", + Gbl_TableCount); } - if (Info->Instances > 1) + if (OutputFile) { - return (Info->NextInstance++); + fclose (OutputFile); } - return (0); + fclose (InputFile); + return (Status); } /****************************************************************************** * - * FUNCTION: AxExtractTables + * FUNCTION: AxExtractToMultiAmlFile * - * PARAMETERS: InputPathname - Filename for acpidump file - * Signature - Requested ACPI signature to extract. - * NULL means extract ALL tables. - * MinimumInstances - Min instances that are acceptable + * PARAMETERS: InputPathname - Filename for input acpidump file * * RETURN: Status * - * DESCRIPTION: Convert text ACPI tables to binary + * DESCRIPTION: Convert all DSDT/SSDT tables to binary and append them all + * into a single output file. Used to simplify the loading of + * multiple/many SSDTs into a utility like acpiexec -- instead + * of creating many separate output files. * ******************************************************************************/ int -AxExtractTables ( - char *InputPathname, - char *Signature, - unsigned int MinimumInstances) +AxExtractToMultiAmlFile ( + char *InputPathname) { FILE *InputFile; - FILE *OutputFile = NULL; - size_t BytesWritten; - size_t TotalBytesWritten = 0; - size_t BytesConverted; - unsigned int State = AX_STATE_FIND_HEADER; - unsigned int FoundTable = 0; - unsigned int Instances = 0; - unsigned int ThisInstance; - char ThisSignature[4]; + FILE *OutputFile; int Status = 0; + unsigned int TotalBytesWritten = 0; + unsigned int ThisTableBytesWritten = 0; + unsigned int BytesConverted; + char ThisSignature[4]; + unsigned int State = AX_STATE_FIND_HEADER; - /* Open input in text mode, output is in binary mode */ + strcpy (Gbl_OutputFilename, AX_MULTI_TABLE_FILENAME); + + /* Open the input file in text mode */ InputFile = fopen (InputPathname, "rt"); if (!InputFile) { - printf ("Could not open file %s\n", InputPathname); + printf ("Could not open input file %s\n", InputPathname); return (-1); } - if (Signature) - { - /* Are there enough instances of the table to continue? */ - - AxNormalizeSignature (Signature); + /* Open the output file in binary mode */ - Instances = AxCountTableInstances (InputPathname, Signature); - if (Instances < MinimumInstances) - { - printf ("Table %s was not found in %s\n", Signature, InputPathname); - Status = -1; - goto CleanupAndExit; - } - - if (Instances == 0) - { - goto CleanupAndExit; - } + OutputFile = fopen (Gbl_OutputFilename, "w+b"); + if (!OutputFile) + { + printf ("Could not open output file %s\n", Gbl_OutputFilename); + fclose (InputFile); + return (-1); } - /* Convert all instances of the table to binary */ + /* Convert the DSDT and all SSDTs to binary */ - while (fgets (LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) + while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) { switch (State) { case AX_STATE_FIND_HEADER: - /* Ignore lines that are too short to be header lines */ - - if (strlen (LineBuffer) < AX_MIN_TABLE_NAME_LENGTH) + if (!AxIsDataBlockHeader ()) { continue; } - /* Ignore empty lines and lines that start with a space */ + ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer); - if (AxIsEmptyLine (LineBuffer) || - (LineBuffer[0] == ' ')) - { - continue; - } + /* Only want DSDT and SSDTs */ - /* - * Ignore lines that are not of the form <sig> @ <addr>. - * Examples of lines that must be supported: - * - * DSDT @ 0x737e4000 - * XSDT @ 0x737f2fff - * RSD PTR @ 0xf6cd0 - * SSDT @ (nil) - */ - if (!strstr (LineBuffer, " @ ")) + if (!ACPI_COMPARE_NAME (ThisSignature, ACPI_SIG_DSDT) && + !ACPI_COMPARE_NAME (ThisSignature, ACPI_SIG_SSDT)) { continue; } - AxNormalizeSignature (LineBuffer); - ACPI_MOVE_NAME (ThisSignature, LineBuffer); - - if (Signature) - { - /* Ignore signatures that don't match */ - - if (!ACPI_COMPARE_NAME (ThisSignature, Signature)) - { - continue; - } - } - /* - * Get the instance number for this signature. Only the - * SSDT and PSDT tables can have multiple instances. + * Toss this block header of the form "<sig> @ <addr>" line + * and move on to the actual data block */ - ThisInstance = AxGetNextInstance (InputPathname, ThisSignature); - - /* Build an output filename and create/open the output file */ - - if (ThisInstance > 0) - { - sprintf (Filename, "%4.4s%u.dat", ThisSignature, ThisInstance); - } - else - { - sprintf (Filename, "%4.4s.dat", ThisSignature); - } - - AcpiUtStrlwr (Filename); - OutputFile = fopen (Filename, "w+b"); - if (!OutputFile) - { - printf ("Could not open file %s\n", Filename); - Status = -1; - goto CleanupAndExit; - } - + Gbl_TableCount++; + ThisTableBytesWritten = 0; State = AX_STATE_EXTRACT_DATA; - TotalBytesWritten = 0; - FoundTable = 1; continue; case AX_STATE_EXTRACT_DATA: - /* Empty line or non-data line terminates the data */ + /* Empty line or non-data line terminates the data block */ - if (AxIsEmptyLine (LineBuffer) || - (LineBuffer[0] != ' ')) + BytesConverted = AxProcessOneTextLine ( + OutputFile, ThisSignature, ThisTableBytesWritten); + switch (BytesConverted) { - fclose (OutputFile); - OutputFile = NULL; - State = AX_STATE_FIND_HEADER; + case 0: - printf ("Acpi table [%4.4s] - %u bytes written to %s\n", - ThisSignature, (unsigned int) TotalBytesWritten, Filename); + State = AX_STATE_FIND_HEADER; /* No more data block lines */ continue; - } - /* Convert the ascii data (one line of text) to binary */ + case -1: - BytesConverted = AxConvertLine (LineBuffer, Data); + goto CleanupAndExit; /* There was a write error */ - /* Write the binary data */ + default: /* Normal case, get next line */ - BytesWritten = fwrite (Data, 1, BytesConverted, OutputFile); - if (BytesWritten != BytesConverted) - { - printf ("Error when writing file %s\n", Filename); - fclose (OutputFile); - OutputFile = NULL; - Status = -1; - goto CleanupAndExit; + ThisTableBytesWritten += BytesConverted; + TotalBytesWritten += BytesConverted; + continue; } - TotalBytesWritten += BytesConverted; - continue; - default: Status = -1; @@ -621,27 +349,22 @@ AxExtractTables ( } } - if (!FoundTable) - { - printf ("Table %s was not found in %s\n", Signature, InputPathname); - } - CleanupAndExit: - if (OutputFile) + if (State == AX_STATE_EXTRACT_DATA) { - fclose (OutputFile); - if (State == AX_STATE_EXTRACT_DATA) - { - /* Received an EOF while extracting data */ + /* Received an input file EOF or error while writing data */ - printf ("Acpi table [%4.4s] - %u bytes written to %s\n", - ThisSignature, (unsigned int) TotalBytesWritten, Filename); - } + printf (AX_TABLE_INFO_FORMAT, + ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename); } + printf ("\n%d binary ACPI tables extracted and written to %s (%u bytes)\n", + Gbl_TableCount, Gbl_OutputFilename, TotalBytesWritten); + fclose (InputFile); + fclose (OutputFile); return (Status); } @@ -666,7 +389,6 @@ AxListTables ( FILE *InputFile; size_t HeaderSize; unsigned char Header[48]; - unsigned int TableCount = 0; ACPI_TABLE_HEADER *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header; @@ -675,21 +397,21 @@ AxListTables ( InputFile = fopen (InputPathname, "rt"); if (!InputFile) { - printf ("Could not open file %s\n", InputPathname); + printf ("Could not open input file %s\n", InputPathname); return (-1); } /* Dump the headers for all tables found in the input file */ printf ("\nSignature Length Revision OemId OemTableId" - " OemRevision CompilerId CompilerRevision\n\n"); + " OemRevision CompilerId CompilerRevision\n\n"); - while (fgets (LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) + while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) { /* Ignore empty lines and lines that start with a space */ - if (AxIsEmptyLine (LineBuffer) || - (LineBuffer[0] == ' ')) + if (AxIsEmptyLine (Gbl_LineBuffer) || + (Gbl_LineBuffer[0] == ' ')) { continue; } @@ -707,8 +429,9 @@ AxListTables ( if (!strncmp (TableHeader->Signature, "RSD PTR ", 8)) { AxCheckAscii ((char *) &Header[9], 6); - printf ("%7.4s \"%6.6s\"\n", "RSDP", &Header[9]); - TableCount++; + printf ("%7.4s \"%6.6s\"\n", "RSDP", + &Header[9]); + Gbl_TableCount++; continue; } @@ -721,8 +444,9 @@ AxListTables ( /* Signature and Table length */ - TableCount++; - printf ("%7.4s 0x%8.8X", TableHeader->Signature, TableHeader->Length); + Gbl_TableCount++; + printf ("%7.4s 0x%8.8X", TableHeader->Signature, + TableHeader->Length); /* FACS has only signature and length */ @@ -738,13 +462,15 @@ AxListTables ( AxCheckAscii (TableHeader->OemTableId, 8); AxCheckAscii (TableHeader->AslCompilerId, 4); - printf (" 0x%2.2X \"%6.6s\" \"%8.8s\" 0x%8.8X \"%4.4s\" 0x%8.8X\n", + printf ( + " 0x%2.2X \"%6.6s\" \"%8.8s\" 0x%8.8X" + " \"%4.4s\" 0x%8.8X\n", TableHeader->Revision, TableHeader->OemId, TableHeader->OemTableId, TableHeader->OemRevision, TableHeader->AslCompilerId, TableHeader->AslCompilerRevision); } - printf ("\nFound %u ACPI tables\n", TableCount); + printf ("\nFound %u ACPI tables\n", Gbl_TableCount); fclose (InputFile); return (0); } |