summaryrefslogtreecommitdiff
path: root/Platform/Intel/MinPlatformPkg/Tools/AmlGenOffset/AmlGenOffset.py
blob: 312c1abb75ddf2431c26e90ea3dbc1d10bc81964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
## @file
#
# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution.  The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#

'''
AmlGenOffset
'''

import os
import sys
import argparse
import subprocess
import uuid
import struct
import collections
import binascii
import re
from   ctypes import *

#
# Globals for help information
#
__prog__      = 'AmlGenOffset'
__version__   = '%s Version %s' % (__prog__, '0.1 ')
__copyright__ = 'Copyright (c) 2017, Intel Corporation. All rights reserved.'
__usage__     = '%s -e|-d [options] <input_file>' % (__prog__)


if __name__ == '__main__':
  #
  # Create command line argument parser object
  #
  parser = argparse.ArgumentParser(prog=__prog__, version=__version__, usage=__usage__, description=__copyright__, conflict_handler='resolve')
  group = parser.add_mutually_exclusive_group(required=True)
  group.add_argument("-e", action="store_true", dest='Encode', help='encode file')
  group.add_argument("-d", action="store_true", dest='Decode', help='decode file')
  parser.add_argument("-o", "--output", dest='OutputFile', type=str, metavar='filename', help="specify the output filename", required=True)
  parser.add_argument("-v", "--verbose", dest='Verbose', action="store_true", help="increase output messages")
  parser.add_argument("-q", "--quiet", dest='Quiet', action="store_true", help="reduce output messages")
  parser.add_argument("--debug", dest='Debug', type=int, metavar='[0-9]', choices=range(0,10), default=0, help="set debug level")
  parser.add_argument("--aml_filter", dest='AmlFilterStr', type=str, help="specify the AML filter.")
  parser.add_argument(metavar="input_file", dest='InputFile', type=argparse.FileType('rb'), help="specify the input filename")

  #
  # Parse command line arguments
  #
  args = parser.parse_args()

  if args.Encode:
    print 'Unsupported'

  if args.Decode:
    args.OutputFileName = args.OutputFile
    args.OutputFile = open(args.OutputFileName, 'wb')

    AmlFilter = args.AmlFilterStr
    filter_pattern = '|'.join(AmlFilter.split(' '))

    lines = args.InputFile.readlines()
    args.InputFile.close()
    for line in lines:
        if line.strip().startswith('{\"') == False:
            if line.strip().startswith('* Compilation') == False and line.strip().startswith('* ASL+') == False and line.strip().startswith('* Copyright') == False:
                args.OutputFile.write(line)
        else:
            match_obj = re.search(filter_pattern, line, re.M | re.I)
            if match_obj is not None:
                args.OutputFile.write(line)
    args.OutputFile.close()