Exemplo n.º 1
0
def replace_vhdl_templates(vhdl_snippets_dir, src_fw_dir, dest_fw_dir):
    """Replace VHDL templates with snippets from VHDL Producer."""
    #Read generated VHDL snippets
    logging.info("replace VHDL templates with snippets from VHDL Producer ...")
    replace_map = {
        '{{algo_index}}':
        tb.read_file(os.path.join(vhdl_snippets_dir, 'algo_index.vhd')),
        '{{ugt_constants}}':
        tb.read_file(os.path.join(vhdl_snippets_dir, 'ugt_constants.vhd')),
        '{{gtl_module_signals}}':
        tb.read_file(os.path.join(vhdl_snippets_dir,
                                  'gtl_module_signals.vhd')),
        '{{gtl_module_instances}}':
        tb.read_file(
            os.path.join(vhdl_snippets_dir, 'gtl_module_instances.vhd')),
    }

    gtl_fdl_wrapper_dir = os.path.join(src_fw_dir, 'hdl', 'gt_mp7_core',
                                       'gtl_fdl_wrapper')
    gtl_dir = os.path.join(gtl_fdl_wrapper_dir, 'gtl')
    fdl_dir = os.path.join(gtl_fdl_wrapper_dir, 'fdl')

    #Patch VHDL files in IPBB area (
    tb.template_replace(os.path.join(fdl_dir, 'algo_mapping_rop_tpl.vhd'),
                        replace_map,
                        os.path.join(dest_fw_dir, 'algo_mapping_rop.vhd'))
    tb.template_replace(os.path.join(gtl_dir, 'gtl_pkg_tpl.vhd'), replace_map,
                        os.path.join(dest_fw_dir, 'gtl_pkg.vhd'))
    tb.template_replace(os.path.join(gtl_dir,
                                     'gtl_module_tpl.vhd'), replace_map,
                        os.path.join(dest_fw_dir, 'gtl_module.vhd'))
Exemplo n.º 2
0
def insert_l1a_ttc(filename):
    content = tb.read_file(filename)

    expr_payload = re.compile(r"(\s*ctrs\s*=>\s*ctrs\s*,)(\s*bc0\s*=>\s*payload_bc0\s*,)")
    l1a_str = "\n                l1a => ttc_l1a,"

    content, count = expr_payload.subn(r"\g<1>{l1a_str}\g<2>".format(**locals()), content)
    if count != 1:
        raise RuntimeError("Could not insert l1a ttc port.")

    with open(filename, "wb") as fp:
        fp.write(content)
        logging.info("Successfully patched l1a_ttc file '{}'".format(filename))
Exemplo n.º 3
0
def replace_area_constraints(filename):
    content = tb.read_file(filename)

    expr_forloop = re.compile(r"(for\s+{\s*set\s*i\s*0\s*}\s+{\s*\$i\s*<\s*)(\d+)(\s*}\s+{\s*incr\s+i\s*})")
    expr_cells = re.compile(r"(add_cells_to_pblock\s+\[\s*get_pblocks\s+payload_)(\d+)(\s*]\s*\[get_cells\s+(?:-\w+\s+)?datapath/rgen\[)(\d+)(]\.region/pgen\.\*])")

    content, count = expr_forloop.subn(r"\g<1>7\g<3>", content)
    if count != 1:
        raise RuntimeError("Could not replace the for-loop value.")

    content, count = expr_cells.subn(r"\g<1>6\g<3>6\g<5>", content)
    if count != 1:
        raise RuntimeError("Could not replace add_cells_to_pblock line.")

    with open(filename, "wb") as fp:
        fp.write(content)
        logging.info("Successfully patched area_constraints file '{}'".format(filename))
Exemplo n.º 4
0
def replace_brd_decl(filename):
    content = tb.read_file(filename)

    expr_nregion = re.compile(r"(constant\s+N_REGION\s*:\s*integer\s*:=\s*)(\d+)(\s*;)")
    expr_crossregion = re.compile(r"(constant\s+CROSS_REGION\s*:\s*integer\s*:=\s*)(\d+)(\s*;)")

    content, count = expr_nregion.subn(r"\g<1>7\g<3>", content)
    if count != 1:
        raise RuntimeError("Could not replace the N_REGION value.")

    content, count = expr_crossregion.subn(r"\g<1>6\g<3>", content)
    if count != 1:
        raise RuntimeError("Could not replace the CROSS_REGION value.")

    with open(filename, "wb") as fp:
        fp.write(content)
        logging.info("Successfully patched brd_decl file '{}'".format(filename))
Exemplo n.º 5
0
def main():
    """Main routine."""

    # Parse command line arguments.
    args = parse_args()

    # Setup console logging
    logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

    # Compile build root directory
    project_type = "{}_{}".format(BOARD_TYPE, FW_TYPE)
    build_name = "0x{}".format(args.build)
    build_root = os.path.join(args.path, project_type, build_name)

    if os.path.isdir(build_root):
        raise RuntimeError("build area alredy exists: {}".format(build_root))

    # Fetch menu name from path.
    menu_name = os.path.basename(args.menu)

    if not menu_name.startswith('L1Menu_'):
        raise RuntimeError("Invalid menu name: {}".format(menu_name))

    # Fetch number of menu modules.
    modules = tb.count_modules(args.menu)

    if not modules:
        raise RuntimeError("Menu contains no modules")

    logging.info("Creating uGT build area...")
    logging.info("tag: %s (%s)", args.tag, "unstable" if args.unstable else "stable")
    logging.info("user: %s", args.user)
    logging.info("path: %s", build_root)
    logging.info("menu file: %s", args.menu)
    logging.info("menu name: %s", menu_name)
    logging.info("menu modules: %s", modules)
    logging.info("build: 0x%s", args.build)
    logging.info("board type: %s", args.board)

    if not os.path.isdir(args.menu):
        raise RuntimeError("menu directory does not exist: {}".format(args.menu))

    # MP7 tag path inside build root directry.
    # mp7path: /home/user/work/fwdir/0x1234/mp7_v1_2_3
    mp7path = os.path.join(build_root, args.tag)

    #
    # Create build area
    #
    logging.info("creating directory %s", mp7path)
    os.makedirs(mp7path)

    # Check out mp7fw
    os.chdir(mp7path)

    logging.info("downloading project manager...")
    filename = "ProjectManager.py"
    # Remove existing file.
    tb.remove(filename)
    # Download file
    release_mode = 'unstable' if args.unstable else 'stable'
    url = "https://svnweb.cern.ch/trac/cactus/browser/tags/mp7/{release_mode}/firmware/{args.tag}/cactusupgrades/scripts/firmware/ProjectManager.py?format=txt".format(**locals())
    logging.info("retrieving %s", url)
    urllib.urlretrieve(url, filename)
    tb.make_executable(filename)

    # Pffff....
    d = open(filename).read()
    d = d.replace(', default=os.getlogin()', '')
    with open(filename, 'wb') as fp:
        fp.write(d)

    logging.info("checkout MP7 base firmware...")
    path = os.path.join('tags', 'mp7', 'unstable' if args.unstable else 'stable', 'firmware', args.tag)
    if args.old:
        subprocess.check_call(['python', 'ProjectManager.py', 'checkout', path, '-u', args.user])
    else:
        subprocess.check_call(['python', 'ProjectManager.py', 'create', path, '-u', args.user]) #changes in ProjectManager.py, have to differ between older and newer versions

    # Remove unused boards
    logging.info("removing unused boards...")
    boards_dir = os.path.join(mp7path,'cactusupgrades', 'boards')
    for board in os.listdir(boards_dir):
        if board != 'mp7':
            tb.remove(os.path.join(boards_dir, board))

    #
    # Patch downlaoded files
    #
    mp7patch.patch_all(os.path.join(mp7path,'cactusupgrades'))

    os.chdir(mp7path)

    #
    #  Patching top VHDL
    #
    logging.info("patch the target package with current UNIX timestamp/username/hostname...")
    subprocess.check_call(['python', os.path.join(scripts_dir, 'pkgpatch.py'), '--build', args.build ,TARGET_PKG_TPL, TARGET_PKG])

    #
    #  Creating build areas
    #
    logging.info("creating build areas...")
    build_area_dir = 'build'

    # Create build directory for fw synthesis...
    project_dir = os.path.abspath(os.path.join(build_area_dir, menu_name))
    os.makedirs(project_dir)

    # Do for every module of the menu...
    for module_id in range(modules):
        module_name = 'module_{}'.format(module_id)
        module_dir = os.path.join(project_dir, module_name)
        local_fw_dir = os.path.abspath(os.path.join(module_dir, 'mp7_ugt'))

        # Creat module build area
        os.makedirs(local_fw_dir)

        # Copy sources to module build area
        copy_tree(os.path.join(firmware_dir, 'cfg'), os.path.join(local_fw_dir, 'firmware', 'cfg'))
        copy_tree(os.path.join(firmware_dir, 'hdl'), os.path.join(local_fw_dir, 'firmware', 'hdl'))
        copy_tree(os.path.join(firmware_dir, 'ngc'), os.path.join(local_fw_dir, 'firmware', 'ngc'))
        copy_tree(os.path.join(firmware_dir, 'ucf'), os.path.join(local_fw_dir, 'firmware', 'ucf'))

        # Read generated VHDL snippets
        src_dir = os.path.join(args.menu, 'vhdl', module_name, 'src')

        replace_map = {
            '{{algo_index}}': tb.read_file(os.path.join(src_dir, 'algo_index.vhd')),
            '{{ugt_constants}}': tb.read_file(os.path.join(src_dir, 'ugt_constants.vhd')),
            '{{gtl_module_signals}}': tb.read_file(os.path.join(src_dir, 'gtl_module_signals.vhd')),
            '{{gtl_module_instances}}': tb.read_file(os.path.join(src_dir, 'gtl_module_instances.vhd')),
        }

        gtl_fdl_wrapper_dir = os.path.join(local_fw_dir, 'firmware', 'hdl', 'gt_mp7_core', 'gtl_fdl_wrapper')
        gtl_dir = os.path.join(gtl_fdl_wrapper_dir, 'gtl')
        fdl_dir = os.path.join(gtl_fdl_wrapper_dir, 'fdl')

        # Patch VHDL files
        tb.template_replace(os.path.join(fdl_dir, 'algo_mapping_rop_tpl.vhd'), replace_map, os.path.join(fdl_dir, 'algo_mapping_rop.vhd'))
        tb.template_replace(os.path.join(gtl_dir, 'gtl_pkg_tpl.vhd'), replace_map, os.path.join(gtl_dir, 'gtl_pkg.vhd'))
        tb.template_replace(os.path.join(gtl_dir, 'gtl_module_tpl.vhd'), replace_map, os.path.join(gtl_dir, 'gtl_module.vhd'))

        # Run project manager
        subprocess.check_call(['python', 'ProjectManager.py', 'vivado', local_fw_dir, '-w', module_dir])

    # Go to build area root directory.
    os.chdir(mp7path)
    os.chdir(build_area_dir)

    # Creating configuration file.
    config = ConfigParser.RawConfigParser()
    config.add_section('environment')
    config.set('environment', 'timestamp', tb.timestamp())
    config.set('environment', 'hostname', tb.hostname())
    config.set('environment', 'username', tb.username())

    config.add_section('menu')
    config.set('menu', 'build', args.build)
    config.set('menu', 'name', menu_name)
    config.set('menu', 'location', args.menu)
    config.set('menu', 'modules', modules)

    config.add_section('firmware')
    config.set('firmware', 'tag', args.tag)
    config.set('firmware', 'stable', str(not args.unstable))
    config.set('firmware', 'type', FW_TYPE)
    config.set('firmware', 'buildarea', os.path.join(mp7path, build_area_dir, menu_name))

    config.add_section('device')
    config.set('device', 'type', args.board)
    config.set('device', 'name', BOARD_TYPE)
    config.set('device', 'alias', BoardAliases[args.board])

    # Writing our configuration file to 'example.cfg'
    with open('build_0x{}.cfg'.format(args.build), 'wb') as fp:
        config.write(fp)

    logging.info("finished with success.")