| 1 | /* |
| 2 | * Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | * |
| 16 | * See file CREDITS for list of people who contributed to this |
| 17 | * project. |
| 18 | */ |
| 19 | |
| 20 | #ifndef INCLUDED_NVBOOT_BCT_T210_H |
| 21 | #define INCLUDED_NVBOOT_BCT_T210_H |
| 22 | |
| 23 | #include <sys/types.h> |
| 24 | #include "nvboot_sdram_param_t210.h" |
| 25 | |
| 26 | /** |
| 27 | * Defines the number of 32-bit words in the customer_data area of the BCT. |
| 28 | */ |
| 29 | #define NVBOOT_BCT_CUSTOMER_DATA_WORDS 49 |
| 30 | |
| 31 | /** |
| 32 | * Defines the number of bytes in the customer_data area of the BCT. |
| 33 | */ |
| 34 | #define NVBOOT_BCT_CUSTOMER_DATA_SIZE \ |
| 35 | (NVBOOT_BCT_CUSTOMER_DATA_WORDS * 4) |
| 36 | |
| 37 | /** |
| 38 | * Defines the number of bytes in the reserved area of the BCT. |
| 39 | */ |
| 40 | #define NVBOOT_BCT_RESERVED_SIZE 18 |
| 41 | |
| 42 | /** |
| 43 | * Defines the maximum number of bootloader descriptions in the BCT. |
| 44 | */ |
| 45 | #define NVBOOT_MAX_BOOTLOADERS 4 |
| 46 | |
| 47 | /** |
| 48 | * Defines the maximum number of device parameter sets in the BCT. |
| 49 | * The value must be equal to (1 << # of device straps) |
| 50 | */ |
| 51 | #define NVBOOT_BCT_MAX_PARAM_SETS 1 |
| 52 | |
| 53 | /** |
| 54 | * Defines the maximum number of SDRAM parameter sets in the BCT. |
| 55 | * The value must be equal to (1 << # of SDRAM straps) |
| 56 | */ |
| 57 | #define NVBOOT_BCT_MAX_SDRAM_SETS 4 |
| 58 | |
| 59 | /** |
| 60 | * Defines the number of entries (bits) in the bad block table. |
| 61 | * The consequences of changing its value are as follows. Using P as the |
| 62 | * # of physical blocks in the boot loader and B as the value of this |
| 63 | * constant: |
| 64 | * B > P: There will be unused storage in the bad block table. |
| 65 | * B < P: The virtual block size will be greater than the physical block |
| 66 | * size, so the granularity of the bad block table will be less than |
| 67 | * one bit per physical block. |
| 68 | * |
| 69 | * 4096 bits is enough to represent an 8MiB partition of 2KiB blocks with one |
| 70 | * bit per block (1 virtual block = 1 physical block). This occupies 512 bytes |
| 71 | * of storage. |
| 72 | */ |
| 73 | #define NVBOOT_BAD_BLOCK_TABLE_SIZE 4096 |
| 74 | |
| 75 | /** |
| 76 | * Defines the amount of padding needed to pad the bad block table to a |
| 77 | * multiple of AES block size. |
| 78 | */ |
| 79 | #define NVBOOT_BAD_BLOCK_TABLE_PADDING 10 |
| 80 | |
| 81 | /** |
| 82 | * Defines the maximum number of blocks to search for BCTs. |
| 83 | * |
| 84 | * This value covers the initial block and a set of journal blocks. |
| 85 | * |
| 86 | * Ideally, this number will span several erase units for reliable updates |
| 87 | * and tolerance for blocks to become bad with use. Safe updates require |
| 88 | * a minimum of 2 erase units in which BCTs can appear. |
| 89 | * |
| 90 | * To ensure that the BCT search spans a sufficient range of configurations, |
| 91 | * the search block count has been set to 64. This allows for redundancy with |
| 92 | * a wide range of parts and provides room for greater problems in this |
| 93 | * region of the device. |
| 94 | */ |
| 95 | #define NVBOOT_MAX_BCT_SEARCH_BLOCKS 64 |
| 96 | |
| 97 | #define ARSE_RSA_MAX_MODULUS_SIZE 2048 |
| 98 | |
| 99 | /** |
| 100 | * Defines the RSA modulus length in bits and bytes used for PKC secure boot. |
| 101 | */ |
| 102 | enum {NVBOOT_SE_RSA_MODULUS_LENGTH_BITS = ARSE_RSA_MAX_MODULUS_SIZE}; |
| 103 | |
| 104 | /* |
| 105 | * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words) |
| 106 | */ |
| 107 | enum {NVBOOT_CMAC_AES_HASH_LENGTH = 4}; |
| 108 | |
| 109 | /** |
| 110 | * Defines the storage for a hash value (128 bits). |
| 111 | */ |
| 112 | typedef struct nvboot_hash_rec { |
| 113 | uint32_t hash[NVBOOT_CMAC_AES_HASH_LENGTH]; |
| 114 | } nvboot_hash; |
| 115 | |
| 116 | /* |
| 117 | * Defines the storage for the RSA public key's modulus |
| 118 | * in the BCT |
| 119 | */ |
| 120 | typedef struct nvboot_rsa_key_modulus_rec { |
| 121 | /* The modulus size is 2048-bits. */ |
| 122 | uint32_t modulus[NVBOOT_SE_RSA_MODULUS_LENGTH_BITS / 8 / 4]; |
| 123 | } nvboot_rsa_key_modulus; |
| 124 | |
| 125 | typedef struct nvboot_rsa_pss_sig_rec { |
| 126 | /* |
| 127 | * The RSA-PSS signature length is equal to the |
| 128 | * length in octets of the RSA modulus. |
| 129 | * In our case, it's 2048-bits. |
| 130 | */ |
| 131 | uint32_t signature[NVBOOT_SE_RSA_MODULUS_LENGTH_BITS / 8 / 4]; |
| 132 | } nvboot_rsa_pss_sig; |
| 133 | |
| 134 | typedef struct nvboot_object_signature_rec { |
| 135 | /* |
| 136 | * Specifies the AES-CMAC signature for the rest of the BCT structure |
| 137 | * if symmetric key encryption secure boot scheme is used. |
| 138 | */ |
| 139 | nvboot_hash crypto_hash; |
| 140 | |
| 141 | /* |
| 142 | * Specifies the RSASSA-PSS signature for the rest of the BCT structure |
| 143 | * if public key cryptography secure boot scheme is used. |
| 144 | */ |
| 145 | nvboot_rsa_pss_sig rsa_pss_sig; |
| 146 | } nvboot_object_signature; |
| 147 | |
| 148 | typedef struct nvboot_ecid_rec { |
| 149 | uint32_t ecid_0; |
| 150 | uint32_t ecid_1; |
| 151 | uint32_t ecid_2; |
| 152 | uint32_t ecid_3; |
| 153 | } nvboot_ecid; |
| 154 | |
| 155 | /* Defines various data widths supported. */ |
| 156 | typedef enum { |
| 157 | /** |
| 158 | * Specifies a 1 bit interface to eMMC. |
| 159 | * Note that 1-bit data width is only for the driver's internal use. |
| 160 | * Fuses doesn't provide option to select 1-bit data width. |
| 161 | * The driver selects 1-bit internally based on need. |
| 162 | * It is used for reading Extended CSD and when the power class |
| 163 | * requirements of a card for 4-bit or 8-bit transfers are not |
| 164 | * supported by the target board. |
| 165 | */ |
| 166 | nvboot_sdmmc_data_width_1bit = 0, |
| 167 | |
| 168 | /* Specifies a 4 bit interface to eMMC. */ |
| 169 | nvboot_sdmmc_data_width_4bit = 1, |
| 170 | |
| 171 | /* Specifies a 8 bit interface to eMMC. */ |
| 172 | nvboot_sdmmc_data_width_8bit = 2, |
| 173 | /* Specifies a 4 bit Ddr interface to eMMC. */ |
| 174 | nvboot_sdmmc_data_width_ddr_4bit = 5, |
| 175 | /* Specifies a 8 bit Ddr interface to eMMC. */ |
| 176 | nvboot_sdmmc_data_width_ddr_8bit = 6, |
| 177 | |
| 178 | nvboot_sdmmc_data_width_num, |
| 179 | nvboot_sdmmc_data_width_force32 = 0x7FFFFFFF |
| 180 | } nvboot_sdmmc_data_width; |
| 181 | |
| 182 | /* Defines the parameters that can be changed after BCT is read. */ |
| 183 | typedef struct nvboot_sdmmc_params_rec { |
| 184 | /** |
| 185 | * Specifies the clock divider for the SDMMC controller's clock source, |
| 186 | * which is PLLP running at 216MHz. If it is set to 9, then the SDMMC |
| 187 | * controller runs at 216/9 = 24MHz. |
| 188 | */ |
| 189 | uint8_t clock_divider; |
| 190 | |
| 191 | /* Specifies the data bus width. Supported data widths are 4/8 bits. */ |
| 192 | nvboot_sdmmc_data_width data_width; |
| 193 | |
| 194 | /** |
| 195 | * Max Power class supported by the target board. |
| 196 | * The driver determines the best data width and clock frequency |
| 197 | * supported within the power class range (0 to Max) if the selected |
| 198 | * data width cannot be used at the chosen clock frequency. |
| 199 | */ |
| 200 | uint8_t max_power_class_supported; |
| 201 | |
| 202 | /* Specifies the max page size supported by driver */ |
| 203 | uint8_t multi_page_support; |
| 204 | } nvboot_sdmmc_params; |
| 205 | |
| 206 | typedef enum { |
| 207 | /* Specifies SPI clock source to be PLLP. */ |
| 208 | nvboot_spi_clock_source_pllp_out0 = 0, |
| 209 | |
| 210 | /* Specifies SPI clock source to be ClockM. */ |
| 211 | nvboot_spi_clock_source_clockm = 6, |
| 212 | |
| 213 | nvboot_spi_clock_source_num, |
| 214 | nvboot_spi_clock_source_force32 = 0x7FFFFFF |
| 215 | } nvboot_spi_clock_source; |
| 216 | |
| 217 | /** |
| 218 | * Defines the parameters SPI FLASH devices. |
| 219 | */ |
| 220 | typedef struct nvboot_spiflash_params_rec { |
| 221 | /** |
| 222 | * Specifies the clock source to use. |
| 223 | */ |
| 224 | uint32_t clock_source; |
| 225 | |
| 226 | /** |
| 227 | * Specifes the clock divider to use. |
| 228 | * The value is a 7-bit value based on an input clock of 432Mhz. |
| 229 | * Divider = (432+ DesiredFrequency-1)/DesiredFrequency; |
| 230 | * Typical values: |
| 231 | * NORMAL_READ at 20MHz: 22 |
| 232 | * FAST_READ at 33MHz: 14 |
| 233 | * FAST_READ at 40MHz: 11 |
| 234 | * FAST_READ at 50MHz: 9 |
| 235 | */ |
| 236 | uint8_t clock_divider; |
| 237 | |
| 238 | /** |
| 239 | * Specifies the type of command for read operations. |
| 240 | * NV_FALSE specifies a NORMAL_READ Command |
| 241 | * NV_TRUE specifies a FAST_READ Command |
| 242 | */ |
| 243 | uint8_t read_command_type_fast; |
| 244 | |
| 245 | /* 0 = 2k page size, 1 = 16K page size */ |
| 246 | uint8_t page_size_2k_or_16k; |
| 247 | } nvboot_spiflash_params; |
| 248 | |
| 249 | /** |
| 250 | * Defines the union of the parameters required by each device. |
| 251 | */ |
| 252 | typedef union { |
| 253 | uint8_t size[64]; |
| 254 | /* Specifies optimized parameters for eMMC and eSD */ |
| 255 | nvboot_sdmmc_params sdmmc_params; |
| 256 | /* Specifies optimized parameters for SPI NOR */ |
| 257 | nvboot_spiflash_params spiflash_params; |
| 258 | } nvboot_dev_params; |
| 259 | |
| 260 | /** |
| 261 | * Identifies the types of devices from which the system booted. |
| 262 | * Used to identify primary and secondary boot devices. |
| 263 | * @note These no longer match the fuse API device values (for |
| 264 | * backward compatibility with AP15). |
| 265 | */ |
| 266 | typedef enum { |
| 267 | /* Specifies a default (unset) value. */ |
| 268 | nvboot_dev_type_none = 0, |
| 269 | |
| 270 | /* Specifies SPI NOR. */ |
| 271 | nvboot_dev_type_spi = 3, |
| 272 | |
| 273 | /* Specifies SDMMC (either eMMC or eSD). */ |
| 274 | nvboot_dev_type_sdmmc = 4, |
| 275 | |
| 276 | nvboot_dev_type_max, |
| 277 | |
| 278 | /* Ignore -- Forces compilers to make 32-bit enums. */ |
| 279 | nvboot_dev_type_force32 = 0x7FFFFFFF |
| 280 | } nvboot_dev_type; |
| 281 | |
| 282 | /** |
| 283 | * Stores information needed to locate and verify a boot loader. |
| 284 | * |
| 285 | * There is one \c nv_bootloader_info structure for each copy of a BL stored on |
| 286 | * the device. |
| 287 | */ |
| 288 | typedef struct nv_bootloader_info_rec { |
| 289 | uint32_t version; |
| 290 | uint32_t start_blk; |
| 291 | uint32_t start_page; |
| 292 | uint32_t length; |
| 293 | uint32_t load_addr; |
| 294 | uint32_t entry_point; |
| 295 | uint32_t attribute; |
| 296 | |
| 297 | /* Specifies the AES-CMAC MAC or RSASSA-PSS signature of the BL. */ |
| 298 | nvboot_object_signature signature; |
| 299 | } nv_bootloader_info; |
| 300 | |
| 301 | /** |
| 302 | * Defines the bad block table structure stored in the BCT. |
| 303 | */ |
| 304 | typedef struct nvboot_badblock_table_rec { |
| 305 | uint32_t entries_used; |
| 306 | uint8_t virtual_blk_size_log2; |
| 307 | uint8_t block_size_log2; |
| 308 | uint8_t bad_blks[NVBOOT_BAD_BLOCK_TABLE_SIZE / 8]; |
| 309 | /* |
| 310 | * Add a reserved field as padding to make the bad block table structure |
| 311 | * a multiple of 16 bytes (AES block size). |
| 312 | */ |
| 313 | uint8_t reserved[NVBOOT_BAD_BLOCK_TABLE_PADDING]; |
| 314 | } nvboot_badblock_table; |
| 315 | |
| 316 | enum {NVBOOT_SE_AES_KEY256_LENGTH_BYTES = 32}; |
| 317 | /** |
| 318 | * Contains the information needed to load BLs from the secondary boot device. |
| 319 | * |
| 320 | * - Supplying NumParamSets = 0 indicates not to load any of them. |
| 321 | * - Supplying NumDramSets = 0 indicates not to load any of them. |
| 322 | * - The \c random_aes_blk member exists to increase the difficulty of |
| 323 | * key attacks based on knowledge of this structure. |
| 324 | */ |
| 325 | typedef struct nvboot_config_table_rec { |
| 326 | nvboot_badblock_table badblock_table; |
| 327 | nvboot_rsa_key_modulus key; |
| 328 | nvboot_object_signature signature; /* 310 */ |
| 329 | |
| 330 | /** |
| 331 | * Specifies the Factory Secure Provisioning number to be used. |
| 332 | * Only valid and consumed by BR in NvProduction Mode. |
| 333 | * Because the key number is specified in the BCT, BR needs to read in |
| 334 | * the BCT first to know the key number to validate against. |
| 335 | * This field must match SecProvisioningKeyNum_Secure to be a valid |
| 336 | * BCT for use in the Factory Secure Provisioning mode. |
| 337 | */ |
| 338 | uint32_t secure_provisioning_key_number_insecure; /* 420 */ |
| 339 | |
| 340 | /** |
| 341 | * A 256-bit AES key encrypted by a reserved 256-bit AES "key wrap" |
| 342 | * key. Only used in Factory Secure Provisioning mode. |
| 343 | */ |
| 344 | uint8_t aes_key[NVBOOT_SE_AES_KEY256_LENGTH_BYTES]; /* 424 */ |
| 345 | |
| 346 | uint8_t customer_data[NVBOOT_BCT_CUSTOMER_DATA_SIZE]; /* 444 */ |
| 347 | uint32_t odm_data; /* 508 */ |
| 348 | uint32_t reserved1; |
| 349 | |
| 350 | /* START OF SIGNED SECTION OF THE BCT */ |
| 351 | nvboot_hash random_aes_blk; /* 0x510 */ |
| 352 | nvboot_ecid unique_chip_id; /* 0x520 */ |
| 353 | uint32_t boot_data_version; /* 0x530 */ |
| 354 | uint32_t block_size_log2; |
| 355 | uint32_t page_size_log2; |
| 356 | uint32_t partition_size; |
| 357 | uint32_t num_param_sets; |
| 358 | nvboot_dev_type dev_type[NVBOOT_BCT_MAX_PARAM_SETS]; |
| 359 | nvboot_dev_params dev_params[NVBOOT_BCT_MAX_PARAM_SETS]; |
| 360 | uint32_t num_sdram_sets; /* 0x588 */ |
| 361 | nvboot_sdram_params sdram_params[NVBOOT_BCT_MAX_SDRAM_SETS]; /* 0x58c */ |
| 362 | |
| 363 | uint32_t bootloader_used; /* 0x232c */ |
| 364 | nv_bootloader_info bootloader[NVBOOT_MAX_BOOTLOADERS]; /* 0x2330 */ |
| 365 | |
| 366 | uint8_t enable_fail_back; |
| 367 | |
| 368 | /** |
| 369 | * Specifies which debug features to be enabled or disabled. |
| 370 | * Maps directly to APBDEV_PMC_DEBUG_AUTHENTICATION_0. Must specify |
| 371 | * the ECID of the chip in UniqueChipId on production systems. |
| 372 | * 0x1 = ENABLED. 0x0 = DISABLED. |
| 373 | * DBGEN - bit 5 |
| 374 | * NIDEN - bit 4 |
| 375 | * SPIDEN - bit 3 |
| 376 | * SPNIDEN - bit 2 |
| 377 | * DEVICEEN - bit 1 |
| 378 | * JTAG_ENABLE - bit 0 |
| 379 | */ |
| 380 | uint32_t secure_debug_control; |
| 381 | |
| 382 | /** |
| 383 | * Specifies the factory secure provisioning key number to use. |
| 384 | * There are 64 such 256-bit AES keys. |
| 385 | * |
| 386 | * Specifying a key number of 0 will cause Boot ROM to default to |
| 387 | * NvProduction mode boot (i.e. Factory Secure Provisioning mode |
| 388 | * disabled). |
| 389 | * |
| 390 | * Specifying a key number of 1 to 15 is invalid. These are |
| 391 | * anti-cloning keys numbers and BR will ignore these values. |
| 392 | * BR will ignore this field if the secure_provision_index fuse is |
| 393 | * burned. |
| 394 | * |
| 395 | * Key number 64 (index [63]) is reserved for NVIDIA debug use. |
| 396 | * So, this field will only be used if the chip is in NvProductionMode, |
| 397 | * and when secure_provision_index is zero, and when |
| 398 | * SecProvisioningKeyNum is not 0 to 15. |
| 399 | * |
| 400 | * This key number must match SecProvisioningKeyNum_Insecure. |
| 401 | */ |
| 402 | uint32_t secure_provisioning_key_number_secure; |
| 403 | |
| 404 | uint8_t reserved[NVBOOT_BCT_RESERVED_SIZE]; |
| 405 | } nvboot_config_table; |
| 406 | #endif /* #ifndef INCLUDED_NVBOOT_BCT_T210_H */ |