2019-01-24 17:05:06 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <switch.h>
|
2021-06-13 22:55:46 +01:00
|
|
|
#include "ams_bpc.h"
|
2019-01-24 17:05:06 +00:00
|
|
|
|
2020-12-14 18:01:03 +00:00
|
|
|
#define IRAM_PAYLOAD_MAX_SIZE 0x24000
|
2021-06-13 22:55:46 +01:00
|
|
|
static u8 g_reboot_payload[IRAM_PAYLOAD_MAX_SIZE];
|
2019-01-24 17:05:06 +00:00
|
|
|
|
2021-06-13 22:55:46 +01:00
|
|
|
void userAppExit(void)
|
|
|
|
{
|
|
|
|
amsBpcExit();
|
|
|
|
setsysExit();
|
|
|
|
spsmExit();
|
2019-01-24 17:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void reboot_to_payload(void) {
|
2021-06-13 22:55:46 +01:00
|
|
|
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);
|
2019-01-24 17:05:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
consoleInit(NULL);
|
2020-11-14 19:11:41 +00:00
|
|
|
|
2020-12-01 23:51:02 +00:00
|
|
|
padConfigureInput(8, HidNpadStyleSet_NpadStandard);
|
|
|
|
|
|
|
|
PadState pad;
|
|
|
|
padInitializeAny(&pad);
|
|
|
|
|
2021-06-13 22:55:46 +01:00
|
|
|
Result rc = 0;
|
2019-01-24 17:05:06 +00:00
|
|
|
bool can_reboot = true;
|
2021-06-13 22:55:46 +01:00
|
|
|
|
|
|
|
if (R_FAILED(rc = setsysInitialize())) {
|
|
|
|
printf("Failed to initialize set:sys: 0x%x\n", rc);
|
2019-01-24 17:05:06 +00:00
|
|
|
can_reboot = false;
|
2021-06-13 22:55:46 +01:00
|
|
|
}
|
|
|
|
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) {
|
2019-01-24 17:05:06 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2020-11-14 19:11:41 +00:00
|
|
|
|
2019-01-24 17:05:06 +00:00
|
|
|
printf("Press [L] to exit\n");
|
|
|
|
|
|
|
|
// Main loop
|
|
|
|
while(appletMainLoop())
|
|
|
|
{
|
2020-12-01 23:51:02 +00:00
|
|
|
padUpdate(&pad);
|
|
|
|
u64 kDown = padGetButtonsDown(&pad);
|
2019-01-24 17:05:06 +00:00
|
|
|
|
2020-12-01 23:51:02 +00:00
|
|
|
if (can_reboot && (kDown & HidNpadButton_Minus)) {
|
2019-01-24 17:05:06 +00:00
|
|
|
reboot_to_payload();
|
|
|
|
}
|
2020-12-01 23:51:02 +00:00
|
|
|
if (kDown & HidNpadButton_L) { break; } // break in order to return to hbmenu
|
2019-01-24 17:05:06 +00:00
|
|
|
|
2019-01-24 17:11:46 +00:00
|
|
|
consoleUpdate(NULL);
|
2019-01-24 17:05:06 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 17:10:51 +00:00
|
|
|
consoleExit(NULL);
|
2019-01-24 17:05:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|