From 8252e996088ec90a1d671880840bdea4d5781ee8 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 21 Jun 2023 14:46:00 +0200 Subject: [PATCH] drivers: entropy native: Refactor to support embedded libCs 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 --- boards/posix/native_sim/doc/index.rst | 2 +- drivers/entropy/Kconfig.native_posix | 1 - drivers/entropy/fake_entropy_native_posix.c | 5 +++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/boards/posix/native_sim/doc/index.rst b/boards/posix/native_sim/doc/index.rst index 2c4d53111c41c4..2f524829b721ff 100644 --- a/boards/posix/native_sim/doc/index.rst +++ b/boards/posix/native_sim/doc/index.rst @@ -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`, all - 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 diff --git a/drivers/entropy/Kconfig.native_posix b/drivers/entropy/Kconfig.native_posix index ea31a5fbbf29b4..94fd73006705f8 100644 --- a/drivers/entropy/Kconfig.native_posix +++ b/drivers/entropy/Kconfig.native_posix @@ -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 diff --git a/drivers/entropy/fake_entropy_native_posix.c b/drivers/entropy/fake_entropy_native_posix.c index cccb66f905502d..b39c07bbf30576 100644 --- a/drivers/entropy/fake_entropy_native_posix.c +++ b/drivers/entropy/fake_entropy_native_posix.c @@ -22,6 +22,7 @@ #include #include "soc.h" #include "cmdline.h" /* native_posix command line options header */ +#include "nsi_host_trampolines.h" static unsigned int seed = 0x5678; @@ -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)); @@ -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;