def main(): """Main routine.""" # Parse command line arguments. args = parse_args() # Setup console logging logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) # with tarfile config = configparser.RawConfigParser() config.read(args.config) for section in config.sections(): print(section) for option in config.options(section): print(" ", option, "=", config.get(section, option)) menu = config.get('menu', 'name') location = config.get('menu', 'location') build = tb.build_t(config.get('menu', 'build')) # format 'ffff' board = config.get('device', 'alias') buildarea = config.get('firmware', 'buildarea') menu_modules = int(config.get('menu', 'modules')) timestamp = tb.timestamp() # Definitions for name of IPBB 'proj' directory fw_type = config.get('firmware', 'type') device_name = config.get('device', 'name') basename = "{menu}_v{build}_{board}".format(**locals()) basepath = os.path.dirname(args.config) # Custom output directory? if args.outdir: basepath = args.outdir filename = os.path.join(basepath, "{basename}-{timestamp}.tar.gz".format(**locals())) tmpdir = tempfile.mkdtemp() logging.info("Created temporary dircetory %s", tmpdir) # Check modules for i in range(menu_modules): #for i in range(len(glob.glob(os.path.join(buildarea, 'module_*')))): logging.info("collecting data from module %s", i) module_dir = 'module_{i}'.format(**locals()) #proj_dir = 'proj/{}_{}_0x{}_{}'.format(device_name, fw_type, build, i) proj_dir = 'proj/{}'.format(module_dir) build_dir = os.path.join(tmpdir, module_dir, 'build') log_dir = os.path.join(tmpdir, module_dir, 'log') # for IPBB v0.5.2 directory structure proj_runs = '{0}/{0}.runs'.format(module_dir) #bit_file = '{}.bit'.format(module_dir) bit_file = 'top.bit' os.makedirs(build_dir) os.makedirs(log_dir) shutil.copy( os.path.join(buildarea, proj_dir, proj_runs, 'impl_1', bit_file), os.path.join( build_dir, 'gt_mp7_{board}_v{build}_module_{i}.bit'.format(**locals()))) shutil.copy( os.path.join(buildarea, proj_dir, proj_runs, 'synth_1', 'runme.log'), os.path.join(log_dir, 'runme_synth_1.log')) shutil.copy( os.path.join(buildarea, proj_dir, proj_runs, 'impl_1', 'runme.log'), os.path.join(log_dir, 'runme_impl_1.log')) logging.info("adding build configuration: %s", args.config) shutil.copy(args.config, tmpdir) xml_file = os.path.join(buildarea, 'src', '{menu}.xml'.format(**locals())) logging.info("adding XML menu: %s", xml_file) shutil.copy(xml_file, tmpdir) logging.info("creating tarball: %s", filename) with tarfile.open(filename, "w:gz") as tar: logging.info("adding to tarball: %s", tmpdir) tar.add(tmpdir, arcname=basename, recursive=True) logging.info("closed tarball: %s", filename) logging.info("removing temporary directory %s.", tmpdir) shutil.rmtree(tmpdir) logging.info("done.")
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.")
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, "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 = 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) os.system( 'git clone https://github.com/herbberg/mp7fw_v2_4_1 {mp7path}'.format( **locals())) # 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') 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') # 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.")
def main(): """Main routine.""" # Parse command line arguments. args = parse_args() # Setup console logging logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) # Check for VIVADO_BASE_DIR vivado_base_dir = os.getenv('VIVADO_BASE_DIR') if not vivado_base_dir: raise RuntimeError( "Environment variable 'VIVADO_BASE_DIR' not set. Set with: 'export VIVADO_BASE_DIR=...'" ) # Setup console logging logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) # Board type taken from mp7url repo name board_type_repo_name = os.path.basename(args.mp7url) if board_type_repo_name.find(".") > 0: board_type = board_type_repo_name.split('.')[ 0] # Remove ".git" from repo name else: board_type = board_type_repo_name # Project type taken from ugturl repo name project_type_repo_name = os.path.basename(args.ugturl) if project_type_repo_name.find(".") > 0: project_type = project_type_repo_name.split( '.') # Remove ".git" from repo name else: project_type = project_type_repo_name # Create MP7 tag name for ugt mp7fw_ugt = args.mp7tag + mp7fw_ugt_suffix #ipbb_dir = os.path.join(args.path, project_type, args.mp7tag, args.menuname, args.build) # HB 2019-11-12: inserted mp7_ugt tag and vivado version in directory name and changed order vivado_version = "vivado_" + args.vivado ipbb_dir = os.path.join(args.path, args.menuname, args.build, project_type, args.ugt, args.mp7tag, vivado_version) if os.path.isdir(ipbb_dir): raise RuntimeError("build area alredy exists: {}".format(ipbb_dir)) # Runnig simulation with Questa simulator, if args.sim is set if args.sim: logging.info( "===========================================================================" ) logging.info("running simulation with Questa ...") run_simulation_questa(args.simmp7path, args.menuname, args.menuurl, args.vivado, args.questasim, args.questasimlibs, args.output, False, False, False) else: logging.info( "===========================================================================" ) logging.info("no simulation required ...") ipbb_version = args.ipbb # IPBB commands: creating IPBB area cmd_ipbb_init = "ipbb init {ipbb_dir}".format(**locals()) cmd_ipbb_add_ipb = "ipbb add git {args.ipburl} -b {args.ipb}".format( **locals()) cmd_ipbb_add_mp7 = "ipbb add git {args.mp7url} -b {mp7fw_ugt}".format( **locals()) cmd_ipbb_add_ugt = "ipbb add git {args.ugturl} -b {args.ugt}".format( **locals()) logging.info( "===========================================================================" ) logging.info("creating IPBB area ...") command = 'bash -c "cd; {cmd_ipbb_init}; cd {ipbb_dir}; {cmd_ipbb_add_ipb} && {cmd_ipbb_add_mp7} && {cmd_ipbb_add_ugt}"'.format( **locals()) run_command(command) logging.info( "===========================================================================" ) logging.info("download XML file from L1Menu repository ...") xml_name = "{}{}".format(args.menuname, '.xml') html_name = "{}{}".format(args.menuname, '.html') url_menu = "{}/{}".format(args.menuurl, args.menuname) #print "url_menu",url_menu # Download XML and HTML files (HTML for buildReporter.py) filename = os.path.join(ipbb_dir, 'src', xml_name) url = "{url_menu}/xml/{xml_name}".format(**locals()) download_file_from_url(url, filename) menu = XmlMenu(filename) filename = os.path.join(ipbb_dir, 'src', html_name) url = "{url_menu}/doc/{html_name}".format(**locals()) download_file_from_url(url, filename) # Fetch menu name from path. menu_name = menu.name if not menu_name.startswith('L1Menu_'): raise RuntimeError("Invalid menu name: {}".format(menu_name)) # Fetch number of menu modules. modules = menu.n_modules if not modules: raise RuntimeError("Menu contains no modules") ipbb_src_fw_dir = os.path.abspath( os.path.join(ipbb_dir, 'src', project_type, 'firmware')) for module_id in range(modules): module_name = 'module_{}'.format(module_id) ipbb_module_dir = os.path.join(ipbb_dir, module_name) ipbb_dest_fw_dir = os.path.abspath( os.path.join(ipbb_dir, 'src', module_name)) os.makedirs(ipbb_dest_fw_dir) #Download generated VHDL snippets from repository and replace VHDL templates logging.info( "===========================================================================" ) logging.info(" *** module %s ***", module_id) logging.info( "===========================================================================" ) logging.info( "download generated VHDL snippets from L1Menu repository for module %s and replace VHDL templates ...", module_id) vhdl_snippets_dir = os.path.join(ipbb_dest_fw_dir, 'vhdl_snippets') os.makedirs(vhdl_snippets_dir) for i in range(len(vhdl_snippets)): vhdl_snippet = vhdl_snippets[i] filename = os.path.join(vhdl_snippets_dir, vhdl_snippet) url = "{url_menu}/vhdl/{module_name}/src/{vhdl_snippet}".format( **locals()) download_file_from_url(url, filename) replace_vhdl_templates(vhdl_snippets_dir, ipbb_src_fw_dir, ipbb_dest_fw_dir) logging.info( "patch the target package with current UNIX timestamp/username/hostname ..." ) top_pkg_tpl = os.path.join(ipbb_src_fw_dir, 'hdl', 'gt_mp7_top_pkg_tpl.vhd') top_pkg = os.path.join(ipbb_src_fw_dir, 'hdl', 'gt_mp7_top_pkg.vhd') subprocess.check_call([ 'python', os.path.join(ipbb_src_fw_dir, '..', 'scripts', 'pkgpatch.py'), '--build', args.build, top_pkg_tpl, top_pkg ]) #Vivado settings settings64 = os.path.join(vivado_base_dir, args.vivado, 'settings64.sh') if not os.path.isfile(settings64): raise RuntimeError( "no such Xilinx Vivado settings file '{settings64}'\n" \ " check if Xilinx Vivado {args.vivado} is installed on this machine.".format(**locals()) ) logging.info( "===========================================================================" ) logging.info("creating IPBB project for module %s ...", module_id) cmd_ipbb_proj_create = "ipbb proj create vivado {module_name} {board_type}:../{project_type}".format( **locals()) #command = 'bash -c "cd; {cmd_activate_env}; cd {ipbb_dir}; {cmd_ipbb_proj_create}"'.format(**locals()) command = 'bash -c "cd; cd {ipbb_dir}; {cmd_ipbb_proj_create}"'.format( **locals()) run_command(command) logging.info( "===========================================================================" ) logging.info( "running IPBB project, synthesis and implementation, creating bitfile for module %s ...", module_id) #IPBB commands: running IPBB project, synthesis and implementation, creating bitfile cmd_ipbb_project = "ipbb vivado make-project --single" # workaround to prevent "hang-up" in make-project with IPBB v0.5.2 cmd_ipbb_synth = "ipbb vivado synth" cmd_ipbb_impl = "ipbb vivado impl" cmd_ipbb_bitfile = "ipbb vivado package" #Set variable "module_id" for tcl script (l1menu_files.tcl in uGT_algo.dep) command = 'bash -c "cd; source {settings64}; cd {ipbb_dir}/proj/{module_name}; module_id={module_id} {cmd_ipbb_project} && {cmd_ipbb_synth} && {cmd_ipbb_impl} && {cmd_ipbb_bitfile}"'.format( **locals()) session = "build_{project_type}_{args.build}_{module_id}".format( **locals()) logging.info("starting screen session '%s' for module %s ...", session, module_id) run_command('screen', '-dmS', session, command) # list running screen sessions logging.info( "===========================================================================" ) run_command('screen', '-ls') os.chdir(ipbb_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') # Remove "0x" from args.build build_raw = args.build.split("x", 1) config.set('menu', 'build', build_raw[1]) # Take args.menuname with distribution number config.set('menu', 'name', args.menuname) # Location of menu XML file menu_xml_loc = "{}/xml/{}.xml".format(url_menu, args.menuname) config.set('menu', 'location', menu_xml_loc) config.set('menu', 'modules', modules) config.add_section('ipbb') config.set('ipbb', 'version', ipbb_version) config.add_section('vivado') config.set('vivado', 'version', args.vivado) config.add_section('firmware') config.set('firmware', 'ipburl', args.ipburl) config.set('firmware', 'ipbtag', args.ipb) config.set('firmware', 'mp7url', args.mp7url) config.set('firmware', 'mp7tag', args.mp7tag) config.set('firmware', 'mp7fw_ugt', mp7fw_ugt) config.set('firmware', 'ugturl', args.ugturl) config.set('firmware', 'ugttag', args.ugt) config.set('firmware', 'type', project_type) config.set('firmware', 'buildarea', ipbb_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 configuration file with open('build_{}.cfg'.format(args.build), 'w') as fp: config.write(fp) logging.info("created configuration file: %s/build_%s.cfg.", ipbb_dir, args.build) logging.info("done.")
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) ipbb_dir = os.path.join(args.path, project_type, args.tag, build_name) if os.path.isdir(ipbb_dir): raise RuntimeError("build area alredy exists: {}".format(ipbb_dir)) ipbb_src_fw_dir = os.path.abspath(os.path.join(ipbb_dir, 'src', 'ugt', project_type, 'firmware')) # IPBB commands: creating IPBB area cmd_source_ipbb = "source ipbb-0.2.8/env.sh" cmd_ipbb_init = "ipbb init {ipbb_dir}".format(**locals()) cmd_ipbb_add_ipb = "ipbb add git {args.ipburl} -b {args.ipb}".format(**locals()) cmd_ipbb_add_mp7 = "ipbb add git {args.mp7url} -b {args.tag}_amc502_finor".format(**locals()) cmd_ipbb_add_ugt = "ipbb add git {args.ugturl} -b {args.ugt}".format(**locals()) logging.info("===========================================================================") logging.info("creating IPBB area ...") command = 'bash -c "cd; {cmd_source_ipbb}; {cmd_ipbb_init}; cd {ipbb_dir}; {cmd_ipbb_add_ipb} && {cmd_ipbb_add_mp7} && {cmd_ipbb_add_ugt}"'.format(**locals()) run_command(command) # Removing unused mp7_ugt, mp7_tdf and AMC502 firmware directories logging.info("removing src directories of unused firmware ...") command = 'bash -c "cd; cd {ipbb_dir}/src/ugt; rm -rf mp7_ugt && rm -rf amc502_extcond && rm -rf amc502_finor_pre && rm -rf mp7_tdf"'.format(**locals()) run_command(command) logging.info("patch the target package with current UNIX timestamp/username/hostname ...") top_pkg_tpl = os.path.join(ipbb_src_fw_dir, 'hdl', 'top_decl_tpl.vhd') top_pkg = os.path.join(ipbb_src_fw_dir, 'hdl', 'top_decl.vhd') subprocess.check_call(['python', os.path.join(ipbb_src_fw_dir, '..', 'scripts', 'pkgpatch.py'), '--build', args.build, top_pkg_tpl, top_pkg]) # Vivado settings settings64 = os.path.join(VIVADO_BASE_DIR, args.vivado, 'settings64.sh') if not os.path.isfile(settings64): raise RuntimeError( "no such Xilinx Vivado settings file '{settings64}'\n" \ " check if Xilinx Vivado {args.vivado} is installed on this machine.".format(**locals()) ) logging.info("creating IPBB project ...") cmd_ipbb_proj_create = "ipbb proj create vivado {project_type}_{build_name} mp7:../ugt/{project_type}".format(**locals()) command = 'bash -c "cd; {cmd_source_ipbb}; cd {ipbb_dir}; {cmd_ipbb_proj_create}"'.format(**locals()) run_command(command) logging.info("running IPBB project, synthesis and implementation, creating bitfile ...") # IPBB commands: running IPBB project, synthesis and implementation, creating bitfile cmd_ipbb_project = "ipbb vivado project" cmd_ipbb_synth = "ipbb vivado synth" cmd_ipbb_impl = "ipbb vivado impl" cmd_ipbb_bitfile = "ipbb vivado package" command = 'bash -c "cd; {cmd_source_ipbb}; source {settings64}; cd {ipbb_dir}/proj/{project_type}_{build_name}; {cmd_ipbb_project} && {cmd_ipbb_synth} && {cmd_ipbb_impl} && {cmd_ipbb_bitfile}"'.format(**locals()) session = "build_{project_type}_{build_name}".format(**locals()) logging.info("starting screen session '%s' ...", session) run_command('screen', '-dmS', session, command) # list running screen sessions run_command('screen', '-ls') os.chdir(ipbb_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('firmware') config.set('firmware', 'ipb URL', args.ipburl) config.set('firmware', 'ipb branch', args.ipb) config.set('firmware', 'mp7 URL', args.mp7url) config.set('firmware', 'mp7 tag', args.tag) config.set('firmware', 'ugt URL', args.ugturl) config.set('firmware', 'ugt branch', args.ugt) config.set('firmware', 'type', FW_TYPE) config.set('firmware', 'buildarea', ipbb_dir) config.set('firmware', 'build', args.build) config.add_section('device') config.set('device', 'type', args.board) config.set('device', 'name', BOARD_TYPE) config.set('device', 'alias', BoardAliases[args.board]) # Writing configuration file with open('build_0x{}.cfg'.format(args.build), 'wb') as fp: config.write(fp) logging.info("created configuration file: %s/build_0x%s.cfg.", ipbb_dir, args.build) logging.info("done.")
def main(): """Main routine.""" # Parse command line arguments. args = parse_args() # Setup console logging logging.basicConfig(format = '%(levelname)s: %(message)s', level = logging.DEBUG) # with tarfile config = ConfigParser.RawConfigParser() config.read(args.config) for section in config.sections(): print section for option in config.options(section): print " ", option, "=", config.get(section, option) menu = config.get('menu', 'name') location = config.get('menu', 'location') build = tb.build_t(config.get('menu', 'build')) # format 'ffff' board = config.get('device', 'alias') buildarea = config.get('firmware', 'buildarea') timestamp = tb.timestamp() basename = "{menu}_v{build}_{board}".format(**locals()) basepath = os.path.dirname(args.config) # Custom output directory? if args.outdir: basepath = args.outdir filename = os.path.join(basepath, "{basename}-{timestamp}.tar.gz".format(**locals())) tmpdir = tempfile.mkdtemp() logging.info("Created temporary dircetory %s", tmpdir) for i in range(len(glob.glob(os.path.join(buildarea, 'module_*')))): logging.info("collecting data from module %s", i) module_dir = 'module_{i}'.format(**locals()) build_dir = os.path.join(tmpdir, module_dir, 'build') log_dir = os.path.join(tmpdir, module_dir, 'log') os.makedirs(build_dir) os.makedirs(log_dir) shutil.copy(os.path.join(buildarea, module_dir, 'top', 'top.runs', 'impl_1', 'top.bit'), os.path.join(build_dir, 'gt_mp7_{board}_v{build}_module_{i}.bit'.format(**locals()))) shutil.copy(os.path.join(buildarea, module_dir, 'vivado.log'), log_dir) logging.info("adding build configuration: %s", args.config) shutil.copy(args.config, tmpdir) xml_file = os.path.join(location, 'xml', '{menu}.xml'.format(**locals())) logging.info("adding XML menu: %s", xml_file) shutil.copy(xml_file, tmpdir) logging.info("creating tarball: %s", filename) tar = tarfile.open(filename, "w:gz") logging.info("adding to tarball: %s", tmpdir) tar.add(tmpdir, arcname=basename, recursive=True) logging.info("closing tarball: %s", filename) tar.close() logging.info("removing temporary directory %s.", tmpdir) shutil.rmtree(tmpdir) logging.info("done.")