Skip to content

Commit

Permalink
[ESP32] cmake option to set software version and software version str…
Browse files Browse the repository at this point in the history
…ing (project-chip#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
  • Loading branch information
shubhamdp authored Aug 31, 2022
1 parent a880ec3 commit dcd8931
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 9 deletions.
12 changes: 12 additions & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}\"")
Expand Down
8 changes: 1 addition & 7 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions examples/all-clusters-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions examples/all-clusters-minimal-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions examples/bridge-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions examples/chef/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions examples/light-switch-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions examples/lighting-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions examples/lock-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions examples/ota-provider-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions examples/ota-requestor-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions examples/persistent-storage/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions examples/pigweed-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions examples/shell/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions examples/temperature-measurement-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/platform/ESP32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <platform/ESP32/ESP32Config.h>
#include <platform/internal/GenericConfigurationManagerImpl.ipp>

#include "esp_ota_ops.h"
#include "esp_wifi.h"
#include "nvs.h"
#include "nvs_flash.h"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/test_driver/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dcd8931

Please sign in to comment.