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

Moving OVMS to latest ESP-IDF framework #360

Open
markwj opened this issue Apr 27, 2020 · 6 comments
Open

Moving OVMS to latest ESP-IDF framework #360

markwj opened this issue Apr 27, 2020 · 6 comments

Comments

@markwj
Copy link
Member

markwj commented Apr 27, 2020

This issue will be used to track the possibility / progress of moving OVMS to the latest ESP IDF framework.

@markwj
Copy link
Member Author

markwj commented Apr 27, 2020

Original (now closed, as unresolvable) issue was here:

Problems when trying to update esp-idf and toolchain to version 8.2 (the latest) #263

@leres
Copy link
Contributor

leres commented Apr 29, 2020

(After a lot of work) I have built the espressif crosstool-NG esp-2020r1 release version of the toolchain for my chosen dev environment (FreeBSD).

Is it time to create branches of openvehicles/Open-Vehicle-Monitoring-System-3 and openvehicles/esp-idf to give us a place to work? I'd assume we want to target the esp-idf v4.0 release?

@leres
Copy link
Contributor

leres commented May 2, 2020

I took a run at this today. I used the esp-idf v4.0 branch.

I created a pull request for two easy problems. One is that esp32wifi::SetPowerMode() is using WIFI_PS_MODEM which is deprecated. In the current esp-idf-espressif version this is a define to WIFI_PS_MIN_MODEM. The define is gone by v4.0.

The other problem was a conflict with the spi_signal_conn_t struct definition in components/spinodma/spi_master_nodma.c. The versions of spi_signal_conn_t in the esp-idf-espressif and v4.0 of soc/spi_periph.h look the same and are similar to what's in spi_master_nodma.c with members renamed (e.g. spiclk_native becomes spiclk_iomux_pin).

There is a lot of churn resulting in code ifdef'ed off of ESP_DNS in components/lwip/port/esp32/include/lwipopts.h. This changes dns_getserver() from returning a pointer to a const ip_addr_t to returning a ip_addr_t. You can't just turn off ESP_DNS because it breaks some ESP_LWIP code (that really should be tied to ESP_DNS). I decided against including these changes in my pull request because it involves changing the esp-idf and I wanted my pull to be conservative.

strverscmp() is in the standard libraries with gcc8 and conflicts with components/strverscmp.

There are a bunch of gcc8 errors in the version of wolfssl we're using related to the len parameter to xstrncpy() and friends. This is supposed to indicate available space in the dst buffer. But the code is not using it that way (and it looks like their are many opportunities for buffer overflow!) For example:

XSTRNCPY(header, BEGIN_CERT, headerLen);
XSTRNCAT(header, "\n", 1);
[...]
XSTRNCAT(header, "Proc-Type: 4,ENCRYPTED\n", 23);
XSTRNCAT(header, "DEK-Info: ", 10);

where headerLen is set to the size of the buffer initially I dunno what is up with the rest of the calls.

I looked at the current version of wolfssl and the code looks better but I suspect gcc8 will still flag remaining problems.

Boot::Boot() in main/ovms_boot.cpp sets up an error handler that v4.0 doesn't have:

// install error handler:
xt_set_error_handler_callback(ErrorCallback);

It looks like Fabrizio ran into this and opened an issue with espressif.

When I stopped I was getting linker errors for undefined symbols, e.g. mbuf_init, mbuf_free, etc. I didn't find these in the v4.0 esp-idf.

@dexterbg
Copy link
Member

dexterbg commented May 3, 2020

Regarding the panic callback, see my post:
espressif/esp-idf#5163 (comment)

The mbuf_init etc. calls are mongoose related. See:
https://github.com/openvehicles/mongoose/blob/master/mongoose.c#L1547
Note these also are also different in our fork, as my change to these regarding thread safety hasn't been merged upstream yet.

gcc8 does a good job at detecting possible buffer issues, it's definitely a good idea not to ignore the warnings.

@leres
Copy link
Contributor

leres commented Jun 12, 2020

I was going to do some more work on this; should I be targeting v4.0.1 (released three weeks ago) or v4.1 (beta2 pre-released a week ago).

llange added a commit to llange/mongoose that referenced this issue Nov 27, 2022
GCC 8.4.0 does not accept function defined only with `inline` while
it is ok with `static inline`.
GCC 5.2.0 does not seem to care.

See also openvehicles/Open-Vehicle-Monitoring-System-3#360

Signed-off-by: Ludovic LANGE <[email protected]>
llange added a commit to llange/Open-Vehicle-Monitoring-System-3 that referenced this issue Nov 28, 2022
We have a local implementation of `strverscmp` ; however ESP-IDF
seems to include it in newlib since version 4.x
(I'm not 100% sure but at least in 4.4 it is present)

A small test allows to include or not the component.

Tested on both our local fork of ESP-IDF and release 4.4

See openvehicles#360

Signed-off-by: Ludovic LANGE <[email protected]>
llange added a commit to llange/Open-Vehicle-Monitoring-System-3 that referenced this issue Nov 28, 2022
GCC 8.4.0 does not accept an assignment with the macros
[`SDMMC_HOST_DEFAULT()`](https://github.com/espressif/esp-idf/blob/8153bfe4125e6a608abccf1561fd10285016c90a/components/driver/include/driver/sdmmc_host.h#L30)
and [`SDMMC_SLOT_CONFIG_DEFAULT()`](https://github.com/espressif/esp-idf/blob/8153bfe4125e6a608abccf1561fd10285016c90a/components/driver/include/driver/sdmmc_host.h#L92),
because the macros are defined as a curly braces list ; it fails with
`error: no match for 'operator=' (operand types are 'sdmmc_host_t' and '<brace-enclosed initializer list>')`

This patch fixes the syntax so that it works with GCC 8.4.0, by prepending the type before the list.
GCC 5.2.0 is OK with the fix.

See openvehicles#360

Signed-off-by: Ludovic LANGE <[email protected]>
llange added a commit to llange/Open-Vehicle-Monitoring-System-3 that referenced this issue Nov 29, 2022
We have a local implementation of `strverscmp` ; however ESP-IDF
seems to include it in newlib since version 4.x
(I'm not 100% sure but at least in 4.4 it is present)

A small test allows to include or not the component include files
(which are otherwise defined in `<string.h>`)

Tested on both our local fork of ESP-IDF and release 4.4

See openvehicles#360

Signed-off-by: Ludovic LANGE <[email protected]>
@fowi4hjte
Copy link
Contributor

There are many CVE issues that have been fixed since the unsupported IDF 3.3 the OVMS is using currently: https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=esp
Its really important to have latest security fixes to a device that have 24/7 access to the CAN bus of the car and can open the doors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants