Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/utils/util.h
3694 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
typedef enum
25
{
26
REBOOT_RCM, // PMC reset. Enter RCM mode.
27
REBOOT_BYPASS_FUSES, // PMC reset via watchdog. Enter Normal mode. Bypass fuse programming in package1.
28
29
POWER_OFF, // Power off PMIC. Do not reset regulators.
30
POWER_OFF_RESET, // Power off PMIC. Reset regulators.
31
POWER_OFF_REBOOT, // Power off PMIC. Reset regulators. Power on.
32
} power_state_t;
33
34
typedef struct _reg_cfg_t
35
{
36
u32 idx;
37
u32 val;
38
} reg_cfg_t;
39
40
u8 bit_count(u32 val);
41
u32 bit_count_mask(u8 bits);
42
char *strcpy_ns(char *dst, char *src);
43
u64 sqrt64(u64 num);
44
long strtol(const char *nptr, char **endptr, register int base);
45
int atoi(const char *nptr);
46
47
void reg_write_array(vu32 *base, const reg_cfg_t *cfg, u32 num_cfg);
48
u32 crc32_calc(u32 crc, const u8 *buf, u32 len);
49
50
int qsort_compare_int(const void *a, const void *b);
51
int qsort_compare_char(const void *a, const void *b);
52
int qsort_compare_char_case(const void *a, const void *b);
53
54
void panic(u32 val);
55
void power_set_state(power_state_t state);
56
void power_set_state_ex(void *param);
57
58
59
/*! hekate and Nyx common defines */
60
#define NYX_NEW_INFO 0x3058594E
61
62
typedef enum
63
{
64
ERR_LIBSYS_LP0 = BIT(0),
65
ERR_SYSOLD_NYX = BIT(1),
66
ERR_LIBSYS_MTC = BIT(2),
67
ERR_SD_BOOT_EN = BIT(3),
68
ERR_PANIC_CODE = BIT(4),
69
ERR_L4T_KERNEL = BIT(24),
70
ERR_EXCEPTION = BIT(31),
71
} hekate_errors_t;
72
73
typedef enum
74
{
75
NYX_CFG_UMS = BIT(6),
76
77
NYX_CFG_EXTRA = 0xFF << 24
78
} nyx_cfg_t;
79
80
typedef struct _nyx_info_t
81
{
82
u32 magic;
83
u32 sd_init;
84
u32 sd_errors[3];
85
u8 rsvd[0x1000];
86
u32 panel_id;
87
u32 errors;
88
} nyx_info_t;
89
90
typedef struct _nyx_info_ex_t
91
{
92
u32 magic;
93
u32 rsvd_flags;
94
} nyx_info_ex_t;
95
96
typedef struct _nyx_storage_t
97
{
98
u32 version;
99
u32 cfg;
100
u8 rsdv0[0x8000];
101
u8 hekate[0x30000];
102
nyx_info_ex_t info_ex;
103
u8 rsvd1[SZ_8M - sizeof(nyx_info_ex_t) - sizeof(nyx_info_t)];
104
nyx_info_t info;
105
minerva_str_t minerva;
106
} nyx_storage_t;
107
108
#endif
109
110