This source file includes following definitions.
- ap_display_usage
- ap_insert_action
- ap_do_options
- main
1
2
3
4
5
6
7
8
9
10 #define _DECLARE_GLOBALS
11 #include "acpidump.h"
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 static void ap_display_usage(void);
37
38 static int ap_do_options(int argc, char **argv);
39
40 static int ap_insert_action(char *argument, u32 to_be_done);
41
42
43
44 struct ap_dump_action action_table[AP_MAX_ACTIONS];
45 u32 current_action = 0;
46
47 #define AP_UTILITY_NAME "ACPI Binary Table Dump Utility"
48 #define AP_SUPPORTED_OPTIONS "?a:bc:f:hn:o:r:sv^xz"
49
50
51
52
53
54
55
56
57
58 static void ap_display_usage(void)
59 {
60
61 ACPI_USAGE_HEADER("acpidump [options]");
62
63 ACPI_OPTION("-b", "Dump tables to binary files");
64 ACPI_OPTION("-h -?", "This help message");
65 ACPI_OPTION("-o <File>", "Redirect output to file");
66 ACPI_OPTION("-r <Address>", "Dump tables from specified RSDP");
67 ACPI_OPTION("-s", "Print table summaries only");
68 ACPI_OPTION("-v", "Display version information");
69 ACPI_OPTION("-vd", "Display build date and time");
70 ACPI_OPTION("-z", "Verbose mode");
71
72 ACPI_USAGE_TEXT("\nTable Options:\n");
73
74 ACPI_OPTION("-a <Address>", "Get table via a physical address");
75 ACPI_OPTION("-c <on|off>", "Turning on/off customized table dumping");
76 ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file");
77 ACPI_OPTION("-n <Signature>", "Get table via a name/signature");
78 ACPI_OPTION("-x", "Do not use but dump XSDT");
79 ACPI_OPTION("-x -x", "Do not use or dump XSDT");
80
81 ACPI_USAGE_TEXT("\n"
82 "Invocation without parameters dumps all available tables\n"
83 "Multiple mixed instances of -a, -f, and -n are supported\n\n");
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 static int ap_insert_action(char *argument, u32 to_be_done)
100 {
101
102
103
104 action_table[current_action].argument = argument;
105 action_table[current_action].to_be_done = to_be_done;
106
107 current_action++;
108 if (current_action > AP_MAX_ACTIONS) {
109 fprintf(stderr, "Too many table options (max %d)\n",
110 AP_MAX_ACTIONS);
111 return (-1);
112 }
113
114 return (0);
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 static int ap_do_options(int argc, char **argv)
131 {
132 int j;
133 acpi_status status;
134
135
136
137 while ((j =
138 acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END)
139 switch (j) {
140
141
142
143 case 'b':
144
145 gbl_binary_mode = TRUE;
146 continue;
147
148 case 'c':
149
150 if (!strcmp(acpi_gbl_optarg, "on")) {
151 gbl_dump_customized_tables = TRUE;
152 } else if (!strcmp(acpi_gbl_optarg, "off")) {
153 gbl_dump_customized_tables = FALSE;
154 } else {
155 fprintf(stderr,
156 "%s: Cannot handle this switch, please use on|off\n",
157 acpi_gbl_optarg);
158 return (-1);
159 }
160 continue;
161
162 case 'h':
163 case '?':
164
165 ap_display_usage();
166 return (1);
167
168 case 'o':
169
170 if (ap_open_output_file(acpi_gbl_optarg)) {
171 return (-1);
172 }
173 continue;
174
175 case 'r':
176
177 status =
178 acpi_ut_strtoul64(acpi_gbl_optarg, &gbl_rsdp_base);
179 if (ACPI_FAILURE(status)) {
180 fprintf(stderr,
181 "%s: Could not convert to a physical address\n",
182 acpi_gbl_optarg);
183 return (-1);
184 }
185 continue;
186
187 case 's':
188
189 gbl_summary_mode = TRUE;
190 continue;
191
192 case 'x':
193
194 if (!acpi_gbl_do_not_use_xsdt) {
195 acpi_gbl_do_not_use_xsdt = TRUE;
196 } else {
197 gbl_do_not_dump_xsdt = TRUE;
198 }
199 continue;
200
201 case 'v':
202
203 switch (acpi_gbl_optarg[0]) {
204 case '^':
205
206 fprintf(stderr,
207 ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
208 return (1);
209
210 case 'd':
211
212 fprintf(stderr,
213 ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
214 printf(ACPI_COMMON_BUILD_TIME);
215 return (1);
216
217 default:
218
219 printf("Unknown option: -v%s\n",
220 acpi_gbl_optarg);
221 return (-1);
222 }
223 break;
224
225 case 'z':
226
227 gbl_verbose_mode = TRUE;
228 fprintf(stderr, ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
229 continue;
230
231
232
233
234 case 'a':
235
236 if (ap_insert_action
237 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_ADDRESS)) {
238 return (-1);
239 }
240 break;
241
242 case 'f':
243
244 if (ap_insert_action
245 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_FILE)) {
246 return (-1);
247 }
248 break;
249
250 case 'n':
251
252 if (ap_insert_action
253 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_NAME)) {
254 return (-1);
255 }
256 break;
257
258 default:
259
260 ap_display_usage();
261 return (-1);
262 }
263
264
265
266 if (current_action == 0) {
267 if (ap_insert_action(NULL, AP_DUMP_ALL_TABLES)) {
268 return (-1);
269 }
270 }
271
272 return (0);
273 }
274
275
276
277
278
279
280
281
282
283
284
285
286
287 #if !defined(_GNU_EFI) && !defined(_EDK2_EFI)
288 int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
289 #else
290 int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[])
291 #endif
292 {
293 int status = 0;
294 struct ap_dump_action *action;
295 u32 file_size;
296 u32 i;
297
298 ACPI_DEBUG_INITIALIZE();
299 acpi_os_initialize();
300 gbl_output_file = ACPI_FILE_OUT;
301 acpi_gbl_integer_byte_width = 8;
302
303
304
305 status = ap_do_options(argc, argv);
306 if (status > 0) {
307 return (0);
308 }
309 if (status < 0) {
310 return (status);
311 }
312
313
314
315 for (i = 0; i < current_action; i++) {
316 action = &action_table[i];
317 switch (action->to_be_done) {
318 case AP_DUMP_ALL_TABLES:
319
320 status = ap_dump_all_tables();
321 break;
322
323 case AP_DUMP_TABLE_BY_ADDRESS:
324
325 status = ap_dump_table_by_address(action->argument);
326 break;
327
328 case AP_DUMP_TABLE_BY_NAME:
329
330 status = ap_dump_table_by_name(action->argument);
331 break;
332
333 case AP_DUMP_TABLE_BY_FILE:
334
335 status = ap_dump_table_from_file(action->argument);
336 break;
337
338 default:
339
340 fprintf(stderr,
341 "Internal error, invalid action: 0x%X\n",
342 action->to_be_done);
343 return (-1);
344 }
345
346 if (status) {
347 return (status);
348 }
349 }
350
351 if (gbl_output_filename) {
352 if (gbl_verbose_mode) {
353
354
355
356 file_size = cm_get_file_size(gbl_output_file);
357 fprintf(stderr,
358 "Output file %s contains 0x%X (%u) bytes\n\n",
359 gbl_output_filename, file_size, file_size);
360 }
361
362 fclose(gbl_output_file);
363 }
364
365 return (status);
366 }