sim: Move flash pointer up into Rust
Move the reference to the Flash device up into the Rust code instead of
trying to pass it back and forth to C. This will allow a future change
to use a fat pointer (such as a trait pointer), which ultimately will
allow different kinds of flash devices.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/src/c.rs b/sim/src/c.rs
index a770ca6..dd98c19 100644
--- a/sim/src/c.rs
+++ b/sim/src/c.rs
@@ -3,11 +3,14 @@
use area::AreaDesc;
use flash::Flash;
use libc;
+use api;
/// Invoke the bootloader on this flash device.
pub fn boot_go(flash: &mut Flash, areadesc: &AreaDesc) -> i32 {
- unsafe { raw::invoke_boot_go(flash as *mut _ as *mut libc::c_void,
- &areadesc.get_c() as *const _) as i32 }
+ unsafe { api::set_flash(flash) };
+ let result = unsafe { raw::invoke_boot_go(&areadesc.get_c() as *const _) as i32 };
+ unsafe { api::clear_flash(); };
+ result
}
/// Setter/getter for the flash counter. This isn't thread safe.
@@ -49,7 +52,7 @@
// This generates a warning about `CAreaDesc` not being foreign safe. There doesn't appear to
// be any way to get rid of this warning. See https://github.com/rust-lang/rust/issues/34798
// for information and tracking.
- pub fn invoke_boot_go(flash: *mut libc::c_void, areadesc: *const CAreaDesc) -> libc::c_int;
+ pub fn invoke_boot_go(areadesc: *const CAreaDesc) -> libc::c_int;
pub static mut flash_counter: libc::c_int;
pub static mut sim_flash_align: u8;