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 {
2626}
2727
2828impl 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 {
3032 PartitionTable :: basic (
3133 self . nvs_addr ,
3234 self . nvs_size ,
3335 self . phy_init_data_addr ,
3436 self . phy_init_data_size ,
3537 self . app_addr ,
36- self . app_size ,
38+ flash_size . map_or ( self . app_size , |size| size - self . app_addr ) ,
3739 )
3840 }
3941}
Original file line number Diff line number Diff line change @@ -65,6 +65,22 @@ impl FlashSize {
6565 _ => Err ( Error :: UnsupportedFlash ( FlashDetectError :: from ( value) ) ) ,
6666 }
6767 }
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+ }
6884}
6985
7086impl FromStr for FlashSize {
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ impl<'a> Esp32BootloaderFormat<'a> {
3232 partition_table : Option < PartitionTable > ,
3333 bootloader : Option < Vec < u8 > > ,
3434 ) -> 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 ( ) ) ) ) ;
3637 let mut bootloader = if let Some ( bytes) = bootloader {
3738 Cow :: Owned ( bytes)
3839 } else {
You can’t perform that action at this time.
0 commit comments