Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[platform] [WIP] make setup constants configurable in gn #2296

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/BUILDING-GN.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ To find dependency paths:
gn path out/host //src/transport/tests:tests //src/system
```

### Useful gn arguments

You can specify these gn arguments in the `--args=` section of the command to
customize your build.

- `chip_device_config_use_test_setup_pin_code`: The setup pincode of the
device if not found in the storage.
- `chip_device_config_use_test_setup_discriminator`: The discriminator of the
device if not found in the storage.

## Maintaining CHIP

If you make any change to the GN build system, the next build will regenerate
Expand Down
5 changes: 5 additions & 0 deletions examples/lock-app/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@
#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34

// Use a default pairing code if one hasn't been provisioned in flash.
#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 12345678
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
#endif

// For convenience, Chip Security Test Mode can be enabled and the
// requirement for authentication in various protocols can be disabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
#define CHIP_PROJECT_CONFIG_H

// Use a default pairing code if one hasn't been provisioned in flash.
#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 12345678
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
#endif

#endif // CHIP_PROJECT_CONFIG_H
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@
#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34

// Use a default pairing code if one hasn't been provisioned in flash.
#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 12345678
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
#endif

/**
* CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER
Expand Down
19 changes: 19 additions & 0 deletions gn_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ else
echo "Hint: Set \$EFR32_SDK_ROOT to enable building for EFR32"
fi

opts=$(getopt --longoptions "pincode:,discriminator:" -n "$0" --options "" -- "$@")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disagree with creating new bespoke options here, instead we could just generically accept args:

gn_build.sh chip_device_config_use_test_setup_pin_code=12345

But really, if you want a custom configuration, I'd actually recommend not using gn_build.sh at all and following the documented instructions for creating a custom configuration.

gn_build.sh is more intended to build what CI builds, without any local deviations.

eval set --"$opts"

while [[ $# -gt 0 ]]; do
case "$1" in
--pincode)
extra_args+=" chip_device_config_use_test_setup_pin_code=$2"
shift 2
;;
--discriminator)
extra_args+=" chip_device_config_use_test_setup_discriminator=$2"
shift 2
;;
*)
break
;;
esac
done

echo

_chip_banner "Build: GN configure"
Expand Down
13 changes: 13 additions & 0 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {

# Time the firmware was built.
chip_device_config_firmware_build_time = ""

# Test setup pincode
chip_device_config_use_test_setup_pin_code = ""

# Test setup discriminator
chip_device_config_use_test_setup_discriminator = ""
}

config("platform_config") {
Expand All @@ -58,6 +64,13 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
defines += [ "CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_TIME=\"${chip_device_config_firmware_build_time}\"" ]
}

if (chip_device_config_use_test_setup_pin_code != "") {
defines += [ "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${chip_device_config_use_test_setup_pin_code}" ]
}
if (chip_device_config_use_test_setup_discriminator != "") {
defines += [ "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${chip_device_config_use_test_setup_discriminator}" ]
}

if (chip_device_platform == "darwin") {
frameworks = [
"CoreFoundation.framework",
Expand Down
7 changes: 5 additions & 2 deletions src/platform/nRF5/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE

#include <ble/CHIPBleServiceData.h>
#include <platform/ConfigurationManager.h>
#include <platform/internal/BLEManager.h>

#include <support/CodeUtils.h>
Expand Down Expand Up @@ -253,8 +254,10 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * devName)
}
else
{
// FIXME: the name should be derived from factory data
snprintf(devNameBuf, sizeof(devNameBuf), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, (uint32_t) 0);
uint32_t discriminator = 0;

ConfigurationMgr().GetSetupDiscriminator(discriminator);
snprintf(devNameBuf, sizeof(devNameBuf), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, discriminator);
devNameBuf[kMaxDeviceNameLength] = 0;
}

Expand Down