David Brown | de7729e | 2017-01-09 10:41:35 -0700 | [diff] [blame] | 1 | /// Interface wrappers to C API entering to the bootloader |
| 2 | |
| 3 | use area::AreaDesc; |
| 4 | use flash::Flash; |
| 5 | use libc; |
| 6 | |
| 7 | /// Invoke the bootloader on this flash device. |
| 8 | pub 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. |
| 14 | pub 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. |
| 20 | pub fn set_flash_counter(counter: i32) { |
| 21 | unsafe { raw::flash_counter = counter as libc::c_int }; |
| 22 | } |
| 23 | |
| 24 | pub fn boot_trailer_sz() -> u32 { |
Fabio Utzig | 7ebb7c2 | 2017-04-26 10:59:31 -0300 | [diff] [blame] | 25 | unsafe { raw::boot_slots_trailer_sz(raw::sim_flash_align) } |
David Brown | de7729e | 2017-01-09 10:41:35 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | pub fn get_sim_flash_align() -> u8 { |
| 29 | unsafe { raw::sim_flash_align } |
| 30 | } |
| 31 | |
| 32 | pub fn set_sim_flash_align(align: u8) { |
| 33 | unsafe { raw::sim_flash_align = align }; |
| 34 | } |
| 35 | |
Fabio Utzig | a0bc9b5 | 2017-06-28 09:19:55 -0300 | [diff] [blame^] | 36 | pub fn boot_magic_sz() -> usize { |
| 37 | unsafe { raw::BOOT_MAGIC_SZ as usize } |
| 38 | } |
| 39 | |
| 40 | pub fn boot_max_align() -> usize { |
| 41 | unsafe { raw::BOOT_MAX_ALIGN as usize } |
| 42 | } |
| 43 | |
David Brown | de7729e | 2017-01-09 10:41:35 -0700 | [diff] [blame] | 44 | mod 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 Utzig | 7ebb7c2 | 2017-04-26 10:59:31 -0300 | [diff] [blame] | 56 | pub fn boot_slots_trailer_sz(min_write_sz: u8) -> u32; |
Fabio Utzig | a0bc9b5 | 2017-06-28 09:19:55 -0300 | [diff] [blame^] | 57 | |
| 58 | pub static BOOT_MAGIC_SZ: u32; |
| 59 | pub static BOOT_MAX_ALIGN: u32; |
David Brown | de7729e | 2017-01-09 10:41:35 -0700 | [diff] [blame] | 60 | } |
| 61 | } |