diff --git a/espflash/src/chip/esp32.rs b/espflash/src/chip/esp32.rs index 1ea7f646..46b00b3b 100644 --- a/espflash/src/chip/esp32.rs +++ b/espflash/src/chip/esp32.rs @@ -24,8 +24,14 @@ const DROM_MAP_END: u32 = 0x3F800000; const BOOT_ADDR: u32 = 0x1000; const PARTION_ADDR: u32 = 0x8000; +const NVS_ADDR: u32 = 0x9000; +const PHY_INIT_DATA_ADDR: u32 = 0xf000; const APP_ADDR: u32 = 0x10000; +const NVS_SIZE: u32 = 0x6000; +const PHY_INIT_DATA_SIZE: u32 = 0x1000; +const APP_SIZE: u32 = 0x3f0000; + impl ChipType for Esp32 { const CHIP_DETECT_MAGIC_VALUE: u32 = 0x00f01d83; @@ -49,7 +55,15 @@ impl ChipType for Esp32 { ) -> Box, Error>> + 'a> { let bootloader = include_bytes!("../../bootloader/esp32-bootloader.bin"); - let partition_table = PartitionTable::basic(0x10000, 0x3f0000).to_bytes(); + let partition_table = PartitionTable::basic( + NVS_ADDR, + NVS_SIZE, + PHY_INIT_DATA_ADDR, + PHY_INIT_DATA_SIZE, + APP_ADDR, + APP_SIZE, + ) + .to_bytes(); fn get_data<'a>(image: &'a FirmwareImage) -> Result, Error> { let mut data = Vec::new(); diff --git a/espflash/src/chip/esp32c3.rs b/espflash/src/chip/esp32c3.rs index e170e291..f261f305 100644 --- a/espflash/src/chip/esp32c3.rs +++ b/espflash/src/chip/esp32c3.rs @@ -24,8 +24,14 @@ const DROM_MAP_END: u32 = 0x3c800000; const BOOT_ADDR: u32 = 0x0; const PARTITION_ADDR: u32 = 0x8000; +const NVS_ADDR: u32 = 0x9000; +const PHY_INIT_DATA_ADDR: u32 = 0xf000; const APP_ADDR: u32 = 0x10000; +const NVS_SIZE: u32 = 0x6000; +const PHY_INIT_DATA_SIZE: u32 = 0x1000; +const APP_SIZE: u32 = 0x3f0000; + impl ChipType for Esp32c3 { const CHIP_DETECT_MAGIC_VALUE: u32 = 0x6921506f; const CHIP_DETECT_MAGIC_VALUE2: u32 = 0x1b31506f; @@ -50,7 +56,15 @@ impl ChipType for Esp32c3 { ) -> Box, Error>> + 'a> { let bootloader = include_bytes!("../../bootloader/esp32c3-bootloader.bin"); - let partition_table = PartitionTable::basic(0x10000, 0x3f0000).to_bytes(); + let partition_table = PartitionTable::basic( + NVS_ADDR, + NVS_SIZE, + PHY_INIT_DATA_ADDR, + PHY_INIT_DATA_SIZE, + APP_ADDR, + APP_SIZE, + ) + .to_bytes(); fn get_data<'a>(image: &'a FirmwareImage) -> Result, Error> { let mut data = Vec::new(); diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index c80e0241..71ee882d 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -72,17 +72,39 @@ pub struct PartitionTable { } impl PartitionTable { - /// Create a basic partition table with a single app entry - pub fn basic(app_offset: u32, app_size: u32) -> Self { + /// Create a basic partition table with NVS, PHY init data, and the app partition + pub fn basic( + nvs_offset: u32, + nvs_size: u32, + phy_init_data_offset: u32, + phy_init_data_size: u32, + app_offset: u32, + app_size: u32, + ) -> Self { PartitionTable { - partitions: vec![Partition::new( - String::from("factory"), - Type::App, - SubType::App(AppType::Factory), - app_offset, - app_size, - 0, - )], + partitions: vec![ + Partition::new( + String::from("nvs"), + SubType::Data(DataType::Nvs), + nvs_offset, + nvs_size, + 0, + ), + Partition::new( + String::from("phy_init"), + SubType::Data(DataType::Phy), + phy_init_data_offset, + phy_init_data_size, + 0, + ), + Partition::new( + String::from("factory"), + SubType::App(AppType::Factory), + app_offset, + app_size, + 0, + ), + ], } } @@ -127,17 +149,13 @@ struct Partition { } impl Partition { - pub fn new( - name: String, - ty: Type, - sub_type: SubType, - offset: u32, - size: u32, - flags: u32, - ) -> Self { + pub fn new(name: String, sub_type: SubType, offset: u32, size: u32, flags: u32) -> Self { Partition { name, - ty, + ty: match sub_type { + SubType::App(_) => Type::App, + SubType::Data(_) => Type::Data, + }, sub_type, offset, size, @@ -194,9 +212,23 @@ impl HashWriter { #[test] fn test_basic() { use std::fs::read; + const NVS_ADDR: u32 = 0x9000; + const PHY_INIT_DATA_ADDR: u32 = 0xf000; + const APP_ADDR: u32 = 0x10000; + + const NVS_SIZE: u32 = 0x6000; + const PHY_INIT_DATA_SIZE: u32 = 0x1000; + const APP_SIZE: u32 = 0x3f0000; let expected = read("./tests/data/partitions.bin").unwrap(); - let table = PartitionTable::basic(0x10000, 0x3f0000); + let table = PartitionTable::basic( + NVS_ADDR, + NVS_SIZE, + PHY_INIT_DATA_ADDR, + PHY_INIT_DATA_SIZE, + APP_ADDR, + APP_SIZE, + ); let result = table.to_bytes(); diff --git a/espflash/tests/data/partitions.bin b/espflash/tests/data/partitions.bin index e65b24a7..4b003b95 100644 Binary files a/espflash/tests/data/partitions.bin and b/espflash/tests/data/partitions.bin differ diff --git a/espflash/tests/data/partitions.csv b/espflash/tests/data/partitions.csv new file mode 100644 index 00000000..b0b425b9 --- /dev/null +++ b/espflash/tests/data/partitions.csv @@ -0,0 +1,5 @@ +# ESP-IDF Partition Table +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x6000, +phy_init, data, phy, 0xf000, 0x1000, +factory, app, factory, 0x10000, 0x3f0000,