The entry was hidden on Erista whenever the SD card was not mounted while the menu was built. When shown, it tried atmosphere/reboot_payload.bin first; on OmniNX that is fusee, which is rejected as not hekate, and the rejection unmounted the card, so bootloader/update.bin was never found. Always offer the entry, try the hekate files first, mount the card before each attempt and point to RCM if hekate cannot be loaded.
233 lines
6.4 KiB
C
233 lines
6.4 KiB
C
#include "utils.h"
|
|
#include <string.h>
|
|
#include <utils/types.h>
|
|
#include <mem/heap.h>
|
|
#include <utils/util.h>
|
|
#include <soc/timer.h>
|
|
#include "vector.h"
|
|
#include "../gfx/gfxutils.h"
|
|
#include "../gfx/gfx.h"
|
|
#include "../gfx/menu.h"
|
|
#include "../hid/hid.h"
|
|
#include "../fs/fsutils.h"
|
|
#include "../config.h"
|
|
#include <rtc/max77620-rtc.h>
|
|
#include <storage/sd.h>
|
|
#include <string.h>
|
|
|
|
extern hekate_config h_cfg;
|
|
|
|
extern int launch_payload_ex(char *path, bool force_hekate_menu);
|
|
|
|
// Hekate files first: reboot_payload.bin is often Atmosphere's fusee (no hekate
|
|
// magic, skipped by launch_payload_ex), so it only helps when it is hekate.
|
|
static const char *hekate_payload_paths[] = {
|
|
"sd:/bootloader/update.bin",
|
|
"sd:/bootloader/payloads/hekate.bin",
|
|
"sd:/atmosphere/reboot_payload.bin",
|
|
"sd:/sept/payload.bin",
|
|
};
|
|
|
|
void reboot_to_hekate_menu(void)
|
|
{
|
|
if (h_cfg.t210b01)
|
|
{
|
|
rtc_reboot_reason_t rr = {0};
|
|
rr.dec.reason = REBOOT_REASON_MENU;
|
|
max77620_rtc_set_reboot_reason(&rr);
|
|
power_set_state(POWER_OFF_REBOOT);
|
|
return;
|
|
}
|
|
|
|
// Erista: chainload hekate from the SD card (mounted here, so the entry
|
|
// also works after an action unmounted the card).
|
|
if (!sd_get_card_mounted() && !sd_mount())
|
|
{
|
|
gfx_clearscreen();
|
|
gfx_printf("\n\nSD-Karte konnte nicht gemountet werden.\n\nNutze \"Neustart in RCM-Modus\" und starte\nhekate per Payload-Injector.\n\nDruecke eine Taste um zurueckzukehren");
|
|
hidWait();
|
|
return;
|
|
}
|
|
|
|
for (u32 i = 0; i < sizeof(hekate_payload_paths) / sizeof(hekate_payload_paths[0]); i++)
|
|
{
|
|
// launch_payload_ex() unmounts the card when it rejects a payload that is
|
|
// not hekate, so mount again before checking the next path.
|
|
if (!sd_get_card_mounted() && !sd_mount())
|
|
break;
|
|
if (!FileExists(hekate_payload_paths[i]))
|
|
continue;
|
|
|
|
if (launch_payload_ex((char *)hekate_payload_paths[i], true) != 2)
|
|
return;
|
|
}
|
|
|
|
gfx_clearscreen();
|
|
gfx_printf("\n\nHekate nicht gefunden (bootloader/update.bin).\n\nNutze \"Neustart in RCM-Modus\" und starte\nhekate per Payload-Injector.\n\nDruecke eine Taste um zurueckzukehren");
|
|
hidWait();
|
|
}
|
|
|
|
void inline __attribute__((always_inline)) power_off(){
|
|
power_set_state(POWER_OFF_RESET);
|
|
}
|
|
|
|
void inline __attribute__((always_inline)) reboot_rcm(){
|
|
power_set_state(REBOOT_RCM);
|
|
}
|
|
|
|
void inline __attribute__((always_inline)) reboot_normal(){
|
|
power_set_state((h_cfg.t210b01) ? REBOOT_BYPASS_FUSES : POWER_OFF_REBOOT);
|
|
}
|
|
|
|
void RebootToPayloadOrRcm(){
|
|
if (FileExists("sd:/atmosphere/reboot_payload.bin"))
|
|
launch_payload("sd:/atmosphere/reboot_payload.bin");
|
|
reboot_rcm();
|
|
}
|
|
|
|
char *CpyStr(const char* in){
|
|
int len = strlen(in);
|
|
char *out = malloc(len + 1);
|
|
out[len] = 0;
|
|
memcpy(out, in, len);
|
|
return out;
|
|
}
|
|
|
|
void MaskIn(char *mod, u32 bitstream, char mask){
|
|
u32 len = strlen(mod);
|
|
for (int i = 0; i < len; i++){
|
|
if (!(bitstream & 1))
|
|
*mod = mask;
|
|
|
|
bitstream >>= 1;
|
|
mod++;
|
|
}
|
|
}
|
|
|
|
// non-zero is yes, zero is no
|
|
bool StrEndsWith(char *begin, char *end){
|
|
begin = strrchr(begin, *end);
|
|
if (begin != NULL)
|
|
return !strcmp(begin, end);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void WaitFor(u32 ms){
|
|
u32 a = get_tmr_ms();
|
|
while (a + ms > get_tmr_ms());
|
|
}
|
|
|
|
char *lines[] = {
|
|
"1234567890*", // 0 - 10
|
|
"qwertyuiop~", // 11 - 21
|
|
"asdfghjkl.+", // 22 - 32
|
|
"^zxcvbnm_<>" // 33 - 43
|
|
};
|
|
|
|
char *ShowKeyboard(const char *toEdit, u8 alwaysRet){
|
|
char *ret = CpyStr(toEdit);
|
|
int pos = 0;
|
|
int posOnWord = 0;
|
|
bool shift = 0;
|
|
|
|
gfx_printf("* = exit | ~ = backspace | ^(left) = shift | + = add char\n\n");
|
|
|
|
u32 x, y;
|
|
gfx_con_getpos(&x, &y);
|
|
|
|
while (1){
|
|
gfx_con_setpos(x, y);
|
|
|
|
for (int i = 0; i < strlen(ret); i++){
|
|
(i == posOnWord) ? SETCOLOR(COLOR_WHITE, COLOR_VIOLET) : SETCOLOR(COLOR_WHITE, COLOR_DEFAULT);
|
|
gfx_putc(ret[i]);
|
|
}
|
|
|
|
RESETCOLOR;
|
|
gfx_putc(' ');
|
|
|
|
for (int a = 0; a < 4; a++){
|
|
for (int b = 0; b < 11; b++){
|
|
(pos == ((b % 11) + (a * 11))) ? SETCOLOR(COLOR_DEFAULT, COLOR_WHITE) : SETCOLOR(COLOR_WHITE, COLOR_DEFAULT);
|
|
gfx_con_setpos(x + 16 + (b * 2 * 16), y + a * 16 * 2 + 32);
|
|
if (shift && lines[a][b] >= 'a' && lines[a][b] <= 'z')
|
|
gfx_putc(lines[a][b] & ~BIT(5));
|
|
else
|
|
gfx_putc(lines[a][b]);
|
|
}
|
|
}
|
|
|
|
Input_t *input = hidWait();
|
|
if (input->buttons & (JoyA | JoyLB | JoyRB)){
|
|
if (pos == 42 || input->l){
|
|
if (posOnWord > 0)
|
|
posOnWord--;
|
|
}
|
|
else if (pos == 43 || input->r){
|
|
if (strlen(ret) - 1 > posOnWord)
|
|
posOnWord++;
|
|
}
|
|
else if (pos == 10){
|
|
break;
|
|
}
|
|
else if (pos == 21){
|
|
u32 wordLen = strlen(ret);
|
|
if (!wordLen)
|
|
continue;
|
|
|
|
for (int i = posOnWord; i < wordLen - 1; i++){
|
|
ret[i] = ret[i + 1];
|
|
}
|
|
ret[wordLen - 1] = 0;
|
|
if (posOnWord > wordLen - 2)
|
|
posOnWord--;
|
|
}
|
|
else if (pos == 32){
|
|
u32 wordLen = strlen(ret);
|
|
if (wordLen >= 79)
|
|
continue;
|
|
|
|
char *copy = calloc(wordLen + 2, 1);
|
|
memcpy(copy, ret, wordLen);
|
|
copy[wordLen] = 'a';
|
|
free(ret);
|
|
ret = copy;
|
|
}
|
|
else if (pos == 33){
|
|
shift = !shift;
|
|
}
|
|
else {
|
|
char toPut = lines[pos / 11][pos % 11];
|
|
if (shift)
|
|
toPut &= ~BIT(5);
|
|
ret[posOnWord] = toPut;
|
|
|
|
if (strlen(ret) - 1 > posOnWord)
|
|
posOnWord++;
|
|
}
|
|
}
|
|
int val = (input->up || input->down) ? 11 : 1;
|
|
|
|
// Btn buttons do not work lol
|
|
if (input->buttons & (JoyLLeft | JoyLUp | BtnVolM)){
|
|
if (pos > -1 + val)
|
|
pos -= val;
|
|
}
|
|
if (input->buttons & (JoyLRight | JoyLDown | BtnVolP)){
|
|
if (pos < 44 - val)
|
|
pos += val;
|
|
}
|
|
|
|
if (input->b){
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!strcmp(ret, toEdit) && !alwaysRet){
|
|
free(ret);
|
|
return NULL;
|
|
}
|
|
|
|
return ret;
|
|
} |