17
17
/* Assumption of 2K TCPA log size reserved for CAR/SRAM */
18
18
#define MAX_PRERAM_TPM_LOG_ENTRIES 15
19
19
20
+ /**
21
+ * Checks whether TCG TPM1.2 log format should be used.
22
+ * When required, initializes TPM if it wasn't yet initialized.
23
+ */
24
+ static inline bool tpm_log_use_tpm1_format (void )
25
+ {
26
+ if (CONFIG (TPM_LOG_TPM1 ))
27
+ return true;
28
+ if (CONFIG (TPM_LOG_TCG ))
29
+ return tlcl_lib_init () == TPM_SUCCESS && tlcl_get_family () == TPM_1 ;
30
+ return false;
31
+ }
32
+
33
+ /**
34
+ * Checks whether TCG TPM2.0 log format should be used.
35
+ * When required, initializes TPM if it wasn't yet initialized.
36
+ */
37
+ static inline bool tpm_log_use_tpm2_format (void )
38
+ {
39
+ if (CONFIG (TPM_LOG_TPM2 ))
40
+ return true;
41
+ if (CONFIG (TPM_LOG_TCG ))
42
+ return tlcl_lib_init () == TPM_SUCCESS && tlcl_get_family () == TPM_2 ;
43
+ return false;
44
+ }
45
+
20
46
/**
21
47
* Retrieves hash algorithm used by TPM event log or VB2_HASH_INVALID.
22
48
*/
@@ -25,10 +51,10 @@ static inline enum vb2_hash_algorithm tpm_log_alg(void)
25
51
if (CONFIG (TPM_LOG_CB ))
26
52
return (tlcl_get_family () == TPM_1 ? VB2_HASH_SHA1 : VB2_HASH_SHA256 );
27
53
28
- if (CONFIG ( TPM_LOG_TPM1 ))
54
+ if (tpm_log_use_tpm1_format ( ))
29
55
return VB2_HASH_SHA1 ;
30
56
31
- if (CONFIG ( TPM_LOG_TPM2 )) {
57
+ if (tpm_log_use_tpm2_format ( )) {
32
58
if (CONFIG (TPM_HASH_SHA1 ))
33
59
return VB2_HASH_SHA1 ;
34
60
if (CONFIG (TPM_HASH_SHA256 ))
@@ -56,9 +82,9 @@ static inline void *tpm_log_cbmem_init(void)
56
82
{
57
83
if (CONFIG (TPM_LOG_CB ))
58
84
return tpm_cb_log_cbmem_init ();
59
- if (CONFIG ( TPM_LOG_TPM1 ))
85
+ if (tpm_log_use_tpm1_format ( ))
60
86
return tpm1_log_cbmem_init ();
61
- if (CONFIG ( TPM_LOG_TPM2 ))
87
+ if (tpm_log_use_tpm2_format ( ))
62
88
return tpm2_log_cbmem_init ();
63
89
return NULL ;
64
90
}
@@ -71,9 +97,9 @@ static inline void tpm_preram_log_clear(void)
71
97
{
72
98
if (CONFIG (TPM_LOG_CB ))
73
99
tpm_cb_preram_log_clear ();
74
- else if (CONFIG ( TPM_LOG_TPM1 ))
100
+ else if (tpm_log_use_tpm1_format ( ))
75
101
tpm1_preram_log_clear ();
76
- else if (CONFIG ( TPM_LOG_TPM2 ))
102
+ else if (tpm_log_use_tpm2_format ( ))
77
103
tpm2_preram_log_clear ();
78
104
}
79
105
@@ -84,9 +110,9 @@ static inline uint16_t tpm_log_get_size(const void *log_table)
84
110
{
85
111
if (CONFIG (TPM_LOG_CB ))
86
112
return tpm_cb_log_get_size (log_table );
87
- if (CONFIG ( TPM_LOG_TPM1 ))
113
+ if (tpm_log_use_tpm1_format ( ))
88
114
return tpm1_log_get_size (log_table );
89
- if (CONFIG ( TPM_LOG_TPM2 ))
115
+ if (tpm_log_use_tpm2_format ( ))
90
116
return tpm2_log_get_size (log_table );
91
117
return 0 ;
92
118
}
@@ -98,9 +124,9 @@ static inline void tpm_log_copy_entries(const void *from, void *to)
98
124
{
99
125
if (CONFIG (TPM_LOG_CB ))
100
126
tpm_cb_log_copy_entries (from , to );
101
- else if (CONFIG ( TPM_LOG_TPM1 ))
127
+ else if (tpm_log_use_tpm1_format ( ))
102
128
tpm1_log_copy_entries (from , to );
103
- else if (CONFIG ( TPM_LOG_TPM2 ))
129
+ else if (tpm_log_use_tpm2_format ( ))
104
130
tpm2_log_copy_entries (from , to );
105
131
}
106
132
@@ -112,9 +138,9 @@ static inline int tpm_log_get(int entry_idx, int *pcr, const uint8_t **digest_da
112
138
{
113
139
if (CONFIG (TPM_LOG_CB ))
114
140
return tpm_cb_log_get (entry_idx , pcr , digest_data , digest_algo , event_name );
115
- if (CONFIG ( TPM_LOG_TPM1 ))
141
+ if (tpm_log_use_tpm1_format ( ))
116
142
return tpm1_log_get (entry_idx , pcr , digest_data , digest_algo , event_name );
117
- if (CONFIG ( TPM_LOG_TPM2 ))
143
+ if (tpm_log_use_tpm2_format ( ))
118
144
return tpm2_log_get (entry_idx , pcr , digest_data , digest_algo , event_name );
119
145
return 1 ;
120
146
}
@@ -134,9 +160,9 @@ static inline void tpm_log_add_table_entry(const char *name, const uint32_t pcr,
134
160
{
135
161
if (CONFIG (TPM_LOG_CB ))
136
162
tpm_cb_log_add_table_entry (name , pcr , digest_algo , digest , digest_len );
137
- else if (CONFIG ( TPM_LOG_TPM1 ))
163
+ else if (tpm_log_use_tpm1_format ( ))
138
164
tpm1_log_add_table_entry (name , pcr , digest_algo , digest , digest_len );
139
- else if (CONFIG ( TPM_LOG_TPM2 ))
165
+ else if (tpm_log_use_tpm2_format ( ))
140
166
tpm2_log_add_table_entry (name , pcr , digest_algo , digest , digest_len );
141
167
}
142
168
@@ -147,9 +173,9 @@ static inline void tpm_log_dump(void *unused)
147
173
{
148
174
if (CONFIG (TPM_LOG_CB ))
149
175
tpm_cb_log_dump ();
150
- else if (CONFIG ( TPM_LOG_TPM1 ))
176
+ else if (tpm_log_use_tpm1_format ( ))
151
177
tpm1_log_dump ();
152
- else if (CONFIG ( TPM_LOG_TPM2 ))
178
+ else if (tpm_log_use_tpm2_format ( ))
153
179
tpm2_log_dump ();
154
180
}
155
181
0 commit comments