Skip to content

Commit

Permalink
scripts: genpinctrl: detect XML namespace automatically
Browse files Browse the repository at this point in the history
This commit modifies the genpinctrl script to detect
the XML namespace of pin data files automatically.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
  • Loading branch information
mathieuchopstm committed Aug 2, 2024
1 parent 276c2c8 commit 5131bed
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/genpinctrl/genpinctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,42 @@ def get_mcu_signals(data_path, gpio_ip_afs):
return results


def detect_xml_namespace(data_path: Path):
"""
Attempt to detect the XML namespace used in the pindata files automatically.
This removes the need to modify this file when using pin data from sources
other than the official ST repository, which may use a different xmlns.
"""
global NS

mcus_path = data_path / "mcu"
sampled_file = next(mcus_path.glob("STM32*.xml"))

with open(sampled_file, "r") as fd:
line = "<dummy>"
xmlns = None
while len(line) > 0:
line = fd.readline().removeprefix("<").removesuffix(">\n")

#'<Mcu ...>' tag sets XML namespace
if line.startswith("Mcu"):
#Find the XML namespace in tag elements
for e in line.split():
if e.startswith("xmlns="):
xmlns = e
break
break

if xmlns == None:
logger.info(f"Could not determine XML namespace from {sampled_file}")
return
else:
xml_namespace_url = xmlns.removeprefix('xmlns="').removesuffix('"')
NS = "{" + xml_namespace_url + "}"

logger.info(f"Using {NS} as XML namespace.")


def main(data_path, output):
"""Entry point.
Expand All @@ -558,6 +594,8 @@ def main(data_path, output):
pinctrl_template = env.get_template(PINCTRL_TEMPLATE)
readme_template = env.get_template(README_TEMPLATE)

detect_xml_namespace(data_path)

gpio_ip_afs = get_gpio_ip_afs(data_path)
mcu_signals = get_mcu_signals(data_path, gpio_ip_afs)

Expand Down

0 comments on commit 5131bed

Please sign in to comment.