blob: 4de9553bd91713b7f4c6e096701e7303470e34f3 [file] [log] [blame]
David Brownde7729e2017-01-09 10:41:35 -07001/// Interface wrappers to C API entering to the bootloader
2
3use area::AreaDesc;
4use flash::Flash;
5use libc;
6
7/// Invoke the bootloader on this flash device.
8pub fn boot_go(flash: &mut Flash, areadesc: &AreaDesc) -> i32 {
9 unsafe { raw::invoke_boot_go(flash as *mut _ as *mut libc::c_void,
10 &areadesc.get_c() as *const _) as i32 }
11}
12
13/// Setter/getter for the flash counter. This isn't thread safe.
14pub fn get_flash_counter() -> i32 {
15 unsafe { raw::flash_counter as i32 }
16}
17
18/// Set the flash counter. Zero indicates the flash should not be interrupted. The counter will
19/// then go negative for each flash operation.
20pub fn set_flash_counter(counter: i32) {
21 unsafe { raw::flash_counter = counter as libc::c_int };
22}
23
24pub fn boot_trailer_sz() -> u32 {
Fabio Utzig7ebb7c22017-04-26 10:59:31 -030025 unsafe { raw::boot_slots_trailer_sz(raw::sim_flash_align) }
David Brownde7729e2017-01-09 10:41:35 -070026}
27
28pub fn get_sim_flash_align() -> u8 {
29 unsafe { raw::sim_flash_align }
30}
31
32pub fn set_sim_flash_align(align: u8) {
33 unsafe { raw::sim_flash_align = align };
34}
35
36mod raw {
37 use area::CAreaDesc;
38 use libc;
39
40 extern "C" {
41 // This generates a warning about `CAreaDesc` not being foreign safe. There doesn't appear to
42 // be any way to get rid of this warning. See https://github.com/rust-lang/rust/issues/34798
43 // for information and tracking.
44 pub fn invoke_boot_go(flash: *mut libc::c_void, areadesc: *const CAreaDesc) -> libc::c_int;
45 pub static mut flash_counter: libc::c_int;
46
47 pub static mut sim_flash_align: u8;
Fabio Utzig7ebb7c22017-04-26 10:59:31 -030048 pub fn boot_slots_trailer_sz(min_write_sz: u8) -> u32;
David Brownde7729e2017-01-09 10:41:35 -070049 }
50}