From ce6335f2e286fa63fef096d803d90936ca31ec37 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Wed, 31 Aug 2022 20:47:34 +0530 Subject: [PATCH] [ESP32] cmake option to set software version and software version string (#22229) * [ESP32] cmake option to set software version and software version string ESP-IDF lets user set software version string by two ways: Project's CMakeLists.txt file or configuration option. It depends on CONFIG_APP_PROJECT_VER_FROM_CONFIG option so making the same provision for software version number. Also, Reading the software version string from the app description which is set using any one of above method. Setting the default software version as per spec i.e. 0. Setting PROJECT_VER and PROJECT_VER_NUMBER in all the examples * Fix the QEMU tests * Set software version to 0 if not set using cmake or config option * Override GetSoftwareVersion in configuration manager --- config/esp32/components/chip/CMakeLists.txt | 12 ++++++++++++ config/esp32/components/chip/Kconfig | 8 +------- examples/all-clusters-app/esp32/CMakeLists.txt | 4 ++++ .../esp32/CMakeLists.txt | 4 ++++ examples/bridge-app/esp32/CMakeLists.txt | 4 ++++ examples/chef/esp32/CMakeLists.txt | 3 +++ examples/light-switch-app/esp32/CMakeLists.txt | 4 ++++ examples/lighting-app/esp32/CMakeLists.txt | 4 ++++ examples/lock-app/esp32/CMakeLists.txt | 4 ++++ examples/ota-provider-app/esp32/CMakeLists.txt | 3 +++ examples/ota-requestor-app/esp32/CMakeLists.txt | 3 +++ .../persistent-storage/esp32/CMakeLists.txt | 4 ++++ examples/pigweed-app/esp32/CMakeLists.txt | 4 ++++ examples/shell/esp32/CMakeLists.txt | 4 ++++ .../esp32/CMakeLists.txt | 3 +++ src/platform/ESP32/BUILD.gn | 5 +++++ src/platform/ESP32/CHIPDevicePlatformConfig.h | 3 +-- src/platform/ESP32/ConfigurationManagerImpl.cpp | 17 +++++++++++++++++ src/platform/ESP32/ConfigurationManagerImpl.h | 2 ++ src/test_driver/esp32/CMakeLists.txt | 4 ++++ 20 files changed, 90 insertions(+), 9 deletions(-) diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index 74b79dffc93466..707d23784bc350 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -67,6 +67,18 @@ macro(chip_gn_arg_bool arg boolean) endif() endmacro() +# ESP-IDF lets user set software version string by two ways: +# 1. Project's CMakeLists.txt file and 2. Config option +# It depends on CONFIG_APP_PROJECT_VER_FROM_CONFIG option +# So, below makes the same provision for software version number +if (CONFIG_APP_PROJECT_VER_FROM_CONFIG) + chip_gn_arg_append("chip_config_software_version_number" ${CONFIG_DEVICE_SOFTWARE_VERSION_NUMBER}) +elseif (DEFINED PROJECT_VER_NUMBER) + chip_gn_arg_append("chip_config_software_version_number" ${PROJECT_VER_NUMBER}) +else() + chip_gn_arg_append("chip_config_software_version_number" 0) +endif() + chip_gn_arg_append("esp32_ar" "\"${CMAKE_AR}\"") chip_gn_arg_append("esp32_cc" "\"${CMAKE_C_COMPILER}\"") chip_gn_arg_append("esp32_cxx" "\"${CMAKE_CXX_COMPILER}\"") diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index 55cafa1c8a07a8..402d9ad64fe7fc 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -301,15 +301,9 @@ menu "CHIP Device Layer" This is a default value which is used when a hardware version has not been stored in device persistent storage (e.g. by a factory provisioning process). - config DEVICE_SOFTWARE_VERSION - string "Device Software Version String" - default "v1.0" - help - A string identifying the software version running on the device. - config DEVICE_SOFTWARE_VERSION_NUMBER int "Device Software Version Number" - default 1 + default 0 help Software version number running on the device. diff --git a/examples/all-clusters-app/esp32/CMakeLists.txt b/examples/all-clusters-app/esp32/CMakeLists.txt index de70f669cd1836..fad386531fb057 100644 --- a/examples/all-clusters-app/esp32/CMakeLists.txt +++ b/examples/all-clusters-app/esp32/CMakeLists.txt @@ -17,6 +17,10 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/all-clusters-minimal-app/esp32/CMakeLists.txt b/examples/all-clusters-minimal-app/esp32/CMakeLists.txt index ca7bbb5b25c0f9..a1d45e27a1df70 100644 --- a/examples/all-clusters-minimal-app/esp32/CMakeLists.txt +++ b/examples/all-clusters-minimal-app/esp32/CMakeLists.txt @@ -17,6 +17,10 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/bridge-app/esp32/CMakeLists.txt b/examples/bridge-app/esp32/CMakeLists.txt index 9ab16ea66bc35e..1e7c544310462c 100644 --- a/examples/bridge-app/esp32/CMakeLists.txt +++ b/examples/bridge-app/esp32/CMakeLists.txt @@ -15,6 +15,10 @@ # limitations under the License. cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/chef/esp32/CMakeLists.txt b/examples/chef/esp32/CMakeLists.txt index 683e111720f61f..1bb4915047133b 100644 --- a/examples/chef/esp32/CMakeLists.txt +++ b/examples/chef/esp32/CMakeLists.txt @@ -18,6 +18,9 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake) diff --git a/examples/light-switch-app/esp32/CMakeLists.txt b/examples/light-switch-app/esp32/CMakeLists.txt index 2fff0f04eea418..bf879bedfbbe1c 100644 --- a/examples/light-switch-app/esp32/CMakeLists.txt +++ b/examples/light-switch-app/esp32/CMakeLists.txt @@ -17,6 +17,10 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake) diff --git a/examples/lighting-app/esp32/CMakeLists.txt b/examples/lighting-app/esp32/CMakeLists.txt index 06359e838141bc..30d1000b51b198 100644 --- a/examples/lighting-app/esp32/CMakeLists.txt +++ b/examples/lighting-app/esp32/CMakeLists.txt @@ -17,6 +17,10 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/lock-app/esp32/CMakeLists.txt b/examples/lock-app/esp32/CMakeLists.txt index 13cc58a23025f3..0c557571f36513 100644 --- a/examples/lock-app/esp32/CMakeLists.txt +++ b/examples/lock-app/esp32/CMakeLists.txt @@ -17,6 +17,10 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/ota-provider-app/esp32/CMakeLists.txt b/examples/ota-provider-app/esp32/CMakeLists.txt index 16e469b44e2954..d9abb2fe27f3d3 100644 --- a/examples/ota-provider-app/esp32/CMakeLists.txt +++ b/examples/ota-provider-app/esp32/CMakeLists.txt @@ -18,6 +18,9 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/ota-requestor-app/esp32/CMakeLists.txt b/examples/ota-requestor-app/esp32/CMakeLists.txt index 7eccf3fdc0fb42..ca79dd4561b1aa 100644 --- a/examples/ota-requestor-app/esp32/CMakeLists.txt +++ b/examples/ota-requestor-app/esp32/CMakeLists.txt @@ -18,6 +18,9 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) +set(PROJECT_VER "v2.0") +set(PROJECT_VER_NUMBER 2) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/persistent-storage/esp32/CMakeLists.txt b/examples/persistent-storage/esp32/CMakeLists.txt index 946a07627d85ac..372d88c2729db1 100644 --- a/examples/persistent-storage/esp32/CMakeLists.txt +++ b/examples/persistent-storage/esp32/CMakeLists.txt @@ -16,6 +16,10 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/pigweed-app/esp32/CMakeLists.txt b/examples/pigweed-app/esp32/CMakeLists.txt index 1e04ace6022501..fd8c1787569120 100644 --- a/examples/pigweed-app/esp32/CMakeLists.txt +++ b/examples/pigweed-app/esp32/CMakeLists.txt @@ -17,6 +17,10 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/shell/esp32/CMakeLists.txt b/examples/shell/esp32/CMakeLists.txt index 36e26b691a7b4a..1b1c919acef6ee 100644 --- a/examples/shell/esp32/CMakeLists.txt +++ b/examples/shell/esp32/CMakeLists.txt @@ -17,6 +17,10 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake) diff --git a/examples/temperature-measurement-app/esp32/CMakeLists.txt b/examples/temperature-measurement-app/esp32/CMakeLists.txt index 57a4caddb4cb68..dd7332f9661b2d 100644 --- a/examples/temperature-measurement-app/esp32/CMakeLists.txt +++ b/examples/temperature-measurement-app/esp32/CMakeLists.txt @@ -18,6 +18,9 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + set(is_debug true CACHE BOOL "Optimization variable") if(NOT is_debug) set(SDKCONFIG_DEFAULTS "sdkconfig.optimize.defaults") diff --git a/src/platform/ESP32/BUILD.gn b/src/platform/ESP32/BUILD.gn index 7af8b309033771..1100de4948e5ed 100644 --- a/src/platform/ESP32/BUILD.gn +++ b/src/platform/ESP32/BUILD.gn @@ -23,8 +23,13 @@ declare_args() { # DeviceAttestationCredentialsProvider and DeviceInstanceInforProvider chip_use_factory_data_provider = false chip_use_device_info_provider = false + chip_config_software_version_number = 0 } +defines = [ + "CHIP_CONFIG_SOFTWARE_VERSION_NUMBER=${chip_config_software_version_number}", +] + static_library("ESP32") { sources = [ "../SingletonConfigurationManager.cpp", diff --git a/src/platform/ESP32/CHIPDevicePlatformConfig.h b/src/platform/ESP32/CHIPDevicePlatformConfig.h index c40cd8c565e11d..d2777360ee3922 100644 --- a/src/platform/ESP32/CHIPDevicePlatformConfig.h +++ b/src/platform/ESP32/CHIPDevicePlatformConfig.h @@ -44,8 +44,7 @@ #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID CONFIG_DEVICE_PRODUCT_ID #define CHIP_DEVICE_CONFIG_DEVICE_TYPE CONFIG_DEVICE_TYPE #define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION -#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING CONFIG_DEVICE_SOFTWARE_VERSION -#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION CONFIG_DEVICE_SOFTWARE_VERSION_NUMBER + #endif /* CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID */ #define CHIP_DEVICE_CONFIG_ENABLE_THREAD CONFIG_OPENTHREAD_ENABLED diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 2cf42f7ed141d1..92adb755fb09e3 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -31,6 +31,7 @@ #include #include +#include "esp_ota_ops.h" #include "esp_wifi.h" #include "nvs.h" #include "nvs_flash.h" @@ -204,6 +205,22 @@ CHIP_ERROR ConfigurationManagerImpl::GetProductLabel(char * buf, size_t bufSize) return err; } +CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t bufSize) +{ + memset(buf, 0, bufSize); + const esp_app_desc_t * appDescription = esp_ota_get_app_description(); + ReturnErrorCodeIf(bufSize < sizeof(appDescription->version), CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(sizeof(appDescription->version) > ConfigurationManager::kMaxSoftwareVersionStringLength, CHIP_ERROR_INTERNAL); + strcpy(buf, appDescription->version); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersion(uint32_t & softwareVer) +{ + softwareVer = CHIP_CONFIG_SOFTWARE_VERSION_NUMBER; + return CHIP_NO_ERROR; +} + CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { #if CHIP_DEVICE_CONFIG_ENABLE_WIFI diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index 2eaa5fac60c648..32f4951473349e 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -55,6 +55,8 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override; CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override; CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override; + CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize); + CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override; static ConfigurationManagerImpl & GetDefaultInstance(); private: diff --git a/src/test_driver/esp32/CMakeLists.txt b/src/test_driver/esp32/CMakeLists.txt index 6955354e425482..8f303d7f2a572a 100644 --- a/src/test_driver/esp32/CMakeLists.txt +++ b/src/test_driver/esp32/CMakeLists.txt @@ -17,6 +17,10 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) + +set(PROJECT_VER "v1.0") +set(PROJECT_VER_NUMBER 1) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/esp32_unit_tests.cmake)