Ejemplo n.º 1
0
    def __init__(self):
        # Version and Copyright
        self.VersionNumber = ("1.0" + " Build " + gBUILD_VERSION)
        self.Version = "%prog Version " + self.VersionNumber
        self.Copyright = "Copyright (c) 2009 - 2018, Intel Corporation  All rights reserved."

        self.InitDefaultConfigIni()
        self.OutputFile = 'output.txt'
        self.ReportFile = 'Report.csv'
        self.ExceptionFile = 'exception.xml'
        self.IsInit = True
        self.ScanSourceCode = True
        self.ScanMetaData = True
        self.MetaFile = ''
        self.OnlyScan = None

        # Parse the options and args
        self.ParseOption()
        EdkLogger.info(time.strftime("%H:%M:%S, %b.%d %Y ", time.localtime()) + "[00:00]" + "\n")

        WorkspaceDir = os.path.normcase(os.path.normpath(os.environ["WORKSPACE"]))
        os.environ["WORKSPACE"] = WorkspaceDir

        # set multiple workspace
        PackagesPath = os.getenv("PACKAGES_PATH")
        mws.setWs(WorkspaceDir, PackagesPath)

        GlobalData.gWorkspace = WorkspaceDir

        GlobalData.gGlobalDefines["WORKSPACE"]  = WorkspaceDir

        EdkLogger.info("Loading ECC configuration ... done")
        # Generate checkpoints list
        EccGlobalData.gConfig = Configuration(self.ConfigFile)

        # Generate exception list
        EccGlobalData.gException = ExceptionCheck(self.ExceptionFile)

        # Init Ecc database
        EccGlobalData.gDb = Database.Database(Database.DATABASE_PATH)
        EccGlobalData.gDb.InitDatabase(self.IsInit)

        #
        # Get files real name in workspace dir
        #
        GlobalData.gAllFiles = DirCache(GlobalData.gWorkspace)

        # Build ECC database
#         self.BuildDatabase()
        self.DetectOnlyScanDirs()

        # Start to check
        self.Check()

        # Show report
        self.GenReport()

        # Close Database
        EccGlobalData.gDb.Close()
Ejemplo n.º 2
0
def MyOptionParser():
    #
    # Process command line firstly.
    #
    parser = OptionParser(version="%s - Version %s" % (PROJECT_NAME, VERSION),
                          description='',
                          prog='BPDG',
                          usage=st.LBL_BPDG_USAGE)
    parser.add_option('-d',
                      '--debug',
                      action='store',
                      type="int",
                      dest='debug_level',
                      help=st.MSG_OPTION_DEBUG_LEVEL)
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      dest='opt_verbose',
                      help=st.MSG_OPTION_VERBOSE)
    parser.add_option('-q',
                      '--quiet',
                      action='store_true',
                      dest='opt_quiet',
                      default=False,
                      help=st.MSG_OPTION_QUIET)
    parser.add_option('-o',
                      '--vpd-filename',
                      action='store',
                      dest='bin_filename',
                      help=st.MSG_OPTION_VPD_FILENAME)
    parser.add_option('-m',
                      '--map-filename',
                      action='store',
                      dest='filename',
                      help=st.MSG_OPTION_MAP_FILENAME)
    parser.add_option('-f',
                      '--force',
                      action='store_true',
                      dest='opt_force',
                      help=st.MSG_OPTION_FORCE)

    (options, args) = parser.parse_args()
    if len(args) == 0:
        EdkLogger.info(
            "Please specify the filename.txt file which contain the VPD pcd info!"
        )
        EdkLogger.info(parser.usage)
        sys.exit(1)
    return options, args
Ejemplo n.º 3
0
def ParseArgs():
    # Initialize the parser.
    Parser = argparse.ArgumentParser(description=__description__)

    # Define the possible arguments.
    Parser.add_argument(
        dest="InputFile",
        help="Path to an input AML file to generate a .c file from.")
    Parser.add_argument(
        "-o",
        "--out-dir",
        dest="OutDir",
        help=
        "Output directory where the .c file will be generated. Default is the input file's directory."
    )

    # Parse the input arguments.
    Args = Parser.parse_args()
    SplitInputName = ""

    if not os.path.exists(Args.InputFile):
        EdkLogger.error(__file__, FILE_OPEN_FAILURE, ExtraData=Args.InputFile)
        return None
    else:
        with open(Args.InputFile, "rb") as fIn:
            Signature = str(fIn.read(4))
            if ("DSDT" not in Signature) and ("SSDT" not in Signature):
                EdkLogger.info(
                    "Invalid file type. File does not have a valid DSDT or SSDT signature: {}"
                    .format(Args.InputFile))
                return None

    # Get the basename of the input file.
    SplitInputName = os.path.splitext(Args.InputFile)
    BaseName = os.path.basename(SplitInputName[0])

    # If no output directory is specified, output to the input directory.
    if not Args.OutDir:
        Args.OutputFile = os.path.join(os.path.dirname(Args.InputFile),
                                       BaseName + ".c")
    else:
        if not os.path.exists(Args.OutDir):
            os.mkdir(Args.OutDir)
        Args.OutputFile = os.path.join(Args.OutDir, BaseName + ".c")

    Args.BaseName = BaseName

    return Args
Ejemplo n.º 4
0
def CreateCCodeDB(FileNameList):
    FileObjList = []
    ParseErrorFileList = []
    ParsedFiles = {}
    for FullName in FileNameList:
        if os.path.splitext(FullName)[1] in ('.h', '.c'):
            if FullName.lower() in ParsedFiles:
                continue
            ParsedFiles[FullName.lower()] = 1
            EdkLogger.info("Parsing " + FullName)
            model = FullName.endswith(
                'c') and DataClass.MODEL_FILE_C or DataClass.MODEL_FILE_H
            collector = CodeFragmentCollector.CodeFragmentCollector(FullName)
            try:
                collector.ParseFile()
            except:
                ParseErrorFileList.append(FullName)
            BaseName = os.path.basename(FullName)
            DirName = os.path.dirname(FullName)
            Ext = os.path.splitext(BaseName)[1].lstrip('.')
            ModifiedTime = os.path.getmtime(FullName)
            FileObj = DataClass.FileClass(-1, BaseName, Ext, DirName,
                                          FullName, model, ModifiedTime,
                                          GetFunctionList(),
                                          GetIdentifierList(), [])
            FileObjList.append(FileObj)
            collector.CleanFileProfileBuffer()

    if len(ParseErrorFileList) > 0:
        EdkLogger.info("Found unrecoverable error during parsing:\n\t%s\n" %
                       "\n\t".join(ParseErrorFileList))

    Db = EotGlobalData.gDb
    for file in FileObjList:
        Db.InsertOneFile(file)

    Db.UpdateIdentifierBelongsToFunction()
Ejemplo n.º 5
0
def StartBpdg(InputFileName, MapFileName, VpdFileName, Force):
    if os.path.exists(VpdFileName) and not Force:
        print("\nFile %s already exist, Overwrite(Yes/No)?[Y]: " % VpdFileName)
        choice = sys.stdin.readline()
        if choice.strip().lower() not in ['y', 'yes', '']:
            return

    GenVPD = GenVpd.GenVPD(InputFileName, MapFileName, VpdFileName)

    EdkLogger.info('%-24s = %s' % ("VPD input data file: ", InputFileName))
    EdkLogger.info('%-24s = %s' % ("VPD output map file: ", MapFileName))
    EdkLogger.info('%-24s = %s' % ("VPD output binary file: ", VpdFileName))

    GenVPD.ParserInputFile()
    GenVPD.FormatFileLine()
    GenVPD.FixVpdOffset()
    GenVPD.GenerateVpdFile(MapFileName, VpdFileName)

    EdkLogger.info("- Vpd pcd fixed done! -")
Ejemplo n.º 6
0
    if isinstance(Target, str):
        Target = [Target]
    if not Target:
        Target = []
    if isinstance(Item, list):
        Target.extend(Item)
    else:
        Target.append(Item)
    Target.append('\n')
    return Target


# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
if __name__ == '__main__':
    EdkLogger.info('start')

    UniFileList = [r'C:\\Edk\\Strings2.uni', r'C:\\Edk\\Strings.uni']

    SrcFileList = []
    for Root, Dirs, Files in os.walk('C:\\Edk'):
        for File in Files:
            SrcFileList.append(File)

    IncludeList = [r'C:\\Edk']

    SkipList = ['.inf', '.uni']
    BaseName = 'DriverSample'
    (h, c) = GetStringFiles(UniFileList, SrcFileList, IncludeList, SkipList,
                            BaseName, True)
    hfile = open('unistring.h', 'w')
 def InfLogger(msg):
     EdkLogger.info(msg)