Skip to content

Commit 2483900

Browse files
committed
rust/src: add stdout print
Due to the cyclic dependency issues, rust part of the firmware can not import std create and therefore it does not have io capabilities, including 'println!'. As a result, C 'printf' function is exposed to rust as an external function. It is a useful feature to have it because as developers we may need to debug many parts of the rust code when we are not using debuggers. Also, in projects such as simulator, firmware is mainly debugged with gdb. Hence there is limited flexibility of debugging when execution jumps to rust. In addition, simulator could print some of the ui elements of firmware to stdout in this way. Signed-off-by: asi345 <inanata15@gmail.com>
1 parent 460c7bd commit 2483900

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ add_custom_target(rust-bindgen
395395
--allowlist-function secp256k1_ecdsa_anti_exfil_host_commit
396396
--allowlist-function wally_get_secp_context
397397
--allowlist-function wally_hash160
398+
--allowlist-function printf
398399
${CMAKE_CURRENT_SOURCE_DIR}/rust/bitbox02-sys/wrapper.h --
399400
-DPB_NO_PACKED_STRUCTS=1 -DPB_FIELD_16BIT=1 -fshort-enums ${RUST_BINDGEN_FLAGS} ${RUST_INCLUDES}
400401
COMMAND

src/rust/bitbox02/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ pub fn reboot() -> ! {
176176
panic!("reboot called")
177177
}
178178

179+
#[cfg(feature = "testing")]
180+
pub fn print_stdout(msg: &str) {
181+
unsafe {
182+
bitbox02_sys::printf(crate::util::str_to_cstr_vec(msg).unwrap().as_ptr());
183+
}
184+
}
185+
179186
#[cfg(test)]
180187
mod tests {
181188
use super::*;

0 commit comments

Comments
 (0)