diff --git a/edalize/tools/efinity.py b/edalize/tools/efinity.py index f62d4ed65..7987c3724 100644 --- a/edalize/tools/efinity.py +++ b/edalize/tools/efinity.py @@ -31,6 +31,26 @@ class Efinity(Edatool): "type": "str", "desc": "Speed grade (e.g. C4)", }, + "ip_gen": { + "type": "dict", + "desc": "IP generator", + "list": True, + }, + "bitstream_gen": { + "type": "dict", + "desc": "Bitstream generator options", + "list": True, + } + } + + BITSTREAM_MODES = ["active", "passive"] + BITSTREAM_FORMATS = ["bit", "bitbin", "hex", "hexbin"] + CLOCK_DIVS = ['DIV1', 'DIV4', 'DIV8'] + + BITSTREAM_GEN_DEFAULTS = { + "mode": "active", + "formats": ["bit", "hex"], + "clk_div": 'DIV8', } def setup(self, edam): @@ -53,6 +73,21 @@ def setup(self, edam): for i in ["family", "part", "timing"]: if not i in self.tool_options: raise RuntimeError("Missing required option '{}'".format(i)) + + for default in self.BITSTREAM_GEN_DEFAULTS: + if not default in self.tool_options['bitstream_gen']: + self.tool_options['bitstream_gen'][default] = self.BITSTREAM_GEN_DEFAULTS[default] + + if not self.tool_options['bitstream_gen']['mode'] in self.BITSTREAM_MODES: + raise RuntimeError("Invalid bitstream_gen mode: {}".format(self.tool_options['bitstream_gen']['mode'])) + + for format in self.tool_options['bitstream_gen']['formats']: + if not format in self.BITSTREAM_FORMATS: + raise RuntimeError("Invalid bitstream_gen format: {}".format(format)) + + if not self.tool_options['bitstream_gen']['clk_div'] in self.CLOCK_DIVS: + raise RuntimeError("Invalid bitstream_gen clk_div: {}".format(self.tool_options['bitstream_gen']['clk_div'])) + design_files = [] constr_files = [] @@ -124,6 +159,25 @@ def setup(self, edam): ) dep_files.append(self.name + ".peri.xml") + # Add command to generate IP + if "ip_gen" in self.tool_options: + for ip_config in self.tool_options.get("ip_gen"): + module_name = ip_config.get("module_name") + commands.add( + [ + self.efinity_python, + "gen_ip_" + module_name + ".py", + self.name, + self.tool_options.get("part"), + ], + [self.name + "_" + module_name], + [], + variables={ + "EFXIPM_HOME": self.efinity_home + "/ipm", + }, + ) + dep_files.append(self.name + "_" + module_name) + commands.add( [ self.efinity_python, @@ -140,6 +194,7 @@ def setup(self, edam): "EFXPGM_HOME": self.efinity_home + "/pgm", }, ) + commands.set_default_target(bit_file) self.commands = commands @@ -152,3 +207,10 @@ def write_config_files(self): if self.isf_file: # Create XML file with IO and hard blocks definitions self.render_template("isf_to_xml.py", "isf_to_xml.py") + if "ip_gen" in self.tool_options: + for ip_config in self.tool_options.get("ip_gen"): + self.render_template( + "gen_ip.py.j2", + "gen_ip_" + ip_config.get("module_name") + ".py", + ip_config, + ) diff --git a/edalize/tools/templates/efinity/gen_ip.py.j2 b/edalize/tools/templates/efinity/gen_ip.py.j2 new file mode 100644 index 000000000..1670c013d --- /dev/null +++ b/edalize/tools/templates/efinity/gen_ip.py.j2 @@ -0,0 +1,48 @@ +# Get access to useful python package +import os +import sys + +# Tell python where to get IP Manager's API package +ipm_home = os.environ["EFXIPM_HOME"] +sys.path.append(ipm_home + "/bin") + +from efx_ipmgr import api_v2 +from ipm_api_service.design import IPMDesignAPI +from ipm_api_service.projectxml import ProjectXML + +name = sys.argv[1] +part = sys.argv[2] +workdir = "." + +ipm = IPMDesignAPI( + device_name=part, family_name=name, project_path=workdir, is_verbose=True +) +project_xml_path = workdir + "/" + name + ".xml" +projectxml = ProjectXML(project_xml_path=project_xml_path, is_verbose=True) + +module_name = "{{ module_name }}" +vendor = "{{ vendor }}" +library = "{{ library }}" +name = "{{ name }}" + +ipm.create_ip( + module_name=module_name, + vendor=vendor, + library=library, + name=name, +) + +configs = { + {% for k, v in config.items() %} + "{{k}}": "{{v}}", + {% endfor %} +} + +ipm.config_ip(module_name=module_name, configs=configs) + +success, errors, param = ipm.validate_ip(module_name=module_name) + +if success: + result = ipm.generate_ip(module_name=module_name) + projectxml.add_ip(module_name=module_name) + projectxml.save() diff --git a/edalize/tools/templates/efinity/newproj_tmpl.xml.j2 b/edalize/tools/templates/efinity/newproj_tmpl.xml.j2 index a4e8125ca..bfc1194dd 100644 --- a/edalize/tools/templates/efinity/newproj_tmpl.xml.j2 +++ b/edalize/tools/templates/efinity/newproj_tmpl.xml.j2 @@ -59,13 +59,13 @@ - + - + @@ -75,6 +75,10 @@ + + {% for k in tool_options.bitstream_gen.formats %} + + {% endfor %}