OpenCores
URL https://opencores.org/ocsvn/light52/light52/trunk

Subversion Repositories light52

[/] [light52/] [trunk/] [tools/] [build_rom/] [src/] [build_rom.py] - Diff between revs 4 and 22

Show entire file | Details | Blame | View Log

Rev 4 Rev 22
Line 1... Line 1...
#!/usr/bin/env python
#!/usr/bin/env python
"""
"""
build_rom.py: Create VHDL package with ROM initialization constant from
build_rom.py: Create VHDL package with ROM initialization constant from
Intel-HEX object code file.
Intel-HEX object code file.
 
Please use with --help to get some brief usage instructions.
"""
"""
__author__ = "Jose A. Ruiz"
__author__ = "Jose A. Ruiz"
__license__ = "LGPL"
__license__ = "LGPL"
 
 
 
 
Line 23... Line 24...
    print "usage:"
    print "usage:"
    print "python build_rom.py [arguments]\n"
    print "python build_rom.py [arguments]\n"
    print "Builds VHDL ROM constant from template and Intel HEX object file.\n"
    print "Builds VHDL ROM constant from template and Intel HEX object file.\n"
    print "ALL of the following arguments should be given, in any order:"
    print "ALL of the following arguments should be given, in any order:"
    print "{f|file} <filename>        Object code file name"
    print "{f|file} <filename>        Object code file name"
    print "{c|constant} <name>        Name of target VHDL constant"
 
    print "{p|package} <name>         Name of target VHDL package"
 
    print "{n|name} <name>            Name of project (used only in comment)"
 
    print "{o|output} <filename>      Target VHDL file name"
 
    print ""
    print ""
    print "Additionally, any of these arguments can be given:"
    print "Additionally, any of these arguments can be given:"
 
    print "{h|help}                   Show help string and exit"
 
    print "{c|constant} <name>        Name of target VHDL object code constant"
 
    print "{p|package} <name>         Name of target VHDL package"
 
    print "{n|name} <name>            Name of project (used only in comments)"
 
    print "{o|output} <filename>      Target VHDL file name"
 
    print "{xcode} <number>           Size of XCODE memory in bytes"
 
    print "         (defaults to 2048)"
 
    print "{xdata} <number>           Size of XDATA memory in bytes"
 
    print "         (defaults to 0)"
    print "{v|vhdl} <filename>        VHDL template"
    print "{v|vhdl} <filename>        VHDL template"
    print "         (defaults to templates/obj_code_kg_template.vhdl)"
    print "         (defaults to templates/obj_code_kg_template.vhdl)"
    print "{i|indent} <number>        Indentation in VHDL tables (decimal)"
    print "{i|indent} <number>        Indentation in VHDL tables (decimal)"
    print "         (defaults to 4)"
    print "         (defaults to 4)"
 
 
 
 
 
 
def help():
def help():
    """Print help message a bit longer than usage message."""
    """Print help message a bit longer than usage message."""
    print "\nPurpose:\n"
    print "\nPurpose:\n"
    print "Reads the code and data binary files and 'slices' them in byte"
    print "Builds initialization package for Light52 MCU core."
    print "columns."
    print "The object code bytes are converted to VHDL strings and then inserted"
    print "The data columns are converted to VHDL strings and then inserted"
    print "into the vhdl template, in place of tag @code_bytes@.\n"
    print "into the vhdl template, in place of tags @code0@ .. @code3@ and "
 
    print "@data0@ .. @data3@. Column 0 is LSB and column3 is MSB.\n"
 
    print "Tags like @data31@ and @data20@ etc. can be used to initialize"
 
    print "memories in 16-bit buses, also split in byte columns.\n"
 
    print "Template tags are replaced as follows:"
    print "Template tags are replaced as follows:"
    print "@obj_pkg_name@        : Name of package in target vhdl file."
    print "@obj_pkg_name@        : Name of package in target vhdl file."
    print "@const_name@          : Name of constant (VHDL table)."
    print "@const_name@          : Name of object code constant (VHDL table)."
    print "@obj_size@            : Total size of code table in bytes."
    print "@obj_size@            : Total size of code table in bytes."
    print "@project@             : Project name."
    print "@obj_bytes@           : Array of object code bytes."
 
    print "@project_name@        : Project name."
    print "@xcode_size@          : Size of XCODE memory."
    print "@xcode_size@          : Size of XCODE memory."
    print "@xdata_size@          : Size of XDATA memory."
    print "@xdata_size@          : Size of XDATA memory."
 
 
def parse_hex_line(line):
def parse_hex_line(line):
    """Parse code line in HEX object file."""
    """Parse code line in HEX object file."""
Line 231... Line 235...
        elif opt in ("--xcode"):
        elif opt in ("--xcode"):
            params['xcode_size'] = int(arg)
            params['xcode_size'] = int(arg)
        elif opt in ("--xdata"):
        elif opt in ("--xdata"):
            params['xdata_size'] = int(arg)
            params['xdata_size'] = int(arg)
 
 
    # Ok, now 
    # Ok, now read and parse the input Intel HEX object code file.
    if params['hex']:
    if params['hex']:
        (xcode, total_bytes, bottom, top) = read_ihex_file(params['hex']);
        (xcode, total_bytes, bottom, top) = read_ihex_file(params['hex']);
    else:
    else:
        print "Object HEX file name missing.";
        print "Object HEX file name missing.";
        usage()
        usage()
        return 1
        return 1
 
 
 
 
    # Make sure the object code fits the implemented XCODE space.
    # Make sure the object code fits into the implemented XCODE space.
    # If it doesn't, print a warning and let the user deal with it.
    # If it doesn't, print a warning and let the user deal with it.
    # Assuming that XCODE starts at address zero -- that's how the core works.
    # Assuming that XCODE starts at address zero -- that's how the core works.
    if params['xcode_size'] < top:
    if params['xcode_size'] < top:
        print "\nWARNING: Object code does not fit XCODE space!\n"
        print "\nWARNING: Object code does not fit XCODE space!\n"
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.