From 1b22c6c0ad69af41993f619be19f548598ec339f Mon Sep 17 00:00:00 2001 From: Franck Jullien Date: Thu, 24 Feb 2022 21:28:34 +0100 Subject: [PATCH] efinix: add a list of values to fix in xml Sometimes the Python API of the interface designer produce a wrong XML file. Values can be changed in the XML file with this new list. For example: fix_pll = [ # Tag name properties / values ("comp_output_clock", "mipi_clk", [("out_divider", "20")]), ("comp_output_clock", "mipi_tx_clk_fastclk", [("out_divider", "4"), ("phase_setting", "3")]), ("comp_output_clock", "mipi_tx_data_fastclk", [("out_divider", "4"), ("phase_setting", "1")]), ("comp_output_clock", "mipi_tx_slowclk", [("out_divider", "16")]) ] platform.toolchain.ifacewriter.fix_xml += fix_pll --- litex/build/efinix/efinity.py | 4 ++++ litex/build/efinix/ifacewriter.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) 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")