Skip to content

Commit 8265d6b

Browse files
committed
Add a setting to disable creating a backing memory region for SVD regions
This is apart of #6678
1 parent 4e77062 commit 8265d6b

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

plugins/svd/src/mapper.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,29 @@ impl DeviceMapper {
163163
let memory_info =
164164
self.peripheral_block_memory_info(peripheral, address_block, block_name.clone());
165165

166-
// Add the block segment, section and backing memory.
167-
let data_memory = DataBuffer::new(&vec![0; address_block.size as usize]).unwrap();
168-
let added_memory = view.memory_map().add_data_memory_region(
169-
&block_name,
170-
block_addr,
171-
&data_memory,
172-
Some(memory_info.segment_flags),
173-
);
174-
view.add_segment(memory_info.segment);
175-
view.add_section(memory_info.section);
176-
177-
if !added_memory {
178-
log::error!(
179-
"Failed to add memory for peripheral block! {} @ 0x{:x}",
180-
block_name,
181-
block_addr
166+
// Add the block segment, section and backing memory (optional).
167+
if self.settings.add_backing_regions {
168+
// Because adding a memory region will add a possibly large memory buffer in the BNDB, this
169+
// is optional. if a user disables this, they cannot write to the segment until they add a backing memory region.
170+
let data_memory = DataBuffer::new(&vec![0; address_block.size as usize]).unwrap();
171+
let added_memory = view.memory_map().add_data_memory_region(
172+
&block_name,
173+
block_addr,
174+
&data_memory,
175+
Some(memory_info.segment_flags),
182176
);
177+
178+
if !added_memory {
179+
log::error!(
180+
"Failed to add memory for peripheral block! {} @ 0x{:x}",
181+
block_name,
182+
block_addr
183+
);
184+
}
183185
}
186+
187+
view.add_segment(memory_info.segment);
188+
view.add_section(memory_info.section);
184189

185190
// Handle usage specific stuff like adding registers.
186191
match address_block.usage {

plugins/svd/src/settings.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ use std::path::PathBuf;
55

66
#[derive(Debug, Clone)]
77
pub struct LoadSettings {
8+
pub add_backing_regions: bool,
89
pub add_bitfields: bool,
910
pub add_comments: bool,
1011
pub auto_load_file: Option<PathBuf>,
1112
}
1213

1314
impl LoadSettings {
15+
pub const ADD_BACKING_REGIONS_DEFAULT: bool = true;
16+
pub const ADD_BACKING_REGIONS_SETTING: &'static str = "analysis.svd.addBackingRegions";
1417
pub const ADD_BITFIELDS_DEFAULT: bool = true;
1518
pub const ADD_BITFIELDS_SETTING: &'static str = "analysis.svd.addBitfields";
1619
pub const ADD_COMMENTS_DEFAULT: bool = true;
@@ -21,6 +24,15 @@ impl LoadSettings {
2124
pub fn register() {
2225
let bn_settings = Settings::new();
2326

27+
let add_backing_region_props = json!({
28+
"title" : "Add Backing Regions",
29+
"type" : "boolean",
30+
"default" : Self::ADD_BACKING_REGIONS_DEFAULT,
31+
"description" : "Whether to add backing regions. Backing regions allow you to write to the underlying memory of a view, but will take up space in the BNDB.",
32+
});
33+
bn_settings
34+
.register_setting_json(Self::ADD_BACKING_REGIONS_SETTING, add_backing_region_props.to_string());
35+
2436
let add_bitfields_props = json!({
2537
"title" : "Add Bitfields",
2638
"type" : "boolean",
@@ -53,6 +65,10 @@ impl LoadSettings {
5365
let mut load_settings = LoadSettings::default();
5466
let settings = Settings::new();
5567
let mut query_opts = QueryOptions::new_with_view(view);
68+
if settings.contains(Self::ADD_BACKING_REGIONS_SETTING) {
69+
load_settings.add_backing_regions =
70+
settings.get_bool_with_opts(Self::ADD_BACKING_REGIONS_SETTING, &mut query_opts);
71+
}
5672
if settings.contains(Self::ADD_BITFIELDS_SETTING) {
5773
load_settings.add_bitfields =
5874
settings.get_bool_with_opts(Self::ADD_BITFIELDS_SETTING, &mut query_opts);
@@ -76,6 +92,7 @@ impl LoadSettings {
7692
impl Default for LoadSettings {
7793
fn default() -> Self {
7894
Self {
95+
add_backing_regions: Self::ADD_BACKING_REGIONS_DEFAULT,
7996
add_bitfields: Self::ADD_BITFIELDS_DEFAULT,
8097
add_comments: Self::ADD_COMMENTS_DEFAULT,
8198
auto_load_file: None,

0 commit comments

Comments
 (0)