From 474797891ccd904c4cac4fc9f4803dbac6189748 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 3 Sep 2024 17:52:04 +0200 Subject: [PATCH 1/3] [nrf fromtree] entropy: native_posix: Add kconfig to not seed by default Provide a new kconfig option which can be used to disable the default seeding of the host standard library random generator by this driver. This allows some other component to do so without this component default initialization interfering. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit e58a49190010dfe2b205c57f2a76c1d88a1ce224) --- drivers/entropy/Kconfig.native_posix | 9 +++++++++ drivers/entropy/fake_entropy_native_posix.c | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/entropy/Kconfig.native_posix b/drivers/entropy/Kconfig.native_posix index 94fd7300670..39298c444df 100644 --- a/drivers/entropy/Kconfig.native_posix +++ b/drivers/entropy/Kconfig.native_posix @@ -12,3 +12,12 @@ config FAKE_ENTROPY_NATIVE_POSIX not generate real entropy. It actually generates always the same sequence of random numbers if initialized with the same seed. + +config FAKE_ENTROPY_NATIVE_POSIX_SEED_BY_DEFAULT + bool "Seed the generator by default" + default y + depends on FAKE_ENTROPY_NATIVE_POSIX + help + Apply a seed by default, even if the user does not request it through the command line. + Disabling this feature allows some other component to seed the host standard library random + generator without this component's default initialization interfering. diff --git a/drivers/entropy/fake_entropy_native_posix.c b/drivers/entropy/fake_entropy_native_posix.c index ccdd3aa46e5..e9ee4ab9284 100644 --- a/drivers/entropy/fake_entropy_native_posix.c +++ b/drivers/entropy/fake_entropy_native_posix.c @@ -27,6 +27,7 @@ static unsigned int seed = 0x5678; static bool seed_random; +static bool seed_set; static int entropy_native_posix_get_entropy(const struct device *dev, uint8_t *buffer, @@ -69,7 +70,10 @@ 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); - entropy_native_seed(seed, seed_random); + if (seed_set || seed_random || + IS_ENABLED(CONFIG_FAKE_ENTROPY_NATIVE_POSIX_SEED_BY_DEFAULT)) { + entropy_native_seed(seed, seed_random); + } posix_print_warning("WARNING: " "Using a test - not safe - entropy source\n"); return 0; @@ -86,6 +90,13 @@ DEVICE_DT_INST_DEFINE(0, PRE_KERNEL_1, CONFIG_ENTROPY_INIT_PRIORITY, &entropy_native_posix_api_funcs); +static void seed_was_set(char *argv, int offset) +{ + ARG_UNUSED(argv); + ARG_UNUSED(offset); + seed_set = true; +} + static void add_fake_entropy_option(void) { static struct args_struct_t entropy_options[] = { @@ -94,6 +105,7 @@ static void add_fake_entropy_option(void) .name = "r_seed", .type = 'u', .dest = (void *)&seed, + .call_when_found = seed_was_set, .descript = "A 32-bit integer seed value for the entropy device, such as " "97229 (decimal), 0x17BCD (hex), or 0275715 (octal)" }, From d1937983aebf08e79b8f3ca3bb6e552eac5def39 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 3 Sep 2024 17:53:27 +0200 Subject: [PATCH 2/3] [nrf fromtree] board: nrf54l15bsim: Disable native_posix entropy seeding Let's disable the default seeding done by the native_posix entropy driver to allow the normal simulation initialization of the random number generation to take place. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 11cde13b9451b0860dad43b16bf4469c6ccc7da9) --- boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp_defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp_defconfig b/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp_defconfig index 0fde4e01b58..c8f804a2005 100644 --- a/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp_defconfig +++ b/boards/native/nrf_bsim/nrf54l15bsim_nrf54l15_cpuapp_defconfig @@ -6,3 +6,5 @@ CONFIG_NO_OPTIMIZATIONS=y # Start SYSCOUNTER on driver init CONFIG_NRF_GRTC_START_SYSCOUNTER=y + +CONFIG_FAKE_ENTROPY_NATIVE_POSIX_SEED_BY_DEFAULT=n From 5f1fb8f0fc7afdc064cc63279f6371e7bea79dc5 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 6 Sep 2024 13:32:10 +0200 Subject: [PATCH 3/3] [nrf fromtree] manifest: Update nRF hw models to latest Update the HW models module to: d2a119a9c7600ce06033a794de042e0ad9a38702 Including the following: d2a119a 54 ECB/CCM tests: Add BLE spec examples and more printouts 17692a6 54 CCM: Correct variable names 16629b5 RRAMC: Add backwards compatible command line aliases for flash_* 52cbc36 54 AAR, CCM, ECB: Fix reset values and ECB key endianess d51acf4 RADIO: Implement TASK_SOFTRESET 8285509 54 ECB: Correct t_ECB 4f70fba 54: AAR/CCM: Route tasks to the appropriate module 895eabb RADIO: Warn only once about TASK_SOFTRESET not being implemented Signed-off-by: Alberto Escolar Piedras (cherry picked from commit c297e2df67a0d21f660421bd4ae828d12384d721) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 1da99e5545c..746c8b9655c 100644 --- a/west.yml +++ b/west.yml @@ -295,7 +295,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: 4b0b020e25dbf1a11ccccf7b7741d6ca991ba9e4 + revision: d2a119a9c7600ce06033a794de042e0ad9a38702 path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: da78aea63159771956fe0c9263f2e6985b66e9d5