Revamp config format, add saving of Rosalina opt.

(menu combo & 3dsx title ID)
This commit is contained in:
TuxSH 2017-06-18 22:31:21 +02:00
parent 2363817265
commit 17828273a5
18 changed files with 188 additions and 65 deletions

View File

@ -5,9 +5,9 @@
#define MAKE_BRANCH(src,dst) (0xEA000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
#define MAKE_BRANCH_LINK(src,dst) (0xEB000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
#define CONFIG(a) (((cfwInfo.config >> (a + 17)) & 1) != 0)
#define MULTICONFIG(a) ((cfwInfo.config >> (a * 2 + 7)) & 3)
#define BOOTCONFIG(a, b) ((cfwInfo.config >> a) & b)
#define CONFIG(a) (((cfwInfo.config >> (a)) & 1) != 0)
#define MULTICONFIG(a) ((cfwInfo.multiConfig >> (2 * (a))) & 3)
#define BOOTCONFIG(a, b) ((cfwInfo.bootConfig >> (a)) & (b))
#define BOOTCFG_NAND BOOTCONFIG(0, 7)
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)

View File

@ -113,7 +113,7 @@ extern void (*initFPU)(void);
extern void (*mcuReboot)(void);
extern void (*coreBarrier)(void);
typedef struct PACKED CfwInfo
typedef struct CfwInfo
{
char magic[4];
@ -124,7 +124,10 @@ typedef struct PACKED CfwInfo
u32 commitHash;
u32 config;
u16 configFormatVersionMajor, configFormatVersionMinor;
u32 config, multiConfig, bootConfig;
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
} CfwInfo;
extern CfwInfo cfwInfo;

View File

@ -278,5 +278,4 @@ void main(FcramLayout *layout, KCoreContext *ctxs)
rosalinaState = 0;
hasStartedRosalinaNetworkFuncsOnce = false;
//wat(0xAA, criticalSectionLock);
}

View File

@ -46,18 +46,35 @@ Result GetSystemInfoHook(s64 *out, s32 type, s32 param)
*out = cfwInfo.commitHash;
break;
case 2:
*out = (cfwInfo.configFormatVersionMajor << 16) | cfwInfo.configFormatVersionMinor;
break;
case 3:
*out = cfwInfo.config;
break;
case 3: // isRelease
case 4:
*out = cfwInfo.multiConfig;
break;
case 5:
*out = cfwInfo.bootConfig;
break;
case 0x100:
*out = (s64)cfwInfo.hbldr3dsxTitleId;
break;
case 0x101:
*out = cfwInfo.rosalinaMenuCombo;
break;
case 0x200: // isRelease
*out = cfwInfo.flags & 1;
break;
case 4: // isN3DS
case 0x201: // isN3DS
*out = (cfwInfo.flags >> 4) & 1;
break;
case 5: // isSafeMode
case 0x202: // isSafeMode
*out = (cfwInfo.flags >> 5) & 1;
break;
case 6: // isSdMode
case 0x203: // isSdMode
*out = (cfwInfo.flags >> 6) & 1;
break;
default:

View File

@ -35,7 +35,7 @@
CfgData configData;
ConfigurationStatus needConfig;
static u32 oldConfig;
static CfgData oldConfig;
bool readConfig(void)
{
@ -46,13 +46,13 @@ bool readConfig(void)
configData.formatVersionMajor != CONFIG_VERSIONMAJOR ||
configData.formatVersionMinor != CONFIG_VERSIONMINOR)
{
configData.config = 0;
memset(&configData, 0, sizeof(CfgData));
ret = false;
}
else ret = true;
oldConfig = configData.config;
oldConfig = configData;
return ret;
}
@ -61,8 +61,8 @@ void writeConfig(bool isConfigOptions)
{
/* If the configuration is different from previously, overwrite it.
Just the no-forcing flag being set is not enough */
if(needConfig != CREATE_CONFIGURATION && ((isConfigOptions && (configData.config & 0xFFFFFF00) == (oldConfig & 0xFFFFFF00)) ||
(!isConfigOptions && (configData.config & 0xBF) == (oldConfig & 0xFF)))) return;
if(needConfig != CREATE_CONFIGURATION && ((isConfigOptions && configData.config == oldConfig.config && configData.multiConfig == oldConfig.multiConfig) ||
(!isConfigOptions && (configData.bootConfig & ~0x40) == oldConfig.bootConfig))) return;
if(needConfig == CREATE_CONFIGURATION)
{
@ -383,14 +383,15 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
else if(singleOptions[singleSelected].enabled) drawCharacter(true, 10 + SPACING_X, singleOptions[singleSelected].posY, COLOR_RED, selected);
}
//Preserve the last-used boot options (first 9 bits)
configData.config &= 0x7F;
//Preserve the last-used boot options
//Parse and write the new configuration
configData.multiConfig = 0;
for(u32 i = 0; i < multiOptionsAmount; i++)
configData.config |= multiOptions[i].enabled << (i * 2 + 7);
configData.multiConfig |= multiOptions[i].enabled << (i * 2);
configData.config = 0;
for(u32 i = 0; i < singleOptionsAmount; i++)
configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 17);
configData.config |= (singleOptions[i].enabled ? 1 : 0) << i;
u32 newPinMode = MULTICONFIG(PIN);

View File

@ -28,13 +28,13 @@
#include "types.h"
#define CONFIG(a) (((configData.config >> (a + 17)) & 1) != 0)
#define MULTICONFIG(a) ((configData.config >> (a * 2 + 7)) & 3)
#define BOOTCONFIG(a, b) ((configData.config >> a) & b)
#define CONFIG(a) (((configData.config >> (a)) & 1) != 0)
#define MULTICONFIG(a) ((configData.multiConfig >> (2 * (a))) & 3)
#define BOOTCONFIG(a, b) ((configData.bootConfig >> (a)) & (b))
#define CONFIG_FILE "config.bin"
#define CONFIG_VERSIONMAJOR 1
#define CONFIG_VERSIONMINOR 13
#define CONFIG_VERSIONMAJOR 2
#define CONFIG_VERSIONMINOR 0
#define BOOTCFG_NAND BOOTCONFIG(0, 7)
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)

View File

@ -279,7 +279,7 @@ boot:
if(!isFirmlaunch)
{
configData.config = (configData.config & 0xFFFFFF80) | ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType;
configData.bootConfig = ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType;
writeConfig(false);
}

View File

@ -122,8 +122,11 @@ u32 installK11Extension(u8 *pos, u32 size, bool isSafeMode, u32 baseK11VA, u32 *
u32 commitHash;
u32 config;
} __attribute__((packed)) info;
u16 configFormatVersionMajor, configFormatVersionMinor;
u32 config, multiConfig, bootConfig;
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
} info;
};
static const u8 patternHook1[] = {0x02, 0xC2, 0xA0, 0xE3, 0xFF}; //MMU setup hook
@ -185,7 +188,13 @@ u32 installK11Extension(u8 *pos, u32 size, bool isSafeMode, u32 baseK11VA, u32 *
struct CfwInfo *info = &p->info;
memcpy(&info->magic, "LUMA", 4);
info->commitHash = COMMIT_HASH;
info->configFormatVersionMajor = configData.formatVersionMajor;
info->configFormatVersionMinor = configData.formatVersionMinor;
info->config = configData.config;
info->multiConfig = configData.multiConfig;
info->bootConfig = configData.bootConfig;
info->hbldr3dsxTitleId = configData.hbldr3dsxTitleId;
info->rosalinaMenuCombo = configData.rosalinaMenuCombo;
info->versionMajor = VERSION_MAJOR;
info->versionMinor = VERSION_MINOR;
info->versionBuild = VERSION_BUILD;

View File

@ -66,7 +66,9 @@ typedef struct __attribute__((packed))
char magic[4];
u16 formatVersionMajor, formatVersionMinor;
u32 config;
u32 config, multiConfig, bootConfig;
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
} CfgData;
typedef struct __attribute__((packed))

View File

@ -6,7 +6,7 @@
#include "ifile.h"
#include "../build/bundled.h"
static u32 config;
static u32 config, multiConfig, bootConfig;
static bool isN3DS, isSafeMode, isSdMode;
static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, s32 offset, const void *replace, u32 repSize, u32 count)
@ -80,13 +80,18 @@ static inline void loadCFWInfo(void)
if(infoLoaded) return;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 2))) svcBreak(USERBREAK_ASSERT);
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 3))) svcBreak(USERBREAK_ASSERT);
config = (u32)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 4))) svcBreak(USERBREAK_ASSERT);
isN3DS = (bool)out;
multiConfig = (u32)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 5))) svcBreak(USERBREAK_ASSERT);
bootConfig = (u32)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x201))) svcBreak(USERBREAK_ASSERT);
isN3DS = (bool)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x202))) svcBreak(USERBREAK_ASSERT);
isSafeMode = (bool)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 6))) svcBreak(USERBREAK_ASSERT);
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x203))) svcBreak(USERBREAK_ASSERT);
isSdMode = (bool)out;
IFile file;

View File

@ -5,9 +5,9 @@
#define MAKE_BRANCH(src,dst) (0xEA000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
#define MAKE_BRANCH_LINK(src,dst) (0xEB000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
#define CONFIG(a) (((config >> (a + 17)) & 1) != 0)
#define MULTICONFIG(a) ((config >> (a * 2 + 7)) & 3)
#define BOOTCONFIG(a, b) ((config >> a) & b)
#define CONFIG(a) (((config >> (a)) & 1) != 0)
#define MULTICONFIG(a) ((multiConfig >> (2 * (a))) & 3)
#define BOOTCONFIG(a, b) ((bootConfig >> (a)) & (b))
#define BOOTCFG_NAND BOOTCONFIG(0, 7)
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)

View File

@ -33,6 +33,7 @@ extern Menu miscellaneousMenu;
void MiscellaneousMenu_SwitchBoot3dsxTargetTitle(void);
void MiscellaneousMenu_ChangeMenuCombo(void);
void MiscellaneousMenu_SaveSettings(void);
void MiscellaneousMenu_InputRedirection(void);
void MiscellaneousMenu_PowerOff(void);
void MiscellaneousMenu_Reboot(void);

View File

@ -78,7 +78,7 @@ GDB_DECLARE_XFER_OSDATA_HANDLER(CfwVersion)
svcGetSystemInfo(&out, 0x10000, 1);
commitHash = (u32)out;
svcGetSystemInfo(&out, 0x10000, 3);
svcGetSystemInfo(&out, 0x10000, 0x200);
isRelease = (bool)out;
if(GET_VERSION_REVISION(version) == 0)

View File

@ -34,6 +34,7 @@
#include "utils.h"
#include "MyThread.h"
#include "menus/process_patches.h"
#include "menus/miscellaneous.h"
// this is called before main
bool isN3DS;
@ -43,9 +44,6 @@ void __appInit()
fsregInit();
fsSysInit();
s64 dummy;
isN3DS = svcGetSystemInfo(&dummy, 0x10001, 0) == 0;
}
// this is called after main exits
@ -74,8 +72,19 @@ void __ctru_exit()
void initSystem()
{
HBLDR_3DSX_TID = HBLDR_DEFAULT_3DSX_TID;
__libc_init_array();
s64 out;
isN3DS = svcGetSystemInfo(&out, 0x10001, 0) == 0;
svcGetSystemInfo(&out, 0x10000, 0x100);
HBLDR_3DSX_TID = out == 0 ? HBLDR_DEFAULT_3DSX_TID : (u64)out;
svcGetSystemInfo(&out, 0x10000, 0x101);
menuCombo = out == 0 ? DEFAULT_MENU_COMBO : (u32)out;
miscellaneousMenu.items[0].title = HBLDR_3DSX_TID == HBLDR_DEFAULT_3DSX_TID ? "Switch the hb. title to the current app." :
"Switch the hb. title to hblauncher_loader";
__sync_init();
__appInit();
}

View File

@ -156,7 +156,7 @@ MyThread *menuCreateThread(void)
}
extern bool isN3DS;
u32 menuCombo = DEFAULT_MENU_COMBO;
u32 menuCombo;
void menuThreadMain(void)
{
@ -224,7 +224,7 @@ static void menuDraw(Menu *menu, u32 selected)
svcGetSystemInfo(&out, 0x10000, 1);
commitHash = (u32)out;
svcGetSystemInfo(&out, 0x10000, 3);
svcGetSystemInfo(&out, 0x10000, 0x200);
isRelease = (bool)out;
if(GET_VERSION_REVISION(version) == 0)

View File

@ -102,7 +102,7 @@ void RosalinaMenu_TakeScreenshot(void)
s64 out;
bool isSdMode;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 6))) svcBreak(USERBREAK_ASSERT);
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x203))) svcBreak(USERBREAK_ASSERT);
isSdMode = (bool)out;
archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;

View File

@ -33,13 +33,15 @@
#include "fmt.h"
#include "utils.h" // for makeARMBranch
#include "minisoc.h"
#include "ifile.h"
Menu miscellaneousMenu = {
"Miscellaneous options menu",
.nbItems = 5,
.nbItems = 6,
{
{ "Switch the hb. title to the current app.", METHOD, .method = &MiscellaneousMenu_SwitchBoot3dsxTargetTitle },
{ "Change the menu combo", METHOD, .method = MiscellaneousMenu_ChangeMenuCombo },
{ "Save settings", METHOD, .method = &MiscellaneousMenu_SaveSettings },
{ "Start InputRedirection", METHOD, .method = &MiscellaneousMenu_InputRedirection },
{ "Power off", METHOD, .method = &MiscellaneousMenu_PowerOff },
{ "Reboot", METHOD, .method = &MiscellaneousMenu_Reboot },
@ -167,6 +169,72 @@ void MiscellaneousMenu_ChangeMenuCombo(void)
while(!(waitInput() & BUTTON_B) && !terminationRequest);
}
void MiscellaneousMenu_SaveSettings(void)
{
Result res;
IFile file;
u64 total;
struct PACKED
{
char magic[4];
u16 formatVersionMajor, formatVersionMinor;
u32 config, multiConfig, bootConfig;
u64 hbldr3dsxTitleId;
u32 rosalinaMenuCombo;
} configData;
u32 formatVersion;
u32 config, multiConfig, bootConfig;
s64 out;
bool isSdMode;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 2))) svcBreak(USERBREAK_ASSERT);
formatVersion = (u32)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 3))) svcBreak(USERBREAK_ASSERT);
config = (u32)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 4))) svcBreak(USERBREAK_ASSERT);
multiConfig = (u32)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 5))) svcBreak(USERBREAK_ASSERT);
bootConfig = (u32)out;
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x203))) svcBreak(USERBREAK_ASSERT);
isSdMode = (bool)out;
memcpy(configData.magic, "CONF", 4);
configData.formatVersionMajor = (u16)(formatVersion >> 16);
configData.formatVersionMinor = (u16)formatVersion;
configData.config = config;
configData.multiConfig = multiConfig;
configData.bootConfig = bootConfig;
configData.hbldr3dsxTitleId = HBLDR_3DSX_TID;
configData.rosalinaMenuCombo = menuCombo;
FS_ArchiveID archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
res = IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, "/luma/config.bin"), FS_OPEN_CREATE | FS_OPEN_WRITE);
if(R_SUCCEEDED(res))
res = IFile_Write(&file, &total, &configData, sizeof(configData), 0);
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Process patches menu");
if(R_SUCCEEDED(res))
Draw_DrawString(10, 30, COLOR_WHITE, "Operation succeeded.");
else
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08x).", res);
Draw_FlushFramebuffer();
Draw_Unlock();
}
while(!(waitInput() & BUTTON_B) && !terminationRequest);
}
void MiscellaneousMenu_InputRedirection(void)
{
static MyThread *inputRedirectionThread = NULL;
@ -207,6 +275,11 @@ void MiscellaneousMenu_InputRedirection(void)
}
}
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
@ -262,40 +335,46 @@ void MiscellaneousMenu_InputRedirection(void)
while(!(waitInput() & BUTTON_B) && !terminationRequest);
}
void MiscellaneousMenu_Reboot()
void MiscellaneousMenu_Reboot(void)
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Miscellaneous options menu");
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to reboot, press B to go back.");
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
u32 pressed = waitInputWithTimeout(1000);
if(pressed & BUTTON_A)
{
svcKernelSetState(7);
}
else if(pressed & BUTTON_B)
{
return;
}
}
while(!terminationRequest);
}
void MiscellaneousMenu_PowerOff() // Soft shutdown.
void MiscellaneousMenu_PowerOff(void) // Soft shutdown.
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Miscellaneous options menu");
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to power off, press B to go back.");
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
u32 pressed = waitInputWithTimeout(1000);
if(pressed & BUTTON_A)
@ -304,9 +383,7 @@ void MiscellaneousMenu_PowerOff() // Soft shutdown.
srvPublishToSubscriber(0x203, 0);
}
else if(pressed & BUTTON_B)
{
return;
}
}
while(!terminationRequest);
}