Skip to content

Commit 3a3f7a3

Browse files
tpamborjessebraham
authored andcommitted
Remove dependency to FirmwareImage from flash_targets
1 parent 2d5b08c commit 3a3f7a3

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

espflash/src/chip/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ impl Chip {
254254
}
255255
}
256256

257-
pub fn ram_target(&self) -> Box<dyn FlashTarget> {
258-
Box::new(RamTarget::new())
257+
pub fn ram_target(&self, entry: Option<u32>) -> Box<dyn FlashTarget> {
258+
Box::new(RamTarget::new(entry))
259259
}
260260

261261
pub fn flash_target(&self, spi_params: SpiAttachParams) -> Box<dyn FlashTarget> {

espflash/src/flash_target/esp32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::command::{Command, CommandType};
22
use crate::connection::{Connection, USB_SERIAL_JTAG_PID};
3-
use crate::elf::{FirmwareImage, RomSegment};
3+
use crate::elf::RomSegment;
44
use crate::error::Error;
55
use crate::flash_target::FlashTarget;
66
use crate::flasher::{SpiAttachParams, FLASH_SECTOR_SIZE, FLASH_WRITE_SIZE};
@@ -25,7 +25,7 @@ impl Esp32Target {
2525
}
2626

2727
impl FlashTarget for Esp32Target {
28-
fn begin(&mut self, connection: &mut Connection, _image: &FirmwareImage) -> Result<(), Error> {
28+
fn begin(&mut self, connection: &mut Connection) -> Result<(), Error> {
2929
connection.with_timeout(CommandType::SpiAttach.timeout(), |connection| {
3030
connection.command(Command::SpiAttach {
3131
spi_params: self.spi_attach_params,

espflash/src/flash_target/esp8266.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::command::{Command, CommandType};
22
use crate::connection::Connection;
3-
use crate::elf::{FirmwareImage, RomSegment};
3+
use crate::elf::RomSegment;
44
use crate::error::Error;
55
use crate::flash_target::FlashTarget;
66
use crate::flasher::{get_erase_size, FLASH_WRITE_SIZE};
@@ -21,7 +21,7 @@ impl Default for Esp8266Target {
2121
}
2222

2323
impl FlashTarget for Esp8266Target {
24-
fn begin(&mut self, connection: &mut Connection, _image: &FirmwareImage) -> Result<(), Error> {
24+
fn begin(&mut self, connection: &mut Connection) -> Result<(), Error> {
2525
connection.command(Command::FlashBegin {
2626
size: 0,
2727
blocks: 0,

espflash/src/flash_target/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod esp8266;
33
mod ram;
44

55
use crate::connection::Connection;
6-
use crate::elf::{FirmwareImage, RomSegment};
6+
use crate::elf::RomSegment;
77
use crate::error::Error;
88

99
use bytemuck::{Pod, Zeroable};
@@ -12,7 +12,7 @@ pub use esp8266::Esp8266Target;
1212
pub use ram::RamTarget;
1313

1414
pub trait FlashTarget {
15-
fn begin(&mut self, connection: &mut Connection, image: &FirmwareImage) -> Result<(), Error>;
15+
fn begin(&mut self, connection: &mut Connection) -> Result<(), Error>;
1616
fn write_segment(
1717
&mut self,
1818
connection: &mut Connection,

espflash/src/flash_target/ram.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::command::{Command, CommandType};
22
use crate::connection::Connection;
3-
use crate::elf::{FirmwareImage, RomSegment};
3+
use crate::elf::RomSegment;
44
use crate::error::Error;
55
use crate::flash_target::FlashTarget;
66
use bytemuck::{Pod, Zeroable};
@@ -17,20 +17,19 @@ pub struct RamTarget {
1717
}
1818

1919
impl RamTarget {
20-
pub fn new() -> Self {
21-
RamTarget { entry: None }
20+
pub fn new(entry: Option<u32>) -> Self {
21+
RamTarget { entry }
2222
}
2323
}
2424

2525
impl Default for RamTarget {
2626
fn default() -> Self {
27-
Self::new()
27+
Self::new(None)
2828
}
2929
}
3030

3131
impl FlashTarget for RamTarget {
32-
fn begin(&mut self, _connection: &mut Connection, image: &FirmwareImage) -> Result<(), Error> {
33-
self.entry = Some(image.entry());
32+
fn begin(&mut self, _connection: &mut Connection) -> Result<(), Error> {
3433
Ok(())
3534
}
3635

espflash/src/flasher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ impl Flasher {
420420
pub fn load_elf_to_ram(&mut self, elf_data: &[u8]) -> Result<(), Error> {
421421
let image = FirmwareImageBuilder::new(elf_data).build()?;
422422

423-
let mut target = self.chip.ram_target();
424-
target.begin(&mut self.connection, &image).flashing()?;
423+
let mut target = self.chip.ram_target(Some(image.entry()));
424+
target.begin(&mut self.connection).flashing()?;
425425

426426
if image.rom_segments(self.chip).next().is_some() {
427427
return Err(Error::ElfNotRamLoadable);
@@ -465,7 +465,7 @@ impl Flasher {
465465
let image = builder.build()?;
466466

467467
let mut target = self.chip.flash_target(self.spi_params);
468-
target.begin(&mut self.connection, &image).flashing()?;
468+
target.begin(&mut self.connection).flashing()?;
469469

470470
let flash_image = self.chip.get_flash_image(
471471
&image,

0 commit comments

Comments
 (0)