Skip to content

Commit

Permalink
cmake: sysbuild: fast_pair: add support for DTS-based memory maps
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Piszczek <[email protected]>
  • Loading branch information
kapi-no committed Oct 16, 2024
1 parent e533a5f commit cf0c164
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
80 changes: 79 additions & 1 deletion cmake/sysbuild/fast_pair_hex.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

function(fast_pair_hex)
function(fast_pair_hex_pm)
set(fp_partition_name bt_fast_pair)

set(
Expand Down Expand Up @@ -47,4 +47,82 @@ function(fast_pair_hex)
)
endfunction()

function(fast_pair_hex_dts)
set(fp_partition_name bt_fast_pair_partition)

sysbuild_dt_nodelabel(bt_fast_pair_partition_nodelabel IMAGE ${DEFAULT_IMAGE} NODELABEL "${fp_partition_name}")
sysbuild_dt_reg_addr(bt_fast_pair_partition_address IMAGE ${DEFAULT_IMAGE} PATH "${bt_fast_pair_partition_nodelabel}")

set(
fp_provisioning_data_hex
${CMAKE_BINARY_DIR}/modules/nrf/subsys/bluetooth/services/fast_pair/fp_provisioning_data.hex
)

set(fp_provisioning_data_address ${bt_fast_pair_partition_address})

add_custom_command(
OUTPUT
${fp_provisioning_data_hex}
COMMAND
${PYTHON_EXECUTABLE} ${ZEPHYR_NRF_MODULE_DIR}/scripts/nrf_provision/fast_pair/fp_provision_cli.py
-o ${fp_provisioning_data_hex} -a ${fp_provisioning_data_address}
-m ${FP_MODEL_ID} -k ${FP_ANTI_SPOOFING_KEY}
COMMENT
"Generating Fast Pair provisioning data hex file"
USES_TERMINAL
)

add_custom_target(
${fp_partition_name}_target
ALL
DEPENDS
"${fp_provisioning_data_hex}"
)

# TODO: Integrate the generated hex file into the merged hex file chain using a dedicated
# CMake function like the one suggested in the following draft PR:
# https://github.com/nrfconnect/sdk-nrf/pull/16425.
# Code below is highly experimental and needs to be improved.
if(NOT SB_CONFIG_SOC_SERIES_NRF54HX)
message(FATAL_ERROR "Fast Pair data provisioning using DTS partitions is only supported"
"for nRF54H series.")
endif()

set(OUTPUT_FILE_PATH ${APPLICATION_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr)

add_custom_command(
OUTPUT
${OUTPUT_FILE_PATH}/uicr_merged_fast_pair.hex
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/mergehex.py
-o ${OUTPUT_FILE_PATH}/uicr_merged_fast_pair.hex
${OUTPUT_FILE_PATH}/uicr_merged.hex
${fp_provisioning_data_hex}
DEPENDS
${fp_partition_name}_target
create_suit_artifacts
${fp_provisioning_data_hex}
COMMENT
"Merging Fast Pair provisioning data hex file"
USES_TERMINAL
)

add_custom_target(
${fp_partition_name}_hex_target
ALL
COMMAND ${CMAKE_COMMAND} -E copy ${OUTPUT_FILE_PATH}/uicr_merged_fast_pair.hex ${OUTPUT_FILE_PATH}/uicr_merged.hex
DEPENDS
${OUTPUT_FILE_PATH}/uicr_merged_fast_pair.hex
)
endfunction()

function(fast_pair_hex)
if(SB_CONFIG_PARTITION_MANAGER)
fast_pair_hex_pm()
else()
fast_pair_hex_dts()
endif()
endfunction()

fast_pair_hex()
2 changes: 1 addition & 1 deletion subsys/bluetooth/services/fast_pair/Kconfig.fast_pair
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ endif # BT_FAST_PAIR_GATT_SERVICE
config BT_FAST_PAIR_REGISTRATION_DATA
bool
default y
select PM_SINGLE_IMAGE
select PM_SINGLE_IMAGE if !(SOC_SERIES_NRF54HX)
help
Add Fast Pair registration data source files.

Expand Down
11 changes: 8 additions & 3 deletions subsys/bluetooth/services/fast_pair/fp_registration_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <string.h>
#include <zephyr/device.h>
#include <zephyr/storage/flash_map.h>
#include <pm_config.h>

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(fast_pair, CONFIG_BT_FAST_PAIR_LOG_LEVEL);
Expand All @@ -18,8 +17,14 @@ LOG_MODULE_DECLARE(fast_pair, CONFIG_BT_FAST_PAIR_LOG_LEVEL);
#include "fp_crypto.h"
#include "fp_registration_data.h"

#define FP_PARTITION_ID PM_BT_FAST_PAIR_ID
#define FP_PARTITION_SIZE PM_BT_FAST_PAIR_SIZE
#if IS_ENABLED(CONFIG_PARTITION_MANAGER_ENABLED)
#include <pm_config.h>
#define FP_PARTITION_ID PM_BT_FAST_PAIR_ID
#define FP_PARTITION_SIZE PM_BT_FAST_PAIR_SIZE
#else
#define FP_PARTITION_ID FIXED_PARTITION_ID(bt_fast_pair_partition)
#define FP_PARTITION_SIZE FIXED_PARTITION_SIZE(bt_fast_pair_partition)
#endif

static const uint8_t fp_magic[] = {0xFA, 0x57, 0xFA, 0x57};

Expand Down
5 changes: 4 additions & 1 deletion sysbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake)
set_config_bool(${DEFAULT_IMAGE} CONFIG_BT_FAST_PAIR y)

if(DEFINED FP_MODEL_ID AND DEFINED FP_ANTI_SPOOFING_KEY)
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/fast_pair_hex.cmake)
set(FP_DATA_PRESENT "y" CACHE INTERNAL "Fast Pair provisioning data provided" FORCE)
else()
message(WARNING "Fast Pair support is enabled but `FP_MODEL_ID` or `FP_ANTI_SPOOFING_KEY` were not provided, this is likely to cause a build error")
Expand Down Expand Up @@ -556,6 +555,10 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_post_cmake)
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/mesh_dfu_metadata.cmake)
endif()

if(FP_DATA_PRESENT)
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/fast_pair_hex.cmake)
endif()

include(${ZEPHYR_NRF_MODULE_DIR}/cmake/extensions.cmake)
if(SB_CONFIG_PARTITION_MANAGER)
# Run partition manager for each image before running CMake.
Expand Down

0 comments on commit cf0c164

Please sign in to comment.