Skip to content

Commit 1efe57a

Browse files
Suppress resolving addresses for 1st stage bootloader output (#979)
* Suppress resolving addresses for 1st stage bootloader output * PR number * Update espflash/src/cli/monitor/mod.rs Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com> * Add `\r\n` to avoid weird formatting of output * Fix log output --------- Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com>
1 parent 70bea62 commit 1efe57a

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
- A new CLI argument `rom-elf` was added which will be used for backtraces (#963)
1414

15+
- A new monitor CLI argument `--all-addresses` was added, by default well known misleading addresses printed by the first stage bootloader are suppressed (#979)
16+
1517
### Changed
1618
- `read_efuse` is deprecated (#969)
1719

espflash/src/cli/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ pub struct MonitorConfigArgs {
329329
/// Disable address resolution for a smaller log output
330330
#[arg(long)]
331331
pub no_addresses: bool,
332+
/// Try to resolve all addresses, even well-known misleading ones
333+
#[arg(long)]
334+
pub all_addresses: bool,
332335
}
333336

334337
/// Arguments for MD5 checksum calculation

espflash/src/cli/monitor/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn monitor(
109109
let mut stdout = if monitor_args.no_addresses {
110110
ResolvingPrinter::new_no_addresses(firmware_elf, stdout.lock())
111111
} else {
112-
ResolvingPrinter::new(elfs, stdout.lock())
112+
ResolvingPrinter::new(elfs, stdout.lock(), monitor_args.all_addresses)
113113
};
114114

115115
let mut parser: Box<dyn InputParser> = match monitor_args
@@ -475,6 +475,7 @@ pub fn check_monitor_args(
475475
|| non_interactive
476476
|| monitor_args.no_reset
477477
|| monitor_args.no_addresses
478+
|| monitor_args.all_addresses
478479
|| monitor_args.monitor_baud != 115_200)
479480
{
480481
warn!(
@@ -488,6 +489,12 @@ pub fn check_monitor_args(
488489
);
489490
}
490491

492+
if monitor_args.no_addresses && monitor_args.all_addresses {
493+
log::warn!(
494+
"Using `--no-addresses` disables address resolution, making `--all-addresses` ineffective. Consider using only one of these flags."
495+
);
496+
}
497+
491498
// Check if log-format is used with serial but output-format is specified
492499
if let Some(LogFormat::Serial) = monitor_args.log_format {
493500
if monitor_args.output_format.is_some() {

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,27 @@ pub trait InputParser {
2020
// Pattern to much a function address in serial output.
2121
static RE_FN_ADDR: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"0[xX][[:xdigit:]]{8}").unwrap());
2222

23+
// We won't try to resolve addresses for lines starting with these prefixes.
24+
// Those lines are output from the first stage bootloader mostly about loading
25+
// the 2nd stage bootloader. The resolved addresses are not useful and mostly
26+
// confusing noise.
27+
const SUPPRESS_FOR_LINE_START: &[&str] = &[
28+
"Saved PC:", // this might be useful to see in some situations
29+
"load:0x",
30+
"entry 0x",
31+
];
32+
2333
fn resolve_addresses(
2434
symbols: &Symbols<'_>,
2535
line: &str,
2636
out: &mut dyn Write,
37+
try_resolve_all_addresses: bool,
2738
) -> std::io::Result<()> {
39+
// suppress resolving well known misleading addresses
40+
if !try_resolve_all_addresses && SUPPRESS_FOR_LINE_START.iter().any(|s| line.starts_with(s)) {
41+
return Ok(());
42+
}
43+
2844
// Check the previous line for function addresses. For each address found,
2945
// attempt to look up the associated function's name and location and write both
3046
// to the terminal.
@@ -113,11 +129,12 @@ pub struct ResolvingPrinter<'ctx, W: Write> {
113129
merger: Utf8Merger,
114130
line_fragment: String,
115131
disable_address_resolution: bool,
132+
try_resolve_all_addresses: bool,
116133
}
117134

118135
impl<'ctx, W: Write> ResolvingPrinter<'ctx, W> {
119136
/// Creates a new `ResolvingPrinter` with the given ELF file and writer.
120-
pub fn new(elf: Vec<&'ctx [u8]>, writer: W) -> Self {
137+
pub fn new(elf: Vec<&'ctx [u8]>, writer: W, try_resolve_all_addresses: bool) -> Self {
121138
Self {
122139
writer,
123140
symbols: elf
@@ -128,6 +145,7 @@ impl<'ctx, W: Write> ResolvingPrinter<'ctx, W> {
128145
merger: Utf8Merger::new(),
129146
line_fragment: String::new(),
130147
disable_address_resolution: false,
148+
try_resolve_all_addresses,
131149
}
132150
}
133151

@@ -140,6 +158,7 @@ impl<'ctx, W: Write> ResolvingPrinter<'ctx, W> {
140158
merger: Utf8Merger::new(),
141159
line_fragment: String::new(),
142160
disable_address_resolution: true,
161+
try_resolve_all_addresses: false,
143162
}
144163
}
145164
}
@@ -181,7 +200,12 @@ impl<W: Write> Write for ResolvingPrinter<'_, W> {
181200
if !self.disable_address_resolution {
182201
for symbols in &self.symbols {
183202
// Try to print the names of addresses in the current line.
184-
resolve_addresses(symbols, &line, &mut self.writer)?;
203+
resolve_addresses(
204+
symbols,
205+
&line,
206+
&mut self.writer,
207+
self.try_resolve_all_addresses,
208+
)?;
185209
}
186210

187211
if line.starts_with(stack_dump::MARKER)

espflash/src/flasher/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ impl DeviceInfo {
463463
pub fn rom(&self) -> Option<Vec<u8>> {
464464
match self.chip {
465465
Chip::Esp32 => {
466-
if let Some((major, _)) = self.revision {
467-
if major >= 3 {
466+
if let Some((_, minor)) = self.revision {
467+
if minor >= 3 {
468468
Some(include_bytes!("../../resources/roms/esp32_rev300_rom.elf").into())
469469
} else {
470470
Some(include_bytes!("../../resources/roms/esp32_rev0_rom.elf").into())
@@ -477,8 +477,8 @@ impl DeviceInfo {
477477
Some(include_bytes!("../../resources/roms/esp32c2_rev100_rom.elf").into())
478478
}
479479
Chip::Esp32c3 => {
480-
if let Some((major, _)) = self.revision {
481-
if major >= 3 {
480+
if let Some((_, minor)) = self.revision {
481+
if minor >= 3 {
482482
Some(include_bytes!("../../resources/roms/esp32c3_rev3_rom.elf").into())
483483
} else {
484484
Some(include_bytes!("../../resources/roms/esp32c3_rev0_rom.elf").into())

0 commit comments

Comments
 (0)