66
77#include "sw/device/lib/base/mmio.h"
88#include "sw/device/lib/dif/dif_keymgr.h"
9+ #include "sw/device/lib/dif/dif_otp_ctrl.h"
10+ #include "sw/device/lib/dif/dif_rstmgr.h"
911#include "sw/device/lib/runtime/ibex.h"
1012#include "sw/device/lib/runtime/log.h"
1113#include "sw/device/lib/testing/keymgr_testutils.h"
14+ #include "sw/device/lib/testing/otp_ctrl_testutils.h"
15+ #include "sw/device/lib/testing/rstmgr_testutils.h"
1216#include "sw/device/lib/testing/test_framework/check.h"
1317#include "sw/device/lib/testing/test_framework/ottf_main.h"
1418#include "sw/device/silicon_creator/lib/base/boot_measurements.h"
2327
2428OTTF_DEFINE_TEST_CONFIG ();
2529
30+ static dif_keymgr_t keymgr ;
31+ static dif_otp_ctrl_t otp_ctrl ;
32+ static dif_rstmgr_t rstmgr ;
2633static uint32_t otp_state [kHmacDigestNumWords + 4 ] = {0 };
2734
35+ static void print_otp_sw_cfg_digests (void ) {
36+ uint64_t creator_digest , owner_digest = 0 ;
37+ CHECK_DIF_OK (dif_otp_ctrl_get_digest (
38+ & otp_ctrl , kDifOtpCtrlPartitionCreatorSwCfg , & creator_digest ));
39+ CHECK_DIF_OK (dif_otp_ctrl_get_digest (
40+ & otp_ctrl , kDifOtpCtrlPartitionOwnerSwCfg , & owner_digest ));
41+ LOG_INFO ("CreatorSwCfg Digest: 0x%08x%08x" , (uint32_t )(creator_digest >> 32 ),
42+ (uint32_t )creator_digest );
43+ LOG_INFO ("OwnerSwCfg Digest: 0x%08x%08x" , (uint32_t )(owner_digest >> 32 ),
44+ (uint32_t )owner_digest );
45+ }
46+
2847bool test_main (void ) {
29- dif_keymgr_t keymgr ;
3048 CHECK_DIF_OK (dif_keymgr_init (
3149 mmio_region_from_addr (TOP_EARLGREY_KEYMGR_BASE_ADDR ), & keymgr ));
50+ CHECK_DIF_OK (dif_otp_ctrl_init (
51+ mmio_region_from_addr (TOP_EARLGREY_OTP_CTRL_CORE_BASE_ADDR ), & otp_ctrl ));
52+ CHECK_DIF_OK (dif_rstmgr_init (
53+ mmio_region_from_addr (TOP_EARLGREY_RSTMGR_AON_BASE_ADDR ), & rstmgr ));
54+
55+ /*// Lock OTP *SwCfg partitions if this is the first boot and reset.*/
56+ if (UNWRAP (rstmgr_testutils_is_reset_info (& rstmgr , kDifRstmgrResetInfoPor ))) {
57+ LOG_INFO ("Power on reset. Locking OTP *SwCfg partitions ..." );
58+ const uint64_t kFakeOtpDigest = 0xaaaabbbbccccdddd ;
59+ CHECK_STATUS_OK (otp_ctrl_testutils_lock_partition (
60+ & otp_ctrl , kDifOtpCtrlPartitionCreatorSwCfg ,
61+ /*digest=*/ kFakeOtpDigest ));
62+ CHECK_STATUS_OK (otp_ctrl_testutils_lock_partition (
63+ & otp_ctrl , kDifOtpCtrlPartitionOwnerSwCfg ,
64+ /*digest=*/ kFakeOtpDigest ));
65+ rstmgr_testutils_reason_clear ();
66+ LOG_INFO ("Issuing a software reset ..." );
67+ CHECK_DIF_OK (dif_rstmgr_software_device_reset (& rstmgr ));
68+ wait_for_interrupt ();
69+ } else {
70+ print_otp_sw_cfg_digests ();
71+ LOG_INFO ("SW reset. Executing test ..." );
72+ }
3273
3374 CHECK_STATUS_OK (keymgr_testutils_check_state (& keymgr , kDifKeymgrStateReset ));
3475
@@ -39,36 +80,31 @@ bool test_main(void) {
3980
4081 if (otp_read32 (OTP_CTRL_PARAM_OWNER_SW_CFG_ROM_KEYMGR_OTP_MEAS_EN_OFFSET ) ==
4182 kHardenedBoolTrue ) {
83+ LOG_INFO ("ROM OTP measurement feature ENABLED." );
4284 // Check that the attestation is equal to the digest of concatenations of:
4385 // - the digest of the CreatorSwCfg partition,
4486 // - the digest of the OwnerSwCfg partition,
4587 // - the SHA256 integrity hash of the first stage boot keys.
46- otp_dai_read (
47- kOtpPartitionCreatorSwCfg ,
48- /*relative_address=*/
49- otp_readable_partition_info (kOtpPartitionCreatorSwCfg ).digest_addr -
50- OTP_CTRL_PARAM_CREATOR_SW_CFG_OFFSET ,
51- otp_state ,
52- /*num_words=*/ 2 );
53- otp_dai_read (
54- kOtpPartitionOwnerSwCfg ,
55- /*relative_address=*/
56- otp_readable_partition_info (kOtpPartitionOwnerSwCfg ).digest_addr -
57- OTP_CTRL_PARAM_OWNER_SW_CFG_OFFSET ,
58- & otp_state [2 ],
59- /*num_words=*/ 2 );
60- otp_dai_read (kOtpPartitionRotCreatorAuthCodesign ,
61- /*relative_address=*/
62- OTP_CTRL_PARAM_ROTCREATORAUTHCODESIGNBLOCKSHA2_256HASHOFFSET -
63- OTP_CTRL_PARAM_ROT_CREATOR_AUTH_CODESIGN_OFFSET ,
64- & otp_state [4 ],
65- /*num_words=*/ kHmacDigestNumWords );
88+ CHECK_DIF_OK (dif_otp_ctrl_get_digest (
89+ & otp_ctrl , kDifOtpCtrlPartitionCreatorSwCfg , (uint64_t * )otp_state ));
90+ CHECK_DIF_OK (dif_otp_ctrl_get_digest (
91+ & otp_ctrl , kDifOtpCtrlPartitionOwnerSwCfg , (uint64_t * )& otp_state [2 ]));
92+ CHECK_STATUS_OK (otp_ctrl_testutils_dai_read32_array (
93+ & otp_ctrl , kDifOtpCtrlPartitionRotCreatorAuthCodesign ,
94+ OTP_CTRL_PARAM_ROTCREATORAUTHCODESIGNBLOCKSHA2_256HASHOFFSET -
95+ OTP_CTRL_PARAM_ROT_CREATOR_AUTH_CODESIGN_OFFSET ,
96+ & otp_state [4 ], /*num_words=*/ kHmacDigestNumWords ));
6697 hmac_digest_t otp_measurement ;
67- hmac_sha256 (otp_state , (kHmacDigestNumWords + 4 ) * sizeof (uint32_t ),
68- & otp_measurement );
98+ hmac_sha256 (otp_state , sizeof (otp_state ), & otp_measurement );
99+ LOG_INFO ("OTP CreatorSwCfg Digest: 0x%08x%08x" , otp_state [1 ], otp_state [0 ]);
100+ LOG_INFO ("OTP OwnerSwCfg Digest: 0x%08x%08x" , otp_state [3 ], otp_state [2 ]);
101+ LOG_INFO ("OTP Root Keys Digest: 0x%08x%08x%08x%08x%08x%08x%08x%08x" ,
102+ otp_state [11 ], otp_state [10 ], otp_state [9 ], otp_state [8 ],
103+ otp_state [7 ], otp_state [6 ], otp_state [5 ], otp_state [4 ]);
69104 CHECK_ARRAYS_EQ (bindings .attestation , otp_measurement .digest ,
70105 ARRAYSIZE (bindings .attestation ));
71106 } else {
107+ LOG_INFO ("ROM OTP measurement feature DISABLED." );
72108 // Check that the attestation is equal to `binding_value` field of the
73109 // manifest.
74110 CHECK_ARRAYS_EQ (bindings .attestation , manifest -> binding_value .data ,
0 commit comments