add renode as a target to utralib

This commit is contained in:
bunnie 2022-09-27 18:09:33 +08:00
parent 4f2506f009
commit d0dc2e2a9f
6 changed files with 5986 additions and 29 deletions

2
utralib/Cargo.lock generated
View file

@ -120,7 +120,7 @@ checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "utralib"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"svd2utra",
]

View file

@ -1,6 +1,6 @@
[package]
name = "utralib"
version = "0.1.1"
version = "0.1.2"
authors = ["Sean Cross <sean@xobs.io>", "bunnie <bunnie@kosagi.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
@ -41,6 +41,7 @@ precursor-c809403-perflib = []
# checks inside build.rs to ensure consistency.
precursor = []
hosted = []
renode = []
# Specify a Precusor default so that we can pass packaging CI tests.
default = ["precursor-c809403", "precursor"]

View file

@ -20,12 +20,25 @@ fn main() {
)]
panic!("Precursor target specified, but no corresponding gitrev specified");
// this list grows O(N) as we add more targets. :-/ I don't know of a better way
// to express "only one of N should be selected" using cfg syntax
#[cfg(all(
feature="precursor",
feature="hosted"
any(feature="hosted", feature="renode")
))]
panic!("Multiple targets specified. This is disallowed");
#[cfg(all(
feature="hosted",
any(feature="precursor", feature="renode")
))]
panic!("Multiple targets specified. This is disallowed");
#[cfg(all(
feature="renode",
any(feature="precursor", feature="hosted")
))]
panic!("Multiple targets specified. This is disallowed");
// also grows O(N) as we add more gitrevs
#[cfg(all(
feature="precursor-c809403",
feature="precursor-c809403-perflib"
@ -43,34 +56,53 @@ fn main() {
#[cfg(feature="precursor-c809403-perflib")]
let generated_filename = "src/generated/precursor_perf_c809403.rs";
#[cfg(feature="renode")]
let svd_filename = "renode/renode.svd";
#[cfg(feature="renode")]
let generated_filename = "src/generated/renode.rs";
// ----- control file generation and rebuild sequence -----
// check and see if the configuration has changed since the last build. This should be
// passed by the build system (e.g. xtask) if the feature is used.
let last_config = out_dir().join("../../LAST_CONFIG");
if last_config.exists() {
println!("cargo:rerun-if-changed={}", last_config.canonicalize().unwrap().display());
#[cfg(not(feature="hosted"))]
{
let last_config = out_dir().join("../../LAST_CONFIG");
if last_config.exists() {
println!("cargo:rerun-if-changed={}", last_config.canonicalize().unwrap().display());
}
let svd_file_path = std::path::Path::new(&svd_filename);
println!("cargo:rerun-if-changed={}", svd_file_path.canonicalize().unwrap().display());
let src_file = std::fs::File::open(svd_filename).expect("couldn't open src file");
let mut dest_file = std::fs::File::create(generated_filename).expect("couldn't open dest file");
svd2utra::generate(src_file, &mut dest_file).unwrap();
// ----- feedback SVD path to build framework -----
// pass the computed SVD filename back to the build system, so that we can pass this
// on to the image creation program. This is necessary so we can extract all the memory
// regions and create the whitelist of memory pages allowed to the kernel; any page not
// explicitly used by the hardware model is ineligible for mapping and allocation by any
// process. This helps to prevent memory aliasing attacks by hardware blocks that partially
// decode their addresses (this would be in anticipation of potential hardware bugs; ideally
// this isn't ever a problem).
let svd_path = out_dir().join("../../SVD_PATH");
let mut svd_file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(svd_path)
.unwrap();
write!(svd_file, "utralib/{}", svd_filename).unwrap();
}
#[cfg(feature="hosted")]
{
let svd_path = out_dir().join("../../SVD_PATH");
let mut svd_file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(svd_path)
.unwrap();
write!(svd_file, "").unwrap(); // there is no SVD file for hosted mode
}
let svd_file_path = std::path::Path::new(&svd_filename);
println!("cargo:rerun-if-changed={}", svd_file_path.canonicalize().unwrap().display());
let src_file = std::fs::File::open(svd_filename).expect("couldn't open src file");
let mut dest_file = std::fs::File::create(generated_filename).expect("couldn't open dest file");
svd2utra::generate(src_file, &mut dest_file).unwrap();
// ----- feedback SVD path to build framework -----
// pass the computed SVD filename back to the build system, so that we can pass this
// on to the image creation program. This is necessary so we can extract all the memory
// regions and create the whitelist of memory pages allowed to the kernel; any page not
// explicitly used by the hardware model is ineligible for mapping and allocation by any
// process. This helps to prevent memory aliasing attacks by hardware blocks that partially
// decode their addresses (this would be in anticipation of potential hardware bugs; ideally
// this isn't ever a problem).
let svd_path = out_dir().join("../../SVD_PATH");
let mut svd_file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(svd_path)
.unwrap();
write!(svd_file, "utralib/{}", svd_filename).unwrap();
}

View file

@ -12,6 +12,11 @@ mod precursor_perf_c809403;
#[cfg(feature="precursor-c809403-perflib")]
pub use precursor_perf_c809403::*;
#[cfg(feature="renode")]
mod renode;
#[cfg(feature="renode")]
pub use renode::*;
// Hosted mode includes nothing, as it relies on the abstract host
// architecture for I/O; so this file is empty when the "hosted"
// configuration is selected and there are no corresponding "hosted"

File diff suppressed because it is too large Load diff