Пример #1
0
def _build_ise(prj, hwdir):
    hwdir = hwdir if hwdir is not None else prj.basedir + ".hw"

    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;
	  cd """ + hwdir + """ &&
	  echo -e "run hwclean\nrun bits\nexit\n" | xps -nw system""",
                    shell=True)

    print()

    with open(shutil2.join(hwdir, "implementation", "system.bin"), "rb") as b:
        with open(shutil2.join(hwdir, "implementation", "system.bin.rev"),
                  "wb") as r:
            while True:
                word = b.read(4)
                if not word:
                    break
                r.write(word[::-1])

    shutil2.chdir(prj.dir)
Пример #2
0
def _export_hw_ise(prj, hwdir, link):
    ''' 
	Generates the project directory for an ISE/XPS project.
	
	It first compiles the configuration dictionary and then processes the templates
	according to the configuration dictionary.
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	'''
    hwdir = hwdir if hwdir is not None else prj.basedir + ".hw"

    log.info("Export hardware to directory '" + hwdir + "'")

    dictionary = get_dict(prj)

    log.info("Generating export files ...")
    tmpl = "ref_" + prj.impinfo.os + "_" + "_".join(
        prj.impinfo.board
    ) + "_" + prj.impinfo.design + "_" + prj.impinfo.xil[1]
    prj.apply_template(tmpl, dictionary, hwdir, link)

    log.info("Generating threads ...")
    for t in prj.threads:
        export_hw_thread(prj, shutil2.join(hwdir, "pcores"), link, t.name)
Пример #3
0
def export_sim_ise(args, simdir, link, thread):
	prj = args.prj
	simdir = simdir if simdir is not None else prj.basedir + ".sim" + "." + thread.lower()

	log.info("Generating testbench for thread " + thread + " to '" + simdir + "'")

	threads = [_ for _ in prj.threads if _.name == thread]
	if (len(threads) == 1):
		thread = threads[0]

		if thread.hwsource is None:
			log.error("No hardware source specified")
	else:
		log.error("Thread '" + thread  + "' not found")
		return

	tmp = tempfile.TemporaryDirectory()
	reconos.scripts.hw.export.export_hw_thread(args, tmp.name, link, thread.name)

	dictionary = {}
	dictionary["THREAD"] = thread.name.lower()
	srcs = shutil2.join(tmp.name, "rt_" + thread.name.lower() + "_v1_00_a", "hdl", "vhdl")
	dictionary["SOURCES"] = [srcs]
	files = shutil2.listfiles(srcs, True)
	dictionary["FILES"] = [{"File": _} for _ in files]

	log.info("Generating export files ...")
	tmpl = "sim_testbench_" + prj.impinfo.xil[1]
	prj.apply_template(tmpl, dictionary, simdir, link)
Пример #4
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)
Пример #5
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)
Пример #6
0
def _export_hw_vivado(prj, hwdir, link):
    ''' 
	Generates a TCL script for generation of a Vivado based project.
	
	It first compiles the configuration dictionary and then processes the templates
	according to the configuration dictionary.
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	'''

    print("export_hw_vivado")
    hwdir = hwdir if hwdir is not None else prj.basedir + ".hw"

    log.info("Export hardware to directory '" + hwdir + "'")

    dictionary = get_dict(prj)

    log.info("Generating export files ...")

    tmpl = "ref_" + prj.impinfo.os + "_" + "_".join(
        prj.impinfo.board) + "_" + prj.impinfo.design + "_" + prj.impinfo.xil[
            0] + "_" + prj.impinfo.xil[1]
    print("Using template directory " + tmpl)
    # TODO: No error message when template directory is not found!
    prj.apply_template(tmpl, dictionary, hwdir, link)

    log.info("Generating threads ...")
    for t in prj.threads:
        export_hw_thread(prj, shutil2.join(hwdir, "pcores"), link, t.name)

    print("Calling TCL script to generate Vivado IP Repository")
    result = subprocess.call("""
					source /opt/Xilinx/Vivado/{1}/settings64.sh;
					cd {0};
					vivado -mode batch -notrace -nojournal -nolog -source create_ip_library.tcl;"""
                             .format(hwdir, prj.impinfo.xil[1]),
                             shell=True,
                             executable='/bin/bash')
    if result != 0:
        print(
            "[RDK] Generation of Vivado IP repository failed. Maybe you specified unknown components in build.cfg?"
        )
        exit(1)

    print("Calling TCL script to generate ReconOS in Vivado IP Integrator")
    subprocess.call("""
					source /opt/Xilinx/Vivado/{1}/settings64.sh;
					cd {0};
					vivado -mode batch -notrace -nojournal -nolog -source export.tcl -tclargs -proj_name myReconOS -proj_path . ;"""
                    .format(hwdir, prj.impinfo.xil[1]),
                    shell=True,
                    executable='/bin/bash')
Пример #7
0
def _export_hw_vivado(prj, hwdir, link):
	''' 
	Generates a TCL script for generation of a Vivado based project.
	
	It first compiles the configuration dictionary and then processes the templates
	according to the configuration dictionary.
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	'''
	
	print("export_hw_vivado")
	hwdir = hwdir if hwdir is not None else prj.basedir + ".hw"

	log.info("Export hardware to directory '" + hwdir + "'")

	dictionary = get_dict(prj)

	log.info("Generating export files ...")
	
	
	tmpl = "ref_" + prj.impinfo.os + "_" + "_".join(prj.impinfo.board) + "_" + prj.impinfo.design + "_" + prj.impinfo.xil[0] + "_" + prj.impinfo.xil[1]
	print("Using template directory " + tmpl)
	# TODO: No error message when template directory is not found!
	prj.apply_template(tmpl, dictionary, hwdir, link)

	log.info("Generating threads ...")
	for t in prj.threads:
		export_hw_thread(prj, shutil2.join(hwdir, "pcores"), link, t.name)
		
	print("Calling TCL script to generate Vivado IP Repository")
	result = subprocess.call("""
					source /opt/Xilinx/Vivado/{1}/settings64.sh;
					cd {0};
					vivado -mode batch -notrace -nojournal -nolog -source create_ip_library.tcl;""".format(hwdir, prj.impinfo.xil[1]),
					shell=True)
	if result != 0 :
		print("[RDK] Generation of Vivado IP repository failed. Maybe you specified unknown components in build.cfg?")
		exit(1)
	
	print("Calling TCL script to generate ReconOS in Vivado IP Integrator")
	subprocess.call("""
					source /opt/Xilinx/Vivado/{1}/settings64.sh;
					cd {0};
					vivado -mode batch -notrace -nojournal -nolog -source export.tcl -tclargs -proj_name myReconOS -proj_path . ;""".format(hwdir, prj.impinfo.xil[1]),
					shell=True)
Пример #8
0
def export_hw_vivado(args, hwdir, link):
	''' 
	Generates a TCL script for generation of a Vivado based project.
	
	It first compiles the configuration dictionary and then processes the templates
	according to the configuration dictionary.
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	'''
	
	print("export_hw_vivado")
	prj = args.prj
	hwdir = hwdir if hwdir is not None else prj.basedir + ".hw"

	log.info("Export hardware to directory '" + hwdir + "'")

	dictionary = get_dict(prj)

	log.info("Generating export files ...")
	
	
	tmpl = "ref_" + prj.impinfo.os + "_" + "_".join(prj.impinfo.board) + "_" + prj.impinfo.design + "_" + prj.impinfo.xil[0] + "_" + prj.impinfo.xil[1]
	print("Using template directory " + tmpl)
	# TODO: No error message when template directory is not found!
	prj.apply_template(tmpl, dictionary, hwdir, link)

	log.info("Generating threads ...")
	for t in prj.threads:
		export_hw_thread(args, shutil2.join(hwdir, "pcores"), link, t.name)
		
	print("Calling TCL script to generate Vivado IP Repository")
	subprocess.call("""
					source /opt/Xilinx/SDSoC/{1}/settings64.sh;
					cd {0};
					vivado -mode batch -notrace -nojournal -nolog -source create_ip_library.tcl;""".format(hwdir, prj.impinfo.xil[1]),
					shell=True)
	
	print("Calling TCL script to generate ReconOS in Vivado IP Integrator")
	subprocess.call("""
					source /opt/Xilinx/SDSoC/{1}/settings64.sh;
					cd {0};
					vivado -mode batch -source system.tcl -tclargs -proj_name myReconOS -proj_path . -hwts rt_matrixmul,rt_matrixmul;""".format(hwdir, prj.impinfo.xil[1]),
					# vivado -mode batch -notrace -nojournal -nolog -source system.tcl -tclargs -proj_name myReconOS -proj_path . -hwts rt_matrixmul,rt_matrixmul;""".format(hwdir, prj.impinfo.xil[1]),
					shell=True)
Пример #9
0
def export_sw_thread(args, swdir, link, thread):
    prj = args.prj
    swdir = swdir if swdir is not None else prj.basedir + ".sw" + "." + thread.lower(
    )

    log.info("Exporting thread " + thread + " to directory '" + swdir + "'")

    threads = [_ for _ in prj.threads if _.name == thread]
    if (len(threads) == 1):
        thread = threads[0]

        if thread.swsource is None:
            log.info("No software source specified")
            return
    else:
        log.info("Thread '" + thread + "' not found")
        return

    dictionary = {}
    dictionary["NAME"] = thread.name.lower()
    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["Id"] = r.id
        d["HexId"] = "%08x" % r.id
        d["LocalId"] = i
        d["HexLocalId"] = "%08x" % i
        d["Type"] = r.type
        d["TypeUpper"] = r.type.upper()
        dictionary["RESOURCES"].append(d)
    dictionary["SOURCES"] = [
        shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                     thread.swsource)
    ]

    log.info("Generating export files ...")
    if thread.swsource == "c":
        prj.apply_template("thread_c_plain", dictionary, swdir, link)
    elif thread.swsource == "hls":
        prj.apply_template("thread_c_hls", dictionary, swdir, link)
Пример #10
0
def export_hls_ise(args, hlsdir, link, thread):
	prj = args.prj
	hlsdir = hlsdir if hlsdir is not None else prj.basedir + ".hls" + "." + thread.lower()

	log.info("Generating hls project for thread " + thread + " to '" + hlsdir + "'")

	threads = [_ for _ in prj.threads if _.name == thread]
	if (len(threads) == 1):
		thread = threads[0]

		if thread.hwsource is None or not thread.hwsource == "hls":
			log.error("No hardware source specified")
	else:
		log.error("Thread '" + thread  + "' not found")
		return

	dictionary = {}
	dictionary["PART"] = prj.impinfo.part
	dictionary["NAME"] = thread.name.lower()
	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["HLSDIR"] = hlsdir
	dictionary["MEM"] = thread.mem
	dictionary["MEM_N"] = not thread.mem
	dictionary["RESOURCES"] = []
	for i, r in enumerate(thread.resources):
		d = {}
		d["Id"] = r.id
		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 export files ...")
	prj.apply_template("thread_hls_prj", dictionary, hlsdir)
Пример #11
0
def _export_hw_ise(prj, hwdir, link):
	''' 
	Generates the project directory for an ISE/XPS project.
	
	It first compiles the configuration dictionary and then processes the templates
	according to the configuration dictionary.
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	'''
	hwdir = hwdir if hwdir is not None else prj.basedir + ".hw"

	log.info("Export hardware to directory '" + hwdir + "'")

	dictionary = get_dict(prj)

	log.info("Generating export files ...")
	tmpl = "ref_" + prj.impinfo.os + "_" + "_".join(prj.impinfo.board) + "_" + prj.impinfo.design + "_" + prj.impinfo.xil[1]
	prj.apply_template(tmpl, dictionary, hwdir, link)

	log.info("Generating threads ...")
	for t in prj.threads:
		export_hw_thread(prj, shutil2.join(hwdir, "pcores"), link, t.name)
Пример #12
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 = {}
        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")
Пример #13
0
def export_sw(args, swdir, link):
	prj = args.prj
	swdir = swdir if swdir is not None else prj.basedir + ".sw"

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

	dictionary = {}
	dictionary["NAME"] = prj.name.lower()
	dictionary["CFLAGS"] = prj.impinfo.cflags
	dictionary["LDFLAGS"] = prj.impinfo.ldflags
	dictionary["THREADS"] = []
	for t in prj.threads:
		d = {}
		d["Name"] = t.name.lower()
		d["Slots"] = ",".join([str(_.id) for _ in t.slots])
		d["SlotCount"] = len(t.slots)
		d["Resources"] = ",".join(["&" + (_.group + "_" + _.name).lower() + "_res" for _ in t.resources])
		d["ResourceCount"] = len(t.resources)
		d["HasHw"] = t.hwsource is not None
		d["HasSw"] = t.swsource is not None
		dictionary["THREADS"].append(d)
	dictionary["RESOURCES"] = []
	for r in prj.resources:
		d = {}
		d["Id"] = r.id
		d["NameUpper"] = (r.group + "_" + r.name).upper()
		d["NameLower"] = (r.group + "_" + r.name).lower()
		d["Type"] = r.type
		d["TypeUpper"] = r.type.upper()
		d["Args"] = ", ".join(r.args)
		d["Id"] = r.id
		dictionary["RESOURCES"].append(d)
	dictionary["CLOCKS"] = []
	for c in prj.clocks:
		d = {}
		d["NameLower"] = c.name.lower()
		d["Id"] = c.id
		param = c.get_pllparam(800000000, 1600000000, 100000000)
		d["M"] = param[0]
		d["O"] = param[1]
		dictionary["CLOCKS"].append(d)

	srcs = shutil2.join(prj.dir, "src", "application")
	dictionary["SOURCES"] = [srcs]

	log.info("Generating export files ...")
	templ = "app_" + prj.impinfo.os
	prj.apply_template(templ, dictionary, swdir, link)

	log.info("Generating threads ...")
	for t in prj.threads:
		export_sw_thread(args, swdir, link, t.name)

	dictionary = {}
	dictionary["OS"] = prj.impinfo.os.lower()
	dictionary["BOARD"] = "_".join(prj.impinfo.board)
	dictionary["REPO_REL"] = shutil2.relpath(prj.impinfo.repo, swdir)
	dictionary["OBJS"] = [{"Source": shutil2.trimext(_) + ".o"}
	                       for _ in shutil2.listfiles(swdir, True, "c[p]*$")]

	template.preproc(shutil2.join(swdir, "Makefile"), dictionary, "overwrite", force=True)
Пример #14
0
 def get_swtref(self, thread):
     return shutil2.join(self.impinfo.repo, "templates", "export_sw",
                         "thread_" + thread.swsource)
Пример #15
0
 def get_hwtref(self, thread):
     return shutil2.join(self.impinfo.repo, "templates", "export_hw",
                         self.impinfo.xil[0], "thread_" + thread.hwsource)
Пример #16
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)
Пример #17
0
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)
Пример #18
0
def export_sw(args, swdir, link):
    prj = args.prj
    swdir = swdir if swdir is not None else prj.basedir + ".sw"

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

    dictionary = {}
    dictionary["NAME"] = prj.name.lower()
    dictionary["CFLAGS"] = prj.impinfo.cflags
    dictionary["LDFLAGS"] = prj.impinfo.ldflags
    dictionary["THREADS"] = []
    dictionary["ROSMsgHeader"] = ""
    for t in prj.threads:
        d = {}
        d["Name"] = t.name.lower()
        d["Slots"] = ",".join([str(_.id) for _ in t.slots])
        d["SlotCount"] = len(t.slots)
        d["Resources"] = ",".join([
            "&" + (_.group + "_" + _.name).lower() + "_res"
            for _ in t.resources
        ])
        d["ResourceCount"] = len(t.resources)
        d["HasHw"] = t.hwsource is not None
        d["HasSw"] = t.swsource is not None
        dictionary["THREADS"].append(d)
    dictionary["RESOURCES"] = []
    for r in prj.resources:
        d = {}

        d["Group"] = r.group.lower()
        d["Id"] = r.id
        d["NameUpper"] = (r.group + "_" + r.name).upper()
        d["NameLower"] = (r.group + "_" + r.name).lower()
        d["Type"] = r.type
        d["TypeUpper"] = r.type.upper()
        if r.type == "rossub":
            for msg in prj.resources:
                if msg.name == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_message_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    break

        elif r.type == "rospub":
            for msg in prj.resources:
                if msg.name == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_message_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2]
                    break

        elif r.type == "rossrvs":
            for msg in prj.resources:
                print(msg.name.replace('_req', '') + ";" + r.args[1] + ";")
                if msg.name.replace('_req', '') == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_service_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    print(d["Args"])
                    break
        elif r.type == "rossrvc":
            for msg in prj.resources:
                print(msg.name.replace('_req', '') + ";" + r.args[1] + ";")
                if msg.name.replace('_req', '') == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_service_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    print(d["Args"])
                    break
        elif r.type == "rosactions":
            for msg in prj.resources:
                print(
                    msg.name.replace('_goal_req', '') + ";" + r.args[1] + ";")
                if msg.name.replace('_goal_req', '') == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_action_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    print(d["Args"])
                    break
        elif r.type == "rosactionc":
            for msg in prj.resources:
                print(
                    msg.name.replace('_goal_req', '') + ";" + r.args[1] + ";")
                if msg.name.replace('_goal_req', '') == r.args[1]:
                    d["Args"] = r.args[
                        0] + "," + "rosidl_typesupport_c__get_action_type_support_handle__" + msg.args[
                            0] + "__" + msg.args[1] + "__" + msg.args[
                                2] + "(), " + r.args[2] + ", " + r.args[3]
                    print(d["Args"])
                    break
        else:
            d["Args"] = ", ".join(r.args)
        d["Id"] = r.id
        if r.type == "rosmsg":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2]
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "
                dictionary["ROSMsgHeader"] += ("#include <" + r.args[0] + "/" +
                                               r.args[1] + "/" + r.args[2] +
                                               ".h>\n").lower()
            elif len(r.args) == 4:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__Sequence"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__Sequence__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "__Sequence__destroy"
                d["ROSDataTypeSequenceLength"] = r.args[3]
        if r.type == "rossrvmsgreq":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "
                dictionary["ROSMsgHeader"] += ("#include <" + r.args[0] + "/" +
                                               r.args[1] + "/" + r.args[2] +
                                               ".h>\n").lower()
        if r.type == "rossrvmsgres":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        if r.type == "rosactionmsggoalreq":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_SendGoal_Request"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_SendGoal_Request" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_SendGoal_Request" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "
                dictionary["ROSMsgHeader"] += ("#include <" + r.args[0] + "/" +
                                               r.args[1] + "/" + r.args[2] +
                                               ".h>\n").lower()
        if r.type == "rosactionmsggoalres":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Response" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        if r.type == "rosactionmsgresultreq":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_Request" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        if r.type == "rosactionmsgresultres":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_GetResult_Response"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_GetResult_Response" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_GetResult_Response" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        if r.type == "rosactionmsgfeedback":
            if len(r.args) == 3:
                d["ROSDataType"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_FeedbackMessage"
                d["ROSDataTypeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_FeedbackMessage" + "__create"
                d["ROSDataTypeDeInitFunc"] = r.args[0] + "__" + r.args[
                    1] + "__" + r.args[2] + "_FeedbackMessage" + "__destroy"
                d["ROSDataTypeSequenceLength"] = " "

        dictionary["RESOURCES"].append(d)
    dictionary["CLOCKS"] = []
    for c in prj.clocks:
        d = {}
        d["NameLower"] = c.name.lower()
        d["Id"] = c.id
        param = c.get_pllparam(800000000, 1600000000, 100000000)
        d["M"] = param[0]
        d["O"] = param[1]
        dictionary["CLOCKS"].append(d)

    srcs = shutil2.join(prj.dir, "src", "application")
    dictionary["SOURCES"] = [srcs]

    log.info("Generating export files ...")
    templ = "app_" + prj.impinfo.os
    prj.apply_template(templ, dictionary, swdir, link)

    log.info("Generating threads ...")
    for t in prj.threads:
        export_sw_thread(args, swdir, link, t.name)

    dictionary = {}
    dictionary["OS"] = prj.impinfo.os.lower()
    dictionary["BOARD"] = "_".join(prj.impinfo.board)
    dictionary["REPO_REL"] = shutil2.relpath(prj.impinfo.repo, swdir)
    dictionary["OBJS"] = [{
        "Source": shutil2.trimext(_) + ".o"
    } for _ in shutil2.listfiles(swdir, True, "c[cp]*$")]

    template.preproc(shutil2.join(swdir, "Makefile"),
                     dictionary,
                     "overwrite",
                     force=True)
Пример #19
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 = {}
		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")