2 /******************************************************************************
4 * Module Name: acpixtract - convert ascii ACPI tables to binary
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
122 #define VERSION 0x20060324
124 #define FIND_HEADER 0
125 #define EXTRACT_DATA 1
126 #define BUFFER_SIZE 256
129 unsigned char Data
[16];
131 /* Local prototypes */
151 unsigned int MinimumInstances
);
156 unsigned char *OutputData
);
159 CountTableInstances (
165 char *InputPathname
);
170 unsigned char *OutputData
);
179 unsigned int Signature
;
180 unsigned int Instances
;
181 unsigned int NextInstance
;
182 struct TableInfo
*Next
;
185 struct TableInfo
*ListHead
= NULL
;
188 /******************************************************************************
190 * FUNCTION: DisplayUsage
192 * DESCRIPTION: Usage message
194 ******************************************************************************/
201 printf ("Usage: acpixtract [option] <InputFile>\n");
202 printf ("\nExtract binary ACPI tables from text acpidump output\n");
203 printf ("Default invocation extracts all DSDTs and SSDTs\n");
204 printf ("Version %8.8X\n\n", VERSION
);
205 printf ("Options:\n");
206 printf (" -a Extract all tables, not just DSDT/SSDT\n");
207 printf (" -l List table summaries, do not extract\n");
208 printf (" -s<Signature> Extract all tables named <Signature>\n");
213 /*******************************************************************************
215 * FUNCTION: CheckAscii
217 * PARAMETERS: Name - Ascii string, at least as long as Count
218 * Count - Number of characters to check
222 * DESCRIPTION: Ensure that the requested number of characters are printable
223 * Ascii characters. Sets non-printable and null chars to <space>.
225 ******************************************************************************/
235 for (i
= 0; i
< Count
; i
++)
237 if (!Name
[i
] || !isprint (Name
[i
]))
245 /*******************************************************************************
247 * FUNCTION: NormalizeSignature
249 * PARAMETERS: Name - Ascii string
253 * DESCRIPTION: Change "RSD PTR" to "RSDP"
255 ******************************************************************************/
262 if (!strncmp (Signature
, "RSD ", 4))
269 /******************************************************************************
271 * FUNCTION: ConvertLine
273 * DESCRIPTION: Convert one line of ascii text binary (up to 16 bytes)
275 ******************************************************************************/
280 unsigned char *OutputData
)
288 /* Terminate the input line at the end of the actual data (for sscanf) */
290 End
= strstr (InputLine
+ 2, " ");
293 return 0; /* Don't understand the format */
298 * Convert one line of table data, of the form:
299 * <offset>: <up to 16 bytes of hex data> <ASCII representation> <newline>
302 * 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08 _SB_LNKD........
304 BytesConverted
= sscanf (InputLine
,
305 "%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
306 &Converted
[0], &Converted
[1], &Converted
[2], &Converted
[3],
307 &Converted
[4], &Converted
[5], &Converted
[6], &Converted
[7],
308 &Converted
[8], &Converted
[9], &Converted
[10], &Converted
[11],
309 &Converted
[12], &Converted
[13], &Converted
[14], &Converted
[15]);
311 /* Pack converted data into a byte array */
313 for (i
= 0; i
< BytesConverted
; i
++)
315 OutputData
[i
] = (unsigned char) Converted
[i
];
318 return ((size_t) BytesConverted
);
322 /******************************************************************************
324 * FUNCTION: GetTableHeader
326 * DESCRIPTION: Extract and convert a table heaader
328 ******************************************************************************/
333 unsigned char *OutputData
)
335 size_t BytesConverted
;
336 size_t TotalConverted
= 0;
337 char Buffer
[BUFFER_SIZE
];
341 /* Get the full 36 byte header, requires 3 lines */
343 for (i
= 0; i
< 3; i
++)
345 if (!fgets (Buffer
, BUFFER_SIZE
, InputFile
))
347 return TotalConverted
;
350 BytesConverted
= ConvertLine (Buffer
, OutputData
);
351 TotalConverted
+= BytesConverted
;
354 if (BytesConverted
!= 16)
356 return TotalConverted
;
360 return TotalConverted
;
364 /******************************************************************************
366 * FUNCTION: CountTableInstances
368 * DESCRIPTION: Count the instances of table <Signature> within the input file
370 ******************************************************************************/
373 CountTableInstances (
377 char Buffer
[BUFFER_SIZE
];
379 unsigned int Instances
= 0;
382 InputFile
= fopen (InputPathname
, "rt");
385 printf ("Could not open %s\n", InputPathname
);
389 /* Count the number of instances of this signature */
391 while (fgets (Buffer
, BUFFER_SIZE
, InputFile
))
393 /* Ignore empty lines and lines that start with a space */
395 if ((Buffer
[0] == ' ') ||
401 NormalizeSignature (Buffer
);
402 if (!strncmp (Buffer
, Signature
, 4))
413 /******************************************************************************
415 * FUNCTION: GetNextInstance
419 ******************************************************************************/
426 struct TableInfo
*Info
;
432 if (*(unsigned int *) Signature
== Info
->Signature
)
442 Info
= malloc (sizeof (struct TableInfo
));
444 Info
->Signature
= *(unsigned int *) Signature
;
445 Info
->Instances
= CountTableInstances (InputPathname
, Signature
);
446 Info
->NextInstance
= 1;
448 Info
->Next
= ListHead
;
452 if (Info
->Instances
> 1)
454 return (Info
->NextInstance
++);
461 /******************************************************************************
463 * FUNCTION: ExtractTables
465 * DESCRIPTION: Convert text ACPI tables to binary
467 ******************************************************************************/
473 unsigned int MinimumInstances
)
475 char Buffer
[BUFFER_SIZE
];
477 FILE *OutputFile
= NULL
;
479 size_t TotalBytesWritten
= 0;
480 size_t BytesConverted
;
481 unsigned int State
= FIND_HEADER
;
482 unsigned int FoundTable
= 0;
483 unsigned int Instances
= 0;
484 unsigned int ThisInstance
;
485 char ThisSignature
[4];
488 /* Open input in text mode, output is in binary mode */
490 InputFile
= fopen (InputPathname
, "rt");
493 printf ("Could not open %s\n", InputPathname
);
499 /* Are there enough instances of the table to continue? */
501 NormalizeSignature (Signature
);
503 Instances
= CountTableInstances (InputPathname
, Signature
);
504 if (Instances
< MinimumInstances
)
506 printf ("Table %s was not found in %s\n", Signature
, InputPathname
);
516 /* Convert all instances of the table to binary */
518 while (fgets (Buffer
, BUFFER_SIZE
, InputFile
))
524 /* Ignore empty lines and lines that start with a space */
526 if ((Buffer
[0] == ' ') ||
532 NormalizeSignature (Buffer
);
533 strncpy (ThisSignature
, Buffer
, 4);
537 /* Ignore signatures that don't match */
539 if (strncmp (ThisSignature
, Signature
, 4))
545 /* Get the instance # for this signature */
547 ThisInstance
= GetNextInstance (InputPathname
, ThisSignature
);
549 /* Build an output filename and create/open the output file */
551 if (ThisInstance
> 0)
553 sprintf (Filename
, "%4.4s%u.dat", ThisSignature
, ThisInstance
);
557 sprintf (Filename
, "%4.4s.dat", ThisSignature
);
560 OutputFile
= fopen (Filename
, "w+b");
563 printf ("Could not open %s\n", Filename
);
567 State
= EXTRACT_DATA
;
568 TotalBytesWritten
= 0;
574 /* Empty line or non-data line terminates the data */
576 if ((Buffer
[0] == '\n') ||
583 printf ("Acpi table [%4.4s] - % 6d bytes written to %s\n",
584 ThisSignature
, TotalBytesWritten
, Filename
);
588 /* Convert the ascii data (one line of text) to binary */
590 BytesConverted
= ConvertLine (Buffer
, Data
);
592 /* Write the binary data */
594 BytesWritten
= fwrite (Data
, 1, BytesConverted
, OutputFile
);
595 if (BytesWritten
!= BytesConverted
)
597 printf ("Write error on %s\n", Filename
);
602 TotalBytesWritten
+= BytesConverted
;
612 printf ("Table %s was not found in %s\n", Signature
, InputPathname
);
618 if (State
== EXTRACT_DATA
)
620 /* Received an EOF while extracting data */
622 printf ("Acpi table [%4.4s] - % 6d bytes written to %s\n",
623 ThisSignature
, TotalBytesWritten
, Filename
);
632 /******************************************************************************
634 * FUNCTION: ListTables
636 * DESCRIPTION: Display info for all ACPI tables found in input
638 ******************************************************************************/
645 char Buffer
[BUFFER_SIZE
];
647 unsigned char Header
[48];
651 /* Open input in text mode, output is in binary mode */
653 InputFile
= fopen (InputPathname
, "rt");
656 printf ("Could not open %s\n", InputPathname
);
660 printf ("\nSignature Length OemId OemTableId OemRevision CompilerId CompilerRevision\n\n");
662 while (fgets (Buffer
, BUFFER_SIZE
, InputFile
))
664 /* Ignore empty lines and lines that start with a space */
666 if ((Buffer
[0] == ' ') ||
672 /* Get the 36 byte header and display the fields */
674 HeaderSize
= GetTableHeader (InputFile
, Header
);
680 /* RSDP has an oddball signature and header */
682 if (!strncmp ((char *) Header
, "RSD PTR ", 8))
684 CheckAscii (&Header
[9], 6);
685 printf ("%8.4s \"%6.6s\"\n", "RSDP", &Header
[9]);
697 /* Signature and Table length */
700 printf ("%8.4s % 7d", Header
, *(int *) &Header
[4]);
702 /* FACS has only signature and length */
704 if (!strncmp ((char *) Header
, "FACS", 4))
710 /* OEM IDs and Compiler IDs */
712 CheckAscii (&Header
[10], 6);
713 CheckAscii (&Header
[16], 8);
714 CheckAscii (&Header
[28], 4);
716 printf (" \"%6.6s\" \"%8.8s\" %8.8X \"%4.4s\" %8.8X\n",
717 &Header
[10], &Header
[16], *(int *) &Header
[24],
718 &Header
[28], *(int *) &Header
[32]);
721 printf ("\nFound %d ACPI tables [%8.8X]\n", TableCount
, VERSION
);
727 /******************************************************************************
731 * DESCRIPTION: C main function
733 ******************************************************************************/
749 if (argv
[1][0] == '-')
760 return (ExtractTables (argv
[2], NULL
, 0));
763 return (ListTables (argv
[2]));
766 return (ExtractTables (argv
[2], &argv
[1][2], 1));
775 * Default output is the DSDT and all SSDTs. One DSDT is required,
776 * any SSDTs are optional.
778 Status
= ExtractTables (argv
[1], "DSDT", 1);
784 Status
= ExtractTables (argv
[1], "SSDT", 0);