rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
697 stars 150 forks source link

HDL to SVD? #739

Open rmsyn opened 1 year ago

rmsyn commented 1 year ago

I'm interested in creating a PAC crate for a chip that only seems to have RTL files available (https://github.com/T-head-Semi/openc910).

Is there any way to convert these files to SVD, and then use svd2rust to generate the PAC crate?

I know they are different purpose-built levels of abstraction, just hoping to not have to wait for the vendor to release SVD files.

Apologies if this is a noobish question that is obvious to others in this community.

adamgreig commented 1 year ago

I don't think there's any general-purpose existing thing, because the RTL will be quite different for each chip. Some RTL generators like LiteX can output suitable metadata automatically, but if you don't already have that you'll probably have to write something to parse that specific chip's RTL and emit an SVD.

rmsyn commented 1 year ago

Some RTL generators like LiteX can output suitable metadata automatically, but if you don't already have that you'll probably have to write something to parse that specific chip's RTL and emit an SVD.

Looks like I just got another project to work on :sweat_smile: Thanks for the advice, I'll start working on something.

Edit: Small update, after looking into HTL-to-SVD translation, it seems to require annotating the HDL files to get the required info for SVD.

Ultimately, I don't think it's worth the effort, so I've transitioned to expanding SiFive's cmsis-svd-generator tool. Since a lot of these hardware vendors have some form of u-boot/linux support, the included DTS files seem like a better starting point. Especially when the vendors supply register information for board peripherals.