move bitbox02-rust C API that needs HAL to bitbox-rust-c - main_loop
What changed, and why it matters
This commit is a straightforward internal code reorganization. It moves the C-compatible entry point for the device's main loop from one Rust module to another, so that the core Rust logic no longer directly depends on the hardware abstraction layer. There is no change to user-facing behavior, no bug fix, and no security-related content.
No security action required. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the BitBox02 firmware’s Rust code. It makes bitbox02-rust::main_loop::main_loop public and removes its local #[no_mangle] extern "C" rust_main_loop() wrapper. A new module firmware_c_api.rs in bitbox02-rust-c provides the same rust_main_loop() symbol, instantiating BitBox02Hal. This decouples bitbox02-rust from the concrete bitbox02 HAL dependency. The logic of the main loop is unchanged.
Changed components
src/rust/bitbox02-rust-c/src/firmware_c_api.rssrc/rust/bitbox02-rust-c/src/lib.rssrc/rust/bitbox02-rust/src/main_loop.rsInspect captured patch +13 / −10
diff --git a/src/rust/bitbox02-rust-c/src/firmware_c_api.rs b/src/rust/bitbox02-rust-c/src/firmware_c_api.rs
new file mode 100644
index 0000000..195111b
--- /dev/null
+++ b/src/rust/bitbox02-rust-c/src/firmware_c_api.rs
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: Apache-2.0
+
+#[allow(unused)]
+type HalImpl = bitbox02::hal::BitBox02Hal;
+
+#[cfg(not(any(feature = "c-unit-testing", feature = "simulator-graphical")))]
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_main_loop() -> ! {
+ bitbox02_rust::main_loop::main_loop(&mut HalImpl::new())
+}
diff --git a/src/rust/bitbox02-rust-c/src/lib.rs b/src/rust/bitbox02-rust-c/src/lib.rs
index a136ce1..3e57597 100644
--- a/src/rust/bitbox02-rust-c/src/lib.rs
+++ b/src/rust/bitbox02-rust-c/src/lib.rs
@@ -13,6 +13,8 @@ mod alloc;
pub mod async_usb;
#[cfg(feature = "firmware")]
mod der;
+#[cfg(feature = "firmware")]
+mod firmware_c_api;
#[cfg(feature = "factory-setup")]
mod secp256k1;
diff --git a/src/rust/bitbox02-rust/src/main_loop.rs b/src/rust/bitbox02-rust/src/main_loop.rs
index 77a8bee..3d46334 100644
--- a/src/rust/bitbox02-rust/src/main_loop.rs
+++ b/src/rust/bitbox02-rust/src/main_loop.rs
@@ -20,7 +20,7 @@ pub fn spawn(fut: DynExecutorFuture) {
EXECUTOR.spawn(fut).detach();
}
-fn main_loop(hal: &mut impl crate::hal::Hal) -> ! {
+pub fn main_loop(hal: &mut impl crate::hal::Hal) -> ! {
static ORIENTATION_CHOSEN: AtomicBool = AtomicBool::new(false);
// Set the size of uart_read_buf to the size of the ringbuffer in the UART driver so we can read
@@ -172,12 +172,3 @@ fn main_loop(hal: &mut impl crate::hal::Hal) -> ! {
}
}
}
-
-//
-// C interface
-//
-
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_main_loop() -> ! {
- main_loop(&mut crate::hal::BitBox02Hal::new())
-}
Why this scored 15/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.