Build: move host hardware fakes into bitbox02-sys
What changed, and why it matters
This is a build-system cleanup, not a security fix. It moves test-only fake hardware code into a lower-level Rust crate and adds a linker trick so the fake disk storage implementation is not accidentally left out when building the desktop simulator. There is no change to how real devices work and no reported vulnerability.
No security action required. Treat as ordinary build maintenance. If reviewing, verify simulator builds still link and tests pass.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates host-side hardware fakes (fake_component.c, fake_diskio.c, fake_memory.c, etc.) from the bitbox02-rust crate into bitbox02-sys and merges their object files into the same static archive as the bitbox02 C sources. It also moves the fatfs-sys dependency to bitbox02-sys and adds a #[used] static symbol anchor referencing disk_status so the fake diskio object is retained during host linking even if fatfs appears later in archive order. This is purely a build/linkage refactor for host/simulator targets; ARM firmware builds are unaffected.
Changed components
src/rust/bitbox02-sys/build.rssrc/rust/bitbox02-sys/src/lib.rssrc/rust/bitbox02-rust/src/lib.rsCargo.toml and Cargo.lock filesInspect captured patch +38 / −27
diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock
index d96d381..c55146d 100644
--- a/src/rust/Cargo.lock
+++ b/src/rust/Cargo.lock
@@ -182,7 +182,6 @@ dependencies = [
"digest",
"ed25519-dalek",
"erc20_params",
- "fatfs-sys",
"futures-lite",
"hex",
"hex_lit",
@@ -229,6 +228,7 @@ name = "bitbox02-sys"
version = "0.1.0"
dependencies = [
"cc",
+ "fatfs-sys",
"util",
]
diff --git a/src/rust/bitbox02-rust/Cargo.toml b/src/rust/bitbox02-rust/Cargo.toml
index aa40fc7..f381efa 100644
--- a/src/rust/bitbox02-rust/Cargo.toml
+++ b/src/rust/bitbox02-rust/Cargo.toml
@@ -39,7 +39,6 @@ minicbor = { version = "0.24.0", default-features = false, features = ["alloc"],
crc = { workspace = true, optional = true }
ed25519-dalek = { version = "2.1.1", default-features = false, features = ["hazmat", "digest"], optional = true }
hmac = { workspace = true }
-fatfs-sys = { path = "../fatfs-sys"}
miniscript = { version = "13.0.0", default-features = false, features = [], optional = true }
bitcoin = { workspace = true }
diff --git a/src/rust/bitbox02-rust/src/lib.rs b/src/rust/bitbox02-rust/src/lib.rs
index fe6f863..e40a854 100644
--- a/src/rust/bitbox02-rust/src/lib.rs
+++ b/src/rust/bitbox02-rust/src/lib.rs
@@ -46,9 +46,6 @@ extern crate alloc;
#[cfg(test)]
extern crate bitbox_aes;
-// Manually link fatfs
-extern crate fatfs_sys;
-
//
// C interface
//
diff --git a/src/rust/bitbox02-sys/Cargo.toml b/src/rust/bitbox02-sys/Cargo.toml
index f02950f..b6ba595 100644
--- a/src/rust/bitbox02-sys/Cargo.toml
+++ b/src/rust/bitbox02-sys/Cargo.toml
@@ -10,6 +10,7 @@ license = "Apache-2.0"
[dependencies]
util = {path = "../util"}
+fatfs-sys = { path = "../fatfs-sys" }
[build-dependencies]
cc = {version="1.2", features=["parallel"]}
diff --git a/src/rust/bitbox02-sys/build.rs b/src/rust/bitbox02-sys/build.rs
index cd3c21b..68a5d6b 100644
--- a/src/rust/bitbox02-sys/build.rs
+++ b/src/rust/bitbox02-sys/build.rs
@@ -295,6 +295,17 @@ const BITBOX02_SOURCES: &[&str] = &[
"external/asf4-drivers/hal/utils/src/utils_ringbuffer.c",
];
+const FAKEHARDWARE_SOURCES: &[&str] = &[
+ "test/hardware-fakes/src/fake_component.c",
+ "test/hardware-fakes/src/fake_diskio.c",
+ "test/hardware-fakes/src/fake_memory.c",
+ "test/hardware-fakes/src/fake_qtouch.c",
+ "test/hardware-fakes/src/fake_screen.c",
+ "test/hardware-fakes/src/fake_securechip.c",
+ "test/hardware-fakes/src/fake_smarteeprom.c",
+ "test/hardware-fakes/src/fake_spi_mem.c",
+];
+
pub fn main() -> Result<(), &'static str> {
// We could theoretically list every header file that we end up depending on, but that is hard
// to maintain. So instead we just listen to changes on "wrapper.h" which is good enough.
@@ -435,10 +446,6 @@ pub fn main() -> Result<(), &'static str> {
return Err("Bindgen failed");
}
- // For the c unit tests and c simulator we build a library that mocks/fakes real user behavior
- // and logs to stdout
- // For the rust simulator (with gui) we build a library that behaves more like the real
- // hardware since we have graphical inputs and outputs.
let excludes = if let Ok(libtype) = env::var("LIB_TYPE") {
match libtype.as_str() {
"c-unit-tests" => vec!["src/screen.c"],
@@ -448,28 +455,20 @@ pub fn main() -> Result<(), &'static str> {
vec![]
};
- let source_includes = &[
- "test/hardware-fakes/src/fake_component.c",
- "test/hardware-fakes/src/fake_diskio.c",
- "test/hardware-fakes/src/fake_memory.c",
- "test/hardware-fakes/src/fake_qtouch.c",
- "test/hardware-fakes/src/fake_screen.c",
- "test/hardware-fakes/src/fake_securechip.c",
- "test/hardware-fakes/src/fake_smarteeprom.c",
- "test/hardware-fakes/src/fake_spi_mem.c",
- ];
-
- // Build the c deps for unit tests
+ // Build native C deps for host builds. Keep bitbox C and hardware fakes in one archive so
+ // static archive ordering cannot drop fake providers before bitbox02 consumers.
if !cross_compiling {
let mdir = env::var("CARGO_MANIFEST_DIR").unwrap();
let mut builder = cc::Build::new();
- let files: Vec<String> = BITBOX02_SOURCES
+ let bitbox02_files = BITBOX02_SOURCES
.iter()
- .chain(source_includes.iter())
.filter(|x| !excludes.contains(x))
- .map(|s| [&mdir, "../../..", s].join("/"))
- .collect();
+ .map(|s| [&mdir, "../../..", s].join("/"));
+ let fakehardware_files = FAKEHARDWARE_SOURCES
+ .iter()
+ .map(|s| [&mdir, "../../..", s].join("/"));
+ let files: Vec<String> = bitbox02_files.chain(fakehardware_files).collect();
builder.files(&files);
for definition in &definitions {
diff --git a/src/rust/bitbox02-sys/src/lib.rs b/src/rust/bitbox02-sys/src/lib.rs
index e714f83..d7a0699 100644
--- a/src/rust/bitbox02-sys/src/lib.rs
+++ b/src/rust/bitbox02-sys/src/lib.rs
@@ -8,5 +8,20 @@
// Can be removed once https://github.com/rust-lang/rust-bindgen/issues/1651 is resolved.
#![allow(deref_nullptr)]
+#[allow(unused_extern_crates)]
+extern crate fatfs_sys;
+
+// Host targets link fatfs and bitbox02 static archives separately. Keep one explicit reference to
+// a diskio symbol so the fake diskio object is pulled from libbitbox02 even if fatfs appears later
+// in archive processing order.
+#[cfg(not(target_arch = "arm"))]
+unsafe extern "C" {
+ fn disk_status(pdrv: u8) -> u8;
+}
+
+#[cfg(not(target_arch = "arm"))]
+#[used]
+static DISK_STATUS_LINK_ANCHOR: unsafe extern "C" fn(u8) -> u8 = disk_status;
+
// include our generated bindings
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
diff --git a/test/simulator-graphical-bb03/Cargo.lock b/test/simulator-graphical-bb03/Cargo.lock
index ff25580..af6a7ad 100644
--- a/test/simulator-graphical-bb03/Cargo.lock
+++ b/test/simulator-graphical-bb03/Cargo.lock
@@ -402,7 +402,6 @@ dependencies = [
"digest",
"ed25519-dalek",
"erc20_params",
- "fatfs-sys",
"futures-lite",
"hex",
"hex_lit",
@@ -444,6 +443,7 @@ name = "bitbox02-sys"
version = "0.1.0"
dependencies = [
"cc",
+ "fatfs-sys",
"util",
]
diff --git a/test/simulator-graphical/Cargo.lock b/test/simulator-graphical/Cargo.lock
index 91084ca..24716d6 100644
--- a/test/simulator-graphical/Cargo.lock
+++ b/test/simulator-graphical/Cargo.lock
@@ -364,7 +364,6 @@ dependencies = [
"digest",
"ed25519-dalek",
"erc20_params",
- "fatfs-sys",
"futures-lite",
"hex",
"hex_lit",
@@ -406,6 +405,7 @@ name = "bitbox02-sys"
version = "0.1.0"
dependencies = [
"cc",
+ "fatfs-sys",
"util",
]
Why this scored 13/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.