From 13dfa1cf20b281d71da4d8dbde8f6b98d9b5d822 Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Fri, 3 Sep 2021 15:32:07 -0700 Subject: [PATCH 1/4] Simplify Partition constructor The partition type can be inferred from the SubType enum, so no need to pass both. --- espflash/src/partition_table.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index c80e0241..3bfb0624 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -77,7 +77,6 @@ impl PartitionTable { PartitionTable { partitions: vec![Partition::new( String::from("factory"), - Type::App, SubType::App(AppType::Factory), app_offset, app_size, @@ -127,17 +126,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, From bfba9a0b773512c7c64831f169760c19a89aa38c Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Fri, 3 Sep 2021 13:57:49 -0700 Subject: [PATCH 2/4] Also write nvs and phy_init partitions for the basic part table --- espflash/src/chip/esp32.rs | 15 +++++++++++- espflash/src/chip/esp32c3.rs | 16 ++++++++++++- espflash/src/partition_table.rs | 41 +++++++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/espflash/src/chip/esp32.rs b/espflash/src/chip/esp32.rs index 1ea7f646..922f73b8 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,14 @@ 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, + ); 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 3bfb0624..0684c921 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -72,16 +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"), - 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, + ), + ], } } From 965df748a0cfc3eeb43d646d09268f6732910fe5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 4 Sep 2021 14:49:45 +0200 Subject: [PATCH 3/4] fix esp32 --- espflash/src/chip/esp32.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/espflash/src/chip/esp32.rs b/espflash/src/chip/esp32.rs index 922f73b8..46b00b3b 100644 --- a/espflash/src/chip/esp32.rs +++ b/espflash/src/chip/esp32.rs @@ -62,7 +62,8 @@ impl ChipType for Esp32 { PHY_INIT_DATA_SIZE, APP_ADDR, APP_SIZE, - ); + ) + .to_bytes(); fn get_data<'a>(image: &'a FirmwareImage) -> Result, Error> { let mut data = Vec::new(); From 2941b243ccf907e0acc036eda1d781271961992e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 4 Sep 2021 14:59:48 +0200 Subject: [PATCH 4/4] update partition table tests --- espflash/src/partition_table.rs | 16 +++++++++++++++- espflash/tests/data/partitions.bin | Bin 3072 -> 3072 bytes espflash/tests/data/partitions.csv | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 espflash/tests/data/partitions.csv diff --git a/espflash/src/partition_table.rs b/espflash/src/partition_table.rs index 0684c921..71ee882d 100644 --- a/espflash/src/partition_table.rs +++ b/espflash/src/partition_table.rs @@ -212,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 e65b24a785dd88eb9b84bf7f46dcaf609c0b83d6..4b003b95ac9d1c757c75f75d521023ecb8591af9 100644 GIT binary patch delta 92 zcmZpWXpnGN6~M^EFoA)AA%TG*udEozKm|Z~MurbSF#!gKf{e=e%)HDJWEB$(1j7FQ WdaO_s*jRdXYVe;{InRxb4cq|zyA==s delta 31 ncmZpWXporbU?6bTzAogy!U3Na;a$i5lJg&KY^>*=IKdGB$~_H& 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,