4#include "sw/device/lib/testing/entropy_testutils.h"
9#include "sw/device/lib/testing/test_framework/check.h"
18#define MODULE_ID MAKE_MODULE_ID('e', 'n', 'y')
20status_t entropy_testutils_entropy_src_init(
void) {
23 CHECK_DIF_OK(dif_entropy_src_init_from_dt(
kDtEntropySrc, &entropy_src));
28 .route_to_firmware =
false,
29 .bypass_conditioner =
false,
30 .clear_esfinal_fifo_while_disabled =
true,
32 .health_test_window_size = 0x0200,
41status_t entropy_testutils_auto_mode_init(
void) {
45 CHECK_DIF_OK(dif_csrng_init_from_dt(
kDtCsrng, &csrng));
46 CHECK_DIF_OK(dif_edn_init_from_dt(
kDtEdn0, &edn0));
47 CHECK_DIF_OK(dif_edn_init_from_dt(
kDtEdn1, &edn1));
49 TRY(entropy_testutils_stop_all());
52 TRY(entropy_testutils_entropy_src_init());
53 TRY(dif_csrng_configure(&csrng));
56 TRY(dif_edn_set_auto_mode(
64 .cmd = csrng_cmd_header_build(kCsrngAppCmdInstantiate,
75 .cmd = csrng_cmd_header_build(
86 .cmd = csrng_cmd_header_build(kCsrngAppCmdGenerate,
96 .reseed_interval = 32,
100 TRY(dif_edn_set_auto_mode(
107 .cmd = csrng_cmd_header_build(kCsrngAppCmdInstantiate,
118 .cmd = csrng_cmd_header_build(
129 .cmd = csrng_cmd_header_build(kCsrngAppCmdGenerate,
139 .reseed_interval = 4,
144status_t entropy_testutils_boot_mode_init(
void) {
148 CHECK_DIF_OK(dif_csrng_init_from_dt(
kDtCsrng, &csrng));
149 CHECK_DIF_OK(dif_edn_init_from_dt(
kDtEdn0, &edn0));
150 CHECK_DIF_OK(dif_edn_init_from_dt(
kDtEdn1, &edn1));
152 TRY(entropy_testutils_stop_all());
154 TRY(entropy_testutils_entropy_src_init());
155 TRY(dif_csrng_configure(&csrng));
156 TRY(dif_edn_set_boot_mode(&edn0));
157 TRY(dif_edn_set_boot_mode(&edn1));
158 TRY(dif_edn_configure(&edn0));
159 TRY(dif_edn_configure(&edn1));
163status_t entropy_testutils_stop_csrng_edn(
void) {
167 CHECK_DIF_OK(dif_csrng_init_from_dt(
kDtCsrng, &csrng));
168 CHECK_DIF_OK(dif_edn_init_from_dt(
kDtEdn0, &edn0));
169 CHECK_DIF_OK(dif_edn_init_from_dt(
kDtEdn1, &edn1));
171 TRY(dif_edn_stop(&edn0));
172 TRY(dif_edn_stop(&edn1));
173 TRY(dif_csrng_stop(&csrng));
177status_t entropy_testutils_stop_all(
void) {
178 CHECK_STATUS_OK(entropy_testutils_stop_csrng_edn());
180#ifdef HAS_ENTROPY_SRC
182 CHECK_DIF_OK(dif_entropy_src_init_from_dt(
kDtEntropySrc, &entropy_src));
183 TRY(dif_entropy_src_stop(&entropy_src));
189status_t entropy_testutils_error_check(
const dif_csrng_t *csrng,
193 bool found_error =
false;
195#ifdef HAS_ENTROPY_SRC
197 CHECK_DIF_OK(dif_entropy_src_init_from_dt(
kDtEntropySrc, &entropy_src));
198 TRY(dif_entropy_src_get_errors(&entropy_src, &err_code));
201 LOG_ERROR(
"entropy_src status. err: 0x%x", err_code);
206 TRY(dif_csrng_get_cmd_interface_status(csrng, &
status));
213 uint32_t fifo_errors;
214 TRY(dif_edn_get_errors(edn0, &fifo_errors, &err_code));
215 if (err_code || fifo_errors) {
217 LOG_ERROR(
"end0 error status. err: 0x%x, fifo_err: 0x%x", err_code,
221 TRY(dif_edn_get_errors(edn1, &fifo_errors, &err_code));
222 if (err_code || fifo_errors) {
224 LOG_ERROR(
"end1 error status. err: 0x%x, fifo_err: 0x%x", err_code,
227 TRY_CHECK(!found_error,
"entropy_testutils_error_check fail");