| 1 | /* |
| 2 | * Copyright (c) 2014, 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_T132_H |
| 21 | #define INCLUDED_NVBOOT_BCT_T132_H |
| 22 | |
| 23 | #include <sys/types.h> |
| 24 | #include "nvboot_sdram_param_t132.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 162 |
| 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 338 |
| 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 4 |
| 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 | /** |
| 98 | * Defines the maximum number of MTS boot components descriptions in the BCT. |
| 99 | */ |
| 100 | #define NVBOOT_MAX_MTS_COMPONENTS 6 |
| 101 | |
| 102 | #define ARSE_RSA_MAX_MODULUS_SIZE 2048 |
| 103 | |
| 104 | /** |
| 105 | * Defines the RSA modulus length in bits and bytes used for PKC secure boot. |
| 106 | */ |
| 107 | enum {NVBOOT_SE_RSA_MODULUS_LENGTH_BITS = ARSE_RSA_MAX_MODULUS_SIZE}; |
| 108 | |
| 109 | /* |
| 110 | * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words) |
| 111 | */ |
| 112 | enum {NVBOOT_CMAC_AES_HASH_LENGTH = 4}; |
| 113 | |
| 114 | /** |
| 115 | * Defines the storage for a hash value (128 bits). |
| 116 | */ |
| 117 | typedef struct nvboot_hash_rec { |
| 118 | uint32_t hash[NVBOOT_CMAC_AES_HASH_LENGTH]; |
| 119 | } nvboot_hash; |
| 120 | |
| 121 | /* |
| 122 | * Defines the storage for the RSA public key's modulus |
| 123 | * in the BCT |
| 124 | */ |
| 125 | typedef struct nvboot_rsa_key_modulus_rec { |
| 126 | /* The modulus size is 2048-bits. */ |
| 127 | uint32_t modulus[NVBOOT_SE_RSA_MODULUS_LENGTH_BITS / 8 / 4]; |
| 128 | } nvboot_rsa_key_modulus; |
| 129 | |
| 130 | typedef struct nvboot_rsa_pss_sig_rec { |
| 131 | /* |
| 132 | * The RSA-PSS signature length is equal to the |
| 133 | * length in octets of the RSA modulus. |
| 134 | * In our case, it's 2048-bits. |
| 135 | */ |
| 136 | uint32_t signature[NVBOOT_SE_RSA_MODULUS_LENGTH_BITS / 8 / 4]; |
| 137 | } nvboot_rsa_pss_sig; |
| 138 | |
| 139 | typedef struct nvboot_object_signature_rec { |
| 140 | /* |
| 141 | * Specifies the AES-CMAC signature for the rest of the BCT structure if symmetric key |
| 142 | * encryption secure boot scheme is used. |
| 143 | */ |
| 144 | nvboot_hash crypto_hash; |
| 145 | |
| 146 | /* |
| 147 | * Specifies the RSASSA-PSS signature for the rest of the BCT structure if public |
| 148 | * key cryptography secure boot scheme is used. |
| 149 | */ |
| 150 | nvboot_rsa_pss_sig rsa_pss_sig; |
| 151 | } nvboot_object_signature; |
| 152 | |
| 153 | typedef struct nvboot_ecid_rec { |
| 154 | uint32_t ecid_0; |
| 155 | uint32_t ecid_1; |
| 156 | uint32_t ecid_2; |
| 157 | uint32_t ecid_3; |
| 158 | } nvboot_ecid; |
| 159 | |
| 160 | /* Defines various data widths supported. */ |
| 161 | typedef enum { |
| 162 | /** |
| 163 | * Specifies a 1 bit interface to eMMC. |
| 164 | * Note that 1-bit data width is only for the driver's internal use. |
| 165 | * Fuses doesn't provide option to select 1-bit data width. |
| 166 | * The driver selects 1-bit internally based on need. |
| 167 | * It is used for reading Extended CSD and when the power class |
| 168 | * requirements of a card for 4-bit or 8-bit transfers are not |
| 169 | * supported by the target board. |
| 170 | */ |
| 171 | nvboot_sdmmc_data_width_1bit = 0, |
| 172 | |
| 173 | /* Specifies a 4 bit interface to eMMC. */ |
| 174 | nvboot_sdmmc_data_width_4bit = 1, |
| 175 | |
| 176 | /* Specifies a 8 bit interface to eMMC. */ |
| 177 | nvboot_sdmmc_data_width_8bit = 2, |
| 178 | /* Specifies a 4 bit Ddr interface to eMMC. */ |
| 179 | nvboot_sdmmc_data_width_ddr_4bit = 5, |
| 180 | /* Specifies a 8 bit Ddr interface to eMMC. */ |
| 181 | nvboot_sdmmc_data_width_ddr_8bit = 6, |
| 182 | |
| 183 | nvboot_sdmmc_data_width_num, |
| 184 | nvboot_sdmmc_data_width_force32 = 0x7FFFFFFF |
| 185 | } nvboot_sdmmc_data_width; |
| 186 | |
| 187 | /* Defines the parameters that can be changed after BCT is read. */ |
| 188 | typedef struct nvboot_sdmmc_params_rec { |
| 189 | /** |
| 190 | * Specifies the clock divider for the SDMMC controller's clock source, |
| 191 | * which is PLLP running at 216MHz. If it is set to 9, then the SDMMC |
| 192 | * controller runs at 216/9 = 24MHz. |
| 193 | */ |
| 194 | uint8_t clock_divider; |
| 195 | |
| 196 | /* Specifies the data bus width. Supported data widths are 4/8 bits. */ |
| 197 | nvboot_sdmmc_data_width data_width; |
| 198 | |
| 199 | /** |
| 200 | * Max Power class supported by the target board. |
| 201 | * The driver determines the best data width and clock frequency |
| 202 | * supported within the power class range (0 to Max) if the selected |
| 203 | * data width cannot be used at the chosen clock frequency. |
| 204 | */ |
| 205 | uint8_t max_power_class_supported; |
| 206 | |
| 207 | /* Specifies the max page size supported by driver */ |
| 208 | uint8_t multi_page_support; |
| 209 | } nvboot_sdmmc_params; |
| 210 | |
| 211 | typedef enum { |
| 212 | /* Specifies SPI clock source to be PLLP. */ |
| 213 | nvboot_spi_clock_source_pllp_out0 = 0, |
| 214 | |
| 215 | /* Specifies SPI clock source to be ClockM. */ |
| 216 | nvboot_spi_clock_source_clockm = 6, |
| 217 | |
| 218 | nvboot_spi_clock_source_num, |
| 219 | nvboot_spi_clock_source_force32 = 0x7FFFFFF |
| 220 | } nvboot_spi_clock_source; |
| 221 | |
| 222 | /** |
| 223 | * Defines the parameters SPI FLASH devices. |
| 224 | */ |
| 225 | typedef struct nvboot_spiflash_params_rec { |
| 226 | /** |
| 227 | * Specifies the clock source to use. |
| 228 | */ |
| 229 | uint32_t clock_source; |
| 230 | |
| 231 | /** |
| 232 | * Specifes the clock divider to use. |
| 233 | * The value is a 7-bit value based on an input clock of 432Mhz. |
| 234 | * Divider = (432+ DesiredFrequency-1)/DesiredFrequency; |
| 235 | * Typical values: |
| 236 | * NORMAL_READ at 20MHz: 22 |
| 237 | * FAST_READ at 33MHz: 14 |
| 238 | * FAST_READ at 40MHz: 11 |
| 239 | * FAST_READ at 50MHz: 9 |
| 240 | */ |
| 241 | uint8_t clock_divider; |
| 242 | |
| 243 | /** |
| 244 | * Specifies the type of command for read operations. |
| 245 | * NV_FALSE specifies a NORMAL_READ Command |
| 246 | * NV_TRUE specifies a FAST_READ Command |
| 247 | */ |
| 248 | uint8_t read_command_type_fast; |
| 249 | |
| 250 | /* 0 = 2k page size, 1 = 16K page size */ |
| 251 | uint8_t page_size_2k_or_16k; |
| 252 | } nvboot_spiflash_params; |
| 253 | |
| 254 | /** |
| 255 | * Defines the union of the parameters required by each device. |
| 256 | */ |
| 257 | typedef union { |
| 258 | uint8_t size[64]; |
| 259 | /* Specifies optimized parameters for eMMC and eSD */ |
| 260 | nvboot_sdmmc_params sdmmc_params; |
| 261 | /* Specifies optimized parameters for SPI NOR */ |
| 262 | nvboot_spiflash_params spiflash_params; |
| 263 | } nvboot_dev_params; |
| 264 | |
| 265 | /** |
| 266 | * Identifies the types of devices from which the system booted. |
| 267 | * Used to identify primary and secondary boot devices. |
| 268 | * @note These no longer match the fuse API device values (for |
| 269 | * backward compatibility with AP15). |
| 270 | */ |
| 271 | typedef enum { |
| 272 | /* Specifies a default (unset) value. */ |
| 273 | nvboot_dev_type_none = 0, |
| 274 | |
| 275 | /* Specifies SPI NOR. */ |
| 276 | nvboot_dev_type_spi = 3, |
| 277 | |
| 278 | /* Specifies SDMMC (either eMMC or eSD). */ |
| 279 | nvboot_dev_type_sdmmc = 4, |
| 280 | |
| 281 | nvboot_dev_type_max, |
| 282 | |
| 283 | /* Ignore -- Forces compilers to make 32-bit enums. */ |
| 284 | nvboot_dev_type_force32 = 0x7FFFFFFF |
| 285 | } nvboot_dev_type; |
| 286 | |
| 287 | /** |
| 288 | * Stores information needed to locate MTS image on the boot media. |
| 289 | * |
| 290 | * There is one MTS boot structure for each of the Preboot, Bootcode and |
| 291 | * the package image. |
| 292 | */ |
| 293 | typedef struct nvboot_mts_info_rec |
| 294 | { |
| 295 | /* |
| 296 | * Specifies a version number for the MTS image. The assignment of |
| 297 | * numbers is arbitrary; the numbers are only used to identify redundant. |
| 298 | */ |
| 299 | uint32_t version; |
| 300 | |
| 301 | /* |
| 302 | * Specifies the first physical block on the secondary boot device |
| 303 | * that contains the start of the MTS image. The first block can never be |
| 304 | * a known bad block. |
| 305 | */ |
| 306 | uint32_t start_blk; |
| 307 | |
| 308 | /* |
| 309 | * Specifies the page within the first block that contains the start |
| 310 | * of the MTS image. |
| 311 | */ |
| 312 | uint32_t start_page; |
| 313 | |
| 314 | /* |
| 315 | * Specifies the length of the MTS image in bytes. MTS image must be |
| 316 | * padded to an integral number of 16 bytes with the padding pattern. |
| 317 | * @note The end of the MTS image cannot fall within the last 16 bytes of |
| 318 | * a page. Add another 16 bytes to work around this restriction if |
| 319 | * needed. |
| 320 | */ |
| 321 | uint32_t length; |
| 322 | |
| 323 | /* |
| 324 | * Specifies the starting address of the memory region into which the |
| 325 | * MTS will be loaded. This is optional. |
| 326 | */ |
| 327 | uint32_t load_addr; |
| 328 | |
| 329 | /* Specifies the entry point address in the loaded MTS image. Optional */ |
| 330 | uint32_t entry_point; |
| 331 | |
| 332 | /* |
| 333 | * Specifies an attribute available for use by other code. |
| 334 | * Not interpreted by the Boot ROM. |
| 335 | */ |
| 336 | uint32_t attribute; |
| 337 | |
| 338 | } nvboot_mts_info; |
| 339 | |
| 340 | /** |
| 341 | * Stores information needed to locate and verify a boot loader. |
| 342 | * |
| 343 | * There is one \c nv_bootloader_info structure for each copy of a BL stored on |
| 344 | * the device. |
| 345 | */ |
| 346 | typedef struct nv_bootloader_info_rec { |
| 347 | uint32_t version; |
| 348 | uint32_t start_blk; |
| 349 | uint32_t start_page; |
| 350 | uint32_t length; |
| 351 | uint32_t load_addr; |
| 352 | uint32_t entry_point; |
| 353 | uint32_t attribute; |
| 354 | |
| 355 | /* Specifies the AES-CMAC MAC or RSASSA-PSS signature of the BL. */ |
| 356 | nvboot_object_signature signature; |
| 357 | } nv_bootloader_info; |
| 358 | |
| 359 | /** |
| 360 | * Defines the bad block table structure stored in the BCT. |
| 361 | */ |
| 362 | typedef struct nvboot_badblock_table_rec { |
| 363 | uint32_t entries_used; |
| 364 | uint8_t virtual_blk_size_log2; |
| 365 | uint8_t block_size_log2; |
| 366 | uint8_t bad_blks[NVBOOT_BAD_BLOCK_TABLE_SIZE / 8]; |
| 367 | /* |
| 368 | * Add a reserved field as padding to make the bad block table structure |
| 369 | * a multiple of 16 bytes (AES block size). |
| 370 | */ |
| 371 | uint8_t reserved[NVBOOT_BAD_BLOCK_TABLE_PADDING]; |
| 372 | } nvboot_badblock_table; |
| 373 | |
| 374 | /** |
| 375 | * Contains the information needed to load BLs from the secondary boot device. |
| 376 | * |
| 377 | * - Supplying NumParamSets = 0 indicates not to load any of them. |
| 378 | * - Supplying NumDramSets = 0 indicates not to load any of them. |
| 379 | * - The \c random_aes_blk member exists to increase the difficulty of |
| 380 | * key attacks based on knowledge of this structure. |
| 381 | */ |
| 382 | typedef struct nvboot_config_table_rec { |
| 383 | nvboot_badblock_table badblock_table; |
| 384 | nvboot_rsa_key_modulus key; |
| 385 | nvboot_object_signature signature; |
| 386 | uint8_t customer_data[NVBOOT_BCT_CUSTOMER_DATA_SIZE]; |
| 387 | uint32_t odm_data; |
| 388 | uint32_t reserved1; |
| 389 | |
| 390 | /* START OF SIGNED SECTION OF THE BCT */ |
| 391 | nvboot_hash random_aes_blk; |
| 392 | nvboot_ecid unique_chip_id; |
| 393 | uint32_t boot_data_version; |
| 394 | uint32_t block_size_log2; |
| 395 | uint32_t page_size_log2; |
| 396 | uint32_t partition_size; |
| 397 | uint32_t num_param_sets; |
| 398 | nvboot_dev_type dev_type[NVBOOT_BCT_MAX_PARAM_SETS]; |
| 399 | nvboot_dev_params dev_params[NVBOOT_BCT_MAX_PARAM_SETS]; |
| 400 | uint32_t num_sdram_sets; |
| 401 | nvboot_sdram_params sdram_params[NVBOOT_BCT_MAX_SDRAM_SETS]; |
| 402 | |
| 403 | uint32_t bootloader_used; |
| 404 | nv_bootloader_info bootloader[NVBOOT_MAX_BOOTLOADERS]; |
| 405 | |
| 406 | /* |
| 407 | * Specify the number of Mts boot components described in the mts boot |
| 408 | * table. |
| 409 | */ |
| 410 | uint32_t mts_boot_components_used; |
| 411 | |
| 412 | /* |
| 413 | * Specify the information needed to locate and validate Denver Boot. |
| 414 | * components. The BR interprets entries 0/1 for preboot, 2/3 |
| 415 | * for MTS bootcode and 4/5 for MTS package. |
| 416 | */ |
| 417 | nvboot_mts_info mts_boot_components[NVBOOT_MAX_MTS_COMPONENTS]; |
| 418 | |
| 419 | uint8_t enable_fail_back; |
| 420 | |
| 421 | /* |
| 422 | * Specify whether or not to enable JTAG access when the JTAG disable fuse |
| 423 | * has not been burned. |
| 424 | * secure_jtag_control = NV_FALSE (0) = Disable JTAG access. |
| 425 | * secure_jtag_control = NV_TRUE (1) = Enable JTAG access. |
| 426 | */ |
| 427 | uint8_t secure_jtag_control; |
| 428 | |
| 429 | /* |
| 430 | * Specify whether or not to enable denver dfd access |
| 431 | * cust_denver_dfd_en = NV_FALSE (0) = Disable Dfd access. |
| 432 | * cust_denver_dfd_en = NV_TRUE (1) = Enable Dfd access. |
| 433 | */ |
| 434 | uint8_t cust_denver_dfd_en; |
| 435 | |
| 436 | uint8_t reserved[NVBOOT_BCT_RESERVED_SIZE]; |
| 437 | } nvboot_config_table; |
| 438 | #endif /* #ifndef INCLUDED_NVBOOT_BCT_T132_H */ |