summaryrefslogtreecommitdiff
path: root/tools/acpixtract/acpixtract.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/acpixtract/acpixtract.c')
-rw-r--r--tools/acpixtract/acpixtract.c324
1 files changed, 122 insertions, 202 deletions
diff --git a/tools/acpixtract/acpixtract.c b/tools/acpixtract/acpixtract.c
index 4393595ee9671..318b7e9b561f3 100644
--- a/tools/acpixtract/acpixtract.c
+++ b/tools/acpixtract/acpixtract.c
@@ -1,4 +1,3 @@
-
/******************************************************************************
*
* Module Name: acpixtract - convert ascii ACPI tables to binary
@@ -42,121 +41,117 @@
* 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>
-
-/* Note: This is a 32-bit program only */
-
-#define VERSION 0x20110330
-#define FIND_HEADER 0
-#define EXTRACT_DATA 1
-#define BUFFER_SIZE 256
-#define MIN_HEADER_LENGTH 6 /* strlen ("DSDT @") */
-
/* Local prototypes */
static void
-CheckAscii (
+AxStrlwr (
+ char *String);
+
+static void
+AxCheckAscii (
char *Name,
int Count);
static void
-NormalizeSignature (
+AxNormalizeSignature (
char *Signature);
static unsigned int
-GetNextInstance (
+AxGetNextInstance (
char *InputPathname,
char *Signature);
-static int
-ExtractTables (
- char *InputPathname,
- char *Signature,
- unsigned int MinimumInstances);
-
static size_t
-GetTableHeader (
+AxGetTableHeader (
FILE *InputFile,
unsigned char *OutputData);
static unsigned int
-CountTableInstances (
+AxCountTableInstances (
char *InputPathname,
char *Signature);
-static int
-ListTables (
+int
+AxExtractTables (
+ char *InputPathname,
+ char *Signature,
+ unsigned int MinimumInstances);
+
+int
+AxListTables (
char *InputPathname);
static size_t
-ConvertLine (
+AxConvertLine (
char *InputLine,
unsigned char *OutputData);
-static void
-DisplayUsage (
- void);
-
-typedef struct acpi_table_header
-{
- char Signature[4];
- int Length;
- unsigned char Revision;
- unsigned char Checksum;
- char OemId[6];
- char OemTableId[8];
- int OemRevision;
- char AslCompilerId[4];
- int AslCompilerRevision;
-
-} ACPI_TABLE_HEADER;
-
-struct TableInfo
+typedef struct AxTableInfo
{
- unsigned int Signature;
+ UINT32 Signature;
unsigned int Instances;
unsigned int NextInstance;
- struct TableInfo *Next;
-};
+ struct AxTableInfo *Next;
-static struct TableInfo *ListHead = NULL;
+} 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: DisplayUsage
+ * FUNCTION: AxStrlwr
*
- * DESCRIPTION: Usage message
+ * PARAMETERS: String - Ascii string
+ *
+ * RETURN: None
+ *
+ * DESCRIPTION: String lowercase function.
*
******************************************************************************/
static void
-DisplayUsage (
- void)
+AxStrlwr (
+ char *String)
{
- printf ("Usage: acpixtract [option] <InputFile>\n");
- printf ("\nExtract binary ACPI tables from text acpidump output\n");
- printf ("Default invocation extracts all DSDTs and SSDTs\n");
- printf ("Version %8.8X\n\n", VERSION);
- printf ("Options:\n");
- printf (" -a Extract all tables, not just DSDT/SSDT\n");
- printf (" -l List table summaries, do not extract\n");
- printf (" -s<Signature> Extract all tables named <Signature>\n");
- printf ("\n");
+ while (*String)
+ {
+ *String = (char) tolower ((int) *String);
+ String++;
+ }
}
/*******************************************************************************
*
- * FUNCTION: CheckAscii
+ * FUNCTION: AxCheckAscii
*
* PARAMETERS: Name - Ascii string, at least as long as Count
* Count - Number of characters to check
@@ -169,7 +164,7 @@ DisplayUsage (
******************************************************************************/
static void
-CheckAscii (
+AxCheckAscii (
char *Name,
int Count)
{
@@ -188,7 +183,7 @@ CheckAscii (
/*******************************************************************************
*
- * FUNCTION: NormalizeSignature
+ * FUNCTION: AxNormalizeSignature
*
* PARAMETERS: Name - Ascii string containing an ACPI signature
*
@@ -199,7 +194,7 @@ CheckAscii (
******************************************************************************/
static void
-NormalizeSignature (
+AxNormalizeSignature (
char *Signature)
{
@@ -212,7 +207,7 @@ NormalizeSignature (
/******************************************************************************
*
- * FUNCTION: ConvertLine
+ * FUNCTION: AxConvertLine
*
* PARAMETERS: InputLine - One line from the input acpidump file
* OutputData - Where the converted data is returned
@@ -224,7 +219,7 @@ NormalizeSignature (
******************************************************************************/
static size_t
-ConvertLine (
+AxConvertLine (
char *InputLine,
unsigned char *OutputData)
{
@@ -270,7 +265,7 @@ ConvertLine (
/******************************************************************************
*
- * FUNCTION: GetTableHeader
+ * FUNCTION: AxGetTableHeader
*
* PARAMETERS: InputFile - Handle for the input acpidump file
* OutputData - Where the table header is returned
@@ -282,26 +277,25 @@ ConvertLine (
******************************************************************************/
static size_t
-GetTableHeader (
+AxGetTableHeader (
FILE *InputFile,
unsigned char *OutputData)
{
size_t BytesConverted;
size_t TotalConverted = 0;
- char Buffer[BUFFER_SIZE];
int i;
- /* Get the full 36 byte header, requires 3 lines */
+ /* Get the full 36 byte ACPI table header, requires 3 input text lines */
for (i = 0; i < 3; i++)
{
- if (!fgets (Buffer, BUFFER_SIZE, InputFile))
+ if (!fgets (HeaderBuffer, AX_LINE_BUFFER_SIZE, InputFile))
{
return (TotalConverted);
}
- BytesConverted = ConvertLine (Buffer, OutputData);
+ BytesConverted = AxConvertLine (HeaderBuffer, OutputData);
TotalConverted += BytesConverted;
OutputData += 16;
@@ -317,7 +311,7 @@ GetTableHeader (
/******************************************************************************
*
- * FUNCTION: CountTableInstances
+ * FUNCTION: AxCountTableInstances
*
* PARAMETERS: InputPathname - Filename for acpidump file
* Signature - Requested signature to count
@@ -330,11 +324,10 @@ GetTableHeader (
******************************************************************************/
static unsigned int
-CountTableInstances (
+AxCountTableInstances (
char *InputPathname,
char *Signature)
{
- char Buffer[BUFFER_SIZE];
FILE *InputFile;
unsigned int Instances = 0;
@@ -348,18 +341,18 @@ CountTableInstances (
/* Count the number of instances of this signature */
- while (fgets (Buffer, BUFFER_SIZE, InputFile))
+ while (fgets (InstanceBuffer, AX_LINE_BUFFER_SIZE, InputFile))
{
/* Ignore empty lines and lines that start with a space */
- if ((Buffer[0] == ' ') ||
- (Buffer[0] == '\n'))
+ if ((InstanceBuffer[0] == ' ') ||
+ (InstanceBuffer[0] == '\n'))
{
continue;
}
- NormalizeSignature (Buffer);
- if (!strncmp (Buffer, Signature, 4))
+ AxNormalizeSignature (InstanceBuffer);
+ if (!strncmp (InstanceBuffer, Signature, 4))
{
Instances++;
}
@@ -372,7 +365,7 @@ CountTableInstances (
/******************************************************************************
*
- * FUNCTION: GetNextInstance
+ * FUNCTION: AxGetNextInstance
*
* PARAMETERS: InputPathname - Filename for acpidump file
* Signature - Requested ACPI signature
@@ -388,17 +381,17 @@ CountTableInstances (
******************************************************************************/
static unsigned int
-GetNextInstance (
+AxGetNextInstance (
char *InputPathname,
char *Signature)
{
- struct TableInfo *Info;
+ AX_TABLE_INFO *Info;
- Info = ListHead;
+ Info = AxTableListHead;
while (Info)
{
- if (*(unsigned int *) Signature == Info->Signature)
+ if (*(UINT32 *) Signature == Info->Signature)
{
break;
}
@@ -410,18 +403,18 @@ GetNextInstance (
{
/* Signature not found, create new table info block */
- Info = malloc (sizeof (struct TableInfo));
+ Info = malloc (sizeof (AX_TABLE_INFO));
if (!Info)
{
printf ("Could not allocate memory\n");
exit (0);
}
- Info->Signature = *(unsigned int *) Signature;
- Info->Instances = CountTableInstances (InputPathname, Signature);
+ Info->Signature = *(UINT32 *) Signature;
+ Info->Instances = AxCountTableInstances (InputPathname, Signature);
Info->NextInstance = 1;
- Info->Next = ListHead;
- ListHead = Info;
+ Info->Next = AxTableListHead;
+ AxTableListHead = Info;
}
if (Info->Instances > 1)
@@ -435,7 +428,7 @@ GetNextInstance (
/******************************************************************************
*
- * FUNCTION: ExtractTables
+ * FUNCTION: AxExtractTables
*
* PARAMETERS: InputPathname - Filename for acpidump file
* Signature - Requested ACPI signature to extract.
@@ -448,19 +441,18 @@ GetNextInstance (
*
******************************************************************************/
-static int
-ExtractTables (
+int
+AxExtractTables (
char *InputPathname,
char *Signature,
unsigned int MinimumInstances)
{
- char Buffer[BUFFER_SIZE];
FILE *InputFile;
FILE *OutputFile = NULL;
size_t BytesWritten;
size_t TotalBytesWritten = 0;
size_t BytesConverted;
- unsigned int State = FIND_HEADER;
+ unsigned int State = AX_STATE_FIND_HEADER;
unsigned int FoundTable = 0;
unsigned int Instances = 0;
unsigned int ThisInstance;
@@ -481,9 +473,9 @@ ExtractTables (
{
/* Are there enough instances of the table to continue? */
- NormalizeSignature (Signature);
+ AxNormalizeSignature (Signature);
- Instances = CountTableInstances (InputPathname, Signature);
+ Instances = AxCountTableInstances (InputPathname, Signature);
if (Instances < MinimumInstances)
{
printf ("Table %s was not found in %s\n", Signature, InputPathname);
@@ -499,42 +491,43 @@ ExtractTables (
/* Convert all instances of the table to binary */
- while (fgets (Buffer, BUFFER_SIZE, InputFile))
+ while (fgets (LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
{
switch (State)
{
- case FIND_HEADER:
+ case AX_STATE_FIND_HEADER:
/* Ignore lines that are too short to be header lines */
- if (strlen (Buffer) < MIN_HEADER_LENGTH)
+ if (strlen (LineBuffer) < AX_MIN_TABLE_NAME_LENGTH)
{
continue;
}
/* Ignore empty lines and lines that start with a space */
- if ((Buffer[0] == ' ') ||
- (Buffer[0] == '\n'))
+ if ((LineBuffer[0] == ' ') ||
+ (LineBuffer[0] == '\n'))
{
continue;
}
/*
- * Ignore lines that are not of the form <sig> @ <addr>. Examples:
+ * 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 (Buffer, " @ "))
+ if (!strstr (LineBuffer, " @ "))
{
continue;
}
- NormalizeSignature (Buffer);
- strncpy (ThisSignature, Buffer, 4);
+ AxNormalizeSignature (LineBuffer);
+ strncpy (ThisSignature, LineBuffer, 4);
if (Signature)
{
@@ -550,7 +543,7 @@ ExtractTables (
* Get the instance number for this signature. Only the
* SSDT and PSDT tables can have multiple instances.
*/
- ThisInstance = GetNextInstance (InputPathname, ThisSignature);
+ ThisInstance = AxGetNextInstance (InputPathname, ThisSignature);
/* Build an output filename and create/open the output file */
@@ -563,6 +556,7 @@ ExtractTables (
sprintf (Filename, "%4.4s.dat", ThisSignature);
}
+ AxStrlwr (Filename);
OutputFile = fopen (Filename, "w+b");
if (!OutputFile)
{
@@ -571,21 +565,21 @@ ExtractTables (
goto CleanupAndExit;
}
- State = EXTRACT_DATA;
+ State = AX_STATE_EXTRACT_DATA;
TotalBytesWritten = 0;
FoundTable = 1;
continue;
- case EXTRACT_DATA:
+ case AX_STATE_EXTRACT_DATA:
/* Empty line or non-data line terminates the data */
- if ((Buffer[0] == '\n') ||
- (Buffer[0] != ' '))
+ if ((LineBuffer[0] == '\n') ||
+ (LineBuffer[0] != ' '))
{
fclose (OutputFile);
OutputFile = NULL;
- State = FIND_HEADER;
+ State = AX_STATE_FIND_HEADER;
printf ("Acpi table [%4.4s] - %u bytes written to %s\n",
ThisSignature, (unsigned int) TotalBytesWritten, Filename);
@@ -594,7 +588,7 @@ ExtractTables (
/* Convert the ascii data (one line of text) to binary */
- BytesConverted = ConvertLine (Buffer, Data);
+ BytesConverted = AxConvertLine (LineBuffer, Data);
/* Write the binary data */
@@ -628,7 +622,7 @@ CleanupAndExit:
if (OutputFile)
{
fclose (OutputFile);
- if (State == EXTRACT_DATA)
+ if (State == AX_STATE_EXTRACT_DATA)
{
/* Received an EOF while extracting data */
@@ -644,7 +638,7 @@ CleanupAndExit:
/******************************************************************************
*
- * FUNCTION: ListTables
+ * FUNCTION: AxListTables
*
* PARAMETERS: InputPathname - Filename for acpidump file
*
@@ -655,12 +649,11 @@ CleanupAndExit:
*
******************************************************************************/
-static int
-ListTables (
+int
+AxListTables (
char *InputPathname)
{
FILE *InputFile;
- char Buffer[BUFFER_SIZE];
size_t HeaderSize;
unsigned char Header[48];
int TableCount = 0;
@@ -681,19 +674,19 @@ ListTables (
printf ("\nSignature Length Revision OemId OemTableId"
" OemRevision CompilerId CompilerRevision\n\n");
- while (fgets (Buffer, BUFFER_SIZE, InputFile))
+ while (fgets (LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
{
/* Ignore empty lines and lines that start with a space */
- if ((Buffer[0] == ' ') ||
- (Buffer[0] == '\n'))
+ if ((LineBuffer[0] == ' ') ||
+ (LineBuffer[0] == '\n'))
{
continue;
}
/* Get the 36 byte header and display the fields */
- HeaderSize = GetTableHeader (InputFile, Header);
+ HeaderSize = AxGetTableHeader (InputFile, Header);
if (HeaderSize < 16)
{
continue;
@@ -703,7 +696,7 @@ ListTables (
if (!strncmp (TableHeader->Signature, "RSD PTR ", 8))
{
- CheckAscii ((char *) &Header[9], 6);
+ AxCheckAscii ((char *) &Header[9], 6);
printf ("%8.4s \"%6.6s\"\n", "RSDP", &Header[9]);
TableCount++;
continue;
@@ -711,7 +704,7 @@ ListTables (
/* Minimum size for table with standard header */
- if (HeaderSize < 36)
+ if (HeaderSize < sizeof (ACPI_TABLE_HEADER))
{
continue;
}
@@ -731,9 +724,9 @@ ListTables (
/* OEM IDs and Compiler IDs */
- CheckAscii (TableHeader->OemId, 6);
- CheckAscii (TableHeader->OemTableId, 8);
- CheckAscii (TableHeader->AslCompilerId, 4);
+ AxCheckAscii (TableHeader->OemId, 6);
+ AxCheckAscii (TableHeader->OemTableId, 8);
+ AxCheckAscii (TableHeader->AslCompilerId, 4);
printf (" %2.2X \"%6.6s\" \"%8.8s\" %8.8X \"%4.4s\" %8.8X\n",
TableHeader->Revision, TableHeader->OemId,
@@ -741,80 +734,7 @@ ListTables (
TableHeader->AslCompilerId, TableHeader->AslCompilerRevision);
}
- printf ("\nFound %u ACPI tables [%8.8X]\n", TableCount, VERSION);
+ printf ("\nFound %u ACPI tables\n", TableCount);
fclose (InputFile);
return (0);
}
-
-
-/******************************************************************************
- *
- * FUNCTION: main
- *
- * DESCRIPTION: C main function
- *
- ******************************************************************************/
-
-int
-main (
- int argc,
- char *argv[])
-{
- int Status;
-
-
- if (argc < 2)
- {
- DisplayUsage ();
- return (0);
- }
-
- if (argv[1][0] == '-')
- {
- if (argc < 3)
- {
- DisplayUsage ();
- return (0);
- }
-
- switch (argv[1][1])
- {
- case 'a':
-
- /* Extract all tables found */
-
- return (ExtractTables (argv[2], NULL, 0));
-
- case 'l':
-
- /* List tables only, do not extract */
-
- return (ListTables (argv[2]));
-
- case 's':
-
- /* Extract only tables with this signature */
-
- return (ExtractTables (argv[2], &argv[1][2], 1));
-
- default:
- DisplayUsage ();
- return (0);
- }
- }
-
- /*
- * Default output is the DSDT and all SSDTs. One DSDT is required,
- * any SSDTs are optional.
- */
- Status = ExtractTables (argv[1], "DSDT", 1);
- if (Status)
- {
- return (Status);
- }
-
- Status = ExtractTables (argv[1], "SSDT", 0);
- return (Status);
-}
-
-