Skip to content

Commit 99d58ae

Browse files
authored
Restore support for ESP-IDF (#100)
1 parent a9e807a commit 99d58ae

File tree

25 files changed

+300
-84
lines changed

25 files changed

+300
-84
lines changed

.github/workflows/ci.yml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ jobs:
212212
uses: esp-rs/[email protected]
213213
with:
214214
default: true
215-
ldproxy: false
215+
ldproxy: true
216216

217217
# TODO: Double-check and uncomment
218218
# - uses: Swatinem/rust-cache@v2
@@ -236,14 +236,73 @@ jobs:
236236
- name: Build - Examples
237237
run: export WIFI_SSID=ssid; export WIFI_PASS=pass; cd examples/${{ matrix.mcu[0] }}; cargo build --no-default-features --features ${{ matrix.mcu[1] }} --target ${{ matrix.mcu[2] }} -Zbuild-std=core,alloc,panic_abort
238238

239+
build-esp-idf:
240+
name: Build-ESP-IDF
241+
runs-on: ubuntu-latest
242+
permissions: read-all
243+
needs: build-mcu
244+
strategy:
245+
fail-fast: false
246+
matrix:
247+
mcu:
248+
- [std, esp32, xtensa-esp32-espidf]
249+
# - [std, esp32s2, xtensa-esp32s2-espidf]
250+
- [std, esp32s3, xtensa-esp32s3-espidf]
251+
# - [std, esp32c2, riscv32imc-esp-espidf]
252+
# - [std, esp32c3, riscv32imc-esp-espidf]
253+
# - [std, esp32c6, riscv32imac-esp-espidf]
254+
# No Wifi support on esp32h2
255+
# - [std, esp32h2, riscv32imac-esp-espidf]
256+
steps:
257+
- uses: actions/checkout@v4
258+
259+
- uses: dtolnay/rust-toolchain@v1
260+
with:
261+
target: x86_64-unknown-linux-gnu
262+
toolchain: nightly
263+
components: rust-src,rustfmt,clippy
264+
265+
- name: Install MCU target
266+
if: startsWith(matrix.mcu[2], 'riscv32')
267+
run: rustup target add ${{ matrix.mcu[2] }}
268+
269+
- name: Install Rust for Xtensa
270+
if: startsWith(matrix.mcu[2], 'xtensa-')
271+
uses: esp-rs/[email protected]
272+
with:
273+
default: true
274+
ldproxy: true
275+
276+
# TODO: Double-check and uncomment
277+
# - uses: Swatinem/rust-cache@v2
278+
# with:
279+
# workspaces: |
280+
# ./
281+
# xtask
282+
283+
- name: Clippy
284+
run: cargo clippy --target ${{ matrix.mcu[2] }} -Zbuild-std=std,panic_abort -- -D warnings
285+
286+
- name: Build
287+
run: cargo build --target ${{ matrix.mcu[2] }} -Zbuild-std=std,panic_abort
288+
289+
- name: Fmt Check - Examples
290+
run: cd examples/${{ matrix.mcu[0] }}; cargo fmt -- --check
291+
292+
- name: Clippy - Examples
293+
run: export WIFI_SSID=ssid; export WIFI_PASS=pass; cd examples/${{ matrix.mcu[0] }}; cargo clippy --target ${{ matrix.mcu[2] }} -Zbuild-std=std,panic_abort -- -D warnings
294+
295+
- name: Build - Examples
296+
run: export WIFI_SSID=ssid; export WIFI_PASS=pass; cd examples/${{ matrix.mcu[0] }}; cargo build --target ${{ matrix.mcu[2] }} -Zbuild-std=std,panic_abort
297+
239298
# If libraries are rebuilt and tests are successful, we upload them in a specific job
240299
# that has write access to prevent security breaches, and unwanted use of the token
241300
commit-libs:
242301
name: Commit MbedTLS libs
243302
runs-on: ubuntu-latest
244303
permissions:
245304
contents: write
246-
needs: build-mcu
305+
needs: build-esp-idf
247306
# TODO: Currently GitHub doesn't allow pushing to a forked repo's branch when running an action on a PR to upstream.
248307
if: |
249308
github.event.pull_request.head.repo.full_name == github.repository &&

esp-mbedtls-sys/src/hook/digest/sha1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub unsafe fn hook_sha1(sha1: Option<&'static (dyn MbedtlsSha1 + Send + Sync)>)
2121
critical_section::with(|cs| {
2222
#[allow(clippy::if_same_then_else)]
2323
if sha1.is_some() {
24-
info!("SHA-1 hook: added custom/HW accelerated impl");
24+
debug!("SHA-1 hook: added custom/HW accelerated impl");
2525
} else {
26-
info!("SHA-1 hook: removed");
26+
debug!("SHA-1 hook: removed");
2727
}
2828

2929
alt::SHA1.borrow(cs).set(sha1);

esp-mbedtls-sys/src/hook/digest/sha256.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub unsafe fn hook_sha256(sha256: Option<&'static (dyn MbedtlsSha256 + Send + Sy
2222
critical_section::with(|cs| {
2323
#[allow(clippy::if_same_then_else)]
2424
if sha256.is_some() {
25-
info!("SHA-256 hook: added custom/HW accelerated impl");
25+
debug!("SHA-256 hook: added custom/HW accelerated impl");
2626
} else {
27-
info!("SHA-256 hook: removed");
27+
debug!("SHA-256 hook: removed");
2828
}
2929

3030
alt::SHA256.borrow(cs).set(sha256);
@@ -43,9 +43,9 @@ pub unsafe fn hook_sha224(sha224: Option<&'static (dyn MbedtlsSha224 + Send + Sy
4343
critical_section::with(|cs| {
4444
#[allow(clippy::if_same_then_else)]
4545
if sha224.is_some() {
46-
info!("SHA-224 hook: added custom/HW accelerated impl");
46+
debug!("SHA-224 hook: added custom/HW accelerated impl");
4747
} else {
48-
info!("SHA-224 hook: removed");
48+
debug!("SHA-224 hook: removed");
4949
}
5050

5151
alt::SHA224.borrow(cs).set(sha224);

esp-mbedtls-sys/src/hook/digest/sha512.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub unsafe fn hook_sha512(sha512: Option<&'static (dyn MbedtlsSha512 + Send + Sy
2222
critical_section::with(|cs| {
2323
#[allow(clippy::if_same_then_else)]
2424
if sha512.is_some() {
25-
info!("SHA-512 hook: added custom/HW accelerated impl");
25+
debug!("SHA-512 hook: added custom/HW accelerated impl");
2626
} else {
27-
info!("SHA-512 hook: removed");
27+
debug!("SHA-512 hook: removed");
2828
}
2929

3030
alt::SHA512.borrow(cs).set(sha512);
@@ -43,9 +43,9 @@ pub unsafe fn hook_sha384(sha384: Option<&'static (dyn MbedtlsSha384 + Send + Sy
4343
critical_section::with(|cs| {
4444
#[allow(clippy::if_same_then_else)]
4545
if sha384.is_some() {
46-
info!("SHA-384 hook: added custom/HW accelerated impl");
46+
debug!("SHA-384 hook: added custom/HW accelerated impl");
4747
} else {
48-
info!("SHA-384 hook: removed");
48+
debug!("SHA-384 hook: removed");
4949
}
5050

5151
alt::SHA384.borrow(cs).set(sha384);

esp-mbedtls-sys/src/hook/exp_mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ pub unsafe fn hook_exp_mod(exp_mod: Option<&'static (dyn MbedtlsMpiExpMod + Send
5757
critical_section::with(|cs| {
5858
#[allow(clippy::if_same_then_else)]
5959
if exp_mod.is_some() {
60-
info!("RSA-EXP-MOD hook: added custom/HW accelerated impl");
60+
debug!("RSA-EXP-MOD hook: added custom/HW accelerated impl");
6161
} else {
62-
info!("RSA-EXP-MOD hook: removed");
62+
debug!("RSA-EXP-MOD hook: removed");
6363
}
6464

6565
alt::EXP_MOD.borrow(cs).set(exp_mod);

esp-mbedtls-sys/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub use error::*;
1010
pub(crate) mod fmt;
1111

1212
mod error;
13+
#[cfg(not(target_os = "espidf"))]
1314
mod extra_impls; // TODO: Figure out if we still need this
1415

1516
#[cfg(not(target_os = "espidf"))]

esp-mbedtls/src/cert.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use core::ffi::CStr;
22
use core::marker::PhantomData;
33

4-
use esp_mbedtls_sys::*;
5-
6-
use super::{merr, MRc, SessionError};
4+
use super::sys::*;
5+
use super::{MRc, SessionError};
76

87
/// Holds a reference to a PEM or DER-encoded X509 certificate or private key.
98
///

esp-mbedtls/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ use core::ptr::NonNull;
1010

1111
use critical_section::Mutex;
1212

13-
use esp_mbedtls_sys::*;
13+
#[cfg(not(target_os = "espidf"))]
14+
use crate::sys::{mbedtls_calloc, mbedtls_free};
15+
use crate::sys::{
16+
mbedtls_ctr_drbg_context, mbedtls_ctr_drbg_free, mbedtls_ctr_drbg_init, mbedtls_pk_context,
17+
mbedtls_pk_free, mbedtls_pk_init, mbedtls_ssl_conf_dbg, mbedtls_ssl_config,
18+
mbedtls_ssl_config_free, mbedtls_ssl_config_init, mbedtls_ssl_context, mbedtls_ssl_free,
19+
mbedtls_ssl_init, mbedtls_x509_crt, mbedtls_x509_crt_free, mbedtls_x509_crt_init,
20+
};
1421

1522
use rand_core::CryptoRng;
1623

@@ -82,6 +89,8 @@ impl<'d> Tls<'d> {
8289
pub fn set_debug(&mut self, level: u32) {
8390
#[cfg(not(target_os = "espidf"))]
8491
unsafe {
92+
use crate::sys::mbedtls_debug_set_threshold;
93+
8594
mbedtls_debug_set_threshold(level as c_int);
8695
}
8796
}
@@ -423,3 +432,11 @@ unsafe extern "C" fn mbedtls_platform_zeroize(dst: *mut c_uchar, len: u32) {
423432
dst.offset(i).write_volatile(0);
424433
}
425434
}
435+
436+
#[cfg(target_os = "espidf")]
437+
extern "C" {
438+
#[link_name = "calloc"]
439+
fn mbedtls_calloc(num: usize, size: usize) -> *mut c_void;
440+
#[link_name = "free"]
441+
fn mbedtls_free(ptr: *mut c_void);
442+
}

esp-mbedtls/src/session.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use core::ffi::{c_int, c_void, CStr};
22

33
use embedded_io::{Error, ErrorKind};
44

5-
use esp_mbedtls_sys::*;
6-
7-
use super::{mbedtls_rng, merr, Certificate, MBox, PrivateKey, Tls, TlsReference, TlsVersion};
5+
use super::sys::*;
6+
use super::{mbedtls_rng, Certificate, MBox, PrivateKey, Tls, TlsReference, TlsVersion};
87

98
pub use asynch::*;
109

esp-mbedtls/src/session/asynch.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ use core::task::{Context, Poll};
55

66
use embedded_io::ErrorKind;
77

8-
use esp_mbedtls_sys::*;
9-
108
use io::{ErrorType, Read, Write};
119

12-
use crate::{merr, SessionError, TlsReference};
10+
use crate::sys::*;
11+
use crate::{SessionError, TlsReference};
1312

1413
use super::{SessionConfig, SessionState};
1514

0 commit comments

Comments
 (0)