Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
102 changes: 30 additions & 72 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,42 @@
#
# SPDX-License-Identifier: Apache-2.0

# Helpers
include(${CMAKE_CURRENT_LIST_DIR}/cmake/pouch_target.cmake)

# Platform Specific
if(ESP_PLATFORM)
include(${CMAKE_CURRENT_LIST_DIR}/port/esp_idf/CMakeLists.txt)
# TODO: transitional; this return() will be removed when tree is update to use pure cmake
return()
endif()

if(CONFIG_POUCH)
target_include_directories(pouch PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include)

set(pouch_source_files)

list(APPEND pouch_source_files
src/pouch.c
src/uplink.c
src/header.c
src/buf.c
src/block.c
src/entry.c
src/stream.c
src/downlink.c
)

if (CONFIG_POUCH_ENCRYPTION_NONE)
list(APPEND pouch_source_files src/crypto_none.c)
endif (CONFIG_POUCH_ENCRYPTION_NONE)

if (CONFIG_POUCH_ENCRYPTION_SAEAD)
list(APPEND pouch_source_files
src/crypto_saead.c
src/cert.c
src/saead/session.c
src/saead/uplink.c
src/saead/downlink.c
)
endif (CONFIG_POUCH_ENCRYPTION_SAEAD)

target_sources(pouch PRIVATE ${pouch_source_files})

add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/header_decode.c
${CMAKE_CURRENT_BINARY_DIR}/header_encode.c
COMMAND zcbor code -c ${CMAKE_CURRENT_LIST_DIR}/src/header.cddl -t pouch_header -sde
--include-prefix cddl/ --oc header.c --oh ../include/cddl/header.h
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/include/cddl/header_decode.h
${CMAKE_CURRENT_BINARY_DIR}/include/cddl/header_encode.h
${CMAKE_CURRENT_BINARY_DIR}/include/cddl/header_types.h
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/src/header.cddl)

add_custom_target(pouch_generate_headers DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/header_decode.c
${CMAKE_CURRENT_BINARY_DIR}/header_encode.c)

add_dependencies(pouch pouch_generate_headers)

if (DEFINED CONFIG_POUCH_ENCRYPTION_SAEAD AND NOT DEFINED CONFIG_POUCH_VALIDATE_SERVER_CERT)
message(WARNING " \n"
" ************************************************\n"
" Pouch server certificate validation is disabled.\n"
" Do not use this in production.\n"
" ************************************************")
# ESP-IDF evaluates component CMake in script mode for dependency discovery.
# In that mode, add_subdirectory() is not scriptable, so stop before shared subdirs.
if(CMAKE_SCRIPT_MODE_FILE)
return()
endif()
elseif(Zephyr_DIR)
include(${CMAKE_CURRENT_LIST_DIR}/port/zephyr/CMakeLists.txt)
endif()

if (DEFINED CONFIG_POUCH_ENCRYPTION_SAEAD AND DEFINED CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED)
message(FATAL_ERROR " \n"
" **************************************************\n"
" CONFIG_MBEDTLS_PSA_256M_DRIVER_ENABLED breaks\n"
" support for the secp384r1 curve, which is required\n"
" for Pouch. Disable this option in prj.conf\n"
" **************************************************")
endif()
# Only add additional sources if CONFIG_POUCH is selected
pouch_config_enabled(_pouch_selected CONFIG_POUCH)
if(NOT _pouch_selected)
return()
endif()

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src/transport transport)
# Validate Kconfig settings
pouch_validate_config()

if(NOT DEFINED POUCH_ACTIVE_TARGET)
message(FATAL_ERROR "POUCH_ACTIVE_TARGET must be set by port/<platform>/CMakeLists.txt")
endif()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/golioth_sdk golioth_sdk)
# Assert that the Port set required values
if(NOT DEFINED POUCH_ACTIVE_TARGET)
message(FATAL_ERROR "POUCH_ACTIVE_TARGET must be set by port/<platform>/CMakeLists.txt")
endif()

if(NOT DEFINED POUCH_ACTIVE_GENERATED_DIR)
message(FATAL_ERROR "POUCH_ACTIVE_GENERATED_DIR must be set by port/<platform>/CMakeLists.txt")
endif()

# Core
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src src)

# SDKs
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/golioth_sdk golioth_sdk)
40 changes: 40 additions & 0 deletions cmake/pouch_target.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2026 Golioth, Inc.
#
# SPDX-License-Identifier: Apache-2.0

function(pouch_config_enabled out_var config_name)
if(DEFINED ${config_name})
if(${config_name} OR "${${config_name}}" STREQUAL "y")
set(${out_var} TRUE PARENT_SCOPE)
return()
endif()
endif()

set(${out_var} FALSE PARENT_SCOPE)
endfunction()

function(pouch_validate_config)
pouch_config_enabled(_pouch_encryption_saead CONFIG_POUCH_ENCRYPTION_SAEAD)
if(NOT _pouch_encryption_saead)
return()
endif()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Zephyr we could probably do:

if (NOT CONFIG_POUCH_ENCRYPTION_SAEAD)
    return()
endif()

Isn't that the case for ESP-IDF? I just wonder what value does pouch_config_enabled() bring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I found is that ESP-IDF sets unselected symbols to "" (empty string):

build/config/sdkconfig.cmake
1486:set(CONFIG_POUCH_DELAYABLE_WORK "")

But in Zephyr the symbol is just not present. I added a helper function that differentiates and sets the true/false to deal with the issue.

pouch_config_enabled(_pouch_validate_cert CONFIG_POUCH_VALIDATE_SERVER_CERT)
if(NOT _pouch_validate_cert)
message(WARNING " \n"
" ************************************************\n"
" Pouch server certificate validation is disabled.\n"
" Do not use this in production.\n"
" ************************************************")
endif()

pouch_config_enabled(_pouch_psa_p256m CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED)
if(_pouch_psa_p256m)
message(FATAL_ERROR " \n"
" **************************************************\n"
" CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED breaks\n"
" support for the secp384r1 curve, which is required\n"
" for Pouch. Disable this option in sdkconfig\n"
" **************************************************")
endif()
endfunction()
3 changes: 0 additions & 3 deletions examples/esp_idf/ble_gatt/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ CONFIG_GOLIOTH=y
CONFIG_GOLIOTH_SETTINGS=y
CONFIG_GOLIOTH_OTA=y

# mbedTLS / PSA Crypto
CONFIG_MBEDTLS_PSA_CRYPTO_C=y

# Bluetooth (NimBLE)
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
Expand Down
2 changes: 1 addition & 1 deletion examples/zephyr/coap_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ WiFi by including the extra config file in the `boards` directory.
Build and flash the binary:

```
west build -p -b frdm_rw612 examples/zephyr/coap_client -- -DEXTRA_CONF_FILE=boards/frdm_rw612_wifi.conf
west build -p -b frdm_rw612 --sysbuild examples/zephyr/coap_client -- -DEXTRA_CONF_FILE=boards/frdm_rw612_wifi.conf
west flash
```

Expand Down
5 changes: 1 addition & 4 deletions examples/zephyr/coap_client/boards/frdm_rw612_wifi.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Extra configuration file for using NXP frdm_rw612 with WiFi instead of Ethernet
# To use, add as extra conf file:
# west build -p -b frdm_rw612 <path_to>/examples/zephyr/coap_client -- -DEXTRA_CONF_FILE=boards/frdm_rw612_wifi.conf
# west build -p -b frdm_rw612 --sysbuild <path_to>/examples/zephyr/coap_client -- -DEXTRA_CONF_FILE=boards/frdm_rw612_wifi.conf
#
CONFIG_WIFI=y
CONFIG_WIFI_NXP=y
Expand All @@ -24,9 +24,6 @@ CONFIG_NET_BUF_RX_COUNT=40
CONFIG_NET_BUF_TX_COUNT=40
CONFIG_NET_BUF_DATA_SIZE=1744

# WiFi Connection Callbacks
CONFIG_NET_CONNECTION_MANAGER_CONNECTIVITY_WIFI_MGMT=y

# Handle WiFi Networks with Multiple DNS Servers
CONFIG_DNS_RESOLVER_MAX_SERVERS=3

Expand Down
2 changes: 1 addition & 1 deletion examples/zephyr/http_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ WiFi by including the extra config file in the `boards` directory.
Build and flash the binary:

```
west build -p -b frdm_rw612 examples/zephyr/http_client -- -DEXTRA_CONF_FILE=boards/frdm_rw612_wifi.conf
west build -p -b frdm_rw612 --sysbuild examples/zephyr/http_client -- -DEXTRA_CONF_FILE=boards/frdm_rw612_wifi.conf
west flash
```

Expand Down
3 changes: 0 additions & 3 deletions examples/zephyr/http_client/boards/frdm_rw612_wifi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ CONFIG_NET_BUF_RX_COUNT=40
CONFIG_NET_BUF_TX_COUNT=40
CONFIG_NET_BUF_DATA_SIZE=1744

# WiFi Connection Callbacks
CONFIG_NET_CONNECTION_MANAGER_CONNECTIVITY_WIFI_MGMT=y

# Handle WiFi Networks with Multiple DNS Servers
CONFIG_DNS_RESOLVER_MAX_SERVERS=3

Expand Down
Loading