From 19e0c40685b4088e553479231d3f93d29928452e Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Wed, 5 Aug 2020 11:44:14 -0400 Subject: [PATCH] EFR32: Fix ARM arch setup when setting efr32_board in GN args (#1978) * EFR32: Fix ARM arch setup when setting efr32_board in GN args Currently examples/lock-app/efr32/args.gni tries to set the ARM architecture flags based on a condition: if (efr32_family == "efr32mg12") { arm_float_abi = "softfp" arm_fpu = "fpv4-sp-d16" } else if (efr32_family == "efr32mg21") { arm_float_abi = "hard" arm_fpu = "fpv5-sp-d16" } This isn't working if the board is set via GN args, which is preferred over the environment variable. The reason is that this file is providing the default arguments, and it's not possible to use the user arguments to set the defaults. We want explicit args to take precedence, and this is necessary for toolchain specific arguments to work. Fix this by adding a way for platforms to provide a config file that sets up the default ARM architecture flags (and which can account for other platform specific arguments in doing so, such as efr32_board). * Fix building for nRF5 via gn_build.sh * Share the build_overrides * Add efr32_sdk.gni back to build_overrides --- .../efr32 => }/build_overrides/efr32_sdk.gni | 0 examples/lock-app/efr32/args.gni | 15 ------ examples/lock-app/efr32/build_overrides | 1 + .../lock-app/efr32/build_overrides/chip.gni | 18 ------- .../lock-app/efr32/build_overrides/lwip.gni | 18 ------- .../efr32/build_overrides/mbedtls.gni | 18 ------- .../efr32/build_overrides/nlassert copy.gni | 18 ------- .../efr32/build_overrides/nlassert.gni | 18 ------- .../build_overrides/nlfaultinjection.gni | 19 ------- .../lock-app/efr32/build_overrides/nlio.gni | 18 ------- gn/build/config/arm.gni | 48 +++++++++++++---- gn_build.sh | 3 +- src/platform/EFR32/args.gni | 11 ++-- .../efr32_sdk/efr32_arm.gni | 17 ++++-- third_party/efr32_sdk/efr32_board.gni | 53 +++++++++++++++++++ third_party/efr32_sdk/efr32_sdk.gni | 48 ++--------------- 16 files changed, 112 insertions(+), 211 deletions(-) rename examples/{lock-app/efr32 => }/build_overrides/efr32_sdk.gni (100%) create mode 120000 examples/lock-app/efr32/build_overrides delete mode 100644 examples/lock-app/efr32/build_overrides/chip.gni delete mode 100644 examples/lock-app/efr32/build_overrides/lwip.gni delete mode 100644 examples/lock-app/efr32/build_overrides/mbedtls.gni delete mode 100644 examples/lock-app/efr32/build_overrides/nlassert copy.gni delete mode 100644 examples/lock-app/efr32/build_overrides/nlassert.gni delete mode 100644 examples/lock-app/efr32/build_overrides/nlfaultinjection.gni delete mode 100644 examples/lock-app/efr32/build_overrides/nlio.gni rename examples/lock-app/efr32/build_overrides/pigweed.gni => third_party/efr32_sdk/efr32_arm.gni (68%) create mode 100644 third_party/efr32_sdk/efr32_board.gni diff --git a/examples/lock-app/efr32/build_overrides/efr32_sdk.gni b/examples/build_overrides/efr32_sdk.gni similarity index 100% rename from examples/lock-app/efr32/build_overrides/efr32_sdk.gni rename to examples/build_overrides/efr32_sdk.gni diff --git a/examples/lock-app/efr32/args.gni b/examples/lock-app/efr32/args.gni index fa822f940c10d1..94284a87cc0de5 100644 --- a/examples/lock-app/efr32/args.gni +++ b/examples/lock-app/efr32/args.gni @@ -13,26 +13,11 @@ # limitations under the License. import("//build_overrides/chip.gni") -import("//build_overrides/efr32_sdk.gni") - import("${chip_root}/src/platform/EFR32/args.gni") -import("${efr32_sdk_build_root}/efr32_sdk.gni") efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") - mbedtls_target = efr32_sdk_target -if (efr32_family == "efr32mg12") { - arm_float_abi = "softfp" - arm_fpu = "fpv4-sp-d16" -} else if (efr32_family == "efr32mg21") { - arm_float_abi = "hard" - arm_fpu = "fpv5-sp-d16" -} - -arm_abi = "aapcs" -arm_cpu = "cortex-m4" - ble_project_config_include = "" chip_device_project_config_include = "" chip_project_config_include = "" diff --git a/examples/lock-app/efr32/build_overrides b/examples/lock-app/efr32/build_overrides new file mode 120000 index 00000000000000..e578e73312ebd1 --- /dev/null +++ b/examples/lock-app/efr32/build_overrides @@ -0,0 +1 @@ +../../build_overrides \ No newline at end of file diff --git a/examples/lock-app/efr32/build_overrides/chip.gni b/examples/lock-app/efr32/build_overrides/chip.gni deleted file mode 100644 index 23aafc1df7b3cd..00000000000000 --- a/examples/lock-app/efr32/build_overrides/chip.gni +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -declare_args() { - # Root directory for CHIP. - chip_root = "//third_party/connectedhomeip" -} diff --git a/examples/lock-app/efr32/build_overrides/lwip.gni b/examples/lock-app/efr32/build_overrides/lwip.gni deleted file mode 100644 index 9a50a46bae6a8b..00000000000000 --- a/examples/lock-app/efr32/build_overrides/lwip.gni +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -declare_args() { - # Root directory for lwIP. - lwip_root = "//third_party/connectedhomeip/third_party/lwip" -} diff --git a/examples/lock-app/efr32/build_overrides/mbedtls.gni b/examples/lock-app/efr32/build_overrides/mbedtls.gni deleted file mode 100644 index fff24c4f29f01f..00000000000000 --- a/examples/lock-app/efr32/build_overrides/mbedtls.gni +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -declare_args() { - # Root directory for mbedTLS. - mbedtls_root = "//third_party/connectedhomeip/third_party/mbedtls" -} diff --git a/examples/lock-app/efr32/build_overrides/nlassert copy.gni b/examples/lock-app/efr32/build_overrides/nlassert copy.gni deleted file mode 100644 index 30e8c701634664..00000000000000 --- a/examples/lock-app/efr32/build_overrides/nlassert copy.gni +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -declare_args() { - # Root directory for nlassert. - nlassert_root = "//third_party/connectedhomeip/third_party/nlassert" -} diff --git a/examples/lock-app/efr32/build_overrides/nlassert.gni b/examples/lock-app/efr32/build_overrides/nlassert.gni deleted file mode 100644 index 30e8c701634664..00000000000000 --- a/examples/lock-app/efr32/build_overrides/nlassert.gni +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -declare_args() { - # Root directory for nlassert. - nlassert_root = "//third_party/connectedhomeip/third_party/nlassert" -} diff --git a/examples/lock-app/efr32/build_overrides/nlfaultinjection.gni b/examples/lock-app/efr32/build_overrides/nlfaultinjection.gni deleted file mode 100644 index 155d765597d110..00000000000000 --- a/examples/lock-app/efr32/build_overrides/nlfaultinjection.gni +++ /dev/null @@ -1,19 +0,0 @@ -# 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. - -declare_args() { - # Root directory for nlfaultinjection. - nlfaultinjection_root = - "//third_party/connectedhomeip/third_party/nlfaultinjection" -} diff --git a/examples/lock-app/efr32/build_overrides/nlio.gni b/examples/lock-app/efr32/build_overrides/nlio.gni deleted file mode 100644 index f7d5ee6117e826..00000000000000 --- a/examples/lock-app/efr32/build_overrides/nlio.gni +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -declare_args() { - # Root directory for nlio. - nlio_root = "//third_party/connectedhomeip/third_party/nlio" -} diff --git a/gn/build/config/arm.gni b/gn/build/config/arm.gni index 7a7b2d3405e913..7826448bbc5446 100644 --- a/gn/build/config/arm.gni +++ b/gn/build/config/arm.gni @@ -12,29 +12,55 @@ # See the License for the specific language governing permissions and # limitations under the License. -assert(current_cpu == "arm" || current_cpu == "arm64") +if (current_cpu == "arm" || current_cpu == "arm64") { + declare_args() { + # Build file to import for ARM defaults. + arm_platform_config = "" + } + + # Allow platforms to override how ARM architecture flags are chosen by + # providing a file to import. + if (arm_platform_config != "") { + _platform_defaults = { + import(arm_platform_config) + } + } + + _defaults = { + arm_arch = "" + arm_cpu = "" + arm_tune = "" + arm_fpu = "" + arm_float_abi = "" + arm_abi = "" + arm_use_thumb = true + + # Update defaults with platform values, if any. + if (arm_platform_config != "") { + forward_variables_from(_platform_defaults, "*") + } + } -if (current_cpu == "arm") { declare_args() { # ARM architecture (value for -march flag). - arm_arch = "" + arm_arch = _defaults.arm_arch # ARM CPU (value for -mcpu flag). - arm_cpu = "" + arm_cpu = _defaults.arm_cpu # ARM tuning (value for -mtune flag). - arm_tune = "" + arm_tune = _defaults.arm_tune # ARM FPU (value for -mfpu flag). - arm_fpu = "" + arm_fpu = _defaults.arm_fpu - # ARM float ABI (value for -mfloat-api flag). - arm_float_abi = "" + # ARM float ABI (value for -mfloat-abi flag). + arm_float_abi = _defaults.arm_float_abi - # ARM ABI (value for -mapi flag). - arm_abi = "" + # ARM ABI (value for -mabi flag). + arm_abi = _defaults.arm_abi # ARM thumb instruction set (value for -mthumb flag). - arm_use_thumb = true + arm_use_thumb = _defaults.arm_use_thumb } } diff --git a/gn_build.sh b/gn_build.sh index 61c4d930c66873..13baa92a1a3d74 100755 --- a/gn_build.sh +++ b/gn_build.sh @@ -89,10 +89,9 @@ echo # EFR32 SDK setup efr32_sdk_args="" -extra_args="" if [[ -d "$EFR32_SDK_ROOT/protocol/" ]]; then - efr32_sdk_args+="efr32_sdk_root=\"$EFR32_SDK_ROOT\"" + efr32_sdk_args+="efr32_sdk_root=\"$EFR32_SDK_ROOT\" efr32_board=\"$EFR32_BOARD\"" extra_args+=" $efr32_sdk_args enable_efr32_builds=true" echo 'To build the EFR32 lock sample as a standalone project': echo "(cd $CHIP_ROOT/examples/lock-app/efr32; gn gen out/debug --args='$efr32_sdk_args'; ninja -C out/debug)" diff --git a/src/platform/EFR32/args.gni b/src/platform/EFR32/args.gni index 1ae52e6e0f0c0c..2f0f3c674166a3 100644 --- a/src/platform/EFR32/args.gni +++ b/src/platform/EFR32/args.gni @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build_overrides/efr32_sdk.gni") + +# ARM architecture flags will be set based on efr32_family. +arm_platform_config = "${efr32_sdk_build_root}/efr32_arm.gni" + device_platform = "efr32" lwip_platform = "efr32" @@ -23,9 +28,3 @@ inet_config_enable_ipv4 = false inet_config_enable_dns_resolver = false chip_build_tests = false - -ble_platform_config_include = "" -chip_device_platform_config_include = "" -chip_platform_config_include = "" -inet_platform_config_include = "" -system_platform_config_include = "" diff --git a/examples/lock-app/efr32/build_overrides/pigweed.gni b/third_party/efr32_sdk/efr32_arm.gni similarity index 68% rename from examples/lock-app/efr32/build_overrides/pigweed.gni rename to third_party/efr32_sdk/efr32_arm.gni index 0aaf7c4d226844..2e871b39139b37 100644 --- a/examples/lock-app/efr32/build_overrides/pigweed.gni +++ b/third_party/efr32_sdk/efr32_arm.gni @@ -12,9 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -declare_args() { - # Location of the Pigweed repository. - dir_pigweed = "//third_party/connectedhomeip/third_party/pigweed/repo" -} +import("efr32_board.gni") + +arm_arch = "armv7e-m" +arm_abi = "aapcs" +arm_cpu = "cortex-m4" -import("$dir_pigweed/modules.gni") +if (efr32_family == "efr32mg12") { + arm_float_abi = "softfp" + arm_fpu = "fpv4-sp-d16" +} else if (efr32_family == "efr32mg21") { + arm_float_abi = "hard" + arm_fpu = "fpv5-sp-d16" +} diff --git a/third_party/efr32_sdk/efr32_board.gni b/third_party/efr32_sdk/efr32_board.gni new file mode 100644 index 00000000000000..5208df0aee99af --- /dev/null +++ b/third_party/efr32_sdk/efr32_board.gni @@ -0,0 +1,53 @@ +# 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. + +declare_args() { + # EFR32 board used + efr32_board = "" +} + +if (efr32_board == "") { + efr32_board = getenv("EFR32_BOARD") +} + +assert(efr32_board != "", "efr32_board must be specified") + +# Differentiate between boards +# - BRD4304A / SLWSTK6000B / MGM12P Module / 2.4GHz@19dBm +# - BRD4161A / SLWSTK6000B / Wireless Starter Kit / 2.4GHz@19dBm +# - BRD4166A / SLTB004A / Thunderboard Sense 2 / 2.4GHz@10dBm +# - BRD4170A / SLWSTK6000B / Multiband Wireless Starter Kit / 2.4GHz@19dBm, 915MHz@19dBm, 868MHz@19dBm +# - BRD4180A / SLWSTK6006A / MG21 Module / 2.4GHz@20dBm + +if (efr32_board == "BRD4304A") { + efr32_family = "efr32mg12" + efr32_mcu = "EFR32MG12P432F1024GM48" +} else if (efr32_board == "BRD4161A") { + efr32_family = "efr32mg12" + efr32_mcu = "EFR32MG12P432F1024GL125" +} else if (efr32_board == "BRD4166A") { + efr32_family = "efr32mg12" + efr32_mcu = "EFR32MG12P332F1024GL125" +} else if (efr32_board == "BRD4170A") { + efr32_family = "efr32mg12" + efr32_mcu = "EFR32MG12P433F1024GM68" +} else if (efr32_board == "BRD4180A") { + efr32_family = "efr32mg21" + efr32_mcu = "EFR32MG21A020F1024IM32" +} else { + print( + "Please provide a valid value for EFR32_BOARD env variable (currently supported BRD4304A, BRD4161A, BRD4166A, BRD4170A or BRD4180A)") + assert(false, "The board ${efr32_board} is unsupported as for now.") +} + diff --git a/third_party/efr32_sdk/efr32_sdk.gni b/third_party/efr32_sdk/efr32_sdk.gni index 93323814691830..471fd48431e62b 100644 --- a/third_party/efr32_sdk/efr32_sdk.gni +++ b/third_party/efr32_sdk/efr32_sdk.gni @@ -15,60 +15,19 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/mbedtls.gni") +import("efr32_board.gni") + declare_args() { # Location of the efr32 SDK. efr32_sdk_root = "" - - # EFR32 board used - efr32_board = "" - - # EFR32 chip family - efr32_family = "" - - # EFR32 MCU - efr32_mcu = "" -} - -if (efr32_board == "") { - efr32_board = getenv("EFR32_BOARD") } -assert(efr32_board != "", "The EFR32_BOARD env must be specified") - if (efr32_sdk_root == "") { efr32_sdk_root = getenv("EFR32_SDK_ROOT") } assert(efr32_sdk_root != "", "efr32_sdk_root must be specified") -# Differentiate between boards -# - BRD4304A / SLWSTK6000B / MGM12P Module / 2.4GHz@19dBm -# - BRD4161A / SLWSTK6000B / Wireless Starter Kit / 2.4GHz@19dBm -# - BRD4166A / SLTB004A / Thunderboard Sense 2 / 2.4GHz@10dBm -# - BRD4170A / SLWSTK6000B / Multiband Wireless Starter Kit / 2.4GHz@19dBm, 915MHz@19dBm, 868MHz@19dBm -# - BRD4180A / SLWSTK6006A / MG21 Module / 2.4GHz@20dBm - -if (efr32_board == "BRD4304A") { - efr32_family = "efr32mg12" - efr32_mcu = "EFR32MG12P432F1024GM48" -} else if (efr32_board == "BRD4161A") { - efr32_family = "efr32mg12" - efr32_mcu = "EFR32MG12P432F1024GL125" -} else if (efr32_board == "BRD4166A") { - efr32_family = "efr32mg12" - efr32_mcu = "EFR32MG12P332F1024GL125" -} else if (efr32_board == "BRD4170A") { - efr32_family = "efr32mg12" - efr32_mcu = "EFR32MG12P433F1024GM68" -} else if (efr32_board == "BRD4180A") { - efr32_family = "efr32mg21" - efr32_mcu = "EFR32MG21A020F1024IM32" -} else { - print( - "Please provide a valid value for EFR32_BOARD env variable (currently supported BRD4304A, BRD4161A, BRD4166A, BRD4170A or BRD4180A)") - assert(false, "The board ${efr32_board} is unsupported as for now.") -} - # Defines an efr32 SDK build target. # # Parameters: @@ -168,8 +127,7 @@ template("efr32_sdk") { } defines = [ -"__STARTUP_CLEAR_BSS", - + "__STARTUP_CLEAR_BSS", "HARD_FAULT_LOG_ENABLE", "RETARGET_VCOM", "RETARGET_USART0",