1*385cc6b4SJerry Jelinek /****************************************************************************** 2*385cc6b4SJerry Jelinek * 3*385cc6b4SJerry Jelinek * Module Name: acpixtract - convert ascii ACPI tables to binary 4*385cc6b4SJerry Jelinek * 5*385cc6b4SJerry Jelinek *****************************************************************************/ 6*385cc6b4SJerry Jelinek 7*385cc6b4SJerry Jelinek /* 8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp. 9*385cc6b4SJerry Jelinek * All rights reserved. 10*385cc6b4SJerry Jelinek * 11*385cc6b4SJerry Jelinek * Redistribution and use in source and binary forms, with or without 12*385cc6b4SJerry Jelinek * modification, are permitted provided that the following conditions 13*385cc6b4SJerry Jelinek * are met: 14*385cc6b4SJerry Jelinek * 1. Redistributions of source code must retain the above copyright 15*385cc6b4SJerry Jelinek * notice, this list of conditions, and the following disclaimer, 16*385cc6b4SJerry Jelinek * without modification. 17*385cc6b4SJerry Jelinek * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18*385cc6b4SJerry Jelinek * substantially similar to the "NO WARRANTY" disclaimer below 19*385cc6b4SJerry Jelinek * ("Disclaimer") and any redistribution must be conditioned upon 20*385cc6b4SJerry Jelinek * including a substantially similar Disclaimer requirement for further 21*385cc6b4SJerry Jelinek * binary redistribution. 22*385cc6b4SJerry Jelinek * 3. Neither the names of the above-listed copyright holders nor the names 23*385cc6b4SJerry Jelinek * of any contributors may be used to endorse or promote products derived 24*385cc6b4SJerry Jelinek * from this software without specific prior written permission. 25*385cc6b4SJerry Jelinek * 26*385cc6b4SJerry Jelinek * Alternatively, this software may be distributed under the terms of the 27*385cc6b4SJerry Jelinek * GNU General Public License ("GPL") version 2 as published by the Free 28*385cc6b4SJerry Jelinek * Software Foundation. 29*385cc6b4SJerry Jelinek * 30*385cc6b4SJerry Jelinek * NO WARRANTY 31*385cc6b4SJerry Jelinek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32*385cc6b4SJerry Jelinek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33*385cc6b4SJerry Jelinek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34*385cc6b4SJerry Jelinek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35*385cc6b4SJerry Jelinek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36*385cc6b4SJerry Jelinek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37*385cc6b4SJerry Jelinek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38*385cc6b4SJerry Jelinek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39*385cc6b4SJerry Jelinek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40*385cc6b4SJerry Jelinek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41*385cc6b4SJerry Jelinek * POSSIBILITY OF SUCH DAMAGES. 42*385cc6b4SJerry Jelinek */ 43*385cc6b4SJerry Jelinek 44*385cc6b4SJerry Jelinek #include "acpixtract.h" 45*385cc6b4SJerry Jelinek 46*385cc6b4SJerry Jelinek 47*385cc6b4SJerry Jelinek /* Local prototypes */ 48*385cc6b4SJerry Jelinek 49*385cc6b4SJerry Jelinek static BOOLEAN 50*385cc6b4SJerry Jelinek AxIsFileAscii ( 51*385cc6b4SJerry Jelinek FILE *Handle); 52*385cc6b4SJerry Jelinek 53*385cc6b4SJerry Jelinek 54*385cc6b4SJerry Jelinek /****************************************************************************** 55*385cc6b4SJerry Jelinek * 56*385cc6b4SJerry Jelinek * FUNCTION: AxExtractTables 57*385cc6b4SJerry Jelinek * 58*385cc6b4SJerry Jelinek * PARAMETERS: InputPathname - Filename for input acpidump file 59*385cc6b4SJerry Jelinek * Signature - Requested ACPI signature to extract. 60*385cc6b4SJerry Jelinek * NULL means extract ALL tables. 61*385cc6b4SJerry Jelinek * MinimumInstances - Min instances that are acceptable 62*385cc6b4SJerry Jelinek * 63*385cc6b4SJerry Jelinek * RETURN: Status 64*385cc6b4SJerry Jelinek * 65*385cc6b4SJerry Jelinek * DESCRIPTION: Convert text ACPI tables to binary 66*385cc6b4SJerry Jelinek * 67*385cc6b4SJerry Jelinek ******************************************************************************/ 68*385cc6b4SJerry Jelinek 69*385cc6b4SJerry Jelinek int 70*385cc6b4SJerry Jelinek AxExtractTables ( 71*385cc6b4SJerry Jelinek char *InputPathname, 72*385cc6b4SJerry Jelinek char *Signature, 73*385cc6b4SJerry Jelinek unsigned int MinimumInstances) 74*385cc6b4SJerry Jelinek { 75*385cc6b4SJerry Jelinek FILE *InputFile; 76*385cc6b4SJerry Jelinek FILE *OutputFile = NULL; 77*385cc6b4SJerry Jelinek unsigned int BytesConverted; 78*385cc6b4SJerry Jelinek unsigned int ThisTableBytesWritten = 0; 79*385cc6b4SJerry Jelinek unsigned int FoundTable = 0; 80*385cc6b4SJerry Jelinek unsigned int Instances = 0; 81*385cc6b4SJerry Jelinek unsigned int ThisInstance; 82*385cc6b4SJerry Jelinek char ThisSignature[5]; 83*385cc6b4SJerry Jelinek char UpperSignature[5]; 84*385cc6b4SJerry Jelinek int Status = 0; 85*385cc6b4SJerry Jelinek unsigned int State = AX_STATE_FIND_HEADER; 86*385cc6b4SJerry Jelinek 87*385cc6b4SJerry Jelinek 88*385cc6b4SJerry Jelinek /* Open input in text mode, output is in binary mode */ 89*385cc6b4SJerry Jelinek 90*385cc6b4SJerry Jelinek InputFile = fopen (InputPathname, "rt"); 91*385cc6b4SJerry Jelinek if (!InputFile) 92*385cc6b4SJerry Jelinek { 93*385cc6b4SJerry Jelinek printf ("Could not open input file %s\n", InputPathname); 94*385cc6b4SJerry Jelinek return (-1); 95*385cc6b4SJerry Jelinek } 96*385cc6b4SJerry Jelinek 97*385cc6b4SJerry Jelinek if (!AxIsFileAscii (InputFile)) 98*385cc6b4SJerry Jelinek { 99*385cc6b4SJerry Jelinek fclose (InputFile); 100*385cc6b4SJerry Jelinek return (-1); 101*385cc6b4SJerry Jelinek } 102*385cc6b4SJerry Jelinek 103*385cc6b4SJerry Jelinek if (Signature) 104*385cc6b4SJerry Jelinek { 105*385cc6b4SJerry Jelinek strncpy (UpperSignature, Signature, 4); 106*385cc6b4SJerry Jelinek UpperSignature[4] = 0; 107*385cc6b4SJerry Jelinek AcpiUtStrupr (UpperSignature); 108*385cc6b4SJerry Jelinek 109*385cc6b4SJerry Jelinek /* Are there enough instances of the table to continue? */ 110*385cc6b4SJerry Jelinek 111*385cc6b4SJerry Jelinek AxNormalizeSignature (UpperSignature); 112*385cc6b4SJerry Jelinek 113*385cc6b4SJerry Jelinek Instances = AxCountTableInstances (InputPathname, UpperSignature); 114*385cc6b4SJerry Jelinek if (Instances < MinimumInstances) 115*385cc6b4SJerry Jelinek { 116*385cc6b4SJerry Jelinek printf ("Table [%s] was not found in %s\n", 117*385cc6b4SJerry Jelinek UpperSignature, InputPathname); 118*385cc6b4SJerry Jelinek fclose (InputFile); 119*385cc6b4SJerry Jelinek return (-1); 120*385cc6b4SJerry Jelinek } 121*385cc6b4SJerry Jelinek 122*385cc6b4SJerry Jelinek if (Instances == 0) 123*385cc6b4SJerry Jelinek { 124*385cc6b4SJerry Jelinek fclose (InputFile); 125*385cc6b4SJerry Jelinek return (-1); 126*385cc6b4SJerry Jelinek } 127*385cc6b4SJerry Jelinek } 128*385cc6b4SJerry Jelinek 129*385cc6b4SJerry Jelinek /* Convert all instances of the table to binary */ 130*385cc6b4SJerry Jelinek 131*385cc6b4SJerry Jelinek while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) 132*385cc6b4SJerry Jelinek { 133*385cc6b4SJerry Jelinek switch (State) 134*385cc6b4SJerry Jelinek { 135*385cc6b4SJerry Jelinek case AX_STATE_FIND_HEADER: 136*385cc6b4SJerry Jelinek 137*385cc6b4SJerry Jelinek if (!AxIsDataBlockHeader ()) 138*385cc6b4SJerry Jelinek { 139*385cc6b4SJerry Jelinek continue; 140*385cc6b4SJerry Jelinek } 141*385cc6b4SJerry Jelinek 142*385cc6b4SJerry Jelinek ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer); 143*385cc6b4SJerry Jelinek if (Signature) 144*385cc6b4SJerry Jelinek { 145*385cc6b4SJerry Jelinek /* Ignore signatures that don't match */ 146*385cc6b4SJerry Jelinek 147*385cc6b4SJerry Jelinek if (!ACPI_COMPARE_NAME (ThisSignature, UpperSignature)) 148*385cc6b4SJerry Jelinek { 149*385cc6b4SJerry Jelinek continue; 150*385cc6b4SJerry Jelinek } 151*385cc6b4SJerry Jelinek } 152*385cc6b4SJerry Jelinek 153*385cc6b4SJerry Jelinek /* 154*385cc6b4SJerry Jelinek * Get the instance number for this signature. Only the 155*385cc6b4SJerry Jelinek * SSDT and PSDT tables can have multiple instances. 156*385cc6b4SJerry Jelinek */ 157*385cc6b4SJerry Jelinek ThisInstance = AxGetNextInstance (InputPathname, ThisSignature); 158*385cc6b4SJerry Jelinek 159*385cc6b4SJerry Jelinek /* Build an output filename and create/open the output file */ 160*385cc6b4SJerry Jelinek 161*385cc6b4SJerry Jelinek if (ThisInstance > 0) 162*385cc6b4SJerry Jelinek { 163*385cc6b4SJerry Jelinek /* Add instance number to the output filename */ 164*385cc6b4SJerry Jelinek 165*385cc6b4SJerry Jelinek sprintf (Gbl_OutputFilename, "%4.4s%u.dat", 166*385cc6b4SJerry Jelinek ThisSignature, ThisInstance); 167*385cc6b4SJerry Jelinek } 168*385cc6b4SJerry Jelinek else 169*385cc6b4SJerry Jelinek { 170*385cc6b4SJerry Jelinek sprintf (Gbl_OutputFilename, "%4.4s.dat", 171*385cc6b4SJerry Jelinek ThisSignature); 172*385cc6b4SJerry Jelinek } 173*385cc6b4SJerry Jelinek 174*385cc6b4SJerry Jelinek AcpiUtStrlwr (Gbl_OutputFilename); 175*385cc6b4SJerry Jelinek OutputFile = fopen (Gbl_OutputFilename, "w+b"); 176*385cc6b4SJerry Jelinek if (!OutputFile) 177*385cc6b4SJerry Jelinek { 178*385cc6b4SJerry Jelinek printf ("Could not open output file %s\n", 179*385cc6b4SJerry Jelinek Gbl_OutputFilename); 180*385cc6b4SJerry Jelinek fclose (InputFile); 181*385cc6b4SJerry Jelinek return (-1); 182*385cc6b4SJerry Jelinek } 183*385cc6b4SJerry Jelinek 184*385cc6b4SJerry Jelinek /* 185*385cc6b4SJerry Jelinek * Toss this block header of the form "<sig> @ <addr>" line 186*385cc6b4SJerry Jelinek * and move on to the actual data block 187*385cc6b4SJerry Jelinek */ 188*385cc6b4SJerry Jelinek Gbl_TableCount++; 189*385cc6b4SJerry Jelinek FoundTable = 1; 190*385cc6b4SJerry Jelinek ThisTableBytesWritten = 0; 191*385cc6b4SJerry Jelinek State = AX_STATE_EXTRACT_DATA; 192*385cc6b4SJerry Jelinek continue; 193*385cc6b4SJerry Jelinek 194*385cc6b4SJerry Jelinek case AX_STATE_EXTRACT_DATA: 195*385cc6b4SJerry Jelinek 196*385cc6b4SJerry Jelinek /* Empty line or non-data line terminates the data block */ 197*385cc6b4SJerry Jelinek 198*385cc6b4SJerry Jelinek BytesConverted = AxProcessOneTextLine ( 199*385cc6b4SJerry Jelinek OutputFile, ThisSignature, ThisTableBytesWritten); 200*385cc6b4SJerry Jelinek switch (BytesConverted) 201*385cc6b4SJerry Jelinek { 202*385cc6b4SJerry Jelinek case 0: 203*385cc6b4SJerry Jelinek 204*385cc6b4SJerry Jelinek State = AX_STATE_FIND_HEADER; /* No more data block lines */ 205*385cc6b4SJerry Jelinek continue; 206*385cc6b4SJerry Jelinek 207*385cc6b4SJerry Jelinek case -1: 208*385cc6b4SJerry Jelinek 209*385cc6b4SJerry Jelinek goto CleanupAndExit; /* There was a write error */ 210*385cc6b4SJerry Jelinek 211*385cc6b4SJerry Jelinek default: /* Normal case, get next line */ 212*385cc6b4SJerry Jelinek 213*385cc6b4SJerry Jelinek ThisTableBytesWritten += BytesConverted; 214*385cc6b4SJerry Jelinek continue; 215*385cc6b4SJerry Jelinek } 216*385cc6b4SJerry Jelinek 217*385cc6b4SJerry Jelinek default: 218*385cc6b4SJerry Jelinek 219*385cc6b4SJerry Jelinek Status = -1; 220*385cc6b4SJerry Jelinek goto CleanupAndExit; 221*385cc6b4SJerry Jelinek } 222*385cc6b4SJerry Jelinek } 223*385cc6b4SJerry Jelinek 224*385cc6b4SJerry Jelinek if (!FoundTable) 225*385cc6b4SJerry Jelinek { 226*385cc6b4SJerry Jelinek printf ("No ACPI tables were found in %s\n", InputPathname); 227*385cc6b4SJerry Jelinek } 228*385cc6b4SJerry Jelinek 229*385cc6b4SJerry Jelinek 230*385cc6b4SJerry Jelinek CleanupAndExit: 231*385cc6b4SJerry Jelinek 232*385cc6b4SJerry Jelinek if (State == AX_STATE_EXTRACT_DATA) 233*385cc6b4SJerry Jelinek { 234*385cc6b4SJerry Jelinek /* Received an input file EOF while extracting data */ 235*385cc6b4SJerry Jelinek 236*385cc6b4SJerry Jelinek printf (AX_TABLE_INFO_FORMAT, 237*385cc6b4SJerry Jelinek ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename); 238*385cc6b4SJerry Jelinek } 239*385cc6b4SJerry Jelinek 240*385cc6b4SJerry Jelinek if (Gbl_TableCount > 1) 241*385cc6b4SJerry Jelinek { 242*385cc6b4SJerry Jelinek printf ("\n%u binary ACPI tables extracted\n", 243*385cc6b4SJerry Jelinek Gbl_TableCount); 244*385cc6b4SJerry Jelinek } 245*385cc6b4SJerry Jelinek 246*385cc6b4SJerry Jelinek if (OutputFile) 247*385cc6b4SJerry Jelinek { 248*385cc6b4SJerry Jelinek fclose (OutputFile); 249*385cc6b4SJerry Jelinek } 250*385cc6b4SJerry Jelinek 251*385cc6b4SJerry Jelinek fclose (InputFile); 252*385cc6b4SJerry Jelinek return (Status); 253*385cc6b4SJerry Jelinek } 254*385cc6b4SJerry Jelinek 255*385cc6b4SJerry Jelinek 256*385cc6b4SJerry Jelinek /****************************************************************************** 257*385cc6b4SJerry Jelinek * 258*385cc6b4SJerry Jelinek * FUNCTION: AxExtractToMultiAmlFile 259*385cc6b4SJerry Jelinek * 260*385cc6b4SJerry Jelinek * PARAMETERS: InputPathname - Filename for input acpidump file 261*385cc6b4SJerry Jelinek * 262*385cc6b4SJerry Jelinek * RETURN: Status 263*385cc6b4SJerry Jelinek * 264*385cc6b4SJerry Jelinek * DESCRIPTION: Convert all DSDT/SSDT tables to binary and append them all 265*385cc6b4SJerry Jelinek * into a single output file. Used to simplify the loading of 266*385cc6b4SJerry Jelinek * multiple/many SSDTs into a utility like acpiexec -- instead 267*385cc6b4SJerry Jelinek * of creating many separate output files. 268*385cc6b4SJerry Jelinek * 269*385cc6b4SJerry Jelinek ******************************************************************************/ 270*385cc6b4SJerry Jelinek 271*385cc6b4SJerry Jelinek int 272*385cc6b4SJerry Jelinek AxExtractToMultiAmlFile ( 273*385cc6b4SJerry Jelinek char *InputPathname) 274*385cc6b4SJerry Jelinek { 275*385cc6b4SJerry Jelinek FILE *InputFile; 276*385cc6b4SJerry Jelinek FILE *OutputFile; 277*385cc6b4SJerry Jelinek int Status = 0; 278*385cc6b4SJerry Jelinek unsigned int TotalBytesWritten = 0; 279*385cc6b4SJerry Jelinek unsigned int ThisTableBytesWritten = 0; 280*385cc6b4SJerry Jelinek unsigned int BytesConverted; 281*385cc6b4SJerry Jelinek char ThisSignature[4]; 282*385cc6b4SJerry Jelinek unsigned int State = AX_STATE_FIND_HEADER; 283*385cc6b4SJerry Jelinek 284*385cc6b4SJerry Jelinek 285*385cc6b4SJerry Jelinek strcpy (Gbl_OutputFilename, AX_MULTI_TABLE_FILENAME); 286*385cc6b4SJerry Jelinek 287*385cc6b4SJerry Jelinek /* Open the input file in text mode */ 288*385cc6b4SJerry Jelinek 289*385cc6b4SJerry Jelinek InputFile = fopen (InputPathname, "rt"); 290*385cc6b4SJerry Jelinek if (!InputFile) 291*385cc6b4SJerry Jelinek { 292*385cc6b4SJerry Jelinek printf ("Could not open input file %s\n", InputPathname); 293*385cc6b4SJerry Jelinek return (-1); 294*385cc6b4SJerry Jelinek } 295*385cc6b4SJerry Jelinek 296*385cc6b4SJerry Jelinek if (!AxIsFileAscii (InputFile)) 297*385cc6b4SJerry Jelinek { 298*385cc6b4SJerry Jelinek fclose (InputFile); 299*385cc6b4SJerry Jelinek return (-1); 300*385cc6b4SJerry Jelinek } 301*385cc6b4SJerry Jelinek 302*385cc6b4SJerry Jelinek /* Open the output file in binary mode */ 303*385cc6b4SJerry Jelinek 304*385cc6b4SJerry Jelinek OutputFile = fopen (Gbl_OutputFilename, "w+b"); 305*385cc6b4SJerry Jelinek if (!OutputFile) 306*385cc6b4SJerry Jelinek { 307*385cc6b4SJerry Jelinek printf ("Could not open output file %s\n", Gbl_OutputFilename); 308*385cc6b4SJerry Jelinek fclose (InputFile); 309*385cc6b4SJerry Jelinek return (-1); 310*385cc6b4SJerry Jelinek } 311*385cc6b4SJerry Jelinek 312*385cc6b4SJerry Jelinek /* Convert the DSDT and all SSDTs to binary */ 313*385cc6b4SJerry Jelinek 314*385cc6b4SJerry Jelinek while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) 315*385cc6b4SJerry Jelinek { 316*385cc6b4SJerry Jelinek switch (State) 317*385cc6b4SJerry Jelinek { 318*385cc6b4SJerry Jelinek case AX_STATE_FIND_HEADER: 319*385cc6b4SJerry Jelinek 320*385cc6b4SJerry Jelinek if (!AxIsDataBlockHeader ()) 321*385cc6b4SJerry Jelinek { 322*385cc6b4SJerry Jelinek continue; 323*385cc6b4SJerry Jelinek } 324*385cc6b4SJerry Jelinek 325*385cc6b4SJerry Jelinek ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer); 326*385cc6b4SJerry Jelinek 327*385cc6b4SJerry Jelinek /* Only want DSDT and SSDTs */ 328*385cc6b4SJerry Jelinek 329*385cc6b4SJerry Jelinek if (!ACPI_COMPARE_NAME (ThisSignature, ACPI_SIG_DSDT) && 330*385cc6b4SJerry Jelinek !ACPI_COMPARE_NAME (ThisSignature, ACPI_SIG_SSDT)) 331*385cc6b4SJerry Jelinek { 332*385cc6b4SJerry Jelinek continue; 333*385cc6b4SJerry Jelinek } 334*385cc6b4SJerry Jelinek 335*385cc6b4SJerry Jelinek /* 336*385cc6b4SJerry Jelinek * Toss this block header of the form "<sig> @ <addr>" line 337*385cc6b4SJerry Jelinek * and move on to the actual data block 338*385cc6b4SJerry Jelinek */ 339*385cc6b4SJerry Jelinek Gbl_TableCount++; 340*385cc6b4SJerry Jelinek ThisTableBytesWritten = 0; 341*385cc6b4SJerry Jelinek State = AX_STATE_EXTRACT_DATA; 342*385cc6b4SJerry Jelinek continue; 343*385cc6b4SJerry Jelinek 344*385cc6b4SJerry Jelinek case AX_STATE_EXTRACT_DATA: 345*385cc6b4SJerry Jelinek 346*385cc6b4SJerry Jelinek /* Empty line or non-data line terminates the data block */ 347*385cc6b4SJerry Jelinek 348*385cc6b4SJerry Jelinek BytesConverted = AxProcessOneTextLine ( 349*385cc6b4SJerry Jelinek OutputFile, ThisSignature, ThisTableBytesWritten); 350*385cc6b4SJerry Jelinek switch (BytesConverted) 351*385cc6b4SJerry Jelinek { 352*385cc6b4SJerry Jelinek case 0: 353*385cc6b4SJerry Jelinek 354*385cc6b4SJerry Jelinek State = AX_STATE_FIND_HEADER; /* No more data block lines */ 355*385cc6b4SJerry Jelinek continue; 356*385cc6b4SJerry Jelinek 357*385cc6b4SJerry Jelinek case -1: 358*385cc6b4SJerry Jelinek 359*385cc6b4SJerry Jelinek goto CleanupAndExit; /* There was a write error */ 360*385cc6b4SJerry Jelinek 361*385cc6b4SJerry Jelinek default: /* Normal case, get next line */ 362*385cc6b4SJerry Jelinek 363*385cc6b4SJerry Jelinek ThisTableBytesWritten += BytesConverted; 364*385cc6b4SJerry Jelinek TotalBytesWritten += BytesConverted; 365*385cc6b4SJerry Jelinek continue; 366*385cc6b4SJerry Jelinek } 367*385cc6b4SJerry Jelinek 368*385cc6b4SJerry Jelinek default: 369*385cc6b4SJerry Jelinek 370*385cc6b4SJerry Jelinek Status = -1; 371*385cc6b4SJerry Jelinek goto CleanupAndExit; 372*385cc6b4SJerry Jelinek } 373*385cc6b4SJerry Jelinek } 374*385cc6b4SJerry Jelinek 375*385cc6b4SJerry Jelinek 376*385cc6b4SJerry Jelinek CleanupAndExit: 377*385cc6b4SJerry Jelinek 378*385cc6b4SJerry Jelinek if (State == AX_STATE_EXTRACT_DATA) 379*385cc6b4SJerry Jelinek { 380*385cc6b4SJerry Jelinek /* Received an input file EOF or error while writing data */ 381*385cc6b4SJerry Jelinek 382*385cc6b4SJerry Jelinek printf (AX_TABLE_INFO_FORMAT, 383*385cc6b4SJerry Jelinek ThisSignature, ThisTableBytesWritten, Gbl_OutputFilename); 384*385cc6b4SJerry Jelinek } 385*385cc6b4SJerry Jelinek 386*385cc6b4SJerry Jelinek printf ("\n%u binary ACPI tables extracted and written to %s (%u bytes)\n", 387*385cc6b4SJerry Jelinek Gbl_TableCount, Gbl_OutputFilename, TotalBytesWritten); 388*385cc6b4SJerry Jelinek 389*385cc6b4SJerry Jelinek fclose (InputFile); 390*385cc6b4SJerry Jelinek fclose (OutputFile); 391*385cc6b4SJerry Jelinek return (Status); 392*385cc6b4SJerry Jelinek } 393*385cc6b4SJerry Jelinek 394*385cc6b4SJerry Jelinek 395*385cc6b4SJerry Jelinek /****************************************************************************** 396*385cc6b4SJerry Jelinek * 397*385cc6b4SJerry Jelinek * FUNCTION: AxListTables 398*385cc6b4SJerry Jelinek * 399*385cc6b4SJerry Jelinek * PARAMETERS: InputPathname - Filename for acpidump file 400*385cc6b4SJerry Jelinek * 401*385cc6b4SJerry Jelinek * RETURN: Status 402*385cc6b4SJerry Jelinek * 403*385cc6b4SJerry Jelinek * DESCRIPTION: Display info for all ACPI tables found in input. Does not 404*385cc6b4SJerry Jelinek * perform an actual extraction of the tables. 405*385cc6b4SJerry Jelinek * 406*385cc6b4SJerry Jelinek ******************************************************************************/ 407*385cc6b4SJerry Jelinek 408*385cc6b4SJerry Jelinek int 409*385cc6b4SJerry Jelinek AxListTables ( 410*385cc6b4SJerry Jelinek char *InputPathname) 411*385cc6b4SJerry Jelinek { 412*385cc6b4SJerry Jelinek FILE *InputFile; 413*385cc6b4SJerry Jelinek size_t HeaderSize; 414*385cc6b4SJerry Jelinek unsigned char Header[48]; 415*385cc6b4SJerry Jelinek ACPI_TABLE_HEADER *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header; 416*385cc6b4SJerry Jelinek 417*385cc6b4SJerry Jelinek 418*385cc6b4SJerry Jelinek /* Open input in text mode, output is in binary mode */ 419*385cc6b4SJerry Jelinek 420*385cc6b4SJerry Jelinek InputFile = fopen (InputPathname, "rt"); 421*385cc6b4SJerry Jelinek if (!InputFile) 422*385cc6b4SJerry Jelinek { 423*385cc6b4SJerry Jelinek printf ("Could not open input file %s\n", InputPathname); 424*385cc6b4SJerry Jelinek return (-1); 425*385cc6b4SJerry Jelinek } 426*385cc6b4SJerry Jelinek 427*385cc6b4SJerry Jelinek if (!AxIsFileAscii (InputFile)) 428*385cc6b4SJerry Jelinek { 429*385cc6b4SJerry Jelinek fclose (InputFile); 430*385cc6b4SJerry Jelinek return (-1); 431*385cc6b4SJerry Jelinek } 432*385cc6b4SJerry Jelinek 433*385cc6b4SJerry Jelinek /* Dump the headers for all tables found in the input file */ 434*385cc6b4SJerry Jelinek 435*385cc6b4SJerry Jelinek printf ("\nSignature Length Revision OemId OemTableId" 436*385cc6b4SJerry Jelinek " OemRevision CompilerId CompilerRevision\n\n"); 437*385cc6b4SJerry Jelinek 438*385cc6b4SJerry Jelinek while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) 439*385cc6b4SJerry Jelinek { 440*385cc6b4SJerry Jelinek /* Ignore empty lines and lines that start with a space */ 441*385cc6b4SJerry Jelinek 442*385cc6b4SJerry Jelinek if (AxIsEmptyLine (Gbl_LineBuffer) || 443*385cc6b4SJerry Jelinek (Gbl_LineBuffer[0] == ' ')) 444*385cc6b4SJerry Jelinek { 445*385cc6b4SJerry Jelinek continue; 446*385cc6b4SJerry Jelinek } 447*385cc6b4SJerry Jelinek 448*385cc6b4SJerry Jelinek /* Get the 36 byte header and display the fields */ 449*385cc6b4SJerry Jelinek 450*385cc6b4SJerry Jelinek HeaderSize = AxGetTableHeader (InputFile, Header); 451*385cc6b4SJerry Jelinek if (HeaderSize < 16) 452*385cc6b4SJerry Jelinek { 453*385cc6b4SJerry Jelinek continue; 454*385cc6b4SJerry Jelinek } 455*385cc6b4SJerry Jelinek 456*385cc6b4SJerry Jelinek /* RSDP has an oddball signature and header */ 457*385cc6b4SJerry Jelinek 458*385cc6b4SJerry Jelinek if (!strncmp (TableHeader->Signature, "RSD PTR ", 8)) 459*385cc6b4SJerry Jelinek { 460*385cc6b4SJerry Jelinek AxCheckAscii ((char *) &Header[9], 6); 461*385cc6b4SJerry Jelinek printf ("%7.4s \"%6.6s\"\n", "RSDP", 462*385cc6b4SJerry Jelinek &Header[9]); 463*385cc6b4SJerry Jelinek Gbl_TableCount++; 464*385cc6b4SJerry Jelinek continue; 465*385cc6b4SJerry Jelinek } 466*385cc6b4SJerry Jelinek 467*385cc6b4SJerry Jelinek /* Minimum size for table with standard header */ 468*385cc6b4SJerry Jelinek 469*385cc6b4SJerry Jelinek if (HeaderSize < sizeof (ACPI_TABLE_HEADER)) 470*385cc6b4SJerry Jelinek { 471*385cc6b4SJerry Jelinek continue; 472*385cc6b4SJerry Jelinek } 473*385cc6b4SJerry Jelinek 474*385cc6b4SJerry Jelinek if (!AcpiUtValidNameseg (TableHeader->Signature)) 475*385cc6b4SJerry Jelinek { 476*385cc6b4SJerry Jelinek continue; 477*385cc6b4SJerry Jelinek } 478*385cc6b4SJerry Jelinek 479*385cc6b4SJerry Jelinek /* Signature and Table length */ 480*385cc6b4SJerry Jelinek 481*385cc6b4SJerry Jelinek Gbl_TableCount++; 482*385cc6b4SJerry Jelinek printf ("%7.4s 0x%8.8X", TableHeader->Signature, 483*385cc6b4SJerry Jelinek TableHeader->Length); 484*385cc6b4SJerry Jelinek 485*385cc6b4SJerry Jelinek /* FACS has only signature and length */ 486*385cc6b4SJerry Jelinek 487*385cc6b4SJerry Jelinek if (ACPI_COMPARE_NAME (TableHeader->Signature, "FACS")) 488*385cc6b4SJerry Jelinek { 489*385cc6b4SJerry Jelinek printf ("\n"); 490*385cc6b4SJerry Jelinek continue; 491*385cc6b4SJerry Jelinek } 492*385cc6b4SJerry Jelinek 493*385cc6b4SJerry Jelinek /* OEM IDs and Compiler IDs */ 494*385cc6b4SJerry Jelinek 495*385cc6b4SJerry Jelinek AxCheckAscii (TableHeader->OemId, 6); 496*385cc6b4SJerry Jelinek AxCheckAscii (TableHeader->OemTableId, 8); 497*385cc6b4SJerry Jelinek AxCheckAscii (TableHeader->AslCompilerId, 4); 498*385cc6b4SJerry Jelinek 499*385cc6b4SJerry Jelinek printf ( 500*385cc6b4SJerry Jelinek " 0x%2.2X \"%6.6s\" \"%8.8s\" 0x%8.8X" 501*385cc6b4SJerry Jelinek " \"%4.4s\" 0x%8.8X\n", 502*385cc6b4SJerry Jelinek TableHeader->Revision, TableHeader->OemId, 503*385cc6b4SJerry Jelinek TableHeader->OemTableId, TableHeader->OemRevision, 504*385cc6b4SJerry Jelinek TableHeader->AslCompilerId, TableHeader->AslCompilerRevision); 505*385cc6b4SJerry Jelinek } 506*385cc6b4SJerry Jelinek 507*385cc6b4SJerry Jelinek printf ("\nFound %u ACPI tables in %s\n", Gbl_TableCount, InputPathname); 508*385cc6b4SJerry Jelinek fclose (InputFile); 509*385cc6b4SJerry Jelinek return (0); 510*385cc6b4SJerry Jelinek } 511*385cc6b4SJerry Jelinek 512*385cc6b4SJerry Jelinek 513*385cc6b4SJerry Jelinek /******************************************************************************* 514*385cc6b4SJerry Jelinek * 515*385cc6b4SJerry Jelinek * FUNCTION: AxIsFileAscii 516*385cc6b4SJerry Jelinek * 517*385cc6b4SJerry Jelinek * PARAMETERS: Handle - To open input file 518*385cc6b4SJerry Jelinek * 519*385cc6b4SJerry Jelinek * RETURN: TRUE if file is entirely ASCII and printable 520*385cc6b4SJerry Jelinek * 521*385cc6b4SJerry Jelinek * DESCRIPTION: Verify that the input file is entirely ASCII. 522*385cc6b4SJerry Jelinek * 523*385cc6b4SJerry Jelinek ******************************************************************************/ 524*385cc6b4SJerry Jelinek 525*385cc6b4SJerry Jelinek static BOOLEAN 526*385cc6b4SJerry Jelinek AxIsFileAscii ( 527*385cc6b4SJerry Jelinek FILE *Handle) 528*385cc6b4SJerry Jelinek { 529*385cc6b4SJerry Jelinek UINT8 Byte; 530*385cc6b4SJerry Jelinek 531*385cc6b4SJerry Jelinek 532*385cc6b4SJerry Jelinek /* Read the entire file */ 533*385cc6b4SJerry Jelinek 534*385cc6b4SJerry Jelinek while (fread (&Byte, 1, 1, Handle) == 1) 535*385cc6b4SJerry Jelinek { 536*385cc6b4SJerry Jelinek /* Check for an ASCII character */ 537*385cc6b4SJerry Jelinek 538*385cc6b4SJerry Jelinek if (!ACPI_IS_ASCII (Byte)) 539*385cc6b4SJerry Jelinek { 540*385cc6b4SJerry Jelinek goto ErrorExit; 541*385cc6b4SJerry Jelinek } 542*385cc6b4SJerry Jelinek 543*385cc6b4SJerry Jelinek /* Ensure character is either printable or a "space" char */ 544*385cc6b4SJerry Jelinek 545*385cc6b4SJerry Jelinek else if (!isprint (Byte) && !isspace (Byte)) 546*385cc6b4SJerry Jelinek { 547*385cc6b4SJerry Jelinek goto ErrorExit; 548*385cc6b4SJerry Jelinek } 549*385cc6b4SJerry Jelinek } 550*385cc6b4SJerry Jelinek 551*385cc6b4SJerry Jelinek /* File is OK (100% ASCII) */ 552*385cc6b4SJerry Jelinek 553*385cc6b4SJerry Jelinek fseek (Handle, 0, SEEK_SET); 554*385cc6b4SJerry Jelinek return (TRUE); 555*385cc6b4SJerry Jelinek 556*385cc6b4SJerry Jelinek ErrorExit: 557*385cc6b4SJerry Jelinek 558*385cc6b4SJerry Jelinek printf ("File is binary (contains non-text or non-ascii characters)\n"); 559*385cc6b4SJerry Jelinek fseek (Handle, 0, SEEK_SET); 560*385cc6b4SJerry Jelinek return (FALSE); 561*385cc6b4SJerry Jelinek 562*385cc6b4SJerry Jelinek } 563