1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: apmain - Main module for the acpidump utility
6 * Copyright (C) 2000 - 2023, Intel Corp.
8 *****************************************************************************/
10 #define _DECLARE_GLOBALS
14 * acpidump - A portable utility for obtaining system ACPI tables and dumping
15 * them in an ASCII hex format suitable for binary extraction via acpixtract.
17 * Obtaining the system ACPI tables is an OS-specific operation.
19 * This utility can be ported to any host operating system by providing a
20 * module containing system-specific versions of these interfaces:
22 * acpi_os_get_table_by_address
23 * acpi_os_get_table_by_index
24 * acpi_os_get_table_by_name
26 * See the ACPICA Reference Guide for the exact definitions of these
27 * interfaces. Also, see these ACPICA source code modules for example
30 * source/os_specific/service_layers/oswintbl.c
31 * source/os_specific/service_layers/oslinuxtbl.c
34 /* Local prototypes */
36 static void ap_display_usage(void);
38 static int ap_do_options(int argc, char **argv);
40 static int ap_insert_action(char *argument, u32 to_be_done);
42 /* Table for deferred actions from command line options */
44 struct ap_dump_action action_table[AP_MAX_ACTIONS];
45 u32 current_action = 0;
47 #define AP_UTILITY_NAME "ACPI Binary Table Dump Utility"
48 #define AP_SUPPORTED_OPTIONS "?a:bc:f:hn:o:r:sv^xz"
50 /******************************************************************************
52 * FUNCTION: ap_display_usage
54 * DESCRIPTION: Usage message for the acpi_dump utility
56 ******************************************************************************/
58 static void ap_display_usage(void)
61 ACPI_USAGE_HEADER("acpidump [options]");
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");
72 ACPI_USAGE_TEXT("\nTable Options:\n");
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");
82 "Invocation without parameters dumps all available tables\n"
83 "Multiple mixed instances of -a, -f, and -n are supported\n\n");
86 /******************************************************************************
88 * FUNCTION: ap_insert_action
90 * PARAMETERS: argument - Pointer to the argument for this action
91 * to_be_done - What to do to process this action
95 * DESCRIPTION: Add an action item to the action table
97 ******************************************************************************/
99 static int ap_insert_action(char *argument, u32 to_be_done)
102 /* Insert action and check for table overflow */
104 action_table[current_action].argument = argument;
105 action_table[current_action].to_be_done = to_be_done;
108 if (current_action > AP_MAX_ACTIONS) {
109 fprintf(stderr, "Too many table options (max %d)\n",
117 /******************************************************************************
119 * FUNCTION: ap_do_options
121 * PARAMETERS: argc/argv - Standard argc/argv
125 * DESCRIPTION: Command line option processing. The main actions for getting
126 * and dumping tables are deferred via the action table.
128 *****************************************************************************/
130 static int ap_do_options(int argc, char **argv)
135 /* Command line options */
138 acpi_getopt(argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END)
143 case 'b': /* Dump all input tables to binary files */
145 gbl_binary_mode = TRUE;
148 case 'c': /* Dump customized tables */
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;
156 "%s: Cannot handle this switch, please use on|off\n",
168 case 'o': /* Redirect output to a single file */
170 if (ap_open_output_file(acpi_gbl_optarg)) {
175 case 'r': /* Dump tables from specified RSDP */
178 acpi_ut_strtoul64(acpi_gbl_optarg, &gbl_rsdp_base);
179 if (ACPI_FAILURE(status)) {
181 "%s: Could not convert to a physical address\n",
187 case 's': /* Print table summaries only */
189 gbl_summary_mode = TRUE;
192 case 'x': /* Do not use XSDT */
194 if (!acpi_gbl_do_not_use_xsdt) {
195 acpi_gbl_do_not_use_xsdt = TRUE;
197 gbl_do_not_dump_xsdt = TRUE;
201 case 'v': /* -v: (Version): signon already emitted, just exit */
203 switch (acpi_gbl_optarg[0]) {
204 case '^': /* -v: (Version) */
207 ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
213 ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
214 printf(ACPI_COMMON_BUILD_TIME);
219 printf("Unknown option: -v%s\n",
225 case 'z': /* Verbose mode */
227 gbl_verbose_mode = TRUE;
228 fprintf(stderr, ACPI_COMMON_SIGNON(AP_UTILITY_NAME));
234 case 'a': /* Get table by physical address */
237 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_ADDRESS)) {
242 case 'f': /* Get table from a file */
245 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_FILE)) {
250 case 'n': /* Get table by input name (signature) */
253 (acpi_gbl_optarg, AP_DUMP_TABLE_BY_NAME)) {
264 /* If there are no actions, this means "get/dump all tables" */
266 if (current_action == 0) {
267 if (ap_insert_action(NULL, AP_DUMP_ALL_TABLES)) {
275 /******************************************************************************
279 * PARAMETERS: argc/argv - Standard argc/argv
283 * DESCRIPTION: C main function for acpidump utility
285 ******************************************************************************/
287 #if !defined(_GNU_EFI) && !defined(_EDK2_EFI)
288 int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
290 int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[])
294 struct ap_dump_action *action;
298 ACPI_DEBUG_INITIALIZE(); /* For debug version only */
299 acpi_os_initialize();
300 gbl_output_file = ACPI_FILE_OUT;
301 acpi_gbl_integer_byte_width = 8;
303 /* Process command line options */
305 status = ap_do_options(argc, argv);
313 /* Get/dump ACPI table(s) as requested */
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:
320 status = ap_dump_all_tables();
323 case AP_DUMP_TABLE_BY_ADDRESS:
325 status = ap_dump_table_by_address(action->argument);
328 case AP_DUMP_TABLE_BY_NAME:
330 status = ap_dump_table_by_name(action->argument);
333 case AP_DUMP_TABLE_BY_FILE:
335 status = ap_dump_table_from_file(action->argument);
341 "Internal error, invalid action: 0x%X\n",
351 if (gbl_output_filename) {
352 if (gbl_verbose_mode) {
354 /* Summary for the output file */
356 file_size = cm_get_file_size(gbl_output_file);
358 "Output file %s contains 0x%X (%u) bytes\n\n",
359 gbl_output_filename, file_size, file_size);
362 fclose(gbl_output_file);