Skip to content

Commit

Permalink
Merge pull request #7636 from gojimmypi/PR-ESP8266-Make-Clarification
Browse files Browse the repository at this point in the history
Clarify WOLFSSL_ROOT location for ESP8266 make builds
  • Loading branch information
SparkiDev authored Jul 15, 2024
2 parents 475ec7b + 20e0e12 commit 56b8ac4
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 62 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ user_settings_asm.h
/IDE/Espressif/**/sdkconfig
/IDE/Espressif/**/sdkconfig.old

# ESP8266 RTOS SDK has a slightly different sdkconfig filename to exclude:
/IDE/Espressif/**/sdkconfig.debug
/IDE/Espressif/**/sdkconfig.release

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

# MPLAB
/IDE/MPLABX16/wolfssl.X/dist/default/
/IDE/MPLABX16/wolfssl.X/.generated_files
Expand Down
105 changes: 55 additions & 50 deletions IDE/Espressif/ESP-IDF/examples/wolfssl_client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#
PROJECT_NAME := wolfssl_client

# Optionally include component source when print path (needs work to then properly build)
#
# include components/wolfssl/component.mk

MY_PRIVATE_CONFIG ?= n
USE_MY_PRIVATE_WSL_CONFIG ?= n
USE_MY_PRIVATE_MAC_CONFIG ?= n
Expand All @@ -52,76 +56,76 @@ USE_MY_PRIVATE_WINDOWS_CONFIG ?= n
$(info ************* wolfssl_client *************)

ifeq ($(MY_PRIVATE_CONFIG),y)
CFLAGS += -DMY_PRIVATE_CONFIG
$(info Enabled MY_PRIVATE_CONFIG")
CFLAGS += -DMY_PRIVATE_CONFIG
$(info Enabled MY_PRIVATE_CONFIG")
endif

# Check for Windows environment variable: USE_MY_PRIVATE_WINDOWS_CONFIG
ifeq ($(USE_MY_PRIVATE_WINDOWS_CONFIG),y)
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := /workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_WINDOWS_CONFIG
$(info Using private config file for: Windows)
endif
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := /workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_WINDOWS_CONFIG
$(info Using private config file for: Windows)
endif
endif

# Check for WSL environment variable: USE_MY_PRIVATE_WSL_CONFIG
ifeq ($(USE_MY_PRIVATE_WSL_CONFIG),y)
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := /mnt/c/workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_WSL_CONFIG
$(info Using private config file for: WSL)
endif
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := /mnt/c/workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_WSL_CONFIG
$(info Using private config file for: WSL)
endif
endif

# Check for Linux environment variable: USE_MY_PRIVATE_LINUX_CONFIG
ifeq ($(USE_MY_PRIVATE_LINUX_CONFIG),y)
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := ~/workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_LINUX_CONFIG
$(info Using private config file for: Linux)
endif
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := ~/workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_LINUX_CONFIG
$(info Using private config file for: Linux)
endif
endif

# Check for Mac environment variable: USE_MY_PRIVATE_MAC_CONFIG
ifeq ($(USE_MY_PRIVATE_MAC_CONFIG),y)
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := ~/Documents/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_MAC_CONFIG
$(info Using private config file for: Mac)
endif
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := ~/Documents/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_MAC_CONFIG
$(info Using private config file for: Mac)
endif
endif

ifneq ($(OS),MY_PRIVATE_CONFIG)
CFLAGS += -DMY_PRIVATE_CONFIG="$(MY_PRIVATE_CONFIG)"
CFLAGS += -DMY_PRIVATE_CONFIG="$(MY_PRIVATE_CONFIG)"
else
ifeq ($(OS),Linux)
CFLAGS += -DOS_LINUX
endif
ifeq ($(OS),Windows_NT)
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_WINDOWS
endif
ifeq ($(OS),Darwin)
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_APPLE
endif
ifneq (,$(findstring MINGW,$(OS)))
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_MINGW
endif
ifneq (,$(findstring CYGWIN,$(OS)))
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_CYGWIN
endif
ifeq ($(OS),Linux)
CFLAGS += -DOS_LINUX
endif
ifeq ($(OS),Windows_NT)
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_WINDOWS
endif
ifeq ($(OS),Darwin)
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_APPLE
endif
ifneq (,$(findstring MINGW,$(OS)))
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_MINGW
endif
ifneq (,$(findstring CYGWIN,$(OS)))
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_CYGWIN
endif
endif

# It is essential that the build process sees the WOLFSSL_USER_SETTINGS
Expand All @@ -132,3 +136,4 @@ EXTRA_COMPONENT_DIRS = $(IDF_PATH)/examples/common_components/protocol_examples_

# The Standard Espressif IDF include:
include $(IDF_PATH)/make/project.mk

68 changes: 66 additions & 2 deletions IDE/Espressif/ESP-IDF/examples/wolfssl_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,75 @@ Reminder that we build with `make` and not `cmake` in VisualGDB.

Build files will be created in `[project directory]\build`

## ESP-IDF make Commandline (version 3.5 or earlier for the ESP8266)
See notes below if building a project in a directory other than the examples.

Problems?

- Try deleting any existing `sdkconfig` file and/or `./build` directory to start fresh.
- Be sure the RTOS SDK is installed and properly configured.

## ESP-IDF `make` Commandline (version 3.5 or earlier for the ESP8266)

In-place example build:

```bash
export IDF_PATH=~/esp/ESP8266_RTOS_SDK
export PATH="$PATH:$HOME/esp/xtensa-lx106-elf/bin"
cd /mnt/c/workspace/wolfssl-master/IDE/Espressif/ESP-IDF/examples/wolfssl_client
make clean
make
```

When building a in a *different directory*, for example assuming the `wolfssl_client` in the wolfssl examples
directory is copied to the `C:\test\demo` directory in Windows. (aka ` /mnt/c/test/demo` in WSL),
with a clone of wolfSSL `master` branch in `C:\workspace\wolfssl-master`:

```bash
cp -r /mnt/c/workspace/wolfssl-master/IDE/Espressif/ESP-IDF/examples/wolfssl_client/* /mnt/c/test/demo
```

Modify the project `./components/wolfssl/component.mk` file. Adjust `WOLFSSL_ROOT` setting, in this case to a value of:

`WOLFSSL_ROOT := ../../../../workspace/wolfssl-master`

Ensure the path is *relative* to the project `component.mk` file location and *not* absolute.

Note the location of the component makefile in this case is `c:\test\demo\components\wolfssl\component.mk`.
Thus we need to navigate up 4 parents to the root of `C:\` to find `/mnt/c` in WSL.

Proceed to run `make` from the project directory as usual:

```bash
# setup environment as needed
export IDF_PATH=~/esp/ESP8266_RTOS_SDK
export PATH="$PATH:$HOME/esp/xtensa-lx106-elf/bin"

# copy and navigate to project directory
mkdir -p /mnt/c/test/demo
cp -r /mnt/c/workspace/wolfssl-master/IDE/Espressif/ESP-IDF/examples/wolfssl_client/* /mnt/c/test/demo
cd /mnt/c/test/demo

# Clean
rm -rf ./build
rm sdkconfig
make clean

# Edit ./components/wolfssl/component.mk and set WOLFSSL_ROOT value
# WOLFSSL_ROOT := ../../../../workspace/wolfssl-master

# build the example project
make
```

When using `make` there should be details in the build log to indicate
the assigned path, and the equivalent, fully-qualified path of `WOLFSSL_ROOT`.

```
************* wolfssl_client *************
*********** wolfssl component ************
WOLFSSL_ROOT defined: ../../../../workspace/wolfssl-master
WOLFSSL_ROOT actual: /mnt/c/workspace/wolfssl-master
********** end wolfssl component **********
```


Expand Down Expand Up @@ -158,7 +222,7 @@ Command:

```
cd /mnt/c/workspace/wolfssl-$USER/IDE/Espressif/ESP-IDF/examples/wolfssl_server
. /mnt/c/SysGCC/esp32/esp-idf/v5.1/export.sh
. /mnt/c/SysGCC/esp32/esp-idf/v5.2/export.sh
idf.py flash -p /dev/ttyS19 -b 115200 monitor
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
#

#
$(info *********** wolfssl component ************)

#
# Component Makefile
#
#
Expand Down Expand Up @@ -48,14 +50,57 @@
# define it here:
CFLAGS +=-DWOLFSSL_USER_SETTINGS

# Note that 4 source files created by autogen are excluded here.
#
# See these files commented out, below. Adjust as needed for your application:
#
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/async.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/selftest.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wolfcrypt_first.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wolfcrypt_last.o


# NOTICE: the WOLFSSL_ROOT setting MUST be relative!
# See https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/api-guides/build-system.html?highlight=must+relative#optional-component-specific-variables
# In the wolfSSL GitHub examples for Espressif:
# 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 root is 7 directories up from here (the location of of this component.mk):
WOLFSSL_ROOT := ../../../../../../..

# To set the location of a different location, it is best to use relative paths.
#
# Set WOLFSSL_ROOT to a relative path from the current component directory.
# For example, if the wolfssl_client is copied from the examples to test:
#
# cp -r /IDE/Espressif/ESP-IDF/examples/wolfssl_client/* /mnt/c/test/demo
#
# we run make in /mnt/c/test/demo
# component is in /mnt/c/test/demo/components/wolfssl
# wolfssl is in /mnt/c/workspace/wolfssl-master
#
# "/mnt/c" is 4 directories up:
# 2 for `./test/demo` from where we run `make`, plus
# 2 more from the location of `component.mk` located
# in `[currect directory]/components/wolfssl`.
#
# Thus we need 4 parent reference to find the relative path to wolfSSL:
# WOLFSSL_ROOT := ../../../../workspace/wolfssl-master

# Optional CFLAGS (make works without these; for reference only)
# CFLAGS += -I$(WOLFSSL_ROOT)/wolfssl
# CFLAGS += -I$(WOLFSSL_ROOT)/wolfssl/wolfcrypt
# CFLAGS += -I$(WOLFSSL_ROOT)/wolfssl/wolfcrypt/port/Espressif

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))

# NOTE: The wolfSSL include directory (e.g. user_settings.h) is
# located HERE in THIS project, and *not* in the wolfSSL root.
COMPONENT_ADD_INCLUDEDIRS := .
Expand All @@ -64,7 +109,6 @@ 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 += $(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 Down Expand Up @@ -120,7 +164,7 @@ COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/aes.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/arc4.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/asm.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/asn.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/async.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/async.o # autogen exclusion
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/blake2b.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/blake2s.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/camellia.o
Expand All @@ -144,7 +188,7 @@ COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/ed25519.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/ed448.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/error.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/evp.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)wolfcrypt/src/ext_kyber.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/ext_kyber.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/ext_lms.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/ext_xmss.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/falcon.o
Expand Down Expand Up @@ -176,7 +220,7 @@ COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/rc2.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/ripemd.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/rsa.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/sakke.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/selftest.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/selftest.o # autogen exclusion
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/sha.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/sha256.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/sha3.o
Expand Down Expand Up @@ -213,8 +257,8 @@ COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wc_lms.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wc_pkcs11.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wc_port.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wc_xmss.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wolfcrypt_first.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wolfcrypt_last.o
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wolfcrypt_first.o # autogen exclusion
# COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wolfcrypt_last.o # autogen exclusion
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wolfevent.o
COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/wolfmath.o

Expand Down Expand Up @@ -246,5 +290,7 @@ COMPONENT_OBJS += $(WOLFSSL_ROOT)/wolfcrypt/src/port/Espressif/esp_sdk_wifi_lib.
##
## wolfcrypt
##
# COMPONENT_PRIV_INCLUDEDIRS += $(PROJECT_PATH)/components/wolfssl/include
COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)wolfcrypt/src
## COMPONENT_PRIV_INCLUDEDIRS += $(PROJECT_PATH)/components/wolfssl/include
## COMPONENT_SRCDIRS += $(WOLFSSL_ROOT)/wolfcrypt/src

$(info ********** end wolfssl component **********)

0 comments on commit 56b8ac4

Please sign in to comment.