TwlNmenu boot code (see notes)

I can't actually test this feature right now. melonDS doesn't seem to support jumping from `nand:/tmp/jump.app`, and I can't set up WINE to test with no$gba. I'll set up my other computer later.
This commit is contained in:
rmc 2024-02-05 10:50:06 -05:00
parent 383053e42f
commit 65c8c11906
No known key found for this signature in database
GPG Key ID: 5633EC10309D77D1
4 changed files with 61 additions and 47 deletions

View File

@ -3,9 +3,7 @@
# Project: SLOT-1 Boot Menu
# File: Makefile
#
# This source code is derived from "os_jump" in the TwlSDK
#
# $Date:: 2024-02-01#$
# $Date:: 2024-02-04#$
# $Author: Lillian Skinner (rmc) $
#---------------------------------------------------------------------------
@ -13,14 +11,15 @@
#---------------------------------------------------------------------------
TARGET_PLATFORM := TWL
TWL_ARCHGEN = LIMITED
TARGET_BIN = SLOT1_Booter.srl
SRCS = main.c screen.c font.c
INCDIR = ./include $(TWLSDK_ROOT)/build/libraries/os/common/include
SRCDIR = ./src $(TWLSDK_ROOT)/build/libraries/os/common/src
SRCS = main.c screen.c font.c twlnmenu.c
MAKEROM_ROMROOT = ./data
MAKEROM_ROMFILES = *.srl

View File

@ -1,10 +1,10 @@
/*---------------------------------------------------------------------------*
Project: SLOT-1 Boot Menu
File: screen.h
File: twlnmenu.h
This source code is derived from "os_jump" in the TwlSDK
$Date:: 2024-02-01#$
$Date:: 2024-02-03#$
$Author: Lillian Skinner (rmc) $
*---------------------------------------------------------------------------*/
@ -16,19 +16,16 @@
extern "C" {
#endif
/*===========================================================================*/
#include <nitro/types.h>
/*---------------------------------------------------------------------------*
Function Definitions
*---------------------------------------------------------------------------*/
static BOOL WriteTwlNmenu(void);
static void JumpTwlNmenu(void)
BOOL WriteTwlNmenu(void);
void JumpTwlNmenu(void);
/*===========================================================================*/
#ifdef __cplusplus
} /* extern "C" */
}
#endif
#endif /* SCREEN_H_ */
#endif

View File

@ -4,7 +4,7 @@
This source code is derived from "os_jump" in the TwlSDK
$Date:: 2024-02-01#$
$Date:: 2024-02-03#$
$Author: Lillian Skinner (rmc) $
*---------------------------------------------------------------------------*/
@ -19,7 +19,7 @@
/*---------------------------------------------------------------------------*
Constant Definitions
*---------------------------------------------------------------------------*/
#define VERSION 61
#define VERSION 83
#define KEY_REPEAT_START 25 // Number of frames until key repeat starts
#define KEY_REPEAT_SPAN 10 // Number of frames between key repeats
#define DMA_NO_FS 1
@ -40,6 +40,7 @@ typedef struct KeyInfo
// Key input
static KeyInfo gKey;
BOOL result;
/*---------------------------------------------------------------------------*
Payload stuffs
*---------------------------------------------------------------------------*/
@ -115,7 +116,6 @@ void TwlMain(void)
if (gKey.trg & PAD_BUTTON_A)
{
if (FALSE == OS_JumpToSystemMenu() )
// OSi_CanArbitraryJumpTo(0x00030015484e4241)
{
//Jump failure
PutSubScreen(0, 22, 0xf1, " Failed jump to Launcher ");
@ -125,6 +125,7 @@ void TwlMain(void)
if (gKey.trg & PAD_BUTTON_B)
{
if (FALSE == OS_JumpToWirelessSetting())
// OSi_CanArbitraryJumpTo(0x00030015484e4241)
{
//Jump failure
PutSubScreen(0, 22, 0xf1, " Failed jump to MachineSettings ");
@ -134,11 +135,13 @@ void TwlMain(void)
if (gKey.trg & PAD_BUTTON_X)
{
result = WriteTwlNmenu();
if(result = TRUE )
if (result == TRUE)
{
JumpTwlNmenu();
JumpTwlNmenu();
}
PutSubScreen(0, 22, 0xf1, " Failed to write to TwlNmenu ");
PutSubScreen(0, 22, 0xf1, " Something went very wrong! ");
OS_Terminate();
}
if (gKey.trg & PAD_BUTTON_Y)

View File

@ -1,31 +1,33 @@
/*---------------------------------------------------------------------------*
Project: SLOT-1 Boot Menu
File: main.c
File: twlnmenu.c
This source code is derived from "os_jump" in the TwlSDK
This source code is derived from "NandInitializer" in TwlIPL
$Date:: 2024-02-01#$
$Date:: 2024-02-04#$
$Author: Lillian Skinner (rmc) $
*---------------------------------------------------------------------------*/
#include <twl.h>
#include <twl/os.h>
#include <stdlib.h>
#include "screen.h"
#include "DEMO.h"
#include "twlnmenu.h"
#include "application_jump_private.h"
#define ROUND_UP(value, alignment) \
(((u32)(value) + (alignment-1)) & ~(alignment-1))
static u64 ROM_SRL_TID[1] =
{
0x0003001134544E41
};
static const char ROM_SRL_PATH[1][32] =
{
"rom:/TwlNmenu.srl"
};
#define ROM_SRL_PATH "rom:/TwlNmenu.srl"
static BOOL WriteTwlNmenu(void)
BOOL WriteTwlNmenu(void)
{
FSFile file;
BOOL open_is_ok;
@ -34,21 +36,20 @@ static BOOL WriteTwlNmenu(void)
u32 file_size;
u32 alloc_size;
BOOL result = TRUE;
//PutSubScreen(0, 22, 0xf2, " Copying TwlNmenu... ");
FS_InitFile(&file);
open_is_ok = FS_OpenFile(&file, OS_TMP_APP_PATH);
if (open_is_ok)
{
FS_CloseFile(&file);
OS_Printf("%s is already exist.", OS_TMP_APP_PATH);
return TRUE;
//PutSubScreen(0, 22, 0xf1, " Error: NAND SRL already exists!");
return FALSE;
}
FS_InitFile(&file);
open_is_ok = FS_OpenFile(&file, ROM_SRL_PATH);
if (!open_is_ok)
{
OS_Printf("FS_OpenFile(%s) ERROR!", ROM_SRL_PATH);
//PutSubScreen(0, 22, 0xf1, " Error: can't open TwlNmenu! (1)");
return FALSE;
}
@ -57,47 +58,61 @@ static BOOL WriteTwlNmenu(void)
pTempBuf = OS_Alloc( alloc_size );
SDK_NULL_ASSERT(pTempBuf);
DC_InvalidateRange(pTempBuf, alloc_size);
//PutSubScreen(0, 22, 0xf2, " Writing TwlNmenu to buffer ");
read_is_ok = FS_ReadFile( &file, pTempBuf, (s32)file_size );
if (!read_is_ok)
{
OS_Panic("FS_ReadFile(%s) ERROR!", ROM_SRL_PATH);
//PutSubScreen(0, 22, 0xf1, " Error: can't write TwlNmenu! (1)");
FS_CloseFile(&file);
OS_Free(pTempBuf);
return FALSE;
}
FS_CloseFile(&file);
//PutSubScreen(0, 22, 0xf2, " Creating TwlNmenu in NAND ");
if (!FS_CreateFile(OS_TMP_APP_PATH, FS_PERMIT_R | FS_PERMIT_W))
{
OS_Panic("FS_CreateFile(%s) failed.", OS_TMP_APP_PATH);
//PutSubScreen(0, 22, 0xf1, " Error: can't create NAND file! ");
result = FALSE;
}
else
{
FS_InitFile(&file);
//PutSubScreen(0, 22, 0xf2, " Opening TwlNmenu in NAND");
open_is_ok = FS_OpenFileEx(&file, OS_TMP_APP_PATH, FS_FILEMODE_W);
if (!open_is_ok)
{
OS_Panic("FS_OpenFile(%s) failed.\n", OS_TMP_APP_PATH);
//PutSubScreen(0, 22, 0xf1, " Error: can't open TwlNmenu! (2)");
result = FALSE;
}
else if (FS_WriteFile(&file, pTempBuf, (s32)file_size) == -1)
{
OS_Panic("FS_WritFile() failed.\n");
//PutSubScreen(0, 22, 0xf1, " Error: can't write TwlNmenu! (2)");
result = FALSE;
}
(void)FS_CloseFile(&file);
//PutSubScreen(0, 22, 0xf2, " Closing file TwlNmenu ");
//(void)FS_CloseFile(&file);
// This isn't working no matter what I try. Commenting out for now, hopefully files on NAND don't need any write protection lol
}
//PutSubScreen(0, 22, 0xf2, " Freeing buffer ");
OS_Free(pTempBuf);
//PutSubScreen(0, 22, 0xf2, " Done writing TwlNmenu ");
return result;
}
static void JumpTwlNmenu(void) {
OS_DoApplicationJump( ROM_SRL_TID[0], OS_APP_JUMP_TMP );
PutSubScreen(0, 22, 0xf1, " Failed jump to TwlNmenu ");
void JumpTwlNmenu(void) {
LauncherBootFlags flag;
flag.bootType = LAUNCHER_BOOTTYPE_NAND;
flag.isValid = TRUE;
flag.isLogoSkip = TRUE;
flag.isInitialShortcutSkip = FALSE;
flag.isAppLoadCompleted = FALSE;
flag.isAppRelocate = FALSE;
flag.rsv = 0;
//PutSubScreen(0, 22, 0xf2, " Jumping to TwlNmenu ");
OS_SetLauncherParamAndResetHardware(ROM_SRL_TID[1], &flag);
//PutSubScreen(0, 22, 0xf1, " Failed jump to TwlNmenu ");
OS_Terminate();
}