Cleanup, fix latest ctrulib, removed reboot after config (needs testing!), fixed L+SELECT payload

This commit is contained in:
Aurora 2016-05-09 03:41:00 +02:00
parent c3ad7eda08
commit b90b138766
17 changed files with 89 additions and 74 deletions

View File

@ -82,23 +82,23 @@ Result FSLDR_SetPriority(u32 priority)
return cmdbuf[1];
}
Result FSLDR_OpenFileDirectly(Handle* out, FS_Archive archive, FS_Path path, u32 openFlags, u32 attributes)
Result FSLDR_OpenFileDirectly(Handle* out, FS_ArchiveID archiveId, FS_Path archivePath, FS_Path filePath, u32 openFlags, u32 attributes)
{
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x803,8,4); // 0x8030204
cmdbuf[1] = 0;
cmdbuf[2] = archive.id;
cmdbuf[3] = archive.lowPath.type;
cmdbuf[4] = archive.lowPath.size;
cmdbuf[5] = path.type;
cmdbuf[6] = path.size;
cmdbuf[2] = archiveId;
cmdbuf[3] = archivePath.type;
cmdbuf[4] = archivePath.size;
cmdbuf[5] = filePath.type;
cmdbuf[6] = filePath.size;
cmdbuf[7] = openFlags;
cmdbuf[8] = attributes;
cmdbuf[9] = IPC_Desc_StaticBuffer(archive.lowPath.size, 2);
cmdbuf[10] = (u32) archive.lowPath.data;
cmdbuf[11] = IPC_Desc_StaticBuffer(path.size, 0);
cmdbuf[12] = (u32) path.data;
cmdbuf[9] = IPC_Desc_StaticBuffer(archivePath.size, 2);
cmdbuf[10] = (u32)archivePath.data;
cmdbuf[11] = IPC_Desc_StaticBuffer(filePath.size, 0);
cmdbuf[12] = (u32)filePath.data;
Result ret = 0;
if(R_FAILED(ret = svcSendSyncRequest(fsldrHandle))) return ret;

View File

@ -6,4 +6,4 @@ Result fsldrInit(void);
void fsldrExit(void);
Result FSLDR_InitializeWithSdkVersion(Handle session, u32 version);
Result FSLDR_SetPriority(u32 priority);
Result FSLDR_OpenFileDirectly(Handle* out, FS_Archive archive, FS_Path path, u32 openFlags, u32 attributes);
Result FSLDR_OpenFileDirectly(Handle* out, FS_ArchiveID archiveId, FS_Path archivePath, FS_Path filePath, u32 openFlags, u32 attributes);

View File

@ -2,11 +2,11 @@
#include "ifile.h"
#include "fsldr.h"
Result IFile_Open(IFile *file, FS_Archive archive, FS_Path path, u32 flags)
Result IFile_Open(IFile *file, FS_ArchiveID archiveId, FS_Path archivePath, FS_Path filePath, u32 flags)
{
Result res;
res = FSLDR_OpenFileDirectly(&file->handle, archive, path, flags, 0);
res = FSLDR_OpenFileDirectly(&file->handle, archiveId, archivePath, filePath, flags, 0);
file->pos = 0;
file->size = 0;
return res;

View File

@ -9,7 +9,7 @@ typedef struct
u64 size;
} IFile;
Result IFile_Open(IFile *file, FS_Archive archive, FS_Path path, u32 flags);
Result IFile_Open(IFile *file, FS_ArchiveID archiveId, FS_Path archivePath, FS_Path filePath, u32 flags);
Result IFile_Close(IFile *file);
Result IFile_GetSize(IFile *file, u64 *size);
Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len);

View File

@ -109,21 +109,20 @@ static Result allocate_shared_mem(prog_addrs_t *shared, prog_addrs_t *vaddr, int
static Result load_code(u64 progid, prog_addrs_t *shared, u64 prog_handle, int is_compressed)
{
IFile file;
FS_Archive archive;
FS_Path path;
FS_Path archivePath;
FS_Path filePath;
Result res;
u64 size;
u64 total;
archive.id = ARCHIVE_SAVEDATA_AND_CONTENT2;
archive.lowPath.type = PATH_BINARY;
archive.lowPath.data = &prog_handle;
archive.lowPath.size = 8;
//archive.handle = prog_handle; // not needed
path.type = PATH_BINARY;
path.data = CODE_PATH;
path.size = sizeof(CODE_PATH);
if (R_FAILED(IFile_Open(&file, archive, path, FS_OPEN_READ)))
archivePath.type = PATH_BINARY;
archivePath.data = &prog_handle;
archivePath.size = 8;
filePath.type = PATH_BINARY;
filePath.data = CODE_PATH;
filePath.size = sizeof(CODE_PATH);
if (R_FAILED(IFile_Open(&file, ARCHIVE_SAVEDATA_AND_CONTENT2, archivePath, filePath, FS_OPEN_READ)))
{
svcBreak(USERBREAK_ASSERT);
}

View File

@ -82,21 +82,12 @@ static inline size_t strnlen(const char *string, size_t maxlen)
return size;
}
static int fileOpen(IFile *file, FS_ArchiveID id, const char *path, int flags)
static int fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int flags)
{
FS_Archive archive;
FS_Path ppath;
FS_Path filePath = {PATH_ASCII, strnlen(path, PATH_MAX) + 1, path},
archivePath = {PATH_EMPTY, 1, (u8 *)""};
size_t len = strnlen(path, PATH_MAX);
archive.id = id;
archive.lowPath.type = PATH_EMPTY;
archive.lowPath.size = 1;
archive.lowPath.data = (u8 *)"";
ppath.type = PATH_ASCII;
ppath.data = path;
ppath.size = len + 1;
return IFile_Open(file, archive, ppath, flags);
return IFile_Open(file, archiveId, archivePath, filePath, flags);
}
static u32 secureInfoExists(void)

View File

@ -7,14 +7,15 @@
#include "screeninit.h"
#include "draw.h"
#include "fs.h"
#include "i2c.h"
#include "buttons.h"
void configureCFW(const char *configPath)
{
initScreens();
u32 needToDeinit = initScreens();
drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE);
drawString("Press A to select, START to save and reboot", 10, 30, COLOR_WHITE);
drawString("Press A to select, START to save", 10, 30, COLOR_WHITE);
const char *multiOptionsText[] = { "Screen-init brightness: 4( ) 3( ) 2( ) 1( )",
"New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )" };
@ -174,8 +175,15 @@ void configureCFW(const char *configPath)
fileWrite(&config, configPath, 4);
//Zero the last booted FIRM flag
CFG_BOOTENV = 0;
//Wait for the pressed buttons to change
while(HID_PAD == BUTTON_START);
mcuReboot();
if(needToDeinit)
{
//Turn off backlight
i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x16);
deinitScreens();
}
delay(0x1400000);
}

View File

@ -6,8 +6,6 @@
#include "types.h"
#define CFG_BOOTENV (*(vu32 *)0x10010000)
#define CONFIG(a) ((config >> (a + 16)) & 1)
#define MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3)
#define BOOTCONFIG(a, b) ((config >> a) & b)

View File

@ -6,6 +6,7 @@
#include "draw.h"
#include "screeninit.h"
#include "utils.h"
#include "fs.h"
#include "memory.h"
#include "font.h"
@ -39,10 +40,7 @@ void loadSplash(void)
//Don't delay boot if no splash image is on the SD
if(fileRead(fb->top_left, "/luma/splash.bin") +
fileRead(fb->bottom, "/luma/splashbottom.bin"))
{
u64 i = 0x1400000;
while(i--) __asm("mov r0, r0"); //Less Ghetto sleep func
}
delay(0x1400000);
}
void drawCharacter(char character, int posX, int posY, u32 color)

View File

@ -67,8 +67,16 @@ void main(void)
//If no configuration file exists or SELECT is held, load configuration menu
if(needConfig == 2 || (pressed & BUTTON_SELECT))
{
configureCFW(configPath);
//Zero the last booted FIRM flag
CFG_BOOTENV = 0;
//Update pressed buttons
pressed = HID_PAD;
}
bootType = 0;
firmType = 0;
@ -201,7 +209,7 @@ void main(void)
break;
}
launchFirm(bootType, (firmType == 0) ? 1 : 0);
launchFirm(!firmType, bootType);
}
static inline void loadFirm(u32 firmType, u32 externalFirm)
@ -344,14 +352,13 @@ static inline void patchReboots(u8 *arm9Section, u8 *proc9Offset)
static inline void copySection0AndInjectLoader(void)
{
u32 loaderSize;
u8 *arm11Section0 = (u8 *)firm + section[0].offset;
u32 injectorOffset = (u8 *)getLoader((u8 *)firm + section[0].offset, section[0].size, &loaderSize) - arm11Section0;
u32 remaining = section[0].size - (injectorOffset + loaderSize);
memcpy(section[0].address, arm11Section0, injectorOffset);
memcpy(section[0].address + injectorOffset, injector, injector_size);
memcpy(section[0].address + injectorOffset + injector_size, arm11Section0 + section[0].size - remaining, remaining);
u32 loaderSize;
u32 loaderOffset = getLoader(arm11Section0, &loaderSize);
memcpy(section[0].address, arm11Section0, loaderOffset);
memcpy(section[0].address + loaderOffset, injector, injector_size);
memcpy(section[0].address + loaderOffset + injector_size, arm11Section0 + loaderOffset + loaderSize, section[0].size - (loaderOffset + loaderSize));
}
static inline void patchLegacyFirm(u32 firmType)
@ -433,7 +440,7 @@ static void patchFirmWrites(u8 *arm9Section, u32 mode)
}
}
static inline void launchFirm(u32 bootType, u32 firstSectionToCopy)
static inline void launchFirm(u32 firstSectionToCopy, u32 bootType)
{
//Copy FIRM sections to respective memory locations
for(u32 i = firstSectionToCopy; i < 4 && section[i].size; i++)

View File

@ -8,6 +8,7 @@
#define PDN_MPCORE_CFG (*(vu32 *)0x10140FFC)
#define PDN_SPI_CNT (*(vu32 *)0x101401C0)
#define CFG_BOOTENV (*(vu32 *)0x10010000)
//FIRM Header layout
typedef struct firmSectionHeader {
@ -44,4 +45,4 @@ static inline void copySection0AndInjectLoader(void);
static inline void patchLegacyFirm(u32 firmType);
static inline void patchSafeFirm(void);
static void patchFirmWrites(u8 *arm9Section, u32 mode);
static inline void launchFirm(u32 bootType, u32 firstSectionToCopy);
static inline void launchFirm(u32 firstSectionToCopy, u32 bootType);

View File

@ -72,18 +72,19 @@ u16 *getFirmWriteSafe(u8 *pos, u32 size)
return (u16 *)memsearch(pos, pattern, size, 4);
}
void *getLoader(u8 *pos, u32 size, u32 *loaderSize)
u32 getLoader(u8 *pos, u32 *loaderSize)
{
u8 *off = pos;
do
u32 size;
while(1)
{
if(*(u32 *)(off + 0x200) == 0x64616F6C) break; //"load"
off += *(u32 *)(off + 0x104) * 0x200; //size of the CXI
size = *(u32 *)(off + 0x104) * 0x200;
if(*(u32 *)(off + 0x200) == 0x64616F6C) break;
off += size;
}
while(off < pos + size);
if(off >= pos + size) return NULL;
*loaderSize = *(u32 *)(off + 0x104) * 0x200;
return off;
*loaderSize = size;
return (u32)(off - pos);
}

View File

@ -24,4 +24,4 @@ void *getReboot(u8 *pos, u32 size);
u32 getfOpen(u8 *proc9Offset, void *rebootOffset);
u16 *getFirmWrite(u8 *pos, u32 size);
u16 *getFirmWriteSafe(u8 *pos, u32 size);
void *getLoader(u8 *pos, u32 size, u32 *loaderSize);
u32 getLoader(u8 *pos, u32 *loaderSize);

View File

@ -40,12 +40,16 @@ void deinitScreens(void)
{
*arm11Entry = (u32)ARM11;
while(*arm11Entry);
PDN_GPU_CNT = 1;
}
}
void initScreens(void)
u32 initScreens(void)
{
if(PDN_GPU_CNT == 1)
u32 needToInit = PDN_GPU_CNT == 1;
if(needToInit)
{
u32 *const screenInitAddress = (u32 *)0x24FFFC00;
@ -62,4 +66,6 @@ void initScreens(void)
}
clearScreens();
return needToInit;
}

View File

@ -9,7 +9,7 @@
#include "types.h"
#define PDN_GPU_CNT (*(vu8 *)0x10141200)
#define PDN_GPU_CNT (*(vu8 *)0x10141200)
void deinitScreens(void);
void initScreens(void);
u32 initScreens(void);

View File

@ -33,6 +33,11 @@ u32 waitInput(void)
return key;
}
void delay(u64 length)
{
while(length--) __asm("mov r0, r0");
}
void mcuReboot(void)
{
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);

View File

@ -7,4 +7,5 @@
#include "types.h"
u32 waitInput(void);
void delay(u64 length);
void mcuReboot(void);