1 /****************************************************************************** 2 * 3 * Module Name: apmain - Main module for the acpidump utility 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2013, 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:svz" 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 128 printf ( 129 "\n" 130 "Invocation without parameters dumps all available tables\n" 131 "Multiple mixed instances of -a, -f, and -n are supported\n\n"); 132 } 133 134 135 /****************************************************************************** 136 * 137 * FUNCTION: ApInsertAction 138 * 139 * PARAMETERS: Argument - Pointer to the argument for this action 140 * ToBeDone - What to do to process this action 141 * 142 * RETURN: None. Exits program if action table becomes full. 143 * 144 * DESCRIPTION: Add an action item to the action table 145 * 146 ******************************************************************************/ 147 148 static void 149 ApInsertAction ( 150 char *Argument, 151 UINT32 ToBeDone) 152 { 153 154 /* Insert action and check for table overflow */ 155 156 ActionTable [CurrentAction].Argument = Argument; 157 ActionTable [CurrentAction].ToBeDone = ToBeDone; 158 159 CurrentAction++; 160 if (CurrentAction > AP_MAX_ACTIONS) 161 { 162 fprintf (stderr, "Too many table options (max %u)\n", AP_MAX_ACTIONS); 163 exit (-1); 164 } 165 } 166 167 168 /****************************************************************************** 169 * 170 * FUNCTION: ApDoOptions 171 * 172 * PARAMETERS: argc/argv - Standard argc/argv 173 * 174 * RETURN: Status 175 * 176 * DESCRIPTION: Command line option processing. The main actions for getting 177 * and dumping tables are deferred via the action table. 178 * 179 *****************************************************************************/ 180 181 static int 182 ApDoOptions ( 183 int argc, 184 char **argv) 185 { 186 int j; 187 ACPI_STATUS Status; 188 189 190 /* Command line options */ 191 192 while ((j = AcpiGetopt (argc, argv, AP_SUPPORTED_OPTIONS)) != EOF) switch (j) 193 { 194 /* 195 * Global options 196 */ 197 case 'b': /* Dump all input tables to binary files */ 198 199 Gbl_BinaryMode = TRUE; 200 continue; 201 202 case 'c': /* Dump customized tables */ 203 204 Gbl_DumpCustomizedTables = TRUE; 205 continue; 206 207 case 'h': 208 case '?': 209 210 ApDisplayUsage (); 211 exit (0); 212 213 case 'o': /* Redirect output to a single file */ 214 215 if (ApOpenOutputFile (AcpiGbl_Optarg)) 216 { 217 exit (-1); 218 } 219 continue; 220 221 case 'r': /* Dump tables from specified RSDP */ 222 223 Status = AcpiUtStrtoul64 (AcpiGbl_Optarg, 0, &Gbl_RsdpBase); 224 if (ACPI_FAILURE (Status)) 225 { 226 fprintf (stderr, "%s: Could not convert to a physical address\n", 227 AcpiGbl_Optarg); 228 exit (-1); 229 } 230 continue; 231 232 case 's': /* Print table summaries only */ 233 234 Gbl_SummaryMode = TRUE; 235 continue; 236 237 case 'v': /* Revision/version */ 238 239 printf (ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); 240 exit (0); 241 242 case 'z': /* Verbose mode */ 243 244 Gbl_VerboseMode = TRUE; 245 fprintf (stderr, ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); 246 continue; 247 248 /* 249 * Table options 250 */ 251 case 'a': /* Get table by physical address */ 252 253 ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_ADDRESS); 254 break; 255 256 case 'f': /* Get table from a file */ 257 258 ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_FILE); 259 break; 260 261 case 'n': /* Get table by input name (signature) */ 262 263 ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_NAME); 264 break; 265 266 default: 267 268 ApDisplayUsage (); 269 exit (-1); 270 } 271 272 /* If there are no actions, this means "get/dump all tables" */ 273 274 if (CurrentAction == 0) 275 { 276 ApInsertAction (NULL, AP_DUMP_ALL_TABLES); 277 } 278 279 return (0); 280 } 281 282 283 /****************************************************************************** 284 * 285 * FUNCTION: main 286 * 287 * PARAMETERS: argc/argv - Standard argc/argv 288 * 289 * RETURN: Status 290 * 291 * DESCRIPTION: C main function for acpidump utility 292 * 293 ******************************************************************************/ 294 295 int ACPI_SYSTEM_XFACE 296 main ( 297 int argc, 298 char *argv[]) 299 { 300 int Status = 0; 301 AP_DUMP_ACTION *Action; 302 UINT32 FileSize; 303 UINT32 i; 304 305 306 ACPI_DEBUG_INITIALIZE (); /* For debug version only */ 307 308 /* Process command line options */ 309 310 if (ApDoOptions (argc, argv)) 311 { 312 return (-1); 313 } 314 315 /* Get/dump ACPI table(s) as requested */ 316 317 for (i = 0; i < CurrentAction; i++) 318 { 319 Action = &ActionTable[i]; 320 switch (Action->ToBeDone) 321 { 322 case AP_DUMP_ALL_TABLES: 323 324 Status = ApDumpAllTables (); 325 break; 326 327 case AP_DUMP_TABLE_BY_ADDRESS: 328 329 Status = ApDumpTableByAddress (Action->Argument); 330 break; 331 332 case AP_DUMP_TABLE_BY_NAME: 333 334 Status = ApDumpTableByName (Action->Argument); 335 break; 336 337 case AP_DUMP_TABLE_BY_FILE: 338 339 Status = ApDumpTableFromFile (Action->Argument); 340 break; 341 342 default: 343 344 fprintf (stderr, "Internal error, invalid action: 0x%X\n", 345 Action->ToBeDone); 346 return (-1); 347 } 348 349 if (Status) 350 { 351 return (Status); 352 } 353 } 354 355 if (Gbl_OutputFile) 356 { 357 if (Gbl_VerboseMode) 358 { 359 /* Summary for the output file */ 360 361 FileSize = ApGetFileSize (Gbl_OutputFile); 362 fprintf (stderr, "Output file %s contains 0x%X (%u) bytes\n\n", 363 Gbl_OutputFilename, FileSize, FileSize); 364 } 365 366 fclose (Gbl_OutputFile); 367 } 368 369 return (Status); 370 }