1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 
8 #ifndef __TST_OTP_H__
9 #define __TST_OTP_H__
10 
11 #include <stdint.h>
12 
13 
14 /* TBD later should these definitions should be taken from shared cc_*.h */
15 
16 /* LCS */
17 #define TESTS_LCS_CM        0x0
18 #define TESTS_LCS_DM        0x1
19 #define TESTS_LCS_SEC_DISABLED  0x3
20 #define TESTS_LCS_SEC_ENABLED   0x5
21 #define TESTS_LCS_RMA       0x7
22 
23 /* HW KEYS */
24 #define TEST_HUK_KEY            0
25 #define TEST_RTL_KEY            1
26 #define TEST_KCP_KEY            2
27 #define TEST_KCE_KEY            3
28 #define TEST_KPICV_KEY          4
29 #define TEST_KCEICV_KEY         5
30 
31 #define TEST_HBK0_KEY           16
32 #define TEST_HBK1_KEY           17
33 #define TEST_HBK_FULL_KEY       18
34 
35 typedef enum otpHbkTypes_t{
36     TEST_OTP_HBK0_TYPE = 1, //HBK0
37     TEST_OTP_HBK1_TYPE = 2, //HBK1
38     TEST_OTP_HBK_256_TYPE = 4, //HBK
39 }OtpHbkTypes_t;
40 
41 
42 /******************************/
43 /*   function declaration     */
44 /*****************************/
45 
46 /*
47 unsigned int testBurnOtp(unsigned int  *otp, unsigned int  nextLcs);
48 unsigned int testGetLcs(unsigned int  *lcs);
49 unsigned int testGetOtpSize(unsigned int * size);
50 unsigned int testCheckLcs(unsigned int  nextLcs);
51 */
52 // hash key
53 
54 // tbd - move functionality to general functions
55 /**
56  * This function sets HBK to otp buffer and update "NotInUse" and "ZerosBits"
57  *
58  */uint32_t Test_SetHbkInOtpBuff(
59          uint32_t *otp,         //!< [out] otp image
60          uint8_t *hbkBuff,      //!< [in]  hbk value
61          OtpHbkTypes_t type     //!< [in]  hbk type
62          );
63 
64  /**
65   * This function pads with '0's the remaining SW version field after the first '0'
66   *
67   */uint32_t Test_SetSwVerInOtpBuff(
68          uint32_t *otp,         //!< [out] otp image
69          uint32_t offset,       //!< [in]  offset within the otp
70          uint32_t max_size      //!< [in]  max field size in words
71          );
72 
73 /**
74  * This function sets hw key itself to otp buffer and update "NotInUse" and "ZerosBits"
75  *
76  */
77 uint32_t Test_SetKeyOtpBuff(
78         uint32_t *otpBuf,       //!< [out] otp image
79         uint32_t *keyBuff,      //!< [in]  key value
80         uint32_t keyType        //!< [in]  hw key type
81         );
82 
83 /**
84  * This function gets hw key and its size from otp buffer to user buffer
85  *
86  */
87 uint32_t Test_GetKeyOtpBuff(
88         uint32_t *otpBuf,         //!< [in] otp image
89         uint32_t keyType,         //!< [in] key type
90         uint32_t *keySizeInWords, //!< [in] size in words
91         uint32_t *keyBuff         //!< [out] hw key value
92         );
93 
94 /**
95  * This function sets "notInUse" bit for appropriate hw key
96  *
97  */
98 uint32_t Test_SetNotInUseOtpBuff(
99         uint32_t *otpBuf,       //!< [out] otp image
100         uint32_t keyType,       //!< [in]  hw key type
101         uint32_t value          //!< [in] "in use" bit value to set
102         );
103 
104 /**
105  * This function sets "ZeroBits" bits for appropriate hw key
106  *
107  */
108 uint32_t Test_SetZeroBitsOtpBuff(
109         uint32_t *otpBuf,       //!< [out] otp image
110         uint32_t keyType,       //!< [in]  hw key type
111         uint32_t value          //!< [in]  value
112         );
113 
114 /**
115  * This function sets manufacture and oem flags accordingly to reuired LCS state
116  *
117  */
118 uint32_t Test_SetLcsOtpBuff(
119         uint32_t *otpBuf,       //!< [out] otp image
120         uint32_t lcsState       //!< [in] lifecycle state
121         );
122 
123 /**
124  * This function sets entire OTP image with set of keys and lcs as parameter
125  *
126  */
127 void Test_SetDefaultOtp(
128         uint32_t* otpValues,     //!< [out] otp image
129         uint32_t otpSize,        //!< [in] otp size
130         uint32_t lcsState        //!< [in] lcs
131         );
132 
133 /**
134  * This function burns otp image through "back door", performs reset, and check if system booted to required lcs
135  *
136  */
137 uint32_t Test_GetKeySizeInWordsOtp(
138         uint32_t  keyType,         //!< [in] key Type
139         uint32_t* keySizeInWords   //!< [out] key Size in words
140         );
141 
142 /**
143  * This function burns otp image through "back door", performs reset, and check if system booted to required lcs
144  *
145  */
146 uint32_t Test_BurnOtp(
147         uint32_t  *otp,         //!< [in] otp image
148         uint32_t  nextLcs       //!< [in] lcs that system should boot to
149         );
150 
151 
152 
153 #endif //__TST_OTP_H__
154