1 /****************************************************************************** 2 * Copyright (c) 2021-2023 Texas Instruments Incorporated. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * 1) Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * 10 * 2) Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * 3) Neither the name of the copyright holder nor the names of its contributors 15 * may be used to endorse or promote products derived from this software 16 * without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 ****************************************************************************** 30 * \file hw_ccfg.h 31 * 32 * \brief Customer Configuration (CCFG) header file. 33 ******************************************************************************/ 34 35 #ifndef __HW_CCFG_H__ 36 #define __HW_CCFG_H__ 37 38 #include <stdint.h> 39 #include "hw_device.h" 40 41 /*! CCFG sector data structure definition 42 * This structure should be allocated at the base of CCFG section defined in 43 * the linker file. 44 */ 45 typedef struct { 46 47 // Bootloader/application configuration 48 struct { // [0]: length 16B 49 // Pointer to user bootloader vector table 50 void* pBldrVtor; 51 #define CCFG_BC_PBLDR_USE_FCFG ((void*)0xFFFFFFF0) 52 #define XCFG_BC_PBLDR_FORBID ((void*)0xFFFFFFFC) 53 #define XCFG_BC_PBLDR_UNDEF ((void*)0xFFFFFFFF) 54 #define CCFG_BC_PBLDR_VALID(x) ((x) < CCFG_BC_PBLDR_USE_FCFG) 55 // Parameter passed to bootloader 56 union { 57 uint32_t val32; 58 #define CCFG_BC_BLDRCFG_UNDEF 0xFFFFFFFF 59 // Serial ROM bootloader parameters (also used in FCFG.h) 60 struct serialRomBldrParam_struct { 61 uint32_t bldrEnabled : 1; 62 #define XCFG_BC_BLDR_DIS 0 63 #define XCFG_BC_BLDR_EN 1 64 uint32_t pinTriggerEnabled : 1; 65 #define XCFG_BC_PINTRIG_DIS 0 66 #define XCFG_BC_PINTRIG_EN 1 67 uint32_t pinTriggerLevel : 1; 68 #define XCFG_BC_PINTRIG_LEVEL_LO 0 69 #define XCFG_BC_PINTRIG_LEVEL_HI 1 70 uint32_t res0 : 13; 71 uint32_t pinTriggerDio : 6; 72 uint32_t res1 : 2; 73 uint32_t serialIoCfgIndex : 3; 74 #define XCFG_BC_IOCFGIND_DEFAULT 0 75 uint32_t res2 : 5; 76 } serialRomBldrParamStruct; 77 } bldrParam; 78 // Pointer to application VTOR table 79 void* pAppVtor; 80 #define CCFG_BC_PAPP_NONE ((void*)0xFFFFFFFF) 81 uint32_t crc32; 82 } bootCfg; 83 84 85 // Paperspin options [16]: length 8 B 86 // Defines peripheral/feature availability and accessible memory. Allows 87 // customer to target a paperspin device features on a superset device 88 // AND-combined with FCFG.hwOpts. 89 uint32_t hwOpts[2]; 90 91 92 // Device permissions [24]: length 4 B 93 // This is maximally-restrictive combined with similar field in FCFG 94 struct { 95 #define CCFG_PERMISSION_ALLOW 0xA 96 #define CCFG_PERMISSION_FORBID 0x0 97 // (all other value other than ALLOW are interpreted as FORBID) 98 uint32_t allowReturnToFactory : 4; 99 uint32_t allowFakeStby : 4; 100 uint32_t allowToolsClientMode : 4; 101 uint32_t allowChipErase : 4; 102 uint32_t allowFlashProgram : 4; 103 uint32_t allowFlashVerify : 4; 104 uint32_t allowEnergyTrace : 4; 105 uint32_t allowDebugPort : 4; 106 } permissions; 107 108 109 // Miscellaneous fields [28]: length 4B 110 struct { 111 // SACI timeout is infinite when 0, else (2^saciTimeoutExp)*64 ms 112 // Fcfg timeout applied instead if CCfg.saciTimeoutOverride==0 113 uint32_t saciTimeoutExp : 3; 114 #define XCFG_MISC_SACITOEXP_8SEC 7 115 #define XCFG_MISC_SACITOEXP_1SEC 4 116 #define XCFG_MISC_SACITOEXP_INFINITE 0 117 uint32_t saciTimeoutOverride : 1; 118 uint32_t res0 : 28; 119 } misc; 120 121 122 // Flash protection [32]: length 32 B 123 // This is maximally-restrictive combined with similar field in FCFG 124 struct { 125 struct { 126 // Sticky-0 bits written to VIMS.WEPRA (sectors 0-31, 1/bit) 127 uint32_t mainSectors0_31; 128 // Sticky-0 bits written to VIMS.WEPRB(0) (sectors 32-255, 8/bit) 129 uint32_t mainSectors32_255; 130 // Sticky-0 bit written to VIMS.WEPRAUX 131 union { 132 uint32_t auxSectors; 133 struct { 134 uint32_t ccfgSector : 1; 135 uint32_t fcfgSector : 1; 136 uint32_t engrSector : 1; 137 uint32_t res1 : 29; 138 }; 139 }; 140 } writeEraseProt; 141 uint32_t res; 142 struct { 143 // Set bits (sectors 0-31, 1/bit) define what a chip erase command can optionally retain 144 uint32_t mainSectors0_31; 145 // Set bits (sectors 32-255, 8/bit) define what a chip erase command can optionally retain 146 uint32_t mainSectors32_255; 147 } chipEraseRetain; 148 // Reserved for future flash increases 149 uint32_t res0[2]; 150 } flashProt; 151 152 153 // Optional HW initialization copy-list [64]: length x B 154 // Copy list applied before user application is entered. May be used by customer/SYSCFG to 155 // initialize hardware right before application is entered. 156 // Also used to pad out CCFG to correct size 157 uint32_t hwInitCopyList[(FLASH_1T_SECTOR_SIZE / 4) - 61]; 158 // Simple macros to assist in initializing copy lists 159 // NOTE: Addresses to CPYLIST_CPY must fulfill ((a&0x0FF00003)==0). 160 // The memory map ensures this for SRAM and peripherals. 161 // There is no check as ELF only supports {symbol + const offset} 162 #define CPYLST_EOL 0 163 #define CPYLST_NOP 0x10000000 164 #define CPYLST_WAIT(x) ( 0x10000000 + (((x)<<2)&0x000FFFFC) ) 165 #define CPYLST_CPY(a, n) ( ((uint32_t)(a)) + (((n)<<20)&0x0FF00000) ) 166 #define CPYLST_CPYFULLADDR(a) (((uint32_t)(a)) + 1) 167 #define CPYLST_JUMP(a) (((uint32_t)(a)) + 2) 168 #define CPYLST_CALL(a) (((uint32_t)(a)) + 3) 169 170 171 // CRC across hwOpts through hwInitCopyList 172 // [End-180]: length 4B 173 uint32_t crc32; 174 175 176 // User record (programmable also through separate SACI command), no dependencies in boot code 177 // User record size is fixed at 128 B. Last word assumed to be CRC over first 124 B (optional) 178 #define CCFG_USER_RECORD_SIZE 128 179 union { // [End-176]: length 128B 180 struct { 181 union { 182 // Generic 32b record layout 183 uint32_t val32[(CCFG_USER_RECORD_SIZE/4)-1]; 184 // Generic 8b record layout 185 uint8_t val8[CCFG_USER_RECORD_SIZE-4]; 186 }; 187 // CRC field across first 124B of userRecord (supported by SACI verifyCcfg command) 188 uint32_t crc32; 189 }; 190 } userRecord; 191 192 // Debug configuration and password 193 struct { // [End-48]: length 48B 194 // Debug authorization requirements 195 uint8_t authorization; 196 #define CCFG_DBGAUTH_REQPWD 0xA5 197 #define CCFG_DBGAUTH_DBGOPEN 0x5A 198 #define CCFG_DBGAUTH_DBGFORBID 0x00 199 // (and any other value) 200 // Allow debugging of bootloader 201 uint8_t allowBldr; 202 #define CCFG_DBGBLDR_ALLOW 0xA5 203 #define CCFG_DBGBLDR_FORBID 0x00 204 // (and any other value) 205 uint8_t res0[2]; 206 // 64b password ID value (may be used to calculate or look up debug password) 207 uint8_t pwdId[8]; 208 // SHA256 hash of debug password 209 uint8_t pwdHash[32]; 210 // CRC32 of previous fields in debugCfg 211 uint32_t crc32; 212 } debugCfg; 213 214 } ccfg_t; 215 216 217 /*! Typedef of substruct as it is also used in hw_fcfg.h and in the ROM bootloader itself */ 218 typedef struct serialRomBldrParam_struct serialRomBldrParam_t; 219 220 221 /*! \brief Extern declaration of the CCFG struct. 222 * This extern declaration can be used to access CCFG fields from other parts 223 * of the code base. 224 * This extern assumes that the ccfg_t struct allocated in the system is called 225 * "ccfg". 226 */ 227 extern const ccfg_t ccfg; 228 229 #endif // __HW_CCFG_H__ 230