abmain.c revision 1.1 1
2 /******************************************************************************
3 *
4 * Module Name: abmain - Main module for the acpi binary utility
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45
46 #define _DECLARE_GLOBALS
47 #include "acpibin.h"
48 #include "acapps.h"
49
50 /* Local prototypes */
51
52 static void
53 AbDisplayUsage (
54 UINT8 OptionCount);
55
56
57 /******************************************************************************
58 *
59 * FUNCTION: AbDisplayUsage
60 *
61 * DESCRIPTION: Usage message
62 *
63 ******************************************************************************/
64
65 static void
66 AbDisplayUsage (
67 UINT8 OptionCount)
68 {
69
70 if (OptionCount)
71 {
72 printf ("Option requires %u arguments\n\n", OptionCount);
73 }
74
75 printf ("Usage: acpibin [options]\n\n");
76 printf ("Options:\n\n");
77 printf (" -c <File1> <File2> Compare two AML files\n");
78 printf (" -d <InFile> <OutFile> Dump AML binary to text file\n");
79 printf (" -e <Sig> <InFile> <OutFile> Extract binary AML table from AcpiDmp file\n\n");
80
81 printf (" -h <File> Display table header for binary AML file\n");
82 printf (" -s <File> Update checksum for binary AML file\n");
83 printf (" -t Terse mode\n");
84
85 printf ("\n");
86 return;
87 }
88
89
90 /******************************************************************************
91 *
92 * FUNCTION: main
93 *
94 * DESCRIPTION: C main function
95 *
96 ******************************************************************************/
97
98 int ACPI_SYSTEM_XFACE
99 main (
100 int argc,
101 char *argv[])
102 {
103 int j;
104 int Status = AE_OK;
105
106
107 AcpiGbl_DebugFile = NULL;
108 AcpiGbl_DbOutputFlags = DB_CONSOLE_OUTPUT ;
109
110 AcpiOsInitialize ();
111 printf (ACPI_COMMON_SIGNON ("ACPI Binary AML File Utility"));
112
113 if (argc < 2)
114 {
115 AbDisplayUsage (0);
116 return 0;
117 }
118
119 /* Command line options */
120
121 while ((j = AcpiGetopt (argc, argv, "c:d:e:h:s:t")) != EOF) switch(j)
122 {
123 case 'c': /* Compare Files */
124
125 if (argc < 4)
126 {
127 AbDisplayUsage (2);
128 return -1;
129 }
130
131 Status = AbCompareAmlFiles (AcpiGbl_Optarg, argv[AcpiGbl_Optind]);
132 break;
133
134 case 'd': /* Dump AML file */
135
136 if (argc < 4)
137 {
138 AbDisplayUsage (2);
139 return -1;
140 }
141
142 Status = AbDumpAmlFile (AcpiGbl_Optarg, argv[AcpiGbl_Optind]);
143 break;
144
145 case 'e': /* Extract AML text file */
146
147 if (argc < 5)
148 {
149 AbDisplayUsage (3);
150 return -1;
151 }
152
153 Status = AbExtractAmlFile (AcpiGbl_Optarg, argv[AcpiGbl_Optind],
154 argv[AcpiGbl_Optind+1]);
155 break;
156
157 case 'h': /* Display ACPI table header */
158
159 if (argc < 3)
160 {
161 AbDisplayUsage (1);
162 return -1;
163 }
164
165 AbDisplayHeader (AcpiGbl_Optarg);
166 return (0);
167
168 case 's': /* Compute/update checksum */
169
170 if (argc < 3)
171 {
172 AbDisplayUsage (1);
173 return -1;
174 }
175
176 AbComputeChecksum (AcpiGbl_Optarg);
177 return (0);
178
179 case 't': /* Enable terse mode */
180
181 Gbl_TerseMode = TRUE;
182 break;
183
184 default:
185 AbDisplayUsage (0);
186 return -1;
187 }
188
189 return Status;
190 }
191