Commit f38bc342 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: Make `find_image` dynamic instead of cfg

Change the `find_image` to use a dynamic query instead of compile time
configuration.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent b8882113
Loading
Loading
Loading
Loading
+5 −17
Changes for sim/src/image.rs: 5 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -811,31 +811,19 @@ fn make_tlv() -> TlvGen {
    }
}

#[cfg(feature = "enc-rsa")]
fn find_image(images: &[Option<Vec<u8>>; 2], slot: usize) -> &Vec<u8> {
    match &images[slot] {
        Some(image) => return image,
        None => panic!("Invalid image"),
    }
}
    let slot = if Caps::EncRsa.present() || Caps::EncKw.present() {
        slot
    } else {
        0
    };

#[cfg(feature = "enc-kw")]
fn find_image(images: &[Option<Vec<u8>>; 2], slot: usize) -> &Vec<u8> {
    match &images[slot] {
        Some(image) => return image,
        None => panic!("Invalid image"),
    }
}

#[cfg(not(feature = "enc-rsa"))]
#[cfg(not(feature = "enc-kw"))]
fn find_image(images: &[Option<Vec<u8>>; 2], _slot: usize) -> &Vec<u8> {
    match &images[0] {
        Some(image) => return image,
        None => panic!("Invalid image"),
    }
}

/// Verify that given image is present in the flash at the given offset.
fn verify_image(flashmap: &SimFlashMap, slots: &[SlotInfo], slot: usize,
                images: &[Option<Vec<u8>>; 2]) -> bool {