| # 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/cyw30739_sdk.gni") |
| |
| import("${chip_root}/src/platform/device.gni") |
| |
| declare_args() { |
| # Location of the CYW30739 SDK. |
| cyw30739_sdk_root = "${cyw30739_sdk_build_root}/repos" |
| cyw30739_sdk_verbose = false |
| cyw30739_sdk_debug = 0 |
| |
| # Matter DAC in the DER format. |
| matter_dac = "${chip_root}/credentials/test/attestation/Chip-Test-DAC-FFF2-8002-0010-Cert.der" |
| |
| # Matter DAC EC key in the DER format. |
| matter_dac_key = "${chip_root}/credentials/test/attestation/Chip-Test-DAC-FFF2-8002-0010-Key.der" |
| |
| # Matter PAI certificate in the DER format. |
| matter_pai = "${chip_root}/credentials/test/attestation/Chip-Test-PAI-FFF2-NoPID-Cert.der" |
| |
| # Matter Certification Declaration in the DER format. |
| matter_cd = "${chip_root}/credentials/test/certification-declaration/Chip-Test-CD-FFF2-8001-8002.der" |
| } |
| |
| assert(cyw30739_sdk_root != "", "cyw30739_sdk_root must be specified") |
| |
| cyw30739_sdk_bsp_design_modus_dir = |
| "${cyw30739_sdk_build_root}/bsp_design_modus" |
| cyw30739_sdk_baselib_dir = "${cyw30739_sdk_root}/30739A0/COMPONENT_30739A0" |
| cyw30739_sdk_board_dir = "${cyw30739_sdk_root}/CYW930739M2EVB-01" |
| cyw30739_sdk_include_dir = "${cyw30739_sdk_root}/btsdk-include" |
| cyw30739_sdk_patch_dir = |
| "${cyw30739_sdk_baselib_dir}/internal/30739A0/patches_CYW930739M2EVB_01" |
| cyw30739_sdk_platform_dir = "${cyw30739_sdk_baselib_dir}/platforms" |
| cyw30739_sdk_scripts_dir = "${cyw30739_sdk_baselib_dir}/make/scripts" |
| cyw30739_sdk_btp_file = "${cyw30739_sdk_build_root}/flash.btp" |
| cyw30739_sdk_patch_sym_file = "${cyw30739_sdk_patch_dir}/patch.sym" |
| |
| cyw30739_sdk_tools_dir = "${cyw30739_sdk_root}/btsdk-tools/" |
| if (host_os == "linux") { |
| cyw30739_sdk_tools_dir += "Linux64" |
| } else if (host_os == "mac") { |
| cyw30739_sdk_tools_dir += "OSX" |
| } else if (host_os == "win") { |
| cyw30739_sdk_tools_dir += "Windows" |
| } |
| |
| btp_reader_args = |
| [ "--btp=" + rebase_path(cyw30739_sdk_btp_file, root_build_dir) ] |
| if (chip_enable_ota_requestor) { |
| btp_reader_args += [ "--enable_ota" ] |
| } |
| btp = exec_script("${cyw30739_sdk_build_root}/btp_reader.py", |
| btp_reader_args, |
| "json", |
| [ cyw30739_sdk_btp_file ]) |
| |
| cyw30739_sdk_crt_entry = "spar_crt_setup" |
| |
| template("cyw30739_sdk_script") { |
| action(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "script_file_name", |
| "sources", |
| "outputs", |
| ]) |
| |
| script_file = "${cyw30739_sdk_scripts_dir}/${script_file_name}" |
| |
| script = "${build_root}/gn_run_binary.py" |
| |
| inputs = [ script_file ] |
| |
| args = [ |
| "bash", |
| "--norc", |
| "--noprofile", |
| rebase_path(script_file, root_build_dir), |
| "--scripts=" + rebase_path(cyw30739_sdk_scripts_dir, root_build_dir), |
| ] |
| if (defined(invoker.args)) { |
| args += invoker.args |
| } |
| if (cyw30739_sdk_verbose) { |
| args += [ "--verbose" ] |
| } |
| } |
| } |
| |
| # Defines a CYW30739 SDK build target. |
| # |
| # Parameters: |
| # cyw30739_sdk_root - The location of the erf32 SDK. |
| # sources - The sources files to build. |
| template("cyw30739_sdk") { |
| if (defined(invoker.cyw30739_sdk_root)) { |
| cyw30739_sdk_root = invoker.cyw30739_sdk_root |
| } |
| |
| assert(cyw30739_sdk_root != "", "cyw30739_sdk_root must be specified") |
| |
| config("${target_name}_config") { |
| include_dirs = [] |
| defines = [] |
| libs = [] |
| |
| if (defined(invoker.include_dirs)) { |
| include_dirs += invoker.include_dirs |
| } |
| |
| if (defined(invoker.defines)) { |
| defines += invoker.defines |
| } |
| |
| include_dirs += [ |
| "${cyw30739_sdk_baselib_dir}/WICED/common", |
| "${cyw30739_sdk_baselib_dir}/include", |
| "${cyw30739_sdk_baselib_dir}/include/hal", |
| "${cyw30739_sdk_baselib_dir}/include/internal", |
| "${cyw30739_sdk_baselib_dir}/include/stack", |
| "${cyw30739_sdk_baselib_dir}/platforms", |
| "${cyw30739_sdk_board_dir}", |
| "${cyw30739_sdk_build_root}/include", |
| "${cyw30739_sdk_include_dir}", |
| ] |
| |
| cflags = [ "--specs=nano.specs" ] |
| if (is_debug) { |
| cflags += [ "-Wno-unused" ] |
| } |
| |
| ldflags = [ |
| "--specs=nano.specs", |
| "-Wl,--entry=${cyw30739_sdk_crt_entry}", |
| "-Wl,--just-symbols=" + |
| rebase_path(cyw30739_sdk_patch_sym_file, root_build_dir), |
| "-nostartfiles", |
| ] |
| } |
| |
| cyw30739_sdk_script("${target_name}_gen_lib_installer") { |
| script_file_name = "bt_gen_lib_installer.bash" |
| |
| lib_installer_file = "${root_gen_dir}/lib_installer.c" |
| |
| args = [ "--out=" + rebase_path(lib_installer_file, root_build_dir) ] |
| |
| outputs = [ lib_installer_file ] |
| } |
| |
| source_set(target_name) { |
| sources = [ |
| "${cyw30739_sdk_baselib_dir}/WICED/common/spar_setup.c", |
| "${cyw30739_sdk_baselib_dir}/platforms/platform_entropy.c", |
| "${cyw30739_sdk_baselib_dir}/platforms/platform_nvram.h", |
| "${cyw30739_sdk_baselib_dir}/platforms/platform_retarget_lock.h", |
| "${cyw30739_sdk_baselib_dir}/platforms/platform_stdio.c", |
| "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform.c", |
| "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform_bt_cfg.c", |
| "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform_bt_cfg.h", |
| "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform_memory.c", |
| "${cyw30739_sdk_baselib_dir}/platforms/wiced_platform_os.c", |
| "${cyw30739_sdk_board_dir}/gpio_button.c", |
| "${cyw30739_sdk_board_dir}/gpio_button.h", |
| "${cyw30739_sdk_board_dir}/platform.c", |
| "${cyw30739_sdk_board_dir}/platform_button.c", |
| "${cyw30739_sdk_board_dir}/wiced_platform.h", |
| "${cyw30739_sdk_board_dir}/wiced_platform_memory.h", |
| "${cyw30739_sdk_board_dir}/wiced_platform_os.h", |
| "${cyw30739_sdk_bsp_design_modus_dir}/cycfg_notices.h", |
| "${cyw30739_sdk_bsp_design_modus_dir}/cycfg_pins.c", |
| "${cyw30739_sdk_bsp_design_modus_dir}/cycfg_pins.h", |
| "${cyw30739_sdk_bsp_design_modus_dir}/cycfg_routing.h", |
| "${cyw30739_sdk_build_root}/include/auto_flags.h", |
| "${cyw30739_sdk_build_root}/include/wiced_button_manager.h", |
| "${cyw30739_sdk_build_root}/include/wiced_led_manager.h", |
| "${cyw30739_sdk_build_root}/src/platform_retarget_lock.c", |
| "${cyw30739_sdk_build_root}/src/wiced_button_manager.c", |
| "${cyw30739_sdk_build_root}/src/wiced_led_manager.c", |
| ] |
| |
| if (chip_enable_ota_requestor) { |
| sources += [ |
| "${cyw30739_sdk_build_root}/include/ota_fw_upgrade.h", |
| "${cyw30739_sdk_build_root}/src/ota_fw_upgrade.c", |
| ] |
| } |
| |
| sources += get_target_outputs(":${target_name}_gen_lib_installer") |
| |
| if (defined(invoker.sources)) { |
| sources += invoker.sources |
| } |
| |
| defines = [ |
| "CHIP_HAVE_CONFIG_H=1", |
| "CY_PLATFORM_SWDCK=WICED_P05", |
| "CY_PLATFORM_SWDIO=WICED_P03", |
| "ENABLE_DEBUG=${cyw30739_sdk_debug}", |
| "SPAR_CRT_SETUP=${cyw30739_sdk_crt_entry}", |
| "XS_LOCATION_ACTIVE=${btp.ConfigXS1Location}", |
| "XS_LOCATION_UPGRADE=${btp.ConfigXS2Location}", |
| ] |
| if (chip_enable_ota_requestor) { |
| defines += [ "BLE_OTA_FW_UPGRADE=1" ] |
| } |
| |
| public_configs = [ ":${target_name}_config" ] |
| |
| deps = [ ":${target_name}_gen_lib_installer" ] |
| } |
| } |
| |
| template("cyw30739_sdk_pre_build") { |
| action(target_name) { |
| script_file = "${cyw30739_sdk_build_root}/scripts/wiced-gen-ld.pl" |
| |
| script = "${build_root}/gn_run_binary.py" |
| |
| inputs = [ |
| "${cyw30739_sdk_build_root}/btp_reader.py", |
| script_file, |
| ] |
| |
| sources = [ cyw30739_sdk_btp_file ] |
| |
| outputs = [ invoker.ldscript_file ] |
| |
| args = [ |
| "perl", |
| "-I", |
| rebase_path(cyw30739_sdk_scripts_dir, root_build_dir), |
| rebase_path(script_file, root_build_dir), |
| "FLASH0_BEGIN_ADDR=${btp.DLConfigSSLocation}", |
| "FLASH0_LENGTH=0x00100000", |
| "XIP_DS_OFFSET=${btp.ConfigXS1DS1Offset}", |
| "XIP_LEN=${btp.ConfigXS1Length}", |
| "SRAM_BEGIN_ADDR=0x00200000", |
| "SRAM_LENGTH=0x00070000", |
| "AON_AREA_END=0x00284000", |
| "ISTATIC_BEGIN=0x500C00", |
| "ISTATIC_LEN=0x400", |
| "NUM_PATCH_ENTRIES=256", |
| "BTP=" + rebase_path(cyw30739_sdk_btp_file, root_build_dir), |
| rebase_path(cyw30739_sdk_patch_sym_file, root_build_dir), |
| "out=" + rebase_path(invoker.ldscript_file, root_build_dir), |
| ] |
| } |
| } |
| |
| template("cyw30739_sdk_post_build") { |
| output_base_path = "${root_out_dir}/${invoker.output_base_name}" |
| elf = "${output_base_path}.elf" |
| hex = "${output_base_path}_download.hex" |
| ss_hex = "${output_base_path}.ss.hex" |
| ds_hex = "${output_base_path}.ds.hex" |
| xs_hex = "${output_base_path}.xs.hex" |
| ss_hdf = "${output_base_path}.ss.hdf" |
| ss_cgs = "${output_base_path}.ss.cgs" |
| empty_cgs = "${output_base_path}.empty.cgs" |
| cgs = "${output_base_path}.cgs" |
| cx_cgs = "${output_base_path}.cx.cgs" |
| hdf = "${root_out_dir}/configdef30739A0.hdf" |
| |
| patched_cgs_args = |
| exec_script("${build_root}/gn_run_binary.py", |
| [ |
| "perl", |
| rebase_path("${cyw30739_sdk_scripts_dir}/wiced-bdaddr.pl", |
| root_build_dir), |
| "30739A0", |
| rebase_path(cyw30739_sdk_btp_file, root_build_dir), |
| "-O", |
| "DLConfigBD_ADDRBase:default", |
| ], |
| "list lines", |
| [ "${cyw30739_sdk_scripts_dir}/wiced-bdaddr.pl" ]) |
| |
| cgs_args = [] |
| foreach(arg, patched_cgs_args) { |
| cgs_args += string_split(arg) |
| } |
| |
| group(target_name) { |
| deps = [ ":${target_name}_merge_hex" ] |
| if (chip_enable_ota_requestor) { |
| deps += [ ":${target_name}_ota_image" ] |
| } |
| |
| data_deps = [ |
| ":${target_name}_btp", |
| ":${target_name}_disassemble", |
| ":${target_name}_hci_id", |
| ":${target_name}_minidriver", |
| ] |
| } |
| |
| action("${target_name}_merge_hex") { |
| config_header = |
| "${chip_root}/src/platform/Infineon/CYW30739/CYW30739Config.h" |
| |
| script = "${cyw30739_sdk_build_root}/merge_hex.py" |
| |
| outputs = [ hex ] |
| |
| sources = [ |
| config_header, |
| ds_hex, |
| matter_cd, |
| matter_dac, |
| matter_dac_key, |
| matter_pai, |
| ss_hex, |
| xs_hex, |
| ] |
| |
| args = [ |
| "--output=" + rebase_path(hex, root_build_dir), |
| "--ss_hex=" + rebase_path(ss_hex, root_build_dir), |
| "--ds_hex=" + rebase_path(ds_hex, root_build_dir), |
| "--xs_hex=" + rebase_path(xs_hex, root_build_dir), |
| "--config_header=" + rebase_path(config_header, root_build_dir), |
| "--config=DAC:file:" + rebase_path(matter_dac, root_build_dir), |
| "--config=DACKey:file:" + rebase_path(matter_dac_key, root_build_dir), |
| "--config=PAICert:file:" + rebase_path(matter_pai, root_build_dir), |
| "--config=CertDeclaration:file:" + rebase_path(matter_cd, root_build_dir), |
| ] |
| foreach(arg, cgs_args) { |
| options = [] |
| options = string_split(arg, ":") |
| if (options[0] == "DLConfigBD_ADDRBase") { |
| args += [ "--config=ExtendedAddress:address:" + options[1] ] |
| } |
| } |
| |
| deps = [ |
| ":${invoker.target_name}_gen_ds_hex", |
| ":${invoker.target_name}_gen_ss_hex", |
| ":${invoker.target_name}_gen_xs_hex", |
| ] |
| } |
| |
| action("${target_name}_gen_ss_hex") { |
| script = "${build_root}/gn_run_binary.py" |
| |
| outputs = [ ss_hex ] |
| |
| sources = [ |
| cyw30739_sdk_btp_file, |
| empty_cgs, |
| ] |
| |
| args = [ |
| rebase_path("${cyw30739_sdk_tools_dir}/CGS/cgs", root_build_dir), |
| "-D", |
| rebase_path(root_out_dir, root_build_dir), |
| "-I", |
| rebase_path(ss_hex, root_build_dir), |
| "-B", |
| rebase_path(cyw30739_sdk_btp_file, root_build_dir), |
| "--cgs-files", |
| rebase_path(empty_cgs, root_build_dir), |
| ] |
| args += cgs_args |
| |
| deps = [ ":${invoker.target_name}_gen_ss_cgs" ] |
| } |
| |
| action("${target_name}_gen_ds_hex") { |
| cgs_map = "${cgs}.map" |
| script = "${build_root}/gn_run_binary.py" |
| |
| outputs = [ |
| cgs_map, |
| ds_hex, |
| ] |
| |
| sources = [ |
| cx_cgs, |
| cyw30739_sdk_btp_file, |
| ] |
| |
| inputs = [ hdf ] |
| |
| args = [ |
| rebase_path("${cyw30739_sdk_tools_dir}/CGS/cgs", root_build_dir), |
| "-D", |
| rebase_path(root_out_dir, root_build_dir), |
| "-M", |
| rebase_path(cgs_map, root_build_dir), |
| "-I", |
| rebase_path(ds_hex, root_build_dir), |
| "-B", |
| rebase_path(cyw30739_sdk_btp_file, root_build_dir), |
| "--cgs-files", |
| rebase_path(cx_cgs, root_build_dir), |
| "--paramoverride", |
| "DLConfigFixedHeader:0", |
| ] |
| |
| deps = [ |
| ":${invoker.target_name}_compress_cgs_data", |
| ":${invoker.target_name}_hdf", |
| ] |
| } |
| |
| action("${target_name}_gen_xs_hex") { |
| script = "${build_root}/gn_run_binary.py" |
| |
| outputs = [ xs_hex ] |
| |
| sources = [ elf ] |
| |
| args = [ |
| "arm-none-eabi-objcopy", |
| "--only-section=.app_xip_area", |
| "--output-target=ihex", |
| rebase_path(elf, root_build_dir), |
| rebase_path(xs_hex, root_build_dir), |
| ] |
| |
| deps = [ ":${invoker.executable_target}" ] |
| } |
| |
| action("${target_name}_compress_cgs_data") { |
| script = "${cyw30739_sdk_build_root}/compress_cgs_data.py" |
| |
| outputs = [ cx_cgs ] |
| |
| sources = [ cgs ] |
| |
| args = [ |
| "--output=" + rebase_path(cx_cgs, root_build_dir), |
| "--input=" + rebase_path(cgs, root_build_dir), |
| "--lzss_tool=" + |
| rebase_path(cyw30739_sdk_tools_dir + "/lzss/lzss", root_build_dir), |
| ] |
| |
| deps = [ ":${invoker.target_name}_gen_cgs" ] |
| } |
| |
| action("${target_name}_gen_ss_cgs") { |
| script = "${cyw30739_sdk_build_root}/scripts/gen_ss_cgs.py" |
| |
| outputs = [ |
| ss_hdf, |
| ss_cgs, |
| empty_cgs, |
| ] |
| |
| args = [ |
| "--ss_hdf=" + rebase_path(ss_hdf, root_build_dir), |
| "--ss_cgs=" + rebase_path(ss_cgs, root_build_dir), |
| "--empty_cgs=" + rebase_path(empty_cgs, root_build_dir), |
| ] |
| } |
| |
| action("${target_name}_gen_cgs") { |
| script_file = "${cyw30739_sdk_scripts_dir}/wiced-gen-cgs.pl" |
| |
| script = "${build_root}/gn_run_binary.py" |
| |
| inputs = [ script_file ] |
| |
| sources = [ |
| "${cyw30739_sdk_patch_dir}/patch.cgs", |
| "${cyw30739_sdk_platform_dir}/platform.cgs", |
| "${cyw30739_sdk_platform_dir}/platform_xip.cgs", |
| cyw30739_sdk_btp_file, |
| elf, |
| hdf, |
| invoker.ldscript_file, |
| ] |
| |
| outputs = [ cgs ] |
| |
| args = [ |
| "perl", |
| "-I", |
| rebase_path(cyw30739_sdk_scripts_dir, root_build_dir), |
| rebase_path(script_file, root_build_dir), |
| "${cyw30739_sdk_crt_entry}.entry", |
| "out=" + rebase_path(cgs, root_build_dir), |
| ] |
| foreach(source, sources) { |
| args += [ rebase_path(source, root_build_dir) ] |
| } |
| |
| deps = [ |
| ":${invoker.executable_target}", |
| ":${invoker.pre_build_target}", |
| ":${invoker.target_name}_hdf", |
| ] |
| } |
| |
| action("${target_name}_disassemble") { |
| asm = "${output_base_path}.asm" |
| |
| script = "${build_root}/gn_run_binary.py" |
| |
| outputs = [ asm ] |
| |
| sources = [ elf ] |
| |
| args = [ |
| "bash", |
| "--norc", |
| "--noprofile", |
| "-c", |
| "arm-none-eabi-objdump --disassemble " + |
| rebase_path(elf, root_build_dir) + " > " + |
| rebase_path(asm, root_build_dir), |
| ] |
| |
| deps = [ ":${invoker.executable_target}" ] |
| } |
| |
| copy("${target_name}_btp") { |
| sources = [ "${cyw30739_sdk_btp_file}" ] |
| outputs = [ "${output_base_path}.btp" ] |
| } |
| |
| copy("${target_name}_hdf") { |
| sources = |
| [ "${cyw30739_sdk_baselib_dir}/internal/30739A0/configdef30739A0.hdf" ] |
| outputs = [ hdf ] |
| } |
| |
| copy("${target_name}_hci_id") { |
| sources = [ "${cyw30739_sdk_platform_dir}/IDFILE.txt" ] |
| outputs = [ "${output_base_path}_hci_id.txt" ] |
| } |
| |
| copy("${target_name}_minidriver") { |
| sources = [ "${cyw30739_sdk_platform_dir}/minidriver.hex" ] |
| outputs = [ "${root_out_dir}/{{source_file_part}}" ] |
| } |
| |
| write_file("${root_out_dir}/chipload_flags.txt", "-NOHCIRESET") |
| |
| action("${target_name}_ota_image") { |
| script = "${cyw30739_sdk_build_root}/gen_ota_image.py" |
| |
| binary = "${output_base_path}.bin" |
| |
| outputs = [ binary ] |
| |
| sources = [ |
| ds_hex, |
| xs_hex, |
| ] |
| |
| args = [ |
| "--binary=" + rebase_path(binary, root_build_dir), |
| "--ds_hex=" + rebase_path(ds_hex, root_build_dir), |
| "--xs_hex=" + rebase_path(xs_hex, root_build_dir), |
| "--lzss_tool=" + |
| rebase_path(cyw30739_sdk_tools_dir + "/lzss/lzss", root_build_dir), |
| "--active_xs_len=${btp.ConfigXS1Length}", |
| "--upgrade_xs_len=${btp.ConfigXS2Length}", |
| "--project_config=" + |
| rebase_path("//include/CHIPProjectConfig.h", root_build_dir), |
| "--ota_image_tool=" + |
| rebase_path("${chip_root}/src/app/ota_image_tool.py", root_build_dir), |
| ] |
| |
| deps = [ |
| ":${invoker.target_name}_gen_ds_hex", |
| ":${invoker.target_name}_gen_xs_hex", |
| ] |
| } |
| } |