Skip to content

Commit dcd8931

Browse files
authored
[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
1 parent a880ec3 commit dcd8931

File tree

20 files changed

+90
-9
lines changed

20 files changed

+90
-9
lines changed

config/esp32/components/chip/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ macro(chip_gn_arg_bool arg boolean)
6767
endif()
6868
endmacro()
6969

70+
# ESP-IDF lets user set software version string by two ways:
71+
# 1. Project's CMakeLists.txt file and 2. Config option
72+
# It depends on CONFIG_APP_PROJECT_VER_FROM_CONFIG option
73+
# So, below makes the same provision for software version number
74+
if (CONFIG_APP_PROJECT_VER_FROM_CONFIG)
75+
chip_gn_arg_append("chip_config_software_version_number" ${CONFIG_DEVICE_SOFTWARE_VERSION_NUMBER})
76+
elseif (DEFINED PROJECT_VER_NUMBER)
77+
chip_gn_arg_append("chip_config_software_version_number" ${PROJECT_VER_NUMBER})
78+
else()
79+
chip_gn_arg_append("chip_config_software_version_number" 0)
80+
endif()
81+
7082
chip_gn_arg_append("esp32_ar" "\"${CMAKE_AR}\"")
7183
chip_gn_arg_append("esp32_cc" "\"${CMAKE_C_COMPILER}\"")
7284
chip_gn_arg_append("esp32_cxx" "\"${CMAKE_CXX_COMPILER}\"")

config/esp32/components/chip/Kconfig

+1-7
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,9 @@ menu "CHIP Device Layer"
301301
This is a default value which is used when a hardware version has not been stored in device
302302
persistent storage (e.g. by a factory provisioning process).
303303

304-
config DEVICE_SOFTWARE_VERSION
305-
string "Device Software Version String"
306-
default "v1.0"
307-
help
308-
A string identifying the software version running on the device.
309-
310304
config DEVICE_SOFTWARE_VERSION_NUMBER
311305
int "Device Software Version Number"
312-
default 1
306+
default 0
313307
help
314308
Software version number running on the device.
315309

examples/all-clusters-app/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# The following lines of boilerplate have to be in your project's
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
20+
21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2024
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2125
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2226

examples/all-clusters-minimal-app/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# The following lines of boilerplate have to be in your project's
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
20+
21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2024
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2125
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2226

examples/bridge-app/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# limitations under the License.
1616

1717
cmake_minimum_required(VERSION 3.5)
18+
19+
set(PROJECT_VER "v1.0")
20+
set(PROJECT_VER_NUMBER 1)
21+
1822
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
1923
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2024

examples/chef/esp32/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
2020

21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2124
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2225
include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake)
2326

examples/light-switch-app/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# The following lines of boilerplate have to be in your project's
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
20+
21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2024
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2125
include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake)
2226

examples/lighting-app/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# The following lines of boilerplate have to be in your project's
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
20+
21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2024
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2125
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2226

examples/lock-app/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# The following lines of boilerplate have to be in your project's
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
20+
21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2024
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2125
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2226

examples/ota-provider-app/esp32/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
2020

21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2124
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2225
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2326

examples/ota-requestor-app/esp32/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
2020

21+
set(PROJECT_VER "v2.0")
22+
set(PROJECT_VER_NUMBER 2)
23+
2124
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2225
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2326

examples/persistent-storage/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
# CMakeLists in this exact order for cmake to work correctly
1818
cmake_minimum_required(VERSION 3.5)
19+
20+
set(PROJECT_VER "v1.0")
21+
set(PROJECT_VER_NUMBER 1)
22+
1923
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2024
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2125

examples/pigweed-app/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# The following lines of boilerplate have to be in your project's
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
20+
21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2024
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2125
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2226

examples/shell/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# The following lines of boilerplate have to be in your project's
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
20+
21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2024
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2125
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)
2226

examples/temperature-measurement-app/esp32/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
2020

21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2124
set(is_debug true CACHE BOOL "Optimization variable")
2225
if(NOT is_debug)
2326
set(SDKCONFIG_DEFAULTS "sdkconfig.optimize.defaults")

src/platform/ESP32/BUILD.gn

+5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ declare_args() {
2323
# DeviceAttestationCredentialsProvider and DeviceInstanceInforProvider
2424
chip_use_factory_data_provider = false
2525
chip_use_device_info_provider = false
26+
chip_config_software_version_number = 0
2627
}
2728

29+
defines = [
30+
"CHIP_CONFIG_SOFTWARE_VERSION_NUMBER=${chip_config_software_version_number}",
31+
]
32+
2833
static_library("ESP32") {
2934
sources = [
3035
"../SingletonConfigurationManager.cpp",

src/platform/ESP32/CHIPDevicePlatformConfig.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID CONFIG_DEVICE_PRODUCT_ID
4545
#define CHIP_DEVICE_CONFIG_DEVICE_TYPE CONFIG_DEVICE_TYPE
4646
#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION
47-
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING CONFIG_DEVICE_SOFTWARE_VERSION
48-
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION CONFIG_DEVICE_SOFTWARE_VERSION_NUMBER
47+
4948
#endif /* CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID */
5049

5150
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD CONFIG_OPENTHREAD_ENABLED

src/platform/ESP32/ConfigurationManagerImpl.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <platform/ESP32/ESP32Config.h>
3232
#include <platform/internal/GenericConfigurationManagerImpl.ipp>
3333

34+
#include "esp_ota_ops.h"
3435
#include "esp_wifi.h"
3536
#include "nvs.h"
3637
#include "nvs_flash.h"
@@ -204,6 +205,22 @@ CHIP_ERROR ConfigurationManagerImpl::GetProductLabel(char * buf, size_t bufSize)
204205
return err;
205206
}
206207

208+
CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t bufSize)
209+
{
210+
memset(buf, 0, bufSize);
211+
const esp_app_desc_t * appDescription = esp_ota_get_app_description();
212+
ReturnErrorCodeIf(bufSize < sizeof(appDescription->version), CHIP_ERROR_BUFFER_TOO_SMALL);
213+
ReturnErrorCodeIf(sizeof(appDescription->version) > ConfigurationManager::kMaxSoftwareVersionStringLength, CHIP_ERROR_INTERNAL);
214+
strcpy(buf, appDescription->version);
215+
return CHIP_NO_ERROR;
216+
}
217+
218+
CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersion(uint32_t & softwareVer)
219+
{
220+
softwareVer = CHIP_CONFIG_SOFTWARE_VERSION_NUMBER;
221+
return CHIP_NO_ERROR;
222+
}
223+
207224
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
208225
{
209226
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI

src/platform/ESP32/ConfigurationManagerImpl.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
5555
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
5656
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
5757
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
58+
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize);
59+
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override;
5860
static ConfigurationManagerImpl & GetDefaultInstance();
5961

6062
private:

src/test_driver/esp32/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# The following lines of boilerplate have to be in your project's
1818
# CMakeLists in this exact order for cmake to work correctly
1919
cmake_minimum_required(VERSION 3.5)
20+
21+
set(PROJECT_VER "v1.0")
22+
set(PROJECT_VER_NUMBER 1)
23+
2024
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
2125

2226
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/esp32_unit_tests.cmake)

0 commit comments

Comments
 (0)