Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Register derivedFrom and svd updates #256

Closed
wants to merge 10 commits into from

Conversation

jamesmunns
Copy link
Member

@jamesmunns jamesmunns commented Nov 17, 2018

This PR extends #193 (edit: and #190), and also brings support for the changes made in svd-parser, primarily understanding the RegisterCluster type.

@jamesmunns jamesmunns requested a review from a team as a code owner November 17, 2018 21:06
@jamesmunns
Copy link
Member Author

bors try

@bors
Copy link
Contributor

bors bot commented Nov 17, 2018

try

Build failed

@jamesmunns
Copy link
Member Author

Note, I believe this failure may be a regression of svd's ability to parse MSP430 SVDs. The backtrace for this failure (run locally) looks like this:

➜  other-test git:(register-derived-from) ✗ RUST_BACKTRACE=full ../target/release/svd2rust --target msp430 -i ./msp430g2553.svd
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:355:21
stack backtrace:
   0:     0x55dbd43a19b3 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h76492c069e044094
                               at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x55dbd439c488 - std::sys_common::backtrace::_print::h94a018b30274f0aa
                               at libstd/sys_common/backtrace.rs:71
   2:     0x55dbd43a0b74 - std::panicking::default_hook::{{closure}}::ha3ab490579270e44
                               at libstd/sys_common/backtrace.rs:59
                               at libstd/panicking.rs:211
   3:     0x55dbd43a08dd - std::panicking::default_hook::hc3ba68bed94f8a90
                               at libstd/panicking.rs:227
   4:     0x55dbd43a11fe - std::panicking::rust_panic_with_hook::h8380fbfdb3a9ef26
                               at libstd/panicking.rs:476
   5:     0x55dbd43a0da1 - std::panicking::continue_panic_fmt::he5272a22537494ee
                               at libstd/panicking.rs:390
   6:     0x55dbd43a0c85 - rust_begin_unwind
                               at libstd/panicking.rs:325
   7:     0x55dbd43b1d0c - core::panicking::panic_fmt::he3157e9749b52890
                               at libcore/panicking.rs:77
   8:     0x55dbd43b1c3b - core::panicking::panic::h629a30fc6a0298aa
                               at libcore/panicking.rs:52
   9:     0x55dbd4305632 - <svd_parser::svd::device::Device as svd_parser::parse::Parse>::parse::h98591c7a661028b6
  10:     0x55dbd42f0a01 - svd_parser::parse::h534a94050a300c22
  11:     0x55dbd42202a7 - svd2rust::main::h34a3bf77a67818e0
  12:     0x55dbd422f3d2 - std::rt::lang_start::{{closure}}::hc6a90ef6c35166bc
  13:     0x55dbd43a0c22 - std::panicking::try::do_call::h6d19b60204e9d839
                               at libstd/rt.rs:59
                               at libstd/panicking.rs:310
  14:     0x55dbd43aeac9 - __rust_maybe_catch_panic
                               at libpanic_unwind/lib.rs:102
  15:     0x55dbd43a1533 - std::rt::lang_start_internal::h62a3cf6eecce6831
                               at libstd/panicking.rs:289
                               at libstd/panic.rs:398
                               at libstd/rt.rs:58
  16:     0x55dbd4224cc4 - main
  17:     0x7efcaa486222 - __libc_start_main
  18:     0x55dbd421319d - _start
  19:                0x0 - <unknown>

CC @ryankurte @Emilgardis, I'll dig in to this a bit, and if I find anything, I'll report it upstream to svd.

@jamesmunns jamesmunns changed the title Register derivedFrom and svd updates WIP: Register derivedFrom and svd updates Nov 17, 2018
@jamesmunns
Copy link
Member Author

I'd like @wez to review this before merging, to make sure this change is still necessary. There's some confusion described in nrf-rs/nrf52832-pac#11 (comment)

bors bot added a commit to rust-embedded/svd that referenced this pull request Nov 18, 2018
63: Make the schema field optional r=Emilgardis a=jamesmunns

Some devices that have created fake SVDs, such as for the MSP430, may not have schemas listed.

This fixes the error seen with https://travis-ci.org/rust-embedded/svd2rust/jobs/456451847, See also rust-embedded/svd2rust#256 (comment)

Co-authored-by: James Munns <james.munns@ferrous-systems.com>
@Emilgardis Emilgardis added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. breaking-change and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. breaking-change labels Nov 18, 2018
bors bot added a commit to rust-embedded/svd that referenced this pull request Nov 18, 2018
63: Make the schema field optional r=Emilgardis a=jamesmunns

Some devices that have created fake SVDs, such as for the MSP430, may not have schemas listed.

This fixes the error seen with https://travis-ci.org/rust-embedded/svd2rust/jobs/456451847, See also rust-embedded/svd2rust#256 (comment)

Co-authored-by: James Munns <james.munns@ferrous-systems.com>
bors bot added a commit to rust-embedded/svd that referenced this pull request Nov 18, 2018
63: Make the schema field optional r=Emilgardis a=jamesmunns

Some devices that have created fake SVDs, such as for the MSP430, may not have schemas listed.

This fixes the error seen with https://travis-ci.org/rust-embedded/svd2rust/jobs/456451847, See also rust-embedded/svd2rust#256 (comment)

Co-authored-by: James Munns <james.munns@ferrous-systems.com>
bors bot added a commit to rust-embedded/svd that referenced this pull request Nov 18, 2018
63: Make the schema field optional r=Emilgardis a=jamesmunns

Some devices that have created fake SVDs, such as for the MSP430, may not have schemas listed.

This fixes the error seen with https://travis-ci.org/rust-embedded/svd2rust/jobs/456451847, See also rust-embedded/svd2rust#256 (comment)

Co-authored-by: James Munns <james.munns@ferrous-systems.com>
@Emilgardis
Copy link
Member

ping @wez

@wez
Copy link
Contributor

wez commented Nov 28, 2018

Sorry; have been swamped over the Thanksgiving holidays. I'll take a look over the weekend

@wez
Copy link
Contributor

wez commented Dec 2, 2018

I tested this with https://github.com/atsamd-rs/atsamd/blob/master/update.sh and am sorry to report that it doesn't appear to correctly generate the pmux array. If you run that script and then git diff the repo, you'll see that the dim related attributes don't seem to be inherited, so rather than generating an array, it generates a sequence of wrongly sized registers that it then skips because the size sanity check doesn't pass.

It's not clear to me what the cause of this is; it looks like you pulled in the commits that made it work as-is, and then made some seemingly unrelated changes, so I suspect that something else changed in svd2rust or svd that needs to be accounted for. I didn't have time to fully dig into this

@wez
Copy link
Contributor

wez commented Dec 5, 2018

Ok, I traced the issue; the SVD file declares derivedFrom as an attribute:

        <register derivedFrom="PMUX0_%s">

In my original commit to svd: wez/svd@211ae3e this was being extracted correctly, but in the current svd code this appears to have been accidentally refactored to look at a child element instead.

This patch to the svd parser is needed to fix things:

$ git diff
diff --git a/src/svd/registerinfo.rs b/src/svd/registerinfo.rs
index a075e38..6cab32f 100644
--- a/src/svd/registerinfo.rs
+++ b/src/svd/registerinfo.rs
@@ -59,7 +59,7 @@ impl RegisterInfo {
             name,
             alternate_group: tree.get_child_text_opt("alternateGroup")?,
             alternate_register: tree.get_child_text_opt("alternateRegister")?,
-            derived_from: tree.get_child_text_opt("derivedFrom")?,
+            derived_from: tree.attributes.get("derivedFrom").map(|s| s.to_owned()),
             description: tree.get_child_text("description")?,
             address_offset: tree.get_child_u32("addressOffset")?,
             size: parse::optional::<u32>("size", tree)?,

@ryankurte
Copy link

Ahh, looks like I got that wrong when refactoring svd, sorry!

@wez are you up for opening a PR on svd to fix that (and presumably the corresponding encode function)?, otherwise I can put it on my list.

@Emilgardis Emilgardis mentioned this pull request Jun 1, 2019
Emilgardis
Emilgardis previously approved these changes Jun 1, 2019
@Emilgardis
Copy link
Member

Emilgardis commented Jun 1, 2019

bors try

::Ninja Edit
Is gh notifications still down?

@ryankurte
Copy link

hmm bors queue says pending, but there's a crash in the log. i found a closed issue about not working with branch protection on the staging branch, but, i'm not sure why that would be an issue in this instance.

bors try

@bors
Copy link
Contributor

bors bot commented Jun 2, 2019

try

Already running a review

@Emilgardis
Copy link
Member

bors try-

bors try

bors bot added a commit that referenced this pull request Jun 8, 2019
@bors
Copy link
Contributor

bors bot commented Jun 8, 2019

try

Build succeeded

ryankurte
ryankurte previously approved these changes Jun 10, 2019
* Introduce a logging system.

svd2rust now uses env_logger instead of printing directly to stderr.
env_logger is currently configured to log messages >= info to stderr.

* Fix import of logging macro.

* Remove some noise in the generated code

Struct initialisations don't need to repeat field names if they're equal
to a local variable.

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
@therealprof therealprof dismissed stale reviews from ryankurte and Emilgardis via fbc831f July 15, 2019 08:43
@therealprof
Copy link
Contributor

@jamesmunns Mind rebasing this?

@burrbull
Copy link
Member

Conflicts? Again?

@therealprof
Copy link
Contributor

@burrbull Yeah, just got two PRs merged, that's the one in src/generate/register.rs. src/main.rs is the one which removed extern crate which I though you might have caught.

@burrbull
Copy link
Member

cc @jamesmunns
Please, rebase this PR, or approve #314 .

bors bot added a commit that referenced this pull request Jul 19, 2019
317: Use svd-parser 0.7 and Edition 2018 r=therealprof a=burrbull

Use 2 last commits from #256 :
b6d2c9a and b7965db

cc @therealprof 

Co-authored-by: James Munns <james.munns@ferrous-systems.com>
Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
burrbull pushed a commit to burrbull/svd2rust that referenced this pull request Jul 19, 2019
This removes any observable side effect of the --nightly switch by
removing the use of unions and the untagged_unions feature gate.
Unions are replaced with accessor functions that return the appropriate
register block reference.

Here's a playground link that shows that the pointer calculation looks
reasonable:

https://play.integer32.com/?version=stable&mode=debug&edition=2018&gist=cd56444abc03e6781e526bbddc7082bc

This commit is a breaking change.

This is based on this WIP PR branch:
rust-embedded#256

It implements the easiest standalone portion of this issue:
rust-embedded#218

and also makes accessing the unions "safe" too, which is requested here:
rust-embedded#230
@burrbull burrbull mentioned this pull request Jul 19, 2019
bors bot added a commit that referenced this pull request Jul 19, 2019
319: register Derived from r=therealprof a=burrbull

First three commits from #256 .

cc @therealprof 

Co-authored-by: Nebojsa Sabovic <nsabovic@gmail.com>
Co-authored-by: Wez Furlong <wez@wezfurlong.org>
Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
@burrbull burrbull mentioned this pull request Jul 19, 2019
@adamgreig
Copy link
Member

Closing in preference of #319 which incorporates this PR.

@adamgreig adamgreig closed this Jul 26, 2019
@therealprof therealprof deleted the register-derived-from branch July 26, 2019 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants