Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion espflash/src/cli/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ pub fn monitor(
let firmware_elf = elfs.first().map(|v| &**v);
let stdout = stdout();
let mut stdout = if monitor_args.no_addresses {
if monitor_args.all_addresses {
log::warn!("Suppressing address resolution with `--all-addresses` given");
}

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<dyn InputParser> = match monitor_args
Expand Down
28 changes: 26 additions & 2 deletions espflash/src/cli/monitor/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,27 @@ pub trait InputParser {
// Pattern to much a function address in serial output.
static RE_FN_ADDR: LazyLock<Regex> = 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.
Expand Down Expand Up @@ -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
Expand All @@ -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,
}
}

Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -181,7 +200,12 @@ impl<W: Write> 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)
Expand Down
8 changes: 4 additions & 4 deletions espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ impl DeviceInfo {
pub fn rom(&self) -> Option<Vec<u8>> {
match self.chip {
Chip::Esp32 => {
if let Some((major, _)) = self.revision {
if major >= 3 {
if let Some((_, minor)) = self.revision {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are needed after fixing the efuse reading (in a previous PR) - I just noticed it when working on this

if minor >= 3 {
Some(include_bytes!("../../resources/roms/esp32_rev300_rom.elf").into())
} else {
Some(include_bytes!("../../resources/roms/esp32_rev0_rom.elf").into())
Expand All @@ -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())
Expand Down