Exemple #1
0
def GetStructType(name):
    # Create the parser 
    structParser = pyclibrary.CParser(processAll=None)
    structParser.loadCache(name)
    # Make the library that will actually contain the type
    structLibrary = pyclibrary.CLibrary(None, structParser)
    return getattr(structLibrary, '_struct')
Exemple #2
0
    def startParse(self):
        self.createMakeFiles()

        self.p = pyclibrary.CParser(files=self.header_files,
                                    cache=unicode('C2MX2.cachefile'),
                                    process_all=False)
        self.p.process_all(cache=unicode('C2MX2.cachefile'))

        # start parsing/creating
        writeContentToFile(
            self.outputPath + '/' + self.namespace + '.monkey2', "Namespace " +
            self.namespace + '\nImport "makefile.monkey2"\n\nExtern\n')

        # keep this order
        self.createConst()
        self.createEnums()  # so we can check if the Const alreay exists
        self.createMethods()
        self.createStructs()
        self.createUsingUnions()
        self.createUsingTypes()
def get_c_fields(name):
    """
	get c fields
	"""
    filename = os.path.join(C_STRUCTS_DIR, name)
    if not os.path.isfile(filename):
        print("ERR - Could not find file", filename)
        return []
    parser = pyclibrary.CParser(process_all=False)
    try:
        file = parser.load_file(filename)
        if not file:
            print("ERR - Could not load file")
            return []
        parser.remove_comments(filename)
        parser.preprocess(filename)
        parser.parse_defs(filename)
        structs = parser.defs["structs"]
    except:
        print("ERR - File not found")
        return []

    return extract_c_fields(structs)
Exemple #4
0
        'findstr BL2_NS_IMAGE_START ..\config.cmake').read().split(
            "set(BL2_NS_IMAGE_START")[1].split("\"")[1]
else:
    BL2_S_IMAGE_START = os.popen(
        'grep "BL2_S_IMAGE_START" ../config.cmake').read().split(
            "set(BL2_S_IMAGE_START")[1].split("\"")[1]
    BL2_NS_IMAGE_START = os.popen(
        'grep "BL2_NS_IMAGE_START" ../config.cmake').read().split(
            "set(BL2_NS_IMAGE_START")[1].split("\"")[1]

# Update flash base addresses according to the flash_layout.h if pyclibrary is present
try:
    import pyclibrary

    # Parse the flash_layout.h header file with the BL2 configuration
    parser = pyclibrary.CParser('../partition/flash_layout.h',
                                macros={'BL2': 'ON'})

    # Update secure image flash base address according to FLASH_AREA_0_OFFSET
    BL2_S_IMAGE_START = parser.defs['values']['FLASH_AREA_0_OFFSET']
    # Update non secure image flash base address according to BL2_S_IMAGE_START + FLASH_S_PARTITION_SIZE
    BL2_NS_IMAGE_START = BL2_S_IMAGE_START + parser.defs['values'][
        'FLASH_S_PARTITION_SIZE']

# Use the default values if the previous step was not successful
except:
    print("*** WARNING: pyclibrary is not installed ***")
    print(
        "Please install pyclibrary for updating flash base addresses in case of flash_layout.h modification"
    )
    print("Using default values:")
    print("BL2_S_IMAGE_START = " + BL2_S_IMAGE_START)
Exemple #5
0
#!/usr/bin/python3

import argparse
import sys

if not '..' in sys.path:
    sys.path.append('..')

import pyclibrary

parser = argparse.ArgumentParser(
    description=
    "makes a pickled struct definition file from a C header, for use with read_struct and write_struct"
)
parser.add_argument(
    'inputFile',
    help="Input file name; struct to be converted must be called _struct")
parser.add_argument('outputFile', help="Output file name")
args = parser.parse_args()

# Create the parser and process the header
structParser = pyclibrary.CParser(files=args.inputFile, processAll=False)
structParser.processAll(cache=args.outputFile, noCacheWarning=False)