예제 #1
0
파일: template.py 프로젝트: ReconOS/reconos
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)
예제 #2
0
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)
예제 #3
0
파일: export.py 프로젝트: Lien182/ReconROS
def export_msg(args, msgdir, link):
    prj = args.prj
    if not os.path.exists(prj.dir + "/msg/"):
        print("No msg folder, nothing to do.")
    else:

        msgdir = msgdir if msgdir is not None else prj.basedir + ".msg"

        if shutil2.exists(msgdir):
            shutil.rmtree(msgdir)
        shutil2.mkdir(msgdir)

        log.info("Export software to project directory '" + prj.dir + "'")

        msg_packages = [
            f for f in listdir(prj.dir + "/msg/")
            if isdir(join(prj.dir + "/msg/", f))
        ]

        print(msg_packages)

        for msgs_packs in msg_packages:
            dictionary = {}
            dictionary["pkgname"] = msgs_packs
            srv_files = {}
            if shutil2.exists(prj.dir + "/msg/" + msgs_packs + "/srv"):
                srv_files = [
                    f for f in listdir(prj.dir + "/msg/" + msgs_packs + "/srv")
                    if isfile(join(prj.dir + "/msg/" + msgs_packs + "/srv", f))
                ]
                print(srv_files)
            msg_files = {}
            if shutil2.exists(prj.dir + "/msg/" + msgs_packs + "/msg/"):
                msg_files = [
                    f
                    for f in listdir(prj.dir + "/msg/" + msgs_packs + "/msg/")
                    if isfile(join(prj.dir + "/msg/" + msgs_packs +
                                   "/msg/", f))
                ]
                print(msg_files)
            action_files = {}
            if shutil2.exists(prj.dir + "/msg/" + msgs_packs + "/action/"):
                action_files = [
                    f for f in listdir(prj.dir + "/msg/" + msgs_packs +
                                       "/action/")
                    if isfile(
                        join(prj.dir + "/msg/" + msgs_packs + "/action/", f))
                ]
                print(action_files)

            dictionary["interface_files"] = ""
            for f in srv_files:
                dictionary["interface_files"] += '"srv/' + f + '" '

            for f in msg_files:
                dictionary["interface_files"] += '"msg/' + f + '" '

            for f in action_files:
                dictionary["interface_files"] += '"action/' + f + '" '

            print(dictionary["interface_files"])
            prj.apply_template("ros_msg", dictionary,
                               msgdir + "/" + msgs_packs, link)
            if shutil2.exists(prj.dir + "/msg/" + msgs_packs + "/srv/"):
                shutil.copytree(prj.dir + "/msg/" + msgs_packs + "/srv/",
                                msgdir + "/" + msgs_packs + "/srv/")
            if shutil2.exists(prj.dir + "/msg/" + msgs_packs + "/msg/"):
                shutil.copytree(prj.dir + "/msg/" + msgs_packs + "/msg/",
                                msgdir + "/" + msgs_packs + "/msg/")
            if shutil2.exists(prj.dir + "/msg/" + msgs_packs + "/action/"):
                shutil.copytree(prj.dir + "/msg/" + msgs_packs + "/action/",
                                msgdir + "/" + msgs_packs + "/action/")
예제 #4
0
 def get_template(self, name):
     if shutil2.exists(shutil2.join(self.dir, "templates", name)):
         return shutil2.join(self.dir, "templates", name)
     else:
         return shutil2.join(self.impinfo.repo, "templates", name)
예제 #5
0
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 = {}

        #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["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")
예제 #6
0
파일: export.py 프로젝트: Lien182/ReconROS
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)