Home | History | Annotate | Line # | Download | only in acpixtract
axmain.c revision 1.1.1.8
      1 /******************************************************************************
      2  *
      3  * Module Name: axmain - main module for acpixtract utility
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2019, 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 DEFINE_ACPIXTRACT_GLOBALS
     45 #include "acpixtract.h"
     46 
     47 
     48 /* Local prototypes */
     49 
     50 static void
     51 DisplayUsage (
     52     void);
     53 
     54 
     55 /******************************************************************************
     56  *
     57  * FUNCTION:    DisplayUsage
     58  *
     59  * DESCRIPTION: Usage message
     60  *
     61  ******************************************************************************/
     62 
     63 static void
     64 DisplayUsage (
     65     void)
     66 {
     67 
     68     ACPI_USAGE_HEADER ("acpixtract [option] <InputFile>");
     69 
     70     ACPI_OPTION ("-a",                  "Extract all tables, not just DSDT/SSDT");
     71     ACPI_OPTION ("-f",                  "Force extraction, even if there are errors");
     72     ACPI_OPTION ("-l",                  "List table summaries, do not extract");
     73     ACPI_OPTION ("-m",                  "Extract multiple DSDT/SSDTs to a single file");
     74     ACPI_OPTION ("-s <signature>",      "Extract all tables with <signature>");
     75     ACPI_OPTION ("-v",                  "Display version information");
     76     ACPI_OPTION ("-vd",                 "Display build date and time");
     77 
     78     ACPI_USAGE_TEXT ("\nExtract binary ACPI tables from text acpidump output\n");
     79     ACPI_USAGE_TEXT ("Default invocation extracts the DSDT and all SSDTs\n");
     80 }
     81 
     82 
     83 /******************************************************************************
     84  *
     85  * FUNCTION:    main
     86  *
     87  * DESCRIPTION: C main function
     88  *
     89  ******************************************************************************/
     90 
     91 int
     92 main (
     93     int                     argc,
     94     char                    *argv[])
     95 {
     96     char                    *Filename;
     97     int                     AxAction;
     98     int                     Status;
     99     int                     j;
    100 
    101 
    102     Gbl_TableCount = 0;
    103     Gbl_TableListHead = NULL;
    104     Gbl_ForceExtraction = FALSE;
    105     AxAction = AX_EXTRACT_AML_TABLES; /* Default: DSDT & SSDTs */
    106 
    107     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    108     AcpiOsInitialize ();
    109     printf (ACPI_COMMON_SIGNON (AX_UTILITY_NAME));
    110 
    111     if (argc < 2)
    112     {
    113         DisplayUsage ();
    114         return (0);
    115     }
    116 
    117     /* Command line options */
    118 
    119     while ((j = AcpiGetopt (argc, argv, AX_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
    120     {
    121     case 'a':
    122 
    123         AxAction = AX_EXTRACT_ALL;          /* Extract all tables found */
    124         break;
    125 
    126     case 'f':
    127 
    128         Gbl_ForceExtraction = TRUE;           /* Ignore errors */
    129         break;
    130 
    131     case 'l':
    132 
    133         AxAction = AX_LIST_ALL;             /* List tables only, do not extract */
    134         break;
    135 
    136     case 'm':
    137 
    138         AxAction = AX_EXTRACT_MULTI_TABLE;  /* Make single file for all DSDT/SSDTs */
    139         break;
    140 
    141     case 's':
    142 
    143         AxAction = AX_EXTRACT_SIGNATURE;    /* Extract only tables with this sig */
    144         break;
    145 
    146     case 'v':
    147 
    148         switch (AcpiGbl_Optarg[0])
    149         {
    150         case '^':  /* -v: (Version): signon already emitted, just exit */
    151 
    152             exit (0);
    153 
    154         case 'd':
    155 
    156             printf (ACPI_COMMON_BUILD_TIME);
    157             return (0);
    158 
    159         default:
    160 
    161             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
    162             return (-1);
    163         }
    164         break;
    165 
    166     case 'h':
    167     default:
    168 
    169         DisplayUsage ();
    170         return (0);
    171     }
    172 
    173     /* Input filename is always required */
    174 
    175     Filename = argv[AcpiGbl_Optind];
    176     if (!Filename)
    177     {
    178         printf ("Missing required input filename\n");
    179         return (-1);
    180     }
    181 
    182     /* Perform requested action */
    183 
    184     switch (AxAction)
    185     {
    186     case AX_EXTRACT_ALL:
    187 
    188         Status = AxExtractTables (Filename, NULL, AX_OPTIONAL_TABLES);
    189         break;
    190 
    191     case AX_EXTRACT_MULTI_TABLE:
    192 
    193         Status = AxExtractToMultiAmlFile (Filename);
    194         break;
    195 
    196     case AX_LIST_ALL:
    197 
    198         Status = AxListAllTables (Filename);
    199         break;
    200 
    201     case AX_EXTRACT_SIGNATURE:
    202 
    203         Status = AxExtractTables (Filename, AcpiGbl_Optarg, AX_REQUIRED_TABLE);
    204         break;
    205 
    206     default:
    207         /*
    208          * Default output is the DSDT and all SSDTs. One DSDT is required,
    209          * any SSDTs are optional.
    210          */
    211         Status = AxExtractTables (Filename, "DSDT", AX_REQUIRED_TABLE);
    212         if (Status)
    213         {
    214             return (Status);
    215         }
    216 
    217         Status = AxExtractTables (Filename, "SSDT", AX_OPTIONAL_TABLES);
    218         break;
    219     }
    220 
    221     return (Status);
    222 }
    223