Commit 5a317752 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

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: default avatarDavid Brown <david.brown@linaro.org>
parent ab449187
Loading
Loading
Loading
Loading
+2 −2
Changes for sim/src/image.rs: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ impl ImagesBuilder {
    /// 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 @@ impl ImagesBuilder {
    }

    /// 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.
+4 −4
Changes for sim/src/lib.rs: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ impl fmt::Display for DeviceName {
}

#[derive(Debug)]
struct AlignArg(u8);
struct AlignArg(usize);

struct AlignArgVisitor;

@@ -91,11 +91,11 @@ impl<'de> serde::de::Visitor<'de> for AlignArgVisitor {
        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 @@ impl RunStatus {
        }
    }

    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) {