1 /******************************************************************************
3 * Module Name: apmain - Main module for the acpidump utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define _DECLARE_GLOBALS
48 * acpidump - A portable utility for obtaining system ACPI tables and dumping
49 * them in an ASCII hex format suitable for binary extraction via acpixtract.
51 * Obtaining the system ACPI tables is an OS-specific operation.
53 * This utility can be ported to any host operating system by providing a
54 * module containing system-specific versions of these interfaces:
56 * acpi_os_get_table_by_address
57 * acpi_os_get_table_by_index
58 * acpi_os_get_table_by_name
60 * See the ACPICA Reference Guide for the exact definitions of these
61 * interfaces. Also, see these ACPICA source code modules for example
64 * source/os_specific/service_layers/oswintbl.c
65 * source/os_specific/service_layers/oslinuxtbl.c
68 /* Local prototypes */
70 static void ap_display_usage(void);
72 static int ap_do_options(int argc, char **argv);
74 static int ap_insert_action(char *argument, u32 to_be_done);
76 /* Table for deferred actions from command line options */
78 struct ap_dump_action action_table[AP_MAX_ACTIONS];
79 u32 current_action = 0;
81 #define AP_UTILITY_NAME "ACPI Binary Table Dump Utility"
82 #define AP_SUPPORTED_OPTIONS "?a:bc:f:hn:o:r:sv^xz"
84 /******************************************************************************
86 * FUNCTION: ap_display_usage
88 * DESCRIPTION: Usage message for the acpi_dump utility
90 ******************************************************************************/
92 static void ap_display_usage(void)
95 ACPI_USAGE_HEADER("acpidump [options]");
97 ACPI_OPTION("-b", "Dump tables to binary files");
98 ACPI_OPTION("-h -?", "This help message");
99 ACPI_OPTION("-o <File>", "Redirect output to file");
100 ACPI_OPTION("-r <Address>", "Dump tables from specified RSDP");
101 ACPI_OPTION("-s", "Print table summaries only");
102 ACPI_OPTION("-v", "Display version information");
103 ACPI_OPTION("-vd", "Display build date and time");
104 ACPI_OPTION("-z", "Verbose mode");
106 ACPI_USAGE_TEXT("\nTable Options:\n");
108 ACPI_OPTION("-a <Address>", "Get table via a physical address");
109 ACPI_OPTION("-c <on|off>", "Turning on/off customized table dumping");
110 ACPI_OPTION("-f <BinaryFile>", "Get table via a binary file");
111 ACPI_OPTION("-n <Signature>", "Get table via a name/signature");
112 ACPI_OPTION("-x", "Do not use but dump XSDT");
113 ACPI_OPTION("-x -x", "Do not use or dump XSDT");
116 "Invocation without parameters dumps all available tables\n"
117 "Multiple mixed instances of -a, -f, and -n are supported\n\n");
120 /******************************************************************************
122 * FUNCTION: ap_insert_action
124 * PARAMETERS: argument - Pointer to the argument for this action
125 * to_be_done - What to do to process this action
129 * DESCRIPTION: Add an action item to the action table
131 ******************************************************************************/
133 static int ap_insert_action(char *argument, u32 to_be_done)
136 /* Insert action and check for table overflow */
138 action_table[current_action].argument = argument;
139 action_table[current_action].to_be_done = to_be_done;
142 if (current_action > AP_MAX_ACTIONS) {
143 fprintf(stderr, "Too many table options (max %u)\n",
151 /******************************************************************************
153 * FUNCTION: ap_do_options
155 * PARAMETERS: argc/argv - Standard argc/argv
159 * DESCRIPTION: Command line option processing. The main actions for getting
160 * and dumping tables are deferred via the action table.
162 *****************************************************************************/
164 static int ap_do_options(int argc, char **argv)
169 /* Command line options */
172 acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END)
177 case 'b': /* Dump all input tables to binary files */
179 gbl_binary_mode = TRUE;
182 case 'c': /* Dump customized tables */
184 if (!strcmp(acpi_gbl_optarg, "on")) {
185 gbl_dump_customized_tables = TRUE;
186 } else if (!strcmp(acpi_gbl_optarg, "off")) {
187 gbl_dump_customized_tables = FALSE;
190 "%s: Cannot handle this switch, please use on|off\n",
202 case 'o': /* Redirect output to a single file */
204 if (ap_open_output_file(acpi_gbl_optarg)) {
209 case 'r': /* Dump tables from specified RSDP */
212 acpi_ut_strtoul64(acpi_gbl_optarg, &gbl_rsdp_base);
213 if (ACPI_FAILURE(status)) {
215 "%s: Could not convert to a physical address\n",
221 case 's': /* Print table summaries only */
223 gbl_summary_mode = TRUE;
226 case 'x': /* Do not use XSDT */
228 if (!acpi_gbl_do_not_use_xsdt) {
229 acpi_gbl_do_not_use_xsdt = TRUE;
231 gbl_do_not_dump_xsdt = TRUE;
235 case 'v': /* -v: (Version): signon already emitted, just exit */
237 switch (acpi_gbl_optarg[0]) {
238 case '^': /* -v: (Version) */
241 ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
247 ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
248 printf(ACPI_COMMON_BUILD_TIME);
253 printf("Unknown option: -v%s\n",
259 case 'z': /* Verbose mode */
261 gbl_verbose_mode = TRUE;
262 fprintf(stderr, ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
268 case 'a': /* Get table by physical address */
271 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_ADDRESS)) {
276 case 'f': /* Get table from a file */
279 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_FILE)) {
284 case 'n': /* Get table by input name (signature) */
287 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_NAME)) {
298 /* If there are no actions, this means "get/dump all tables" */
300 if (current_action == 0) {
301 if (ap_insert_action(NULL, AP_DUMP_ALL_TABLES)) {
309 /******************************************************************************
313 * PARAMETERS: argc/argv - Standard argc/argv
317 * DESCRIPTION: C main function for acpidump utility
319 ******************************************************************************/
321 #if !defined(_GNU_EFI) && !defined(_EDK2_EFI)
322 int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
324 int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[])
328 struct ap_dump_action *action;
332 ACPI_DEBUG_INITIALIZE(); /* For debug version only */
333 acpi_os_initialize();
334 gbl_output_file = ACPI_FILE_OUT;
335 acpi_gbl_integer_byte_width = 8;
337 /* Process command line options */
339 status = ap_do_options(argc, argv);
347 /* Get/dump ACPI table(s) as requested */
349 for (i = 0; i < current_action; i++) {
350 action = &action_table[i];
351 switch (action->to_be_done) {
352 case AP_DUMP_ALL_TABLES:
354 status = ap_dump_all_tables();
357 case AP_DUMP_TABLE_BY_ADDRESS:
359 status = ap_dump_table_by_address(action->argument);
362 case AP_DUMP_TABLE_BY_NAME:
364 status = ap_dump_table_by_name(action->argument);
367 case AP_DUMP_TABLE_BY_FILE:
369 status = ap_dump_table_from_file(action->argument);
375 "Internal error, invalid action: 0x%X\n",
385 if (gbl_output_filename) {
386 if (gbl_verbose_mode) {
388 /* Summary for the output file */
390 file_size = cm_get_file_size(gbl_output_file);
392 "Output file %s contains 0x%X (%u) bytes\n\n",
393 gbl_output_filename, file_size, file_size);
396 fclose(gbl_output_file);