Skip to content

Commit 652c2af

Browse files
committed
oops v2
1 parent efb9004 commit 652c2af

File tree

24 files changed

+549
-544
lines changed

24 files changed

+549
-544
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Non-linux-musl: Only list the available USB Ports by default (#590)
2020
- `FlashData::new` now returns `crate::Error` (#591)
2121
- Moved `reset_after_flash` method to `reset` module (#594)
22+
- Moved `parse_partition_table, DeviceInfo, FlashSettings, FlashData, FlashDataBuilder, FlashFrequency, FlashMode, FlashSize and SpiAttachParams` to `flash_data` (#599)
23+
- Moved `ProgressCallbacks` to `progress` (#599)
2224

2325
### Removed
2426

espflash/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ strum = { version = "0.26.1", features = ["derive"] }
5555
thiserror = "1.0.56"
5656
toml = { version = "0.8.10", optional = true }
5757
update-informer = { version = "1.1.0", optional = true }
58-
xmas-elf = { version = "0.9.1", optional = true }
58+
xmas-elf = { version = "0.9.1" }
5959

6060
[target.'cfg(unix)'.dependencies]
6161
libc = "0.2.153"
@@ -87,4 +87,4 @@ cli = [
8787
serialport = ["flashing", "dep:serialport", "dep:slip-codec", "dep:regex"]
8888

8989
# enables flash stubs and stub commands
90-
flashing = ["xmas-elf", "dep:toml"]
90+
flashing = ["dep:toml"]

espflash/src/bin/espflash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use espflash::{
1414
EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs, ReadFlashArgs,
1515
},
1616
error::Error,
17-
flasher::{parse_partition_table, FlashData, FlashSettings},
17+
flash_data::{parse_partition_table, FlashData, FlashSettings},
1818
logging::initialize_logger,
1919
targets::{Chip, XtalFrequency},
2020
update::check_for_update,

espflash/src/cli/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ use crate::{
3030
connection::reset::{ResetAfterOperation, ResetBeforeOperation},
3131
elf::ElfFirmwareImage,
3232
error::{Error, MissingPartition, MissingPartitionTable},
33-
flasher::{
34-
parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize, Flasher,
35-
ProgressCallbacks,
36-
},
33+
flash_data::{parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize},
34+
flasher::Flasher,
35+
progress::ProgressCallbacks,
3736
targets::{Chip, XtalFrequency},
3837
};
3938

espflash/src/command.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::{io::Write, mem::size_of, time::Duration};
55
use bytemuck::{bytes_of, Pod, Zeroable};
66
use strum::Display;
77

8-
use crate::flasher::{checksum, SpiAttachParams, SpiSetParams, CHECKSUM_INIT};
8+
use crate::flash_data::{SpiAttachParams, SpiSetParams, CHECKSUM_INIT};
9+
use crate::flasher::checksum;
910

1011
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(3);
1112
const ERASE_REGION_TIMEOUT_PER_MB: Duration = Duration::from_secs(30);

espflash/src/connection/reset.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
command::{Command, CommandType},
1616
connection::{Connection, Port, USB_SERIAL_JTAG_PID},
1717
error::Error,
18-
flasher,
18+
flash_data::FLASH_WRITE_SIZE,
1919
};
2020

2121
/// Default time to wait before releasing the boot pin after a reset
@@ -253,12 +253,11 @@ pub fn soft_reset(
253253
connection.with_timeout(CommandType::FlashBegin.timeout(), |connection| {
254254
let size: u32 = 0;
255255
let offset: u32 = 0;
256-
let blocks: u32 = (size + flasher::FLASH_WRITE_SIZE as u32 - 1)
257-
/ flasher::FLASH_WRITE_SIZE as u32;
256+
let blocks: u32 = (size + FLASH_WRITE_SIZE as u32 - 1) / FLASH_WRITE_SIZE as u32;
258257
connection.command(Command::FlashBegin {
259258
size,
260259
blocks,
261-
block_size: flasher::FLASH_WRITE_SIZE.try_into().unwrap(),
260+
block_size: FLASH_WRITE_SIZE.try_into().unwrap(),
262261
offset,
263262
supports_encryption: false,
264263
})
@@ -272,12 +271,11 @@ pub fn soft_reset(
272271
connection.with_timeout(CommandType::FlashBegin.timeout(), |connection| {
273272
let size: u32 = 0;
274273
let offset: u32 = 0;
275-
let blocks: u32 =
276-
(size + flasher::FLASH_WRITE_SIZE as u32 - 1) / flasher::FLASH_WRITE_SIZE as u32;
274+
let blocks: u32 = (size + FLASH_WRITE_SIZE as u32 - 1) / FLASH_WRITE_SIZE as u32;
277275
connection.command(Command::FlashBegin {
278276
size,
279277
blocks,
280-
block_size: flasher::FLASH_WRITE_SIZE.try_into().unwrap(),
278+
block_size: FLASH_WRITE_SIZE.try_into().unwrap(),
281279
offset,
282280
supports_encryption: false,
283281
})

espflash/src/error.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//! Library and application errors
22
3-
use std::{
4-
fmt::{Display, Formatter},
5-
io,
6-
};
3+
use std::fmt::{Display, Formatter};
74

85
use miette::Diagnostic;
96
#[cfg(feature = "serialport")]
@@ -13,11 +10,10 @@ use thiserror::Error;
1310

1411
#[cfg(feature = "cli")]
1512
use crate::cli::monitor::parser::esp_defmt::DefmtError;
16-
use crate::{
17-
command::CommandType,
18-
flasher::{FlashFrequency, FlashSize},
19-
targets::Chip,
20-
};
13+
#[cfg(feature = "flashing")]
14+
use crate::command::CommandType;
15+
use crate::flash_data::{FlashFrequency, FlashSize};
16+
use crate::targets::Chip;
2117

2218
/// All possible errors returned by espflash
2319
#[derive(Debug, Diagnostic, Error)]
@@ -188,7 +184,7 @@ pub enum Error {
188184
#[diagnostic(transparent)]
189185
RomError(#[from] RomError),
190186

191-
#[cfg(feature = "serialport")]
187+
#[cfg(feature = "cli")]
192188
#[error(transparent)]
193189
#[diagnostic(transparent)]
194190
Defmt(#[from] DefmtError),
@@ -213,8 +209,8 @@ pub enum Error {
213209
}
214210

215211
#[cfg(feature = "serialport")]
216-
impl From<io::Error> for Error {
217-
fn from(err: io::Error) -> Self {
212+
impl From<std::io::Error> for Error {
213+
fn from(err: std::io::Error) -> Self {
218214
Self::Connection(err.into())
219215
}
220216
}
@@ -282,6 +278,7 @@ pub enum ConnectionError {
282278

283279
#[error("Timeout while running {0}command")]
284280
#[diagnostic(code(espflash::timeout))]
281+
#[cfg(feature = "flashing")]
285282
Timeout(TimedOutCommand),
286283

287284
#[cfg(feature = "serialport")]
@@ -295,8 +292,8 @@ pub enum ConnectionError {
295292
}
296293

297294
#[cfg(feature = "serialport")]
298-
impl From<io::Error> for ConnectionError {
299-
fn from(err: io::Error) -> Self {
295+
impl From<std::io::Error> for ConnectionError {
296+
fn from(err: std::io::Error) -> Self {
300297
from_error_kind(err.kind(), err)
301298
}
302299
}
@@ -329,10 +326,12 @@ impl From<SlipError> for ConnectionError {
329326

330327
/// An executed command which has timed out
331328
#[derive(Clone, Debug, Default)]
329+
#[cfg(feature = "flashing")]
332330
pub struct TimedOutCommand {
333331
command: Option<CommandType>,
334332
}
335333

334+
#[cfg(feature = "flashing")]
336335
impl Display for TimedOutCommand {
337336
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
338337
match &self.command {
@@ -342,6 +341,7 @@ impl Display for TimedOutCommand {
342341
}
343342
}
344343

344+
#[cfg(feature = "flashing")]
345345
impl From<CommandType> for TimedOutCommand {
346346
fn from(ct: CommandType) -> Self {
347347
TimedOutCommand { command: Some(ct) }
@@ -488,13 +488,15 @@ impl From<&'static str> for ElfError {
488488
}
489489
}
490490

491+
#[cfg(feature = "flashing")]
491492
pub(crate) trait ResultExt {
492493
/// Mark an error as having occurred during the flashing stage
493494
fn flashing(self) -> Self;
494495
/// Mark the command from which this error originates
495496
fn for_command(self, command: CommandType) -> Self;
496497
}
497498

499+
#[cfg(feature = "flashing")]
498500
impl<T> ResultExt for Result<T, Error> {
499501
fn flashing(self) -> Self {
500502
match self {
@@ -518,7 +520,7 @@ impl<T> ResultExt for Result<T, Error> {
518520

519521
#[cfg(feature = "serialport")]
520522
#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))]
521-
fn from_error_kind<E>(kind: io::ErrorKind, err: E) -> ConnectionError
523+
fn from_error_kind<E>(kind: std::io::ErrorKind, err: E) -> ConnectionError
522524
where
523525
E: Into<serialport::Error>,
524526
{

0 commit comments

Comments
 (0)