Skip to content

Commit b5db91f

Browse files
chengkai15GUIDINGLI
authored andcommitted
boards/sim: Add zblue configuration
Add sim:zblue for the Zephyr Bluetooth host in apps (wireless/bluetooth/zblue): a Bluetooth controller of the host is attached with CONFIG_SIM_HCISOCKET and exposed as /dev/ttyHCI0 through CONFIG_UART_BTH4, and the zblue_peripheral example is enabled. CONFIG_DEV_URANDOM provides the entropy for the host cryptography and CONFIG_TLS_NELEM the thread-specific data used by the porting layer. Document the application and the configuration. Build it in CI with CMake, and not on macOS: it needs the Linux HCI socket and ELF section start/stop symbols. Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
1 parent e337f31 commit b5db91f

4 files changed

Lines changed: 196 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
=======================================================
2+
``zblue`` Zephyr Bluetooth host in userspace
3+
=======================================================
4+
5+
This application builds the Bluetooth host of the `Zephyr project
6+
<https://github.com/zephyrproject-rtos/zephyr>`_ as a userspace library. The
7+
Zephyr source is downloaded from a Zephyr release tag and is used without
8+
modification; only a small porting layer in ``apps/wireless/bluetooth/zblue``
9+
is NuttX code.
10+
11+
It is an optional stack. The NuttX Bluetooth stack
12+
(``wireless/bluetooth``, ``net/bluetooth``) and NimBLE stay available; only
13+
one host can be enabled at a time.
14+
15+
Applications use the Zephyr Bluetooth API (``<zephyr/bluetooth/...>``) as
16+
documented by Zephyr.
17+
18+
Only the simulator is supported for now. On other targets the initialized
19+
iterable RAM sections of the host (``net_buf`` pools) need support in the
20+
board linker scripts, which is not there yet.
21+
22+
Configuration
23+
-------------
24+
25+
``CONFIG_ZBLUE``
26+
Enables the stack. It needs ``CONFIG_UART_BTH4``: the host talks to the
27+
controller through ``/dev/ttyHCIx``, so any driver registered with
28+
``bt_driver_register()`` can be used.
29+
30+
``CONFIG_ZBLUE_REF``
31+
Zephyr release tag to download, for example ``v4.5.0``.
32+
33+
``CONFIG_ZBLUE_CONF``
34+
Zephyr configuration fragment with the ``CONFIG_BT_*`` options, relative
35+
to the application directory (default ``zblue.conf``). The options are
36+
the original Zephyr ones. They are resolved with the Zephyr Kconfig
37+
after download and do not appear in the NuttX menuconfig.
38+
39+
``CONFIG_ZBLUE_HCI_DEVICE``
40+
HCI device, default ``/dev/ttyHCI0``.
41+
42+
``CONFIG_ZBLUE_THREAD_PRIORITY``
43+
Zephyr cooperative priorities are mapped above this NuttX priority,
44+
preemptive priorities below it.
45+
46+
Cryptography uses the PSA API of Mbed TLS (``apps/crypto/mbedtls``); the
47+
options the host needs are selected automatically and
48+
``CONFIG_MBEDTLS_MINIMAL`` is enabled by default. Mbed TLS needs an entropy
49+
source, e.g. ``CONFIG_DEV_URANDOM`` on the simulator or the hardware random
50+
number generator of the board.
51+
52+
Download and build requirements: ``curl``, ``tar`` and ``python3``.
53+
54+
Updating the Zephyr release
55+
---------------------------
56+
57+
Change ``CONFIG_ZBLUE_REF`` and remove the ``zephyr`` directory and the
58+
downloaded archive (``make distclean``). Fixes to the Zephyr host itself are
59+
made in Zephyr, not here.
60+
61+
Porting layer
62+
-------------
63+
64+
* Zephyr kernel services used by the host (threads, semaphores, mutexes,
65+
queues, memory slabs, work queues, timeouts) are implemented on POSIX
66+
threads, without NuttX internal interfaces.
67+
* Zephyr cooperative threads are serialized with one lock that is
68+
released only while a thread blocks; ``k_sched_lock()`` takes the same
69+
lock.
70+
* Iterable sections (``BT_CONN_CB_DEFINE()``, ``BT_GATT_SERVICE_DEFINE()``,
71+
...) are collected by the linker without changes to the board linker
72+
script. Entries of a type are in link order.
73+
* ``SYS_INIT()`` functions run before ``bt_enable()`` starts the host.
74+
75+
Example
76+
-------
77+
78+
``CONFIG_ZBLUE_PERIPHERAL_EXAMPLE`` builds ``zblue_peripheral``: it
79+
advertises as ``CONFIG_BT_DEVICE_NAME`` and accepts connections, with the
80+
GAP and GATT services. See the ``sim:zblue`` configuration of the simulator.

‎Documentation/platforms/sim/sim/boards/sim/index.rst‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,28 @@ At this point you should be able to detect a "nimble" BLE device when scanning
10071007
for BLE devices. You can use nRFConnect Android application from Nordic to
10081008
connect and inspect exposed GATT services.
10091009

1010+
zblue
1011+
-----
1012+
1013+
The Zephyr Bluetooth host (:doc:`/applications/wireless/zblue/index`) in
1014+
userspace, on a Bluetooth controller of the host attached with
1015+
``CONFIG_SIM_HCISOCKET`` and exposed as ``/dev/ttyHCI0``. The controller is
1016+
taken over with the HCI user channel, so it must be down on the host and the
1017+
simulator needs ``CAP_NET_ADMIN``:
1018+
1019+
.. code:: console
1020+
1021+
$ sudo hciconfig hci0 down
1022+
$ sudo ./nuttx --bt-dev=hci0
1023+
nsh> zblue_peripheral &
1024+
zblue: Bluetooth ready, identity P:00:1A:7D:DA:71:11
1025+
zblue: advertising as "NuttX zblue"
1026+
1027+
A central can then scan for "NuttX zblue", connect and read the GAP and GATT
1028+
services, for example ``gatttool -i hci1 -b <address> --primary`` from a
1029+
second adapter. ``CONFIG_DEV_URANDOM`` provides the entropy for the host
1030+
cryptography; it is not suitable for a real device.
1031+
10101032
nsh
10111033
---
10121034

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#
2+
# This file is autogenerated: PLEASE DO NOT EDIT IT.
3+
#
4+
# You can use "make menuconfig" to make any modifications to the installed .config file.
5+
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
6+
# modifications.
7+
#
8+
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
9+
CONFIG_ARCH="sim"
10+
CONFIG_ARCH_BOARD="sim"
11+
CONFIG_ARCH_BOARD_SIM=y
12+
CONFIG_ARCH_CHIP="sim"
13+
CONFIG_ARCH_SIM=y
14+
CONFIG_BOARDCTL_APP_SYMTAB=y
15+
CONFIG_BOARDCTL_POWEROFF=y
16+
CONFIG_BOARD_LOOPSPERMSEC=0
17+
CONFIG_BOOT_RUNFROMEXTSRAM=y
18+
CONFIG_BUILTIN=y
19+
CONFIG_COVERAGE_ALL=y
20+
CONFIG_COVERAGE_TOOLCHAIN=y
21+
CONFIG_DEBUG_ASSERTIONS=y
22+
CONFIG_DEBUG_ASSERTIONS_EXPRESSION=y
23+
CONFIG_DEBUG_FEATURES=y
24+
CONFIG_DEBUG_SYMBOLS=y
25+
CONFIG_DEV_GPIO=y
26+
CONFIG_DEV_LOOP=y
27+
CONFIG_DEV_URANDOM=y
28+
CONFIG_DRIVERS_BLUETOOTH=y
29+
CONFIG_DRIVERS_WIRELESS=y
30+
CONFIG_ETC_FATDEVNO=2
31+
CONFIG_ETC_ROMFS=y
32+
CONFIG_ETC_ROMFSDEVNO=1
33+
CONFIG_EXAMPLES_GPIO=y
34+
CONFIG_EXAMPLES_HELLO=y
35+
CONFIG_EXPERIMENTAL=y
36+
CONFIG_FAT_LCNAMES=y
37+
CONFIG_FAT_LFN=y
38+
CONFIG_FS_BINFS=y
39+
CONFIG_FS_FAT=y
40+
CONFIG_FS_HOSTFS=y
41+
CONFIG_FS_LINKS=y
42+
CONFIG_FS_PROCFS=y
43+
CONFIG_FS_RAMMAP=y
44+
CONFIG_FS_ROMFS=y
45+
CONFIG_GPIO_LOWER_HALF=y
46+
CONFIG_HAVE_CXXINITIALIZE=y
47+
CONFIG_IDLETHREAD_STACKSIZE=4096
48+
CONFIG_INIT_ENTRYPOINT="init_main"
49+
CONFIG_IOEXPANDER=y
50+
CONFIG_IOEXPANDER_DUMMY=y
51+
CONFIG_LIBC_ENVPATH=y
52+
CONFIG_LIBC_EXECFUNCS=y
53+
CONFIG_LIBC_LOCALE=y
54+
CONFIG_LIBC_LOCALE_CATALOG=y
55+
CONFIG_LIBC_LOCALE_GETTEXT=y
56+
CONFIG_LIBC_MAX_EXITFUNS=1
57+
CONFIG_LIBC_NUMBERED_ARGS=y
58+
CONFIG_NDEBUG=y
59+
CONFIG_NSH_BUILTIN_APPS=y
60+
CONFIG_NSH_FILE_APPS=y
61+
CONFIG_NSH_READLINE=y
62+
CONFIG_PATH_INITIAL="/bin"
63+
CONFIG_PIPES=y
64+
CONFIG_PSEUDOFS_ATTRIBUTES=y
65+
CONFIG_PSEUDOFS_FILE=y
66+
CONFIG_READLINE_CMD_HISTORY=y
67+
CONFIG_READLINE_EDIT_EMACS=y
68+
CONFIG_READLINE_TABCOMPLETION=y
69+
CONFIG_RTC=y
70+
CONFIG_RTC_ARCH=y
71+
CONFIG_RTC_DRIVER=y
72+
CONFIG_SCHED_BACKTRACE=y
73+
CONFIG_SCHED_CHILD_STATUS=y
74+
CONFIG_SCHED_EVENTS=y
75+
CONFIG_SCHED_HAVE_PARENT=y
76+
CONFIG_SCHED_WAITPID=y
77+
CONFIG_SIM_HCISOCKET=y
78+
CONFIG_SIM_HOSTFS=y
79+
CONFIG_SIM_WALLTIME_SIGNAL=y
80+
CONFIG_START_MONTH=6
81+
CONFIG_START_YEAR=2008
82+
CONFIG_SYSTEM_DUMPSTACK=y
83+
CONFIG_SYSTEM_GCOV=y
84+
CONFIG_SYSTEM_NSH=y
85+
CONFIG_SYSTEM_NXINIT=y
86+
CONFIG_TESTING_OSTEST=y
87+
CONFIG_TLS_NELEM=4
88+
CONFIG_UART_BTH4=y
89+
CONFIG_ZBLUE=y
90+
CONFIG_ZBLUE_PERIPHERAL_EXAMPLE=y

‎tools/ci/testlist/sim-03.dat‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
-Darwin,sim:usbdev
2525
-Darwin,sim:usbhost
2626

27+
# zblue needs the Linux HCI socket and ELF section start/stop symbols
28+
-Darwin,sim:zblue
29+
2730
# Boards build by CMake
2831
CMake,sim:ostest
2932
CMake,sim:ostest_oneholder
@@ -51,3 +54,4 @@ CMake,sim:userfs
5154
CMake,sim:usrsocktest
5255
CMake,sim:ustream
5356
CMake,sim:vncserver
57+
CMake,sim:zblue

0 commit comments

Comments
 (0)