Skip to content

Commit

Permalink
Move things back
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Feb 24, 2024
1 parent cbdb3a8 commit 226af9b
Show file tree
Hide file tree
Showing 24 changed files with 587 additions and 575 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Non-linux-musl: Only list the available USB Ports by default (#590)
- `FlashData::new` now returns `crate::Error` (#591)
- Moved `reset_after_flash` method to `reset` module (#594)
- Moved `parse_partition_table, DeviceInfo, FlashSettings, FlashData, FlashDataBuilder, FlashFrequency, FlashMode, FlashSize, SpiSetParams and SpiAttachParams` to `flash_data` (#599)
- `flasher::{parse_partition_table, DeviceInfo, FlashSettings, FlashData, FlashDataBuilder, FlashFrequency, FlashMode, FlashSize, SpiSetParams, SpiAttachParams and ProgressCallbacks}` are now available without `serialport`. I think. (#599)
- Moved `ProgressCallbacks` to `progress` (#599)

### Removed
Expand Down
6 changes: 3 additions & 3 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use espflash::{
EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs, ReadFlashArgs,
},
error::Error,
flash_data::{parse_partition_table, FlashData, FlashSettings},
flasher::{parse_partition_table, FlashData, FlashSettings},
logging::initialize_logger,
targets::{Chip, XtalFrequency},
update::check_for_update,
Expand Down Expand Up @@ -335,7 +335,7 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
args.flash_config_args.flash_freq,
);

let flash_data = FlashData::new(
let flasher = FlashData::new(
bootloader,
partition_table,
args.save_image_args.partition_table_offset,
Expand All @@ -353,7 +353,7 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
&elf_data,
args.save_image_args.chip,
args.save_image_args.file,
flash_data,
flasher,
args.save_image_args.merge,
args.save_image_args.skip_padding,
xtal_freq,
Expand Down
19 changes: 8 additions & 11 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ use crate::{
connection::reset::{ResetAfterOperation, ResetBeforeOperation},
elf::ElfFirmwareImage,
error::{Error, MissingPartition, MissingPartitionTable},
flash_data::{parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize},
flasher::Flasher,
progress::ProgressCallbacks,
targets::{Chip, XtalFrequency},
flasher::{parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize, Flasher},
targets::{Chip, ProgressCallbacks, XtalFrequency},
};

pub mod config;
Expand Down Expand Up @@ -453,7 +451,7 @@ pub fn save_elf_as_image(
elf_data: &[u8],
chip: Chip,
image_path: PathBuf,
flash_data: FlashData,
flasher: FlashData,
merge: bool,
skip_padding: bool,
xtal_freq: XtalFrequency,
Expand All @@ -463,9 +461,9 @@ pub fn save_elf_as_image(
if merge {
// To get a chip revision, the connection is needed
// For simplicity, the revision None is used
let image =
chip.into_target()
.get_flash_image(&image, flash_data.clone(), None, xtal_freq)?;
let image = chip
.into_target()
.get_flash_image(&image, flasher.clone(), None, xtal_freq)?;

display_image_size(image.app_size(), image.part_size());

Expand All @@ -490,16 +488,15 @@ pub fn save_elf_as_image(
// Take flash_size as input parameter, if None, use default value of 4Mb
let padding_bytes = vec![
0xffu8;
flash_data.flash_settings.size.unwrap_or_default().size()
as usize
flasher.flash_settings.size.unwrap_or_default().size() as usize
- file.metadata().into_diagnostic()?.len() as usize
];
file.write_all(&padding_bytes).into_diagnostic()?;
}
} else {
let image = chip
.into_target()
.get_flash_image(&image, flash_data, None, xtal_freq)?;
.get_flash_image(&image, flasher, None, xtal_freq)?;

display_image_size(image.app_size(), image.part_size());

Expand Down
13 changes: 11 additions & 2 deletions espflash/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::{io::Write, mem::size_of, time::Duration};
use bytemuck::{bytes_of, Pod, Zeroable};
use strum::Display;

use crate::flash_data::{SpiAttachParams, SpiSetParams, CHECKSUM_INIT};
use crate::flasher::checksum;
use crate::flasher::{SpiAttachParams, SpiSetParams};

const DEFAULT_TIMEOUT: Duration = Duration::from_secs(3);
const ERASE_REGION_TIMEOUT_PER_MB: Duration = Duration::from_secs(30);
Expand Down Expand Up @@ -514,3 +513,13 @@ fn data_command<W: Write>(
}
Ok(())
}

const CHECKSUM_INIT: u8 = 0xEF;

fn checksum(data: &[u8], mut checksum: u8) -> u8 {
for byte in data {
checksum ^= *byte;
}

checksum
}
2 changes: 1 addition & 1 deletion espflash/src/connection/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
command::{Command, CommandType},
connection::{Connection, Port, USB_SERIAL_JTAG_PID},
error::Error,
flash_data::FLASH_WRITE_SIZE,
flasher::stubs::FLASH_WRITE_SIZE,
};

/// Default time to wait before releasing the boot pin after a reset
Expand Down
3 changes: 2 additions & 1 deletion espflash/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Library and application errors

#[cfg(feature = "serialport")]
use std::fmt::{Display, Formatter};

use miette::Diagnostic;
Expand All @@ -12,7 +13,7 @@ use thiserror::Error;
use crate::cli::monitor::parser::esp_defmt::DefmtError;
#[cfg(feature = "serialport")]
use crate::command::CommandType;
use crate::flash_data::{FlashFrequency, FlashSize};
use crate::flasher::{FlashFrequency, FlashSize};
use crate::targets::Chip;

/// All possible errors returned by espflash
Expand Down
Loading

0 comments on commit 226af9b

Please sign in to comment.