瀏覽代碼

feat: supports coexistence of different types of firmware

guttatus 3 月之前
父節點
當前提交
0c3198ac88
共有 6 個文件被更改,包括 53 次插入26 次删除
  1. 12 5
      Cargo.lock
  2. 1 1
      prototyper/Cargo.toml
  3. 2 1
      prototyper/src/fail.rs
  4. 1 1
      prototyper/src/firmware/payload.rs
  5. 2 0
      prototyper/src/sbi/reset.rs
  6. 35 18
      xtask/src/prototyper.rs

+ 12 - 5
Cargo.lock

@@ -212,6 +212,12 @@ version = "1.0.15"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
 
+[[package]]
+name = "plic"
+version = "0.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2ad606bf31d67b0e10a161b7df7d6a97dda7be22ce4bebcff889476e867c9b7a"
+
 [[package]]
 name = "proc-macro2"
 version = "1.0.92"
@@ -415,9 +421,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
 
 [[package]]
 name = "serde"
-version = "1.0.215"
+version = "1.0.216"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
+checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e"
 dependencies = [
  "serde_derive",
 ]
@@ -432,9 +438,9 @@ dependencies = [
 
 [[package]]
 name = "serde_derive"
-version = "1.0.215"
+version = "1.0.216"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
+checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -598,9 +604,10 @@ dependencies = [
 [[package]]
 name = "xuantie-riscv"
 version = "0.0.0"
-source = "git+https://github.com/guttatus/xuantie?branch=edtion#e3f8f83658b9c081307ca8235500886f389d47aa"
+source = "git+https://github.com/rustsbi/xuantie#5d0eeb42b1d5c21b6513ad0b8ec4b6ffd5dd2dc8"
 dependencies = [
  "bit_field",
  "bitflags",
+ "plic",
  "volatile-register",
 ]

+ 1 - 1
prototyper/Cargo.toml

@@ -23,7 +23,7 @@ uart16550 = "0.0.1"
 riscv-decode = "0.2.1"
 fast-trap = { version = "0.0.1", features = ["riscv-m"] }
 uart_xilinx = { git = "https://github.com/duskmoon314/uart-rs/" }
-xuantie-riscv = { git= "https://github.com/guttatus/xuantie", branch = "edtion" }
+xuantie-riscv = { git= "https://github.com/rustsbi/xuantie" }
 
 [[bin]]
 name = "rustsbi-prototyper"

+ 2 - 1
prototyper/src/fail.rs

@@ -1,8 +1,9 @@
 use serde_device_tree::Dtb;
 
 use crate::dt;
-use crate::sbi::reset;
 
+#[cfg(not(feature = "payload"))]
+use crate::sbi::reset;
 #[cfg(not(feature = "payload"))]
 use crate::firmware::dynamic;
 #[cfg(not(feature = "payload"))]

+ 1 - 1
prototyper/src/firmware/payload.rs

@@ -2,7 +2,7 @@ use core::arch::asm;
 use core::sync::atomic::{AtomicBool, Ordering};
 use riscv::register::mstatus;
 
-use super::{BootHart, BootInfo};
+use super::BootInfo;
 
 /// Determine whether the current hart is boot hart.
 ///

+ 2 - 0
prototyper/src/sbi/reset.rs

@@ -18,6 +18,7 @@ impl<'a, T: ResetDevice> SbiReset<T> {
         Self { reset_dev }
     }
 
+    #[allow(unused)]
     pub fn fail(&self) -> ! {
         let reset_dev = self.reset_dev.load(Relaxed);
         if reset_dev.is_null() {
@@ -60,6 +61,7 @@ impl<T: ResetDevice> rustsbi::Reset for SbiReset<T> {
     }
 }
 
+#[allow(unused)]
 pub fn fail() -> ! {
     match unsafe { PLATFORM.sbi.reset.as_ref() } {
         Some(reset) => reset.fail(),

+ 35 - 18
xtask/src/prototyper.rs

@@ -1,5 +1,5 @@
 use std::{
-    env,
+    env, fs,
     process::{Command, ExitStatus},
 };
 
@@ -25,6 +25,13 @@ pub fn run(arg: &PrototyperArg) -> Option<ExitStatus> {
     let arch = "riscv64imac-unknown-none-elf";
     let fdt = arg.fdt.clone();
     let payload = arg.payload.clone();
+    let current_dir = env::current_dir();
+    let target_dir = current_dir
+        .as_ref()
+        .unwrap()
+        .join("target")
+        .join(arch)
+        .join("release");
 
     cargo::Cargo::new("build")
         .package("rustsbi-prototyper")
@@ -44,25 +51,35 @@ pub fn run(arg: &PrototyperArg) -> Option<ExitStatus> {
         .status()
         .ok()?;
 
-    Command::new("rust-objcopy")
+    let exit_status = Command::new("rust-objcopy")
         .args(["-O", "binary"])
         .arg("--binary-architecture=riscv64")
-        .arg(
-            env::current_dir()
-                .unwrap()
-                .join("target")
-                .join(arch)
-                .join("release")
-                .join("rustsbi-prototyper"),
+        .arg(target_dir.join("rustsbi-prototyper"))
+        .arg(target_dir.join("rustsbi-prototyper.bin"))
+        .status()
+        .ok()?;
+
+    if arg.payload.is_some() {
+        fs::copy(
+            target_dir.join("rustsbi-prototyper"),
+            target_dir.join("rustsbi-prototyper-payload.elf"),
+        )
+        .ok()?;
+        fs::copy(
+            target_dir.join("rustsbi-prototyper.bin"),
+            target_dir.join("rustsbi-prototyper-payload.bin"),
         )
-        .arg(
-            env::current_dir()
-                .unwrap()
-                .join("target")
-                .join(arch)
-                .join("release")
-                .join("rustsbi-prototyper.bin"),
+        .ok()?;
+    } else {
+        fs::copy(
+            target_dir.join("rustsbi-prototyper"),
+            target_dir.join("rustsbi-prototyper-dynamic.elf"),
         )
-        .status()
-        .ok()
+        .ok()?;
+        fs::copy(
+            target_dir.join("rustsbi-prototyper.bin"),
+            target_dir.join("rustsbi-prototyper-dynamic.bin"),
+        ).ok()?;
+    }
+    Some(exit_status)
 }