Skip to content

Commit

Permalink
Improve Espressif make and cmake for ESP8266 and ESP32 series
Browse files Browse the repository at this point in the history
  • Loading branch information
gojimmypi committed Jan 31, 2025
1 parent eb7bac3 commit 985eb8b
Show file tree
Hide file tree
Showing 56 changed files with 1,069 additions and 282 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,16 @@ user_settings_asm.h
# ESP8266 RTOS SDK has a slightly different sdkconfig filename to exclude:
/IDE/Espressif/**/sdkconfig.debug
/IDE/Espressif/**/sdkconfig.release
/IDE/Espressif/**/sdkconfig-debug
/IDE/Espressif/**/sdkconfig-release

# Always include Espressif makefiles (typically only used for ESP8266)
!/IDE/Espressif/**/Makefile
!/IDE/Espressif/**/component.mk

# Ignore all the example logs
/IDE/Espressif/ESP-IDF/examples/**/logs/*

# MPLAB
/IDE/MPLABX16/wolfssl.X/dist/default/
/IDE/MPLABX16/wolfssl.X/.generated_files
Expand Down
12 changes: 9 additions & 3 deletions IDE/Espressif/ESP-IDF/examples/template/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ message(STATUS "Begin project ${CMAKE_PROJECT_NAME}")
cmake_minimum_required(VERSION 3.16)

# Optional no watchdog typically used for test & benchmark
add_compile_definitions(WOLFSSL_ESP_NO_WATCHDOG=1)
if (idf_target STREQUAL "esp8266" OR IDF_TARGET STREQUAL "esp8266" OR IDF_VERSION_MAJOR VERSION_LESS "5.0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_ESP_NO_WATCHDOG=1")
else()
add_compile_definitions(WOLFSSL_ESP_NO_WATCHDOG=1)
endif()


# The wolfSSL CMake file should be able to find the source code.
# Otherwise, assign an environment variable or set it here:
Expand Down Expand Up @@ -123,8 +128,8 @@ endif()
# Not only is a project-level "set(COMPONENTS" not needed here, this will cause
# an unintuitive error about Unknown CMake command "esptool_py_flash_project_args".

message(STATUS "begin optional PROTOCOL_EXAMPLES_DIR include")
if(0)
message(STATUS "Begin optional PROTOCOL_EXAMPLES_DIR include")
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
set (PROTOCOL_EXAMPLES_DIR $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)

Expand All @@ -135,9 +140,10 @@ if(0)
else()
message(STATUS "NOT FOUND: PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
endif()
message(STATUS "End optional PROTOCOL_EXAMPLES_DIR include")
endif()

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
message(STATUS "end optional include")

project(wolfssl_template)
message(STATUS "end project")
14 changes: 14 additions & 0 deletions IDE/Espressif/ESP-IDF/examples/template/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

CFLAGS += -DWOLFSSL_USER_SETTINGS

# Some of the tests are CPU intenstive, so we'll force the watchdog timer off.
# There's an espressif NO_WATCHDOG; we don't use it, as it is reset by sdkconfig.
CFLAGS += -DWOLFSSL_ESP_NO_WATCHDOG=1

PROJECT_NAME := wolfssl_template

include $(IDF_PATH)/make/project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -408,17 +408,22 @@ endif()

if ( ("${CONFIG_TARGET_PLATFORM}" STREQUAL "esp8266") OR ("${IDF_TARGET}" STREQUAL "esp8266") )
# There's no esp_timer, no driver components for the ESP8266
message(STATUS "Early expansion EXCLUDES esp_timer for esp8266: ${THIS_INCLUDE_TIMER}")
message(STATUS "Early expansion EXCLUDES driver for esp8266: ${THIS_INCLUDE_DRIVER}")
set(THIS_INCLUDE_TIMER "")
set(THIS_INCLUDE_DRIVER "")
set(THIS_ESP_TLS "")
message(STATUS "Early expansion EXCLUDES for esp8266:")
message(STATUS "THIS_INCLUDE_DRIVER: '${THIS_INCLUDE_DRIVER}'")
message(STATUS "THIS_INCLUDE_TIMER: '${THIS_INCLUDE_TIMER}'")
message(STATUS "Early expansion INCLUDE for esp8266:")
message(STATUS "THIS_INCLUDE_PTHREAD: '${THIS_INCLUDE_PTHREAD}'")
set(THIS_ESP_TLS "")
set(THIS_INCLUDE_DRIVER "")
set(THIS_INCLUDE_TIMER "")
set(THIS_INCLUDE_PTHREAD "pthread")
else()
message(STATUS "Early expansion includes esp_timer: ${THIS_INCLUDE_TIMER}")
message(STATUS "Early expansion includes driver: ${THIS_INCLUDE_DRIVER}")
set(THIS_INCLUDE_TIMER "esp_timer")
set(THIS_ESP_TLS "esp-tls")
set(THIS_INCLUDE_DRIVER "driver")
set(THIS_ESP_TLS "esp-tls")
set(THIS_INCLUDE_TIMER "esp_timer")
set(THIS_INCLUDE_PTHREAD "")
# Let the app know that we've included the esp-tls component requirement.
# This is critical for use the the esp-tls component. See wolfssl esp_crt_bundle.c file.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_REQUIRED_ESP_TLS=1")
Expand All @@ -430,6 +435,7 @@ if(CMAKE_BUILD_EARLY_EXPANSION)
REQUIRES "${COMPONENT_REQUIRES}"
PRIV_REQUIRES # esp_hw_support
"${THIS_ESP_TLS}"
"${THIS_INCLUDE_PTHREAD}"
"${THIS_INCLUDE_TIMER}"
"${THIS_INCLUDE_DRIVER}" # this will typically only be needed for wolfSSL benchmark
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ CFLAGS +=-DWOLFSSL_USER_SETTINGS
# https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF/examples
# When this wolfssl component.mk makefile is in [project]/components/wolfssl
# The root is 7 directories up from here (the location of of this component.mk):
WOLFSSL_ROOT := ../../../../../../..
#
WOLFSSL_ROOT ?= ../../../../../../..
THIS_DIR := $(shell pwd)
WOLFSSL_ROOT_OBJ := $(THIS_DIR)

# When running make from commandline or VisualGDB, the current path varies:
ifeq ("$(VISUALGDB_DIR)","")
# current path is typically /mnt/c/workspace/wolfssl-gojimmypi/IDE/Espressif/ESP-IDF/examples/wolfssl_test/build/wolfssl
$(info VISUALGDB_DIR build not detected. shell: $(shell echo $$SHELL))
else
# current path is typically /C/workspace/wolfssl-gojimmypi/IDE/Espressif/ESP-IDF/examples/wolfssl_test/build/Debug/wolfssl
$(info Detected VisualGDB in: $(VISUALGDB_DIR) shell: $(shell echo $$SHELL))
endif

# To set the location of a different location, it is best to use relative paths.
#
Expand All @@ -92,14 +104,16 @@ WOLFSSL_ROOT := ../../../../../../..
# CFLAGS += -I$(WOLFSSL_ROOT)/wolfssl/wolfcrypt
# CFLAGS += -I$(WOLFSSL_ROOT)/wolfssl/wolfcrypt/port/Espressif

abs_WOLFSSL_ROOT := $(shell realpath $(WOLFSSL_ROOT))
abs_WOLFSSL_ROOT := $(shell realpath $(WOLFSSL_ROOT))

# print-wolfssl-path-value:
# @echo "WOLFSSL_ROOT defined: $(WOLFSSL_ROOT)"
# @echo "WOLFSSL_ROOT actual: $(abs_WOLFSSL_ROOT)"

$(info WOLFSSL_ROOT defined: $(WOLFSSL_ROOT))
$(info WOLFSSL_ROOT actual: $(abs_WOLFSSL_ROOT))
$(info WOLFSSL_ROOT defined: $(WOLFSSL_ROOT))
$(info WOLFSSL_ROOT actual: $(abs_WOLFSSL_ROOT))
$(info THIS_DIR defined: $(THIS_DIR))
$(info WOLFSSL_ROOT_OBJ defined: $(WOLFSSL_ROOT_OBJ))

# NOTE: The wolfSSL include directory (e.g. user_settings.h) is
# located HERE in THIS project, and *not* in the wolfSSL root.
Expand All @@ -109,6 +123,7 @@ COMPONENT_ADD_INCLUDEDIRS += $(WOLFSSL_ROOT)/.
COMPONENT_ADD_INCLUDEDIRS += $(WOLFSSL_ROOT)/wolfssl
COMPONENT_ADD_INCLUDEDIRS += $(WOLFSSL_ROOT)/wolfssl/wolfcrypt
COMPONENT_ADD_INCLUDEDIRS += $(WOLFSSL_ROOT)/wolfssl/wolfcrypt/port/Espressif

# COMPONENT_ADD_INCLUDEDIRS += $ENV(IDF_PATH)/components/freertos/include/freertos
# COMPONENT_ADD_INCLUDEDIRS += "$ENV(IDF_PATH)/soc/esp32s3/include/soc"

Expand All @@ -122,27 +137,27 @@ COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/src
COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/src/port/Espressif
COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/src/port/atmel

COMPONENT_OBJEXCLUDE := $(WOLFSSL_ROOT)/wolfcrypt/src/aes_asm.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT)/wolfcrypt/src/evp.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT)/wolfcrypt/src/misc.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT)/wolfcrypt/src/sha512_asm.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT)/wolfcrypt/src/fe_x25519_asm.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT)/wolfcrypt/src/aes_gcm_x86_asm.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT)/src/bio.o

COMPONENT_OBJEXCLUDE := $(WOLFSSL_ROOT_OBJ)/wolfcrypt/src/aes_asm.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT_OBJ)/wolfcrypt/src/evp.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT_OBJ)/wolfcrypt/src/misc.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT_OBJ)/wolfcrypt/src/sha512_asm.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT_OBJ)/wolfcrypt/src/fe_x25519_asm.o
COMPONENT_OBJEXCLUDE += $(WOLFSSL_ROOT_OBJ)/wolfcrypt/src/aes_gcm_x86_asm.o

##
## wolfSSL
##
COMPONENT_OBJS := $(WOLFSSL_ROOT)/src/bio.o
# COMPONENT_OBJS += src/conf.o
## reminder object files may end up in `./build` or `build/debug` or `build/release`, depending on build environment & settings.
##
# COMPONENT_OBJS := $(WOLFSSL_ROOT)/src/bio.o # part of ssl.c, omitted to avoid "does not need to be compiled separately"
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/conf.o # part of ssl.c
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/crl.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/dtls.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/dtls13.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/internal.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/keys.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/ocsp.o
# COMPONENT_OBJS += src/pk.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/pk.o # part of ssl.c
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/quic.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/sniffer.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/ssl.o
Expand All @@ -154,8 +169,8 @@ COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/ssl.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/tls.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/tls13.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/wolfio.o
# COMPONENT_OBJS += src/x509.o
# COMPONENT_OBJS += src/x509_str.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/x509.o # part of ssl.c
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/src/x509_str.o # part of ssl.c

##
## wolfcrypt
Expand Down Expand Up @@ -276,21 +291,16 @@ COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/port/Espressif/esp_sdk_wifi_lib.
##
## wolfcrypt benchmark (optional)
##
## COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/benchmark/benchmark.o
## COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/benchmark
## COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/benchmark/benchmark.o
## COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/benchmark
## COMPONENT_ADD_INCLUDEDIRS += $(WOLFSSL_ROOT)/wolfcrypt/benchmark


##
## wolfcrypt test (optional)
##
## COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/test/test.o
## COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/test

##
## wolfcrypt
##
## COMPONENT_PRIV_INCLUDEDIRS += $(PROJECT_PATH)/components/wolfssl/include
## COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/src
## COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/test/test.o
## COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/test
## COMPONENT_ADD_INCLUDEDIRS += $(WOLFSSL_ROOT)/wolfcrypt/test/include

$(info ********** end wolfssl component **********)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
#define WOLFSSL_ESPIDF_COMPONENT_VERSION 0x01

/* Examples such as test and benchmark are known to cause watchdog timeouts.
* Note this is often set in project Makefile:
* CFLAGS += -DWOLFSSL_ESP_NO_WATCHDOG=1 */
#define WOLFSSL_ESP_NO_WATCHDOG 1

/* The Espressif project config file. See also sdkconfig.defaults */
#include "sdkconfig.h"

Expand Down Expand Up @@ -219,6 +224,17 @@
#endif
#endif

/* Enable AES for all examples */
#ifdef NO_AES
#warning "Found NO_AES, wolfSSL AES Cannot be enabled. Check config."
#else
#define WOLFSSL_AES
#define WOLFSSL_AES_COUNTER

/* Typically only needed for wolfssl_test, see docs. */
#define WOLFSSL_AES_DIRECT
#endif

/* Pick a cert buffer size: */
/* #define USE_CERT_BUFFERS_2048 */
/* #define USE_CERT_BUFFERS_1024 */
Expand Down
13 changes: 11 additions & 2 deletions IDE/Espressif/ESP-IDF/examples/template/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# wolfSSL Espressif Example Project/main CMakeLists.txt
# v1.1
# v1.2
#
# wolfssl template
#
message(STATUS "Begin wolfSSL main CMakeLists.txt")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")

if (idf_target STREQUAL "esp8266" OR IDF_TARGET STREQUAL "esp8266" OR IDF_VERSION_MAJOR VERSION_LESS "5.0")
# `driver` component not available for ESP8266
SET(THIS_PRIV_REQUIRES_DRIVER "")
else()
SET(THIS_PRIV_REQUIRES_DRIVER "driver")
endif()

if(WIN32)
# Windows-specific configuration here
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
Expand Down Expand Up @@ -57,7 +64,9 @@ endif()
idf_component_register(SRCS main.c
INCLUDE_DIRS "."
"./include"
PRIV_REQUIRES driver "${MAIN_WOLFSSL_COMPONENT_NAME}")
PRIV_REQUIRES "${THIS_PRIV_REQUIRES_DRIVER}"
"${MAIN_WOLFSSL_COMPONENT_NAME}"
)

#
# LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
Expand Down
23 changes: 23 additions & 0 deletions IDE/Espressif/ESP-IDF/examples/template/main/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Main component makefile.
#
# This Makefile can be left empty. By default, it will take the sources in the
# src/ directory, compile them and link them into lib(subdirectory_name).a
# in the build directory. This behavior is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#
# (Uses default behavior of compiling all source files in directory, adding 'include' to include path.)

# We'll add the explicit lines only for old SDK requirements (e.h. ESP8266)

ifeq ("$(VISUALGDB_DIR)","")
$(info VISUALGDB_DIR build not detected. shell: $(shell echo $$SHELL) )
else
$(info Detected VisualGDB in: $(VISUALGDB_DIR) shell: $(shell echo $$SHELL) )
COMPONENT_SRCDIRS := .
COMPONENT_ADD_INCLUDEDIRS := .
COMPONENT_ADD_INCLUDEDIRS += include

# Ensure main.c gets compiled
COMPONENT_OBJS := main.o
endif
2 changes: 2 additions & 0 deletions IDE/Espressif/ESP-IDF/examples/template/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Set the known example app config to template example (see user_settings.h)
CONFIG_WOLFSSL_EXAMPLE_NAME_TEMPLATE=y

# CONFIG_EXAMPLE_WIFI_SSID="myssid"
# CONFIG_EXAMPLE_WIFI_PASSWORD="mypassword"

Expand All @@ -23,6 +24,7 @@ CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
# When using RSA, assign at least 10500 bytes, otherwise 5500 usually works for others
# We set this to 28672 for use in the "test everything possible" in the wolfssl_test app.
CONFIG_ESP_MAIN_TASK_STACK_SIZE=10500

# Legacy stack size name for older ESP-IDF versions
CONFIG_MAIN_TASK_STACK_SIZE=10500

Expand Down
Loading

0 comments on commit 985eb8b

Please sign in to comment.