Skip to content
Draft
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
8 changes: 1 addition & 7 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ use crate::{
},
error::{Error, MissingPartition, MissingPartitionTable},
flasher::{
FLASH_SECTOR_SIZE,
FlashData,
FlashFrequency,
FlashMode,
FlashSettings,
FlashSize,
Flasher,
FLASH_SECTOR_SIZE, FlashData, FlashFrequency, FlashMode, FlashSettings, FlashSize, Flasher,
},
image_format::{ImageFormat, ImageFormatKind, Metadata, idf::IdfBootloaderFormat},
target::{Chip, ProgressCallbacks, XtalFrequency},
Expand Down
3 changes: 1 addition & 2 deletions espflash/src/cli/monitor/parser/esp_defmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::io::Write;

use crossterm::{QueueableCommand, style::Print};
use defmt_decoder::{
Frame,
Table,
Frame, Table,
log::format::{Formatter, FormatterConfig, FormatterFormat},
};
use log::warn;
Expand Down
3 changes: 1 addition & 2 deletions espflash/src/cli/monitor/symbols.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::error::Error;

use addr2line::{
Context,
LookupResult,
Context, LookupResult,
gimli::{self, Dwarf, EndianSlice, LittleEndian, SectionId},
};
use object::{Object, ObjectSection, ObjectSegment, ObjectSymbol, read::File};
Expand Down
9 changes: 2 additions & 7 deletions espflash/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ use self::reset::UnixTightReset;
use self::{
encoder::SlipEncoder,
reset::{
ClassicReset,
ResetStrategy,
UsbJtagSerialReset,
construct_reset_strategy_sequence,
hard_reset,
reset_after_flash,
soft_reset,
ClassicReset, ResetStrategy, UsbJtagSerialReset, construct_reset_strategy_sequence,
hard_reset, reset_after_flash, soft_reset,
},
};
use crate::{
Expand Down
5 changes: 1 addition & 4 deletions espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ use crate::{
connection::{Connection, reset::ResetBeforeOperation},
error::{ConnectionError, ResultExt as _},
flasher::stubs::{
CHIP_DETECT_MAGIC_REG_ADDR,
DEFAULT_TIMEOUT,
EXPECTED_STUB_HANDSHAKE,
FlashStub,
CHIP_DETECT_MAGIC_REG_ADDR, DEFAULT_TIMEOUT, EXPECTED_STUB_HANDSHAKE, FlashStub,
},
image_format::{ImageFormat, Segment, ram_segments, rom_segments},
};
Expand Down
15 changes: 2 additions & 13 deletions espflash/src/image_format/idf.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
//! ESP-IDF application binary image format

use std::{
borrow::Cow,
collections::HashMap,
ffi::c_char,
fs,
io::Write,
iter::once,
mem::size_of,
borrow::Cow, collections::HashMap, ffi::c_char, fs, io::Write, iter::once, mem::size_of,
path::Path,
};

Expand All @@ -16,12 +10,7 @@ use esp_idf_part::{AppType, DataType, Flags, Partition, PartitionTable, SubType,
use log::warn;
use miette::{IntoDiagnostic, Result};
use object::{
Endianness,
File,
Object,
ObjectSection,
ObjectSymbol,
read::elf::ElfFile32 as ElfFile,
Endianness, File, Object, ObjectSection, ObjectSymbol, read::elf::ElfFile32 as ElfFile,
};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
Expand Down
4 changes: 1 addition & 3 deletions espflash/src/image_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use std::{
};

use object::{
Endianness,
Object as _,
ObjectSection as _,
Endianness, Object as _, ObjectSection as _,
elf::SHT_PROGBITS,
read::elf::{ElfFile32 as ElfFile, SectionHeader},
};
Expand Down
45 changes: 33 additions & 12 deletions espflash/src/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use strum::{Display, EnumIter, EnumString, IntoEnumIterator, VariantNames};

#[cfg(feature = "serialport")]
pub use self::flash_target::{
DefaultProgressCallback,
Esp32Target,
FlashTarget,
ProgressCallbacks,
RamTarget,
DefaultProgressCallback, Esp32Target, FlashTarget, ProgressCallbacks, RamTarget,
};
use crate::{
Error,
Expand Down Expand Up @@ -417,16 +413,41 @@ impl Chip {
/// region.
#[cfg(feature = "serialport")]
pub fn read_efuse(&self, connection: &mut Connection, field: EfuseField) -> Result<u32, Error> {
let mask = if field.bit_count == 32 {
u32::MAX
} else {
(1u32 << field.bit_count) - 1
// TODO: Figure out how to fix this. (esp-rs/espflash#960)
if field.bit_count > 32 {
panic!("Tried to read an eFuse field of more than 32 bits");
}

// Calculate the number of bits per word in case the field spans two eFuse words.
let bit_count_first = 32 - (field.bit_start % 32);
let bit_count_second = field.bit_count - bit_count_first;

let value = {
let mask = ((1u32 << bit_count_first) - 1) << bit_count_second;
let shift = (field.bit_start % 32) - bit_count_second;

let value = self.read_efuse_raw(connection, field.block, field.word)?;
let value = (value >> shift) & mask;
value
};

let shift = field.bit_start % 32;
let value = if bit_count_second == 0 {
value
} else {
// The second half doesn't need to be shifted since it will always start at bit 0.
let mask = (1u32 << bit_count_second) - 1;

// Potentially wrap around to the next eFuse block.
let (block, word) = if (field.word + 1) > self.block_size(field.block as usize) {
(field.block + 1, 0)
} else {
(field.block, field.word + 1)
};

let value = self.read_efuse_raw(connection, field.block, field.word)?;
let value = (value >> shift) & mask;
let second_value = self.read_efuse_raw(connection, block, word)?;

value | (second_value & mask)
};

Ok(value)
}
Expand Down
Loading