Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion espflash/src/chip/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -49,7 +55,15 @@ impl ChipType for Esp32 {
) -> Box<dyn Iterator<Item = Result<RomSegment<'a>, 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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, that was dumb. Thanks for fixing that up.


fn get_data<'a>(image: &'a FirmwareImage) -> Result<RomSegment<'a>, Error> {
let mut data = Vec::new();
Expand Down
16 changes: 15 additions & 1 deletion espflash/src/chip/esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,7 +56,15 @@ impl ChipType for Esp32c3 {
) -> Box<dyn Iterator<Item = Result<RomSegment<'a>, 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<RomSegment<'a>, Error> {
let mut data = Vec::new();
Expand Down
72 changes: 52 additions & 20 deletions espflash/src/partition_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
],
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -194,9 +212,23 @@ impl<W: Write> HashWriter<W> {
#[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();

Expand Down
Binary file modified espflash/tests/data/partitions.bin
Binary file not shown.
5 changes: 5 additions & 0 deletions espflash/tests/data/partitions.csv
Original file line number Diff line number Diff line change
@@ -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,