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