Skip to content

Commit 29e9d7f

Browse files
valeriosetticvinayak
authored andcommitted
drivers: entropy: ease runtime requirements on BT HCI
On platforms like nrf5340 there are 2 CPUs: - one is the cpu_net which takes care of the radio stuff and owns the HW random generator - one is the cpu_app which holds application data and polls cpu_net through HCI commands when it needs some random data. The PSA core implemented in Mbed TLS needs random data at initialization time, which happens early in the boot process. If we wait for BT to be ready before issuing the HCI command, then PSA core intialization will fail. In facts there is no need for the BT to be completely initialized just to ask for some random data from the cpu_app to the cpu_net since the HW random generator will likely be already functional in the cpu_net. So let's just try the HCI command and, if something is not right, it will fail anyway. There's no need to anticipate the failure. Signed-off-by: Valerio Setti <[email protected]>
1 parent fe3d4da commit 29e9d7f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

doc/releases/migration-guide-4.0.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ Disk
224224
Enhanced Serial Peripheral Interface (eSPI)
225225
===========================================
226226

227+
Entropy
228+
=======
229+
230+
* BT HCI based entropy driver now directly sends the HCI command to parse random
231+
data instead of waiting for BT connection to be ready. This is helpful on
232+
platforms where the BT controller owns the HW random generator and the application
233+
processor needs to get random data before BT is fully enabled.
234+
(:github:`79931`)
235+
227236
GNSS
228237
====
229238

drivers/entropy/entropy_bt_hci.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ static int entropy_bt_init(const struct device *dev)
2020
static int entropy_bt_get_entropy(const struct device *dev,
2121
uint8_t *buffer, uint16_t length)
2222
{
23-
if (!bt_is_ready()) {
24-
return -EAGAIN;
25-
}
23+
/* Do not wait for BT to be ready (i.e. bt_is_ready()) before issueing
24+
* the command. The reason is that when crypto is enabled and the PSA
25+
* Crypto API support is provided through Mbed TLS, random number generator
26+
* needs to be available since the very first call to psa_crypto_init()
27+
* which is usually done before BT is completely initialized.
28+
* On the other hand, in devices like the nrf5340, the crytographically
29+
* secure RNG is owned by the cpu_net, so the cpu_app needs to poll it
30+
* to get random data. Again, there is no need to wait for BT to be
31+
* completely initialized for this kind of support. Just try to send the
32+
* request through HCI. If the command fails for any reason, then
33+
* we return failure anyway.
34+
*/
2635

2736
return bt_hci_le_rand(buffer, length);
2837
}

0 commit comments

Comments
 (0)