def prefile(filepath, dictionary): old = shutil2.basename(filepath) reg = r"<<(?P<key>[A-Za-z0-9_]+)>>" def repl(m): if m.group("key") in dictionary: return str(dictionary[m.group("key")]) else: return m.string[m.start():m.end()] new = re.sub(reg, repl, old) if (new != old): old = shutil2.join(shutil2.dirname(filepath), old) new = shutil2.join(shutil2.dirname(filepath), new) if shutil2.exists(new): shutil2.rmtree(new) shutil2.rename(old, new)
def clean(args): prj = args.prj swdir = prj.basedir + ".sw" if args.remove: shutil2.rmtree(swdir) else: try: shutil2.chdir(swdir) except: log.error("software directory '" + swdir + "' not found") return subprocess.call("make clean", shell=True) print() shutil2.chdir(prj.dir)
def clean_ise(args): prj = args.prj hwdir = prj.basedir + ".hw" if args.remove: shutil2.rmtree(hwdir) else: try: shutil2.chdir(hwdir) except: log.error("hardware directory '" + hwdir + "' not found") return subprocess.call(""" source /opt/Xilinx/""" + prj.impinfo.xil[1] + """/ISE_DS/settings64.sh; echo -e "run clean\nexit\n" | xps -nw system""", shell=True) print() shutil2.chdir(prj.dir)
def clean_vivado(args): prj = args.prj hwdir = prj.basedir + ".hw" if args.remove: shutil2.rmtree(hwdir) else: try: shutil2.chdir(hwdir) except: log.error("hardware directory '" + hwdir + "' not found") return subprocess.call(""" source /opt/Xilinx/Vivado/{0}/settings64.sh; vivado -mode batch -notrace -nojournal -nolog -source clean.tcl;""".format( prj.impinfo.xil[1]), shell=True) print() shutil2.chdir(prj.dir)
def _export_hw_thread_ise_vivado(prj, hwdir, link, thread): ''' Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project. It checks whether vhdl or hls sources shall be used and generates the hardware thread from the source templates. hwdir gives the name of the project directory link boolean; if true files will be linked instead of copied thread is the name of the hardware thread to generate ''' hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower( ) log.info("Exporting thread " + thread + " to directory '" + hwdir + "'") threads = [_ for _ in prj.threads if _.name == thread] if (len(threads) == 1): thread = threads[0] if thread.hwsource is None: log.info("No hardware source specified") else: log.error("Thread '" + thread + "' not found") return if thread.hwsource == "vhdl": dictionary = {} dictionary["ID"] = thread.id dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem dictionary["CLKPRD"] = min( [_.clock.get_periodns() for _ in thread.slots]) srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource) dictionary["SOURCES"] = [srcs] incls = shutil2.listfiles(srcs, True) dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls] dictionary["RESOURCES"] = [] for i, r in enumerate(thread.resources): d = {} d["NameUpper"] = (r.group + "_" + r.name).upper() d["NameLower"] = (r.group + "_" + r.name).lower() d["LocalId"] = i d["HexLocalId"] = "%08x" % i dictionary["RESOURCES"].append(d) dictionary["PORTS"] = thread.ports log.info("Generating export files ...") prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link) elif thread.hwsource == "hls": tmp = tempfile.TemporaryDirectory() dictionary = {} dictionary["PART"] = prj.impinfo.part dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem dictionary["CLKPRD"] = min( [_.clock.get_periodns() for _ in thread.slots]) srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource) dictionary["SOURCES"] = [srcs] files = shutil2.listfiles(srcs, True) dictionary["FILES"] = [{"File": _} for _ in files] dictionary["RESOURCES"] = [] for i, r in enumerate(thread.resources): d = {} d["NameUpper"] = (r.group + "_" + r.name).upper() d["NameLower"] = (r.group + "_" + r.name).lower() d["LocalId"] = i d["HexLocalId"] = "%08x" % i d["Type"] = r.type d["TypeUpper"] = r.type.upper() dictionary["RESOURCES"].append(d) log.info("Generating temporary HLS project in " + tmp.name + " ...") prj.apply_template("thread_hls_build", dictionary, tmp.name) log.info("Starting Vivado HLS ...") if "bbd" in thread.hwoptions: if "vivado" in thread.hwoptions: subprocess.call(""" source /opt/Xilinx/Vivado/{1}/settings64.sh; cd {0}; vivado_hls -f script_csynth.tcl; vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;""" .format(tmp.name, prj.impinfo.hls[1]), shell=True, executable='/bin/bash') dictionary = {} dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem srcs = shutil2.join(tmp.name, "rt_imp.edn") dictionary["SOURCES"] = [srcs] incls = ["rt_imp.edn"] dictionary["INCLUDES"] = [{"File": _} for _ in incls] else: log.error("No bbd tool found") return log.info("Generating export files ...") prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir) else: subprocess.call(""" source /opt/Xilinx/Vivado/{1}/settings64.sh; cd {0}; vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]), shell=True, executable='/bin/bash') dictionary = {} dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl") dictionary["SOURCES"] = [srcs] incls = shutil2.listfiles(srcs, True) dictionary["INCLUDES"] = [{ "File": shutil2.trimext(_) } for _ in incls] log.info("Generating export files ...") prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir) shutil2.rmtree("/tmp/test") shutil2.mkdir("/tmp/test") shutil2.copytree(tmp.name, "/tmp/test")
def _export_hw_thread_vivado(prj, hwdir, link, thread): ''' Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project. It checks whether vhdl or hls sources shall be used and generates the hardware thread from the source templates. hwdir gives the name of the project directory link boolean; if true files will be linked instead of copied thread is the name of the hardware thread to generate ''' hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower( ) log.info("Exporting thread " + thread + " to directory '" + hwdir + "'") threads = [_ for _ in prj.threads if _.name == thread] if (len(threads) == 1): thread = threads[0] if thread.hwsource is None: log.info("No hardware source specified") else: log.error("Thread '" + thread + "' not found") return if thread.hwsource == "vhdl": dictionary = {} dictionary["ID"] = thread.id dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem dictionary["CLKPRD"] = min( [_.clock.get_periodns() for _ in thread.slots]) dictionary["HWSOURCE"] = thread.hwsource # "reconf" thread for partial reconfiguration is taken from template directory if prj.impinfo.pr == "true" and thread.name.lower() == "reconf": srcs = shutil2.join(prj.get_template("thread_rt_reconf"), thread.hwsource) else: srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource) dictionary["SOURCES"] = [srcs] incls = shutil2.listfiles(srcs, True) dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls] dictionary["RESOURCES"] = [] for i, r in enumerate(thread.resources): d = {} d["NameUpper"] = (r.group + "_" + r.name).upper() d["NameLower"] = (r.group + "_" + r.name).lower() d["LocalId"] = i d["HexLocalId"] = "%08x" % i dictionary["RESOURCES"].append(d) dictionary["PORTS"] = thread.ports log.info("Generating export files ...") prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link) #For each slot: Generate .prj file listing sources for PR flow if thread.slots[0].reconfigurable == "true": for _ in thread.slots: dictionary["SLOTID"] = _.id prj.apply_template("thread_prj", dictionary, hwdir, link) elif thread.hwsource == "hls": tmp = tempfile.TemporaryDirectory() dictionary = {} #Added dictionary["MSGINCLUDEDIR"] = "" msg_install_path = prj.dir + "/build.msg/install/" if shutil2.exists(msg_install_path): msg_packages = [ f for f in listdir(msg_install_path) if isdir(join(msg_install_path, f)) ] #print(msg_packages) for msg_pack in msg_packages: dictionary[ "MSGINCLUDEDIR"] += "-I" + msg_install_path + msg_pack + "/include/ " #End Added dictionary["PART"] = prj.impinfo.part dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem dictionary["HWSOURCE"] = thread.hwsource dictionary["CLKPRD"] = min( [_.clock.get_periodns() for _ in thread.slots]) # "reconf" thread for partial reconfiguration is taken from template directory if prj.impinfo.pr == "true" and thread.name.lower() == "reconf": srcs = shutil2.join(prj.get_template("thread_rt_reconf"), thread.hwsource) else: srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource) dictionary["SOURCES"] = [srcs] files = shutil2.listfiles(srcs, True) dictionary["FILES"] = [{"File": _} for _ in files] dictionary["RESOURCES"] = [] for i, r in enumerate(thread.resources): d = {} d["NameUpper"] = (r.group + "_" + r.name).upper() d["NameLower"] = (r.group + "_" + r.name).lower() d["LocalId"] = i d["HexLocalId"] = "%08x" % i d["Type"] = r.type d["TypeUpper"] = r.type.upper() dictionary["RESOURCES"].append(d) log.info("Generating temporary HLS project in " + tmp.name + " ...") prj.apply_template("thread_hls_build", dictionary, tmp.name) log.info("Starting Vivado HLS ...") if "bbd" in thread.hwoptions: if "vivado" in thread.hwoptions: subprocess.call(""" source /opt/Xilinx/Vivado/{1}/settings64.sh; cd {0}; vivado_hls -f script_csynth.tcl; vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;""" .format(tmp.name, prj.impinfo.hls[1]), shell=True) dictionary = {} dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem srcs = shutil2.join(tmp.name, "rt_imp.edn") dictionary["SOURCES"] = [srcs] incls = ["rt_imp.edn"] dictionary["INCLUDES"] = [{"File": _} for _ in incls] else: log.error("No bbd tool found") return log.info("Generating export files ...") prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir) else: subprocess.call(""" source /opt/Xilinx/Vivado/{1}/settings64.sh; cd {0}; vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]), shell=True) dictionary = {} dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl") #HLS instantiates subcores (e.g. floating point units) in VHDL form during the export step #The path above contains only .tcl instantiations, which our IP Packager flow doesn't understand #So we add extract the convenient .vhd definitions from the following path: srcs2 = shutil2.join(tmp.name, "hls", "sol", "impl", "ip", "hdl", "ip") dictionary["SOURCES"] = [srcs, srcs2] incls = shutil2.listfiles(srcs, True) incls += shutil2.listfiles(srcs2, True) dictionary["INCLUDES"] = [{ "File": shutil2.trimext(_) } for _ in incls] log.info("Generating export files ...") if thread.videoout == 0: prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir) else: print("Found Video Out! \n") prj.apply_template("thread_hls_pcore_video_vhdl", dictionary, hwdir) #For each slot: Generate .prj file listing sources for PR flow if thread.slots[0].reconfigurable == "true": for _ in thread.slots: dictionary["SLOTID"] = _.id prj.apply_template("thread_prj", dictionary, hwdir, link) #Save temporary HLS project directory for analysis: shutil2.mkdir("/tmp/test") save_dir_hls_prj = shutil2.join(hwdir, "..", "tmp_hls_prj_" + thread.name.lower()) shutil2.copytree(tmp.name, "/tmp/test") shutil2.rmtree(save_dir_hls_prj) shutil2.mkdir(save_dir_hls_prj) shutil2.copytree(tmp.name, save_dir_hls_prj)
def _export_hw_thread_ise_vivado(prj, hwdir, link, thread): ''' Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project. It checks whether vhdl or hls sources shall be used and generates the hardware thread from the source templates. hwdir gives the name of the project directory link boolean; if true files will be linked instead of copied thread is the name of the hardware thread to generate ''' hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower() log.info("Exporting thread " + thread + " to directory '" + hwdir + "'") threads = [_ for _ in prj.threads if _.name == thread] if (len(threads) == 1): thread = threads[0] if thread.hwsource is None: log.info("No hardware source specified") else: log.error("Thread '" + thread + "' not found") return if thread.hwsource == "vhdl": dictionary = {} dictionary["ID"] = thread.id dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem dictionary["CLKPRD"] = min([_.clock.get_periodns() for _ in thread.slots]) srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource) dictionary["SOURCES"] = [srcs] incls = shutil2.listfiles(srcs, True) dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls] dictionary["RESOURCES"] = [] for i, r in enumerate(thread.resources): d = {} d["NameUpper"] = (r.group + "_" + r.name).upper() d["NameLower"] = (r.group + "_" + r.name).lower() d["LocalId"] = i d["HexLocalId"] = "%08x" % i dictionary["RESOURCES"].append(d) dictionary["PORTS"] = thread.ports log.info("Generating export files ...") prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link) elif thread.hwsource == "hls": tmp = tempfile.TemporaryDirectory() dictionary = {} dictionary["PART"] = prj.impinfo.part dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem dictionary["CLKPRD"] = min([_.clock.get_periodns() for _ in thread.slots]) srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource) dictionary["SOURCES"] = [srcs] files = shutil2.listfiles(srcs, True) dictionary["FILES"] = [{"File": _} for _ in files] dictionary["RESOURCES"] = [] for i, r in enumerate(thread.resources): d = {} d["NameUpper"] = (r.group + "_" + r.name).upper() d["NameLower"] = (r.group + "_" + r.name).lower() d["LocalId"] = i d["HexLocalId"] = "%08x" % i d["Type"] = r.type d["TypeUpper"] = r.type.upper() dictionary["RESOURCES"].append(d) log.info("Generating temporary HLS project in " + tmp.name + " ...") prj.apply_template("thread_hls_build", dictionary, tmp.name) log.info("Starting Vivado HLS ...") if "bbd" in thread.hwoptions: if "vivado" in thread.hwoptions: subprocess.call(""" source /opt/Xilinx/Vivado/{1}/settings64.sh; cd {0}; vivado_hls -f script_csynth.tcl; vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;""".format(tmp.name, prj.impinfo.hls[1]), shell=True) dictionary = {} dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem srcs = shutil2.join(tmp.name, "rt_imp.edn") dictionary["SOURCES"] = [srcs] incls = ["rt_imp.edn"] dictionary["INCLUDES"] = [{"File": _} for _ in incls] else: log.error("No bbd tool found") return log.info("Generating export files ...") prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir) else: subprocess.call(""" source /opt/Xilinx/Vivado/{1}/settings64.sh; cd {0}; vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]), shell=True) dictionary = {} dictionary["NAME"] = thread.name.lower() dictionary["MEM"] = thread.mem dictionary["MEM_N"] = not thread.mem srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl") dictionary["SOURCES"] = [srcs] incls = shutil2.listfiles(srcs, True) dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls] log.info("Generating export files ...") prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir) shutil2.rmtree("/tmp/test") shutil2.mkdir("/tmp/test") shutil2.copytree(tmp.name, "/tmp/test")