Kaynağa Gözat

Merge pull request #57 from guttatus/bl808-debug

feat(prototyper): add Sipeed m1s dock support
guttatus 2 ay önce
ebeveyn
işleme
50bdbd7a0d

+ 183 - 26
Cargo.lock

@@ -49,14 +49,24 @@ dependencies = [
 
 [[package]]
 name = "anstyle-wincon"
-version = "3.0.6"
+version = "3.0.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
+checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
 dependencies = [
  "anstyle",
+ "once_cell",
  "windows-sys",
 ]
 
+[[package]]
+name = "as-slice"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "516b6b4f0e40d50dcda9365d53964ec74560ad4284da2e7fc97122cd83174516"
+dependencies = [
+ "stable_deref_trait",
+]
+
 [[package]]
 name = "autocfg"
 version = "1.4.0"
@@ -71,9 +81,25 @@ checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
 
 [[package]]
 name = "bitflags"
-version = "2.6.0"
+version = "2.8.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
+checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
+
+[[package]]
+name = "bouffalo-hal"
+version = "0.0.0"
+source = "git+https://github.com/rustsbi/bouffalo-hal?rev=968b949#968b949466adeb6773f7ca3c1052e3a400533ed9"
+dependencies = [
+ "as-slice",
+ "cfg-if",
+ "embedded-hal 0.2.7",
+ "embedded-hal 1.0.0",
+ "embedded-hal-nb",
+ "embedded-io",
+ "embedded-time",
+ "nb 1.1.0",
+ "volatile-register",
+]
 
 [[package]]
 name = "buddy_system_allocator"
@@ -92,9 +118,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
 [[package]]
 name = "clap"
-version = "4.5.23"
+version = "4.5.26"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
+checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783"
 dependencies = [
  "clap_builder",
  "clap_derive",
@@ -112,9 +138,9 @@ dependencies = [
 
 [[package]]
 name = "clap_builder"
-version = "4.5.23"
+version = "4.5.26"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
+checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121"
 dependencies = [
  "anstream",
  "anstyle",
@@ -124,9 +150,9 @@ dependencies = [
 
 [[package]]
 name = "clap_derive"
-version = "4.5.18"
+version = "4.5.24"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
+checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c"
 dependencies = [
  "heck",
  "proc-macro2",
@@ -158,12 +184,47 @@ version = "0.2.0-alpha.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9404d41caa1aa659f7be44d5a902e318c0672900822fe9ca41d9e38c14b52332"
 
+[[package]]
+name = "embedded-hal"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
+dependencies = [
+ "nb 0.1.3",
+ "void",
+]
+
 [[package]]
 name = "embedded-hal"
 version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
 
+[[package]]
+name = "embedded-hal-nb"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605"
+dependencies = [
+ "embedded-hal 1.0.0",
+ "nb 1.1.0",
+]
+
+[[package]]
+name = "embedded-io"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
+
+[[package]]
+name = "embedded-time"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d7a4b4d10ac48d08bfe3db7688c402baadb244721f30a77ce360bd24c3dffe58"
+dependencies = [
+ "num",
+]
+
 [[package]]
 name = "fast-trap"
 version = "0.0.1"
@@ -194,9 +255,9 @@ dependencies = [
 
 [[package]]
 name = "log"
-version = "0.4.22"
+version = "0.4.25"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
+checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f"
 
 [[package]]
 name = "naked-function"
@@ -219,6 +280,89 @@ dependencies = [
  "syn",
 ]
 
+[[package]]
+name = "nb"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
+dependencies = [
+ "nb 1.1.0",
+]
+
+[[package]]
+name = "nb"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
+
+[[package]]
+name = "num"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b7a8e9be5e039e2ff869df49155f1c06bd01ade2117ec783e56ab0932b67a8f"
+dependencies = [
+ "num-complex",
+ "num-integer",
+ "num-iter",
+ "num-rational",
+ "num-traits",
+]
+
+[[package]]
+name = "num-complex"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5"
+dependencies = [
+ "num-traits",
+]
+
+[[package]]
+name = "num-integer"
+version = "0.1.46"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
+dependencies = [
+ "num-traits",
+]
+
+[[package]]
+name = "num-iter"
+version = "0.1.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
+dependencies = [
+ "autocfg",
+ "num-integer",
+ "num-traits",
+]
+
+[[package]]
+name = "num-rational"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
+dependencies = [
+ "autocfg",
+ "num-integer",
+ "num-traits",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.20.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
+
 [[package]]
 name = "panic-halt"
 version = "1.0.0"
@@ -239,18 +383,18 @@ checksum = "2ad606bf31d67b0e10a161b7df7d6a97dda7be22ce4bebcff889476e867c9b7a"
 
 [[package]]
 name = "proc-macro2"
-version = "1.0.92"
+version = "1.0.93"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
+checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
 dependencies = [
  "unicode-ident",
 ]
 
 [[package]]
 name = "quote"
-version = "1.0.37"
+version = "1.0.38"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
+checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
 dependencies = [
  "proc-macro2",
 ]
@@ -272,7 +416,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2f5c1b8bf41ea746266cdee443d1d1e9125c86ce1447e1a2615abd34330d33a9"
 dependencies = [
  "critical-section",
- "embedded-hal",
+ "embedded-hal 1.0.0",
 ]
 
 [[package]]
@@ -282,7 +426,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5ea8ff73d3720bdd0a97925f0bf79ad2744b6da8ff36be3840c48ac81191d7a7"
 dependencies = [
  "critical-section",
- "embedded-hal",
+ "embedded-hal 1.0.0",
  "paste",
  "riscv-pac",
 ]
@@ -341,6 +485,7 @@ name = "rustsbi-prototyper"
 version = "0.0.0"
 dependencies = [
  "aclint",
+ "bouffalo-hal",
  "buddy_system_allocator",
  "cfg-if",
  "fast-trap",
@@ -448,9 +593,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
 
 [[package]]
 name = "serde"
-version = "1.0.216"
+version = "1.0.217"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e"
+checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
 dependencies = [
  "serde_derive",
 ]
@@ -458,16 +603,16 @@ dependencies = [
 [[package]]
 name = "serde-device-tree"
 version = "0.0.1"
-source = "git+https://github.com/rustsbi/serde-device-tree#cffb488e2bb73f0daae1a889813ef21dc6a02450"
+source = "git+https://github.com/rustsbi/serde-device-tree#b3597a098a27640e499c369fd740722181bd181e"
 dependencies = [
  "serde",
 ]
 
 [[package]]
 name = "serde_derive"
-version = "1.0.216"
+version = "1.0.217"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e"
+checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -489,6 +634,12 @@ dependencies = [
  "lock_api",
 ]
 
+[[package]]
+name = "stable_deref_trait"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
+
 [[package]]
 name = "strsim"
 version = "0.11.1"
@@ -497,9 +648,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
 
 [[package]]
 name = "syn"
-version = "2.0.90"
+version = "2.0.96"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
+checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -539,6 +690,12 @@ version = "0.1.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
 
+[[package]]
+name = "void"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
+
 [[package]]
 name = "volatile-register"
 version = "0.2.2"
@@ -633,7 +790,7 @@ dependencies = [
 [[package]]
 name = "xuantie-riscv"
 version = "0.0.0"
-source = "git+https://github.com/rustsbi/xuantie#5d0eeb42b1d5c21b6513ad0b8ec4b6ffd5dd2dc8"
+source = "git+https://github.com/rustsbi/xuantie#7a521c0400dc7edb7a3ee103206dd8246c78d542"
 dependencies = [
  "bit_field",
  "bitflags",

+ 1 - 0
prototyper/Cargo.toml

@@ -26,6 +26,7 @@ fast-trap = { version = "0.0.1", features = ["riscv-m"] }
 serde-device-tree = { git = "https://github.com/rustsbi/serde-device-tree", default-features = false }
 uart_xilinx = { git = "https://github.com/duskmoon314/uart-rs/" }
 xuantie-riscv = { git= "https://github.com/rustsbi/xuantie" }
+bouffalo-hal = { git = "https://github.com/rustsbi/bouffalo-hal", rev = "968b949", features = ["bl808"] }
 
 [[bin]]
 name = "rustsbi-prototyper"

+ 5 - 3
prototyper/src/cfg.rs

@@ -1,14 +1,16 @@
+/// The address where the SBI link start.
+pub const SBI_LINK_START_ADDRESS: usize = 0x80000000;
 /// Maximum number of supported harts.
 pub const NUM_HART_MAX: usize = 8;
 /// Stack size per hart (hardware thread) in bytes.
 pub const LEN_STACK_PER_HART: usize = 16 * 1024;
-/// Heap Size of SBI firmware
+/// Heap Size of SBI firmware.
 pub const HEAP_SIZE: usize = 32 * 1024;
-/// Page size
+/// Platform page size.
 pub const PAGE_SIZE: usize = 4096;
 /// TLB_FLUSH_LIMIT defines the TLB refresh range limit.
 /// If the TLB refresh range is greater than TLB_FLUSH_LIMIT, the entire TLB is refreshed.
 pub const TLB_FLUSH_LIMIT: usize = 4 * PAGE_SIZE;
 
 #[cfg(feature = "jump")]
-pub const JUMP_ADDRESS: usize = 0x80200000;
+pub const JUMP_ADDRESS: usize = 0x50000000;

+ 0 - 10
prototyper/src/devicetree.rs

@@ -11,22 +11,12 @@ use core::ops::Range;
 pub struct Tree<'a> {
     /// Optional model name string.
     pub model: Option<StrSeq<'a>>,
-    /// Chosen node containing boot parameters.
-    pub chosen: Chosen<'a>,
     /// Memory information.
     pub memory: NodeSeq<'a>,
     /// CPU information.
     pub cpus: Cpus<'a>,
 }
 
-/// Chosen node containing boot parameters.
-#[derive(Deserialize)]
-#[serde(rename_all = "kebab-case")]
-pub struct Chosen<'a> {
-    /// Path to stdout device.
-    pub stdout_path: StrSeq<'a>,
-}
-
 /// CPU information container.
 #[derive(Deserialize)]
 #[serde(rename_all = "kebab-case")]

+ 1 - 2
prototyper/src/main.rs

@@ -35,7 +35,6 @@ use crate::sbi::ipi;
 use crate::sbi::trap::{self, trap_vec};
 use crate::sbi::trap_stack;
 
-pub const START_ADDRESS: usize = 0x80000000;
 pub const R_RISCV_RELATIVE: usize = 3;
 
 #[no_mangle]
@@ -200,7 +199,7 @@ unsafe extern "C" fn relocation_update() {
         // Return
         "   ret",
         R_RISCV_RELATIVE = const R_RISCV_RELATIVE,
-        START_ADDRESS = const START_ADDRESS,
+        START_ADDRESS = const cfg::SBI_LINK_START_ADDRESS,
         options(noreturn)
     )
 }

+ 2 - 1
prototyper/src/platform/clint.rs

@@ -3,7 +3,8 @@ use core::arch::asm;
 use xuantie_riscv::peripheral::clint::THeadClint;
 
 use crate::sbi::ipi::IpiDevice;
-pub(crate) const CLINT_COMPATIBLE: [&str; 1] = ["riscv,clint0"];
+pub(crate) const SIFIVE_CLINT_COMPATIBLE: [&str; 1] = ["riscv,clint0"];
+pub(crate) const THEAD_CLINT_COMPATIBLE: [&str; 1] = ["thead,c900-clint"];
 
 #[doc(hidden)]
 #[allow(unused)]

+ 51 - 0
prototyper/src/platform/console.rs

@@ -1,10 +1,12 @@
 use uart16550::{Register, Uart16550};
 use uart_xilinx::MmioUartAxiLite;
+use bouffalo_hal::uart::RegisterBlock as BflbUartRegisterBlock;
 
 use crate::sbi::console::ConsoleDevice;
 pub(crate) const UART16650U8_COMPATIBLE: [&str; 1] = ["ns16550a"];
 pub(crate) const UART16650U32_COMPATIBLE: [&str; 1] = ["snps,dw-apb-uart"];
 pub(crate) const UARTAXILITE_COMPATIBLE: [&str; 1] = ["xlnx,xps-uartlite-1.00.a"];
+pub(crate) const UARTBFLB_COMPATIBLE: [&str; 1] = ["bflb,bl808-uart"];
 
 #[doc(hidden)]
 #[allow(unused)]
@@ -13,8 +15,10 @@ pub enum MachineConsoleType {
     Uart16550U8,
     Uart16550U32,
     UartAxiLite,
+    UartBflb,
 }
 
+/// For Uart 16550
 pub struct Uart16550Wrap<R: Register> {
     inner: *const Uart16550<R>,
 }
@@ -37,6 +41,8 @@ impl<R: Register> ConsoleDevice for Uart16550Wrap<R> {
     }
 }
 
+
+/// For Uart AxiLite
 impl ConsoleDevice for MmioUartAxiLite {
     fn read(&self, buf: &mut [u8]) -> usize {
         self.read(buf)
@@ -46,3 +52,48 @@ impl ConsoleDevice for MmioUartAxiLite {
         self.write(buf)
     }
 }
+
+/// For Uart BFLB
+pub struct UartBflbWrap {
+    inner: *const BflbUartRegisterBlock
+}
+
+impl UartBflbWrap {
+    pub fn new(base: usize) -> Self {
+        Self {
+            inner: base as *const BflbUartRegisterBlock
+        }
+        
+    }
+}
+
+impl ConsoleDevice for UartBflbWrap {
+    fn read(&self, buf: &mut [u8]) -> usize {
+        let  uart = unsafe {&(*self.inner) };
+        while uart.fifo_config_1.read().receive_available_bytes() == 0 {
+            core::hint::spin_loop();
+        }
+        let len = core::cmp::min(
+            uart.fifo_config_1.read().receive_available_bytes() as usize,
+            buf.len(),
+        );
+        buf.iter_mut()
+            .take(len)
+            .for_each(|slot| *slot = uart.fifo_read.read());
+        len
+    }
+
+    fn write(&self, buf: &[u8]) -> usize {
+        let  uart = unsafe {&(*self.inner) };
+        let mut count = 0;
+        for current in buf {
+            if uart.fifo_config_1.read().transmit_available_bytes() == 0 {
+                break;
+            }
+            count += 1;
+            unsafe { uart.fifo_write.write(*current); }
+        }
+        count
+    }
+    
+}

+ 42 - 32
prototyper/src/platform/mod.rs

@@ -12,10 +12,12 @@ use uart_xilinx::MmioUartAxiLite;
 use crate::cfg::NUM_HART_MAX;
 use crate::devicetree::*;
 use crate::fail;
-use crate::platform::clint::{MachineClintType, CLINT_COMPATIBLE};
+use crate::platform::clint::{MachineClintType, SIFIVE_CLINT_COMPATIBLE, THEAD_CLINT_COMPATIBLE};
 use crate::platform::console::Uart16550Wrap;
+use crate::platform::console::UartBflbWrap;
 use crate::platform::console::{
     MachineConsoleType, UART16650U32_COMPATIBLE, UART16650U8_COMPATIBLE, UARTAXILITE_COMPATIBLE,
+    UARTBFLB_COMPATIBLE,
 };
 use crate::platform::reset::SIFIVETEST_COMPATIBLE;
 use crate::sbi::console::SbiConsole;
@@ -88,7 +90,6 @@ impl Platform {
     pub fn init(&mut self, fdt_address: usize) {
         self.info_init(fdt_address);
         self.sbi_init();
-        logger::Logger::init().unwrap();
         trap_stack::prepare_for_trap();
         self.ready.swap(true, Ordering::Release);
     }
@@ -101,34 +102,8 @@ impl Platform {
             .unwrap_or_else(fail::device_tree_deserialize_root);
         let tree: Tree = root.deserialize();
 
-        //  Get console device info
-        for console_path in tree.chosen.stdout_path.iter() {
-            if let Some(node) = root.find(console_path) {
-                let info = get_compatible_and_range(&node);
-                let result = info.is_some_and(|info| {
-                    let (compatible, regs) = info;
-                    for device_id in compatible.iter() {
-                        if UART16650U8_COMPATIBLE.contains(&device_id) {
-                            self.info.console = Some((regs.start, MachineConsoleType::Uart16550U8));
-                            return true;
-                        }
-                        if UART16650U32_COMPATIBLE.contains(&device_id) {
-                            self.info.console =
-                                Some((regs.start, MachineConsoleType::Uart16550U32));
-                            return true;
-                        }
-                        if UARTAXILITE_COMPATIBLE.contains(&device_id) {
-                            self.info.console = Some((regs.start, MachineConsoleType::UartAxiLite));
-                            return true;
-                        }
-                    }
-                    false
-                });
-                if result {
-                    break;
-                }
-            }
-        }
+        // Get console device, init sbi console and logger
+        self.sbi_find_and_init_console(&root);
 
         // Get ipi and reset device info
         let mut find_device = |node: &serde_device_tree::buildin::Node| {
@@ -138,12 +113,14 @@ impl Platform {
                 let base_address = regs.start;
                 for device_id in compatible.iter() {
                     // Initialize clint device.
-                    if CLINT_COMPATIBLE.contains(&device_id) {
+                    if SIFIVE_CLINT_COMPATIBLE.contains(&device_id) {
                         if node.get_prop("clint,has-no-64bit-mmio").is_some() {
                             self.info.ipi = Some((base_address, MachineClintType::TheadClint));
                         } else {
                             self.info.ipi = Some((base_address, MachineClintType::SiFiveClint));
                         }
+                    } else if THEAD_CLINT_COMPATIBLE.contains(&device_id) {
+                        self.info.ipi = Some((base_address, MachineClintType::TheadClint));
                     }
                     // Initialize reset device.
                     if SIFIVETEST_COMPATIBLE.contains(&device_id) {
@@ -196,13 +173,43 @@ impl Platform {
     }
 
     fn sbi_init(&mut self) {
-        self.sbi_console_init();
         self.sbi_ipi_init();
         self.sbi_hsm_init();
         self.sbi_reset_init();
         self.sbi_rfence_init();
     }
 
+    fn sbi_find_and_init_console(&mut self, root: &serde_device_tree::buildin::Node) {
+        //  Get console device info
+        if let Some(stdout_path) = root.chosen_stdout_path() {
+            if let Some(node) = root.find(stdout_path) {
+                let info = get_compatible_and_range(&node);
+                if let Some((compatible, regs)) = info {
+                    for device_id in compatible.iter() {
+                        if UART16650U8_COMPATIBLE.contains(&device_id) {
+                            self.info.console = Some((regs.start, MachineConsoleType::Uart16550U8));
+                        }
+                        if UART16650U32_COMPATIBLE.contains(&device_id) {
+                            self.info.console =
+                                Some((regs.start, MachineConsoleType::Uart16550U32));
+                        }
+                        if UARTAXILITE_COMPATIBLE.contains(&device_id) {
+                            self.info.console = Some((regs.start, MachineConsoleType::UartAxiLite));
+                        }
+                        if UARTBFLB_COMPATIBLE.contains(&device_id) {
+                            self.info.console = Some((regs.start, MachineConsoleType::UartBflb));
+                        }
+                    }
+                }
+            }
+        }
+
+        // init console and logger
+        self.sbi_console_init();
+        logger::Logger::init().unwrap();
+        info!("Hello RustSBI!");
+    }
+
     fn sbi_console_init(&mut self) {
         if let Some((base, console_type)) = self.info.console {
             self.sbi.console = match console_type {
@@ -215,6 +222,9 @@ impl Platform {
                 MachineConsoleType::UartAxiLite => Some(SbiConsole::new(Mutex::new(Box::new(
                     MmioUartAxiLite::new(base),
                 )))),
+                MachineConsoleType::UartBflb => Some(SbiConsole::new(Mutex::new(Box::new(
+                    UartBflbWrap::new(base),
+                )))),
             };
         } else {
             self.sbi.console = None;