acpixtract.c revision 7b1019a6d29ccb7999dc76cba3dde1c627e8e609
/******************************************************************************
*
* Module Name: acpixtract - convert ascii ACPI tables to binary
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#include "acpixtract.h"
/* Local prototypes */
static BOOLEAN
/******************************************************************************
*
* FUNCTION: AxExtractTables
*
* 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: Status
*
* DESCRIPTION: Convert text ACPI tables to binary
*
******************************************************************************/
int
char *InputPathname,
char *Signature,
unsigned int MinimumInstances)
{
unsigned int BytesConverted;
unsigned int ThisTableBytesWritten = 0;
unsigned int FoundTable = 0;
unsigned int Instances = 0;
unsigned int ThisInstance;
char ThisSignature[5];
char UpperSignature[5];
int Status = 0;
unsigned int State = AX_STATE_FIND_HEADER;
/* Open input in text mode, output is in binary mode */
if (!InputFile)
{
return (-1);
}
if (!AxIsFileAscii (InputFile))
{
return (-1);
}
if (Signature)
{
UpperSignature[4] = 0;
/* Are there enough instances of the table to continue? */
if (Instances < MinimumInstances)
{
printf ("Table [%s] was not found in %s\n",
return (-1);
}
if (Instances == 0)
{
return (-1);
}
}
/* Convert all instances of the table to binary */
{
switch (State)
{
case AX_STATE_FIND_HEADER:
if (!AxIsDataBlockHeader ())
{
continue;
}
if (Signature)
{
/* Ignore signatures that don't match */
{
continue;
}
}
/*
* Get the instance number for this signature. Only the
* SSDT and PSDT tables can have multiple instances.
*/
if (ThisInstance > 0)
{
/* Add instance number to the output filename */
}
else
{
}
if (!OutputFile)
{
printf ("Could not open output file %s\n",
return (-1);
}
/*
* Toss this block header of the form "<sig> @ <addr>" line
* and move on to the actual data block
*/
FoundTable = 1;
continue;
case AX_STATE_EXTRACT_DATA:
/* Empty line or non-data line terminates the data block */
switch (BytesConverted)
{
case 0:
continue;
case -1:
goto CleanupAndExit; /* There was a write error */
default: /* Normal case, get next line */
continue;
}
default:
Status = -1;
goto CleanupAndExit;
}
}
if (!FoundTable)
{
}
if (State == AX_STATE_EXTRACT_DATA)
{
/* Received an input file EOF while extracting data */
}
if (Gbl_TableCount > 1)
{
printf ("\n%u binary ACPI tables extracted\n",
}
if (OutputFile)
{
fclose (OutputFile);
}
return (Status);
}
/******************************************************************************
*
* FUNCTION: AxExtractToMultiAmlFile
*
* PARAMETERS: InputPathname - Filename for input acpidump file
*
* RETURN: Status
*
* into a single output file. Used to simplify the loading of
* of creating many separate output files.
*
******************************************************************************/
int
char *InputPathname)
{
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 the input file in text mode */
if (!InputFile)
{
return (-1);
}
if (!AxIsFileAscii (InputFile))
{
return (-1);
}
/* Open the output file in binary mode */
if (!OutputFile)
{
return (-1);
}
/* Convert the DSDT and all SSDTs to binary */
{
switch (State)
{
case AX_STATE_FIND_HEADER:
if (!AxIsDataBlockHeader ())
{
continue;
}
/* Only want DSDT and SSDTs */
{
continue;
}
/*
* Toss this block header of the form "<sig> @ <addr>" line
* and move on to the actual data block
*/
continue;
case AX_STATE_EXTRACT_DATA:
/* Empty line or non-data line terminates the data block */
switch (BytesConverted)
{
case 0:
continue;
case -1:
goto CleanupAndExit; /* There was a write error */
default: /* Normal case, get next line */
continue;
}
default:
Status = -1;
goto CleanupAndExit;
}
}
if (State == AX_STATE_EXTRACT_DATA)
{
/* Received an input file EOF or error while writing data */
}
printf ("\n%u binary ACPI tables extracted and written to %s (%u bytes)\n",
fclose (OutputFile);
return (Status);
}
/******************************************************************************
*
* FUNCTION: AxListTables
*
* PARAMETERS: InputPathname - Filename for acpidump file
*
* RETURN: Status
*
* DESCRIPTION: Display info for all ACPI tables found in input. Does not
* perform an actual extraction of the tables.
*
******************************************************************************/
int
char *InputPathname)
{
unsigned char Header[48];
/* Open input in text mode, output is in binary mode */
if (!InputFile)
{
return (-1);
}
if (!AxIsFileAscii (InputFile))
{
return (-1);
}
/* Dump the headers for all tables found in the input file */
printf ("\nSignature Length Revision OemId OemTableId"
" OemRevision CompilerId CompilerRevision\n\n");
{
/* Ignore empty lines and lines that start with a space */
if (AxIsEmptyLine (Gbl_LineBuffer) ||
(Gbl_LineBuffer[0] == ' '))
{
continue;
}
/* Get the 36 byte header and display the fields */
if (HeaderSize < 16)
{
continue;
}
/* RSDP has an oddball signature and header */
{
&Header[9]);
continue;
}
/* Minimum size for table with standard header */
if (HeaderSize < sizeof (ACPI_TABLE_HEADER))
{
continue;
}
{
continue;
}
/* Signature and Table length */
/* FACS has only signature and length */
{
printf ("\n");
continue;
}
/* OEM IDs and Compiler IDs */
printf (
" 0x%2.2X \"%6.6s\" \"%8.8s\" 0x%8.8X"
" \"%4.4s\" 0x%8.8X\n",
}
return (0);
}
/*******************************************************************************
*
* FUNCTION: AxIsFileAscii
*
* PARAMETERS: Handle - To open input file
*
* RETURN: TRUE if file is entirely ASCII and printable
*
* DESCRIPTION: Verify that the input file is entirely ASCII.
*
******************************************************************************/
static BOOLEAN
{
/* Read the entire file */
{
/* Check for an ASCII character */
if (!ACPI_IS_ASCII (Byte))
{
goto ErrorExit;
}
/* Ensure character is either printable or a "space" char */
{
goto ErrorExit;
}
}
/* File is OK (100% ASCII) */
return (TRUE);
printf ("File is binary (contains non-text or non-ascii characters)\n");
return (FALSE);
}