2 /******************************************************************************
4 * Module Name: acpixtract - convert ascii ACPI tables to binary
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
123 #define VERSION 0x20060324
125 #define FIND_HEADER 0
126 #define EXTRACT_DATA 1
127 #define BUFFER_SIZE 256
130 unsigned char Data
[16];
132 /* Local prototypes */
152 unsigned int MinimumInstances
);
157 unsigned char *OutputData
);
160 CountTableInstances (
166 char *InputPathname
);
171 unsigned char *OutputData
);
180 unsigned int Signature
;
181 unsigned int Instances
;
182 unsigned int NextInstance
;
183 struct TableInfo
*Next
;
186 struct TableInfo
*ListHead
= NULL
;
189 /******************************************************************************
191 * FUNCTION: DisplayUsage
193 * DESCRIPTION: Usage message
195 ******************************************************************************/
202 printf ("Usage: acpixtract [option] <InputFile>\n");
203 printf ("\nExtract binary ACPI tables from text acpidump output\n");
204 printf ("Default invocation extracts all DSDTs and SSDTs\n");
205 printf ("Version %8.8X\n\n", VERSION
);
206 printf ("Options:\n");
207 printf (" -a Extract all tables, not just DSDT/SSDT\n");
208 printf (" -l List table summaries, do not extract\n");
209 printf (" -s<Signature> Extract all tables named <Signature>\n");
214 /*******************************************************************************
216 * FUNCTION: CheckAscii
218 * PARAMETERS: Name - Ascii string, at least as long as Count
219 * Count - Number of characters to check
223 * DESCRIPTION: Ensure that the requested number of characters are printable
224 * Ascii characters. Sets non-printable and null chars to <space>.
226 ******************************************************************************/
236 for (i
= 0; i
< Count
; i
++)
238 if (!Name
[i
] || !isprint (Name
[i
]))
246 /*******************************************************************************
248 * FUNCTION: NormalizeSignature
250 * PARAMETERS: Name - Ascii string
254 * DESCRIPTION: Change "RSD PTR" to "RSDP"
256 ******************************************************************************/
263 if (!strncmp (Signature
, "RSD ", 4))
270 /******************************************************************************
272 * FUNCTION: ConvertLine
274 * DESCRIPTION: Convert one line of ascii text binary (up to 16 bytes)
276 ******************************************************************************/
281 unsigned char *OutputData
)
289 /* Terminate the input line at the end of the actual data (for sscanf) */
291 End
= strstr (InputLine
+ 2, " ");
294 return 0; /* Don't understand the format */
299 * Convert one line of table data, of the form:
300 * <offset>: <up to 16 bytes of hex data> <ASCII representation> <newline>
303 * 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08 _SB_LNKD........
305 BytesConverted
= sscanf (InputLine
,
306 "%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
307 &Converted
[0], &Converted
[1], &Converted
[2], &Converted
[3],
308 &Converted
[4], &Converted
[5], &Converted
[6], &Converted
[7],
309 &Converted
[8], &Converted
[9], &Converted
[10], &Converted
[11],
310 &Converted
[12], &Converted
[13], &Converted
[14], &Converted
[15]);
312 /* Pack converted data into a byte array */
314 for (i
= 0; i
< BytesConverted
; i
++)
316 OutputData
[i
] = (unsigned char) Converted
[i
];
319 return ((size_t) BytesConverted
);
323 /******************************************************************************
325 * FUNCTION: GetTableHeader
327 * DESCRIPTION: Extract and convert a table heaader
329 ******************************************************************************/
334 unsigned char *OutputData
)
336 size_t BytesConverted
;
337 size_t TotalConverted
= 0;
338 char Buffer
[BUFFER_SIZE
];
342 /* Get the full 36 byte header, requires 3 lines */
344 for (i
= 0; i
< 3; i
++)
346 if (!fgets (Buffer
, BUFFER_SIZE
, InputFile
))
348 return TotalConverted
;
351 BytesConverted
= ConvertLine (Buffer
, OutputData
);
352 TotalConverted
+= BytesConverted
;
355 if (BytesConverted
!= 16)
357 return TotalConverted
;
361 return TotalConverted
;
365 /******************************************************************************
367 * FUNCTION: CountTableInstances
369 * DESCRIPTION: Count the instances of table <Signature> within the input file
371 ******************************************************************************/
374 CountTableInstances (
378 char Buffer
[BUFFER_SIZE
];
380 unsigned int Instances
= 0;
383 InputFile
= fopen (InputPathname
, "rt");
386 printf ("Could not open %s\n", InputPathname
);
390 /* Count the number of instances of this signature */
392 while (fgets (Buffer
, BUFFER_SIZE
, InputFile
))
394 /* Ignore empty lines and lines that start with a space */
396 if ((Buffer
[0] == ' ') ||
402 NormalizeSignature (Buffer
);
403 if (!strncmp (Buffer
, Signature
, 4))
414 /******************************************************************************
416 * FUNCTION: GetNextInstance
420 ******************************************************************************/
427 struct TableInfo
*Info
;
433 if (*(unsigned int *) Signature
== Info
->Signature
)
443 Info
= malloc (sizeof (struct TableInfo
));
445 Info
->Signature
= *(unsigned int *) Signature
;
446 Info
->Instances
= CountTableInstances (InputPathname
, Signature
);
447 Info
->NextInstance
= 1;
449 Info
->Next
= ListHead
;
453 if (Info
->Instances
> 1)
455 return (Info
->NextInstance
++);
462 /******************************************************************************
464 * FUNCTION: ExtractTables
466 * DESCRIPTION: Convert text ACPI tables to binary
468 ******************************************************************************/
474 unsigned int MinimumInstances
)
476 char Buffer
[BUFFER_SIZE
];
478 FILE *OutputFile
= NULL
;
480 size_t TotalBytesWritten
= 0;
481 size_t BytesConverted
;
482 unsigned int State
= FIND_HEADER
;
483 unsigned int FoundTable
= 0;
484 unsigned int Instances
= 0;
485 unsigned int ThisInstance
;
486 char ThisSignature
[4];
489 /* Open input in text mode, output is in binary mode */
491 InputFile
= fopen (InputPathname
, "rt");
494 printf ("Could not open %s\n", InputPathname
);
500 /* Are there enough instances of the table to continue? */
502 NormalizeSignature (Signature
);
504 Instances
= CountTableInstances (InputPathname
, Signature
);
505 if (Instances
< MinimumInstances
)
507 printf ("Table %s was not found in %s\n", Signature
, InputPathname
);
517 /* Convert all instances of the table to binary */
519 while (fgets (Buffer
, BUFFER_SIZE
, InputFile
))
525 /* Ignore empty lines and lines that start with a space */
527 if ((Buffer
[0] == ' ') ||
533 NormalizeSignature (Buffer
);
534 strncpy (ThisSignature
, Buffer
, 4);
538 /* Ignore signatures that don't match */
540 if (strncmp (ThisSignature
, Signature
, 4))
546 /* Get the instance # for this signature */
548 ThisInstance
= GetNextInstance (InputPathname
, ThisSignature
);
550 /* Build an output filename and create/open the output file */
552 if (ThisInstance
> 0)
554 sprintf (Filename
, "%4.4s%u.dat", ThisSignature
, ThisInstance
);
558 sprintf (Filename
, "%4.4s.dat", ThisSignature
);
561 OutputFile
= fopen (Filename
, "w+b");
564 printf ("Could not open %s\n", Filename
);
568 State
= EXTRACT_DATA
;
569 TotalBytesWritten
= 0;
575 /* Empty line or non-data line terminates the data */
577 if ((Buffer
[0] == '\n') ||
584 printf ("Acpi table [%4.4s] - % 6d bytes written to %s\n",
585 ThisSignature
, TotalBytesWritten
, Filename
);
589 /* Convert the ascii data (one line of text) to binary */
591 BytesConverted
= ConvertLine (Buffer
, Data
);
593 /* Write the binary data */
595 BytesWritten
= fwrite (Data
, 1, BytesConverted
, OutputFile
);
596 if (BytesWritten
!= BytesConverted
)
598 printf ("Write error on %s\n", Filename
);
603 TotalBytesWritten
+= BytesConverted
;
613 printf ("Table %s was not found in %s\n", Signature
, InputPathname
);
626 /******************************************************************************
628 * FUNCTION: ListTables
630 * DESCRIPTION: Display info for all ACPI tables found in input
632 ******************************************************************************/
639 char Buffer
[BUFFER_SIZE
];
641 unsigned char Header
[48];
645 /* Open input in text mode, output is in binary mode */
647 InputFile
= fopen (InputPathname
, "rt");
650 printf ("Could not open %s\n", InputPathname
);
654 printf ("\nSignature Length OemId OemTableId OemRevision CompilerId CompilerRevision\n\n");
656 while (fgets (Buffer
, BUFFER_SIZE
, InputFile
))
658 /* Ignore empty lines and lines that start with a space */
660 if ((Buffer
[0] == ' ') ||
666 /* Get the 36 byte header and display the fields */
668 HeaderSize
= GetTableHeader (InputFile
, Header
);
674 /* RSDP has an oddball signature and header */
676 if (!strncmp ((char *) Header
, "RSD PTR ", 8))
678 CheckAscii (&Header
[9], 6);
679 printf ("%8.4s \"%6.6s\"\n", "RSDP", &Header
[9]);
691 /* Signature and Table length */
694 printf ("%8.4s % 7d", Header
, *(int *) &Header
[4]);
696 /* FACS has only signature and length */
698 if (!strncmp ((char *) Header
, "FACS", 4))
704 /* OEM IDs and Compiler IDs */
706 CheckAscii (&Header
[10], 6);
707 CheckAscii (&Header
[16], 8);
708 CheckAscii (&Header
[28], 4);
710 printf (" \"%6.6s\" \"%8.8s\" %8.8X \"%4.4s\" %8.8X\n",
711 &Header
[10], &Header
[16], *(int *) &Header
[24],
712 &Header
[28], *(int *) &Header
[32]);
715 printf ("\nFound %d ACPI tables [%8.8X]\n", TableCount
, VERSION
);
721 /******************************************************************************
725 * DESCRIPTION: C main function
727 ******************************************************************************/
743 if (argv
[1][0] == '-')
754 return (ExtractTables (argv
[2], NULL
, 0));
757 return (ListTables (argv
[2]));
760 return (ExtractTables (argv
[2], &argv
[1][2], 1));
769 * Default output is the DSDT and all SSDTs. One DSDT is required,
770 * any SSDTs are optional.
772 Status
= ExtractTables (argv
[1], "DSDT", 1);
778 Status
= ExtractTables (argv
[1], "SSDT", 0);