Skip to content

Commit

Permalink
EFR32: Fix ARM arch setup when setting efr32_board in GN args (#1978)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mspang authored Aug 5, 2020
1 parent 3a23f73 commit 19e0c40
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 211 deletions.
File renamed without changes.
15 changes: 0 additions & 15 deletions examples/lock-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<CHIPProjectConfig.h>"
chip_device_project_config_include = "<CHIPProjectConfig.h>"
chip_project_config_include = "<CHIPProjectConfig.h>"
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/efr32/build_overrides
18 changes: 0 additions & 18 deletions examples/lock-app/efr32/build_overrides/chip.gni

This file was deleted.

18 changes: 0 additions & 18 deletions examples/lock-app/efr32/build_overrides/lwip.gni

This file was deleted.

18 changes: 0 additions & 18 deletions examples/lock-app/efr32/build_overrides/mbedtls.gni

This file was deleted.

18 changes: 0 additions & 18 deletions examples/lock-app/efr32/build_overrides/nlassert copy.gni

This file was deleted.

18 changes: 0 additions & 18 deletions examples/lock-app/efr32/build_overrides/nlassert.gni

This file was deleted.

19 changes: 0 additions & 19 deletions examples/lock-app/efr32/build_overrides/nlfaultinjection.gni

This file was deleted.

18 changes: 0 additions & 18 deletions examples/lock-app/efr32/build_overrides/nlio.gni

This file was deleted.

48 changes: 37 additions & 11 deletions gn/build/config/arm.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 1 addition & 2 deletions gn_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
11 changes: 5 additions & 6 deletions src/platform/EFR32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,9 +28,3 @@ inet_config_enable_ipv4 = false
inet_config_enable_dns_resolver = false

chip_build_tests = false

ble_platform_config_include = "<platform/EFR32/BlePlatformConfig.h>"
chip_device_platform_config_include = "<platform/EFR32/CHIPDevicePlatformConfig.h>"
chip_platform_config_include = "<platform/EFR32/CHIPPlatformConfig.h>"
inet_platform_config_include = "<platform/EFR32/InetPlatformConfig.h>"
system_platform_config_include = "<platform/EFR32/SystemPlatformConfig.h>"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
53 changes: 53 additions & 0 deletions third_party/efr32_sdk/efr32_board.gni
Original file line number Diff line number Diff line change
@@ -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.")
}

Loading

0 comments on commit 19e0c40

Please sign in to comment.