Software APIs
flash_device_info_flash_wr_functest.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include <stdint.h>
6 
11 #include "sw/device/lib/testing/flash_ctrl_testutils.h"
12 #include "sw/device/lib/testing/test_framework/check.h"
14 #include "sw/device/silicon_creator/manuf/lib/flash_info_fields.h"
15 #include "sw/device/silicon_creator/manuf/tests/test_wafer_auth_secret.h"
16 
18 
19 OTTF_DEFINE_TEST_CONFIG();
20 
21 static dif_flash_ctrl_state_t flash_ctrl_state;
22 static dif_lc_ctrl_t lc_ctrl;
23 
24 /**
25  * Initializes all DIF handles used in this test.
26  */
27 static status_t peripheral_handles_init(void) {
29  &flash_ctrl_state,
31  TRY(dif_lc_ctrl_init(
33  return OK_STATUS();
34 }
35 
36 bool test_main(void) {
37  CHECK_STATUS_OK(peripheral_handles_init());
38 
39  LOG_INFO("Executing from flash.");
40 
41  // Read LC state.
43  CHECK_DIF_OK(dif_lc_ctrl_get_state(&lc_ctrl, &lc_state));
44 
45  switch (lc_state) {
48  LOG_INFO("Reading the isolated flash partition.");
49  uint32_t byte_address = 0;
50  uint32_t
51  actual_wafer_auth_secret[kFlashInfoWaferAuthSecretSizeIn32BitWords] =
52  {0};
53  CHECK_STATUS_OK(flash_ctrl_testutils_info_region_setup(
54  &flash_ctrl_state, kFlashInfoFieldWaferAuthSecret.page,
55  kFlashInfoFieldWaferAuthSecret.bank,
56  kFlashInfoFieldWaferAuthSecret.partition, &byte_address));
57  CHECK_STATUS_OK(flash_ctrl_testutils_read(
58  &flash_ctrl_state, byte_address,
59  kFlashInfoFieldWaferAuthSecret.partition, actual_wafer_auth_secret,
60  kDifFlashCtrlPartitionTypeInfo,
61  kFlashInfoWaferAuthSecretSizeIn32BitWords,
62  /*delay_micros=*/0));
63  CHECK_ARRAYS_EQ(actual_wafer_auth_secret, kExpectedWaferAuthSecret,
64  kFlashInfoWaferAuthSecretSizeIn32BitWords);
65  LOG_INFO("Done.");
66  break;
67  default:
68  LOG_ERROR("Unexpected LC state.");
69  return false;
70  }
71 
72  return true;
73 }