blob: a770ca652b725d4bbacace26c0d7c5e7f1136d05 [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
Fabio Utziga0bc9b52017-06-28 09:19:55 -030036pub fn boot_magic_sz() -> usize {
37 unsafe { raw::BOOT_MAGIC_SZ as usize }
38}
39
40pub fn boot_max_align() -> usize {
41 unsafe { raw::BOOT_MAX_ALIGN as usize }
42}
43
David Brownde7729e2017-01-09 10:41:35 -070044mod raw {
45 use area::CAreaDesc;
46 use libc;
47
48 extern "C" {
49 // This generates a warning about `CAreaDesc` not being foreign safe. There doesn't appear to
50 // be any way to get rid of this warning. See https://github.com/rust-lang/rust/issues/34798
51 // for information and tracking.
52 pub fn invoke_boot_go(flash: *mut libc::c_void, areadesc: *const CAreaDesc) -> libc::c_int;
53 pub static mut flash_counter: libc::c_int;
54
55 pub static mut sim_flash_align: u8;
Fabio Utzig7ebb7c22017-04-26 10:59:31 -030056 pub fn boot_slots_trailer_sz(min_write_sz: u8) -> u32;
Fabio Utziga0bc9b52017-06-28 09:19:55 -030057
58 pub static BOOT_MAGIC_SZ: u32;
59 pub static BOOT_MAX_ALIGN: u32;
David Brownde7729e2017-01-09 10:41:35 -070060 }
61}