Sort FlashRegions and always use the first one in the address space
@@ -65,17 +65,7 @@ where
.collect::<Vec<_>>();
// Extract the flash info from the .pdsc file.
- let mut flash = None;
- for memory in device.memories.0.values() {
- if memory.default && memory.access.read && memory.access.execute && !memory.access.write
- {
- flash = Some(FlashRegion {
- range: memory.start as u32..memory.start as u32 + memory.size as u32,
- is_boot_memory: memory.startup,
- });
- break;
- }
- }
+ let flash = get_flash(&device);
// Get the core type.
let core_type = match &device.processor {
@@ -376,3 +366,18 @@ pub(crate) fn get_ram(device: &Device) -> Option<RamRegion> {
regions.last().cloned()
}
}
+
+pub(crate) fn get_flash(device: &Device) -> Option<FlashRegion> {
+ let mut regions = Vec::new();
+ for memory in device.memories.0.values() {
+ if memory.default && memory.access.read && memory.access.execute && !memory.access.write
+ {
+ regions.push(FlashRegion {
+ range: memory.start as u32..memory.start as u32 + memory.size as u32,
+ is_boot_memory: memory.startup,
+ });
+ }
+ }
+ regions.sort_by_key(|r| r.range.start);
+ regions.get(0).cloned()
+}
