Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/nyx/nyx_gui/config.c
3711 views
1
/*
2
* Copyright (c) 2018-2025 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
#include <string.h>
18
#include <stdlib.h>
19
20
#include <bdk.h>
21
22
#include "config.h"
23
#include <libs/fatfs/ff.h>
24
25
void set_default_configuration()
26
{
27
h_cfg.t210b01 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210B01;
28
h_cfg.devmode = fuse_read_hw_state();
29
30
h_cfg.autoboot = 0;
31
h_cfg.autoboot_list = 0;
32
h_cfg.bootwait = 3;
33
h_cfg.noticker = 0; //! TODO: Add GUI option.
34
h_cfg.backlight = 100;
35
h_cfg.autohosoff = h_cfg.t210b01 ? 1 : 0;
36
h_cfg.autonogc = 1;
37
h_cfg.updater2p = 0;
38
h_cfg.bootprotect = 0;
39
40
h_cfg.errors = 0;
41
h_cfg.eks = NULL;
42
h_cfg.rcm_patched = fuse_check_patched_rcm();
43
h_cfg.autorcm_enabled = false;
44
h_cfg.emummc_force_disable = false;
45
46
sd_power_cycle_time_start = 0;
47
}
48
49
void set_nyx_default_configuration()
50
{
51
n_cfg.theme_bg = 0x2D2D2D;
52
n_cfg.theme_color = 167;
53
n_cfg.entries_5_col = 0;
54
n_cfg.timeoffset = 0;
55
n_cfg.timedst = 1;
56
n_cfg.home_screen = 0;
57
n_cfg.verification = 1;
58
n_cfg.ums_emmc_rw = 0;
59
n_cfg.jc_disable = 0;
60
n_cfg.jc_force_right = 0;
61
n_cfg.bpmp_clock = 0;
62
}
63
64
int create_config_entry()
65
{
66
char lbuf[64];
67
FIL fp;
68
bool ini_found = false;
69
70
LIST_INIT(ini_sections);
71
72
if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
73
ini_found = true;
74
else
75
{
76
u8 res = f_open(&fp, "bootloader/hekate_ipl.ini", FA_READ);
77
if (res == FR_NO_FILE || res == FR_NO_PATH)
78
{
79
f_mkdir("bootloader");
80
f_mkdir("bootloader/ini");
81
f_mkdir("bootloader/payloads");
82
f_mkdir("bootloader/sys");
83
}
84
else
85
{
86
if (!res)
87
f_close(&fp);
88
return 1;
89
}
90
}
91
92
if (f_open(&fp, "bootloader/hekate_ipl.ini", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
93
return 1;
94
95
// Add config entry.
96
f_puts("[config]\nautoboot=", &fp);
97
itoa(h_cfg.autoboot, lbuf, 10);
98
f_puts(lbuf, &fp);
99
100
f_puts("\nautoboot_list=", &fp);
101
itoa(h_cfg.autoboot_list, lbuf, 10);
102
f_puts(lbuf, &fp);
103
/*
104
* Clamp value to default if it exceeds 20s to protect against corruption.
105
* Allow up to 20s though for use in cases where user needs lots of time.
106
* For example dock-only use and r2p with enough time to reach dock and cancel it.
107
*/
108
if (h_cfg.bootwait > 20)
109
h_cfg.bootwait = 3;
110
f_puts("\nbootwait=", &fp);
111
itoa(h_cfg.bootwait, lbuf, 10);
112
f_puts(lbuf, &fp);
113
114
f_puts("\nbacklight=", &fp);
115
itoa(h_cfg.backlight, lbuf, 10);
116
f_puts(lbuf, &fp);
117
118
f_puts("\nnoticker=", &fp);
119
itoa(h_cfg.noticker, lbuf, 10);
120
f_puts(lbuf, &fp);
121
122
f_puts("\nautohosoff=", &fp);
123
itoa(h_cfg.autohosoff, lbuf, 10);
124
f_puts(lbuf, &fp);
125
126
f_puts("\nautonogc=", &fp);
127
itoa(h_cfg.autonogc, lbuf, 10);
128
f_puts(lbuf, &fp);
129
130
f_puts("\nupdater2p=", &fp);
131
itoa(h_cfg.updater2p, lbuf, 10);
132
f_puts(lbuf, &fp);
133
134
f_puts("\nbootprotect=", &fp);
135
itoa(h_cfg.bootprotect, lbuf, 10);
136
f_puts(lbuf, &fp);
137
138
f_puts("\n", &fp);
139
140
if (ini_found)
141
{
142
// Re-construct existing entries.
143
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
144
{
145
if (!strcmp(ini_sec->name, "config"))
146
continue;
147
148
switch (ini_sec->type)
149
{
150
case INI_CHOICE: // Re-construct Boot entry [ ].
151
f_puts("[", &fp);
152
f_puts(ini_sec->name, &fp);
153
f_puts("]\n", &fp);
154
// Re-construct boot entry's config.
155
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
156
{
157
f_puts(kv->key, &fp);
158
f_puts("=", &fp);
159
f_puts(kv->val, &fp);
160
f_puts("\n", &fp);
161
}
162
break;
163
case INI_CAPTION: // Re-construct caption entry { }.
164
f_puts("{", &fp);
165
f_puts(ini_sec->name, &fp);
166
f_puts("}\n", &fp);
167
break;
168
case INI_NEWLINE: // Re-construct cosmetic newline \n.
169
f_puts("\n", &fp);
170
break;
171
case INI_COMMENT: // Re-construct comment entry #.
172
f_puts("#", &fp);
173
f_puts(ini_sec->name, &fp);
174
f_puts("\n", &fp);
175
break;
176
}
177
}
178
179
ini_free(&ini_sections);
180
}
181
182
f_close(&fp);
183
184
return 0;
185
}
186
187
int create_nyx_config_entry(bool force_unmount)
188
{
189
bool sd_mounted = sd_get_card_mounted();
190
191
if (sd_mount())
192
return 1;
193
194
char lbuf[64];
195
FIL fp;
196
197
// Make sure that bootloader folder exists.
198
f_mkdir("bootloader");
199
200
if (f_open(&fp, "bootloader/nyx.ini", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
201
return 1;
202
203
// Add config entry.
204
f_puts("[config]\nthemebg=", &fp);
205
itoa(n_cfg.theme_bg, lbuf, 16);
206
f_puts(lbuf, &fp);
207
208
f_puts("\nthemecolor=", &fp);
209
itoa(n_cfg.theme_color, lbuf, 10);
210
f_puts(lbuf, &fp);
211
212
f_puts("\nentries5col=", &fp);
213
itoa(n_cfg.entries_5_col, lbuf, 10);
214
f_puts(lbuf, &fp);
215
216
f_puts("\ntimeoffset=", &fp);
217
itoa(n_cfg.timeoffset, lbuf, 16);
218
f_puts(lbuf, &fp);
219
220
f_puts("\ntimedst=", &fp);
221
itoa(n_cfg.timedst, lbuf, 10);
222
f_puts(lbuf, &fp);
223
224
f_puts("\nhomescreen=", &fp);
225
itoa(n_cfg.home_screen, lbuf, 10);
226
f_puts(lbuf, &fp);
227
228
f_puts("\nverification=", &fp);
229
itoa(n_cfg.verification, lbuf, 10);
230
f_puts(lbuf, &fp);
231
232
f_puts("\numsemmcrw=", &fp);
233
itoa(n_cfg.ums_emmc_rw, lbuf, 10);
234
f_puts(lbuf, &fp);
235
236
f_puts("\njcdisable=", &fp);
237
itoa(n_cfg.jc_disable, lbuf, 10);
238
f_puts(lbuf, &fp);
239
240
f_puts("\njcforceright=", &fp);
241
itoa(n_cfg.jc_force_right, lbuf, 10);
242
f_puts(lbuf, &fp);
243
244
f_puts("\nbpmpclock=", &fp);
245
itoa(n_cfg.bpmp_clock, lbuf, 10);
246
f_puts(lbuf, &fp);
247
248
f_puts("\n", &fp);
249
250
f_close(&fp);
251
252
if (force_unmount || !sd_mounted)
253
sd_unmount();
254
255
return 0;
256
}
257
258