kernel: Use IS-specific entropy function when available
During the early boot process, in prepare_multithreading(), the kernel structures and scheduler are not ready yet. In order to obtain entropy for early works such as stack randomization, optionally use when present the ISR-specific function that some drivers will provide. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
668e31f7db
commit
b54644913d
1 changed files with 13 additions and 6 deletions
|
@ -389,15 +389,22 @@ u32_t z_early_boot_rand32_get(void)
|
|||
goto sys_rand32_fallback;
|
||||
}
|
||||
|
||||
rc = entropy_get_entropy(entropy, (u8_t *)&retval, sizeof(retval));
|
||||
if (rc == 0) {
|
||||
/* Try to see if driver provides an ISR-specific API */
|
||||
rc = entropy_get_entropy_isr(entropy, (u8_t *)&retval,
|
||||
sizeof(retval), ENTROPY_BUSYWAIT);
|
||||
if (rc == -ENOTSUP) {
|
||||
/* Driver does not provide an ISR-specific API, assume it can
|
||||
* be called from ISR context
|
||||
*/
|
||||
rc = entropy_get_entropy(entropy, (u8_t *)&retval,
|
||||
sizeof(retval));
|
||||
}
|
||||
|
||||
if (rc >= 0) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* FIXME: rc could be -EAGAIN here, for cases where the entropy
|
||||
* driver doesn't yet have the requested amount of entropy. In
|
||||
* the meantime, just use the fallback with sys_rand32_get().
|
||||
*/
|
||||
/* Fall through to fallback */
|
||||
|
||||
sys_rand32_fallback:
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue