diff --git a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn index 97ca8d972051a4..9b5fd07f4b6893 100644 --- a/examples/all-clusters-app/cc13x4_26x4/BUILD.gn +++ b/examples/all-clusters-app/cc13x4_26x4/BUILD.gn @@ -37,7 +37,6 @@ ti_sysconfig("sysconfig") { sources = [ "${project_dir}/chip.syscfg" ] outputs = [ - "ti_devices_config.c", "ti_radio_config.c", "ti_radio_config.h", "ti_drivers_config.c", @@ -47,6 +46,10 @@ ti_sysconfig("sysconfig") { "ti_dmm_application_policy.c", "ti_dmm_application_policy.h", + # CCFG generation disabled for OTA-able application + #"ti_devices_config.c", + #"ti_devices_config.h", + # disabled until upstream generation is aligned #"tiop_config.h", #"tiop_config.c", diff --git a/examples/all-clusters-app/cc13x4_26x4/README.md b/examples/all-clusters-app/cc13x4_26x4/README.md index ad8581b52cf26c..f5a355f249c8aa 100644 --- a/examples/all-clusters-app/cc13x4_26x4/README.md +++ b/examples/all-clusters-app/cc13x4_26x4/README.md @@ -164,8 +164,8 @@ the session. Select the ELF image to load on the device with the `Browse` button. This file is placed in the `out/debug` folder by this guide and ends with the `*.out` file extension. For OTA enabled applications, the standalone image will instead end -with the `*-bim.hex` file extension. This this is a combined image with -application and and `BIM` included. The flag to enable or disable the OTA +with the `*-mcuboot.hex` file extension. This this is a combined image with +application and `MCUBoot` included. The flag to enable or disable the OTA feature is determined by "chip_enable_ota_requestor" in the application's args.gni file. diff --git a/examples/all-clusters-app/cc13x4_26x4/args.gni b/examples/all-clusters-app/cc13x4_26x4/args.gni index 5d97a9ca72d768..7c2e2acc9ae809 100644 --- a/examples/all-clusters-app/cc13x4_26x4/args.gni +++ b/examples/all-clusters-app/cc13x4_26x4/args.gni @@ -27,7 +27,7 @@ ti_simplelink_board = "LP_EM_CC1354P10_6" optimize_debug_level = "s" lwip_debug = false -chip_enable_ota_requestor = false +chip_enable_ota_requestor = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x4_26x4:libopenthread-cc13x4_cc26x4" chip_openthread_ftd = true @@ -49,4 +49,4 @@ chip_stack_lock_tracking = "none" matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" -matter_software_ver_str = "1.0d1" +matter_software_ver_str = "1.0.1+1" diff --git a/examples/all-clusters-app/cc13x4_26x4/chip.syscfg b/examples/all-clusters-app/cc13x4_26x4/chip.syscfg index e9cb55c3e22f07..0257d3ed152e5e 100644 --- a/examples/all-clusters-app/cc13x4_26x4/chip.syscfg +++ b/examples/all-clusters-app/cc13x4_26x4/chip.syscfg @@ -83,7 +83,8 @@ for(var setting in ccfgSettings) CCFG[setting] = ccfgSettings[setting]; } -CCFG.enableCodeGeneration = true; +/* disable CCFG for OTA-able application */ +CCFG.enableCodeGeneration = false; /* NVS */ diff --git a/examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp b/examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp index 314ac6edd9adb4..1ab7b33a03c846 100644 --- a/examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp +++ b/examples/all-clusters-app/cc13x4_26x4/main/AppTask.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #endif #include #include diff --git a/examples/lighting-app/cc13x4_26x4/BUILD.gn b/examples/lighting-app/cc13x4_26x4/BUILD.gn index e2f105d8f85fed..8b24330ea346d2 100644 --- a/examples/lighting-app/cc13x4_26x4/BUILD.gn +++ b/examples/lighting-app/cc13x4_26x4/BUILD.gn @@ -45,8 +45,10 @@ ti_sysconfig("sysconfig") { "ti_ble_config.h", "ti_dmm_application_policy.c", "ti_dmm_application_policy.h", - "ti_devices_config.c", - "ti_devices_config.h", + + # CCFG generation disabled for OTA-able application + #"ti_devices_config.c", + #"ti_devices_config.h", # disabled until upstream generation is aligned #"tiop_config.h", diff --git a/examples/lighting-app/cc13x4_26x4/README.md b/examples/lighting-app/cc13x4_26x4/README.md index 2559c732dca70a..6d383e3e8f3be9 100644 --- a/examples/lighting-app/cc13x4_26x4/README.md +++ b/examples/lighting-app/cc13x4_26x4/README.md @@ -162,8 +162,8 @@ the session. Select the ELF image to load on the device with the `Browse` button. This file is placed in the `out/debug` folder by this guide and ends with the `*.out` file extension. For OTA enabled applications, the standalone image will instead end -with the `*-bim.hex` file extension. This this is a combined image with -application and and `BIM` included. The flag to enable or disable the OTA +with the `*-mcuboot.hex` file extension. This this is a combined image with +application and `MCUBoot` included. The flag to enable or disable the OTA feature is determined by "chip_enable_ota_requestor" in the application's args.gni file. diff --git a/examples/lighting-app/cc13x4_26x4/args.gni b/examples/lighting-app/cc13x4_26x4/args.gni index b3aabaa8d985ff..4292dcd7982393 100644 --- a/examples/lighting-app/cc13x4_26x4/args.gni +++ b/examples/lighting-app/cc13x4_26x4/args.gni @@ -27,7 +27,7 @@ ti_simplelink_board = "LP_EM_CC1354P10_6" optimize_debug_level = "s" lwip_debug = false -chip_enable_ota_requestor = false +chip_enable_ota_requestor = true chip_openthread_ftd = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x4_26x4:libopenthread-cc13x4_cc26x4" @@ -47,4 +47,4 @@ chip_stack_lock_tracking = "none" matter_device_vid = "0xFFF1" matter_device_pid = "0x8005" matter_software_ver = "0x0001" -matter_software_ver_str = "1.0d1" +matter_software_ver_str = "1.0.1+1" diff --git a/examples/lighting-app/cc13x4_26x4/chip.syscfg b/examples/lighting-app/cc13x4_26x4/chip.syscfg index e9cb55c3e22f07..0257d3ed152e5e 100644 --- a/examples/lighting-app/cc13x4_26x4/chip.syscfg +++ b/examples/lighting-app/cc13x4_26x4/chip.syscfg @@ -83,7 +83,8 @@ for(var setting in ccfgSettings) CCFG[setting] = ccfgSettings[setting]; } -CCFG.enableCodeGeneration = true; +/* disable CCFG for OTA-able application */ +CCFG.enableCodeGeneration = false; /* NVS */ diff --git a/examples/lock-app/cc13x4_26x4/BUILD.gn b/examples/lock-app/cc13x4_26x4/BUILD.gn index 2aad7a5f06134b..d7ec4065ea098f 100644 --- a/examples/lock-app/cc13x4_26x4/BUILD.gn +++ b/examples/lock-app/cc13x4_26x4/BUILD.gn @@ -41,16 +41,14 @@ ti_sysconfig("sysconfig") { "ti_radio_config.h", "ti_drivers_config.c", "ti_drivers_config.h", - "ti_devices_config.c", - "ti_devices_config.h", "ti_ble_config.c", "ti_ble_config.h", "ti_dmm_application_policy.c", "ti_dmm_application_policy.h", - # disabled until upstream generation is aligned - #"tiop_config.h", - #"tiop_config.c", + # CCFG generation disabled for OTA-able application + #"ti_devices_config.c", + #"ti_devices_config.h", # not traditional source files #"ti_utils_build_linker.cmd.genlibs", diff --git a/examples/lock-app/cc13x4_26x4/README.md b/examples/lock-app/cc13x4_26x4/README.md index a230fbb8bd5fdd..eff189d68e5fcf 100644 --- a/examples/lock-app/cc13x4_26x4/README.md +++ b/examples/lock-app/cc13x4_26x4/README.md @@ -165,8 +165,8 @@ the session. Select the ELF image to load on the device with the `Browse` button. This file is placed in the `out/debug` folder by this guide and ends with the `*.out` file extension. For OTA enabled applications, the standalone image will instead end -with the `*-bim.hex` file extension. This this is a combined image with -application and and `BIM` included. The flag to enable or disable the OTA +with the `*-mcuboot.hex` file extension. This this is a combined image with +application and `MCUBoot` included. The flag to enable or disable the OTA feature is determined by "chip_enable_ota_requestor" in the application's args.gni file. diff --git a/examples/lock-app/cc13x4_26x4/args.gni b/examples/lock-app/cc13x4_26x4/args.gni index 1d6fca57730412..2db85d82d398d3 100644 --- a/examples/lock-app/cc13x4_26x4/args.gni +++ b/examples/lock-app/cc13x4_26x4/args.gni @@ -27,15 +27,15 @@ ti_simplelink_board = "LP_EM_CC1354P10_6" optimize_debug_level = "s" lwip_debug = false -chip_enable_ota_requestor = false +chip_enable_ota_requestor = true chip_openthread_ftd = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x4_26x4:libopenthread-cc13x4_cc26x4" # Disable CHIP Logging -#chip_progress_logging = false -#chip_detail_logging = false -#chip_automation_logging = false +chip_progress_logging = true +chip_detail_logging = true +chip_automation_logging = true # BLE options chip_config_network_layer_ble = true @@ -47,4 +47,5 @@ chip_stack_lock_tracking = "none" matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" -matter_software_ver_str = "1.0d1" +matter_software_ver_str = "1.0.1+1" +# should be maj.min.rev+build with later parts optional for MCUBoot diff --git a/examples/lock-app/cc13x4_26x4/chip.syscfg b/examples/lock-app/cc13x4_26x4/chip.syscfg index e9cb55c3e22f07..0257d3ed152e5e 100644 --- a/examples/lock-app/cc13x4_26x4/chip.syscfg +++ b/examples/lock-app/cc13x4_26x4/chip.syscfg @@ -83,7 +83,8 @@ for(var setting in ccfgSettings) CCFG[setting] = ccfgSettings[setting]; } -CCFG.enableCodeGeneration = true; +/* disable CCFG for OTA-able application */ +CCFG.enableCodeGeneration = false; /* NVS */ diff --git a/examples/pump-app/cc13x4_26x4/BUILD.gn b/examples/pump-app/cc13x4_26x4/BUILD.gn index 18865640fb3259..f3fc4384f69336 100644 --- a/examples/pump-app/cc13x4_26x4/BUILD.gn +++ b/examples/pump-app/cc13x4_26x4/BUILD.gn @@ -36,7 +36,6 @@ ti_sysconfig("sysconfig") { sources = [ "${project_dir}/chip.syscfg" ] outputs = [ - "ti_devices_config.c", "ti_radio_config.c", "ti_radio_config.h", "ti_drivers_config.c", @@ -46,6 +45,10 @@ ti_sysconfig("sysconfig") { "ti_dmm_application_policy.c", "ti_dmm_application_policy.h", + # CCFG generation disabled for OTA-able application + #"ti_devices_config.c", + #"ti_devices_config.h", + # disabled until upstream generation is aligned #"tiop_config.h", #"tiop_config.c", diff --git a/examples/pump-app/cc13x4_26x4/README.md b/examples/pump-app/cc13x4_26x4/README.md index 7ad0521fef77de..23261b75cc575c 100644 --- a/examples/pump-app/cc13x4_26x4/README.md +++ b/examples/pump-app/cc13x4_26x4/README.md @@ -163,8 +163,8 @@ the session. Select the ELF image to load on the device with the `Browse` button. This file is placed in the `out/debug` folder by this guide and ends with the `*.out` file extension. For OTA enabled applications, the standalone image will instead end -with the `*-bim.hex` file extension. This this is a combined image with -application and and `BIM` included. The flag to enable or disable the OTA +with the `*-mcuboot.hex` file extension. This this is a combined image with +application and `MCUBoot` included. The flag to enable or disable the OTA feature is determined by "chip_enable_ota_requestor" in the application's args.gni file. diff --git a/examples/pump-app/cc13x4_26x4/args.gni b/examples/pump-app/cc13x4_26x4/args.gni index 6ce8fc0e1f0d90..66e2a5a2e64ed0 100644 --- a/examples/pump-app/cc13x4_26x4/args.gni +++ b/examples/pump-app/cc13x4_26x4/args.gni @@ -27,7 +27,7 @@ ti_simplelink_board = "LP_EM_CC1354P10_6" optimize_debug_level = "s" lwip_debug = false -chip_enable_ota_requestor = false +chip_enable_ota_requestor = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x4_26x4:libopenthread-cc13x4_cc26x4" chip_openthread_ftd = true @@ -47,4 +47,4 @@ chip_stack_lock_tracking = "none" matter_device_vid = "0xFFF1" matter_device_pid = "0x800A" matter_software_ver = "0x0001" -matter_software_ver_str = "1.0d1" +matter_software_ver_str = "1.0.1+1" diff --git a/examples/pump-app/cc13x4_26x4/chip.syscfg b/examples/pump-app/cc13x4_26x4/chip.syscfg index e9cb55c3e22f07..0257d3ed152e5e 100644 --- a/examples/pump-app/cc13x4_26x4/chip.syscfg +++ b/examples/pump-app/cc13x4_26x4/chip.syscfg @@ -83,7 +83,8 @@ for(var setting in ccfgSettings) CCFG[setting] = ccfgSettings[setting]; } -CCFG.enableCodeGeneration = true; +/* disable CCFG for OTA-able application */ +CCFG.enableCodeGeneration = false; /* NVS */ diff --git a/examples/pump-controller-app/cc13x4_26x4/BUILD.gn b/examples/pump-controller-app/cc13x4_26x4/BUILD.gn index 49fc1b270c7598..95fa5205a3dd67 100644 --- a/examples/pump-controller-app/cc13x4_26x4/BUILD.gn +++ b/examples/pump-controller-app/cc13x4_26x4/BUILD.gn @@ -37,7 +37,6 @@ ti_sysconfig("sysconfig") { sources = [ "${project_dir}/chip.syscfg" ] outputs = [ - "ti_devices_config.c", "ti_radio_config.c", "ti_radio_config.h", "ti_drivers_config.c", @@ -47,6 +46,10 @@ ti_sysconfig("sysconfig") { "ti_dmm_application_policy.c", "ti_dmm_application_policy.h", + # CCFG generation disabled for OTA-able application + #"ti_devices_config.c", + #"ti_devices_config.h", + # disabled until upstream generation is aligned #"tiop_config.h", #"tiop_config.c", diff --git a/examples/pump-controller-app/cc13x4_26x4/README.md b/examples/pump-controller-app/cc13x4_26x4/README.md index 15894f7d596323..a19c79697ddd79 100644 --- a/examples/pump-controller-app/cc13x4_26x4/README.md +++ b/examples/pump-controller-app/cc13x4_26x4/README.md @@ -164,8 +164,8 @@ the session. Select the ELF image to load on the device with the `Browse` button. This file is placed in the `out/debug` folder by this guide and ends with the `*.out` file extension. For OTA enabled applications, the standalone image will instead end -with the `*-bim.hex` file extension. This this is a combined image with -application and and `BIM` included. The flag to enable or disable the OTA +with the `*-mcuboot.hex` file extension. This this is a combined image with +application and `MCUBoot` included. The flag to enable or disable the OTA feature is determined by "chip_enable_ota_requestor" in the application's args.gni file. diff --git a/examples/pump-controller-app/cc13x4_26x4/args.gni b/examples/pump-controller-app/cc13x4_26x4/args.gni index 012565ce996f94..375ff1b7b08ffb 100644 --- a/examples/pump-controller-app/cc13x4_26x4/args.gni +++ b/examples/pump-controller-app/cc13x4_26x4/args.gni @@ -27,7 +27,7 @@ ti_simplelink_board = "LP_EM_CC1354P10_6" optimize_debug_level = "s" lwip_debug = false -chip_enable_ota_requestor = false +chip_enable_ota_requestor = true openthread_external_platform = "${chip_root}/third_party/openthread/platforms/cc13x4_26x4:libopenthread-cc13x4_cc26x4" chip_openthread_ftd = true @@ -47,4 +47,4 @@ chip_stack_lock_tracking = "none" matter_device_vid = "0xFFF1" matter_device_pid = "0x8011" matter_software_ver = "0x0001" -matter_software_ver_str = "1.0d1" +matter_software_ver_str = "1.0.1+1" diff --git a/examples/pump-controller-app/cc13x4_26x4/chip.syscfg b/examples/pump-controller-app/cc13x4_26x4/chip.syscfg index e9cb55c3e22f07..0257d3ed152e5e 100644 --- a/examples/pump-controller-app/cc13x4_26x4/chip.syscfg +++ b/examples/pump-controller-app/cc13x4_26x4/chip.syscfg @@ -83,7 +83,8 @@ for(var setting in ccfgSettings) CCFG[setting] = ccfgSettings[setting]; } -CCFG.enableCodeGeneration = true; +/* disable CCFG for OTA-able application */ +CCFG.enableCodeGeneration = false; /* NVS */ diff --git a/examples/shell/cc13x4_26x4/README.md b/examples/shell/cc13x4_26x4/README.md index 08be886e6fb86e..60b73447c5a7c8 100644 --- a/examples/shell/cc13x4_26x4/README.md +++ b/examples/shell/cc13x4_26x4/README.md @@ -121,8 +121,8 @@ the session. Select the ELF image to load on the device with the `Browse` button. This file is placed in the `out/debug` folder by this guide and ends with the `*.out` file extension. For OTA enabled applications, the standalone image will instead end -with the `*-bim.hex` file extension. This this is a combined image with -application and and `BIM` included. +with the `*-mcuboot.hex` file extension. This this is a combined image with +application and and `MCUBoot` included. Finally click the `Load Image` button to load the executable image onto the device. You should be able to see the log output over the XDS110 User UART. diff --git a/examples/shell/cc13x4_26x4/args.gni b/examples/shell/cc13x4_26x4/args.gni index 9f1f28f24147df..13e622146a320e 100644 --- a/examples/shell/cc13x4_26x4/args.gni +++ b/examples/shell/cc13x4_26x4/args.gni @@ -25,7 +25,7 @@ ti_simplelink_board = "LP_EM_CC1354P10_6" # use -Os instead of -Og, LWIP release build is_debug = false -chip_enable_ota_requestor = false +chip_enable_ota_requestor = true # Disable FTD Build for all-clusters app to save Flash chip_openthread_ftd = false @@ -48,4 +48,4 @@ chip_stack_lock_tracking = "none" matter_device_vid = "0xFFF1" matter_device_pid = "0x8006" matter_software_ver = "0x0001" -matter_software_ver_str = "1.0d1" +matter_software_ver_str = "1.0.1+1" diff --git a/examples/shell/cc13x4_26x4/chip.syscfg b/examples/shell/cc13x4_26x4/chip.syscfg index 1648cae0ac4239..aca6b1dfcc5136 100644 --- a/examples/shell/cc13x4_26x4/chip.syscfg +++ b/examples/shell/cc13x4_26x4/chip.syscfg @@ -83,7 +83,8 @@ for(var setting in ccfgSettings) CCFG[setting] = ccfgSettings[setting]; } -CCFG.enableCodeGeneration = true; +/* disable CCFG for OTA-able application */ +CCFG.enableCodeGeneration = false; /* NVS */ diff --git a/scripts/setup/requirements.ti.txt b/scripts/setup/requirements.ti.txt index b832ec6cf68b69..07f5e30471f1c1 100644 --- a/scripts/setup/requirements.ti.txt +++ b/scripts/setup/requirements.ti.txt @@ -1,2 +1,5 @@ +cbor>=1.0.0 +click +cryptography>=2.6 ecdsa>=0.17.0 intelhex diff --git a/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn b/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn index c86b77ec45f4eb..ff746181a7f632 100644 --- a/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn +++ b/src/platform/cc13xx_26xx/cc13x2_26x2/BUILD.gn @@ -65,8 +65,7 @@ static_library("cc13x2_26x2") { # this needs to be in the final link to place the data correctly # see ${chip_root}/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni #"oad_image_header.c", - "../OTAImageProcessorImpl.cpp", - "../OTAImageProcessorImpl.h", + "OTAImageProcessorImpl.cpp", ] } diff --git a/src/platform/cc13xx_26xx/OTAImageProcessorImpl.cpp b/src/platform/cc13xx_26xx/cc13x2_26x2/OTAImageProcessorImpl.cpp similarity index 100% rename from src/platform/cc13xx_26xx/OTAImageProcessorImpl.cpp rename to src/platform/cc13xx_26xx/cc13x2_26x2/OTAImageProcessorImpl.cpp diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn b/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn index 18298ed0ce5841..414e7b1d78bcdc 100644 --- a/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/BUILD.gn @@ -61,13 +61,7 @@ static_library("cc13x4_26x4") { } if (chip_enable_ota_requestor) { - sources += [ - # this needs to be in the final link to place the data correctly - # see ${chip_root}/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni - #"oad_image_header.c", - "../OTAImageProcessorImpl.cpp", - "../OTAImageProcessorImpl.h", - ] + sources += [ "OTAImageProcessorImpl.cpp" ] } if (chip_enable_openthread) { diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/OTAImageProcessorImpl.cpp b/src/platform/cc13xx_26xx/cc13x4_26x4/OTAImageProcessorImpl.cpp new file mode 100644 index 00000000000000..94e5a2295aaaf7 --- /dev/null +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/OTAImageProcessorImpl.cpp @@ -0,0 +1,391 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "OTAImageProcessorImpl.h" + +#include + +#include "inttypes.h" + +// clang-format off +/* driverlib header for resetting the SoC */ +#include +#include DeviceFamily_constructPath(driverlib/sys_ctrl.h) +// clang-format on + +using namespace chip::DeviceLayer; +using namespace chip::DeviceLayer::PersistedStorage; + +uint64_t totalBytesWrittenNvs = 0; + +#define MATTER_OTA_HEADER_MAGIC_NUMBER_LENGTH 4 +#define MATTER_OTA_HEADER_IMG_LENGTH_BYTES 4 +#define MATTER_OTA_HEADER_PADDING 4 +#define MATTER_OTA_HEADER_LENGTH_BYTES 4 + +namespace chip { + +CHIP_ERROR OTAImageProcessorImpl::PrepareDownload() +{ + PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast(this)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAImageProcessorImpl::Finalize() +{ + PlatformMgr().ScheduleWork(HandleFinalize, reinterpret_cast(this)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAImageProcessorImpl::Apply() +{ + PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast(this)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAImageProcessorImpl::Abort() +{ + PlatformMgr().ScheduleWork(HandleAbort, reinterpret_cast(this)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) +{ + if (nullptr == mNvsHandle) + { + return CHIP_ERROR_INTERNAL; + } + + if ((nullptr == block.data()) || block.empty()) + { + return CHIP_ERROR_INVALID_ARGUMENT; + } + + // Store block data for HandleProcessBlock to access + CHIP_ERROR err = SetBlock(block); + if (err != CHIP_NO_ERROR) + { + ChipLogError(SoftwareUpdate, "Cannot set block data: %" CHIP_ERROR_FORMAT, err.Format()); + } + + PlatformMgr().ScheduleWork(HandleProcessBlock, reinterpret_cast(this)); + return CHIP_NO_ERROR; +} + +bool OTAImageProcessorImpl::IsFirstImageRun() +{ + OTARequestorInterface * requestor; + uint32_t runningSwVer; + + if (CHIP_NO_ERROR != ConfigurationMgr().GetSoftwareVersion(runningSwVer)) + { + return false; + } + + requestor = GetRequestorInstance(); + + return (requestor->GetTargetVersion() == runningSwVer) && + (requestor->GetCurrentUpdateState() == chip::app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kApplying); +} + +/* makes room for the new block if needed */ +static bool writeExtFlashImgPages(NVS_Handle handle, ssize_t offset, MutableByteSpan block) +{ + int_fast16_t status; + NVS_Attrs regionAttrs; + unsigned int erasedSectors; + unsigned int neededSectors; + size_t sectorSize; + size_t imageOffset; + uint8_t * data; + size_t dataSize; + + if (offset < 0) + { + size_t blockOffset = -offset; + if (blockOffset >= block.size()) + { + /* We have not downloaded past the Matter OTA header */ + return true; + } + + imageOffset = 0; + data = block.data() + blockOffset; + dataSize = block.size() - blockOffset; + } + else + { + imageOffset = offset; + data = block.data(); + dataSize = block.size(); + } + + NVS_getAttrs(handle, ®ionAttrs); + sectorSize = regionAttrs.sectorSize; + erasedSectors = (imageOffset + (sectorSize - 1)) / sectorSize; + neededSectors = ((imageOffset + dataSize) + (sectorSize - 1)) / sectorSize; + if (neededSectors != erasedSectors) + { + status = NVS_erase(handle, (erasedSectors * sectorSize), (neededSectors - erasedSectors) * sectorSize); + if (status != NVS_STATUS_SUCCESS) + { + ChipLogError(SoftwareUpdate, "NVS_erase failed status: %d", status); + return false; + } + } + status = NVS_write(handle, imageOffset, data, dataSize, NVS_WRITE_POST_VERIFY); + if (status != NVS_STATUS_SUCCESS) + { + ChipLogError(SoftwareUpdate, "NVS_write failed status: %d", status); + return false; + } + else + { + totalBytesWrittenNvs += dataSize; + ChipLogProgress(SoftwareUpdate, "Total written bytes: %d", (size_t) totalBytesWrittenNvs); + } + return true; +} + +/* Erase the MCUBoot slot */ +#define BOOT_SLOT_SIZE (0x000F6000) /* must match flash_map_backend */ +static bool eraseExtSlot(NVS_Handle handle) +{ + int_fast16_t status; + NVS_Attrs regionAttrs; + unsigned int sectors; + + NVS_getAttrs(handle, ®ionAttrs); + /* calculate the number of sectors to erase */ + sectors = (BOOT_SLOT_SIZE + (regionAttrs.sectorSize - 1)) / regionAttrs.sectorSize; + status = NVS_erase(handle, 0U, sectors * regionAttrs.sectorSize); + + return (status == NVS_STATUS_SUCCESS); +} + +/* Erase the MCUBoot header to ensure the image isn't applied */ +#define BOOT_HEADER_SIZE (0x80) +static bool eraseExtHeader(NVS_Handle handle) +{ + int_fast16_t status; + NVS_Attrs regionAttrs; + unsigned int sectors; + + NVS_getAttrs(handle, ®ionAttrs); + /* calculate the number of sectors to erase */ + sectors = (BOOT_HEADER_SIZE + (regionAttrs.sectorSize - 1)) / regionAttrs.sectorSize; + status = NVS_erase(handle, 0U, sectors * regionAttrs.sectorSize); + + return (status == NVS_STATUS_SUCCESS); +} + +CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() +{ + return CHIP_NO_ERROR; +} + +void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) +{ + auto * imageProcessor = reinterpret_cast(context); + if (imageProcessor == nullptr) + { + ChipLogError(SoftwareUpdate, "ImageProcessor context is null"); + return; + } + else if (imageProcessor->mDownloader == nullptr) + { + ChipLogError(SoftwareUpdate, "mDownloader is null"); + return; + } + + if (NULL == imageProcessor->mNvsHandle) + { + NVS_Params nvsParams; + NVS_Params_init(&nvsParams); + imageProcessor->mNvsHandle = NVS_open(CONFIG_NVSEXTERNAL, &nvsParams); + + if (NULL == imageProcessor->mNvsHandle) + { + imageProcessor->mDownloader->OnPreparedForDownload(CHIP_ERROR_OPEN_FAILED); + return; + } + } + + if (!eraseExtSlot(imageProcessor->mNvsHandle)) + { + imageProcessor->mDownloader->OnPreparedForDownload(CHIP_ERROR_WRITE_FAILED); + } + + imageProcessor->mFixedOtaHeader = { 0 }; + imageProcessor->mDownloader->OnPreparedForDownload(CHIP_NO_ERROR); +} + +void OTAImageProcessorImpl::HandleFinalize(intptr_t context) +{ + auto * imageProcessor = reinterpret_cast(context); + + if (imageProcessor == nullptr) + { + return; + } + + /* possible improvement, add MCUBoot magic at the end of the slot. This + * could be done if the ota file generation truncates the image instead of + * sending the full MCUBoot slot. + */ + + imageProcessor->ReleaseBlock(); + + ChipLogProgress(SoftwareUpdate, "OTA image downloaded"); + ChipLogProgress(SoftwareUpdate, "Total downloaded bytes: %d", (size_t) imageProcessor->mParams.downloadedBytes); +} + +void OTAImageProcessorImpl::HandleApply(intptr_t context) +{ + auto * imageProcessor = reinterpret_cast(context); + if (imageProcessor == nullptr) + { + return; + } + + /* reset SoC to kick MCUBoot */ + SysCtrlSystemReset(); +} + +void OTAImageProcessorImpl::HandleAbort(intptr_t context) +{ + auto * imageProcessor = reinterpret_cast(context); + if (imageProcessor == nullptr) + { + return; + } + + if (!eraseExtHeader(imageProcessor->mNvsHandle)) + { + imageProcessor->mDownloader->OnPreparedForDownload(CHIP_ERROR_WRITE_FAILED); + } + + NVS_close(imageProcessor->mNvsHandle); + imageProcessor->ReleaseBlock(); +} + +void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) +{ + auto * imageProcessor = reinterpret_cast(context); + if (imageProcessor == nullptr) + { + ChipLogError(SoftwareUpdate, "ImageProcessor context is null"); + return; + } + else if (imageProcessor->mDownloader == nullptr) + { + ChipLogError(SoftwareUpdate, "mDownloader is null"); + return; + } + + /* Save the fixed size header */ + if (imageProcessor->mParams.downloadedBytes < sizeof(imageProcessor->mFixedOtaHeader)) + { + uint8_t * header = reinterpret_cast(&(imageProcessor->mFixedOtaHeader)); + if (imageProcessor->mBlock.size() + imageProcessor->mParams.downloadedBytes < sizeof(imageProcessor->mFixedOtaHeader)) + { + // the first block is smaller than the header, somehow + memcpy(header + imageProcessor->mParams.downloadedBytes, imageProcessor->mBlock.data(), imageProcessor->mBlock.size()); + } + else + { + // we have received the whole header, fill it up + memcpy(header + imageProcessor->mParams.downloadedBytes, imageProcessor->mBlock.data(), + sizeof(imageProcessor->mFixedOtaHeader) - imageProcessor->mParams.downloadedBytes); + + // update the total size for download tracking + imageProcessor->mParams.totalFileBytes = imageProcessor->mFixedOtaHeader.totalSize; + ChipLogDetail(SoftwareUpdate, "Total file size: %d", (size_t) imageProcessor->mParams.totalFileBytes); + } + } + + if (imageProcessor->mParams.downloadedBytes + imageProcessor->mBlock.size() > imageProcessor->mFixedOtaHeader.headerSize) + /* chip::OTAImageHeaderParser can be used for processing the variable size header */ + + /* Do not write Matter OTA image header to the external flash, MCUBoot + * needs to have it's header at address 0 + */ + if (imageProcessor->mFixedOtaHeader.headerSize > 0) + { + ssize_t offset = imageProcessor->mParams.downloadedBytes - + (imageProcessor->mFixedOtaHeader.headerSize + MATTER_OTA_HEADER_MAGIC_NUMBER_LENGTH + + MATTER_OTA_HEADER_IMG_LENGTH_BYTES + MATTER_OTA_HEADER_PADDING + MATTER_OTA_HEADER_LENGTH_BYTES); + ChipLogDetail(SoftwareUpdate, "Write block %d, %d", (size_t) imageProcessor->mParams.downloadedBytes, + imageProcessor->mBlock.size()); + if (!writeExtFlashImgPages(imageProcessor->mNvsHandle, offset, imageProcessor->mBlock)) + { + imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + return; + } + } + + imageProcessor->mParams.downloadedBytes += imageProcessor->mBlock.size(); + ChipLogDetail(SoftwareUpdate, "Total downloaded bytes: %d", (size_t) imageProcessor->mParams.downloadedBytes); + imageProcessor->mDownloader->FetchNextData(); +} + +CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) +{ + if (!IsSpanUsable(block)) + { + ReleaseBlock(); + return CHIP_NO_ERROR; + } + if (mBlock.size() < block.size()) + { + if (!mBlock.empty()) + { + ReleaseBlock(); + } + uint8_t * mBlock_ptr = static_cast(chip::Platform::MemoryAlloc(block.size())); + if (mBlock_ptr == nullptr) + { + return CHIP_ERROR_NO_MEMORY; + } + mBlock = MutableByteSpan(mBlock_ptr, block.size()); + } + CHIP_ERROR err = CopySpanToMutableSpan(block, mBlock); + if (err != CHIP_NO_ERROR) + { + ChipLogError(SoftwareUpdate, "Cannot copy block data: %" CHIP_ERROR_FORMAT, err.Format()); + return err; + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAImageProcessorImpl::ReleaseBlock() +{ + if (mBlock.data() != nullptr) + { + chip::Platform::MemoryFree(mBlock.data()); + } + + mBlock = MutableByteSpan(); + return CHIP_NO_ERROR; +} + +} // namespace chip diff --git a/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds index 83b05fb2716c79..a28b2669b3c0b8 100644 --- a/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds +++ b/src/platform/cc13xx_26xx/cc13x4_26x4/cc13x4_cc26x4_freertos_ota.lds @@ -1,6 +1,7 @@ /* * * Copyright (c) 2022 Project CHIP Authors + * Copyright (c) 2020 Texas Instruments Incorporated * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,19 +18,27 @@ /** * @file - * Linkerscript for Matter executable with space reserved for the TI BIM. + * Linkerscript for Matter executable with space reserved for MCUBoot. */ -STACKSIZE = 0x800; +STACKSIZE = 0x2000; MEMORY { - FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0xFF800 + MCUBOOT_HDR (RX) : ORIGIN = 0x00006000, LENGTH = 0x00000080 + FLASH (RX) : ORIGIN = 0x00006080, LENGTH = 0x000F8780 + /* + * NVS is the last 5 pages of slot, this area is not erased + * during OTA. The slot size for the primary and secondary slots + * is therefore 0xF6000 (MCUBoot Header + all the remaining space) + */ + /* FLASH_NVS (RX) : ORIGIN = 0x000FC000, LENGTH = 0x00002800 */ + FLASH_FACTORY_DATA (R) : ORIGIN = 0x000FE800, LENGTH = 0x900 /* * Customer Configuration Area and Bootloader Backdoor configuration in * flash */ - /* FLASH_CCFG (RX) : ORIGIN = 0x50000000, LENGTH = 0x00000800 */ + /* FLASH_CCFG (RX) : ORIGIN = 0x50000000, LENGTH = 0x00000800 */ SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00040000 GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 /* Explicitly placed off target for the storage of logging data. @@ -42,6 +51,7 @@ MEMORY } REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_FACTORY_DATA", FLASH_FACTORY_DATA); REGION_ALIAS("REGION_BSS", SRAM); REGION_ALIAS("REGION_DATA", SRAM); REGION_ALIAS("REGION_STACK", SRAM); @@ -51,17 +61,9 @@ REGION_ALIAS("REGION_ARM_EXIDX", FLASH); REGION_ALIAS("REGION_ARM_EXTAB", FLASH); SECTIONS { - /* BIM header placed at the base of flash by default */ - PROVIDE (_img_header_base_address = - DEFINED(_img_header_base_address) ? _img_header_base_address : 0x0); - - .oad_image_header (_img_header_base_address) : AT (_img_header_base_address) { - KEEP (*(.oad_image_header)) - } > REGION_TEXT - - /* interrupt vectors shifted to accommodate BIM header */ + /* interrupt vectors shifted to accommodate MCUBoot header */ PROVIDE (_intvecs_base_address = - DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x100); + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x6080); .resetVecs (_intvecs_base_address) : AT (_intvecs_base_address) { KEEP (*(.resetVecs)) @@ -74,6 +76,14 @@ SECTIONS { KEEP (*(.ramVecs)) } > REGION_DATA + /* Define base address for the Factory Data arrays and struct */ + PROVIDE (_factory_data_base_address = + DEFINED(_factory_data_base_address) ? _factory_data_base_address : 0xFE800); + + .factory_data(_factory_data_base_address) : AT (_factory_data_base_address) { + KEEP (*(.factory_data_struct)) + } > REGION_FACTORY_DATA + /* * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined * by ti/drivers/dma/UDMACC26XX.h @@ -221,19 +231,19 @@ SECTIONS { /* End of executable code/data, NVS is not part of the OTA image */ PROVIDE (_flash_end_address = .); - /* Two pages of NV Memory (0x800 each) offset by 1 page for BIM/CCFG */ - .nvs (0xFE800) (NOLOAD) : AT (0xFE800) ALIGN(0x2000) { + /* 5 pages of NV Memory (0x800 each) at the end of Flash */ + .nvs (0xFC000) (NOLOAD) : AT (0xFC000) ALIGN(0x800) { *(.nvs) } > REGION_TEXT - /* CCFG is supplied by the BIM project */ + /* CCFG is supplied by the MCUBoot project */ /* .ccfg : { KEEP (*(.ccfg)) } > FLASH_CCFG AT> FLASH_CCFG */ - .bss : { + .bss (NOLOAD) : { __bss_start__ = .; *(.shbss) *(.bss) @@ -243,7 +253,7 @@ SECTIONS { __bss_end__ = .; } > REGION_BSS AT> REGION_BSS - .heap : { + .heap (NOLOAD) : { __heap_start__ = .; end = __heap_start__; _end = end; @@ -267,4 +277,4 @@ SECTIONS { } > REGION_LOG } -ENTRY(resetISR) +ENTRY(resetISR) \ No newline at end of file diff --git a/third_party/ti_simplelink_sdk/mcuboot/flash_map_backend.c b/third_party/ti_simplelink_sdk/mcuboot/flash_map_backend.c new file mode 100644 index 00000000000000..e28a64130828c1 --- /dev/null +++ b/third_party/ti_simplelink_sdk/mcuboot/flash_map_backend.c @@ -0,0 +1,662 @@ +/* + * Copyright (c) 2018 Nordic Semiconductor ASA + * Copyright (c) 2020 Cypress Semiconductor Corporation + * Copyright (c) 2021 Texas Instruments + * + * SPDX-License-Identifier: Apache-2.0 + */ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*******************************************************************************/ + +#include +#include +#include +#include + +#include "flash_map_backend.h" +#include "mcuboot_config/mcuboot_config.h" +#include + +#include "bootutil/bootutil_log.h" + +// clang-format off +#include +#include DeviceFamily_constructPath(driverlib/flash.h) + +#ifndef DeviceFamily_CC23X0R5 +#include DeviceFamily_constructPath(driverlib/vims.h) +#endif +// clang-format on + +#ifdef TI_BOOT_USE_EXTERNAL_FLASH +#include +#endif /* TI_BOOT_USE_EXTERNAL_FLASH */ + +#define FLASH_BASE_ADDRESS 0 + +#ifdef DeviceFamily_CC23X0R5 +/* Remap driverlib API names that changed only for cc23x0 + */ +#define FlashSectorSizeGet FlashGetSectorSize +#define FlashSectorErase FlashEraseSector +#endif + +#define FLASH_ERASE_VALUE 0xFF + +/* XXX: Someone defined assert backwards in this file. We've changed it back to + * not conflict with the GCC assert. + +#define assert(x) if(x) {BOOT_LOG_ERR("assert: %s line %d", __FILE__, __LINE__);} +*/ +#include + +#ifdef TI_FLASH_MAP_EXT_DESC +/* Nothing to be there when external FlashMap Descriptors are used */ +#else +static const struct flash_area bootloader = { .fa_id = FLASH_AREA_BOOTLOADER, + .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH, + .fa_off = BOOTLOADER_BASE_ADDRESS, + .fa_size = BOOT_BOOTLOADER_SIZE }; + +static const struct flash_area primary_1 = { .fa_id = FLASH_AREA_IMAGE_PRIMARY(0), + .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH, + .fa_off = BOOT_PRIMARY_1_BASE_ADDRESS, + .fa_size = BOOT_PRIMARY_1_SIZE }; + +#if (MCUBOOT_IMAGE_NUMBER == 2) +static const struct flash_area primary_2 = { .fa_id = FLASH_AREA_IMAGE_PRIMARY(1), + .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH, + .fa_off = BOOT_PRIMARY_2_BASE_ADDRESS, + .fa_size = BOOT_PRIMARY_2_SIZE }; +#endif + +static const struct flash_area secondary_1 = { .fa_id = FLASH_AREA_IMAGE_SECONDARY(0), +#ifndef TI_BOOT_USE_EXTERNAL_FLASH + .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH, +#else + .fa_device_id = FLASH_DEVICE_EXTERNAL_FLASH(0), +#endif + .fa_off = BOOT_SECONDARY_1_BASE_ADDRESS, + .fa_size = BOOT_SECONDARY_1_SIZE }; + +#if (MCUBOOT_IMAGE_NUMBER == 2) +static const struct flash_area secondary_2 = { .fa_id = FLASH_AREA_IMAGE_SECONDARY(1), +#ifndef TI_BOOT_USE_EXTERNAL_FLASH + .fa_device_id = FLASH_DEVICE_INTERNAL_FLASH, +#else + .fa_device_id = FLASH_DEVICE_EXTERNAL_FLASH(0), +#endif + .fa_off = BOOT_SECONDARY_2_BASE_ADDRESS, + .fa_size = BOOT_SECONDARY_2_SIZE }; +#endif +#endif + +#if (MCUBOOT_IMAGE_NUMBER == 2) && (DeviceFamily_PARENT != DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4) +#error "MCUBOOT_IMAGE_NUMBER == 2 for current device not supported" +#endif + +#if (MCUBOOT_IMAGE_NUMBER > 2) +#error "More than 2 images not supported" +#endif + +#ifdef MCUBOOT_SWAP_USING_SCRATCH +static struct flash_area scratch = { +#error "MCUBOOT_SWAP_USING_SCRATCH not supported" +}; +#endif + +#ifdef TI_FLASH_MAP_EXT_DESC +/* Use external Flash Map Descriptors */ +extern struct flash_area * boot_area_descs[]; +#else +static const struct flash_area * boot_area_descs[] = { &bootloader, &primary_1, &secondary_1, +#if (MCUBOOT_IMAGE_NUMBER == 2) /* if dual-image */ + &primary_2, &secondary_2, +#endif +#ifdef MCUBOOT_SWAP_USING_SCRATCH + &scratch, +#endif + NULL }; +#endif + +#ifdef TI_BOOT_USE_EXTERNAL_FLASH +static bool extFlashStatus = false; +#endif + +#ifndef DeviceFamily_CC23X0R5 +/* Prepares system for a write to flash */ +static uint8_t disableCache(void) +{ + uint8_t mode = VIMSModeGet(VIMS_BASE); + + VIMSLineBufDisable(VIMS_BASE); + + if (mode != VIMS_MODE_DISABLED) + { + VIMSModeSet(VIMS_BASE, VIMS_MODE_DISABLED); + while (VIMSModeGet(VIMS_BASE) != VIMS_MODE_DISABLED) + ; + } + + return (mode); +} + +/* + * ======== restoreFlashCache ======== + */ +static void enableCache(uint8_t mode) +{ + if (mode != VIMS_MODE_DISABLED) + { + VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED); + } + + VIMSLineBufEnable(VIMS_BASE); +} +#endif + +/* Returns device flash start based on supported fa_id */ +int flash_device_base(uint8_t fd_id, uintptr_t * ret) +{ + if ((fd_id != FLASH_DEVICE_INTERNAL_FLASH) || (fd_id != FLASH_DEVICE_EXTERNAL_FLASH(0))) + { + BOOT_LOG_ERR("invalid flash ID %d", fd_id); + return -1; + } + *ret = FLASH_BASE_ADDRESS; + return 0; +} + +/* Opens the area for use. id is one of the `fa_id`s */ +int flash_area_open(uint8_t id, const struct flash_area ** fa) +{ + int ret = -1; + uint32_t i = 0; + + while (NULL != boot_area_descs[i]) + { + if (id == boot_area_descs[i]->fa_id) + { + *fa = boot_area_descs[i]; + +#ifdef TI_BOOT_USE_EXTERNAL_FLASH + if (boot_area_descs[i]->fa_device_id == FLASH_DEVICE_EXTERNAL_FLASH(0)) + { + if (!extFlashStatus) + { + ret = !extFlashOpen(); + // if the external flash has been opened, update the status + if (ret == 0) + { + extFlashStatus = true; + } + } + else + { + ret = 0; + } + } + else + { + ret = 0; + } +#else + ret = 0; +#endif /* TI_BOOT_USE_EXTERNAL_FLASH */ + break; + } + i++; + } + return ret; +} + +void flash_area_close(const struct flash_area * fa) +{ +#ifdef TI_BOOT_USE_EXTERNAL_FLASH + if (fa->fa_device_id == FLASH_DEVICE_EXTERNAL_FLASH(0)) + { + if (extFlashStatus) + { + extFlashClose(); + extFlashStatus = false; + } + } +#endif /* TI_BOOT_USE_EXTERNAL_FLASH */ + + (void) fa; /* Nothing to do there */ +} + +/* + * Reads `len` bytes of flash memory at `off` to the buffer at `dst` + */ +int flash_area_read(const struct flash_area * fa, uint32_t off, void * dst, uint32_t len) +{ + int rc = 0; + size_t addr; + + /* convert to absolute address inside a device*/ + addr = fa->fa_off + off; + + /* check if read is within bounds */ + assert((addr + len) <= (fa->fa_off + fa->fa_size)); + + if (fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH) + { + /* flash read by simple memory copying */ + memcpy((void *) dst, (const void *) addr, (size_t) len); + } +#ifdef TI_BOOT_USE_EXTERNAL_FLASH + else if (fa->fa_device_id == FLASH_DEVICE_EXTERNAL_FLASH(0)) + { + /* verify that flash is open */ + if (!extFlashStatus) + { + rc = flash_area_open(fa->fa_id, &fa); + if (rc != 0) + { + return rc; + } + } + else + { + extFlashClose(); + rc = !extFlashOpen(); + // if the external flash has been opened, update the status + if (rc == 0) + { + extFlashStatus = true; + } + } + + /* Read whole metadata header */ + rc = !extFlashRead(addr, (size_t) len, (void *) dst); + } +#endif /* TI_BOOT_USE_EXTERNAL_FLASH */ + else + { + /* incorrect/non-existing flash device id */ + rc = -1; + } + + if (rc != 0) + { + BOOT_LOG_ERR("Flash area read error, rc = %d", (int) rc); + } + return rc; +} + +/* + * Writes `len` bytes of flash memory at `off` from the buffer at `src` + */ +int flash_area_write(const struct flash_area * fa, uint32_t off, const void * src, uint32_t len) +{ + int rc = -1; + size_t write_start_addr; + + /* convert to absolute address inside a device*/ + write_start_addr = fa->fa_off + off; + + /* check if read is within bounds */ + assert((write_start_addr + len) <= (fa->fa_off + fa->fa_size)); + + if (fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH) + { + uint32_t flashStat; +#ifndef DeviceFamily_CC23X0R5 + uint8_t cacheState = disableCache(); +#endif + + flashStat = FlashProgram((uint8_t *) src, write_start_addr, len); + if (flashStat == FAPI_STATUS_SUCCESS) + { + rc = 0; + } + +#ifndef DeviceFamily_CC23X0R5 + enableCache(cacheState); +#endif + } +#ifdef TI_BOOT_USE_EXTERNAL_FLASH + else if (fa->fa_device_id == FLASH_DEVICE_EXTERNAL_FLASH(0)) + { + /* verify that flash is open */ + if (!extFlashStatus) + { + rc = flash_area_open(fa->fa_id, &fa); + if (rc != 0) + { + return rc; + } + } + + rc = !extFlashWrite(write_start_addr, (size_t) len, (uint8_t *) src); + } +#endif /* TI_BOOT_USE_EXTERNAL_FLASH */ + else + { + /* incorrect/non-existing flash device id */ + rc = -1; + } + + return rc; +} + +/*< Erases `len` bytes of flash memory at `off` */ +int flash_area_erase(const struct flash_area * fa, uint32_t off, uint32_t len) +{ + int rc = -1; + size_t erase_start_addr; + + /* convert to absolute address inside a device*/ + erase_start_addr = fa->fa_off + off; + + /* check if read is within bounds */ + assert((erase_start_addr + len) <= (fa->fa_off + fa->fa_size)); + + if (fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH) + { + uint8_t flashStat; + uint32_t pageAddr; + uint32_t sectorSize = FlashSectorSizeGet(); + + assert(0 == erase_start_addr % sectorSize); + +#ifndef DeviceFamily_CC23X0R5 + uint8_t cacheState = disableCache(); +#endif + + for (pageAddr = erase_start_addr; pageAddr < erase_start_addr + len; pageAddr += sectorSize) + { + flashStat = FlashSectorErase(pageAddr); + if (flashStat != FAPI_STATUS_SUCCESS) + { +#ifndef DeviceFamily_CC23X0R5 + enableCache(cacheState); +#endif + return rc; + } + } + +#ifndef DeviceFamily_CC23X0R5 + enableCache(cacheState); +#endif + rc = 0; + } +#ifdef TI_BOOT_USE_EXTERNAL_FLASH + else if (fa->fa_device_id == FLASH_DEVICE_EXTERNAL_FLASH(0)) + { + assert(0 == erase_start_addr % EXT_FLASH_PAGE_SIZE); + + /* verify that flash is open */ + if (!extFlashStatus) + { + rc = flash_area_open(fa->fa_id, &fa); + if (rc != 0) + { + return rc; + } + } + rc = !extFlashErase(erase_start_addr, (size_t) len); + } +#endif /* TI_BOOT_USE_EXTERNAL_FLASH */ + else + { + /* incorrect/non-existing flash device id */ + rc = -1; + } + return (int) rc; +} + +/*< Returns this `flash_area`s alignment */ +size_t flash_area_align(const struct flash_area * fa) +{ + int ret = -1; + if (fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH) + { + ret = FlashSectorSizeGet(); + } +#ifdef TI_BOOT_USE_EXTERNAL_FLASH + if (fa->fa_device_id == FLASH_DEVICE_EXTERNAL_FLASH(0)) + { + ret = EXT_FLASH_PAGE_SIZE; + } +#endif /* TI_BOOT_USE_EXTERNAL_FLASH */ + else + { + /* incorrect/non-existing flash device id */ + ret = -1; + } + return ret; +} + +#ifndef MCUBOOT_USE_FLASH_AREA_GET_SECTORS +/*< Initializes an array of flash_area elements for the slot's sectors */ +int flash_area_to_sectors(int idx, int * cnt, struct flash_area * fa) +{ + int rc = 0; + + if (fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH) + { + (void) idx; + (void) cnt; + rc = 0; + } + else + { + /* incorrect/non-existing flash device id */ + rc = -1; + } + return rc; +} +#endif + +/* + * This depends on the mappings defined in sysflash.h. + * MCUBoot uses continuous numbering for the primary slot, the secondary slot, + * and the scratch while zephyr might number it differently. + */ +int flash_area_id_from_multi_image_slot(int image_index, int slot) +{ + switch (slot) + { + case 0: + return FLASH_AREA_IMAGE_PRIMARY(image_index); + case 1: + return FLASH_AREA_IMAGE_SECONDARY(image_index); + case 2: + return FLASH_AREA_IMAGE_SCRATCH; + } + + return -1; /* flash_area_open will fail on that */ +} + +int flash_area_id_from_image_slot(int slot) +{ + return flash_area_id_from_multi_image_slot(0, slot); +} + +int flash_area_id_to_multi_image_slot(int image_index, int area_id) +{ + if (area_id == FLASH_AREA_IMAGE_PRIMARY(image_index)) + { + return 0; + } + if (area_id == FLASH_AREA_IMAGE_SECONDARY(image_index)) + { + return 1; + } + + return -1; +} + +int flash_area_id_to_image_slot(int area_id) +{ + return flash_area_id_to_multi_image_slot(0, area_id); +} + +uint8_t flash_area_erased_val(const struct flash_area * fap) +{ + int ret = 0; + + if ((fap->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH) || (fap->fa_device_id == FLASH_DEVICE_EXTERNAL_FLASH(0))) + { + ret = FLASH_ERASE_VALUE; + } + else + { + assert(false); + } + + return ret; +} + +int flash_area_read_is_empty(const struct flash_area * fa, uint32_t off, void * dst, uint32_t len) +{ + uint8_t * mem_dest; + int rc; + + mem_dest = (uint8_t *) dst; + rc = flash_area_read(fa, off, dst, len); + if (rc) + { + return -1; + } + + for (uint8_t i = 0; i < len; i++) + { + if (mem_dest[i] != flash_area_erased_val(fa)) + { + return 0; + } + } + return 1; +} + +#ifdef MCUBOOT_USE_FLASH_AREA_GET_SECTORS +int flash_area_get_sectors(int idx, uint32_t * cnt, struct flash_sector * ret) +{ + int rc = 0; + uint32_t i = 0; + struct flash_area * fa = NULL; + + while (NULL != boot_area_descs[i]) + { + if (idx == boot_area_descs[i]->fa_id) + { + fa = (struct flash_area *) boot_area_descs[i]; + break; + } + i++; + } + + if (NULL != boot_area_descs[i]) + { + size_t sector_size = 0; + + if (fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH) + { + sector_size = FlashSectorSizeGet(); + } +#ifdef TI_BOOT_USE_EXTERNAL_FLASH + else if (fa->fa_device_id == FLASH_DEVICE_EXTERNAL_FLASH(0)) + { + sector_size = EXT_FLASH_PAGE_SIZE; + } +#endif + else + { + rc = -1; + } + + if (0 == rc) + { + uint32_t addr = 0; + size_t sectors_n = 0; + + sectors_n = (fa->fa_size + (sector_size - 1)) / sector_size; + assert(sectors_n <= *cnt); + + addr = fa->fa_off; + for (i = 0; i < sectors_n; i++) + { + ret[i].fs_size = sector_size; + ret[i].fs_off = addr; + addr += sector_size; + } + + *cnt = sectors_n; + } + } + else + { + rc = -1; + } + + return rc; +} +#endif + +#ifdef MCUBOOT_HW_ROLLBACK_PROT + +#ifdef DeviceFamily_CC23X0R5 + +#define FLASH_WRITE_PROTECT 0 + +/* + * There is no implementation of FlashProtectionSet() in cc23x0 driverlib. + * For now it was decided to implement this feature directly in this module. + * + */ + +static void FlashProtectionSet(uint32_t address, uint32_t mode) +{ + uint32_t sector_number; + uint32_t sector_size = FlashSectorSizeGet(); + uint32_t mask; + + /* + * Check that address is within expected range, as in cc23x0r5 + * only the first 32 sectors can be individually locked. + */ + if ((address >= (FLASH_MAIN_BASE + (32 * sector_size))) || (0 != (address & (sector_size - 1)))) + { + return; + } + + sector_number = (address - FLASH_MAIN_BASE) / sector_size; + mask = 1 << sector_number; + + HWREG(VIMS_BASE + VIMS_O_WEPRA) &= ~mask; +} +#endif + +void flash_area_lock(const struct flash_area * fa) +{ + size_t addr; + + /* convert to absolute address inside a device*/ + addr = fa->fa_off; + + if (fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH) + { + FlashProtectionSet(addr, FLASH_WRITE_PROTECT); + } +} +#endif diff --git a/third_party/ti_simplelink_sdk/mcuboot/flash_map_backend.h b/third_party/ti_simplelink_sdk/mcuboot/flash_map_backend.h new file mode 100644 index 00000000000000..728e2ef44cf882 --- /dev/null +++ b/third_party/ti_simplelink_sdk/mcuboot/flash_map_backend.h @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2018 Nordic Semiconductor ASA + * Copyright (c) 2015 Runtime Inc + * Copyright (c) 2020 Cypress Semiconductor Corporation + * Copyright (c) 2021 Texas Instruments + * + * SPDX-License-Identifier: Apache-2.0 + */ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*******************************************************************************/ + +// clang-fomat off +#ifndef __FLASH_MAP_BACKEND_H__ +#define __FLASH_MAP_BACKEND_H__ + +#include +#define FLASH_DEVICE_INDEX_MASK (0x7F) +#define FLASH_DEVICE_GET_EXT_INDEX(n) ((n) &FLASH_DEVICE_INDEX_MASK) +#define FLASH_DEVICE_EXTERNAL_FLAG (0x80) +#define FLASH_DEVICE_INTERNAL_FLASH (0x7F) +#define FLASH_DEVICE_EXTERNAL_FLASH(index) (FLASH_DEVICE_EXTERNAL_FLAG | index) + +#ifndef TI_BOOT_EXTERNAL_DEVICE_INDEX +/* assume first(one) SMIF device is used */ +#define TI_BOOT_EXTERNAL_DEVICE_INDEX (0) +#endif + +/* + * ============== XXX: Definitions changed from upstream example ============== + * + * These definitions have been modified to work with the Matter examples. + * Currently the example application takes up as much flash space as possible + * in the SoC. This may change in the future when a secure image is produced. + * + * This is for external flash storage of the secondary image + */ +#ifndef TI_BOOT_USE_EXTERNAL_FLASH +#error "This file must be used with TI_BOOT_USE_EXTERNAL_FLASH enabled" +#endif + +#ifdef DeviceFamily_CC13X4 +#if (MCUBOOT_IMAGE_NUMBER == 2) +#define BOOT_SLOT_1_SIZE 0x0002B000 +#define BOOT_SLOT_2_SIZE 0x000CC800 + +/* Internal Flash locations */ +#define BOOTLOADER_BASE_ADDRESS 0x00000800 +#define BOOT_BOOTLOADER_SIZE 0x00005800 + +#define BOOT_PRIMARY_1_BASE_ADDRESS (BOOTLOADER_BASE_ADDRESS + BOOT_BOOTLOADER_SIZE) +#define BOOT_PRIMARY_1_SIZE BOOT_SLOT_1_SIZE + +#define BOOT_PRIMARY_2_BASE_ADDRESS (BOOT_PRIMARY_1_BASE_ADDRESS + BOOT_PRIMARY_1_SIZE) +#define BOOT_PRIMARY_2_SIZE BOOT_SLOT_2_SIZE + +/* EXT Flash locations */ +#define BOOT_SECONDARY_1_BASE_ADDRESS 0x00000000 +#define BOOT_SECONDARY_1_SIZE BOOT_SLOT_1_SIZE + +#define BOOT_SECONDARY_2_BASE_ADDRESS (BOOT_SECONDARY_1_BASE_ADDRESS + BOOT_SECONDARY_1_SIZE) +#define BOOT_SECONDARY_2_SIZE BOOT_SLOT_2_SIZE +#else +#define BOOT_SLOT_1_SIZE 0x000F6000 + +/* Internal Flash locations */ +#define BOOTLOADER_BASE_ADDRESS 0x00000000 +#define BOOT_BOOTLOADER_SIZE 0x00006000 + +#define BOOT_PRIMARY_1_BASE_ADDRESS (BOOTLOADER_BASE_ADDRESS + BOOT_BOOTLOADER_SIZE) +#define BOOT_PRIMARY_1_SIZE BOOT_SLOT_1_SIZE + +/* EXT Flash locations */ +#define BOOT_SECONDARY_1_BASE_ADDRESS 0x00000000 +#define BOOT_SECONDARY_1_SIZE BOOT_SLOT_1_SIZE +#endif + +#else +#error "DeviceFamily not recognized, is MCUBoot meant to be used?" + +#endif /* DeviceFamily_XXXXXX */ + +/** + * + * Provides abstraction of flash regions for type of use. + * I.e. dude where's my image? + * + * System will contain a map which contains flash areas. Every + * region will contain flash identifier, offset within flash and length. + * + * 1. This system map could be in a file within filesystem (Initializer + * must know/figure out where the filesystem is at). + * 2. Map could be at fixed location for project (compiled to code) + * 3. Map could be at specific place in flash (put in place at mfg time). + * + * Note that the map you use must be valid for BSP it's for, + * match the linker scripts when platform executes from flash, + * and match the target offset specified in download script. + */ +#include + +/** + * @brief Structure describing an area on a flash device. + * + * Multiple flash devices may be available in the system, each of + * which may have its own areas. For this reason, flash areas track + * which flash device they are part of. + */ +struct flash_area +{ + /** + * This flash area's ID; unique in the system. + */ + uint8_t fa_id; + + /** + * ID of the flash device this area is a part of. + */ + uint8_t fa_device_id; + + uint16_t pad16; + + /** + * This area's offset, relative to the beginning of its flash + * device's storage. + */ + uint32_t fa_off; + + /** + * This area's size, in bytes. + */ + uint32_t fa_size; +}; + +/** + * @brief Structure describing a sector within a flash area. + * + * Each sector has an offset relative to the start of its flash area + * (NOT relative to the start of its flash device), and a size. A + * flash area may contain sectors with different sizes. + */ +struct flash_sector +{ + /** + * Offset of this sector, from the start of its flash area (not device). + */ + uint32_t fs_off; + + /** + * Size of this sector, in bytes. + */ + uint32_t fs_size; +}; + +struct flash_map_entry +{ + uint32_t magic; + struct flash_area area; + unsigned int ref_count; +}; + +/* + * Retrieve a memory-mapped flash device's base address. + * On success, the address will be stored in the value pointed to by + * ret. + * Returns 0 on success, or an error code on failure. + */ +int flash_device_base(uint8_t fd_id, uintptr_t * ret); + +/*< Opens the area for use. id is one of the `fa_id`s */ +int flash_area_open(uint8_t id, const struct flash_area **); +void flash_area_close(const struct flash_area *); +/*< Reads `len` bytes of flash memory at `off` to the buffer at `dst` */ +int flash_area_read(const struct flash_area *, uint32_t off, void * dst, uint32_t len); +/*< Writes `len` bytes of flash memory at `off` from the buffer at `src` */ +int flash_area_write(const struct flash_area *, uint32_t off, const void * src, uint32_t len); +/*< Erases `len` bytes of flash memory at `off` */ +int flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len); +/*< Returns this `flash_area`s alignment */ +size_t flash_area_align(const struct flash_area *); +/*< Initializes an array of flash_area elements for the slot's sectors */ +int flash_area_to_sectors(int idx, int * cnt, struct flash_area * ret); +/*< Returns the `fa_id` for slot, where slot is 0 (primary) or 1 (secondary) */ +int flash_area_id_from_image_slot(int slot); +/*< Returns the slot, for the `fa_id` supplied */ +int flash_area_id_to_image_slot(int area_id); + +int flash_area_id_from_multi_image_slot(int image_index, int slot); +int flash_area_id_to_multi_image_slot(int image_index, int area_id); +#ifdef MCUBOOT_USE_FLASH_AREA_GET_SECTORS +int flash_area_get_sectors(int idx, uint32_t * cnt, struct flash_sector * ret); +#endif +#ifdef MCUBOOT_HW_ROLLBACK_PROT +void flash_area_lock(const struct flash_area * fa); +#endif +/* + * Returns the value expected to be read when accesing any erased + * flash byte. + */ +uint8_t flash_area_erased_val(const struct flash_area * fap); + +/* + * Reads len bytes from off, and checks if the read data is erased. + * + * Returns 1 if erased, 0 if non-erased, and -1 on failure. + */ +int flash_area_read_is_empty(const struct flash_area * fa, uint32_t off, void * dst, uint32_t len); + +#endif /* __FLASH_MAP_BACKEND_H__ */ + +// clang-format on diff --git a/third_party/ti_simplelink_sdk/mcuboot/mcuboot.syscfg b/third_party/ti_simplelink_sdk/mcuboot/mcuboot.syscfg new file mode 100644 index 00000000000000..0a92846df1c88e --- /dev/null +++ b/third_party/ti_simplelink_sdk/mcuboot/mcuboot.syscfg @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * mcuboot.syscfg + */ + + +const Board = scripting.addModule("/ti/drivers/Board"); + +/* ======== Board ======== */ +var boardName = system.deviceData.board.name; + +/** + * Import the modules used in this configuration. + */ +const CCFG = scripting.addModule("/ti/devices/CCFG"); +const ccfgSettings = system.getScript("/ti/common/lprf_ccfg_settings.js").ccfgSettings; +for(var setting in ccfgSettings) +{ + CCFG[setting] = ccfgSettings[setting]; +} + +if (boardName.match(/CC13.2.7|CC26.2.7/)) +{ + // mcuboot stored at end of flash alongside CCFG + CCFG.setFlashVectorTable = true; + CCFG.addressFlashVectorTable = 0x000AC000; +} +else if (boardName.match(/CC13.4|CC26.[34]/)) +{ + // mcuboot stored at the beginning of flash + CCFG.setFlashVectorTable = true; + CCFG.addressFlashVectorTable = 0x00000000; +} +else if (boardName.match(/CC23.0/)) { + // Nothing to do. Default pBldrVtor = 0x00000000 +} +else +{ + // error +} + +CCFG.ccfgTemplate.$name = "ti_devices_CCFG_CCFGCC26XXTemplate0"; + +/* ======== GPIO ======== */ +var GPIO = scripting.addModule("/ti/drivers/GPIO"); + +var gpio0 = GPIO.addInstance(); +gpio0.$hardware = system.deviceData.board.components.LED0; +gpio0.$name = "CONFIG_GPIO_LED_0"; + +var gpio1 = GPIO.addInstance(); +gpio1.$hardware = system.deviceData.board.components.LED1; +gpio1.$name = "CONFIG_GPIO_LED_1"; + +var gpio2 = GPIO.addInstance(); +gpio2.$hardware = system.deviceData.board.components.BUTTON0; +gpio2.$name = "CONFIG_GPIO_BUTTON_0"; + +var gpio3 = GPIO.addInstance(); +gpio3.$hardware = system.deviceData.board.components.BUTTON1; +gpio3.$name = "CONFIG_GPIO_BUTTON_1"; \ No newline at end of file diff --git a/third_party/ti_simplelink_sdk/mcuboot/mcuboot_cc13x4_cc26x4.lds b/third_party/ti_simplelink_sdk/mcuboot/mcuboot_cc13x4_cc26x4.lds new file mode 100644 index 00000000000000..375e18722dc49e --- /dev/null +++ b/third_party/ti_simplelink_sdk/mcuboot/mcuboot_cc13x4_cc26x4.lds @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2022, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +STACKSIZE = 1024; +HEAPSIZE = 16384; /* Size of heap buffer used by HeapMem */ + +FLASH_BASE = DEFINED(DUAL_SLOT) ? 0x800 : 0x0; + +MEMORY +{ + FLASH (RX) : ORIGIN = FLASH_BASE, LENGTH = 0x5800 + /* + * Customer Configuration Area and Bootloader Backdoor configuration in + * flash, up to 1024 bytes + */ + FLASH_CCFG (RX) : ORIGIN = 0x50000000, LENGTH = 0x00000800 + SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00040000 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 +} + +REGION_ALIAS("REGION_FLASH_START", FLASH); +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + + .resetVecs : { + KEEP (*(.resetVecs)) + } > REGION_FLASH_START + + .ramVecs (NOLOAD) : ALIGN(1024){ + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_0400, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20000400; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * --------- DO NOT MODIFY ----------- + */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); + DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); + DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); + DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); + DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); + DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); + DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); + DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); + + /* + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0APriControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; + .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; + .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaGPT0AAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1RxAltControlTableEntry_is_placed = 0; + .dmaSpi1RxAltControlTableEntry DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_dmaSpi1TxAltControlTableEntry_is_placed = 0; + .dmaSpi1TxAltControlTableEntry DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxAltControlTableEntry)} > REGION_DATA + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(4) { + _data = .; + __data_load__ = LOADADDR (.data); + __data_start__ = .; + *(.data) + *(.data.*) + _edata = .; + . = ALIGN (4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + _ldata = LOADADDR(.data); + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + .nvs (NOLOAD) : ALIGN(0x2000) { + *(.nvs) + } > REGION_TEXT + + .ccfg : { + KEEP (*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + + .bss : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN (4); + _ebss = .; + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + _bss = LOADADDR(.bss); + + .heap : { + __heap_start__ = .; + end = __heap_start__; + _end = end; + __end = end; + . = . + HEAPSIZE; + KEEP(*(.heap)) + __heap_end__ = .; + __HeapLimit = __heap_end__; + } > REGION_HEAP AT> REGION_HEAP + + .stack (NOLOAD) : ALIGN(0x8) { + _stack = .; + __stack = .; + KEEP(*(.stack)) + . += STACKSIZE; + _stack_end = .; + __stack_end = .; + _estack = .; + } > REGION_STACK AT> REGION_STACK +} \ No newline at end of file diff --git a/third_party/ti_simplelink_sdk/mcuboot/mcuboot_config/mcuboot_config.h b/third_party/ti_simplelink_sdk/mcuboot/mcuboot_config/mcuboot_config.h new file mode 100644 index 00000000000000..1977bb7af88f4d --- /dev/null +++ b/third_party/ti_simplelink_sdk/mcuboot/mcuboot_config/mcuboot_config.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Texas Instruments Incorporated + * + * SPDX-License-Identifier: Apache-2.0 + */ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +#define MCUBOOT_DOWNGRADE_PREVENTION +#define MCUBOOT_HAVE_LOGGING 1 +#define MCUBOOT_IMAGE_NUMBER 1 +#define MCUBOOT_MAX_IMG_SECTORS 492 +#define MCUBOOT_OVERWRITE_ONLY +#define MCUBOOT_SIGN_EC256 +#define MCUBOOT_USE_FLASH_AREA_GET_SECTORS +#define MCUBOOT_USE_TI_CRYPTO +#define MCUBOOT_VALIDATE_PRIMARY_SLOT +#define MCUBOOT_WATCHDOG_FEED() \ + {} + +#define TI_BOOT_USE_EXTERNAL_FLASH + +#ifdef MCUBOOT_DATA_SHARING +#define MCUBOOT_SHARED_DATA_BASE 0x20000000 +#define MCUBOOT_SHARED_DATA_SIZE 0x400 +#endif + +#if defined(TI_BOOT_USE_EXTERNAL_FLASH) && (!defined(MCUBOOT_OVERWRITE_ONLY) || defined(MCUBOOT_DIRECT_XIP)) +#error "If external flash is configured, only MCUBOOT_OVERWRITE_ONLY is supported" +#endif diff --git a/third_party/ti_simplelink_sdk/oad_merge_tool.py b/third_party/ti_simplelink_sdk/oad_merge_tool.py index c603a2fe445b58..0554601a1da07c 100644 --- a/third_party/ti_simplelink_sdk/oad_merge_tool.py +++ b/third_party/ti_simplelink_sdk/oad_merge_tool.py @@ -14,12 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Simple hexmerge script for combining the BIM and App +"""Simple hexmerge script for combining the BIM/MCUBoot image and App -This script provides a basic utility to combine the OAD application binary file with the Boot Image Manager hex file. The output is a combined hex file that can be programmed on the target and run. +This script provides a basic utility to combine the OAD application binary file with the Boot Image Manager/MCUBoot hex file. The output is a combined hex file that can be programmed on the target and run. Run with: - python oad_merge_tool.py + python oad_merge_tool.py """ import sys @@ -32,7 +32,11 @@ # merge binary executable with bim hex file ota_image = intelhex.IntelHex() -ota_image.fromfile(oad_bin_file, format='bin') +if (oad_bin_file.endswith('hex')): + ota_image.fromfile(oad_bin_file, format='hex') + +else: + ota_image.fromfile(oad_bin_file, format='bin') bim_hex = intelhex.IntelHex() bim_hex.fromfile(bim_hex_file, format='hex') diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni index da4dff87a73460..9cc800e9b1e139 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_executable.gni @@ -37,13 +37,6 @@ assert(matter_software_ver_str != "", template("ti_simplelink_executable") { simplelink_target_name = target_name - if (chip_enable_ota_requestor) { - # Generating the ota binary image - final_target = "${target_name}.ota" - } else { - # The executable is the final target. - final_target = "${simplelink_target_name}.out" - } output_base_name = get_path_info(invoker.output_name, "name") #used for OTA image creator for the cc13xx @@ -109,103 +102,339 @@ template("ti_simplelink_executable") { ] } - if (chip_enable_ota_requestor && - ti_simplelink_device_family == "cc13x2x7_26x2x7") { - pw_python_action("${simplelink_target_name}.bin") { - public_deps = [ ":${simplelink_target_name}.out.image" ] - - script = "${ti_simplelink_sdk_root}//tools/common/oad/oad_image_tool.py" - sources = [ "${root_out_dir}/${objcopy_image_name}" ] - outputs = [ "${root_out_dir}/${output_base_name}.bin" ] - - args = [ - "--verbose", - "ccs", - rebase_path(root_out_dir, root_build_dir), - "7", - "-hex1", - rebase_path("${root_out_dir}/${output_base_name}.hex", root_out_dir), - "-o", - output_base_name, - ] - - if (defined(invoker.pem_file)) { - args += [ - "-k", - rebase_path(invoker.pem_file, root_build_dir), + if (chip_enable_ota_requestor) { + if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { + pw_python_action("${simplelink_target_name}.bin") { + public_deps = [ ":${simplelink_target_name}.out.image" ] + + script = "${ti_simplelink_sdk_root}//tools/common/oad/oad_image_tool.py" + sources = [ "${root_out_dir}/${objcopy_image_name}" ] + outputs = [ "${root_out_dir}/${output_base_name}.bin" ] + + args = [ + "--verbose", + "ccs", + rebase_path(root_out_dir, root_build_dir), + "7", + "-hex1", + rebase_path("${root_out_dir}/${output_base_name}.hex", root_out_dir), + "-o", + output_base_name, ] - } else { + + if (defined(invoker.pem_file)) { + args += [ + "-k", + rebase_path(invoker.pem_file, root_build_dir), + ] + } else { + args += [ + "-k", + rebase_path( + "${ti_simplelink_sdk_root}/tools/common/oad/private.pem", + root_build_dir), + ] + } + } + action("${simplelink_target_name}-bim.hex") { + public_deps = [ ":${simplelink_target_name}.bin" ] + + script = "${ti_simplelink_sdk_build_root}/oad_merge_tool.py" + sources = [ "${root_out_dir}/${output_base_name}.bin" ] + outputs = [ "${root_out_dir}/${output_base_name}-bim.hex" ] + + if (defined(invoker.bim_hex)) { + bim_hex = invoker.bim_hex + } else { + bim_hex = "${ti_simplelink_sdk_root}/examples/nortos/${ti_simplelink_board}/bim/hexfiles/bim_offchip/Release/bim_offchip.hex" + } + + args = [ + rebase_path("${root_out_dir}/${output_base_name}.bin", + root_build_dir), + rebase_path(bim_hex, root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-bim.hex", + root_build_dir), + ] + } + pw_python_action("${target_name}.ota") { + public_deps = [ ":${simplelink_target_name}.bin" ] + + script = "${chip_root}/src/app/ota_image_tool.py" + sources = [ "${root_out_dir}/${output_base_name}.bin" ] + outputs = [ "${root_out_dir}/${output_base_name}.ota" ] + + args = [ + "create", + rebase_path("${root_out_dir}/${output_base_name}.bin", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}.ota", + root_build_dir), + ] + args += [ - "-k", - rebase_path("${ti_simplelink_sdk_root}/tools/common/oad/private.pem", + "-v", + matter_device_vid, + "-p", + matter_device_pid, + "-vn", + matter_software_ver, + "-vs", + matter_software_ver_str, + ] + if (defined(invoker.ota_digest)) { + args += [ + "-da", + matter_ota_digest, + ] + } else { + args += [ + "-da", + "sha256", + ] + } + if (defined(invoker.ota_args)) { + args += invoker.ota_args + } + } + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + # add MCUBoot Header to the executable + action("${simplelink_target_name}_header.hex") { + public_deps = [ ":${simplelink_target_name}.out.image" ] + + script = "${ti_simplelink_sdk_root}/source/third_party/mcuboot/scripts/imgtool.py" + sources = [ "${root_out_dir}/${output_base_name}.hex" ] + outputs = [ "${root_out_dir}/${output_base_name}_header.hex" ] + + args = [ + "sign", + "--header-size", + "0x80", + "--align", + "4", + "--slot-size", + "0x000F6000", # must match the flash_map_backend definitions + "--version", + matter_software_ver_str, + "--pad-header", + "--pad", + "--key", + rebase_path( + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/root-ec-p256.pem", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}.hex", root_out_dir), + rebase_path("${root_out_dir}/${output_base_name}_header.hex", + root_out_dir), + ] + } + action("${simplelink_target_name}_header.bin") { + inputs = [ "${root_out_dir}/${output_base_name}_header.hex" ] + outputs = [ "${root_out_dir}/${output_base_name}_header.bin" ] + deps = [ ":${simplelink_target_name}_header.hex" ] + args = [ + objcopy, + "-I", + "ihex", + "-O", + "binary", + rebase_path("${root_out_dir}/${output_base_name}_header.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}_header.bin", root_build_dir), ] + script = "${build_root}/gn_run_binary.py" } - } - pw_python_action("${simplelink_target_name}-bim.hex") { - public_deps = [ ":${simplelink_target_name}.bin" ] - script = "${ti_simplelink_sdk_build_root}/oad_merge_tool.py" - sources = [ "${root_out_dir}/${output_base_name}.bin" ] - outputs = [ "${root_out_dir}/${output_base_name}-bim.hex" ] + # Generate MCUBoot sysconfig + ti_sysconfig("${simplelink_target_name}_mcuboot.syscfg") { + sources = [ "${ti_simplelink_sdk_build_root}/mcuboot/mcuboot.syscfg" ] + rtos = "nortos" + outputs = [ + "ti_drivers_config.c", + "ti_drivers_config.h", + "ti_devices_config.c", + "ti_devices_config.h", - if (defined(invoker.bim_hex)) { - bim_hex = invoker.bim_hex - } else { - bim_hex = "${ti_simplelink_sdk_root}/examples/nortos/${ti_simplelink_board}/bim/hexfiles/bim_offchip/Release/bim_offchip.hex" + # not traditional source files + #"ti_utils_build_linker.cmd.genlibs", + #"syscfg_c.rov.xs", + ] } - args = [ - rebase_path("${root_out_dir}/${output_base_name}.bin", root_build_dir), - rebase_path(bim_hex, root_build_dir), - rebase_path("${root_out_dir}/${output_base_name}-bim.hex", - root_build_dir), - ] + # build MCUBoot bootloader + config("${simplelink_target_name}_mcubootloader_config") { + libs = [ "${ti_simplelink_sdk_root}/source/ti/devices/cc13x4_cc26x4/driverlib/bin/gcc/driverlib.lib" ] + } + flashable_executable("${simplelink_target_name}_mcubootloader") { + output_name = "${output_base_name}.mcubootloader.out" + output_dir = root_out_dir + deps = [ ":${simplelink_target_name}_mcuboot.syscfg" ] + public_configs = [ ":${simplelink_target_name}_mcubootloader_config" ] + ldscript = + "${ti_simplelink_sdk_build_root}/mcuboot/mcuboot_cc13x4_cc26x4.lds" + objcopy_image_name = "${output_base_name}.mcubootloader.hex" + objcopy_image_format = "ihex" + inputs = [ ldscript ] + sources = [ + "${ti_simplelink_sdk_build_root}/mcuboot/flash_map_backend.c", + "${ti_simplelink_sdk_build_root}/mcuboot/mcuboot_config/mcuboot_config.h", + "${ti_simplelink_sdk_build_root}/syscalls_stubs.cpp", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/boot_record.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/bootutil_misc.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/bootutil_public.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/caps.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/encrypted.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/fault_injection_hardening.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/image_ec.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/image_ec256.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/image_ed25519.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/image_rsa.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/image_validate.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/loader.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/swap_misc.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/swap_move.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/swap_priv.h", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/swap_scratch.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src/tlv.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/ti/source/mcuboot_app/keys.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/ti/source/mcuboot_app/mcuboot_app.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/ti/source/mcuboot_app/security_cnt.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/ext/mbedtls-asn1/src/asn1parse.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/ext/mbedtls-asn1/src/platform_util.c", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/ext/ti-crypto/sl_crypto.c", + "${ti_simplelink_sdk_root}/source/ti/common/cc26xx/debug/led_debug.c", + "${ti_simplelink_sdk_root}/source/ti/common/cc26xx/ecc/ECDSACC26X4_driverlib.c", + "${ti_simplelink_sdk_root}/source/ti/common/cc26xx/sha2/sha2_driverlib.c", + "${ti_simplelink_sdk_root}/source/ti/common/flash/no_rtos/extFlash/bsp_spi_cc13x4_cc26x4.c", + "${ti_simplelink_sdk_root}/source/ti/common/flash/no_rtos/extFlash/ext_flash.c", + "${ti_simplelink_sdk_root}/source/ti/common/mcuboot/boot_seed/boot_seed_cc13x4_cc26x4.c", + ] - args += [ "${root_out_dir}/${output_base_name}-bim.hex" ] - } - pw_python_action("${target_name}.ota") { - public_deps = [ ":${simplelink_target_name}-bim.hex" ] - - script = "${chip_root}/src/app/ota_image_tool.py" - sources = [ "${root_out_dir}/${output_base_name}.bin" ] - outputs = [ "${root_out_dir}/${output_base_name}.ota" ] - - args = [ - "create", - rebase_path("${root_out_dir}/${output_base_name}.bin", root_build_dir), - rebase_path("${root_out_dir}/${output_base_name}.ota", root_build_dir), - ] - - args += [ - "-v", - matter_device_vid, - "-p", - matter_device_pid, - "-vn", - matter_software_ver, - "-vs", - matter_software_ver_str, - ] - if (defined(invoker.ota_digest)) { - args += [ - "-da", - matter_ota_digest, + include_dirs = [ + # === MUST BE BEFORE === + # "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/ti/source/mcuboot_app" + # to eclipse the mcuboot config header + "${ti_simplelink_sdk_build_root}/mcuboot", + + "${ti_simplelink_sdk_root}/kernel/nortos", + "${ti_simplelink_sdk_root}/source", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/include", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/bootutil/src", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/boot/ti/source/mcuboot_app", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/ext", + "${ti_simplelink_sdk_root}/source/third_party/mcuboot/ext/mbedtls-asn1/include", + "${ti_simplelink_sdk_root}/source/ti", + "${ti_simplelink_sdk_root}/source/ti/common/cc26xx/ecc", + "${ti_simplelink_sdk_root}/source/ti/common/cc26xx/sha2", + "${ti_simplelink_sdk_root}/source/ti/common/flash/no_rtos/extFlash", ] - } else { - args += [ - "-da", - "sha256", + + defines = [ + "EXCLUDE_TRACE", + "BOOT_LOADER", + ] + + ldflags = [ + "-eresetISR", + "-L" + + rebase_path(ti_simplelink_sdk_root + "/source", root_build_dir), + "-L" + rebase_path(ti_simplelink_sdk_root + "/kernel/nortos", + root_build_dir), + rebase_path( + "${target_gen_dir}/${simplelink_target_name}_mcuboot.syscfg/ti_utils_build_linker.cmd.genlibs", + root_build_dir), + "-T" + rebase_path(ldscript, root_build_dir), ] } - if (defined(invoker.ota_args)) { - args += invoker.ota_args + + action("${simplelink_target_name}-mcuboot.hex") { + public_deps = [ + ":${simplelink_target_name}_header.bin", + ":${simplelink_target_name}_mcubootloader.image", + ] + + script = "${ti_simplelink_sdk_build_root}/oad_merge_tool.py" + sources = [ + "${root_out_dir}/${output_base_name}.mcubootloader.hex", + "${root_out_dir}/${output_base_name}_header.bin", + ] + outputs = [ "${root_out_dir}/${output_base_name}-mcuboot.hex" ] + + args = [ + rebase_path("${root_out_dir}/${output_base_name}_header.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}.mcubootloader.hex", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}-mcuboot.hex", + root_build_dir), + ] + } + pw_python_action("${target_name}.ota") { + # For MCUBoot the image could be truncated to the actual executable + # size. The hex file is padded to the slot size. + public_deps = [ ":${simplelink_target_name}_header.bin" ] + + script = "${chip_root}/src/app/ota_image_tool.py" + sources = [ "${root_out_dir}/${output_base_name}_header.bin" ] + outputs = [ "${root_out_dir}/${output_base_name}.ota" ] + + args = [ + "create", + rebase_path("${root_out_dir}/${output_base_name}_header.bin", + root_build_dir), + rebase_path("${root_out_dir}/${output_base_name}.ota", + root_build_dir), + ] + + args += [ + "-v", + matter_device_vid, + "-p", + matter_device_pid, + "-vn", + matter_software_ver, + "-vs", + matter_software_ver_str, + ] + if (defined(invoker.ota_digest)) { + args += [ + "-da", + matter_ota_digest, + ] + } else { + args += [ + "-da", + "sha256", + ] + } + if (defined(invoker.ota_args)) { + args += invoker.ota_args + } } } } group(simplelink_target_name) { - data_deps = [ ":$final_target" ] + if (chip_enable_ota_requestor) { + # Generating the ota binary image + if (ti_simplelink_device_family == "cc13x2x7_26x2x7") { + data_deps = [ + ":${simplelink_target_name}-bim.hex", + ":${simplelink_target_name}.ota", + ":${simplelink_target_name}.out", + ] + } else if (ti_simplelink_device_family == "cc13x4_26x4") { + data_deps = [ + ":${simplelink_target_name}-mcuboot.hex", + ":${simplelink_target_name}.ota", + ":${simplelink_target_name}.out", + ] + } + } else { + # The executable is the final target. + data_deps = [ ":${simplelink_target_name}.out" ] + } if (defined(invoker.data_deps)) { data_deps += invoker.data_deps diff --git a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni index ee16f5179e5859..8a8cfd71247598 100644 --- a/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni +++ b/third_party/ti_simplelink_sdk/ti_simplelink_sdk.gni @@ -112,6 +112,12 @@ template("ti_sysconfig") { sources = invoker.sources outputs = gen_outputs + if (defined(invoker.rtos)) { + rtos = invoker.rtos + } else { + rtos = "freertos" + } + if (ti_simplelink_device == "") { args = [ ti_sysconfig_root, @@ -125,7 +131,7 @@ template("ti_sysconfig") { "--board", "/ti/boards/" + ti_simplelink_board, "--rtos", - "freertos", + rtos, ] } else { args = [ @@ -140,7 +146,7 @@ template("ti_sysconfig") { "--device", ti_simplelink_device, "--rtos", - "freertos", + rtos, ] }