1FTPM_FLAGS = -DGCC -DUSE_WOLFCRYPT -DSIMULATION=NO -DUSE_PLATFORM_EPS -DVTPM
2FTPM_DEBUG =  -DCOMPILER_CHECKS=YES -DfTPMDebug -DRUNTIME_SIZE_CHECKS -DLIBRARY_COMPATIBILITY_CHECK
3FTPM_RELEASE = -DCOMPILER_CHECKS=NO -DRUNTIME_SIZE_CHECKS=NO -DLIBRARY_COMPATIBILITY_CHECK=NO
4
5#
6# The fTPM needs to overwrite some of the header files used in the reference implementation. The search order GCC
7# uses is dependent on the order the '-I/include/path' arguments are passed in. This is depended on the optee_os build
8# system which makes it brittle. Force including these files here will make sure the correct files are used first.
9#
10
11FTPM_INCLUDES = -include ./reference/include/VendorString.h -include ./reference/include/Implementation.h
12
13#
14# The TPM causes a few warnings when compiled with GCC which are not critical.
15#
16
17FTPM_WARNING_SUPPRESS = -Wno-cast-align -Wno-switch-default -Wno-suggest-attribute=noreturn -Wno-missing-braces -Wno-sign-compare
18
19cflags-y += $(FTPM_FLAGS) $(WOLF_SSL_FLAGS) $(FTPM_INCLUDES) $(FTPM_WARNING_SUPPRESS)
20
21ifeq ($(CFG_TA_DEBUG),y)
22cflags-y += $(FTPM_DEBUG)
23else
24cflags-y += $(FTPM_RELEASE)
25endif
26
27#
28# For the purposes of this command the current working directory is the makefile root (/fTPM) folder,
29# but the symlink will be created relative to THIS directory so the source requires an extra '../../'.
30#
31# Symlinks are needed since all build output is placed relative to the root. External libraries would result in
32# binaries located outside the ouptut folder.
33#
34./lib/tpm/tpm_symlink:
35	@echo Checking symlink to the TPM folder: $(abspath $(TPM_ROOT))
36	@if [ -L ./lib/tpm/tpm_symlink ] ; \
37	then \
38	echo Symlink already established ; \
39	else \
40	echo Establishing symlink. ; \
41	ln -s ../../$(TPM_ROOT) ./lib/tpm/tpm_symlink; \
42	fi
43
44.PHONY: remove_tpm_symlink
45remove_tpm_symlink:
46	@if [ -e ./lib/tpm/tpm_symlink ] ; \
47	then \
48	unlink ./lib/tpm/tpm_symlink ; \
49	echo Clearing symlink to the TPM folder: $(abspath $(TPM_ROOT)) ; \
50	fi
51
52global-incdirs-y += tpm_symlink/TPMCmd/tpm/include
53global-incdirs-y += tpm_symlink/TPMCmd/tpm/include/ltc
54global-incdirs-y += tpm_symlink/TPMCmd/tpm/include/prototypes
55global-incdirs-y += tpm_symlink/TPMCmd/tpm/include/wolf
56
57#
58# Generated in WSL using:
59# find -name *.c | while read line; do echo XXXX$line; done | sed -e 's/XXXX.\//srcs-y += tpm_symlink/TPMCmd/tpm/src//g'
60# This may need to be updated if there are any changes to the reference implementation.
61#
62
63srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Asymmetric/ECC_Parameters.c
64srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Asymmetric/ECDH_KeyGen.c
65srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Asymmetric/ECDH_ZGen.c
66srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Asymmetric/EC_Ephemeral.c
67srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Asymmetric/RSA_Decrypt.c
68srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Asymmetric/RSA_Encrypt.c
69srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Asymmetric/ZGen_2Phase.c
70srcs-y += tpm_symlink/TPMCmd/tpm/src/command/AttachedComponent/AC_GetCapability.c
71srcs-y += tpm_symlink/TPMCmd/tpm/src/command/AttachedComponent/AC_Send.c
72srcs-y += tpm_symlink/TPMCmd/tpm/src/command/AttachedComponent/AC_spt.c
73srcs-y += tpm_symlink/TPMCmd/tpm/src/command/AttachedComponent/Policy_AC_SendSelect.c
74srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Attestation/Attest_spt.c
75srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Attestation/Certify.c
76srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Attestation/CertifyCreation.c
77srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Attestation/GetCommandAuditDigest.c
78srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Attestation/GetSessionAuditDigest.c
79srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Attestation/GetTime.c
80srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Attestation/Quote.c
81srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Capability/GetCapability.c
82srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Capability/TestParms.c
83srcs-y += tpm_symlink/TPMCmd/tpm/src/command/ClockTimer/ClockRateAdjust.c
84srcs-y += tpm_symlink/TPMCmd/tpm/src/command/ClockTimer/ClockSet.c
85srcs-y += tpm_symlink/TPMCmd/tpm/src/command/ClockTimer/ReadClock.c
86srcs-y += tpm_symlink/TPMCmd/tpm/src/command/CommandAudit/SetCommandCodeAuditStatus.c
87srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Context/ContextLoad.c
88srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Context/ContextSave.c
89srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Context/Context_spt.c
90srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Context/EvictControl.c
91srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Context/FlushContext.c
92srcs-y += tpm_symlink/TPMCmd/tpm/src/command/DA/DictionaryAttackLockReset.c
93srcs-y += tpm_symlink/TPMCmd/tpm/src/command/DA/DictionaryAttackParameters.c
94srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Duplication/Duplicate.c
95srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Duplication/Import.c
96srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Duplication/Rewrap.c
97srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyAuthorize.c
98srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyAuthorizeNV.c
99srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyAuthValue.c
100srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyCommandCode.c
101srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyCounterTimer.c
102srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyCpHash.c
103srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyDuplicationSelect.c
104srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyGetDigest.c
105srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyLocality.c
106srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyNameHash.c
107srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyNV.c
108srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyNvWritten.c
109srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyOR.c
110srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyPassword.c
111srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyPCR.c
112srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyPhysicalPresence.c
113srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicySecret.c
114srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicySigned.c
115srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyTemplate.c
116srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/PolicyTicket.c
117srcs-y += tpm_symlink/TPMCmd/tpm/src/command/EA/Policy_spt.c
118srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Ecdaa/Commit.c
119srcs-y += tpm_symlink/TPMCmd/tpm/src/command/FieldUpgrade/FieldUpgradeData.c
120srcs-y += tpm_symlink/TPMCmd/tpm/src/command/FieldUpgrade/FieldUpgradeStart.c
121srcs-y += tpm_symlink/TPMCmd/tpm/src/command/FieldUpgrade/FirmwareRead.c
122srcs-y += tpm_symlink/TPMCmd/tpm/src/command/HashHMAC/EventSequenceComplete.c
123srcs-y += tpm_symlink/TPMCmd/tpm/src/command/HashHMAC/HashSequenceStart.c
124srcs-y += tpm_symlink/TPMCmd/tpm/src/command/HashHMAC/HMAC_Start.c
125srcs-y += tpm_symlink/TPMCmd/tpm/src/command/HashHMAC/MAC_Start.c
126srcs-y += tpm_symlink/TPMCmd/tpm/src/command/HashHMAC/SequenceComplete.c
127srcs-y += tpm_symlink/TPMCmd/tpm/src/command/HashHMAC/SequenceUpdate.c
128srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Hierarchy/ChangeEPS.c
129srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Hierarchy/ChangePPS.c
130srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Hierarchy/Clear.c
131srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Hierarchy/ClearControl.c
132srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Hierarchy/CreatePrimary.c
133srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Hierarchy/HierarchyChangeAuth.c
134srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Hierarchy/HierarchyControl.c
135srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Hierarchy/SetPrimaryPolicy.c
136srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Misc/PP_Commands.c
137srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Misc/SetAlgorithmSet.c
138srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_Certify.c
139srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_ChangeAuth.c
140srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_DefineSpace.c
141srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_Extend.c
142srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_GlobalWriteLock.c
143srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_Increment.c
144srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_Read.c
145srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_ReadLock.c
146srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_ReadPublic.c
147srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_SetBits.c
148srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_spt.c
149srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_UndefineSpace.c
150srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_UndefineSpaceSpecial.c
151srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_Write.c
152srcs-y += tpm_symlink/TPMCmd/tpm/src/command/NVStorage/NV_WriteLock.c
153srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/ActivateCredential.c
154srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/Create.c
155srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/CreateLoaded.c
156srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/Load.c
157srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/LoadExternal.c
158srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/MakeCredential.c
159srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/ObjectChangeAuth.c
160srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/Object_spt.c
161srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/ReadPublic.c
162srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Object/Unseal.c
163srcs-y += tpm_symlink/TPMCmd/tpm/src/command/PCR/PCR_Allocate.c
164srcs-y += tpm_symlink/TPMCmd/tpm/src/command/PCR/PCR_Event.c
165srcs-y += tpm_symlink/TPMCmd/tpm/src/command/PCR/PCR_Extend.c
166srcs-y += tpm_symlink/TPMCmd/tpm/src/command/PCR/PCR_Read.c
167srcs-y += tpm_symlink/TPMCmd/tpm/src/command/PCR/PCR_Reset.c
168srcs-y += tpm_symlink/TPMCmd/tpm/src/command/PCR/PCR_SetAuthPolicy.c
169srcs-y += tpm_symlink/TPMCmd/tpm/src/command/PCR/PCR_SetAuthValue.c
170srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Random/GetRandom.c
171srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Random/StirRandom.c
172srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Session/PolicyRestart.c
173srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Session/StartAuthSession.c
174srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Signature/Sign.c
175srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Signature/VerifySignature.c
176srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Startup/Shutdown.c
177srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Startup/Startup.c
178srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Symmetric/EncryptDecrypt.c
179srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Symmetric/EncryptDecrypt2.c
180srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Symmetric/EncryptDecrypt_spt.c
181srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Symmetric/Hash.c
182srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Symmetric/HMAC.c
183srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Symmetric/MAC.c
184srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Testing/GetTestResult.c
185srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Testing/IncrementalSelfTest.c
186srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Testing/SelfTest.c
187srcs-y += tpm_symlink/TPMCmd/tpm/src/command/Vendor/Vendor_TCG_Test.c
188srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/AlgorithmTests.c
189srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/BnConvert.c
190srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/BnMath.c
191srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/BnMemory.c
192srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptCmac.c
193srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptDes.c
194srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptEccData.c
195srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptEccKeyExchange.c
196srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptEccMain.c
197srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptEccSignature.c
198srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptHash.c
199srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptHashData.c
200srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptPrime.c
201srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptPrimeSieve.c
202srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptRand.c
203srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptRsa.c
204srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptSelfTest.c
205srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptSmac.c
206srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptSym.c
207srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/CryptUtil.c
208srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/ltc/TpmToLtcDesSupport.c
209srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/ltc/TpmToLtcMath.c
210srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/ltc/TpmToLtcSupport.c
211srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/ossl/TpmToOsslDesSupport.c
212srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/ossl/TpmToOsslMath.c
213srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/ossl/TpmToOsslSupport.c
214srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/PrimeData.c
215srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/RsaKeyCache.c
216srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/Ticket.c
217srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/wolf/TpmToWolfDesSupport.c
218srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/wolf/TpmToWolfMath.c
219srcs-y += tpm_symlink/TPMCmd/tpm/src/crypt/wolf/TpmToWolfSupport.c
220srcs-y += tpm_symlink/TPMCmd/tpm/src/events/_TPM_Hash_Data.c
221srcs-y += tpm_symlink/TPMCmd/tpm/src/events/_TPM_Hash_End.c
222srcs-y += tpm_symlink/TPMCmd/tpm/src/events/_TPM_Hash_Start.c
223srcs-y += tpm_symlink/TPMCmd/tpm/src/events/_TPM_Init.c
224srcs-y += tpm_symlink/TPMCmd/tpm/src/main/CommandDispatcher.c
225srcs-y += tpm_symlink/TPMCmd/tpm/src/main/ExecCommand.c
226srcs-y += tpm_symlink/TPMCmd/tpm/src/main/SessionProcess.c
227srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/CommandAudit.c
228srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/DA.c
229srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/Hierarchy.c
230srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/NvDynamic.c
231srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/NvReserved.c
232srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/Object.c
233srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/PCR.c
234srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/PP.c
235srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/Session.c
236srcs-y += tpm_symlink/TPMCmd/tpm/src/subsystem/Time.c
237srcs-y += tpm_symlink/TPMCmd/tpm/src/support/AlgorithmCap.c
238srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Bits.c
239srcs-y += tpm_symlink/TPMCmd/tpm/src/support/CommandCodeAttributes.c
240srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Entity.c
241srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Global.c
242srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Handle.c
243srcs-y += tpm_symlink/TPMCmd/tpm/src/support/IoBuffers.c
244srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Locality.c
245srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Manufacture.c
246srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Marshal.c
247srcs-y += tpm_symlink/TPMCmd/tpm/src/support/MathOnByteBuffers.c
248srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Memory.c
249srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Power.c
250srcs-y += tpm_symlink/TPMCmd/tpm/src/support/PropertyCap.c
251srcs-y += tpm_symlink/TPMCmd/tpm/src/support/Response.c
252srcs-y += tpm_symlink/TPMCmd/tpm/src/support/ResponseCodeProcessing.c
253srcs-y += tpm_symlink/TPMCmd/tpm/src/support/TpmFail.c
254srcs-y += tpm_symlink/TPMCmd/tpm/src/support/TpmSizeChecks.c