Debian Codegraph @

util/nvidia/cbootimage/src/t114/nvboot_bct_t114.h

raw symbols SCIP
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_T114_H
21 #define INCLUDED_NVBOOT_BCT_T114_H
22
23 #include <sys/types.h>
24 #include "nvboot_sdram_param_t114.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 178
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 2
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 #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 {
122 /// The modulus size is 2048-bits.
123 uint32_t modulus[NVBOOT_SE_RSA_MODULUS_LENGTH_BITS / 8 / 4];
124 } nvboot_rsa_key_modulus;
125
126 typedef struct nvboot_rsa_pss_sig_rec
127 {
128 /*
129 * The RSA-PSS signature length is equal to the
130 * length in octets of the RSA modulus.
131 * In our case, it's 2048-bits.
132 */
133 uint32_t signature[NVBOOT_SE_RSA_MODULUS_LENGTH_BITS / 8 / 4];
134 } nvboot_rsa_pss_sig;
135
136 typedef union nvboot_object_signature_rec
137 {
138 /*
139 * Specifies the AES-CMAC signature for the rest of the BCT structure if symmetric key
140 * encryption secure boot scheme is used.
141 */
142 nvboot_hash crypto_hash;
143
144 /*
145 * Specifies the RSASSA-PSS signature for the rest of the BCT structure if public
146 * key cryptography secure boot scheme is used.
147 */
148 nvboot_rsa_pss_sig rsa_pss_sig;
149 } nvboot_object_signature;
150
151 typedef struct nvboot_ecid_rec
152 {
153 uint32_t ecid_0;
154 uint32_t ecid_1;
155 uint32_t ecid_2;
156 uint32_t ecid_3;
157 } nvboot_ecid;
158
159 /* Defines various data widths supported. */
160 typedef enum {
161 /**
162 * Specifies a 1 bit interface to eMMC.
163 * Note that 1-bit data width is only for the driver's internal use.
164 * Fuses doesn't provide option to select 1-bit data width.
165 * The driver selects 1-bit internally based on need.
166 * It is used for reading Extended CSD and when the power class
167 * requirements of a card for 4-bit or 8-bit transfers are not
168 * supported by the target board.
169 */
170 nvboot_sdmmc_data_width_1bit = 0,
171
172 /* Specifies a 4 bit interface to eMMC. */
173 nvboot_sdmmc_data_width_4bit = 1,
174
175 /* Specifies a 8 bit interface to eMMC. */
176 nvboot_sdmmc_data_width_8bit = 2,
177 /* Specifies a 4 bit Ddr interface to eMMC. */
178 nvboot_sdmmc_data_width_ddr_4bit = 5,
179 /* Specifies a 8 bit Ddr interface to eMMC. */
180 nvboot_sdmmc_data_width_ddr_8bit = 6,
181
182 nvboot_sdmmc_data_width_num,
183 nvboot_sdmmc_data_width_force32 = 0x7FFFFFFF
184 } nvboot_sdmmc_data_width;
185
186 /* Defines the parameters that can be changed after BCT is read. */
187 typedef struct nvboot_sdmmc_params_rec {
188 /**
189 * Specifies the clock divider for the SDMMC controller's clock source,
190 * which is PLLP running at 216MHz. If it is set to 9, then the SDMMC
191 * controller runs at 216/9 = 24MHz.
192 */
193 uint8_t clock_divider;
194
195 /* Specifies the data bus width. Supported data widths are 4/8 bits. */
196 nvboot_sdmmc_data_width data_width;
197
198 /**
199 * Max Power class supported by the target board.
200 * The driver determines the best data width and clock frequency
201 * supported within the power class range (0 to Max) if the selected
202 * data width cannot be used at the chosen clock frequency.
203 */
204 uint8_t max_power_class_supported;
205
206 /* Specifies the max page size supported by driver */
207 uint8_t multi_page_support;
208 } nvboot_sdmmc_params;
209
210 typedef enum {
211 /* Specifies SPI clock source to be PLLP. */
212 nvboot_spi_clock_source_pllp_out0 = 0,
213
214 /* Specifies SPI clock source to be ClockM. */
215 nvboot_spi_clock_source_clockm = 6,
216
217 nvboot_spi_clock_source_num,
218 nvboot_spi_clock_source_force32 = 0x7FFFFFF
219 } nvboot_spi_clock_source;
220
221 /**
222 * Defines the parameters SPI FLASH devices.
223 */
224 typedef struct nvboot_spiflash_params_rec {
225 /**
226 * Specifies the clock source to use.
227 */
228 uint32_t clock_source;
229
230 /**
231 * Specifes the clock divider to use.
232 * The value is a 7-bit value based on an input clock of 432Mhz.
233 * Divider = (432+ DesiredFrequency-1)/DesiredFrequency;
234 * Typical values:
235 * NORMAL_READ at 20MHz: 22
236 * FAST_READ at 33MHz: 14
237 * FAST_READ at 40MHz: 11
238 * FAST_READ at 50MHz: 9
239 */
240 uint8_t clock_divider;
241
242 /**
243 * Specifies the type of command for read operations.
244 * NV_FALSE specifies a NORMAL_READ Command
245 * NV_TRUE specifies a FAST_READ Command
246 */
247 uint8_t read_command_type_fast;
248
249 /* 0 = 2k page size, 1 = 16K page size */
250 uint8_t page_size_2k_or_16k;
251 } nvboot_spiflash_params;
252
253 /**
254 * Defines the union of the parameters required by each device.
255 */
256 typedef union {
257 uint8_t size[64];
258 /* Specifies optimized parameters for eMMC and eSD */
259 nvboot_sdmmc_params sdmmc_params;
260 /* Specifies optimized parameters for SPI NOR */
261 nvboot_spiflash_params spiflash_params;
262 } nvboot_dev_params;
263
264 /**
265 * Identifies the types of devices from which the system booted.
266 * Used to identify primary and secondary boot devices.
267 * @note These no longer match the fuse API device values (for
268 * backward compatibility with AP15).
269 */
270 typedef enum {
271 /* Specifies a default (unset) value. */
272 nvboot_dev_type_none = 0,
273
274 /* Specifies SPI NOR. */
275 nvboot_dev_type_spi = 3,
276
277 /* Specifies SDMMC (either eMMC or eSD). */
278 nvboot_dev_type_sdmmc = 4,
279
280 nvboot_dev_type_max,
281
282 /* Ignore -- Forces compilers to make 32-bit enums. */
283 nvboot_dev_type_force32 = 0x7FFFFFFF
284 } nvboot_dev_type;
285
286 /**
287 * Stores information needed to locate and verify a boot loader.
288 *
289 * There is one \c nv_bootloader_info structure for each copy of a BL stored on
290 * the device.
291 */
292 typedef struct nv_bootloader_info_rec {
293 uint32_t version;
294 uint32_t start_blk;
295 uint32_t start_page;
296 uint32_t length;
297 uint32_t load_addr;
298 uint32_t entry_point;
299 uint32_t attribute;
300
301 /* Specifies the AES-CMAC MAC or RSASSA-PSS signature of the BL. */
302 nvboot_object_signature signature;
303 } nv_bootloader_info;
304
305 /**
306 * Defines the bad block table structure stored in the BCT.
307 */
308 typedef struct nvboot_badblock_table_rec {
309 uint32_t entries_used;
310 uint8_t virtual_blk_size_log2;
311 uint8_t block_size_log2;
312 uint8_t bad_blks[NVBOOT_BAD_BLOCK_TABLE_SIZE / 8];
313 /*
314 * Add a reserved field as padding to make the bad block table structure
315 * a multiple of 16 bytes (AES block size).
316 */
317 uint8_t reserved[NVBOOT_BAD_BLOCK_TABLE_PADDING];
318 } nvboot_badblock_table;
319
320 /**
321 * Contains the information needed to load BLs from the secondary boot device.
322 *
323 * - Supplying NumParamSets = 0 indicates not to load any of them.
324 * - Supplying NumDramSets = 0 indicates not to load any of them.
325 * - The \c random_aes_blk member exists to increase the difficulty of
326 * key attacks based on knowledge of this structure.
327 */
328 typedef struct nvboot_config_table_rec {
329 nvboot_badblock_table badblock_table;
330 nvboot_rsa_key_modulus key;
331 nvboot_object_signature signature;
332 uint8_t customer_data[NVBOOT_BCT_CUSTOMER_DATA_SIZE];
333 uint32_t odm_data;
334 uint32_t reserved1;
335
336 /* START OF SIGNED SECTION OF THE BCT */
337 nvboot_hash random_aes_blk;
338 nvboot_ecid unique_chip_id;
339 uint32_t boot_data_version;
340 uint32_t block_size_log2;
341 uint32_t page_size_log2;
342 uint32_t partition_size;
343 uint32_t num_param_sets;
344 nvboot_dev_type dev_type[NVBOOT_BCT_MAX_PARAM_SETS];
345 nvboot_dev_params dev_params[NVBOOT_BCT_MAX_PARAM_SETS];
346 uint32_t num_sdram_sets;
347 nvboot_sdram_params sdram_params[NVBOOT_BCT_MAX_SDRAM_SETS];
348
349 uint32_t bootloader_used;
350 nv_bootloader_info bootloader[NVBOOT_MAX_BOOTLOADERS];
351
352 uint8_t enable_fail_back;
353
354 /*
355 * Specify whether or not to enable JTAG access when the JTAG disable fuse
356 * has not been burned.
357 * SecureJtagControl = NV_FALSE (0) = Disable JTAG access.
358 * SecureJtagControl = NV_TRUE (1) = Enable JTAG access.
359 */
360 uint8_t secure_jtag_control;
361 uint8_t reserved[NVBOOT_BCT_RESERVED_SIZE];
362 } nvboot_config_table;
363 #endif /* #ifndef INCLUDED_NVBOOT_BCT_T114_H */