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 { |
| 25 | unsafe { raw::boot_trailer_sz(raw::sim_flash_align) } |
| 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 | |
| 36 | mod 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; |
| 48 | pub fn boot_trailer_sz(min_write_sz: u8) -> u32; |
| 49 | } |
| 50 | } |