Exemple #1
0
def download_file_from_url(url, filename):
    """Download files from URL."""
    # Remove existing file.
    tb.remove(filename)
    # Download file
    logging.info("retrieving %s", url)
    urllib.urlretrieve(url, filename)
    tb.make_executable(filename)

    d = open(filename).read()
    d = d.replace(', default=os.getlogin()', '')
    with open(filename, 'wb') as fp:
        fp.write(d)
Exemple #2
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)

    # Feth current timestamp.
    timestamp = get_timestamp()

    # 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)

    #fw_build_dir = os.path.join(args.path, "{}_{}".format(BOARD_TYPE, FW_TYPE))

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

    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("build: 0x%s", args.build)
    logging.info("board type: %s", args.board)

    # 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))

    cwd = os.getcwd()
    os.chdir(mp7path)

    # Copy changed MP7 files to project
    src_sub_dir = '../replacement_files/'

    for source, dest in replace_file_list:
      src_path = os.path.abspath(os.path.join(scripts_dir, src_sub_dir, source))
      dest_path = os.path.abspath(os.path.join(mp7path, 'cactusupgrades', dest))
      shutil.copy(src_path, dest_path)

    logging.info("Sucessfully patched files for AMC502 ExtCond.")

    #
    #  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'

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

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

    # Copy sources to module build area
    copy_tree(os.path.join(amc502Path, 'firmware', 'cfg'), os.path.join(project_dir, 'firmware', 'cfg'))
    copy_tree(os.path.join(amc502Path, 'firmware', 'hdl'), os.path.join(project_dir, 'firmware', 'hdl'))
    copy_tree(os.path.join(amc502Path, 'firmware', 'ucf'), os.path.join(project_dir, 'firmware', 'ucf'))
    copy_tree(os.path.join(amc502Path, 'firmware', 'cgn'), os.path.join(project_dir, 'firmware', 'cgn'))

    # Run project manager
    subprocess.check_call(['python', 'ProjectManager.py', 'vivado', project_dir])
    os.chdir(cwd)

    # 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', timestamp)
    config.set('environment', 'hostname', hostname())
    config.set('environment', 'username', username())

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

    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)
    ## Writing our configuration file to 'example.cfg'
    #with open('.'.join((build_area_dir, 'cfg')), 'wb') as configfile:
        #config.write(configfile)

    logging.info("AMC502 ExtCond project maker finished with success.")
Exemple #3
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)
    logging.info("tcl name: %s", args.tclfile)
    logging.info("HLS path: %s", args.hls)

    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, 'constants_pkg.vhd'))
        #tb.template_replace(os.path.join(gtl_dir, 'gtl_module_tpl.vhd'), replace_map, os.path.join(gtl_dir, 'gtl_module.vhd'))

        # Copy constants_pkg.vhd from "menu" (HLS)
        shutil.copyfile(os.path.join(src_dir, 'constants_pkg.vhd'),
                        os.path.join(gtl_dir, 'constants_pkg.vhd'))

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

        #
        # Create TCL file for adding HLS IP core into Vivado IP catalog
        #
        os.chdir(module_dir)
        #set_prop = "set_property ip_repo_paths %s", args.hls, "[current_project]\n"
        hls_ip_file = open(args.tclfile, "w")
        hls_ip_file.write("open_project top/top.xpr\n")
        hls_ip_file.write("set_property ip_repo_paths ")
        hls_ip_file.write(args.hls)
        hls_ip_file.write(" [current_project]\n")
        hls_ip_file.write("update_ip_catalog\n")
        hls_ip_file.write(
            "create_ip -name algos -library hls -version 1.0 -module_name algos_0\n"
        )
        hls_ip_file.write(
            "generate_target {instantiation_template} [get_files top/top.srcs/sources_1/ip/algos_0/algos_0.xci]\n"
        )
        hls_ip_file.write(
            "generate_target all [get_files top/top.srcs/sources_1/ip/algos_0/algos_0.xci]\n"
        )
        hls_ip_file.write(
            "catch { config_ip_cache -export [get_ips -all algos_0] }\n")
        hls_ip_file.write(
            "generate_target all [get_files top/top.srcs/sources_1/ip/algos_0/algos_0.xci] \n"
        )
        hls_ip_file.write(
            "export_ip_user_files -of_objects [get_files top/top.srcs/sources_1/ip/algos_0/algos_0.xci] \n"
        )
        hls_ip_file.write(
            "create_ip_run [get_files -of_objects [get_fileset sources_1] top/top.srcs/sources_1/ip/algos_0/algos_0.xci] \n"
        )
        hls_ip_file.write("launch_runs -jobs 14 algos_0_synth_1\n")
        hls_ip_file.write("exit\n")
        hls_ip_file.close()

    # 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.")