Skip to content

Switch away from tock-registers #68

Open

Description

@jonathanpallant

The code generated by tock-registers suffers from a couple of issues:

We should switch to Google's safe-mmio, which fixes both of the above.

The alternative would be sending AArch64 MMIO fixes to Knurling's derive-mmio crate and using that instead (it is used heavily by aarch32 and aarch32-rt already).

Edit: This crate actually doesn't do any MMIO, so the unsoundness and the MMIO load issues are irrelevant.

Activity

  1. andre-richter commented on Feb 23, 2026

    @andre-richter
    Member

    Switching to safe-mmio would imply a substantial change in the API for the provided registers I presume? Or do you see a way to wrap around this?

    If not, I guess the argument can be made that it makes more sense for users to directly switch to arm-sysregs (from the same authors as safe-mmio) than to refactor for a big breaking-change aarch64-cpu release?

  2. jonathanpallant commented on Feb 23, 2026

    @jonathanpallant
    ContributorAuthor

    The Rusted Firmware team have a specific goal - implementing Trusted Firmware services for Armv8-A and Armv9-A. I see support for AArch64 as being somewhat wider than that so I'm not sure I'd propose that EDWG abandon AArch64 entirely. For example, this crate is important for all the Raspberry Pi 64-bit bare-metal projects (like the one we host). Also for upcoming safety-island use-cases.

    However I concede that switching to safe-mmio is a big breaking change. I don't know how to remedy that, and it's also one that svd2rust PACs do not have a good answer for. They just do the breakage and hope people are ok with it.

    If you're going to break it, sooner is probably better than later.

  3. andre-richter commented on Feb 24, 2026

    @andre-richter
    Member

    When I started aarch64-cpu back then, the choice of tock-registers was a very deliberate one.
    I found their API and readability much cleaner and more elegant than all the alternatives at the time, and it therefore was the perfect fit for the Pi OS tutorials.

    One alternative would be to hold out some more in hope that the tock folks get the issues fixed sometime soon.

    I saw the GitHub issue you opened in their repo where they say they just restarted their efforts on this.

  4. jonathanpallant commented on Feb 24, 2026

    @jonathanpallant
    ContributorAuthor

    I'll be honest, I'm not having a great time reading the docs generated by tock-registers.

    Like, given https://docs.rs/aarch64-cpu/latest/aarch64_cpu/registers/MAIR_EL1/index.html, how would someone work out how to read or write the fields within that register?

    Actually writing code though, yeah, it has its charms compared to the very closure based svd2rust code (and actually that API is also not very discoverable through the docs either).

  5. alevy commented on Feb 25, 2026

    @alevy

    @jonathanpallant suggestion for or explanation of the "ideal" documentation in an issue somewhere would (hopefully) help put that on the todo list at least (perhaps post a version that fixes the core issues)

  6. jonathanpallant commented on Feb 27, 2026

    @jonathanpallant
    ContributorAuthor

    So I have a blog post (a big blog post) digging into safe-mmio vs derive-mmio vs tock-registers vs svd2rust. But to start, I've made a very simple UART driver and built it four ways.

    https://github.com/ferrous-systems/handling-system-registers/tree/main/tock-registers-example

    I don't know where I'm going to host the docs (pushing to crates.io seems wrong?) but perhaps you could do two things:

    1. Check out that repo and see if my tock-registers example is idiomatic.
    2. Run cargo doc and and try and use it (and only it) to answer the question "How do I make a UART object and configure my UART with it". I actually found it really quite tricky to even write the example, and auto-complete wasn't really helping thanks to having both modules and types with the same name.
  7. alevy commented on Feb 27, 2026

    @alevy

    @jonathanpallant OK, this is very helpful. First, yes, I would say this is pretty canonical use of tock-registers. No notes.

    Second, yes, it's pretty clear from looking at these docs what you mean.

    Basically, two things: your documentation of the specific fields in the control register are not present at all anywhere in the generated documentation. For a UART that looks very similar to any other UART, it's pretty self explanatory, but for anything more complicated or any deviation from typical/expected meanings of fields (e.g. I've seen baud rate being derived by dividing or multiplying the value in the field) you would basically have to have have the datasheet sitting next to you to write driver code on top of this, even though your comments basically have (or certainly could have) all of that information.

    Next, the general interface for using tock-registers is neither typical, canonical Rust-isms, so things like tab-completion aren't going to help much, nor is it documented for the generated structs themselves. So you basically need to know (and remember) how to use tock-registers when you're using them. You don't get to re-learn it from the docs, or from tab-completing methods.

    derive_mmio seems to do much better especially on the latter (documentation itself is a bit thin in general, but how much is there to say, really about "this field is a baud rate").

  8. berkus commented on Mar 10, 2026

    @berkus
    Member

    The discussion from 2026-03-10 WG meeting - the crate does NOT use tock-registers' mmio so it should be safe to keep, although bitbybit and #71 could be interesting follow ups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions