From c15bfe54e77c3b8f840f8a50ac2672bcdba2855a Mon Sep 17 00:00:00 2001 From: octycs Date: Sat, 11 May 2019 12:59:08 +0200 Subject: [PATCH] Integrate patching in the build process --- Makefile | 8 ++++++-- README.md | 5 +++-- patch/svdpatch.py | 13 +++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c9ed4b1..3803d56 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,13 @@ svd/%.bare.svd: vendor/%.atdf mkdir -p svd atdf2svd $< $@ -# TODO: Implement actual patching svd/%.patched.svd: svd/%.bare.svd - cp $< $@ + if [ -f patch/$*.yaml ] ; then \ + python3 patch/svdpatch.py patch/$*.yaml $< $@; \ + else \ + echo "No patches found for $*"; \ + cp $< $@; \ + fi src/devices/%/mod.full.rs: svd/%.patched.svd mkdir -p $(@D) diff --git a/README.md b/README.md index bc7bffe..6d3b8ce 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ avr-device Auto-generated wrappers around registers for avr chips. ## Usage -You need to have [atdf2svd](https://github.com/Rahix/atdf2svd), [svd2rust](https://github.com/rust-embedded/svd2rust), [form](https://github.com/djmcgill/form), and [rustfmt](https://github.com/rust-lang/rustfmt) installed: +You need to have [atdf2svd](https://github.com/Rahix/atdf2svd), [svd2rust](https://github.com/rust-embedded/svd2rust), [form](https://github.com/djmcgill/form), [rustfmt](https://github.com/rust-lang/rustfmt) and [PyYAML](https://github.com/yaml/pyyaml) installed: ```bash rustup component add rustfmt cargo install form @@ -11,6 +11,7 @@ cargo install svd2rust git clone https://github.com/Rahix/atdf2svd cd atdf2svd cargo install --path . +pip3 install --user pyyaml ``` Next, clone this repo and build the device definitions: @@ -38,7 +39,7 @@ Via the feature you can select which chip you want the register specifications f * `attiny85` ## Internals -*avr-device* is generated using [`atdf2svd`](https://github.com/Rahix/atdf2svd) and [`svd2rust`](https://github.com/rust-embedded/svd2rust). The vendor-provided *atdf* files can be found in `vendor/`. Later on, we intend to add support for patching the svd files because some information in the provided files is not quite as good as it should be (mainly undescriptive names and missing descriptions). +*avr-device* is generated using [`atdf2svd`](https://github.com/Rahix/atdf2svd) and [`svd2rust`](https://github.com/rust-embedded/svd2rust). The vendor-provided *atdf* files can be found in `vendor/`. The intermediate svd files are patched by `svdpatch.py` (Adapted from [`svdpatch.py`](https://github.com/stm32-rs/stm32-rs/blob/master/scripts/svdpatch.py) in [stm32-rs](https://github.com/stm32-rs/stm32-rs)) with device-dependent patches in `patch/`, mainly to improve undescriptive names and missing descriptions. ### Adding a new Chip To add a new chip, download the *atdf* from and place it in `vendor/`. Be sure to name it like the Rust module that should be generated. Next, you need to integrate it into the base crate and build system. Follow what was done in [this commit](https://github.com/Rahix/avr-device/commit/8b1679a89704f5a303a1578b261aa2aee53e1251). Please adhere to the alphabetical sorting that is present so far. diff --git a/patch/svdpatch.py b/patch/svdpatch.py index 8b33776..4dba5a8 100644 --- a/patch/svdpatch.py +++ b/patch/svdpatch.py @@ -3,6 +3,9 @@ svdpatch.py Copyright 2017-2019 Adam Greig. Licensed under the MIT and Apache 2.0 licenses. See LICENSE files for details. + +This script was adapted from stm32-rs (https://github.com/stm32-rs/stm32-rs/blob/master/scripts/svdpatch.py). +To be integrated into the build system, support for an input / output svd argument is added. """ import copy @@ -35,6 +38,8 @@ def parseargs(): """Parse our command line arguments, returns a Namespace of results.""" parser = argparse.ArgumentParser() parser.add_argument("yaml", help="Path to YAML file to load") + parser.add_argument("svd_in", help="Path to the input SVD file") + parser.add_argument("svd_out", help="Path to write the patched SVD file") args = parser.parse_args() return args @@ -774,10 +779,10 @@ def main(): root["_path"] = args.yaml # Load the specified SVD file - if "_svd" not in root: - raise RuntimeError("You must have an svd key in the root YAML file") - svdpath = abspath(args.yaml, root["_svd"]) - svdpath_out = svdpath + ".patched" + svdpath = args.svd_in + if not os.path.exists(svdpath): + raise FileNotFoundError("The input SVD file does not exist") + svdpath_out = args.svd_out svd = ET.parse(svdpath) # Load all included YAML files -- 2.48.1