axmain.c revision 1.1.1.1.10.2 1 1.1.1.1.10.2 tls /******************************************************************************
2 1.1.1.1.10.2 tls *
3 1.1.1.1.10.2 tls * Module Name: axmain - main module for acpixtract utility
4 1.1.1.1.10.2 tls *
5 1.1.1.1.10.2 tls *****************************************************************************/
6 1.1.1.1.10.2 tls
7 1.1.1.1.10.2 tls /*
8 1.1.1.1.10.2 tls * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1.1.1.10.2 tls * All rights reserved.
10 1.1.1.1.10.2 tls *
11 1.1.1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
12 1.1.1.1.10.2 tls * modification, are permitted provided that the following conditions
13 1.1.1.1.10.2 tls * are met:
14 1.1.1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
15 1.1.1.1.10.2 tls * notice, this list of conditions, and the following disclaimer,
16 1.1.1.1.10.2 tls * without modification.
17 1.1.1.1.10.2 tls * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.1.10.2 tls * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.1.10.2 tls * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.1.10.2 tls * including a substantially similar Disclaimer requirement for further
21 1.1.1.1.10.2 tls * binary redistribution.
22 1.1.1.1.10.2 tls * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.1.10.2 tls * of any contributors may be used to endorse or promote products derived
24 1.1.1.1.10.2 tls * from this software without specific prior written permission.
25 1.1.1.1.10.2 tls *
26 1.1.1.1.10.2 tls * Alternatively, this software may be distributed under the terms of the
27 1.1.1.1.10.2 tls * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.1.10.2 tls * Software Foundation.
29 1.1.1.1.10.2 tls *
30 1.1.1.1.10.2 tls * NO WARRANTY
31 1.1.1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.1.10.2 tls * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.1.10.2 tls * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.1.10.2 tls * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.1.10.2 tls * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.1.10.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.1.10.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.1.10.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.1.10.2 tls * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.1.10.2 tls * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.1.10.2 tls * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.1.10.2 tls */
43 1.1.1.1.10.2 tls
44 1.1.1.1.10.2 tls #include "acpi.h"
45 1.1.1.1.10.2 tls #include "accommon.h"
46 1.1.1.1.10.2 tls #include "acapps.h"
47 1.1.1.1.10.2 tls #include <stdio.h>
48 1.1.1.1.10.2 tls
49 1.1.1.1.10.2 tls
50 1.1.1.1.10.2 tls static void
51 1.1.1.1.10.2 tls DisplayUsage (
52 1.1.1.1.10.2 tls void);
53 1.1.1.1.10.2 tls
54 1.1.1.1.10.2 tls int
55 1.1.1.1.10.2 tls AxExtractTables (
56 1.1.1.1.10.2 tls char *InputPathname,
57 1.1.1.1.10.2 tls char *Signature,
58 1.1.1.1.10.2 tls unsigned int MinimumInstances);
59 1.1.1.1.10.2 tls
60 1.1.1.1.10.2 tls int
61 1.1.1.1.10.2 tls AxListTables (
62 1.1.1.1.10.2 tls char *InputPathname);
63 1.1.1.1.10.2 tls
64 1.1.1.1.10.2 tls
65 1.1.1.1.10.2 tls /* Options */
66 1.1.1.1.10.2 tls
67 1.1.1.1.10.2 tls #define AX_EXTRACT_ALL 0
68 1.1.1.1.10.2 tls #define AX_LIST_ALL 1
69 1.1.1.1.10.2 tls #define AX_EXTRACT_SIGNATURE 2
70 1.1.1.1.10.2 tls #define AX_EXTRACT_AML_TABLES 3
71 1.1.1.1.10.2 tls
72 1.1.1.1.10.2 tls static int AxAction = AX_EXTRACT_AML_TABLES; /* DSDT & SSDTs */
73 1.1.1.1.10.2 tls
74 1.1.1.1.10.2 tls #define AX_OPTIONAL_TABLES 0
75 1.1.1.1.10.2 tls #define AX_REQUIRED_TABLE 1
76 1.1.1.1.10.2 tls
77 1.1.1.1.10.2 tls #define AX_UTILITY_NAME "ACPI Binary Table Extraction Utility"
78 1.1.1.1.10.2 tls #define AX_SUPPORTED_OPTIONS "ahls:v"
79 1.1.1.1.10.2 tls
80 1.1.1.1.10.2 tls
81 1.1.1.1.10.2 tls /******************************************************************************
82 1.1.1.1.10.2 tls *
83 1.1.1.1.10.2 tls * FUNCTION: DisplayUsage
84 1.1.1.1.10.2 tls *
85 1.1.1.1.10.2 tls * DESCRIPTION: Usage message
86 1.1.1.1.10.2 tls *
87 1.1.1.1.10.2 tls ******************************************************************************/
88 1.1.1.1.10.2 tls
89 1.1.1.1.10.2 tls static void
90 1.1.1.1.10.2 tls DisplayUsage (
91 1.1.1.1.10.2 tls void)
92 1.1.1.1.10.2 tls {
93 1.1.1.1.10.2 tls
94 1.1.1.1.10.2 tls ACPI_USAGE_HEADER ("acpixtract [option] <InputFile>");
95 1.1.1.1.10.2 tls
96 1.1.1.1.10.2 tls ACPI_OPTION ("-a", "Extract all tables, not just DSDT/SSDT");
97 1.1.1.1.10.2 tls ACPI_OPTION ("-l", "List table summaries, do not extract");
98 1.1.1.1.10.2 tls ACPI_OPTION ("-s <signature>", "Extract all tables with <signature>");
99 1.1.1.1.10.2 tls ACPI_OPTION ("-v", "Display version information");
100 1.1.1.1.10.2 tls
101 1.1.1.1.10.2 tls printf ("\nExtract binary ACPI tables from text acpidump output\n");
102 1.1.1.1.10.2 tls printf ("Default invocation extracts the DSDT and all SSDTs\n");
103 1.1.1.1.10.2 tls }
104 1.1.1.1.10.2 tls
105 1.1.1.1.10.2 tls
106 1.1.1.1.10.2 tls /******************************************************************************
107 1.1.1.1.10.2 tls *
108 1.1.1.1.10.2 tls * FUNCTION: main
109 1.1.1.1.10.2 tls *
110 1.1.1.1.10.2 tls * DESCRIPTION: C main function
111 1.1.1.1.10.2 tls *
112 1.1.1.1.10.2 tls ******************************************************************************/
113 1.1.1.1.10.2 tls
114 1.1.1.1.10.2 tls int
115 1.1.1.1.10.2 tls main (
116 1.1.1.1.10.2 tls int argc,
117 1.1.1.1.10.2 tls char *argv[])
118 1.1.1.1.10.2 tls {
119 1.1.1.1.10.2 tls char *Filename;
120 1.1.1.1.10.2 tls int Status;
121 1.1.1.1.10.2 tls int j;
122 1.1.1.1.10.2 tls
123 1.1.1.1.10.2 tls
124 1.1.1.1.10.2 tls ACPI_DEBUG_INITIALIZE (); /* For debug version only */
125 1.1.1.1.10.2 tls printf (ACPI_COMMON_SIGNON (AX_UTILITY_NAME));
126 1.1.1.1.10.2 tls
127 1.1.1.1.10.2 tls if (argc < 2)
128 1.1.1.1.10.2 tls {
129 1.1.1.1.10.2 tls DisplayUsage ();
130 1.1.1.1.10.2 tls return (0);
131 1.1.1.1.10.2 tls }
132 1.1.1.1.10.2 tls
133 1.1.1.1.10.2 tls /* Command line options */
134 1.1.1.1.10.2 tls
135 1.1.1.1.10.2 tls while ((j = AcpiGetopt (argc, argv, AX_SUPPORTED_OPTIONS)) != EOF) switch (j)
136 1.1.1.1.10.2 tls {
137 1.1.1.1.10.2 tls case 'a':
138 1.1.1.1.10.2 tls
139 1.1.1.1.10.2 tls AxAction = AX_EXTRACT_ALL; /* Extract all tables found */
140 1.1.1.1.10.2 tls break;
141 1.1.1.1.10.2 tls
142 1.1.1.1.10.2 tls case 'l':
143 1.1.1.1.10.2 tls
144 1.1.1.1.10.2 tls AxAction = AX_LIST_ALL; /* List tables only, do not extract */
145 1.1.1.1.10.2 tls break;
146 1.1.1.1.10.2 tls
147 1.1.1.1.10.2 tls case 's':
148 1.1.1.1.10.2 tls
149 1.1.1.1.10.2 tls AxAction = AX_EXTRACT_SIGNATURE; /* Extract only tables with this sig */
150 1.1.1.1.10.2 tls break;
151 1.1.1.1.10.2 tls
152 1.1.1.1.10.2 tls case 'v': /* -v: (Version): signon already emitted, just exit */
153 1.1.1.1.10.2 tls
154 1.1.1.1.10.2 tls return (0);
155 1.1.1.1.10.2 tls
156 1.1.1.1.10.2 tls case 'h':
157 1.1.1.1.10.2 tls default:
158 1.1.1.1.10.2 tls
159 1.1.1.1.10.2 tls DisplayUsage ();
160 1.1.1.1.10.2 tls return (0);
161 1.1.1.1.10.2 tls }
162 1.1.1.1.10.2 tls
163 1.1.1.1.10.2 tls /* Input filename is always required */
164 1.1.1.1.10.2 tls
165 1.1.1.1.10.2 tls Filename = argv[AcpiGbl_Optind];
166 1.1.1.1.10.2 tls if (!Filename)
167 1.1.1.1.10.2 tls {
168 1.1.1.1.10.2 tls printf ("Missing required input filename\n");
169 1.1.1.1.10.2 tls return (-1);
170 1.1.1.1.10.2 tls }
171 1.1.1.1.10.2 tls
172 1.1.1.1.10.2 tls /* Perform requested action */
173 1.1.1.1.10.2 tls
174 1.1.1.1.10.2 tls switch (AxAction)
175 1.1.1.1.10.2 tls {
176 1.1.1.1.10.2 tls case AX_EXTRACT_ALL:
177 1.1.1.1.10.2 tls
178 1.1.1.1.10.2 tls Status = AxExtractTables (Filename, NULL, AX_OPTIONAL_TABLES);
179 1.1.1.1.10.2 tls break;
180 1.1.1.1.10.2 tls
181 1.1.1.1.10.2 tls case AX_LIST_ALL:
182 1.1.1.1.10.2 tls
183 1.1.1.1.10.2 tls Status = AxListTables (Filename);
184 1.1.1.1.10.2 tls break;
185 1.1.1.1.10.2 tls
186 1.1.1.1.10.2 tls case AX_EXTRACT_SIGNATURE:
187 1.1.1.1.10.2 tls
188 1.1.1.1.10.2 tls Status = AxExtractTables (Filename, AcpiGbl_Optarg, AX_REQUIRED_TABLE);
189 1.1.1.1.10.2 tls break;
190 1.1.1.1.10.2 tls
191 1.1.1.1.10.2 tls default:
192 1.1.1.1.10.2 tls /*
193 1.1.1.1.10.2 tls * Default output is the DSDT and all SSDTs. One DSDT is required,
194 1.1.1.1.10.2 tls * any SSDTs are optional.
195 1.1.1.1.10.2 tls */
196 1.1.1.1.10.2 tls Status = AxExtractTables (Filename, "DSDT", AX_REQUIRED_TABLE);
197 1.1.1.1.10.2 tls if (Status)
198 1.1.1.1.10.2 tls {
199 1.1.1.1.10.2 tls return (Status);
200 1.1.1.1.10.2 tls }
201 1.1.1.1.10.2 tls
202 1.1.1.1.10.2 tls Status = AxExtractTables (Filename, "SSDT", AX_OPTIONAL_TABLES);
203 1.1.1.1.10.2 tls break;
204 1.1.1.1.10.2 tls }
205 1.1.1.1.10.2 tls
206 1.1.1.1.10.2 tls return (Status);
207 1.1.1.1.10.2 tls }
208