blob: 650f336c443d223850e8e6078f55f8ff411dd1bf [file] [log] [blame]
# Copyright (c) 2020 Project CHIP Authors
#
# 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.
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/ti_simplelink_sdk.gni")
import("${build_root}/toolchain/flashable_executable.gni")
import("${chip_root}/src/platform/device.gni")
import("ti_simplelink_board.gni")
import("ti_simplelink_sdk.gni")
declare_args() {
matter_device_vid = ""
matter_device_pid = ""
matter_software_ver = ""
matter_software_ver_str = ""
}
assert(matter_device_vid != "", "matter_device_vid must be specified")
assert(matter_device_pid != "", "matter_device_pid must be specified")
assert(matter_software_ver != "", "matter_software_ver must be specified")
assert(matter_software_ver_str != "",
"matter_software_ver_str must be specified")
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
if (ti_simplelink_device_family == "cc13x2x7_26x2x7") {
objcopy_image_name = output_base_name + ".hex"
objcopy_image_format = "ihex"
} else {
objcopy_image_name = output_base_name + ".bin"
objcopy_image_format = "binary"
}
objcopy = "arm-none-eabi-objcopy"
config("${simplelink_target_name}_config") {
defines = []
if (defined(invoker.defines)) {
defines += invoker.defines
}
# add OTA options if available
defines += [
"CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID=${matter_device_vid}",
"CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${matter_device_pid}",
"CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION=${matter_software_ver}",
"CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${matter_software_ver_str}\"",
]
}
flashable_executable("${simplelink_target_name}.out") {
forward_variables_from(invoker, "*")
public_configs = [ ":${simplelink_target_name}_config" ]
if (ti_simplelink_device_family == "cc13x2x7_26x2x7") {
if (chip_enable_ota_requestor) {
sources +=
[ "${chip_root}/src/platform/cc13x2_26x2/oad_image_header.c" ]
ldscript = "${chip_root}/src/platform/cc13x2_26x2/cc13x2x7_cc26x2x7_freertos_ota.lds"
} else {
ldscript = "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/cc13x2x7_cc26x2x7.lds"
}
} else if (ti_simplelink_device_family == "cc32xx") {
ldscript = "${ti_simplelink_sdk_root}/source/ti/boards/cc32xxsf/cc32xxsf_freertos.lds"
}
inputs = [ ldscript ]
ldflags = [
"-L" + rebase_path(ti_simplelink_sdk_root + "/source", root_build_dir),
rebase_path(
"${target_gen_dir}/sysconfig/ti_utils_build_linker.cmd.genlibs",
root_build_dir),
"-T" + rebase_path(ldscript, root_build_dir),
]
}
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),
]
} else {
args += [
"-k",
rebase_path("${ti_simplelink_sdk_root}/tools/common/oad/private.pem",
root_build_dir),
]
}
}
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" ]
if (defined(invoker.bim_hex)) {
bim_hex = invoker.bim_hex
} else {
bim_hex = "${ti_simplelink_sdk_root}/examples/rtos/${ti_simplelink_board}/ble5stack/hexfiles/bim_offchip/Release/${ti_simplelink_bim_name}_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),
]
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,
]
} else {
args += [
"-da",
"sha256",
]
}
if (defined(invoker.ota_args)) {
args += invoker.ota_args
}
}
}
group(simplelink_target_name) {
data_deps = [ ":$final_target" ]
if (defined(invoker.data_deps)) {
data_deps += invoker.data_deps
}
}
}