sim: Use `usize` instead of `u8` for alignment
Some devices have a write alignment larger than 128. Allow this within
the simulator, by using `usize` instead of `u8` for the write alignment.
The value is still returned to the C code as an 8-bit integer, but this
help start debugging issues found on these devices.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/src/image.rs b/sim/src/image.rs
index 60369ef..d183c40 100644
--- a/sim/src/image.rs
+++ b/sim/src/image.rs
@@ -84,7 +84,7 @@
/// Construct a new image builder for the given device. Returns
/// Some(builder) if is possible to test this configuration, or None if
/// not possible (for example, if there aren't enough image slots).
- pub fn new(device: DeviceName, align: u8, erased_val: u8) -> Option<Self> {
+ pub fn new(device: DeviceName, align: usize, erased_val: u8) -> Option<Self> {
let (flash, areadesc) = Self::make_device(device, align, erased_val);
let num_images = Caps::get_num_images();
@@ -227,7 +227,7 @@
}
/// Build the Flash and area descriptor for a given device.
- pub fn make_device(device: DeviceName, align: u8, erased_val: u8) -> (SimMultiFlash, AreaDesc) {
+ pub fn make_device(device: DeviceName, align: usize, erased_val: u8) -> (SimMultiFlash, AreaDesc) {
match device {
DeviceName::Stm32f4 => {
// STM style flash. Large sectors, with a large scratch area.
diff --git a/sim/src/lib.rs b/sim/src/lib.rs
index bb88bf3..fda376a 100644
--- a/sim/src/lib.rs
+++ b/sim/src/lib.rs
@@ -80,7 +80,7 @@
}
#[derive(Debug)]
-struct AlignArg(u8);
+struct AlignArg(usize);
struct AlignArgVisitor;
@@ -91,11 +91,11 @@
formatter.write_str("1, 2, 4 or 8")
}
- fn visit_u8<E>(self, n: u8) -> Result<Self::Value, E>
+ fn visit_u32<E>(self, n: u32) -> Result<Self::Value, E>
where E: serde::de::Error
{
Ok(match n {
- 1 | 2 | 4 | 8 => AlignArg(n),
+ 1 | 2 | 4 | 8 => AlignArg(n as usize),
n => {
let err = format!("Could not deserialize '{}' as alignment", n);
return Err(E::custom(err));
@@ -169,7 +169,7 @@
}
}
- pub fn run_single(&mut self, device: DeviceName, align: u8, erased_val: u8) {
+ pub fn run_single(&mut self, device: DeviceName, align: usize, erased_val: u8) {
warn!("Running on device {} with alignment {}", device, align);
let run = match ImagesBuilder::new(device, align, erased_val) {