File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -26,14 +26,16 @@ pub struct Esp32Params {
26
26
}
27
27
28
28
impl Esp32Params {
29
- pub fn default_partition_table ( & self ) -> PartitionTable {
29
+ /// Generates a default partition table.
30
+ /// `flash_size` is used to scale app partition when present, otherwise the param defaults are used.
31
+ pub fn default_partition_table ( & self , flash_size : Option < u32 > ) -> PartitionTable {
30
32
PartitionTable :: basic (
31
33
self . nvs_addr ,
32
34
self . nvs_size ,
33
35
self . phy_init_data_addr ,
34
36
self . phy_init_data_size ,
35
37
self . app_addr ,
36
- self . app_size ,
38
+ flash_size . map_or ( self . app_size , |size| size - self . app_addr ) ,
37
39
)
38
40
}
39
41
}
Original file line number Diff line number Diff line change @@ -65,6 +65,22 @@ impl FlashSize {
65
65
_ => Err ( Error :: UnsupportedFlash ( FlashDetectError :: from ( value) ) ) ,
66
66
}
67
67
}
68
+
69
+ /// Returns the flash size in bytes
70
+ pub fn size ( self ) -> u32 {
71
+ match self {
72
+ FlashSize :: Flash256Kb => 0x0040000 ,
73
+ FlashSize :: Flash512Kb => 0x0080000 ,
74
+ FlashSize :: Flash1Mb => 0x0100000 ,
75
+ FlashSize :: Flash2Mb => 0x0200000 ,
76
+ FlashSize :: Flash4Mb => 0x0400000 ,
77
+ FlashSize :: Flash8Mb => 0x0800000 ,
78
+ FlashSize :: Flash16Mb => 0x1000000 ,
79
+ FlashSize :: Flash32Mb => 0x2000000 ,
80
+ FlashSize :: Flash64Mb => 0x4000000 ,
81
+ FlashSize :: Flash128Mb => 0x8000000 ,
82
+ }
83
+ }
68
84
}
69
85
70
86
impl FromStr for FlashSize {
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ impl<'a> Esp32BootloaderFormat<'a> {
32
32
partition_table : Option < PartitionTable > ,
33
33
bootloader : Option < Vec < u8 > > ,
34
34
) -> Result < Self , Error > {
35
- let partition_table = partition_table. unwrap_or_else ( || params. default_partition_table ( ) ) ;
35
+ let partition_table = partition_table
36
+ . unwrap_or_else ( || params. default_partition_table ( image. flash_size . map ( |v| v. size ( ) ) ) ) ;
36
37
let mut bootloader = if let Some ( bytes) = bootloader {
37
38
Cow :: Owned ( bytes)
38
39
} else {
You can’t perform that action at this time.
0 commit comments