Home | History | Annotate | Line # | Download | only in acpibin
abmain.c revision 1.1.1.8
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: abmain - Main module for the acpi binary utility
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7      1.1    jruoho /*
      8  1.1.1.7  christos  * Copyright (C) 2000 - 2017, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11      1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1    jruoho  * modification, are permitted provided that the following conditions
     13      1.1    jruoho  * are met:
     14      1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1    jruoho  *    without modification.
     17      1.1    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1    jruoho  *    binary redistribution.
     22      1.1    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1    jruoho  *    from this software without specific prior written permission.
     25      1.1    jruoho  *
     26      1.1    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1    jruoho  * Software Foundation.
     29      1.1    jruoho  *
     30      1.1    jruoho  * NO WARRANTY
     31      1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1    jruoho  */
     43      1.1    jruoho 
     44      1.1    jruoho #define _DECLARE_GLOBALS
     45      1.1    jruoho #include "acpibin.h"
     46      1.1    jruoho 
     47      1.1    jruoho /* Local prototypes */
     48      1.1    jruoho 
     49      1.1    jruoho static void
     50      1.1    jruoho AbDisplayUsage (
     51      1.1    jruoho     UINT8                   OptionCount);
     52      1.1    jruoho 
     53      1.1    jruoho 
     54  1.1.1.2  christos #define AB_UTILITY_NAME             "ACPI Binary Table Dump Utility"
     55  1.1.1.8  christos #define AB_SUPPORTED_OPTIONS        "a:c:d:h:o:s:tv^"
     56  1.1.1.2  christos 
     57  1.1.1.2  christos 
     58      1.1    jruoho /******************************************************************************
     59      1.1    jruoho  *
     60      1.1    jruoho  * FUNCTION:    AbDisplayUsage
     61      1.1    jruoho  *
     62      1.1    jruoho  * DESCRIPTION: Usage message
     63      1.1    jruoho  *
     64      1.1    jruoho  ******************************************************************************/
     65      1.1    jruoho 
     66      1.1    jruoho static void
     67      1.1    jruoho AbDisplayUsage (
     68      1.1    jruoho     UINT8                   OptionCount)
     69      1.1    jruoho {
     70      1.1    jruoho 
     71      1.1    jruoho     if (OptionCount)
     72      1.1    jruoho     {
     73      1.1    jruoho         printf ("Option requires %u arguments\n\n", OptionCount);
     74      1.1    jruoho     }
     75      1.1    jruoho 
     76  1.1.1.2  christos     ACPI_USAGE_HEADER ("acpibin [options]");
     77      1.1    jruoho 
     78  1.1.1.7  christos     ACPI_OPTION ("-a <File1> <File2>",      "Compare two binary AML files, dump all mismatches");
     79  1.1.1.7  christos     ACPI_OPTION ("-c <File1> <File2>",      "Compare two binary AML files, dump first 100 mismatches");
     80  1.1.1.5  christos     ACPI_OPTION ("-d <In> <Out>",           "Dump AML binary to text file");
     81  1.1.1.5  christos     ACPI_OPTION ("-e <Sig> <In> <Out>",     "Extract binary AML table from acpidump file");
     82  1.1.1.7  christos     ACPI_OPTION ("-o <Value>",              "Start comparison at this offset into second file");
     83  1.1.1.2  christos     ACPI_OPTION ("-h <File>",               "Display table header for binary AML file");
     84  1.1.1.2  christos     ACPI_OPTION ("-s <File>",               "Update checksum for binary AML file");
     85  1.1.1.2  christos     ACPI_OPTION ("-t",                      "Terse mode");
     86  1.1.1.2  christos     ACPI_OPTION ("-v",                      "Display version information");
     87  1.1.1.8  christos     ACPI_OPTION ("-vd",                     "Display build date and time");
     88      1.1    jruoho }
     89      1.1    jruoho 
     90      1.1    jruoho 
     91      1.1    jruoho /******************************************************************************
     92      1.1    jruoho  *
     93      1.1    jruoho  * FUNCTION:    main
     94      1.1    jruoho  *
     95      1.1    jruoho  * DESCRIPTION: C main function
     96      1.1    jruoho  *
     97      1.1    jruoho  ******************************************************************************/
     98      1.1    jruoho 
     99      1.1    jruoho int ACPI_SYSTEM_XFACE
    100      1.1    jruoho main (
    101      1.1    jruoho     int                     argc,
    102      1.1    jruoho     char                    *argv[])
    103      1.1    jruoho {
    104      1.1    jruoho     int                     j;
    105      1.1    jruoho     int                     Status = AE_OK;
    106      1.1    jruoho 
    107      1.1    jruoho 
    108  1.1.1.2  christos     ACPI_DEBUG_INITIALIZE (); /* For debug version only */
    109  1.1.1.2  christos 
    110      1.1    jruoho     AcpiGbl_DebugFile = NULL;
    111  1.1.1.2  christos     AcpiGbl_DbOutputFlags = DB_CONSOLE_OUTPUT;
    112      1.1    jruoho 
    113      1.1    jruoho     AcpiOsInitialize ();
    114  1.1.1.2  christos     printf (ACPI_COMMON_SIGNON (AB_UTILITY_NAME));
    115      1.1    jruoho 
    116      1.1    jruoho     if (argc < 2)
    117      1.1    jruoho     {
    118      1.1    jruoho         AbDisplayUsage (0);
    119  1.1.1.2  christos         return (0);
    120      1.1    jruoho     }
    121      1.1    jruoho 
    122      1.1    jruoho     /* Command line options */
    123      1.1    jruoho 
    124  1.1.1.3  christos     while ((j = AcpiGetopt (argc, argv, AB_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch(j)
    125      1.1    jruoho     {
    126  1.1.1.7  christos     case 'a':   /* Compare Files, display all differences */
    127  1.1.1.7  christos 
    128  1.1.1.7  christos         AbGbl_DisplayAllMiscompares = TRUE;
    129  1.1.1.7  christos 
    130  1.1.1.7  christos         /* Fallthrough */
    131  1.1.1.7  christos 
    132      1.1    jruoho     case 'c':   /* Compare Files */
    133      1.1    jruoho 
    134      1.1    jruoho         if (argc < 4)
    135      1.1    jruoho         {
    136      1.1    jruoho             AbDisplayUsage (2);
    137  1.1.1.2  christos             return (-1);
    138      1.1    jruoho         }
    139      1.1    jruoho 
    140      1.1    jruoho         Status = AbCompareAmlFiles (AcpiGbl_Optarg, argv[AcpiGbl_Optind]);
    141      1.1    jruoho         break;
    142      1.1    jruoho 
    143      1.1    jruoho     case 'd':   /* Dump AML file */
    144      1.1    jruoho 
    145      1.1    jruoho         if (argc < 4)
    146      1.1    jruoho         {
    147      1.1    jruoho             AbDisplayUsage (2);
    148  1.1.1.2  christos             return (-1);
    149      1.1    jruoho         }
    150      1.1    jruoho 
    151      1.1    jruoho         Status = AbDumpAmlFile (AcpiGbl_Optarg, argv[AcpiGbl_Optind]);
    152      1.1    jruoho         break;
    153      1.1    jruoho 
    154      1.1    jruoho     case 'h':   /* Display ACPI table header */
    155      1.1    jruoho 
    156      1.1    jruoho         if (argc < 3)
    157      1.1    jruoho         {
    158      1.1    jruoho             AbDisplayUsage (1);
    159  1.1.1.2  christos             return (-1);
    160      1.1    jruoho         }
    161      1.1    jruoho 
    162      1.1    jruoho         AbDisplayHeader (AcpiGbl_Optarg);
    163      1.1    jruoho         return (0);
    164      1.1    jruoho 
    165  1.1.1.7  christos     case 'o':
    166  1.1.1.7  christos 
    167  1.1.1.7  christos         AbGbl_CompareOffset = atoi (AcpiGbl_Optarg);
    168  1.1.1.7  christos         continue;
    169  1.1.1.7  christos 
    170      1.1    jruoho     case 's':   /* Compute/update checksum */
    171      1.1    jruoho 
    172      1.1    jruoho         if (argc < 3)
    173      1.1    jruoho         {
    174      1.1    jruoho             AbDisplayUsage (1);
    175  1.1.1.2  christos             return (-1);
    176      1.1    jruoho         }
    177      1.1    jruoho 
    178      1.1    jruoho         AbComputeChecksum (AcpiGbl_Optarg);
    179      1.1    jruoho         return (0);
    180      1.1    jruoho 
    181      1.1    jruoho     case 't':   /* Enable terse mode */
    182      1.1    jruoho 
    183      1.1    jruoho         Gbl_TerseMode = TRUE;
    184      1.1    jruoho         break;
    185      1.1    jruoho 
    186  1.1.1.2  christos     case 'v': /* -v: (Version): signon already emitted, just exit */
    187  1.1.1.2  christos 
    188  1.1.1.8  christos         switch (AcpiGbl_Optarg[0])
    189  1.1.1.8  christos         {
    190  1.1.1.8  christos         case '^':  /* -v: (Version): signon already emitted, just exit */
    191  1.1.1.8  christos 
    192  1.1.1.8  christos             return (1);
    193  1.1.1.8  christos 
    194  1.1.1.8  christos         case 'd':
    195  1.1.1.8  christos 
    196  1.1.1.8  christos             printf (ACPI_COMMON_BUILD_TIME);
    197  1.1.1.8  christos             return (1);
    198  1.1.1.8  christos 
    199  1.1.1.8  christos         default:
    200  1.1.1.8  christos 
    201  1.1.1.8  christos             printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
    202  1.1.1.8  christos             return (-1);
    203  1.1.1.8  christos         }
    204  1.1.1.8  christos         break;
    205  1.1.1.2  christos 
    206      1.1    jruoho     default:
    207  1.1.1.2  christos 
    208      1.1    jruoho         AbDisplayUsage (0);
    209  1.1.1.2  christos         return (-1);
    210      1.1    jruoho     }
    211      1.1    jruoho 
    212  1.1.1.2  christos     return (Status);
    213      1.1    jruoho }
    214