Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental ESP-IDF v5 #810

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
> **Warning**
> This branch is a Work-In-Progress to add compatibility with ESP-IDF v4.x and v5.x.
> Not suitable for production use - only for dev / tests.
> As of now, it (kind-of) works on ESP-IDF v5.0 with the following caveats:
> * the crash handler (`xt_set_error_handler_callback` and `esp_task_wdt_get_trigger_tasknames`) is disabled for the moment, we need to decide whether we "fork" ESP-IDF again to port it ; or if the new APIs are enough to (partially ?) reimplement it (see commit: "**WIP WIP WIP : comment out ESP-IDF specifics of our fork**")
> * There is a crash in `OvmsConsole::Poll` which is not analysed (yet) and which is worked around by declaring a variable static (see commit: "**WIP WIP WIP : prevent a crash at boot (to be analysed)**")
> * Our (previously) local copies of `wolfssh` and `wolfssl` are now in submodules (and moved one level below in terms of directories) - mainly to be able to have a CMakeLists.txt different from the upstream one. In the process, one of our previous patches is now lost : https://github.com/openvehicles/Open-Vehicle-Monitoring-System-3/commit/51444539047daef7bd2accb23ef40d1bc14fdb20 and we need to decide how to handle this.
> * A lot of dependencies are now explicitly (hard-)coded in the CMakeLists.txt - which may, or may not be a good thing. Let's discuss it.
> * The set of defines (in ovms_webserver) have been transformed into a header generation because it was not known how to implement those in a satisfying manner in cmake.
> * There are still some warnings during compilation (mainly ADC which needs conversion + some others)
> * Mongoose is not (yet) ready to compile with TLS enabled.
> * wolfSSL can't be (yet) compiled with OPENSSL defines (see wolfSSL/wolfssl#6028)
> * wolfSSL has been updated to tag `v5.3.0-stable` (Note: later versions causing stack overflow during SSH session, to investigate)
> * wolfSSH has been updated to tag `v1.4.6-stable`
> * mongoose has not been updated but needs patching (see below for the patch)
> * Some commits (identified by "WIP WIP WIP") needs to be addressed
> * No real-world test has been done
> * We wanted to stay compatible with our 3.3.4 branch, and tried as much as we could to keep that compatibility. In case something is broken, please report and we will fix it.
> * This branch has mainly been tested using `cmake` build system / `idf.py`, not Makefiles (which have disappeared in v5.x)

### Patch for mongoose
```patch
diff --git a/mongoose.c b/mongoose.c
index b12cff18..60a7f62e 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -9160,7 +9160,7 @@ static void mg_send_file_data(struct mg_connection *nc, FILE *fp) {
static void mg_do_ssi_include(struct mg_connection *nc, struct http_message *hm,
const char *ssi, char *tag, int include_level,
const struct mg_serve_http_opts *opts) {
- char file_name[MG_MAX_PATH], path[MG_MAX_PATH], *p;
+ char file_name[MG_MAX_PATH], path[MG_MAX_PATH+2], *p;
FILE *fp;

/*
diff --git a/mongoose.h b/mongoose.h
index 3bcf8147..5649e1a7 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -1768,7 +1768,7 @@ typedef struct {

void cs_md5_init(cs_md5_ctx *c);
void cs_md5_update(cs_md5_ctx *c, const unsigned char *data, size_t len);
-void cs_md5_final(unsigned char *md, cs_md5_ctx *c);
+void cs_md5_final(unsigned char md[16], cs_md5_ctx *c);

#ifdef __cplusplus
}
```

Instructions for ESP-IDF v5.0:
* Setup ESP-IDF where you want and ensure it works, [following the instructions here](https://docs.espressif.com/projects/esp-idf/en/v5.0/esp32/get-started/index.html).
* Build as usual (`idf.py build`, etc...)

---

# Open-Vehicle-Monitoring-System-3 (OVMS3)

![OVMS3 module](docs/source/userguide/ovms-intro.jpg)
Expand Down
32 changes: 29 additions & 3 deletions vehicle/OVMS.V3/components/wolfssl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
set(srcs)
set(srcdirs)
set(srcexclude)
set(include_dirs)
set(priv_include_dirs)

if (CONFIG_OVMS_SC_GPL_WOLF)
list(APPEND srcs "wolfssl/src/crl.c" "wolfssl/src/internal.c" "wolfssl/src/keys.c" "wolfssl/src/ocsp.c" "wolfssl/src/sniffer.c" "wolfssl/src/ssl.c" "wolfssl/src/tls.c" "wolfssl/src/tls13.c" "wolfssl/src/wolfio.c" "wolfssl/wolfcrypt/src/aes.c" "wolfssl/wolfcrypt/src/arc4.c" "wolfssl/wolfcrypt/src/asm.c" "wolfssl/wolfcrypt/src/asn.c" "wolfssl/wolfcrypt/src/blake2b.c" "wolfssl/wolfcrypt/src/camellia.c" "wolfssl/wolfcrypt/src/chacha.c" "wolfssl/wolfcrypt/src/chacha20_poly1305.c" "wolfssl/wolfcrypt/src/cmac.c" "wolfssl/wolfcrypt/src/coding.c" "wolfssl/wolfcrypt/src/compress.c" "wolfssl/wolfcrypt/src/cpuid.c" "wolfssl/wolfcrypt/src/curve25519.c" "wolfssl/wolfcrypt/src/des3.c" "wolfssl/wolfcrypt/src/dh.c" "wolfssl/wolfcrypt/src/dsa.c" "wolfssl/wolfcrypt/src/ecc.c" "wolfssl/wolfcrypt/src/ecc_fp.c" "wolfssl/wolfcrypt/src/ed25519.c" "wolfssl/wolfcrypt/src/error.c" "wolfssl/wolfcrypt/src/fe_low_mem.c" "wolfssl/wolfcrypt/src/fe_operations.c" "wolfssl/wolfcrypt/src/ge_low_mem.c" "wolfssl/wolfcrypt/src/ge_operations.c" "wolfssl/wolfcrypt/src/hash.c" "wolfssl/wolfcrypt/src/hc128.c" "wolfssl/wolfcrypt/src/hmac.c" "wolfssl/wolfcrypt/src/idea.c" "wolfssl/wolfcrypt/src/integer.c" "wolfssl/wolfcrypt/src/logging.c" "wolfssl/wolfcrypt/src/md2.c" "wolfssl/wolfcrypt/src/md4.c" "wolfssl/wolfcrypt/src/md5.c" "wolfssl/wolfcrypt/src/memory.c" "wolfssl/wolfcrypt/src/pkcs12.c" "wolfssl/wolfcrypt/src/pkcs7.c" "wolfssl/wolfcrypt/src/poly1305.c" "wolfssl/wolfcrypt/src/port/Espressif/esp32_aes.c" "wolfssl/wolfcrypt/src/port/Espressif/esp32_mp.c" "wolfssl/wolfcrypt/src/port/Espressif/esp32_sha.c" "wolfssl/wolfcrypt/src/port/Espressif/esp32_util.c" "wolfssl/wolfcrypt/src/pwdbased.c" "wolfssl/wolfcrypt/src/rabbit.c" "wolfssl/wolfcrypt/src/random.c" "wolfssl/wolfcrypt/src/ripemd.c" "wolfssl/wolfcrypt/src/rsa.c" "wolfssl/wolfcrypt/src/sha.c" "wolfssl/wolfcrypt/src/sha256.c" "wolfssl/wolfcrypt/src/sha3.c" "wolfssl/wolfcrypt/src/sha512.c" "wolfssl/wolfcrypt/src/signature.c" "wolfssl/wolfcrypt/src/srp.c" "wolfssl/wolfcrypt/src/wc_encrypt.c" "wolfssl/wolfcrypt/src/wc_port.c" "wolfssl/wolfcrypt/src/wolfevent.c" "wolfssl/wolfcrypt/src/wolfmath.c")
# Cf https://github.com/gojimmypi/wolfssl/blob/Espressif_No_Install/IDE/Espressif/ESP-IDF/examples/wolfssl_server/components/wolfssl/CMakeLists.txt
# get a list of all wolfcrypt assembly files; we'll exclude them as they don't target Xtensa
FILE(GLOB EXCLUDE_ASM *.S)
file(GLOB_RECURSE EXCLUDE_ASM ${CMAKE_SOURCE_DIR} "wolfssl/wolfcrypt/src/*.S")
message(STATUS "wolfssl : EXCLUDE_ASM = ${EXCLUDE_ASM}")

list(APPEND include_dirs "port" "wolfssl")
list(APPEND srcdirs "wolfssl/src/"
"wolfssl/wolfcrypt/src"
"wolfssl/wolfcrypt/src/port/Espressif/"
"wolfssl/wolfcrypt/src/port/atmel/"
)
list(APPEND srcexclude
"wolfssl/src/bio.c"
"wolfssl/src/conf.c"
"wolfssl/src/misc.c"
"wolfssl/src/pk.c"
"wolfssl/src/ssl_misc.c" # included by ssl.c
"wolfssl/src/x509.c"
"wolfssl/src/x509_str.c"
"wolfssl/wolfcrypt/src/evp.c"
"wolfssl/wolfcrypt/src/misc.c"
"${EXCLUDE_ASM}"
)
endif ()

# requirements can't depend on config
idf_component_register(SRCS ${srcs}
SRC_DIRS ${srcdirs}
INCLUDE_DIRS ${include_dirs}
PRIV_INCLUDE_DIRS ${priv_include_dirs}
REQUIRES "freertos"
REQUIRES "freertos" "lwip"
EXCLUDE_SRCS ${srcexclude}
# PRIV_REQUIRES "freertos"
WHOLE_ARCHIVE)

if (CONFIG_OVMS_SC_GPL_WOLF)
component_compile_definitions(WOLFSSL_USER_SETTINGS)
component_compile_definitions("WOLFSSL_USER_SETTINGS")
component_compile_options("-Wno-cpp" "-Wno-char-subscripts")
set_source_files_properties(wolfssl/src/ssl.c PROPERTIES COMPILE_FLAGS "-Wno-format-truncation -Wno-char-subscripts")
set_source_files_properties(wolfssl/wolfcrypt/src/random.c PROPERTIES COMPILE_FLAGS "-Wno-implicit-function-declaration")
Expand Down
2 changes: 1 addition & 1 deletion vehicle/OVMS.V3/components/wolfssl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ submodule of the upstream repository during the course of the CMake conversion.
(This was done to isolate the upstream repo from the CMake conversion - there is
an already existing `CMakeLists.txt` file in this repo that we cannot use as-is)

All OVMS-specific changes have been re-applied to https://github.com/openvehicles/wolfssl/tree/v4.7.0-stable-ovms
All OVMS-specific changes have been re-applied to https://github.com/openvehicles/wolfssl/tree/v4.7.0-stable-ovms
27 changes: 24 additions & 3 deletions vehicle/OVMS.V3/components/wolfssl/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,37 @@ COMPONENT_OBJS += wolfssl/wolfcrypt/src/arc4.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/asm.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/asn.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/blake2b.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/blake2s.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/camellia.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/chacha.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/chacha20_poly1305.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/cmac.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/coding.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/compress.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/cpuid.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/cryptocb.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/curve25519.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/curve448.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/des3.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/dh.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/dsa.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/ecc.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/ecc_fp.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/eccsi.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/ed25519.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/ed448.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/error.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/falcon.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/fe_448.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/fe_low_mem.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/fe_operations.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/ge_448.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/ge_low_mem.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/ge_operations.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/hash.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/hc128.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/hmac.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/idea.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/integer.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/kdf.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/logging.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/md2.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/md4.o
Expand All @@ -63,17 +70,31 @@ COMPONENT_OBJS += wolfssl/wolfcrypt/src/port/Espressif/esp32_mp.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/port/Espressif/esp32_sha.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/port/Espressif/esp32_util.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/pwdbased.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/rabbit.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/random.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/rc2.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/ripemd.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/rsa.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sakke.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sha.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sha256.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sha3.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sha512.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/signature.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/siphash.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_arm32.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_arm64.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_armthumb.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_c32.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_c64.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_cortexm.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_dsp32.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_int.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/sp_x86_64.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/srp.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/tfm.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/wc_dsp.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/wc_encrypt.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/wc_pkcs11.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/wc_port.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/wolfevent.o
COMPONENT_OBJS += wolfssl/wolfcrypt/src/wolfmath.o
Expand Down
29 changes: 22 additions & 7 deletions vehicle/OVMS.V3/components/wolfssl/port/user_settings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/* user_settings.h
*
* Part of this file Copyright (C) wolfSSL Inc. (GPL2+)
* See: https://github.com/wolfSSL/wolfssl/blob/master/IDE/Espressif/ESP-IDF/user_settings.h
*/

// Beginning of file : specific to OVMSv3
// --------------------------------------

// For compatibility of WolfSSH with ESP-IDF

#include "esp_idf_version.h"

#define BUILDING_WOLFSSH
#define WOLFSSH_LWIP
//#define DEFAULT_HIGHWATER_MARK (1024 * 4)
Expand All @@ -11,7 +21,6 @@

// For compatibility of WolfSSL with ESP-IDF

//#define DEBUG_WOLFSSL
#define WOLFSSL_ESPIDF
#define WOLFSSL_ESPWROOM32
// The above two imply:
Expand All @@ -25,6 +34,7 @@
// #define ECC_TIMING_RESISTANT
// #define WC_RSA_BLINDING
// #define WOLFSSL_ESP32WROOM32_CRYPT

#define BUILDING_WOLFSSL
#define HAVE_VISIBILITY 1
#define NO_DEV_RANDOM
Expand All @@ -43,8 +53,8 @@

// Inclusion and exclusion of WolfSSL features, may be adjusted

#define OPENSSL_EXTRA
#define OPENSSL_ALL
// #define OPENSSL_EXTRA // -> compile error ssl.c:18011:22: error: size of array 'sha_test' is negative
// #define OPENSSL_ALL // -> compile error ssl.c:18011:22: error: size of array 'sha_test' is negative
#define WC_NO_HARDEN
#define HAVE_EX_DATA
#define NO_DES3
Expand All @@ -59,17 +69,13 @@
#define ECC_SHAMIR
#define ECC_TIMING_RESISTANT
#define HAVE_WC_ECC_SET_RNG
#define HAVE_AESGCM
//#define HAVE_CHACHA
#define HAVE_DH
#define HAVE_ECC
#define HAVE_EXTENDED_MASTER
#define HAVE_HASHDRBG
#define HAVE_ONE_TIME_AUTH
//#define HAVE_POLY1305
#define HAVE_SUPPORTED_CURVES
#define HAVE_THREAD_LS
#define HAVE_TLS_EXTENSIONS
#define TFM_ECC256
#define TFM_TIMING_RESISTANT
#define WC_NO_ASYNC_THREADING
Expand All @@ -82,3 +88,12 @@
#define WOLFSSL_CERT_EXT
#define NO_WOLFSSL_STUB
#define WOLFSSL_OLD_PRIME_CHECK

#define HAVE_TLS_EXTENSIONS
#define HAVE_SUPPORTED_CURVES

#define HAVE_AESGCM
#define HAVE_ECC

/* debug options */
/* #define DEBUG_WOLFSSL */
2 changes: 1 addition & 1 deletion vehicle/OVMS.V3/components/wolfssl/wolfssl
Submodule wolfssl updated 1448 files
4 changes: 4 additions & 0 deletions vehicle/OVMS.V3/main/ovms_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "ovms_console.h"
#include "ovms_version.h"
#include "log_buffers.h"
#include "esp_idf_version.h"

//static const char *TAG = "Console";
static char CRbuf[4] = { '\r', '\033', '[', 'K' };
Expand Down Expand Up @@ -124,6 +125,9 @@ void OvmsConsole::Service()

void OvmsConsole::Poll(portTickType ticks, QueueHandle_t queue)
{
#if ESP_IDF_VERSION_MAJOR >= 4
static
#endif
Event event;

if (!queue)
Expand Down