Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion espflash/src/cli/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn InputParser> = match monitor_args
Expand Down Expand Up @@ -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!(
Expand All @@ -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() {
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