1 // This file was extracted from the TCG Published 2 // Trusted Platform Module Library 3 // Part 4: Supporting Routines 4 // Family "2.0" 5 // Level 00 Revision 01.16 6 // October 30, 2014 7 8 #define MANUFACTURE_C 9 #include "InternalRoutines.h" 10 #include "Global.h" 11 // 12 // 13 // Functions 14 // 15 // TPM_Manufacture() 16 // 17 // This function initializes the TPM values in preparation for the TPM's first use. This function will fail if 18 // previously called. The TPM can be re-manufactured by calling TPM_Teardown() first and then calling this 19 // function again. 20 // 21 // Return Value Meaning 22 // 23 // 0 success 24 // 1 manufacturing process previously performed 25 // 26 LIB_EXPORT int 27 TPM_Manufacture( 28 BOOL firstTime // IN: indicates if this is the first call from 29 // main() 30 ) 31 { 32 TPM_SU orderlyShutdown; 33 UINT64 totalResetCount = 0; 34 // If TPM has been manufactured, return indication. 35 if(!firstTime && g_manufactured) 36 return 1; 37 // initialize crypto units 38 //CryptInitUnits(); 39 // 40 s_selfHealTimer = 0; 41 s_lockoutTimer = 0; 42 s_DAPendingOnNV = FALSE; 43 // initialize NV 44 NvInit(); 45 #ifdef _DRBG_STATE_SAVE 46 // Initialize the drbg. This needs to come before the install 47 // of the hierarchies 48 if(!_cpri__Startup()) // Have to start the crypto units first 49 FAIL(FATAL_ERROR_INTERNAL); 50 _cpri__DrbgGetPutState(PUT_STATE, 0, NULL); 51 #endif 52 // default configuration for PCR 53 PCRSimStart(); 54 // initialize pre-installed hierarchy data 55 // This should happen after NV is initialized because hierarchy data is 56 // stored in NV. 57 HierarchyPreInstall_Init(); 58 // initialize dictionary attack parameters 59 DAPreInstall_Init(); 60 // initialize PP list 61 PhysicalPresencePreInstall_Init(); 62 // initialize command audit list 63 CommandAuditPreInstall_Init(); 64 // first start up is required to be Startup(CLEAR) 65 orderlyShutdown = TPM_SU_CLEAR; 66 NvWriteReserved(NV_ORDERLY, &orderlyShutdown); 67 // initialize the firmware version 68 #ifdef EMBEDDED_MODE 69 _plat__GetFwVersion(&gp.firmwareV1, &gp.firmwareV2); 70 #else 71 gp.firmwareV1 = FIRMWARE_V1; 72 #ifdef FIRMWARE_V2 73 gp.firmwareV2 = FIRMWARE_V2; 74 #else 75 gp.firmwareV2 = 0; 76 #endif 77 NvWriteReserved(NV_FIRMWARE_V1, &gp.firmwareV1); 78 NvWriteReserved(NV_FIRMWARE_V2, &gp.firmwareV2); 79 #endif 80 // initialize the total reset counter to 0 81 NvWriteReserved(NV_TOTAL_RESET_COUNT, &totalResetCount); 82 // initialize the clock stuff 83 go.clock = 0; 84 go.clockSafe = YES; 85 #ifdef _DRBG_STATE_SAVE 86 // initialize the current DRBG state in NV 87 _cpri__DrbgGetPutState(GET_STATE, sizeof(go.drbgState), (BYTE *)&go.drbgState); 88 #endif 89 NvWriteReserved(NV_ORDERLY_DATA, &go); 90 // Commit NV writes. Manufacture process is an artificial process existing 91 // only in simulator environment and it is not defined in the specification 92 // that what should be the expected behavior if the NV write fails at this 93 // point. Therefore, it is assumed the NV write here is always success and 94 // no return code of this function is checked. 95 NvCommit(); 96 g_manufactured = TRUE; 97 return 0; 98 } 99 // 100 // 101 // TPM_TearDown() 102 // 103 // This function prepares the TPM for re-manufacture. It should not be implemented in anything other than a 104 // simulated TPM. 105 // In this implementation, all that is needs is to stop the cryptographic units and set a flag to indicate that the 106 // TPM can be re-manufactured. This should be all that is necessary to start the manufacturing process 107 // again. 108 // 109 // Return Value Meaning 110 // 111 // 0 success 112 // 1 TPM not previously manufactured 113 // 114 LIB_EXPORT int 115 TPM_TearDown( 116 void 117 ) 118 { 119 // stop crypt units 120 CryptStopUnits(); 121 g_manufactured = FALSE; 122 return 0; 123 } 124