LibSSH-ESP32 icon indicating copy to clipboard operation
LibSSH-ESP32 copied to clipboard

ESP-IDF 5.1.1 compile fail

Open VNovytskyi opened this issue 1 year ago • 16 comments

Brief: Can not compile the library with ESP-IDF project. ESP-IDF version: 5.1.1 LibSSH-ESP32 version: 3.1.0 Errors list:

  • LibSSH-ESP32/src/libmbedcrypto.c:196:47: error: 'mbedtls_md_context_t' has no member named 'md_info'
  • LibSSH-ESP32/src/libssh/poll.h:42:27: error: conflicting types for 'nfds_t'; have 'long unsigned int'

Notes:

  1. I think the problem with nfds_t is related to the ESP32 definition. I don't properly understand where I need to provide the #define ESP32 because there are two configuration files (libssh_esp32_config.h)
  2. The problem with md_info can be fixed by the next way: *len = (unsigned int)mbedtls_md_get_size(c->MBEDTLS_PRIVATE(md_info));

Request: Test the LibSSH-ESP32 with ESP-IDF 5.1.1

VNovytskyi avatar Sep 21 '23 15:09 VNovytskyi

I tested builds only with ESP-IDF 4.4.5, since that is the version used with the Arduino framework. Let me have the commit id from the official espressif/arduino-esp32.git repository so this can be reproduced.

ewpa avatar Sep 21 '23 20:09 ewpa

I do not use the Arduino framework. I have a project based on the ESP-IDF framework. I downloaded the last version of the ESP-IDF from the official site (5.1.1) and got the last version of LibSSH-ESP32 (3.1.0). You can use my test repository (https://github.com/VNovytskyi/libssh-esp32-idf511-build) to try the build. This repository was created only to test the build process. I'd like to suggest adding the CMakeList.txt file to simplify the building process for non-Arduino projects. In the test project, you can see a lot of warnings/errors. These errors would be good to clean up.

VNovytskyi avatar Sep 22 '23 09:09 VNovytskyi

Awesome, thanks! When building against ESP-IDF v5.1.1 using idf.py all I'm flooded with the below error. What might be different with my build environment?

error: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]

ewpa avatar Sep 23 '23 09:09 ewpa

It is the first error that would be great to fix. It is an error that occurs in a lot of source files in LibSSH-ESP32. This error appeared because the ESP-IDF 5.1.1 started using the GCC 12.2.0, instead of the old GCC 8.4.0. You can read more information about this at https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/release-5.x/5.0/index.html and https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/release-5.x/5.1/index.html.

I propose the following solution to this problem:

set_source_files_properties(
  ../libs/LibSSH-ESP32/src/auth.c
  ../libs/LibSSH-ESP32/src/agent.c
  ../libs/LibSSH-ESP32/src/dh-gex.c
  ../libs/LibSSH-ESP32/src/channels.c
  
  PROPERTIES
    COMPILE_FLAGS -Wno-format
)

If we are using this solution we steel with backward compatibility (as I think, it needs to be tested). Another way to fix this problem is to replace the %u with %ul (the GCC 11 compiler must help you with hints about errors). In the case of this fix, case may be problems with backward compabilities in the future.

The next error is missing the MBEDTLS_PRIVATE macro in some cases and changing the call of some Mbed TLS functions. This error occurs because the ESP-IDF 5.1.1 updates the version of the Mbed TLS library from v2.x to v3.1.0.

It is not a lot of a problem to update the LibSSH-ESP32 for ESP-IDF 5. You can feel free to ask me about some issues when you update the library. I hope the next release of LibSSH-ESP32 will have ESP-IDF 5 support.

VNovytskyi avatar Sep 24 '23 11:09 VNovytskyi

The following patch is applied to src/libssh/poll.h during porting:

-typedef unsigned long int nfds_t;
+#if !defined ESP32 || ESP_IDF_VERSION_MAJOR < 4
+typedef unsigned long int nfds_t;
+#endif /* ESP32 */

Therefore if you set ESP32 that particular issue should be resolved. GCC compilation errors addressed in version 4.0.0+ of this library (not released yet, supports Arduino 3.0.0 but breaks Arduino 1.0.6).

ewpa avatar Oct 22 '23 12:10 ewpa

The following patch is applied to src/libssh/poll.h during porting:

-typedef unsigned long int nfds_t;
+#if !defined ESP32 || ESP_IDF_VERSION_MAJOR < 4
+typedef unsigned long int nfds_t;
+#endif /* ESP32 */

Therefore if you set ESP32 that particular issue should be resolved. GCC compilation errors addressed in version 4.0.0+ of this library (not released yet, supports Arduino 3.0.0 but breaks Arduino 1.0.6).

I'm still getting the same problem after deleting the conditional block and just having it set. long unsigned int in auth.c

SylvianHemus avatar Dec 09 '23 20:12 SylvianHemus

Fixed variables for recent GCC version, see:

https://github.com/SylvianHemus/LibSSH-ESP32/commit/84a7589ed7d6ff8776856c1e87ed10c145781e09

will make pull request. Need to fix the mbedtls_md_context issue. Espressif provides the following guide I'll follow https://github.com/espressif/mbedtls/blob/9bb5effc3298265f829878825d9bd38478e67514/docs/3.0-migration-guide.md

SylvianHemus avatar Dec 09 '23 21:12 SylvianHemus

Created pull request, compiles now but mostly untested https://github.com/ewpa/LibSSH-ESP32/pull/30

SylvianHemus avatar Dec 09 '23 23:12 SylvianHemus

Created pull request, compiles now but mostly untested

The limitation of PRs is they do not address the re-porting needs when a new release of upstream libssh is available. I had not pushed the work I had done on this a couple of months ago. Now pushed, hence please refer to release 4.0.1 in new branch preview-arduino-esp32-3.0.0 commit 1a11d61 and advise.

ewpa avatar Dec 10 '23 12:12 ewpa

Created pull request, compiles now but mostly untested

The limitation of PRs is they do not address the re-porting needs when a new release of upstream libssh is available. I had not pushed the work I had done on this a couple of months ago. Now pushed, hence please refer to release 4.0.1 in new branch preview-arduino-esp32-3.0.0 commit 1a11d61 and advise.

Oh nice thanks, I'll try this and report back

SylvianHemus avatar Dec 11 '23 08:12 SylvianHemus

Created pull request, compiles now but mostly untested

The limitation of PRs is they do not address the re-porting needs when a new release of upstream libssh is available. I had not pushed the work I had done on this a couple of months ago. Now pushed, hence please refer to release 4.0.1 in new branch preview-arduino-esp32-3.0.0 commit 1a11d61 and advise.

I tested, I get returned mbedtls_md_context_t has no member md_info on branch preview-arduino-esp32-3.0.0. Since the update you can't access it with that function any longer I think, a lot of properties are now private. Have to use something like *len = (unsigned int)mbedtls_md_get_size(mbedtls_md_info_from_ctx(c)); see https://github.com/ewpa/LibSSH-ESP32/pull/30/commits/bdf54294c214989265885adf3a4334600abd9bd7 , https://github.com/ewpa/LibSSH-ESP32/pull/30/commits/2f0cca5c0815824d081285971bb4672f57cbedc5

SylvianHemus avatar Dec 15 '23 01:12 SylvianHemus

I tested, I get returned mbedtls_md_context_t has no member md_info on branch preview-arduino-esp32-3.0.0. Since the update you can't access it with that function any longer I think, a lot of properties are now private. Have to use something like *len = (unsigned int)mbedtls_md_get_size(mbedtls_md_info_from_ctx(c)); see bdf5429 , 2f0cca5

Looking at this line of code, it comes from upstream. The best way to approach a fix is to get and apply a patch for libssh to use the newer mbedtls 3.1 (currently max 3.0 supported for 0.10 stable). However in any case, code for both versions of mbedtls will need to remain in order to support IDF 4.4 and 5 for Arduino.

ewpa avatar Dec 24 '23 13:12 ewpa

Hi, Just to point out that ESP32-Arduino core version 3 has been released with ESP-IDF 5.1.4 behind it. This causes the following error (same as above) using Arduino IDE: LibSSH-ESP32/src/libmbedcrypto.c:196:47: error: 'mbedtls_md_context_t' has no member named 'md_info'

iodeo avatar Jun 17 '24 10:06 iodeo

Acknowledged. I do not think fixing the compilation error is enough since I'd also expect further errors in regards to the new version of mbedtls in IDF 5. I believe support for the new mbedtls version is being added into the libssh master branch now, so maybe a re-port will be the solution (just for core 3.0.1+).

ewpa avatar Jun 18 '24 20:06 ewpa

re-port will be the solution

I have pushed a preview release, branch preview-arduino-esp32-3.0.0 commit 917fc3dfa19f9fcbac36a41ffa6175e524c13fc0 for you to test. I ran only basic tests and found no issues under 2.0.17 or 3.0.1. Let me know how you get on.

ewpa avatar Jun 23 '24 08:06 ewpa