11#include "sw/device/lib/testing/test_framework/check.h"
13#define MODULE_ID MAKE_MODULE_ID('o', 'b', 't')
19 kOtbnWlenBytes = 256 / 8,
22status_t otbn_testutils_wait_for_done(
const dif_otbn_t *otbn,
27 TRY(dif_otbn_get_status(otbn, &
status));
28 busy =
status != kDifOtbnStatusIdle &&
status != kDifOtbnStatusLocked;
32 uint32_t instruction_count;
33 TRY(dif_otbn_get_insn_cnt(otbn, &instruction_count));
36 TRY(dif_otbn_get_err_bits(otbn, &err_bits));
39 TRY_CHECK(
status == kDifOtbnStatusIdle,
"OTBN is locked. Error bits: 0x%08x",
44 err_bits == expected_err_bits,
45 "OTBN error bits: got: 0x%08x, expected: 0x%08x.\nInstruction count: "
47 err_bits, expected_err_bits, instruction_count);
22status_t otbn_testutils_wait_for_done(
const dif_otbn_t *otbn, {
…}
61static void check_app_address_ranges(
const otbn_app_t *app) {
69 check_app_address_ranges(&app);
75 TRY_CHECK(imem_size %
sizeof(uint32_t) == 0);
76 TRY_CHECK(data_size %
sizeof(uint32_t) == 0);
78 TRY(dif_otbn_imem_write(otbn, 0, app.
imem_start, imem_size));
88 TRY(dif_otbn_write_cmd(otbn, kDifOtbnCmdExecute));
92status_t otbn_testutils_write_data(
const dif_otbn_t *otbn,
size_t len_bytes,
94 TRY(dif_otbn_dmem_write(otbn, dest, src, len_bytes));
92status_t otbn_testutils_write_data(
const dif_otbn_t *otbn,
size_t len_bytes, {
…}
98status_t otbn_testutils_read_data(
const dif_otbn_t *otbn,
size_t len_bytes,
100 TRY(dif_otbn_dmem_read(otbn, src, dest, len_bytes));
98status_t otbn_testutils_read_data(
const dif_otbn_t *otbn,
size_t len_bytes, {
…}
104status_t otbn_dump_dmem(
const dif_otbn_t *otbn, uint32_t max_addr) {
105 TRY_CHECK(max_addr % kOtbnWlenBytes == 0);
108 max_addr = dif_otbn_get_dmem_size_bytes(otbn);
111 TRY_CHECK(max_addr <= UINT32_MAX,
"max_addr must fit in uint32_t");
112 for (uint32_t i = 0; i < max_addr; i += kOtbnWlenBytes) {
113 uint32_t data[kOtbnWlenBytes /
sizeof(uint32_t)];
114 TRY(dif_otbn_dmem_read(otbn, i, data, kOtbnWlenBytes));
115 LOG_INFO(
"DMEM @%04d: 0x%08x%08x%08x%08x%08x%08x%08x%08x",
116 i / kOtbnWlenBytes, data[7], data[6], data[5], data[4], data[3],
117 data[2], data[1], data[0]);