Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/utils/tegra_bit.h
3694 views
1
/*
2
* Copyright (c) 2018-2022 CTCaer
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
17
#ifndef TEGRA_BIT_H
18
#define TEGRA_BIT_H
19
20
#include <utils/types.h>
21
22
#define BIT_ADDRESS 0x40000000
23
24
#define BIT_BOOT_TYPE_NONE 0
25
#define BIT_BOOT_TYPE_COLD 1
26
#define BIT_BOOT_TYPE_RCM 2
27
#define BIT_BOOT_TYPE_UART 3
28
#define BIT_BOOT_TYPE_EXIT_RCM 4
29
30
#define BIT_READ_STATUS_NONE 0
31
#define BIT_READ_STATUS_SUCCESS 1
32
#define BIT_READ_STATUS_VALIDATION_ERROR 2
33
#define BIT_READ_STATUS_HW_READ_ERROR 3
34
35
#define BIT_USB_CHARGE_DETECT_EN BIT(0)
36
#define BIT_USB_CHARGE_LOW_BATT BIT(1)
37
#define BIT_USB_CHARGE_CONNECTED BIT(2)
38
#define BIT_USB_CHARGE_HI_CURRENT BIT(8)
39
40
// From T186 with some additions.
41
enum
42
{
43
BIT_FLOW_STATUS_NONE = 0,
44
BIT_FLOW_STATUS_IPATCHUNCORRECTED_ERROR = 1,
45
BIT_FLOW_STATUS_IPATCHSUCCESS = 2,
46
BIT_FLOW_STATUS_SETUPOSCCLK = 3,
47
BIT_FLOW_STATUS_LOWBAT_NOTCHARGED = 4,
48
BIT_FLOW_STATUS_LOWBAT_CHARGED = 5,
49
BIT_FLOW_STATUS_PLLPENABLED = 6,
50
BIT_FLOW_STATUS_MSSINITIALIZED = 7,
51
BIT_FLOW_STATUS_FABRICINITIALIZED = 8,
52
BIT_FLOW_STATUS_NONSECUREDISPATCHERENTRY = 9,
53
BIT_FLOW_STATUS_NONSECUREDISPATCHEREXIT = 10,
54
BIT_FLOW_STATUS_FAMODE = 11,
55
BIT_FLOW_STATUS_PREPRODUCTIONMODEUART = 12,
56
BIT_FLOW_STATUS_PRODUCTIONMODE = 13,
57
BIT_FLOW_STATUS_ODMPRODUCTIONMODE = 14,
58
BIT_FLOW_STATUS_DBGRCMMODE = 15,
59
BIT_FLOW_STATUS_RECOVERYMODE = 16,
60
BIT_FLOW_STATUS_SECUREDISPATCHERENTRY = 17,
61
BIT_FLOW_STATUS_SECUREDISPATCHEREXIT = 18,
62
BIT_FLOW_STATUS_RAMDUMPINIT = 19,
63
BIT_FLOW_STATUS_RAMDUMPEXIT = 20,
64
BIT_FLOW_STATUS_COLDBOOTENTRY = 21,
65
BIT_FLOW_STATUS_COLDBOOTEXIT = 22,
66
BIT_FLOW_STATUS_CBSETUPBOOTDEVICE = 23,
67
BIT_FLOW_STATUS_CBBCTDONE = 24,
68
BIT_FLOW_STATUS_MSSREGIONUNINITIALIZED = 25,
69
BIT_FLOW_STATUS_MSSREGIONENABLEINITIALIZED = 26,
70
BIT_FLOW_STATUS_CBMTSPREBOOTINIT = 27,
71
BIT_FLOW_STATUS_CBREINITSUCCESS = 28,
72
BIT_FLOW_STATUS_CBSDRAMINITSUCCESS = 29,
73
BIT_FLOW_STATUS_CBPAYLOADSUCCESS = 30,
74
BIT_FLOW_STATUS_RCMENTRY = 31,
75
BIT_FLOW_STATUS_RCMEXIT = 32,
76
BIT_FLOW_STATUS_SC7ENTRY = 33,
77
BIT_FLOW_STATUS_SC7ACKWAYPOINT = 34,
78
BIT_FLOW_STATUS_SC7DBELLERROR = 35,
79
BIT_FLOW_STATUS_SC7EXIT = 36,
80
BIT_FLOW_STATUS_SECUREBOOTENTRY = 37,
81
BIT_FLOW_STATUS_SECUREBOOTEXIT = 38,
82
BIT_FLOW_STATUS_DETECTEDWDTRESET = 39,
83
BIT_FLOW_STATUS_DETECTEDAOTAG_SENSORRESET = 40,
84
BIT_FLOW_STATUS_DETECTEDVFSENSORRESET = 41,
85
BIT_FLOW_STATUS_DETECTEDSWMAINRESET = 42,
86
BIT_FLOW_STATUS_DETECTEDHSMRESET = 43,
87
BIT_FLOW_STATUS_DETECTEDCSITEDBGRESET = 44,
88
BIT_FLOW_STATUS_DETECTEDSC7SPEWDT_0_RESET = 45,
89
BIT_FLOW_STATUS_DETECTEDSC7SPEWDT_1_RESET = 46,
90
BIT_FLOW_STATUS_DETECTEDSYSRESETN = 47,
91
BIT_FLOW_STATUS_CRYPTOINITENTRY = 48,
92
BIT_FLOW_STATUS_CRYPTOINITEXIT = 49,
93
BIT_FLOW_STATUS_SECUREEXITSTART = 50
94
};
95
96
typedef struct _bit_flow_log_t
97
{
98
u32 Init_time;
99
u32 exit_time;
100
u32 func_id;
101
u32 func_status;
102
} bit_flow_log_t;
103
104
typedef struct _bit_boot_sdmmc_status_t210_t
105
{
106
u8 fuses_bus_width;
107
u8 fuses_voltage_range;
108
u8 fuses_boo_mode_disable;
109
u8 fuses_drd_mode;
110
111
u32 card_type;
112
u32 voltage_range;
113
u8 bus_width;
114
u8 power_class;
115
u8 auto_cal_status;
116
u8 padding;
117
u32 cid[4];
118
119
u32 pages_read;
120
u32 crc_errors;
121
u8 boot_from_boot_partition;
122
u8 boot_mode_read_success;
123
} bit_boot_sdmmc_status_t210_t;
124
125
typedef struct _bit_boot_sdmmc_status_t210b01_t
126
{
127
u8 clk_src;
128
u8 clk_div;
129
u8 clk_en;
130
u8 clk_rst_status;
131
u8 clk_div_internal;
132
u8 data_mode;
133
134
u8 fuses_bus_width;
135
u8 fuses_drd_mode;
136
u8 fuses_config;
137
u8 fuses_read_mode;
138
139
u8 card_type;
140
u32 voltage_range;
141
u8 bus_width;
142
u8 power_class;
143
u8 auto_cal_status;
144
u32 cid[4];
145
146
u32 pages_read;
147
u32 crc_errors;
148
u8 boot_from_boot_partition;
149
150
u32 time_init;
151
u32 time_controller_init;
152
u32 time_card_enumeration;
153
u32 time_cmd1_op_cond;
154
u32 time_cmd2_cid;
155
u32 time_cmd9_csd;
156
u32 time_transfer_mode;
157
u32 time_cmd8_ext_csd;
158
u32 time_power_class;
159
u32 time_bus_width_and_partition;
160
u32 time_read;
161
162
u32 payload_size;
163
} bit_boot_sdmmc_status_t210b01_t;
164
165
typedef struct _bit_boot_spi_status_t210_t
166
{
167
u32 clk_src;
168
u32 clk_div;
169
u32 fast_read;
170
171
u32 pages_read;
172
u32 last_block_read;
173
u32 last_page_read;
174
175
u32 boot_status;
176
u32 init_status;
177
u32 read_status;
178
u32 params_validated;
179
} bit_boot_spi_status_t210_t;
180
181
typedef struct _bit_boot_spi_status_t210b01_t
182
{
183
u32 clk_en;
184
u32 clk_rst_status;
185
u32 mode;
186
u32 bus_width;
187
u32 clk_src;
188
u32 clk_div;
189
u32 fast_read;
190
191
u32 pages_read;
192
u32 last_block_read;
193
u32 last_page_read;
194
195
u32 boot_status;
196
u32 init_status;
197
u32 read_status;
198
u32 params_validated;
199
200
u32 time_qspi_init;
201
u32 time_read_time;
202
203
u32 payload_size;
204
} bit_boot_spi_status_t210b01_t;
205
206
typedef struct _bit_boot_usb3_status_t
207
{
208
u8 port;
209
u8 sense_key;
210
u8 padding[2];
211
u32 cur_csw_tag;
212
u32 curr_cmd_csw_status;
213
u32 curr_ep_xfer_failed_bytes;
214
u32 periph_dev_type;
215
u32 block_num;
216
u32 last_logical_block_addr;
217
u32 block_length;
218
u32 usb3_ctxt;
219
u32 init_res;
220
u32 read_page_res;
221
u32 xusb_driver_status;
222
u32 dev_status;
223
u32 ep_status;
224
} bit_boot_usb3_status_t;
225
226
typedef union _bit_boot_secondary_dev_status_t210_t
227
{
228
bit_boot_sdmmc_status_t210_t sdmmc_status;
229
bit_boot_spi_status_t210_t spi_status;
230
bit_boot_usb3_status_t usb3_status;
231
232
u8 padding[60];
233
} bit_boot_secondary_dev_status_t210_t;
234
235
typedef union _bit_boot_secondary_dev_status_t210b01_t
236
{
237
bit_boot_sdmmc_status_t210b01_t sdmmc_status;
238
bit_boot_spi_status_t210b01_t spi_status;
239
240
u8 padding[256];
241
} bit_boot_secondary_dev_status_t210b01_t;
242
243
typedef struct _bit_bl_state_t
244
{
245
u32 read_status;
246
247
u32 first_ecc_block;
248
u32 first_ecc_page;
249
u32 first_corrected_ecc_block;
250
u32 first_corrected_ecc_page;
251
u8 had_ecc_error;
252
u8 had_crc_error;
253
u8 had_corrected_ecc_error;
254
u8 used_for_ecc_recovery;
255
} bit_bl_state_t;
256
257
typedef struct _tegra_bit_t210_t
258
{
259
u32 brom_version;
260
u32 data_version;
261
u32 rcm_version;
262
263
u32 boot_type;
264
265
u32 primary_dev_type;
266
u32 secondary_dev_type;
267
268
u32 boot_time_log_init;
269
u32 boot_time_log_exit;
270
u32 bct_read_tick_cnt;
271
u32 bl_read_tick_cnt;
272
273
u32 osc_frequency;
274
u8 dev_initialized;
275
u8 dram_initialized;
276
277
u8 force_recovery_bit_cleared; // APBDEV_PMC_SCRATCH0.
278
u8 failback_bit_cleared; // APBDEV_PMC_SCRATCH0.
279
u8 failback_invoked;
280
281
u8 irom_patch_status; // bit0-3: hamming status, bit7: patches exist.
282
283
u8 bct_valid;
284
u8 bct_status[9]; // Each bit is a block (72 blocks).
285
u32 bct_last_journal_read;
286
u32 bct_block;
287
u32 bct_page;
288
u32 bct_size;
289
u32 bct_ptr;
290
291
bit_bl_state_t bl_state[4];
292
293
bit_boot_secondary_dev_status_t210_t secondary_dev_status;
294
295
u32 usb_charging_status;
296
297
u32 safe_start_addr; // Init: 0x400000F4 / UART: 0x40000100 / BL: 0x40002900.
298
299
u8 padding[12];
300
} tegra_bit_t210_t;
301
302
typedef struct _tegra_bit_t210b01_t
303
{
304
u32 brom_version;
305
u32 data_version;
306
u32 rcm_version;
307
308
u32 boot_type;
309
310
u32 primary_dev_type;
311
u32 secondary_dev_type;
312
313
u32 authentication_scheme;
314
u32 encryption_enabled;
315
316
u32 brom_flow_tracker;
317
318
u32 reserved;
319
u32 boot_time_log_exit;
320
u32 setup_tick_cnt;
321
u32 bct_read_tick_cnt;
322
u32 bl_read_tick_cnt;
323
324
bit_flow_log_t boot_flow_log[40];
325
326
u32 osc_frequency;
327
u8 dev_initialized;
328
u8 dram_initialized;
329
330
u8 force_recovery_bit_cleared;
331
u8 failback_bit_cleared;
332
u8 failback_invoked;
333
334
u8 irom_patch_status; // bit0-3: hamming status, bit7: patches exist.
335
336
u8 bct_size_valid;
337
u8 bct_size_status[9];
338
u32 bct_size_last_journal_read;
339
u32 bct_size_block;
340
u32 bct_size_page;
341
342
u8 bct_valid;
343
u8 bct_status[9];
344
u8 padding[2];
345
u32 bct_last_journal_read;
346
u32 bct_block;
347
u32 bct_page;
348
u32 bct_size;
349
u32 bct_ptr;
350
351
bit_bl_state_t bl_state[4];
352
353
bit_boot_secondary_dev_status_t210b01_t secondary_dev_status;
354
355
u32 usb_charging_status;
356
357
u8 pmu_boot_sel_read_error;
358
359
u32 safe_start_addr; // Init: 0x40000464 / UART: 0x40000464 / BL: 0x40002C64.
360
} tegra_bit_t210b01_t;
361
362
#endif
363
364