diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f357697..7d59eee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - A new CLI argument `rom-elf` was added which will be used for backtraces (#963) +- A new monitor CLI argument `--all-addresses` was added, by default well known misleading addresses printed by the first stage bootloader are suppressed (#979) + ### Changed - `read_efuse` is deprecated (#969) diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index ec833a2c..4292719c 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -329,6 +329,9 @@ pub struct MonitorConfigArgs { /// Disable address resolution for a smaller log output #[arg(long)] pub no_addresses: bool, + /// Try to resolve all addresses, even well-known misleading ones + #[arg(long)] + pub all_addresses: bool, } /// Arguments for MD5 checksum calculation diff --git a/espflash/src/cli/monitor/mod.rs b/espflash/src/cli/monitor/mod.rs index 7b7da2c9..2cce8aca 100644 --- a/espflash/src/cli/monitor/mod.rs +++ b/espflash/src/cli/monitor/mod.rs @@ -109,7 +109,7 @@ pub fn monitor( let mut stdout = if monitor_args.no_addresses { ResolvingPrinter::new_no_addresses(firmware_elf, stdout.lock()) } else { - ResolvingPrinter::new(elfs, stdout.lock()) + ResolvingPrinter::new(elfs, stdout.lock(), monitor_args.all_addresses) }; let mut parser: Box = match monitor_args @@ -475,6 +475,7 @@ pub fn check_monitor_args( || non_interactive || monitor_args.no_reset || monitor_args.no_addresses + || monitor_args.all_addresses || monitor_args.monitor_baud != 115_200) { warn!( @@ -488,6 +489,12 @@ pub fn check_monitor_args( ); } + if monitor_args.no_addresses && monitor_args.all_addresses { + log::warn!( + "Using `--no-addresses` disables address resolution, making `--all-addresses` ineffective. Consider using only one of these flags." + ); + } + // Check if log-format is used with serial but output-format is specified if let Some(LogFormat::Serial) = monitor_args.log_format { if monitor_args.output_format.is_some() { diff --git a/espflash/src/cli/monitor/parser/mod.rs b/espflash/src/cli/monitor/parser/mod.rs index affa53eb..8fa9e6cb 100644 --- a/espflash/src/cli/monitor/parser/mod.rs +++ b/espflash/src/cli/monitor/parser/mod.rs @@ -20,11 +20,27 @@ pub trait InputParser { // Pattern to much a function address in serial output. static RE_FN_ADDR: LazyLock = LazyLock::new(|| Regex::new(r"0[xX][[:xdigit:]]{8}").unwrap()); +// We won't try to resolve addresses for lines starting with these prefixes. +// Those lines are output from the first stage bootloader mostly about loading +// the 2nd stage bootloader. The resolved addresses are not useful and mostly +// confusing noise. +const SUPPRESS_FOR_LINE_START: &[&str] = &[ + "Saved PC:", // this might be useful to see in some situations + "load:0x", + "entry 0x", +]; + fn resolve_addresses( symbols: &Symbols<'_>, line: &str, out: &mut dyn Write, + try_resolve_all_addresses: bool, ) -> std::io::Result<()> { + // suppress resolving well known misleading addresses + if !try_resolve_all_addresses && SUPPRESS_FOR_LINE_START.iter().any(|s| line.starts_with(s)) { + return Ok(()); + } + // Check the previous line for function addresses. For each address found, // attempt to look up the associated function's name and location and write both // to the terminal. @@ -113,11 +129,12 @@ pub struct ResolvingPrinter<'ctx, W: Write> { merger: Utf8Merger, line_fragment: String, disable_address_resolution: bool, + try_resolve_all_addresses: bool, } impl<'ctx, W: Write> ResolvingPrinter<'ctx, W> { /// Creates a new `ResolvingPrinter` with the given ELF file and writer. - pub fn new(elf: Vec<&'ctx [u8]>, writer: W) -> Self { + pub fn new(elf: Vec<&'ctx [u8]>, writer: W, try_resolve_all_addresses: bool) -> Self { Self { writer, symbols: elf @@ -128,6 +145,7 @@ impl<'ctx, W: Write> ResolvingPrinter<'ctx, W> { merger: Utf8Merger::new(), line_fragment: String::new(), disable_address_resolution: false, + try_resolve_all_addresses, } } @@ -140,6 +158,7 @@ impl<'ctx, W: Write> ResolvingPrinter<'ctx, W> { merger: Utf8Merger::new(), line_fragment: String::new(), disable_address_resolution: true, + try_resolve_all_addresses: false, } } } @@ -181,7 +200,12 @@ impl Write for ResolvingPrinter<'_, W> { if !self.disable_address_resolution { for symbols in &self.symbols { // Try to print the names of addresses in the current line. - resolve_addresses(symbols, &line, &mut self.writer)?; + resolve_addresses( + symbols, + &line, + &mut self.writer, + self.try_resolve_all_addresses, + )?; } if line.starts_with(stack_dump::MARKER) diff --git a/espflash/src/flasher/mod.rs b/espflash/src/flasher/mod.rs index 20e35534..4f5c5511 100644 --- a/espflash/src/flasher/mod.rs +++ b/espflash/src/flasher/mod.rs @@ -463,8 +463,8 @@ impl DeviceInfo { pub fn rom(&self) -> Option> { match self.chip { Chip::Esp32 => { - if let Some((major, _)) = self.revision { - if major >= 3 { + if let Some((_, minor)) = self.revision { + if minor >= 3 { Some(include_bytes!("../../resources/roms/esp32_rev300_rom.elf").into()) } else { Some(include_bytes!("../../resources/roms/esp32_rev0_rom.elf").into()) @@ -477,8 +477,8 @@ impl DeviceInfo { Some(include_bytes!("../../resources/roms/esp32c2_rev100_rom.elf").into()) } Chip::Esp32c3 => { - if let Some((major, _)) = self.revision { - if major >= 3 { + if let Some((_, minor)) = self.revision { + if minor >= 3 { Some(include_bytes!("../../resources/roms/esp32c3_rev3_rom.elf").into()) } else { Some(include_bytes!("../../resources/roms/esp32c3_rev0_rom.elf").into())