| 1 | /* |
| 2 | * Copyright (c) 2012, 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_T20_H |
| 21 | #define INCLUDED_NVBOOT_BCT_T20_H |
| 22 | |
| 23 | #include <sys/types.h> |
| 24 | #include "nvboot_sdram_param_t20.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 296 |
| 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 3 |
| 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 maximum number of blocks to search for BCTs. |
| 77 | * |
| 78 | * This value covers the initial block and a set of journal blocks. |
| 79 | * |
| 80 | * Ideally, this number will span several erase units for reliable updates |
| 81 | * and tolerance for blocks to become bad with use. Safe updates require |
| 82 | * a minimum of 2 erase units in which BCTs can appear. |
| 83 | * |
| 84 | * To ensure that the BCT search spans a sufficient range of configurations, |
| 85 | * the search block count has been set to 64. This allows for redundancy with |
| 86 | * a wide range of parts and provides room for greater problems in this |
| 87 | * region of the device. |
| 88 | */ |
| 89 | #define NVBOOT_MAX_BCT_SEARCH_BLOCKS 64 |
| 90 | |
| 91 | /* |
| 92 | * Defines the CMAC-AES-128 hash length in 32 bit words. (128 bits = 4 words) |
| 93 | */ |
| 94 | enum {NVBOOT_CMAC_AES_HASH_LENGTH = 4}; |
| 95 | |
| 96 | /** |
| 97 | * Defines the storage for a hash value (128 bits). |
| 98 | */ |
| 99 | typedef struct nvboot_hash_rec { |
| 100 | uint32_t hash[NVBOOT_CMAC_AES_HASH_LENGTH]; |
| 101 | } nvboot_hash; |
| 102 | |
| 103 | /* Defines the params that can be configured for NAND devices. */ |
| 104 | typedef struct nvboot_nand_params_rec { |
| 105 | /** |
| 106 | * Specifies the clock divider for the PLL_P 432MHz source. |
| 107 | * If it is set to 18, then clock source to Nand controller is |
| 108 | * 432 / 18 = 24MHz. |
| 109 | */ |
| 110 | uint8_t clock_divider; |
| 111 | |
| 112 | /* Specifies the value to be programmed to Nand Timing Register 1 */ |
| 113 | uint32_t nand_timing; |
| 114 | |
| 115 | /* Specifies the value to be programmed to Nand Timing Register 2 */ |
| 116 | uint32_t nand_timing2; |
| 117 | |
| 118 | /* Specifies the block size in log2 bytes */ |
| 119 | uint8_t block_size_log2; |
| 120 | |
| 121 | /* Specifies the page size in log2 bytes */ |
| 122 | uint8_t page_size_log2; |
| 123 | } nvboot_nand_params; |
| 124 | |
| 125 | /* Defines various data widths supported. */ |
| 126 | typedef enum { |
| 127 | /** |
| 128 | * Specifies a 1 bit interface to eMMC. |
| 129 | * Note that 1-bit data width is only for the driver's internal use. |
| 130 | * Fuses doesn't provide option to select 1-bit data width. |
| 131 | * The driver selects 1-bit internally based on need. |
| 132 | * It is used for reading Extended CSD and when the power class |
| 133 | * requirements of a card for 4-bit or 8-bit transfers are not |
| 134 | * supported by the target board. |
| 135 | */ |
| 136 | nvboot_sdmmc_data_width_1bit = 0, |
| 137 | |
| 138 | /* Specifies a 4 bit interface to eMMC. */ |
| 139 | nvboot_sdmmc_data_width_4bit = 1, |
| 140 | |
| 141 | /* Specifies a 8 bit interface to eMMC. */ |
| 142 | nvboot_sdmmc_data_width_8bit = 2, |
| 143 | |
| 144 | nvboot_sdmmc_data_width_num, |
| 145 | nvboot_sdmmc_data_width_force32 = 0x7FFFFFFF |
| 146 | } nvboot_sdmmc_data_width; |
| 147 | |
| 148 | /* Defines the parameters that can be changed after BCT is read. */ |
| 149 | typedef struct nvboot_sdmmc_params_rec { |
| 150 | /** |
| 151 | * Specifies the clock divider for the SDMMC controller's clock source, |
| 152 | * which is PLLP running at 432MHz. If it is set to 18, then the SDMMC |
| 153 | * controller runs at 432/18 = 24MHz. |
| 154 | */ |
| 155 | uint8_t clock_divider; |
| 156 | |
| 157 | /* Specifies the data bus width. Supported data widths are 4/8 bits. */ |
| 158 | nvboot_sdmmc_data_width data_width; |
| 159 | |
| 160 | /** |
| 161 | * Max Power class supported by the target board. |
| 162 | * The driver determines the best data width and clock frequency |
| 163 | * supported within the power class range (0 to Max) if the selected |
| 164 | * data width cannot be used at the chosen clock frequency. |
| 165 | */ |
| 166 | uint8_t max_power_class_supported; |
| 167 | } nvboot_sdmmc_params; |
| 168 | |
| 169 | typedef enum { |
| 170 | /* Specifies SPI clock source to be PLLP. */ |
| 171 | nvboot_spi_clock_source_pllp_out0 = 0, |
| 172 | |
| 173 | /* Specifies SPI clock source to be PLLC. */ |
| 174 | nvboot_spi_clock_source_pllc_out0, |
| 175 | |
| 176 | /* Specifies SPI clock source to be PLLM. */ |
| 177 | nvboot_spi_clock_source_pllm_out0, |
| 178 | |
| 179 | /* Specifies SPI clock source to be ClockM. */ |
| 180 | nvboot_spi_clock_source_clockm, |
| 181 | |
| 182 | nvboot_spi_clock_source_num, |
| 183 | nvboot_spi_clock_source_force32 = 0x7FFFFFF |
| 184 | } nvboot_spi_clock_source; |
| 185 | |
| 186 | |
| 187 | /** |
| 188 | * Defines the parameters SPI FLASH devices. |
| 189 | */ |
| 190 | typedef struct nvboot_spiflash_params_rec { |
| 191 | /** |
| 192 | * Specifies the clock source to use. |
| 193 | */ |
| 194 | nvboot_spi_clock_source clock_source; |
| 195 | |
| 196 | /** |
| 197 | * Specifes the clock divider to use. |
| 198 | * The value is a 7-bit value based on an input clock of 432Mhz. |
| 199 | * Divider = (432+ DesiredFrequency-1)/DesiredFrequency; |
| 200 | * Typical values: |
| 201 | * NORMAL_READ at 20MHz: 22 |
| 202 | * FAST_READ at 33MHz: 14 |
| 203 | * FAST_READ at 40MHz: 11 |
| 204 | * FAST_READ at 50MHz: 9 |
| 205 | */ |
| 206 | uint8_t clock_divider; |
| 207 | |
| 208 | /** |
| 209 | * Specifies the type of command for read operations. |
| 210 | * NV_FALSE specifies a NORMAL_READ Command |
| 211 | * NV_TRUE specifies a FAST_READ Command |
| 212 | */ |
| 213 | uint8_t read_command_type_fast; |
| 214 | } nvboot_spiflash_params; |
| 215 | |
| 216 | /** |
| 217 | * Defines the union of the parameters required by each device. |
| 218 | */ |
| 219 | typedef union { |
| 220 | /* Specifies optimized parameters for NAND */ |
| 221 | nvboot_nand_params nand_params; |
| 222 | /* Specifies optimized parameters for eMMC and eSD */ |
| 223 | nvboot_sdmmc_params sdmmc_params; |
| 224 | /* Specifies optimized parameters for SPI NOR */ |
| 225 | nvboot_spiflash_params spiflash_params; |
| 226 | } nvboot_dev_params; |
| 227 | |
| 228 | /** |
| 229 | * Identifies the types of devices from which the system booted. |
| 230 | * Used to identify primary and secondary boot devices. |
| 231 | * @note These no longer match the fuse API device values (for |
| 232 | * backward compatibility with AP15). |
| 233 | */ |
| 234 | typedef enum { |
| 235 | /* Specifies a default (unset) value. */ |
| 236 | nvboot_dev_type_none = 0, |
| 237 | |
| 238 | /* Specifies NAND. */ |
| 239 | nvboot_dev_type_nand, |
| 240 | |
| 241 | /* Specifies SPI NOR. */ |
| 242 | nvboot_dev_type_spi = 3, |
| 243 | |
| 244 | /* Specifies SDMMC (either eMMC or eSD). */ |
| 245 | nvboot_dev_type_sdmmc, |
| 246 | |
| 247 | nvboot_dev_type_max, |
| 248 | |
| 249 | /* Ignore -- Forces compilers to make 32-bit enums. */ |
| 250 | nvboot_dev_type_force32 = 0x7FFFFFFF |
| 251 | } nvboot_dev_type; |
| 252 | |
| 253 | /** |
| 254 | * Stores information needed to locate and verify a boot loader. |
| 255 | * |
| 256 | * There is one \c nv_bootloader_info structure for each copy of a BL stored on |
| 257 | * the device. |
| 258 | */ |
| 259 | typedef struct nv_bootloader_info_rec { |
| 260 | uint32_t version; |
| 261 | uint32_t start_blk; |
| 262 | uint32_t start_page; |
| 263 | uint32_t length; |
| 264 | uint32_t load_addr; |
| 265 | uint32_t entry_point; |
| 266 | uint32_t attribute; |
| 267 | nvboot_hash crypto_hash; |
| 268 | } nv_bootloader_info; |
| 269 | |
| 270 | /** |
| 271 | * Defines the bad block table structure stored in the BCT. |
| 272 | */ |
| 273 | typedef struct nvboot_badblock_table_rec { |
| 274 | uint32_t entries_used; |
| 275 | uint8_t virtual_blk_size_log2; |
| 276 | uint8_t block_size_log2; |
| 277 | uint8_t bad_blks[NVBOOT_BAD_BLOCK_TABLE_SIZE / 8]; |
| 278 | } nvboot_badblock_table; |
| 279 | |
| 280 | /** |
| 281 | * Contains the information needed to load BLs from the secondary boot device. |
| 282 | * |
| 283 | * - Supplying NumParamSets = 0 indicates not to load any of them. |
| 284 | * - Supplying NumDramSets = 0 indicates not to load any of them. |
| 285 | * - The \c random_aes_blk member exists to increase the difficulty of |
| 286 | * key attacks based on knowledge of this structure. |
| 287 | */ |
| 288 | typedef struct nvboot_config_table_rec { |
| 289 | nvboot_hash crypto_hash; |
| 290 | nvboot_hash random_aes_blk; |
| 291 | uint32_t boot_data_version; |
| 292 | uint32_t block_size_log2; |
| 293 | uint32_t page_size_log2; |
| 294 | uint32_t partition_size; |
| 295 | uint32_t num_param_sets; |
| 296 | nvboot_dev_type dev_type[NVBOOT_BCT_MAX_PARAM_SETS]; |
| 297 | nvboot_dev_params dev_params[NVBOOT_BCT_MAX_PARAM_SETS]; |
| 298 | uint32_t num_sdram_sets; |
| 299 | nvboot_sdram_params sdram_params[NVBOOT_BCT_MAX_SDRAM_SETS]; |
| 300 | nvboot_badblock_table badblock_table; |
| 301 | uint32_t bootloader_used; |
| 302 | nv_bootloader_info bootloader[NVBOOT_MAX_BOOTLOADERS]; |
| 303 | uint8_t customer_data[NVBOOT_BCT_CUSTOMER_DATA_SIZE]; |
| 304 | |
| 305 | /* |
| 306 | * ODMDATA is stored in the BCT in IRAM by the BootROM. |
| 307 | * Read the data @ bct_start + (bct_size - 12). This works |
| 308 | * on T20 and T30 BCTs, which are locked down. If this changes |
| 309 | * in new chips, we can revisit this algorithm. |
| 310 | */ |
| 311 | uint32_t odm_data; |
| 312 | uint32_t reserved1; |
| 313 | uint8_t enable_fail_back; |
| 314 | uint8_t reserved[NVBOOT_BCT_RESERVED_SIZE]; |
| 315 | } nvboot_config_table; |
| 316 | #endif /* #ifndef INCLUDED_NVBOOT_BCT_T20_H */ |