Skip to content

Commit 188cd4e

Browse files
authored
Make eFuse field definitions public, minor public API cleanup (#903)
* Make efuse field definitions public * Remove unnecessary argument and simplify return type for `flash_write_size` and `max_ram_block_size` functions * Update `CHANGELOG.md` * Make eFuse field definitions public
1 parent f31f75e commit 188cd4e

File tree

18 files changed

+1049
-1028
lines changed

18 files changed

+1049
-1028
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- `Connection::into_serial` to get the underlying port from the connection (#882)
3333
- All methods on the now removed `Target` & `ReadEFuse`, `UsbOtg` and `RtcWdtReset` traits have been implemented directly on (#891)
3434
- Update checks can now be skipped by setting the the `ESPFLASH_SKIP_UPDATE_CHECK` environment variable (#900)
35+
- `flash_write_size` and `max_ram_block_size` functions no longer take a connection parameter and return a Result type (#903)
3536

3637
### Changed
3738

@@ -48,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4849
- Removed `get_` prefix from any functions which previously had it (#824)
4950
- Take elf data as bytes rather than `ElfFile` struct when creating an image format (#825)
5051
- Updated to Rust 2024 edition (#843)
51-
- Complete rework of reading eFuse field values (#847)
52+
- Complete rework of reading eFuse field values (#847, #903)
5253
- Updated bootloaders with `release/v5.4` ones from IDF (#857)
5354
- Refactor image formatting to allow supporting more image formats in a backward compatible way (#877)
5455
- Avoid having ESP-IDF format assumptions in the codebase (#877)

espflash/src/flasher/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use object::{Endianness, read::elf::ElfFile32 as ElfFile};
1919
use serde::{Deserialize, Serialize};
2020
use strum::{Display, EnumIter, IntoEnumIterator, VariantNames};
2121

22-
#[cfg(feature = "serialport")]
23-
pub(crate) use self::stubs::{FLASH_SECTOR_SIZE, FLASH_WRITE_SIZE};
2422
use crate::{
2523
Error,
2624
target::{Chip, XtalFrequency},
@@ -47,6 +45,10 @@ pub(crate) mod stubs;
4745
pub(crate) const TRY_SPI_PARAMS: [SpiAttachParams; 2] =
4846
[SpiAttachParams::default(), SpiAttachParams::esp32_pico_d4()];
4947

48+
#[cfg(feature = "serialport")]
49+
pub(crate) const FLASH_SECTOR_SIZE: usize = 0x1000;
50+
pub(crate) const FLASH_WRITE_SIZE: usize = 0x400;
51+
5052
/// Progress update callbacks
5153
pub trait ProgressCallbacks {
5254
/// Initialize some progress report
@@ -745,10 +747,9 @@ impl Flasher {
745747
// Load flash stub
746748
let stub = FlashStub::get(self.chip);
747749

748-
let mut ram_target = self.chip.ram_target(
749-
Some(stub.entry()),
750-
self.chip.max_ram_block_size(&mut self.connection)?,
751-
);
750+
let mut ram_target = self
751+
.chip
752+
.ram_target(Some(stub.entry()), self.chip.max_ram_block_size());
752753
ram_target.begin(&mut self.connection).flashing()?;
753754

754755
let (text_addr, text) = stub.text();
@@ -1021,7 +1022,7 @@ impl Flasher {
10211022

10221023
let mut target = self.chip.ram_target(
10231024
Some(elf.elf_header().e_entry.get(Endianness::Little)),
1024-
self.chip.max_ram_block_size(&mut self.connection)?,
1025+
self.chip.max_ram_block_size(),
10251026
);
10261027
target.begin(&mut self.connection).flashing()?;
10271028

espflash/src/flasher/stubs.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ pub(crate) const CHIP_DETECT_MAGIC_REG_ADDR: u32 = 0x40001000;
2525
pub(crate) const DEFAULT_TIMEOUT: Duration = Duration::from_secs(3);
2626
pub(crate) const EXPECTED_STUB_HANDSHAKE: &str = "OHAI";
2727

28-
pub(crate) const FLASH_SECTOR_SIZE: usize = 0x1000;
29-
pub(crate) const FLASH_WRITE_SIZE: usize = 0x400;
30-
3128
// Include stub objects in binary
3229
const STUB_32: &str = include_str!("../../resources/stubs/esp32.toml");
3330
const STUB_32C2: &str = include_str!("../../resources/stubs/esp32c2.toml");

espflash/src/target/efuse/esp32.rs

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
//! eFuse field definitions for the esp32
2+
//!
13
//! This file was automatically generated, please do not edit it manually!
24
//!
3-
//! Generated: 2025-05-30 12:24
5+
//! Generated: 2025-06-25 11:06
46
//! Version: 369d2d860d34e777c0f7d545a7dfc3c4
57
68
#![allow(unused)]
@@ -11,135 +13,135 @@ use super::EfuseField;
1113
pub(crate) const BLOCK_SIZES: &[u32] = &[28, 32, 32, 32];
1214

1315
/// Efuse write disable mask
14-
pub(crate) const WR_DIS: EfuseField = EfuseField::new(0, 0, 0, 16);
16+
pub const WR_DIS: EfuseField = EfuseField::new(0, 0, 0, 16);
1517
/// Disable reading from BlOCK1-3
16-
pub(crate) const RD_DIS: EfuseField = EfuseField::new(0, 0, 16, 4);
18+
pub const RD_DIS: EfuseField = EfuseField::new(0, 0, 16, 4);
1719
/// Flash encryption is enabled if this field has an odd number of bits set
18-
pub(crate) const FLASH_CRYPT_CNT: EfuseField = EfuseField::new(0, 0, 20, 7);
20+
pub const FLASH_CRYPT_CNT: EfuseField = EfuseField::new(0, 0, 20, 7);
1921
/// Disable UART download mode. Valid for ESP32 V3 and newer; only
20-
pub(crate) const UART_DOWNLOAD_DIS: EfuseField = EfuseField::new(0, 0, 27, 1);
22+
pub const UART_DOWNLOAD_DIS: EfuseField = EfuseField::new(0, 0, 27, 1);
2123
/// reserved
22-
pub(crate) const RESERVED_0_28: EfuseField = EfuseField::new(0, 0, 28, 4);
24+
pub const RESERVED_0_28: EfuseField = EfuseField::new(0, 0, 28, 4);
2325
/// MAC address
24-
pub(crate) const MAC0: EfuseField = EfuseField::new(0, 1, 32, 32);
26+
pub const MAC0: EfuseField = EfuseField::new(0, 1, 32, 32);
2527
/// MAC address
26-
pub(crate) const MAC1: EfuseField = EfuseField::new(0, 2, 64, 16);
28+
pub const MAC1: EfuseField = EfuseField::new(0, 2, 64, 16);
2729
/// CRC8 for MAC address
28-
pub(crate) const MAC_CRC: EfuseField = EfuseField::new(0, 2, 80, 8);
30+
pub const MAC_CRC: EfuseField = EfuseField::new(0, 2, 80, 8);
2931
/// Reserved; it was created by set_missed_fields_in_regs func
30-
pub(crate) const RESERVE_0_88: EfuseField = EfuseField::new(0, 2, 88, 8);
32+
pub const RESERVE_0_88: EfuseField = EfuseField::new(0, 2, 88, 8);
3133
/// Disables APP CPU
32-
pub(crate) const DISABLE_APP_CPU: EfuseField = EfuseField::new(0, 3, 96, 1);
34+
pub const DISABLE_APP_CPU: EfuseField = EfuseField::new(0, 3, 96, 1);
3335
/// Disables Bluetooth
34-
pub(crate) const DISABLE_BT: EfuseField = EfuseField::new(0, 3, 97, 1);
36+
pub const DISABLE_BT: EfuseField = EfuseField::new(0, 3, 97, 1);
3537
/// Chip package identifier #4bit
36-
pub(crate) const CHIP_PACKAGE_4BIT: EfuseField = EfuseField::new(0, 3, 98, 1);
38+
pub const CHIP_PACKAGE_4BIT: EfuseField = EfuseField::new(0, 3, 98, 1);
3739
/// Disables cache
38-
pub(crate) const DIS_CACHE: EfuseField = EfuseField::new(0, 3, 99, 1);
40+
pub const DIS_CACHE: EfuseField = EfuseField::new(0, 3, 99, 1);
3941
/// read for SPI_pad_config_hd
40-
pub(crate) const SPI_PAD_CONFIG_HD: EfuseField = EfuseField::new(0, 3, 100, 5);
42+
pub const SPI_PAD_CONFIG_HD: EfuseField = EfuseField::new(0, 3, 100, 5);
4143
/// Chip package identifier
42-
pub(crate) const CHIP_PACKAGE: EfuseField = EfuseField::new(0, 3, 105, 3);
44+
pub const CHIP_PACKAGE: EfuseField = EfuseField::new(0, 3, 105, 3);
4345
/// If set alongside EFUSE_RD_CHIP_CPU_FREQ_RATED; the ESP32's max CPU frequency
4446
/// is rated for 160MHz. 240MHz otherwise
45-
pub(crate) const CHIP_CPU_FREQ_LOW: EfuseField = EfuseField::new(0, 3, 108, 1);
47+
pub const CHIP_CPU_FREQ_LOW: EfuseField = EfuseField::new(0, 3, 108, 1);
4648
/// If set; the ESP32's maximum CPU frequency has been rated
47-
pub(crate) const CHIP_CPU_FREQ_RATED: EfuseField = EfuseField::new(0, 3, 109, 1);
49+
pub const CHIP_CPU_FREQ_RATED: EfuseField = EfuseField::new(0, 3, 109, 1);
4850
/// BLOCK3 partially served for ADC calibration data
49-
pub(crate) const BLK3_PART_RESERVE: EfuseField = EfuseField::new(0, 3, 110, 1);
51+
pub const BLK3_PART_RESERVE: EfuseField = EfuseField::new(0, 3, 110, 1);
5052
/// bit is set to 1 for rev1 silicon
51-
pub(crate) const CHIP_VER_REV1: EfuseField = EfuseField::new(0, 3, 111, 1);
53+
pub const CHIP_VER_REV1: EfuseField = EfuseField::new(0, 3, 111, 1);
5254
/// Reserved; it was created by set_missed_fields_in_regs func
53-
pub(crate) const RESERVE_0_112: EfuseField = EfuseField::new(0, 3, 112, 16);
55+
pub const RESERVE_0_112: EfuseField = EfuseField::new(0, 3, 112, 16);
5456
/// 8MHz clock freq override
55-
pub(crate) const CLK8M_FREQ: EfuseField = EfuseField::new(0, 4, 128, 8);
57+
pub const CLK8M_FREQ: EfuseField = EfuseField::new(0, 4, 128, 8);
5658
/// True ADC reference voltage
57-
pub(crate) const ADC_VREF: EfuseField = EfuseField::new(0, 4, 136, 5);
59+
pub const ADC_VREF: EfuseField = EfuseField::new(0, 4, 136, 5);
5860
/// Reserved; it was created by set_missed_fields_in_regs func
59-
pub(crate) const RESERVE_0_141: EfuseField = EfuseField::new(0, 4, 141, 1);
61+
pub const RESERVE_0_141: EfuseField = EfuseField::new(0, 4, 141, 1);
6062
/// read for XPD_SDIO_REG
61-
pub(crate) const XPD_SDIO_REG: EfuseField = EfuseField::new(0, 4, 142, 1);
63+
pub const XPD_SDIO_REG: EfuseField = EfuseField::new(0, 4, 142, 1);
6264
/// If XPD_SDIO_FORCE & XPD_SDIO_REG
63-
pub(crate) const XPD_SDIO_TIEH: EfuseField = EfuseField::new(0, 4, 143, 1);
65+
pub const XPD_SDIO_TIEH: EfuseField = EfuseField::new(0, 4, 143, 1);
6466
/// Ignore MTDI pin (GPIO12) for VDD_SDIO on reset
65-
pub(crate) const XPD_SDIO_FORCE: EfuseField = EfuseField::new(0, 4, 144, 1);
67+
pub const XPD_SDIO_FORCE: EfuseField = EfuseField::new(0, 4, 144, 1);
6668
/// Reserved; it was created by set_missed_fields_in_regs func
67-
pub(crate) const RESERVE_0_145: EfuseField = EfuseField::new(0, 4, 145, 15);
69+
pub const RESERVE_0_145: EfuseField = EfuseField::new(0, 4, 145, 15);
6870
/// Override SD_CLK pad (GPIO6/SPICLK)
69-
pub(crate) const SPI_PAD_CONFIG_CLK: EfuseField = EfuseField::new(0, 5, 160, 5);
71+
pub const SPI_PAD_CONFIG_CLK: EfuseField = EfuseField::new(0, 5, 160, 5);
7072
/// Override SD_DATA_0 pad (GPIO7/SPIQ)
71-
pub(crate) const SPI_PAD_CONFIG_Q: EfuseField = EfuseField::new(0, 5, 165, 5);
73+
pub const SPI_PAD_CONFIG_Q: EfuseField = EfuseField::new(0, 5, 165, 5);
7274
/// Override SD_DATA_1 pad (GPIO8/SPID)
73-
pub(crate) const SPI_PAD_CONFIG_D: EfuseField = EfuseField::new(0, 5, 170, 5);
75+
pub const SPI_PAD_CONFIG_D: EfuseField = EfuseField::new(0, 5, 170, 5);
7476
/// Override SD_CMD pad (GPIO11/SPICS0)
75-
pub(crate) const SPI_PAD_CONFIG_CS0: EfuseField = EfuseField::new(0, 5, 175, 5);
77+
pub const SPI_PAD_CONFIG_CS0: EfuseField = EfuseField::new(0, 5, 175, 5);
7678
///
77-
pub(crate) const CHIP_VER_REV2: EfuseField = EfuseField::new(0, 5, 180, 1);
79+
pub const CHIP_VER_REV2: EfuseField = EfuseField::new(0, 5, 180, 1);
7880
/// Reserved; it was created by set_missed_fields_in_regs func
79-
pub(crate) const RESERVE_0_181: EfuseField = EfuseField::new(0, 5, 181, 1);
81+
pub const RESERVE_0_181: EfuseField = EfuseField::new(0, 5, 181, 1);
8082
/// This field stores the voltage level for CPU to run at 240 MHz; or for
8183
/// flash/PSRAM to run at 80 MHz.0x0: level 7; 0x1: level 6; 0x2: level 5; 0x3:
8284
/// level 4. (RO)
83-
pub(crate) const VOL_LEVEL_HP_INV: EfuseField = EfuseField::new(0, 5, 182, 2);
85+
pub const VOL_LEVEL_HP_INV: EfuseField = EfuseField::new(0, 5, 182, 2);
8486
///
85-
pub(crate) const WAFER_VERSION_MINOR: EfuseField = EfuseField::new(0, 5, 184, 2);
87+
pub const WAFER_VERSION_MINOR: EfuseField = EfuseField::new(0, 5, 184, 2);
8688
/// Reserved; it was created by set_missed_fields_in_regs func
87-
pub(crate) const RESERVE_0_186: EfuseField = EfuseField::new(0, 5, 186, 2);
89+
pub const RESERVE_0_186: EfuseField = EfuseField::new(0, 5, 186, 2);
8890
/// Flash encryption config (key tweak bits)
89-
pub(crate) const FLASH_CRYPT_CONFIG: EfuseField = EfuseField::new(0, 5, 188, 4);
91+
pub const FLASH_CRYPT_CONFIG: EfuseField = EfuseField::new(0, 5, 188, 4);
9092
/// Efuse variable block length scheme
91-
pub(crate) const CODING_SCHEME: EfuseField = EfuseField::new(0, 6, 192, 2);
93+
pub const CODING_SCHEME: EfuseField = EfuseField::new(0, 6, 192, 2);
9294
/// Disable ROM BASIC interpreter fallback
93-
pub(crate) const CONSOLE_DEBUG_DISABLE: EfuseField = EfuseField::new(0, 6, 194, 1);
95+
pub const CONSOLE_DEBUG_DISABLE: EfuseField = EfuseField::new(0, 6, 194, 1);
9496
///
95-
pub(crate) const DISABLE_SDIO_HOST: EfuseField = EfuseField::new(0, 6, 195, 1);
97+
pub const DISABLE_SDIO_HOST: EfuseField = EfuseField::new(0, 6, 195, 1);
9698
/// Secure boot V1 is enabled for bootloader image
97-
pub(crate) const ABS_DONE_0: EfuseField = EfuseField::new(0, 6, 196, 1);
99+
pub const ABS_DONE_0: EfuseField = EfuseField::new(0, 6, 196, 1);
98100
/// Secure boot V2 is enabled for bootloader image
99-
pub(crate) const ABS_DONE_1: EfuseField = EfuseField::new(0, 6, 197, 1);
101+
pub const ABS_DONE_1: EfuseField = EfuseField::new(0, 6, 197, 1);
100102
/// Disable JTAG
101-
pub(crate) const JTAG_DISABLE: EfuseField = EfuseField::new(0, 6, 198, 1);
103+
pub const JTAG_DISABLE: EfuseField = EfuseField::new(0, 6, 198, 1);
102104
/// Disable flash encryption in UART bootloader
103-
pub(crate) const DISABLE_DL_ENCRYPT: EfuseField = EfuseField::new(0, 6, 199, 1);
105+
pub const DISABLE_DL_ENCRYPT: EfuseField = EfuseField::new(0, 6, 199, 1);
104106
/// Disable flash decryption in UART bootloader
105-
pub(crate) const DISABLE_DL_DECRYPT: EfuseField = EfuseField::new(0, 6, 200, 1);
107+
pub const DISABLE_DL_DECRYPT: EfuseField = EfuseField::new(0, 6, 200, 1);
106108
/// Disable flash cache in UART bootloader
107-
pub(crate) const DISABLE_DL_CACHE: EfuseField = EfuseField::new(0, 6, 201, 1);
109+
pub const DISABLE_DL_CACHE: EfuseField = EfuseField::new(0, 6, 201, 1);
108110
/// Usage of efuse block 3 (reserved)
109-
pub(crate) const KEY_STATUS: EfuseField = EfuseField::new(0, 6, 202, 1);
111+
pub const KEY_STATUS: EfuseField = EfuseField::new(0, 6, 202, 1);
110112
/// Reserved; it was created by set_missed_fields_in_regs func
111-
pub(crate) const RESERVE_0_203: EfuseField = EfuseField::new(0, 6, 203, 21);
113+
pub const RESERVE_0_203: EfuseField = EfuseField::new(0, 6, 203, 21);
112114
/// Flash encryption key
113-
pub(crate) const BLOCK1: EfuseField = EfuseField::new(1, 0, 0, 256);
115+
pub const BLOCK1: EfuseField = EfuseField::new(1, 0, 0, 256);
114116
/// Security boot key
115-
pub(crate) const BLOCK2: EfuseField = EfuseField::new(2, 0, 0, 256);
117+
pub const BLOCK2: EfuseField = EfuseField::new(2, 0, 0, 256);
116118
/// CRC8 for custom MAC address
117-
pub(crate) const CUSTOM_MAC_CRC: EfuseField = EfuseField::new(3, 0, 0, 8);
119+
pub const CUSTOM_MAC_CRC: EfuseField = EfuseField::new(3, 0, 0, 8);
118120
/// Custom MAC address
119-
pub(crate) const CUSTOM_MAC: EfuseField = EfuseField::new(3, 0, 8, 48);
121+
pub const CUSTOM_MAC: EfuseField = EfuseField::new(3, 0, 8, 48);
120122
/// reserved
121-
pub(crate) const RESERVED_3_56: EfuseField = EfuseField::new(3, 1, 56, 8);
123+
pub const RESERVED_3_56: EfuseField = EfuseField::new(3, 1, 56, 8);
122124
/// read for BLOCK3
123-
pub(crate) const BLK3_RESERVED_2: EfuseField = EfuseField::new(3, 2, 64, 32);
125+
pub const BLK3_RESERVED_2: EfuseField = EfuseField::new(3, 2, 64, 32);
124126
/// ADC1 Two Point calibration low point. Only valid if
125127
/// EFUSE_RD_BLK3_PART_RESERVE
126-
pub(crate) const ADC1_TP_LOW: EfuseField = EfuseField::new(3, 3, 96, 7);
128+
pub const ADC1_TP_LOW: EfuseField = EfuseField::new(3, 3, 96, 7);
127129
/// ADC1 Two Point calibration high point. Only valid if
128130
/// EFUSE_RD_BLK3_PART_RESERVE
129-
pub(crate) const ADC1_TP_HIGH: EfuseField = EfuseField::new(3, 3, 103, 9);
131+
pub const ADC1_TP_HIGH: EfuseField = EfuseField::new(3, 3, 103, 9);
130132
/// ADC2 Two Point calibration low point. Only valid if
131133
/// EFUSE_RD_BLK3_PART_RESERVE
132-
pub(crate) const ADC2_TP_LOW: EfuseField = EfuseField::new(3, 3, 112, 7);
134+
pub const ADC2_TP_LOW: EfuseField = EfuseField::new(3, 3, 112, 7);
133135
/// ADC2 Two Point calibration high point. Only valid if
134136
/// EFUSE_RD_BLK3_PART_RESERVE
135-
pub(crate) const ADC2_TP_HIGH: EfuseField = EfuseField::new(3, 3, 119, 9);
137+
pub const ADC2_TP_HIGH: EfuseField = EfuseField::new(3, 3, 119, 9);
136138
/// Secure version for anti-rollback
137-
pub(crate) const SECURE_VERSION: EfuseField = EfuseField::new(3, 4, 128, 32);
139+
pub const SECURE_VERSION: EfuseField = EfuseField::new(3, 4, 128, 32);
138140
/// reserved
139-
pub(crate) const RESERVED_3_160: EfuseField = EfuseField::new(3, 5, 160, 24);
141+
pub const RESERVED_3_160: EfuseField = EfuseField::new(3, 5, 160, 24);
140142
/// Version of the MAC field
141-
pub(crate) const MAC_VERSION: EfuseField = EfuseField::new(3, 5, 184, 8);
143+
pub const MAC_VERSION: EfuseField = EfuseField::new(3, 5, 184, 8);
142144
/// read for BLOCK3
143-
pub(crate) const BLK3_RESERVED_6: EfuseField = EfuseField::new(3, 6, 192, 32);
145+
pub const BLK3_RESERVED_6: EfuseField = EfuseField::new(3, 6, 192, 32);
144146
/// read for BLOCK3
145-
pub(crate) const BLK3_RESERVED_7: EfuseField = EfuseField::new(3, 7, 224, 32);
147+
pub const BLK3_RESERVED_7: EfuseField = EfuseField::new(3, 7, 224, 32);

0 commit comments

Comments
 (0)