tpm2: define reserved space's sizes and addresses at compile time

s_reservedSize[] and s_reservedAddr[] are practically compile-time
constants, but they are filled-in dynamically and also cleared on TPM
state transitions. This adds code size, use SRAM and requires proper
initialization sequence to use TPM reserved spaces early in the boot
sequence. By moving it to compile-time constants we can simplify code
and make sure they are always initialized.

Before: 9984 bytes in flash and 1076 bytes free
After: 10092 bytes in flash and 1364 bytes free

BUG=b:285094026, b:262324344
TEST=CQ, make & test/tpm_test.py -p
Manually check content of variables:

`objdump -t build/cr50/RW/ec.RW.elf | grep s_reserved`
00074eb4 g     O .rodata 00000048 .hidden s_reservedAddr.lto_priv.0
00074e6c g     O .rodata 00000048 .hidden s_reservedSize.lto_priv.0

`xxd -seek 0x30e6c -e -g 2 -l 144 build/cr50/RW/ec.RW.bin`
00030e6c: 0004 0002 0002 0002 0042 0042 0042 0042   ........B.B.B.B.
00030e7c: 0042 0042 0022 0022 0022 0042 0042 0042   B.B.".".".B.B.B.
00030e8c: 0008 0004 0086 001c 0003 0004 0004 0004   ................
00030e9c: 0004 0004 0002 000f 0002 0008 0004 0004   ................
00030eac: 0004 0060 0b1c 01a8|
     s_reservedAddr:          0000 0004 0006 0008   ..`.............
00030ebc: 000a 004c 008e 00d0 0112 0154 0196 01b8   ..L.......T.....
00030ecc: 01da 01fc 023e 0280 02c2 02ca 02ce 0354   ....>.........T.
00030edc: 0370 0373 0377 037b 037f 0383 0387 0389   p.s.w.{.........
00030eec: 0398 039a 03a2 03a6 03aa 03ae 040e 0f2a   ..............*.

This confirms that sizes are initialized and that addresses are
monotonically increasing and matches original computations.
e.g. 0xf2a = 0x40e + 0xb1c

Original addresses:
Space 0 0004, 0000
Space 1 0002, 0004
Space 2 0002, 0006
Space 3 0002, 0008
Space 4 0042, 000a
Space 5 0042, 004c
Space 6 0042, 008e
Space 7 0042, 00d0
Space 8 0042, 0112
Space 9 0042, 0154
Space 10 0022, 0196
Space 11 0022, 01b8
Space 12 0022, 01da
Space 13 0042, 01fc
Space 14 0042, 023e
Space 15 0042, 0280
Space 16 0008, 02c2
Space 17 0004, 02ca
Space 18 0086, 02ce
Space 19 001c, 0354
Space 20 0003, 0370
Space 21 0004, 0373
Space 22 0004, 0377
Space 23 0004, 037b
Space 24 0004, 037f
Space 25 0004, 0383
Space 26 0002, 0387
Space 27 000f, 0389
Space 28 0002, 0398
Space 29 0008, 039a
Space 30 0004, 03a2
Space 31 0004, 03a6
Space 32 0004, 03aa
Space 33 0060, 03ae
Space 34 0b1c, 040e
Space 35 01a8, 0f2a

Change-Id: Ie02ebeb304833e61273ee7cd3e0bbf9e7634f3e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/tpm2/+/4898271
Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Reviewed-by: Yi Chou <yich@google.com>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
2 files changed
tree: b7a85a863a13266e23f1b20157ab8c9963e14167
  1. fuzz/
  2. .gitignore
  3. _TPM_Hash_Data.c
  4. _TPM_Hash_Data_fp.h
  5. _TPM_Hash_End.c
  6. _TPM_Hash_End_fp.h
  7. _TPM_Hash_Start.c
  8. _TPM_Hash_Start_fp.h
  9. _TPM_Init.c
  10. _TPM_Init_fp.h
  11. ActivateCredential.c
  12. ActivateCredential_fp.h
  13. AlgorithmCap.c
  14. AlgorithmCap_fp.h
  15. Attest_spt.c
  16. Attest_spt_fp.h
  17. BaseTypes.h
  18. Bits.c
  19. bits.h
  20. Bits_fp.h
  21. bool.h
  22. Cancel.c
  23. Capabilities.h
  24. Certify.c
  25. Certify_fp.h
  26. CertifyCreation.c
  27. CertifyCreation_fp.h
  28. ChangeEPS.c
  29. ChangeEPS_fp.h
  30. ChangePPS.c
  31. ChangePPS_fp.h
  32. Clear.c
  33. Clear_fp.h
  34. ClearControl.c
  35. ClearControl_fp.h
  36. Clock.c
  37. ClockRateAdjust.c
  38. ClockRateAdjust_fp.h
  39. ClockSet.c
  40. ClockSet_fp.h
  41. CommandAttributeData.c
  42. CommandAudit.c
  43. CommandAudit_fp.h
  44. CommandCodeAttributes.c
  45. CommandCodeAttributes_fp.h
  46. CommandDispatcher.c
  47. CommandDispatcher_fp.h
  48. Commands_fp.h
  49. Commit.c
  50. Commit_fp.h
  51. Context_spt.c
  52. Context_spt_fp.h
  53. ContextLoad.c
  54. ContextLoad_fp.h
  55. ContextSave.c
  56. ContextSave_fp.h
  57. CpriCryptPri.c
  58. CpriCryptPri_fp.h
  59. CpriDataEcc.c
  60. CpriDataEcc.h
  61. CpriECC.c
  62. CpriECC_fp.h
  63. CpriHash.c
  64. CpriHash_fp.h
  65. CpriHashData.c
  66. CpriMisc.c
  67. CpriMisc_fp.h
  68. CpriRNG.c
  69. CpriRNG_fp.h
  70. CpriRSA.c
  71. CpriRSA_fp.h
  72. CpriSym.c
  73. CpriSym_fp.h
  74. Create.c
  75. Create_fp.h
  76. CreatePrimary.c
  77. CreatePrimary_fp.h
  78. CryptoEngine.h
  79. CryptSelfTest.c
  80. CryptSelfTest_fp.h
  81. CryptUtil.c
  82. CryptUtil_fp.h
  83. DA.c
  84. DA_fp.h
  85. DictionaryAttackLockReset.c
  86. DictionaryAttackLockReset_fp.h
  87. DictionaryAttackParameters.c
  88. DictionaryAttackParameters_fp.h
  89. DRTM.c
  90. Duplicate.c
  91. Duplicate_fp.h
  92. EC_Ephemeral.c
  93. EC_Ephemeral_fp.h
  94. ECC_Parameters.c
  95. ECC_Parameters_fp.h
  96. ECDH_KeyGen.c
  97. ECDH_KeyGen_fp.h
  98. ECDH_ZGen.c
  99. ECDH_ZGen_fp.h
  100. EncryptDecrypt.c
  101. EncryptDecrypt_fp.h
  102. endorsement.c
  103. Entity.c
  104. Entity_fp.h
  105. Entropy.c
  106. EventSequenceComplete.c
  107. EventSequenceComplete_fp.h
  108. EvictControl.c
  109. EvictControl_fp.h
  110. ExecCommand.c
  111. ExecCommand_fp.h
  112. FieldUpgradeData.c
  113. FieldUpgradeData_fp.h
  114. FieldUpgradeStart.c
  115. FieldUpgradeStart_fp.h
  116. FirmwareRead.c
  117. FirmwareRead_fp.h
  118. FlushContext.c
  119. FlushContext_fp.h
  120. GetCapability.c
  121. GetCapability_fp.h
  122. GetCommandAuditDigest.c
  123. GetCommandAuditDigest_fp.h
  124. GetCommandCodeString.c
  125. GetCommandCodeString_fp.h
  126. GetRandom.c
  127. GetRandom_fp.h
  128. GetSessionAuditDigest.c
  129. GetSessionAuditDigest_fp.h
  130. GetTestResult.c
  131. GetTestResult_fp.h
  132. GetTime.c
  133. GetTime_fp.h
  134. Global.c
  135. Global.h
  136. GlobalStateCleanup.c
  137. GlobalStateCleanup_fp.h
  138. Handle.c
  139. Handle_fp.h
  140. HandleProcess.c
  141. HandleProcess_fp.h
  142. Hash.c
  143. Hash_fp.h
  144. HashSequenceStart.c
  145. HashSequenceStart_fp.h
  146. Hierarchy.c
  147. Hierarchy_fp.h
  148. HierarchyChangeAuth.c
  149. HierarchyChangeAuth_fp.h
  150. HierarchyControl.c
  151. HierarchyControl_fp.h
  152. HMAC.c
  153. HMAC_fp.h
  154. HMAC_Start.c
  155. HMAC_Start_fp.h
  156. Implementation.h
  157. Import.c
  158. Import_fp.h
  159. IncrementalSelfTest.c
  160. IncrementalSelfTest_fp.h
  161. InternalRoutines.h
  162. libtpm2.pc.in
  163. LICENSE
  164. Load.c
  165. Load_fp.h
  166. LoadExternal.c
  167. LoadExternal_fp.h
  168. Locality.c
  169. Locality_fp.h
  170. LocalityPlat.c
  171. MakeCredential.c
  172. MakeCredential_fp.h
  173. Makefile
  174. Manufacture.c
  175. Manufacture_fp.h
  176. Marshal_ActivateCredential.c
  177. Marshal_Certify.c
  178. Marshal_CertifyCreation.c
  179. Marshal_ChangeEPS.c
  180. Marshal_ChangePPS.c
  181. Marshal_Clear.c
  182. Marshal_ClearControl.c
  183. Marshal_ClockRateAdjust.c
  184. Marshal_ClockSet.c
  185. Marshal_Commit.c
  186. Marshal_ContextLoad.c
  187. Marshal_ContextSave.c
  188. Marshal_Create.c
  189. Marshal_CreatePrimary.c
  190. Marshal_DictionaryAttackLockReset.c
  191. Marshal_DictionaryAttackParameters.c
  192. Marshal_Duplicate.c
  193. Marshal_EC_Ephemeral.c
  194. Marshal_ECC_Parameters.c
  195. Marshal_ECDH_KeyGen.c
  196. Marshal_ECDH_ZGen.c
  197. Marshal_EncryptDecrypt.c
  198. Marshal_EventSequenceComplete.c
  199. Marshal_EvictControl.c
  200. Marshal_FieldUpgradeData.c
  201. Marshal_FieldUpgradeStart.c
  202. Marshal_FirmwareRead.c
  203. Marshal_FlushContext.c
  204. marshal_fp.h
  205. Marshal_GetCapability.c
  206. Marshal_GetCommandAuditDigest.c
  207. Marshal_GetRandom.c
  208. Marshal_GetSessionAuditDigest.c
  209. Marshal_GetTestResult.c
  210. Marshal_GetTime.c
  211. Marshal_Hash.c
  212. Marshal_HashSequenceStart.c
  213. Marshal_HierarchyChangeAuth.c
  214. Marshal_HierarchyControl.c
  215. Marshal_HMAC.c
  216. Marshal_HMAC_Start.c
  217. Marshal_Import.c
  218. Marshal_IncrementalSelfTest.c
  219. Marshal_Load.c
  220. Marshal_LoadExternal.c
  221. Marshal_MakeCredential.c
  222. Marshal_NV_Certify.c
  223. Marshal_NV_ChangeAuth.c
  224. Marshal_NV_DefineSpace.c
  225. Marshal_NV_Extend.c
  226. Marshal_NV_GlobalWriteLock.c
  227. Marshal_NV_Increment.c
  228. Marshal_NV_Read.c
  229. Marshal_NV_ReadLock.c
  230. Marshal_NV_ReadPublic.c
  231. Marshal_NV_SetBits.c
  232. Marshal_NV_UndefineSpace.c
  233. Marshal_NV_UndefineSpaceSpecial.c
  234. Marshal_NV_Write.c
  235. Marshal_NV_WriteLock.c
  236. Marshal_ObjectChangeAuth.c
  237. Marshal_PCR_Allocate.c
  238. Marshal_PCR_Event.c
  239. Marshal_PCR_Extend.c
  240. Marshal_PCR_Read.c
  241. Marshal_PCR_Reset.c
  242. Marshal_PCR_SetAuthPolicy.c
  243. Marshal_PCR_SetAuthValue.c
  244. Marshal_PolicyAuthorize.c
  245. Marshal_PolicyAuthValue.c
  246. Marshal_PolicyCommandCode.c
  247. Marshal_PolicyCounterTimer.c
  248. Marshal_PolicyCpHash.c
  249. Marshal_PolicyDuplicationSelect.c
  250. Marshal_PolicyFidoSigned.c
  251. Marshal_PolicyGetDigest.c
  252. Marshal_PolicyLocality.c
  253. Marshal_PolicyNameHash.c
  254. Marshal_PolicyNV.c
  255. Marshal_PolicyNvWritten.c
  256. Marshal_PolicyOR.c
  257. Marshal_PolicyPassword.c
  258. Marshal_PolicyPCR.c
  259. Marshal_PolicyPhysicalPresence.c
  260. Marshal_PolicyRestart.c
  261. Marshal_PolicySecret.c
  262. Marshal_PolicySigned.c
  263. Marshal_PolicyTicket.c
  264. Marshal_PP_Commands.c
  265. Marshal_Quote.c
  266. Marshal_ReadClock.c
  267. Marshal_ReadPublic.c
  268. Marshal_Rewrap.c
  269. Marshal_RSA_Decrypt.c
  270. Marshal_RSA_Encrypt.c
  271. Marshal_SelfTest.c
  272. Marshal_SequenceComplete.c
  273. Marshal_SequenceUpdate.c
  274. Marshal_SetAlgorithmSet.c
  275. Marshal_SetCommandCodeAuditStatus.c
  276. Marshal_SetPrimaryPolicy.c
  277. Marshal_Shutdown.c
  278. Marshal_Sign.c
  279. Marshal_StartAuthSession.c
  280. Marshal_Startup.c
  281. Marshal_StirRandom.c
  282. marshal_test.c
  283. Marshal_TestParms.c
  284. Marshal_Unseal.c
  285. Marshal_VerifySignature.c
  286. Marshal_ZGen_2Phase.c
  287. MathFunctions.c
  288. MathFunctions_fp.h
  289. MemoryLib.c
  290. MemoryLib_fp.h
  291. NV.c
  292. NV_Certify.c
  293. NV_Certify_fp.h
  294. NV_ChangeAuth.c
  295. NV_ChangeAuth_fp.h
  296. NV_DefineSpace.c
  297. NV_DefineSpace_fp.h
  298. NV_Extend.c
  299. NV_Extend_fp.h
  300. NV_fp.h
  301. NV_GlobalWriteLock.c
  302. NV_GlobalWriteLock_fp.h
  303. NV_Increment.c
  304. NV_Increment_fp.h
  305. NV_Read.c
  306. NV_Read_fp.h
  307. NV_ReadLock.c
  308. NV_ReadLock_fp.h
  309. NV_ReadPublic.c
  310. NV_ReadPublic_fp.h
  311. NV_SetBits.c
  312. NV_SetBits_fp.h
  313. NV_spt.c
  314. NV_spt_fp.h
  315. NV_UndefineSpace.c
  316. NV_UndefineSpace_fp.h
  317. NV_UndefineSpaceSpecial.c
  318. NV_UndefineSpaceSpecial_fp.h
  319. NV_Write.c
  320. NV_Write_fp.h
  321. NV_WriteLock.c
  322. NV_WriteLock_fp.h
  323. NVMem.c
  324. Object.c
  325. Object_fp.h
  326. Object_spt.c
  327. Object_spt_fp.h
  328. ObjectChangeAuth.c
  329. ObjectChangeAuth_fp.h
  330. OsslCryptoEngine.h
  331. OWNERS
  332. parsep3
  333. parsep4
  334. PCR.c
  335. PCR_Allocate.c
  336. PCR_Allocate_fp.h
  337. PCR_Event.c
  338. PCR_Event_fp.h
  339. PCR_Extend.c
  340. PCR_Extend_fp.h
  341. PCR_fp.h
  342. PCR_Read.c
  343. PCR_Read_fp.h
  344. PCR_Reset.c
  345. PCR_Reset_fp.h
  346. PCR_SetAuthPolicy.c
  347. PCR_SetAuthPolicy_fp.h
  348. PCR_SetAuthValue.c
  349. PCR_SetAuthValue_fp.h
  350. Platform.h
  351. PlatformData.c
  352. PlatformData.h
  353. Policy_spt.c
  354. Policy_spt_fp.h
  355. PolicyAuthorize.c
  356. PolicyAuthorize_fp.h
  357. PolicyAuthValue.c
  358. PolicyAuthValue_fp.h
  359. PolicyCommandCode.c
  360. PolicyCommandCode_fp.h
  361. PolicyCounterTimer.c
  362. PolicyCounterTimer_fp.h
  363. PolicyCpHash.c
  364. PolicyCpHash_fp.h
  365. PolicyDuplicationSelect.c
  366. PolicyDuplicationSelect_fp.h
  367. PolicyFidoSigned.c
  368. PolicyFidoSigned_fp.h
  369. PolicyGetDigest.c
  370. PolicyGetDigest_fp.h
  371. PolicyLocality.c
  372. PolicyLocality_fp.h
  373. PolicyNameHash.c
  374. PolicyNameHash_fp.h
  375. PolicyNV.c
  376. PolicyNV_fp.h
  377. PolicyNvWritten.c
  378. PolicyNvWritten_fp.h
  379. PolicyOR.c
  380. PolicyOR_fp.h
  381. PolicyPassword.c
  382. PolicyPassword_fp.h
  383. PolicyPCR.c
  384. PolicyPCR_fp.h
  385. PolicyPhysicalPresence.c
  386. PolicyPhysicalPresence_fp.h
  387. PolicyRestart.c
  388. PolicyRestart_fp.h
  389. PolicySecret.c
  390. PolicySecret_fp.h
  391. PolicySigned.c
  392. PolicySigned_fp.h
  393. PolicyTicket.c
  394. PolicyTicket_fp.h
  395. Power.c
  396. Power_fp.h
  397. PowerPlat.c
  398. PP.c
  399. PP_Commands.c
  400. PP_Commands_fp.h
  401. PP_fp.h
  402. PPPlat.c
  403. PRESUBMIT.cfg
  404. PropertyCap.c
  405. PropertyCap_fp.h
  406. Quote.c
  407. Quote_fp.h
  408. ReadClock.c
  409. ReadClock_fp.h
  410. README
  411. ReadPublic.c
  412. ReadPublic_fp.h
  413. Rewrap.c
  414. Rewrap_fp.h
  415. RSA_Decrypt.c
  416. RSA_Decrypt_fp.h
  417. RSA_Encrypt.c
  418. RSA_Encrypt_fp.h
  419. RSAData.c
  420. RSAKeySieve.c
  421. RSAKeySieve.h
  422. RSAKeySieve_fp.h
  423. SelfTest.c
  424. SelfTest_fp.h
  425. SequenceComplete.c
  426. SequenceComplete_fp.h
  427. SequenceUpdate.c
  428. SequenceUpdate_fp.h
  429. Session.c
  430. Session_fp.h
  431. SessionProcess.c
  432. SessionProcess_fp.h
  433. SetAlgorithmSet.c
  434. SetAlgorithmSet_fp.h
  435. SetCommandCodeAuditStatus.c
  436. SetCommandCodeAuditStatus_fp.h
  437. SetPrimaryPolicy.c
  438. SetPrimaryPolicy_fp.h
  439. Shutdown.c
  440. Shutdown_fp.h
  441. Sign.c
  442. Sign_fp.h
  443. StartAuthSession.c
  444. StartAuthSession_fp.h
  445. Startup.c
  446. Startup_fp.h
  447. StirRandom.c
  448. StirRandom_fp.h
  449. stubs_ecc.c
  450. stubs_hash.c
  451. stubs_sym.c
  452. swap.h
  453. TcpServer.c
  454. TestParms.c
  455. TestParms_fp.h
  456. thirdparty_preinstall.sh
  457. Ticket.c
  458. Ticket_fp.h
  459. Time.c
  460. Time_fp.h
  461. Tpm.h
  462. tpm_generated.c
  463. tpm_generated.h
  464. tpm_manufacture.c
  465. tpm_manufacture.h
  466. tpm_simulator.hpp
  467. TPM_Types.h
  468. tpm_types.h
  469. TPMB.h
  470. TpmBuildSwitches.h
  471. TPMCmdp.c
  472. TPMCmds.c
  473. TpmError.h
  474. TpmFail.c
  475. TpmFail_fp.h
  476. TpmTcpProtocol.h
  477. Unique.c
  478. Unique_fp.h
  479. Unseal.c
  480. Unseal_fp.h
  481. VendorString.h
  482. VerifySignature.c
  483. VerifySignature_fp.h
  484. ZGen_2Phase.c
  485. ZGen_2Phase_fp.h