-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathmain.c
96 lines (79 loc) · 2.32 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <switch.h>
#include "ams_bpc.h"
#define IRAM_PAYLOAD_MAX_SIZE 0x24000
static u8 g_reboot_payload[IRAM_PAYLOAD_MAX_SIZE];
void userAppExit(void)
{
amsBpcExit();
setsysExit();
spsmExit();
}
static void reboot_to_payload(void) {
Result rc = amsBpcSetRebootPayload(g_reboot_payload, IRAM_PAYLOAD_MAX_SIZE);
if (R_FAILED(rc)) {
printf("Failed to set reboot payload: 0x%x\n", rc);
}
else {
spsmShutdown(true);
}
}
int main(int argc, char **argv)
{
consoleInit(NULL);
padConfigureInput(8, HidNpadStyleSet_NpadStandard);
PadState pad;
padInitializeAny(&pad);
Result rc = 0;
bool can_reboot = true;
if (R_FAILED(rc = setsysInitialize())) {
printf("Failed to initialize set:sys: 0x%x\n", rc);
can_reboot = false;
}
else {
SetSysProductModel model;
setsysGetProductModel(&model);
if (model != SetSysProductModel_Nx && model != SetSysProductModel_Copper) {
printf("Reboot to payload cannot be used on a Mariko system\n");
can_reboot = false;
}
}
if (can_reboot && R_FAILED(rc = spsmInitialize())) {
printf("Failed to initialize spsm: 0x%x\n", rc);
can_reboot = false;
}
if (can_reboot) {
smExit(); //Required to connect to ams:bpc
if R_FAILED(rc = amsBpcInitialize()) {
printf("Failed to initialize ams:bpc: 0x%x\n", rc);
can_reboot = false;
}
}
if (can_reboot) {
FILE *f = fopen("sdmc:/atmosphere/reboot_payload.bin", "rb");
if (f == NULL) {
printf("Failed to open atmosphere/reboot_payload.bin!\n");
can_reboot = false;
} else {
fread(g_reboot_payload, 1, sizeof(g_reboot_payload), f);
fclose(f);
printf("Press [-] to reboot to payload\n");
}
}
printf("Press [L] to exit\n");
// Main loop
while(appletMainLoop())
{
padUpdate(&pad);
u64 kDown = padGetButtonsDown(&pad);
if (can_reboot && (kDown & HidNpadButton_Minus)) {
reboot_to_payload();
}
if (kDown & HidNpadButton_L) { break; } // break in order to return to hbmenu
consoleUpdate(NULL);
}
consoleExit(NULL);
return 0;
}