Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/utils/util.h
1476 views
1
/*
2
* Copyright (c) 2018 naehrwert
3
* Copyright (c) 2018-2025 CTCaer
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms and conditions of the GNU General Public License,
7
* version 2, as published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef _UTIL_H_
19
#define _UTIL_H_
20
21
#include <utils/types.h>
22
#include <mem/minerva.h>
23
24
#define NYX_NEW_INFO 0x3058594E
25
26
typedef enum
27
{
28
REBOOT_RCM, // PMC reset. Enter RCM mode.
29
REBOOT_BYPASS_FUSES, // PMC reset via watchdog. Enter Normal mode. Bypass fuse programming in package1.
30
31
POWER_OFF, // Power off PMIC. Do not reset regulators.
32
POWER_OFF_RESET, // Power off PMIC. Reset regulators.
33
POWER_OFF_REBOOT, // Power off PMIC. Reset regulators. Power on.
34
} power_state_t;
35
36
typedef enum
37
{
38
NYX_CFG_UMS = BIT(6),
39
40
NYX_CFG_EXTRA = 0xFF << 24
41
} nyx_cfg_t;
42
43
typedef enum
44
{
45
ERR_LIBSYS_LP0 = BIT(0),
46
ERR_SYSOLD_NYX = BIT(1),
47
ERR_LIBSYS_MTC = BIT(2),
48
ERR_SD_BOOT_EN = BIT(3),
49
ERR_PANIC_CODE = BIT(4),
50
ERR_L4T_KERNEL = BIT(24),
51
ERR_EXCEPTION = BIT(31),
52
} hekate_errors_t;
53
54
typedef struct _reg_cfg_t
55
{
56
u32 idx;
57
u32 val;
58
} reg_cfg_t;
59
60
typedef struct _nyx_info_t
61
{
62
u32 magic;
63
u32 sd_init;
64
u32 sd_errors[3];
65
u8 rsvd[0x1000];
66
u32 disp_id;
67
u32 errors;
68
} nyx_info_t;
69
70
typedef struct _nyx_storage_t
71
{
72
u32 version;
73
u32 cfg;
74
u8 irama[0x8000];
75
u8 hekate[0x30000];
76
u8 rsvd[SZ_8M - sizeof(nyx_info_t)];
77
nyx_info_t info;
78
mtc_config_t mtc_cfg;
79
emc_table_t mtc_table[11]; // 10 + 1.
80
} nyx_storage_t;
81
82
u8 bit_count(u32 val);
83
u32 bit_count_mask(u8 bits);
84
char *strcpy_ns(char *dst, char *src);
85
u64 sqrt64(u64 num);
86
long strtol(const char *nptr, char **endptr, register int base);
87
int atoi(const char *nptr);
88
89
void reg_write_array(u32 *base, const reg_cfg_t *cfg, u32 num_cfg);
90
u32 crc32_calc(u32 crc, const u8 *buf, u32 len);
91
92
int qsort_compare_int(const void *a, const void *b);
93
int qsort_compare_char(const void *a, const void *b);
94
int qsort_compare_char_case(const void *a, const void *b);
95
96
void panic(u32 val);
97
void power_set_state(power_state_t state);
98
void power_set_state_ex(void *param);
99
100
101
#endif
102
103