This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit ec8f533678347a8f81de55d311ca289aec58333c Author: Kai Cheng <[email protected]> AuthorDate: Thu Nov 5 14:15:50 2026 +0800 wireless/bluetooth/zblue: Add build of the Zephyr Bluetooth host Add CONFIG_ZBLUE and the Make and CMake builds: - download the Zephyr release CONFIG_ZBLUE_REF (default v4.5.0) from GitHub, check it against CONFIG_ZBLUE_SHA256 and unpack only the directories used by the host; - resolve the Zephyr configuration CONFIG_ZBLUE_CONF and generate the syscall headers; - select the host sources from the resolved options in the same way as the upstream CMakeLists.txt files; - link the objects into one relocatable object. Some of them (e.g. services/gap_svc.c) only add entries to an iterable section and have no symbol referenced from elsewhere, so they would not be pulled out of a static library. The NuttX work queues used by the porting layer are selected: CONFIG_SCHED_WORKQUEUE in the flat build, CONFIG_LIBC_USRWORK in the protected and kernel builds. Cryptography uses the PSA API of apps/crypto/mbedtls; the options the host needs are selected. The thread-specific data used by the porting layer needs CONFIG_TLS_NELEM. Only the Linux simulator is supported for now: the initialized iterable RAM sections of the host (net_buf pools) are placed after .data and are not yet initialized by the board startup code, and the sections are found through the ELF __start_/__stop_ symbols. Signed-off-by: Kai Cheng <[email protected]> --- wireless/bluetooth/zblue/.gitignore | 3 + wireless/bluetooth/zblue/CMakeLists.txt | 251 ++++++++++++++++++++++++++++++++ wireless/bluetooth/zblue/Kconfig | 86 +++++++++++ wireless/bluetooth/zblue/Make.defs | 25 ++++ wireless/bluetooth/zblue/Makefile | 201 +++++++++++++++++++++++++ 5 files changed, 566 insertions(+) diff --git a/wireless/bluetooth/zblue/.gitignore b/wireless/bluetooth/zblue/.gitignore new file mode 100644 index 000000000..49603ea57 --- /dev/null +++ b/wireless/bluetooth/zblue/.gitignore @@ -0,0 +1,3 @@ +/zephyr +/zephyr-*.tar.gz +/gen diff --git a/wireless/bluetooth/zblue/CMakeLists.txt b/wireless/bluetooth/zblue/CMakeLists.txt new file mode 100644 index 000000000..67d296372 --- /dev/null +++ b/wireless/bluetooth/zblue/CMakeLists.txt @@ -0,0 +1,251 @@ +# ############################################################################## +# apps/wireless/bluetooth/zblue/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you 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. +# +# ############################################################################## + +if(CONFIG_ZBLUE) + set(ZBLUE_DIR ${CMAKE_CURRENT_LIST_DIR}) + set(ZEPHYR ${ZBLUE_DIR}/zephyr) + set(ZBLUE_GEN ${CMAKE_CURRENT_BINARY_DIR}/gen) + + # Zephyr source, downloaded from the release tag. Only the parts used by the + # Bluetooth host are unpacked, as in the Makefile. + + string(REGEX REPLACE "^v" "" ZEPHYR_VERSION ${CONFIG_ZBLUE_REF}) + set(ZEPHYR_TAR ${ZBLUE_DIR}/zephyr-${CONFIG_ZBLUE_REF}.tar.gz) + set(ZEPHYR_PATHS + LICENSE + Kconfig.constants + include + lib/net_buf + lib/utils + lib/uuid + modules/mbedtls + scripts/kconfig + subsys/bluetooth + subsys/crc + subsys/logging + subsys/settings) + + if(NOT EXISTS ${ZEPHYR}) + if(NOT EXISTS ${ZEPHYR_TAR}) + file( + DOWNLOAD + "https://github.com/zephyrproject-rtos/zephyr/archive/${CONFIG_ZBLUE_REF}.tar.gz" + ${ZEPHYR_TAR} + STATUS status) + list(GET status 0 rc) + if(NOT rc EQUAL 0) + file(REMOVE ${ZEPHYR_TAR}) + message(FATAL_ERROR "zblue: download failed: ${status}") + endif() + endif() + + if(NOT "${CONFIG_ZBLUE_SHA256}" STREQUAL "") + file(SHA256 ${ZEPHYR_TAR} sha256) + if(NOT sha256 STREQUAL CONFIG_ZBLUE_SHA256) + file(REMOVE ${ZEPHYR_TAR}) + message(FATAL_ERROR "zblue: ${ZEPHYR_TAR} has SHA-256 ${sha256}, " + "expected ${CONFIG_ZBLUE_SHA256}") + endif() + else() + message(WARNING "zblue: hash check skipped for ${ZEPHYR_TAR}") + endif() + + list(TRANSFORM ZEPHYR_PATHS PREPEND "zephyr-${ZEPHYR_VERSION}/" + OUTPUT_VARIABLE members) + execute_process( + COMMAND tar xzf ${ZEPHYR_TAR} ${members} + WORKING_DIRECTORY ${ZBLUE_DIR} + RESULT_VARIABLE rc) + if(NOT rc EQUAL 0) + message(FATAL_ERROR "zblue: cannot unpack ${ZEPHYR_TAR}") + endif() + + file(RENAME ${ZBLUE_DIR}/zephyr-${ZEPHYR_VERSION} ${ZEPHYR}) + endif() + + # Zephyr configuration, resolved by the Zephyr Kconfig + + set(ZBLUE_CONF ${CONFIG_ZBLUE_CONF}) + if(NOT IS_ABSOLUTE ${ZBLUE_CONF}) + set(ZBLUE_CONF ${ZBLUE_DIR}/${ZBLUE_CONF}) + endif() + + find_package(Python3 REQUIRED COMPONENTS Interpreter) + execute_process( + COMMAND + ${Python3_EXECUTABLE} ${ZBLUE_DIR}/tools/zkconfig.py --zephyr ${ZEPHYR} + --kconfig ${ZBLUE_DIR}/Kconfig.zephyr --nuttx-config + ${CMAKE_BINARY_DIR}/.config --outdir ${ZBLUE_GEN} ${ZBLUE_CONF} + RESULT_VARIABLE rc) + if(NOT rc EQUAL 0) + message(FATAL_ERROR "zblue: Zephyr Kconfig failed") + endif() + + execute_process( + COMMAND ${Python3_EXECUTABLE} ${ZBLUE_DIR}/tools/gen_syscalls.py + ${ZEPHYR}/include ${ZBLUE_GEN}/zephyr/syscalls RESULT_VARIABLE rc) + if(NOT rc EQUAL 0) + message(FATAL_ERROR "zblue: syscall generation failed") + endif() + + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS ${ZBLUE_CONF} ${CMAKE_BINARY_DIR}/.config + ${ZBLUE_DIR}/Kconfig.zephyr ${ZBLUE_DIR}/tools/zkconfig.py + ${ZBLUE_DIR}/tools/gen_syscalls.py) + + file(STRINGS ${ZBLUE_GEN}/zblue.config lines REGEX "^ZCONFIG_") + foreach(line ${lines}) + string(REGEX MATCH "^([A-Za-z0-9_]+)=(.*)$" _ ${line}) + set(${CMAKE_MATCH_1} ${CMAKE_MATCH_2}) + endforeach() + + # Upstream sources, selected as in the upstream CMakeLists.txt files + + set(BT ${ZEPHYR}/subsys/bluetooth) + file(GLOB SRCS ${ZBLUE_DIR}/port/src/*.c) + + list( + APPEND + SRCS + ${BT}/common/addr.c + ${BT}/common/dummy.c + ${BT}/common/bt_str.c + ${BT}/common/hci_pkt.c + ${BT}/common/hci_lockstep.c) + + macro(zblue_sources_ifdef option) + if("${${option}}" STREQUAL "y") + list(APPEND SRCS ${ARGN}) + endif() + endmacro() + + zblue_sources_ifdef(ZCONFIG_BT_HCI_SET_PUBLIC_ADDR + ${BT}/common/hci_public_addr.c) + zblue_sources_ifdef(ZCONFIG_BT_RPA ${BT}/common/rpa.c) + zblue_sources_ifdef(ZCONFIG_BT_LONG_WQ ${BT}/common/long_wq.c) + + if("${ZCONFIG_BT_HCI_HOST}" STREQUAL "y") + list( + APPEND + SRCS + ${BT}/host/uuid.c + ${BT}/host/addr.c + ${BT}/host/buf.c + ${BT}/host/data.c + ${BT}/host/hci_core.c + ${BT}/host/hci_common.c + ${BT}/host/id.c) + zblue_sources_ifdef(ZCONFIG_BT_BROADCASTER ${BT}/host/adv.c) + zblue_sources_ifdef(ZCONFIG_BT_OBSERVER ${BT}/host/scan.c) + zblue_sources_ifdef(ZCONFIG_BT_HOST_CRYPTO ${BT}/host/crypto_psa.c) + zblue_sources_ifdef(ZCONFIG_BT_ECC ${BT}/host/ecc.c) + if("${ZCONFIG_BT_CONN}" STREQUAL "y") + list(APPEND SRCS ${BT}/host/conn.c ${BT}/host/l2cap.c ${BT}/host/att.c + ${BT}/host/gatt.c) + zblue_sources_ifdef(ZCONFIG_BT_GATT_GAP_SVC_VALIDATE + ${BT}/host/gatt_gap_svc_validate.c) + if("${ZCONFIG_BT_SMP}" STREQUAL "y") + list(APPEND SRCS ${BT}/host/smp.c ${BT}/host/keys.c) + else() + list(APPEND SRCS ${BT}/host/smp_null.c) + endif() + endif() + endif() + + zblue_sources_ifdef(ZCONFIG_BT_HOST_CCM ${BT}/host/aes_ccm.c) + zblue_sources_ifdef(ZCONFIG_BT_CRYPTO ${BT}/crypto/bt_crypto.c + ${BT}/crypto/bt_crypto_psa.c) + zblue_sources_ifdef(ZCONFIG_BT_GAP_SVC ${BT}/services/gap_svc.c) + zblue_sources_ifdef(ZCONFIG_NET_BUF ${ZEPHYR}/lib/net_buf/buf.c + ${ZEPHYR}/lib/net_buf/buf_simple.c) + zblue_sources_ifdef(ZCONFIG_UUID ${ZEPHYR}/lib/uuid/uuid.c) + list(APPEND SRCS ${ZEPHYR}/subsys/crc/crc8_sw.c + ${ZEPHYR}/subsys/crc/crc16_sw.c ${ZEPHYR}/lib/utils/hex.c) + + # Flags for the Zephyr sources, the port and the applications using zblue + + set(ZBLUE_INCDIRS ${ZBLUE_DIR}/port/include ${ZBLUE_GEN} ${ZEPHYR}/include + ${ZEPHYR}/subsys/bluetooth) + set(ZBLUE_FLAGS + -imacros + ${ZBLUE_GEN}/zephyr/autoconf.h + -include + ${ZBLUE_DIR}/port/include/zblue_prefix.h + -D__ZEPHYR__=1 + -std=gnu11 + -Wno-undef + -Wno-shadow + -Wno-unused-but-set-variable) + + # The host relies on the compiler removing code under IS_ENABLED(n) + + if(CONFIG_DEBUG_NOOPT) + list(APPEND ZBLUE_FLAGS -Og) + endif() + + # The objects are linked into one relocatable object. Some of them (e.g. + # services/gap_svc.c) only add entries to an iterable section and have no + # symbol referenced from elsewhere, so they would not be pulled out of a + # static library. + + # Same flags as nuttx_add_library() gives to an application library + + add_library(zblue_objs OBJECT ${SRCS}) + add_dependencies(zblue_objs nuttx_context apps_context) + target_compile_options( + zblue_objs + PRIVATE + $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_COMPILE_OPTIONS>> + $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_COMPILE_OPTIONS>> + ${ZBLUE_FLAGS}) + target_compile_definitions( + zblue_objs + PRIVATE + $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_DEFINITIONS>> + $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_COMPILE_DEFINITIONS>> + ) + target_include_directories( + zblue_objs + PRIVATE + ${ZBLUE_INCDIRS} + $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_INCLUDE_DIRECTORIES>> + $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_INCLUDE_DIRECTORIES>> + $<TARGET_PROPERTY:mbedtls,INTERFACE_INCLUDE_DIRECTORIES>) + target_include_directories( + zblue_objs SYSTEM PRIVATE ${NUTTX_DIR}/include ${NUTTX_BINARY_DIR}/include) + + add_custom_command( + OUTPUT ${ZBLUE_GEN}/zblue.o + COMMAND ${CMAKE_C_COMPILER} -r -nostdlib -o ${ZBLUE_GEN}/zblue.o + $<TARGET_OBJECTS:zblue_objs> + DEPENDS $<TARGET_OBJECTS:zblue_objs> + COMMAND_EXPAND_LISTS + COMMENT "LD: zblue.o") + + set_source_files_properties(${ZBLUE_GEN}/zblue.o + PROPERTIES EXTERNAL_OBJECT TRUE GENERATED TRUE) + nuttx_add_library(zblue STATIC) + target_sources(zblue PRIVATE ${ZBLUE_GEN}/zblue.o) + set_target_properties(zblue PROPERTIES LINKER_LANGUAGE C) +endif() diff --git a/wireless/bluetooth/zblue/Kconfig b/wireless/bluetooth/zblue/Kconfig new file mode 100644 index 000000000..197a80317 --- /dev/null +++ b/wireless/bluetooth/zblue/Kconfig @@ -0,0 +1,86 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menuconfig ZBLUE + bool "zblue: Zephyr Bluetooth host" + default n + depends on ARCH_SIM && HOST_LINUX + depends on TLS_NELEM > 0 + depends on !WIRELESS_BLUETOOTH_HOST && !NIMBLE + depends on UART_BTH4 + select SCHED_WORKQUEUE if BUILD_FLAT + select LIBC_USRWORK if !BUILD_FLAT + select PTHREAD_MUTEX_TYPES + select CRYPTO_MBEDTLS + select MBEDTLS_AES_C + select MBEDTLS_CIPHER_C + select MBEDTLS_CMAC_C + select MBEDTLS_ECP_C + select MBEDTLS_ECDH_C + select MBEDTLS_ECP_DP_SECP256R1_ENABLED + select MBEDTLS_MD5_C + select MBEDTLS_PSA_CRYPTO_C + select MBEDTLS_CTR_DRBG_C + select MBEDTLS_ENTROPY_C + select MBEDTLS_SHA256_C + select MBEDTLS_PLATFORM_C + ---help--- + The Bluetooth host of the Zephyr project, run unmodified in + userspace on top of a small porting layer. The source is + downloaded from the Zephyr release given by ZBLUE_REF. + + Only the simulator is supported for now: initialized data in + iterable RAM sections (net_buf pools) is not yet placed in .data + by the board linker scripts. + + The Bluetooth features are configured with the original + Zephyr CONFIG_BT_* options, in the file given by ZBLUE_CONF. + They are resolved by the Zephyr Kconfig after download and do + not appear in this menu. + + The controller is reached through /dev/ttyHCIx (UART_BTH4), + so any NuttX driver registered with bt_driver_register() can + be used. + +if ZBLUE + +config ZBLUE_REF + string "Zephyr release" + default "v4.5.0" + ---help--- + Zephyr git tag to download the Bluetooth host from. + +config ZBLUE_SHA256 + string "SHA-256 of the Zephyr archive" + default "326614eef9f65c8c37e83e47870cb93d0f570a1c495f5d89da6b4d85ea6b9cb6" if ZBLUE_REF = "v4.5.0" + default "" + ---help--- + Expected SHA-256 of the GitHub archive of ZBLUE_REF, checked + before the archive is unpacked. The check is skipped with a + warning when this is empty. + +config ZBLUE_CONF + string "Zephyr Bluetooth configuration" + default "zblue.conf" + ---help--- + Zephyr style configuration fragment with the CONFIG_BT_* + options. A relative path is relative to this directory. + +config ZBLUE_HCI_DEVICE + string "HCI device" + default "/dev/ttyHCI0" + +config ZBLUE_HCI_RX_STACKSIZE + int "HCI RX thread stack size" + default 2048 + +config ZBLUE_THREAD_PRIORITY + int "Base priority of the Bluetooth threads" + default 120 + ---help--- + Zephyr cooperative priorities are mapped below this value, + preemptive priorities above it. + +endif # ZBLUE diff --git a/wireless/bluetooth/zblue/Make.defs b/wireless/bluetooth/zblue/Make.defs new file mode 100644 index 000000000..483b159c5 --- /dev/null +++ b/wireless/bluetooth/zblue/Make.defs @@ -0,0 +1,25 @@ +############################################################################ +# apps/wireless/bluetooth/zblue/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +ifneq ($(CONFIG_ZBLUE),) +CONFIGURED_APPS += $(APPDIR)/wireless/bluetooth/zblue +endif diff --git a/wireless/bluetooth/zblue/Makefile b/wireless/bluetooth/zblue/Makefile new file mode 100644 index 000000000..7f08dcd88 --- /dev/null +++ b/wireless/bluetooth/zblue/Makefile @@ -0,0 +1,201 @@ +############################################################################ +# apps/wireless/bluetooth/zblue/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +include $(APPDIR)/Make.defs + +ZBLUE_DIR = $(APPDIR)/wireless/bluetooth/zblue + +# Zephyr source, downloaded from the release tag + +ZEPHYR_REF := $(patsubst "%",%,$(strip $(CONFIG_ZBLUE_REF))) +ZEPHYR_SHA256 := $(patsubst "%",%,$(strip $(CONFIG_ZBLUE_SHA256))) +ZEPHYR_URL ?= https://github.com/zephyrproject-rtos/zephyr/archive +ZEPHYR_TAR = zephyr-$(ZEPHYR_REF).tar.gz +ZEPHYR_UNPACK = zephyr +ZEPHYR = $(ZBLUE_DIR)/$(ZEPHYR_UNPACK) + +# Only the parts of the tree used by the Bluetooth host are unpacked + +ZEPHYR_PATHS = LICENSE Kconfig.constants include lib/net_buf lib/utils \ + lib/uuid modules/mbedtls scripts/kconfig subsys/bluetooth \ + subsys/crc subsys/logging subsys/settings + +$(ZEPHYR_TAR): + @echo "Downloading: $(ZEPHYR_URL)/$(ZEPHYR_REF).tar.gz" + $(Q) curl -fL $(ZEPHYR_URL)/$(ZEPHYR_REF).tar.gz -o $(ZEPHYR_TAR) + +$(ZEPHYR_UNPACK): $(ZEPHYR_TAR) + $(Q) $(APPDIR)/tools/check-hash.sh sha256 "$(ZEPHYR_SHA256)" \ + $(ZEPHYR_TAR) + @echo "Unpacking: $(ZEPHYR_TAR) -> $(ZEPHYR_UNPACK)" + $(Q) tar xzf $(ZEPHYR_TAR) \ + $(addprefix zephyr-$(ZEPHYR_REF:v%=%)/,$(ZEPHYR_PATHS)) + $(Q) mv zephyr-$(ZEPHYR_REF:v%=%) $(ZEPHYR_UNPACK) + $(Q) touch $(ZEPHYR_UNPACK) + +ifeq ($(wildcard $(ZEPHYR_UNPACK)/.git),) +context:: $(ZEPHYR_UNPACK) + +distclean:: + $(call DELFILE,$(ZEPHYR_TAR)) + $(call DELDIR,$(ZEPHYR_UNPACK)) +endif + +# Zephyr configuration: resolved by the Zephyr Kconfig after download + +ZBLUE_GEN = $(ZBLUE_DIR)/gen +ZBLUE_CONF := $(patsubst "%",%,$(strip $(CONFIG_ZBLUE_CONF))) +ifeq ($(filter /%,$(ZBLUE_CONF)),) +ZBLUE_CONF := $(ZBLUE_DIR)/$(ZBLUE_CONF) +endif + +$(ZBLUE_GEN)/zblue.config: $(ZBLUE_CONF) $(TOPDIR)/.config \ + Kconfig.zephyr tools/zkconfig.py $(ZEPHYR_UNPACK) + $(Q) python3 tools/zkconfig.py --zephyr $(ZEPHYR) \ + --kconfig Kconfig.zephyr --nuttx-config $(TOPDIR)/.config \ + --outdir $(ZBLUE_GEN) $(ZBLUE_CONF) + $(Q) python3 tools/gen_syscalls.py $(ZEPHYR)/include \ + $(ZBLUE_GEN)/zephyr/syscalls + +context:: $(ZBLUE_GEN)/zblue.config + +distclean:: + $(call DELDIR,$(ZBLUE_GEN)) + +-include $(ZBLUE_GEN)/zblue.config + +# Compiler flags for the Zephyr sources and the port + +ZBLUE_FLAGS = ${INCDIR_PREFIX}$(ZBLUE_DIR)/port/include +ZBLUE_FLAGS += ${INCDIR_PREFIX}$(ZBLUE_GEN) +ZBLUE_FLAGS += ${INCDIR_PREFIX}$(ZEPHYR)/include +ZBLUE_FLAGS += ${INCDIR_PREFIX}$(ZEPHYR)/subsys/bluetooth +ZBLUE_FLAGS += -imacros $(ZBLUE_GEN)/zephyr/autoconf.h +ZBLUE_FLAGS += -include $(ZBLUE_DIR)/port/include/zblue_prefix.h +ZBLUE_FLAGS += -D__ZEPHYR__=1 -std=gnu11 +ZBLUE_FLAGS += -Wno-undef -Wno-shadow -Wno-unused-but-set-variable + +# The host relies on the compiler removing code under IS_ENABLED(n) + +ifeq ($(CONFIG_DEBUG_NOOPT),y) +ZBLUE_FLAGS += -Og +endif + +CFLAGS += $(ZBLUE_FLAGS) + +# Porting layer + +ZSRCS += $(wildcard port/src/*.c) + +# Upstream sources, selected as in the upstream CMakeLists.txt files + +BT = $(ZEPHYR_UNPACK)/subsys/bluetooth + +ZSRCS += $(BT)/common/addr.c $(BT)/common/dummy.c $(BT)/common/bt_str.c +ZSRCS += $(BT)/common/hci_pkt.c $(BT)/common/hci_lockstep.c +ifeq ($(ZCONFIG_BT_HCI_SET_PUBLIC_ADDR),y) +ZSRCS += $(BT)/common/hci_public_addr.c +endif +ifeq ($(ZCONFIG_BT_RPA),y) +ZSRCS += $(BT)/common/rpa.c +endif +ifeq ($(ZCONFIG_BT_LONG_WQ),y) +ZSRCS += $(BT)/common/long_wq.c +endif + +ifeq ($(ZCONFIG_BT_HCI_HOST),y) +ZSRCS += $(BT)/host/uuid.c $(BT)/host/addr.c $(BT)/host/buf.c +ZSRCS += $(BT)/host/data.c $(BT)/host/hci_core.c $(BT)/host/hci_common.c +ZSRCS += $(BT)/host/id.c +ifeq ($(ZCONFIG_BT_BROADCASTER),y) +ZSRCS += $(BT)/host/adv.c +endif +ifeq ($(ZCONFIG_BT_OBSERVER),y) +ZSRCS += $(BT)/host/scan.c +endif +ifeq ($(ZCONFIG_BT_HOST_CRYPTO),y) +ZSRCS += $(BT)/host/crypto_psa.c +endif +ifeq ($(ZCONFIG_BT_ECC),y) +ZSRCS += $(BT)/host/ecc.c +endif +ifeq ($(ZCONFIG_BT_CONN),y) +ZSRCS += $(BT)/host/conn.c $(BT)/host/l2cap.c $(BT)/host/att.c +ZSRCS += $(BT)/host/gatt.c +ifeq ($(ZCONFIG_BT_GATT_GAP_SVC_VALIDATE),y) +ZSRCS += $(BT)/host/gatt_gap_svc_validate.c +endif +ifeq ($(ZCONFIG_BT_SMP),y) +ZSRCS += $(BT)/host/smp.c $(BT)/host/keys.c +else +ZSRCS += $(BT)/host/smp_null.c +endif +endif +endif + +ifeq ($(ZCONFIG_BT_HOST_CCM),y) +ZSRCS += $(BT)/host/aes_ccm.c +endif + +ifeq ($(ZCONFIG_BT_CRYPTO),y) +ZSRCS += $(BT)/crypto/bt_crypto.c $(BT)/crypto/bt_crypto_psa.c +endif + +ifeq ($(ZCONFIG_BT_GAP_SVC),y) +ZSRCS += $(BT)/services/gap_svc.c +endif + +ifeq ($(ZCONFIG_NET_BUF),y) +ZSRCS += $(ZEPHYR_UNPACK)/lib/net_buf/buf.c +ZSRCS += $(ZEPHYR_UNPACK)/lib/net_buf/buf_simple.c +endif + +ZSRCS += $(ZEPHYR_UNPACK)/subsys/crc/crc8_sw.c +ZSRCS += $(ZEPHYR_UNPACK)/subsys/crc/crc16_sw.c +ZSRCS += $(ZEPHYR_UNPACK)/lib/utils/hex.c +ifeq ($(ZCONFIG_UUID),y) +ZSRCS += $(ZEPHYR_UNPACK)/lib/uuid/uuid.c +endif + +# The zblue objects are linked into one relocatable object. Some of them +# (e.g. services/gap_svc.c) only add entries to an iterable section and +# have no symbol referenced from elsewhere, so they would not be pulled out +# of libapps.a. + +ZOBJDIR = $(ZBLUE_GEN)/obj +ZOBJS = $(patsubst %.c,$(ZOBJDIR)/%.o,$(ZSRCS)) + +$(ZOBJDIR)/%.o: %.c $(ZBLUE_GEN)/zblue.config + $(Q) mkdir -p $(dir $@) + $(call COMPILE, $<, $@) + +$(ZBLUE_GEN)/zblue.o: $(ZOBJS) + @echo "LD: zblue.o" + $(Q) $(LD) -r -o $@ $(ZOBJS) + +EXTOBJS += $(ZBLUE_GEN)/zblue.o + +clean:: + $(call DELDIR,$(ZOBJDIR)) + $(call DELFILE,$(ZBLUE_GEN)/zblue.o) + +include $(APPDIR)/Application.mk
