Skip to content

Commit 8c75312

Browse files
authored
Ota partition support (#3354)
* Add basic OTA functionality * Return Result from Ota::new * Restructured * Enable `ota` by default * Include metadata to let tooling know we need an ota-data partition * More docs * CHANGELOG.md * Make OSX happy to run tests * Another try * OSX... * OSX, again * Add tests * Prefer ROM CRC function * Unconditionally include the "ota" feature * Renaming and docs * de-noise tests * De-duplicate * Address more review comments * Review comments and Clippy
1 parent bfe6a1c commit 8c75312

File tree

8 files changed

+553
-5
lines changed

8 files changed

+553
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,4 @@ jobs:
182182
- run: cd esp-config && cargo test --features build
183183

184184
# Run tests in esp-bootloader-esp-idf
185-
- run: cd esp-bootloader-esp-idf && cargo test
185+
- run: cd esp-bootloader-esp-idf && cargo test --features=std

esp-bootloader-esp-idf/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
- Support reading partition tables and conveniently read/write partition content (#3316)
1515

16+
- OTA-DATA partition support (#3354)
17+
1618
### Changed
1719

1820
### Fixed

esp-bootloader-esp-idf/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ document-features = "0.2.11"
1919
esp-config = { version = "0.3.0", path = "../esp-config" }
2020
embedded-storage = "0.3.1"
2121
log = { version = "0.4.26", optional = true }
22-
md-5 = { version = "0.10.6", default-features = false, optional = true }
2322
strum = { version = "0.27.1", default-features = false, features = ["derive"] }
2423

24+
crc = { version = "3.0.0", optional = true }
25+
md-5 = { version = "0.10.6", default-features = false, optional = true }
26+
2527
[build-dependencies]
2628
chrono = { version = "0.4.20", default-features = false, features = ["clock"] }
2729
esp-config = { version = "0.3.0", path = "../esp-config", features = ["build"] }
@@ -37,3 +39,6 @@ log = ["dep:log"]
3739

3840
## Enable support for `defmt`
3941
defmt = ["dep:defmt"]
42+
43+
# Replace ROM functions with pure Rust implementations, needed for tests.
44+
std = ["dep:crc"]

esp-bootloader-esp-idf/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,28 @@
2626
// MUST be the first module
2727
mod fmt;
2828

29+
#[cfg(not(feature = "std"))]
30+
mod rom;
31+
#[cfg(not(feature = "std"))]
32+
pub(crate) use rom as crypto;
33+
34+
#[cfg(feature = "std")]
35+
mod non_rom;
36+
#[cfg(feature = "std")]
37+
pub(crate) use non_rom as crypto;
38+
2939
pub mod partitions;
3040

41+
pub mod ota;
42+
43+
// We run tests on the host which happens to be MacOS machines and mach-o
44+
// doesn't like `link-sections` this way
45+
#[cfg(not(target_os = "macos"))]
46+
#[link_section = ".espressif.metadata"]
47+
#[used]
48+
#[export_name = "bootloader.NAME"]
49+
static OTA_FEATURE: [u8; 7] = *b"ESP-IDF";
50+
3151
/// ESP-IDF compatible application descriptor
3252
///
3353
/// This gets populated by the [esp_app_desc] macro.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crc::{Algorithm, Crc};
2+
3+
static ALGO_CRC32_NORMAL: Algorithm<u32> = Algorithm {
4+
width: 32,
5+
poly: 0x04c11db7,
6+
init: 0,
7+
refin: true,
8+
refout: true,
9+
xorout: 0xffffffff,
10+
check: 0,
11+
residue: 0,
12+
};
13+
14+
pub struct Crc32 {
15+
algo: Crc<u32>,
16+
}
17+
18+
impl Crc32 {
19+
pub fn new() -> Self {
20+
Self {
21+
algo: Crc::<u32>::new(&ALGO_CRC32_NORMAL),
22+
}
23+
}
24+
25+
pub fn crc(&self, data: &[u8]) -> u32 {
26+
let mut digest = self.algo.digest();
27+
digest.update(&data);
28+
digest.finalize()
29+
}
30+
}

0 commit comments

Comments
 (0)