Skip to content

Commit

Permalink
drivers: entropy native: Refactor to support embedded libCs
Browse files Browse the repository at this point in the history
Refactor the host libC accesses to use the native simulator
host trampolines.

In this way we support building this driver with embedded libCs.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
  • Loading branch information
aescolar committed Jul 6, 2023
1 parent 5f75f41 commit 051b992
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion boards/posix/native_sim/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ host libC (:kconfig:option:`CONFIG_EXTERNAL_LIBC`).
can, can native posix, :kconfig:option:`CONFIG_CAN_NATIVE_POSIX_LINUX`, host libC
console backend, POSIX arch console, :kconfig:option:`CONFIG_POSIX_ARCH_CONSOLE`, all
display, display SDL, :kconfig:option:`CONFIG_SDL_DISPLAY`, host libC
entropy, native posix entropy, :kconfig:option:`CONFIG_FAKE_ENTROPY_NATIVE_POSIX`, host libC
entropy, native posix entropy, :kconfig:option:`CONFIG_FAKE_ENTROPY_NATIVE_POSIX`, all
eprom, eprom emulator, :kconfig:option:`CONFIG_EEPROM_EMULATOR`, host libC
ethernet, eth native_posix, :kconfig:option:`CONFIG_ETH_NATIVE_POSIX`, host libC
flash, flash simulator, :kconfig:option:`CONFIG_FLASH_SIMULATOR`, host libC
Expand Down
1 change: 0 additions & 1 deletion drivers/entropy/Kconfig.native_posix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ config FAKE_ENTROPY_NATIVE_POSIX
bool "Native posix entropy driver"
default y
depends on DT_HAS_ZEPHYR_NATIVE_POSIX_RNG_ENABLED
depends on EXTERNAL_LIBC
select ENTROPY_HAS_DRIVER
help
This option enables the test random number generator for the
Expand Down
5 changes: 3 additions & 2 deletions drivers/entropy/fake_entropy_native_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <zephyr/arch/posix/posix_trace.h>
#include "soc.h"
#include "cmdline.h" /* native_posix command line options header */
#include "nsi_host_trampolines.h"

static unsigned int seed = 0x5678;

Expand All @@ -36,7 +37,7 @@ static int entropy_native_posix_get_entropy(const struct device *dev,
* Note that only 1 thread (Zephyr thread or HW models), runs at
* a time, therefore there is no need to use random_r()
*/
long int value = random();
long value = nsi_host_random();

size_t to_copy = MIN(length, sizeof(long int));

Expand Down Expand Up @@ -64,7 +65,7 @@ static int entropy_native_posix_get_entropy_isr(const struct device *dev,
static int entropy_native_posix_init(const struct device *dev)
{
ARG_UNUSED(dev);
srandom(seed);
nsi_host_srandom(seed);
posix_print_warning("WARNING: "
"Using a test - not safe - entropy source\n");
return 0;
Expand Down

0 comments on commit 051b992

Please sign in to comment.