From 6b4312fb905f6cc356cedc07547cab09c92535da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Quentin?= Date: Wed, 8 Jan 2025 08:12:04 +0100 Subject: [PATCH] Use own implementation instead of ROM functions, re-add memchr (#2896) * Use own implementation instead of ROM functions, re-add memchr ROM function * CHANGELOG.md * Improve * Cast --- esp-hal/ld/esp32/rom/additional.ld | 4 ++-- esp-hal/ld/esp32c2/rom/additional.ld | 2 -- esp-hal/ld/esp32c3/rom/additional.ld | 4 ++-- esp-hal/ld/esp32c6/rom/additional.ld | 2 -- esp-hal/ld/esp32h2/rom/additional.ld | 4 ++-- esp-hal/ld/esp32s2/rom/additional.ld | 1 - esp-hal/ld/esp32s3/rom/additional.ld | 2 -- esp-wifi/CHANGELOG.md | 1 + esp-wifi/src/compat/misc.rs | 26 +++++++++++++++++++++++--- 9 files changed, 30 insertions(+), 16 deletions(-) diff --git a/esp-hal/ld/esp32/rom/additional.ld b/esp-hal/ld/esp32/rom/additional.ld index d8afbed12..3846916ff 100644 --- a/esp-hal/ld/esp32/rom/additional.ld +++ b/esp-hal/ld/esp32/rom/additional.ld @@ -16,5 +16,5 @@ PROVIDE ( strchr = 0x4000c53c ); PROVIDE ( strlcpy = 0x4000c584 ); PROVIDE ( strstr = 0x4000c674 ); PROVIDE ( strcasecmp = 0x400011cc ); -PROVIDE ( strdup = 0x4000143c ); -PROVIDE ( atoi = 0x400566c4 ); \ No newline at end of file + +PROVIDE ( memchr = 0x4000c244 ); diff --git a/esp-hal/ld/esp32c2/rom/additional.ld b/esp-hal/ld/esp32c2/rom/additional.ld index 46ef79d8f..146be238c 100644 --- a/esp-hal/ld/esp32c2/rom/additional.ld +++ b/esp-hal/ld/esp32c2/rom/additional.ld @@ -13,5 +13,3 @@ PROVIDE ( strchr = 0x40000514 ); PROVIDE ( strlcpy = 0x40000524 ); PROVIDE ( strstr = 0x400004ac ); PROVIDE ( strcasecmp = 0x40000504 ); -PROVIDE ( strdup = 0x40000510 ); -PROVIDE ( atoi = 0x40000580 ); diff --git a/esp-hal/ld/esp32c3/rom/additional.ld b/esp-hal/ld/esp32c3/rom/additional.ld index f45bec9b5..7a96d17e5 100644 --- a/esp-hal/ld/esp32c3/rom/additional.ld +++ b/esp-hal/ld/esp32c3/rom/additional.ld @@ -17,5 +17,5 @@ PROVIDE( strchr = 0x400003e0 ); PROVIDE( strlcpy = 0x400003f0 ); PROVIDE( strstr = 0x40000378 ); PROVIDE( strcasecmp = 0x400003d0 ); -PROVIDE( strdup = 0x400003dc ); -PROVIDE( atoi = 0x4000044c ); \ No newline at end of file + +PROVIDE( memchr = 0x400003c8 ); diff --git a/esp-hal/ld/esp32c6/rom/additional.ld b/esp-hal/ld/esp32c6/rom/additional.ld index a9c1801e3..b77b1657e 100644 --- a/esp-hal/ld/esp32c6/rom/additional.ld +++ b/esp-hal/ld/esp32c6/rom/additional.ld @@ -15,5 +15,3 @@ PROVIDE(strchr = 0x40000534); PROVIDE(strlcpy = 0x40000544); PROVIDE(strstr = 0x400004cc); PROVIDE(strcasecmp = 0x40000524); -PROVIDE(strdup = 0x40000530); -PROVIDE(atoi = 0x400005a0); diff --git a/esp-hal/ld/esp32h2/rom/additional.ld b/esp-hal/ld/esp32h2/rom/additional.ld index 7c1c27ace..a12eb96ea 100644 --- a/esp-hal/ld/esp32h2/rom/additional.ld +++ b/esp-hal/ld/esp32h2/rom/additional.ld @@ -15,5 +15,5 @@ PROVIDE( strchr = 0x4000052c ); PROVIDE( strlcpy = 0x4000053c ); PROVIDE( strstr = 0x400004c4 ); PROVIDE( strcasecmp = 0x4000051c ); -PROVIDE( strdup = 0x40000528 ); -PROVIDE( atoi = 0x40000598 ); + +PROVIDE( memchr = 0x40000514 ); diff --git a/esp-hal/ld/esp32s2/rom/additional.ld b/esp-hal/ld/esp32s2/rom/additional.ld index ea535add6..028b90211 100644 --- a/esp-hal/ld/esp32s2/rom/additional.ld +++ b/esp-hal/ld/esp32s2/rom/additional.ld @@ -17,4 +17,3 @@ PROVIDE ( strchr = 0x4001adb0 ); PROVIDE ( strlcpy = 0x4001adf8 ); PROVIDE ( strstr = 0x4001aee8 ); PROVIDE ( strcasecmp = 0x40007b38 ); -PROVIDE ( strdup = 0x40007d84 ); diff --git a/esp-hal/ld/esp32s3/rom/additional.ld b/esp-hal/ld/esp32s3/rom/additional.ld index 4e926c8ad..1bd7a4b18 100644 --- a/esp-hal/ld/esp32s3/rom/additional.ld +++ b/esp-hal/ld/esp32s3/rom/additional.ld @@ -19,5 +19,3 @@ PROVIDE( strchr = 0x4000138c ); PROVIDE( strlcpy = 0x400013bc ); PROVIDE( strstr = 0x40001254 ); PROVIDE( strcasecmp = 0x4000135c ); -PROVIDE( strdup = 0x40001380 ); -PROVIDE( atoi = 0x400014d0 ); diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index eb907eaf4..2c19d763a 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed triggering a debug-assertion during scan (#2612) +- Fix WPA2-ENTERPRISE functionality (#2896) ### Removed diff --git a/esp-wifi/src/compat/misc.rs b/esp-wifi/src/compat/misc.rs index 8e586cb2c..9f645f2d2 100644 --- a/esp-wifi/src/compat/misc.rs +++ b/esp-wifi/src/compat/misc.rs @@ -1,5 +1,6 @@ -// these are not called but needed for linking +use crate::compat::malloc::malloc; +// these are not called but needed for linking #[no_mangle] unsafe extern "C" fn fwrite(ptr: *const (), size: usize, count: usize, stream: *const ()) -> usize { todo!("fwrite {:?} {} {} {:?}", ptr, size, count, stream) @@ -20,8 +21,27 @@ unsafe extern "C" fn fclose(stream: *const ()) -> i32 { todo!("fclose {:?}", stream); } -// not available in ROM on ESP32-S2 -#[cfg(feature = "esp32s2")] +// We cannot just use the ROM function since it needs to allocate memory +#[no_mangle] +unsafe extern "C" fn strdup(str: *const core::ffi::c_char) -> *const core::ffi::c_char { + trace!("strdup {:?}", str); + + unsafe { + let s = core::ffi::CStr::from_ptr(str); + let len = s.count_bytes() + 1; + let p = malloc(len); + if !p.is_null() { + core::ptr::copy_nonoverlapping(str, p.cast(), len); + } + p.cast() + } +} + +// We cannot just use the ROM function since it calls `__getreent` +// +// From docs: The __getreent() function returns a per-task pointer to struct +// _reent in newlib libc. This structure is allocated on the TCB of each task. +// i.e. it assumes a FreeRTOS task calling it. #[no_mangle] unsafe extern "C" fn atoi(str: *const i8) -> i32 { trace!("atoi {:?}", str);