1 /****************************************************************************** 2 * 3 * Module Name: apmain - Main module for the acpidump utility 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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. 25 * 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. 29 * 30 * NO WARRANTY 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. 42 */ 43 44 #define _DECLARE_GLOBALS 45 #include "acpidump.h" 46 #include "acapps.h" 47 48 49 /* 50 * acpidump - A portable utility for obtaining system ACPI tables and dumping 51 * them in an ASCII hex format suitable for binary extraction via acpixtract. 52 * 53 * Obtaining the system ACPI tables is an OS-specific operation. 54 * 55 * This utility can be ported to any host operating system by providing a 56 * module containing system-specific versions of these interfaces: 57 * 58 * AcpiOsGetTableByAddress 59 * AcpiOsGetTableByIndex 60 * AcpiOsGetTableByName 61 * 62 * See the ACPICA Reference Guide for the exact definitions of these 63 * interfaces. Also, see these ACPICA source code modules for example 64 * implementations: 65 * 66 * source/os_specific/service_layers/oswintbl.c 67 * source/os_specific/service_layers/oslinuxtbl.c 68 */ 69 70 71 /* Local prototypes */ 72 73 static void 74 ApDisplayUsage ( 75 void); 76 77 static int 78 ApDoOptions ( 79 int argc, 80 char **argv); 81 82 static void 83 ApInsertAction ( 84 char *Argument, 85 UINT32 ToBeDone); 86 87 88 /* Table for deferred actions from command line options */ 89 90 AP_DUMP_ACTION ActionTable [AP_MAX_ACTIONS]; 91 UINT32 CurrentAction = 0; 92 93 94 #define AP_UTILITY_NAME "ACPI Binary Table Dump Utility" 95 #define AP_SUPPORTED_OPTIONS "?a:bcf:hn:o:r:svxz" 96 97 98 /****************************************************************************** 99 * 100 * FUNCTION: ApDisplayUsage 101 * 102 * DESCRIPTION: Usage message for the AcpiDump utility 103 * 104 ******************************************************************************/ 105 106 static void 107 ApDisplayUsage ( 108 void) 109 { 110 111 ACPI_USAGE_HEADER ("acpidump [options]"); 112 113 ACPI_OPTION ("-b", "Dump tables to binary files"); 114 ACPI_OPTION ("-c", "Dump customized tables"); 115 ACPI_OPTION ("-h -?", "This help message"); 116 ACPI_OPTION ("-o <File>", "Redirect output to file"); 117 ACPI_OPTION ("-r <Address>", "Dump tables from specified RSDP"); 118 ACPI_OPTION ("-s", "Print table summaries only"); 119 ACPI_OPTION ("-v", "Display version information"); 120 ACPI_OPTION ("-z", "Verbose mode"); 121 122 printf ("\nTable Options:\n"); 123 124 ACPI_OPTION ("-a <Address>", "Get table via a physical address"); 125 ACPI_OPTION ("-f <BinaryFile>", "Get table via a binary file"); 126 ACPI_OPTION ("-n <Signature>", "Get table via a name/signature"); 127 ACPI_OPTION ("-x", "Do not use but dump XSDT"); 128 ACPI_OPTION ("-x -x", "Do not use or dump XSDT"); 129 130 printf ( 131 "\n" 132 "Invocation without parameters dumps all available tables\n" 133 "Multiple mixed instances of -a, -f, and -n are supported\n\n"); 134 } 135 136 137 /****************************************************************************** 138 * 139 * FUNCTION: ApInsertAction 140 * 141 * PARAMETERS: Argument - Pointer to the argument for this action 142 * ToBeDone - What to do to process this action 143 * 144 * RETURN: None. Exits program if action table becomes full. 145 * 146 * DESCRIPTION: Add an action item to the action table 147 * 148 ******************************************************************************/ 149 150 static void 151 ApInsertAction ( 152 char *Argument, 153 UINT32 ToBeDone) 154 { 155 156 /* Insert action and check for table overflow */ 157 158 ActionTable [CurrentAction].Argument = Argument; 159 ActionTable [CurrentAction].ToBeDone = ToBeDone; 160 161 CurrentAction++; 162 if (CurrentAction > AP_MAX_ACTIONS) 163 { 164 fprintf (stderr, "Too many table options (max %u)\n", AP_MAX_ACTIONS); 165 exit (-1); 166 } 167 } 168 169 170 /****************************************************************************** 171 * 172 * FUNCTION: ApDoOptions 173 * 174 * PARAMETERS: argc/argv - Standard argc/argv 175 * 176 * RETURN: Status 177 * 178 * DESCRIPTION: Command line option processing. The main actions for getting 179 * and dumping tables are deferred via the action table. 180 * 181 *****************************************************************************/ 182 183 static int 184 ApDoOptions ( 185 int argc, 186 char **argv) 187 { 188 int j; 189 ACPI_STATUS Status; 190 191 192 /* Command line options */ 193 194 while ((j = AcpiGetopt (argc, argv, AP_SUPPORTED_OPTIONS)) != EOF) switch (j) 195 { 196 /* 197 * Global options 198 */ 199 case 'b': /* Dump all input tables to binary files */ 200 201 Gbl_BinaryMode = TRUE; 202 continue; 203 204 case 'c': /* Dump customized tables */ 205 206 Gbl_DumpCustomizedTables = TRUE; 207 continue; 208 209 case 'h': 210 case '?': 211 212 ApDisplayUsage (); 213 exit (0); 214 215 case 'o': /* Redirect output to a single file */ 216 217 if (ApOpenOutputFile (AcpiGbl_Optarg)) 218 { 219 exit (-1); 220 } 221 continue; 222 223 case 'r': /* Dump tables from specified RSDP */ 224 225 Status = AcpiUtStrtoul64 (AcpiGbl_Optarg, 0, &Gbl_RsdpBase); 226 if (ACPI_FAILURE (Status)) 227 { 228 fprintf (stderr, "%s: Could not convert to a physical address\n", 229 AcpiGbl_Optarg); 230 exit (-1); 231 } 232 continue; 233 234 case 's': /* Print table summaries only */ 235 236 Gbl_SummaryMode = TRUE; 237 continue; 238 239 case 'x': /* Do not use XSDT */ 240 241 if (!AcpiGbl_DoNotUseXsdt) 242 { 243 AcpiGbl_DoNotUseXsdt = TRUE; 244 } 245 else 246 { 247 Gbl_DoNotDumpXsdt = TRUE; 248 } 249 continue; 250 251 case 'v': /* Revision/version */ 252 253 printf (ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); 254 exit (0); 255 256 case 'z': /* Verbose mode */ 257 258 Gbl_VerboseMode = TRUE; 259 fprintf (stderr, ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); 260 continue; 261 262 /* 263 * Table options 264 */ 265 case 'a': /* Get table by physical address */ 266 267 ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_ADDRESS); 268 break; 269 270 case 'f': /* Get table from a file */ 271 272 ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_FILE); 273 break; 274 275 case 'n': /* Get table by input name (signature) */ 276 277 ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_NAME); 278 break; 279 280 default: 281 282 ApDisplayUsage (); 283 exit (-1); 284 } 285 286 /* If there are no actions, this means "get/dump all tables" */ 287 288 if (CurrentAction == 0) 289 { 290 ApInsertAction (NULL, AP_DUMP_ALL_TABLES); 291 } 292 293 return (0); 294 } 295 296 297 /****************************************************************************** 298 * 299 * FUNCTION: main 300 * 301 * PARAMETERS: argc/argv - Standard argc/argv 302 * 303 * RETURN: Status 304 * 305 * DESCRIPTION: C main function for acpidump utility 306 * 307 ******************************************************************************/ 308 309 int ACPI_SYSTEM_XFACE 310 main ( 311 int argc, 312 char *argv[]) 313 { 314 int Status = 0; 315 AP_DUMP_ACTION *Action; 316 UINT32 FileSize; 317 UINT32 i; 318 319 320 ACPI_DEBUG_INITIALIZE (); /* For debug version only */ 321 322 /* Process command line options */ 323 324 if (ApDoOptions (argc, argv)) 325 { 326 return (-1); 327 } 328 329 /* Get/dump ACPI table(s) as requested */ 330 331 for (i = 0; i < CurrentAction; i++) 332 { 333 Action = &ActionTable[i]; 334 switch (Action->ToBeDone) 335 { 336 case AP_DUMP_ALL_TABLES: 337 338 Status = ApDumpAllTables (); 339 break; 340 341 case AP_DUMP_TABLE_BY_ADDRESS: 342 343 Status = ApDumpTableByAddress (Action->Argument); 344 break; 345 346 case AP_DUMP_TABLE_BY_NAME: 347 348 Status = ApDumpTableByName (Action->Argument); 349 break; 350 351 case AP_DUMP_TABLE_BY_FILE: 352 353 Status = ApDumpTableFromFile (Action->Argument); 354 break; 355 356 default: 357 358 fprintf (stderr, "Internal error, invalid action: 0x%X\n", 359 Action->ToBeDone); 360 return (-1); 361 } 362 363 if (Status) 364 { 365 return (Status); 366 } 367 } 368 369 if (Gbl_OutputFile) 370 { 371 if (Gbl_VerboseMode) 372 { 373 /* Summary for the output file */ 374 375 FileSize = CmGetFileSize (Gbl_OutputFile); 376 fprintf (stderr, "Output file %s contains 0x%X (%u) bytes\n\n", 377 Gbl_OutputFilename, FileSize, FileSize); 378 } 379 380 fclose (Gbl_OutputFile); 381 } 382 383 return (Status); 384 } 385