sim: update alignment (aka write_sz) to u16

The simulated alignment functions were returning u8 which would be
invalid for any alignment beyond 128; as a first step in the direction
of allowing larger alignments, make them u16 which should allow for up
to 2**15 aligment size.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
This commit is contained in:
Fabio Utzig 2020-10-04 11:51:53 -03:00 committed by Fabio Utzig
parent d0157343dc
commit 1edb788695
3 changed files with 6 additions and 6 deletions

View File

@ -42,7 +42,7 @@ extern int sim_flash_read(uint8_t flash_id, uint32_t offset, uint8_t *dest,
uint32_t size);
extern int sim_flash_write(uint8_t flash_id, uint32_t offset, const uint8_t *src,
uint32_t size);
extern uint8_t sim_flash_align(uint8_t flash_id);
extern uint16_t sim_flash_align(uint8_t flash_id);
extern uint8_t sim_flash_erased_val(uint8_t flash_id);
struct sim_context {
@ -202,7 +202,7 @@ done:
#endif
}
uint8_t flash_area_align(const struct flash_area *area)
uint16_t flash_area_align(const struct flash_area *area)
{
return sim_flash_align(area->fa_device_id);
}

View File

@ -123,7 +123,7 @@ int flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len);
/*
* Alignment restriction for flash writes.
*/
uint8_t flash_area_align(const struct flash_area *);
uint16_t flash_area_align(const struct flash_area *);
/*
* What is value is read from erased flash bytes.

View File

@ -21,7 +21,7 @@ use std::{
pub type FlashMap = HashMap<u8, FlashPtr>;
pub struct FlashParamsStruct {
align: u8,
align: u16,
erased_val: u8,
}
@ -81,7 +81,7 @@ thread_local! {
pub unsafe fn set_flash(dev_id: u8, dev: &mut dyn Flash) {
THREAD_CTX.with(|ctx| {
ctx.borrow_mut().flash_params.insert(dev_id, FlashParamsStruct {
align: dev.align() as u8,
align: dev.align() as u16,
erased_val: dev.erased_val(),
});
let dev: &'static mut dyn Flash = mem::transmute(dev);
@ -179,7 +179,7 @@ pub extern fn sim_flash_write(dev_id: u8, offset: u32, src: *const u8, size: u32
}
#[no_mangle]
pub extern fn sim_flash_align(id: u8) -> u8 {
pub extern fn sim_flash_align(id: u8) -> u16 {
THREAD_CTX.with(|ctx| {
ctx.borrow().flash_params.get(&id).unwrap().align
})