From 38dcf788009211d0e933ff0f28a7442f25e26f59 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 28 Sep 2023 21:30:56 +1000 Subject: [PATCH] peripheral nodes: Add addressBlock Not needed for svd2rust, but documented in CMSIS-SVD as required. Allows output to be loaded into Ghidra via SVD-Loader-Ghidra. --- src/main.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index f86656d..473f817 100644 --- a/src/main.rs +++ b/src/main.rs @@ -235,11 +235,15 @@ fn analyze_periph(periph: &Element, periph_out_e: &mut Element) { desc_e.children.push(XMLNode::Text(format!("{} peripheral", peri))); let mut base_addr_e = Element::new("baseAddress"); base_addr_e.children.push(XMLNode::Text(format!("0x{:0x}", base_addr))); + let mut address_block_e = Element::new("addressBlock"); + add_elem_with_text(&mut address_block_e, "offset", "0x0"); + // Address block size is re-written after iterating each register + add_elem_with_text(&mut address_block_e, "size", "0x0"); + add_elem_with_text(&mut address_block_e, "usage", "registers"); let registers_e = Element::new("registers"); - peri_e.children.push(XMLNode::Element(name_e)); - peri_e.children.push(XMLNode::Element(desc_e)); - peri_e.children.push(XMLNode::Element(base_addr_e)); - peri_e.children.push(XMLNode::Element(registers_e)); + for e in [name_e, desc_e, base_addr_e, address_block_e, registers_e] { + peri_e.children.push(XMLNode::Element(e)); + } periph_out_e.children.push(XMLNode::Element(peri_e)); info!("{} base_addr = {:0x}", peri, base_addr); } @@ -300,6 +304,20 @@ fn analyze_periph(periph: &Element, periph_out_e: &mut Element) { ); } info!(""); + + // Update the address block size + periph_out_e + .children + .last_mut() + .unwrap() + .as_mut_element() + .unwrap() + .get_mut_child("addressBlock") + .unwrap() + .get_mut_child("size") + .unwrap() + // Allow space for 4 registers, even if not all are defined + .children[0] = XMLNode::Text(format!("{:#x}", offset + 0x10)); } } }