File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use crate::flasher::FlashSize;
77use std:: fmt:: { Debug , Formatter } ;
88use std:: mem:: take;
99use std:: ops:: AddAssign ;
10+ use xmas_elf:: program:: Type ;
1011use xmas_elf:: sections:: { SectionData , ShType } ;
1112use xmas_elf:: ElfFile ;
1213
@@ -78,6 +79,21 @@ impl<'a> FirmwareImage<'a> {
7879 } )
7980 }
8081
82+ pub fn segments_with_load_addresses ( & ' a self ) -> impl Iterator < Item = CodeSegment < ' a > > + ' a {
83+ self . elf
84+ . program_iter ( )
85+ . filter ( |header| {
86+ header. file_size ( ) > 0 && header. get_type ( ) == Ok ( Type :: Load ) && header. offset ( ) > 0
87+ } )
88+ . flat_map ( move |header| {
89+ let addr = header. physical_addr ( ) as u32 ;
90+ let from = header. offset ( ) as usize ;
91+ let to = header. offset ( ) as usize + header. file_size ( ) as usize ;
92+ let data = & self . elf . input [ from..to] ;
93+ Some ( CodeSegment :: new ( addr, data) )
94+ } )
95+ }
96+
8197 pub fn rom_segments ( & ' a self , chip : Chip ) -> impl Iterator < Item = CodeSegment < ' a > > + ' a {
8298 self . segments ( )
8399 . filter ( move |segment| chip. addr_is_flash ( segment. addr ) )
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ pub struct Esp32DirectBootFormat<'a> {
1414impl < ' a > Esp32DirectBootFormat < ' a > {
1515 pub fn new ( image : & ' a FirmwareImage ) -> Result < Self , Error > {
1616 let mut segment = image
17- . segments ( )
17+ . segments_with_load_addresses ( )
1818 . map ( |mut segment| {
1919 // map address to the first 4MB
2020 segment. addr %= 0x400000 ;
You can’t perform that action at this time.
0 commit comments