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;
7
7
use std:: fmt:: { Debug , Formatter } ;
8
8
use std:: mem:: take;
9
9
use std:: ops:: AddAssign ;
10
+ use xmas_elf:: program:: Type ;
10
11
use xmas_elf:: sections:: { SectionData , ShType } ;
11
12
use xmas_elf:: ElfFile ;
12
13
@@ -78,6 +79,21 @@ impl<'a> FirmwareImage<'a> {
78
79
} )
79
80
}
80
81
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
+
81
97
pub fn rom_segments ( & ' a self , chip : Chip ) -> impl Iterator < Item = CodeSegment < ' a > > + ' a {
82
98
self . segments ( )
83
99
. 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> {
14
14
impl < ' a > Esp32DirectBootFormat < ' a > {
15
15
pub fn new ( image : & ' a FirmwareImage ) -> Result < Self , Error > {
16
16
let mut segment = image
17
- . segments ( )
17
+ . segments_with_load_addresses ( )
18
18
. map ( |mut segment| {
19
19
// map address to the first 4MB
20
20
segment. addr %= 0x400000 ;
You can’t perform that action at this time.
0 commit comments