diff --git a/litex/build/efinix/efinity.py b/litex/build/efinix/efinity.py index 757d0a8e4..682dede4c 100644 --- a/litex/build/efinix/efinity.py +++ b/litex/build/efinix/efinity.py @@ -313,6 +313,10 @@ class EfinityToolchain: if self.ifacewriter.xml_blocks or platform.iobank_info: self.ifacewriter.generate_xml_blocks() + # Because the Python API is sometimes bugged, we need to tweak the generated xml + if self.ifacewriter.fix_xml: + self.ifacewriter.fix_xml_values() + # Run if run: # Synthesis/Mapping. diff --git a/litex/build/efinix/ifacewriter.py b/litex/build/efinix/ifacewriter.py index 3220e3a8e..b361ec50f 100644 --- a/litex/build/efinix/ifacewriter.py +++ b/litex/build/efinix/ifacewriter.py @@ -36,6 +36,7 @@ class InterfaceWriter: self.efinity_path = efinity_path self.blocks = [] self.xml_blocks = [] + self.fix_xml = [] self.filename = "" self.platform = None @@ -43,6 +44,25 @@ class InterfaceWriter: self.filename = build_name self.platform = platform + def fix_xml_values(self): + et.register_namespace("efxpt", "http://www.efinixinc.com/peri_design_db") + tree = et.parse(self.filename + ".peri.xml") + root = tree.getroot() + for tag, name, values in self.fix_xml: + for e in tree.iter(): + if (tag in e.tag) and (name == e.get("name")): + for n, v in values: + e.set(n, v) + + xml_string = et.tostring(root, "utf-8") + reparsed = expatbuilder.parseString(xml_string, False) + print_string = reparsed.toprettyxml(indent=" ") + + # Remove lines with only whitespaces. Not sure why they are here + print_string = os.linesep.join([s for s in print_string.splitlines() if s.strip()]) + + tools.write_to_file("{}.peri.xml".format(self.filename), print_string) + def generate_xml_blocks(self): et.register_namespace("efxpt", "http://www.efinixinc.com/peri_design_db") tree = et.parse(self.filename + ".peri.xml")