Skip to content

Commit 3177481

Browse files
authored
Remove get_ prefixes from various functions (#824)
* Rename `get_flash_image` function to `flash_image` * Rename `get_serial_port_info` function to `serial_port_info` * Remove `get_` prefix from some functions in `Symbol` struct * Remove `get_` prefix from some functions in `flasher` module * Remove all remaining `get_` prefixes * Update `CHANGELOG.md`
1 parent eeef009 commit 3177481

File tree

19 files changed

+68
-72
lines changed

19 files changed

+68
-72
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- `IdfBootloaderFormat` has had its constructor's parameters reduced/simplified (#798)
3434
- Update flash size when creating the app partition (#797)
3535
- `--non-interactive` may now react to key events (user input, Ctrl-C, Ctrl-R) if possible (#819)
36+
- Removed `get_` prefix from any functions which previously had it (#824)
3637

3738
### Fixed
3839

espflash/src/cli/config.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,9 @@ pub struct Config {
102102
}
103103

104104
impl Config {
105-
/// Gets the path to the configuration file.
106-
pub fn get_config_path() -> Result<PathBuf, Error> {
107-
let local_config = std::env::current_dir()?.join("espflash.toml");
108-
if local_config.exists() {
109-
return Ok(local_config);
110-
}
111-
if let Some(parent_folder) = std::env::current_dir()?.parent() {
112-
let workspace_config = parent_folder.join("espflash.toml");
113-
if workspace_config.exists() {
114-
return Ok(workspace_config);
115-
}
116-
}
117-
118-
let project_dirs = ProjectDirs::from("rs", "esp", "espflash").unwrap();
119-
let global_config = project_dirs.config_dir().join("espflash.toml");
120-
Ok(global_config)
121-
}
122-
123105
/// Load configuration from the configuration file
124106
pub fn load() -> Result<Self> {
125-
let file = Self::get_config_path()?;
107+
let file = Self::config_path()?;
126108

127109
let mut config = if let Ok(data) = read_to_string(&file) {
128110
toml::from_str(&data).into_diagnostic()?
@@ -163,6 +145,23 @@ impl Config {
163145
.into_diagnostic()
164146
.wrap_err_with(|| format!("Failed to write config to {}", self.save_path.display()))
165147
}
148+
149+
fn config_path() -> Result<PathBuf, Error> {
150+
let local_config = std::env::current_dir()?.join("espflash.toml");
151+
if local_config.exists() {
152+
return Ok(local_config);
153+
}
154+
if let Some(parent_folder) = std::env::current_dir()?.parent() {
155+
let workspace_config = parent_folder.join("espflash.toml");
156+
if workspace_config.exists() {
157+
return Ok(workspace_config);
158+
}
159+
}
160+
161+
let project_dirs = ProjectDirs::from("rs", "esp", "espflash").unwrap();
162+
let global_config = project_dirs.config_dir().join("espflash.toml");
163+
Ok(global_config)
164+
}
166165
}
167166

168167
#[cfg(test)]

espflash/src/cli/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use serialport::{FlowControl, SerialPortInfo, SerialPortType, UsbPortInfo};
3131
use self::{
3232
config::Config,
3333
monitor::{monitor, LogFormat},
34-
serial::get_serial_port_info,
3534
};
3635
use crate::{
3736
connection::reset::{ResetAfterOperation, ResetBeforeOperation},
@@ -369,7 +368,7 @@ pub fn connect(
369368
);
370369
}
371370

372-
let port_info = get_serial_port_info(args, config)?;
371+
let port_info = serial::serial_port_info(args, config)?;
373372

374373
// Attempt to open the serial port and set its initial baud rate.
375374
info!("Serial port: '{}'", port_info.port_name);
@@ -417,7 +416,7 @@ pub fn board_info(args: &ConnectArgs, config: &Config) -> Result<()> {
417416
print_board_info(&mut flasher)?;
418417

419418
if flasher.chip() != Chip::Esp32 {
420-
let security_info = flasher.get_security_info()?;
419+
let security_info = flasher.security_info()?;
421420
println!("{security_info}");
422421
} else {
423422
println!("Security features: None");
@@ -614,7 +613,7 @@ pub fn save_elf_as_image(
614613
// For simplicity, the revision None is used
615614
let image = chip
616615
.into_target()
617-
.get_flash_image(elf, flash_data.clone(), None, xtal_freq)?;
616+
.flash_image(elf, flash_data.clone(), None, xtal_freq)?;
618617

619618
display_image_size(image.app_size(), image.part_size());
620619

@@ -648,7 +647,7 @@ pub fn save_elf_as_image(
648647
} else {
649648
let image = chip
650649
.into_target()
651-
.get_flash_image(elf, flash_data, None, xtal_freq)?;
650+
.flash_image(elf, flash_data, None, xtal_freq)?;
652651

653652
display_image_size(image.app_size(), image.part_size());
654653

espflash/src/cli/monitor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn deduce_log_format(elf: Option<&[u8]>) -> LogFormat {
201201
};
202202

203203
let Some(format_symbol) =
204-
symbols.get_symbol_data(Some(".espressif.metadata"), b"espflash.LOG_FORMAT")
204+
symbols.symbol_data(Some(".espressif.metadata"), b"espflash.LOG_FORMAT")
205205
else {
206206
return LogFormat::Serial;
207207
};

espflash/src/cli/monitor/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ fn resolve_addresses(
3232
// successfully into an integer.
3333
let addr = u64::from_str_radix(&matched[2..], 16).unwrap();
3434

35-
let name = symbols.get_name(addr);
36-
let location = symbols.get_location(addr);
35+
let name = symbols.name(addr);
36+
let location = symbols.location(addr);
3737

3838
if let Some(name) = name {
3939
let output = if line.trim() == format!("0x{:x}", addr) {

espflash/src/cli/monitor/symbols.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'sym> Symbols<'sym> {
3434

3535
/// Returns the name of the function at the given address, if one can be
3636
/// found.
37-
pub fn get_name(&self, addr: u64) -> Option<String> {
37+
pub fn name(&self, addr: u64) -> Option<String> {
3838
// No need to try an address not contained in any segment:
3939
if !self.object.segments().any(|segment| {
4040
(segment.address()..(segment.address() + segment.size())).contains(&addr)
@@ -85,7 +85,7 @@ impl<'sym> Symbols<'sym> {
8585

8686
/// Returns the file name and line number of the function at the given
8787
/// address, if one can be.
88-
pub fn get_location(&self, addr: u64) -> Option<(String, u32)> {
88+
pub fn location(&self, addr: u64) -> Option<(String, u32)> {
8989
// Find the location which `addr` is in. If we can dedetermine a file name and
9090
// line number for this function we will return them both in a tuple.
9191
self.ctx.find_location(addr).ok()?.map(|location| {
@@ -99,7 +99,7 @@ impl<'sym> Symbols<'sym> {
9999
})?
100100
}
101101

102-
pub(crate) fn get_symbol_data(
102+
pub(crate) fn symbol_data(
103103
&self,
104104
section_name: Option<&str>,
105105
name_bytes: &[u8],

espflash/src/cli/serial.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use crate::{
1414

1515
/// Return the information of a serial port taking into account the different
1616
/// ways of choosing a port.
17-
pub fn get_serial_port_info(
18-
matches: &ConnectArgs,
19-
config: &Config,
20-
) -> Result<SerialPortInfo, Error> {
17+
pub fn serial_port_info(matches: &ConnectArgs, config: &Config) -> Result<SerialPortInfo, Error> {
2118
// A serial port should be specified either as a command-line argument or in a
2219
// configuration file. In the case that both have been provided the command-line
2320
// argument takes precedence.

espflash/src/connection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl Connection {
383383
}
384384

385385
/// Get the current baud rate of the serial port
386-
pub fn get_baud(&self) -> Result<u32, Error> {
386+
pub fn baud(&self) -> Result<u32, Error> {
387387
Ok(self.serial.baud_rate()?)
388388
}
389389

espflash/src/flasher/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl SecurityInfo {
8686
])
8787
}
8888

89-
fn get_security_flag_status(&self, flag_name: &str) -> bool {
89+
fn security_flag_status(&self, flag_name: &str) -> bool {
9090
if let Some(&flag) = Self::security_flag_map().get(flag_name) {
9191
(self.flags & flag) != 0
9292
} else {
@@ -162,9 +162,9 @@ impl fmt::Display for SecurityInfo {
162162
}
163163

164164
// Secure Boot
165-
if self.get_security_flag_status("SECURE_BOOT_EN") {
165+
if self.security_flag_status("SECURE_BOOT_EN") {
166166
writeln!(f, "Secure Boot: Enabled")?;
167-
if self.get_security_flag_status("SECURE_BOOT_AGGRESSIVE_REVOKE") {
167+
if self.security_flag_status("SECURE_BOOT_AGGRESSIVE_REVOKE") {
168168
writeln!(f, "Secure Boot Aggressive key revocation: Enabled")?;
169169
}
170170

@@ -175,7 +175,7 @@ impl fmt::Display for SecurityInfo {
175175
]
176176
.iter()
177177
.enumerate()
178-
.filter(|(_, &key)| self.get_security_flag_status(key))
178+
.filter(|(_, &key)| self.security_flag_status(key))
179179
.map(|(i, _)| format!("Secure Boot Key{} is Revoked", i))
180180
.collect();
181181

@@ -201,22 +201,22 @@ impl fmt::Display for SecurityInfo {
201201
writeln!(f, "{}: 0x{:x}", crypt_cnt_str, self.flash_crypt_cnt)?;
202202

203203
// Cache Disabling
204-
if self.get_security_flag_status("DIS_DOWNLOAD_DCACHE") {
204+
if self.security_flag_status("DIS_DOWNLOAD_DCACHE") {
205205
writeln!(f, "Dcache in UART download mode: Disabled")?;
206206
}
207-
if self.get_security_flag_status("DIS_DOWNLOAD_ICACHE") {
207+
if self.security_flag_status("DIS_DOWNLOAD_ICACHE") {
208208
writeln!(f, "Icache in UART download mode: Disabled")?;
209209
}
210210

211211
// JTAG Status
212-
if self.get_security_flag_status("HARD_DIS_JTAG") {
212+
if self.security_flag_status("HARD_DIS_JTAG") {
213213
writeln!(f, "JTAG: Permanently Disabled")?;
214-
} else if self.get_security_flag_status("SOFT_DIS_JTAG") {
214+
} else if self.security_flag_status("SOFT_DIS_JTAG") {
215215
writeln!(f, "JTAG: Software Access Disabled")?;
216216
}
217217

218218
// USB Access
219-
if self.get_security_flag_status("DIS_USB") {
219+
if self.security_flag_status("DIS_USB") {
220220
writeln!(f, "USB Access: Disabled")?;
221221
}
222222

@@ -1057,7 +1057,7 @@ impl Flasher {
10571057
let image =
10581058
self.chip
10591059
.into_target()
1060-
.get_flash_image(elf, flash_data, chip_revision, xtal_freq)?;
1060+
.flash_image(elf, flash_data, chip_revision, xtal_freq)?;
10611061

10621062
// When the `cli` feature is enabled, display the image size information.
10631063
#[cfg(feature = "cli")]
@@ -1124,15 +1124,15 @@ impl Flasher {
11241124
}
11251125

11261126
/// Get security info
1127-
pub fn get_security_info(&mut self) -> Result<SecurityInfo, Error> {
1128-
get_security_info(&mut self.connection, self.use_stub)
1127+
pub fn security_info(&mut self) -> Result<SecurityInfo, Error> {
1128+
security_info(&mut self.connection, self.use_stub)
11291129
}
11301130

11311131
pub fn change_baud(&mut self, speed: u32) -> Result<(), Error> {
11321132
debug!("Change baud to: {}", speed);
11331133

11341134
let prior_baud = match self.use_stub {
1135-
true => self.connection.get_baud()?,
1135+
true => self.connection.baud()?,
11361136
false => 0,
11371137
};
11381138

@@ -1350,7 +1350,7 @@ impl Flasher {
13501350
}
13511351

13521352
#[cfg(feature = "serialport")]
1353-
fn get_security_info(connection: &mut Connection, use_stub: bool) -> Result<SecurityInfo, Error> {
1353+
fn security_info(connection: &mut Connection, use_stub: bool) -> Result<SecurityInfo, Error> {
13541354
connection.with_timeout(CommandType::GetSecurityInfo.timeout(), |connection| {
13551355
let response = connection.command(Command::GetSecurityInfo)?;
13561356
// Extract raw bytes and convert them into `SecurityInfo`
@@ -1369,7 +1369,7 @@ fn get_security_info(connection: &mut Connection, use_stub: bool) -> Result<Secu
13691369

13701370
#[cfg(feature = "serialport")]
13711371
fn detect_chip(connection: &mut Connection, use_stub: bool) -> Result<Chip, Error> {
1372-
match get_security_info(connection, use_stub) {
1372+
match security_info(connection, use_stub) {
13731373
Ok(info) if info.chip_id.is_some() => {
13741374
let chip_id = info.chip_id.unwrap() as u16;
13751375
let chip = Chip::try_from(chip_id)?;

espflash/src/image_format/esp_idf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a> IdfBootloaderFormat<'a> {
206206

207207
for segment in flash_segments {
208208
loop {
209-
let pad_len = get_segment_padding(data.len(), &segment);
209+
let pad_len = segment_padding(data.len(), &segment);
210210
if pad_len > 0 {
211211
if pad_len > SEG_HEADER_LEN {
212212
if let Some(ram_segment) = ram_segments.first_mut() {
@@ -399,7 +399,7 @@ fn default_partition_table(params: &Esp32Params, flash_size: Option<u32>) -> Par
399399
///
400400
/// (this is because the segment's vaddr may not be IROM_ALIGNed, more likely is
401401
/// aligned IROM_ALIGN+0x18 to account for the binary file header)
402-
fn get_segment_padding(offset: usize, segment: &Segment<'_>) -> u32 {
402+
fn segment_padding(offset: usize, segment: &Segment<'_>) -> u32 {
403403
let align_past = (segment.addr - SEG_HEADER_LEN) % IROM_ALIGN;
404404
let pad_len = ((IROM_ALIGN - ((offset as u32) % IROM_ALIGN)) + align_past) % IROM_ALIGN;
405405

0 commit comments

Comments
 (0)