Make loader recognize SD/CTRNAND modes and only look in the appropriate one

This commit is contained in:
Aurora Wright 2017-05-20 05:09:48 +02:00
parent 55b2db4a8d
commit 98f650a5de
8 changed files with 20 additions and 24 deletions

View File

@ -40,19 +40,19 @@ static Result fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, in
return IFile_Open(file, archiveId, archivePath, filePath, flags); return IFile_Open(file, archiveId, archivePath, filePath, flags);
} }
static u32 dirCheck(FS_ArchiveID archiveId, const char *path) static bool dirCheck(FS_ArchiveID archiveId, const char *path)
{ {
u32 ret; bool ret;
Handle handle; Handle handle;
FS_Archive archive; FS_Archive archive;
FS_Path dirPath = {PATH_ASCII, strnlen(path, 255) + 1, path}, FS_Path dirPath = {PATH_ASCII, strnlen(path, 255) + 1, path},
archivePath = {PATH_EMPTY, 1, (u8 *)""}; archivePath = {PATH_EMPTY, 1, (u8 *)""};
if(R_FAILED(FSLDR_OpenArchive(&archive, archiveId, archivePath))) ret = 1; if(R_FAILED(FSLDR_OpenArchive(&archive, archiveId, archivePath))) ret = false;
else else
{ {
ret = R_SUCCEEDED(FSLDR_OpenDirectory(&handle, archive, dirPath)) ? 0 : 2; ret = R_SUCCEEDED(FSLDR_OpenDirectory(&handle, archive, dirPath));
if(!ret) FSDIR_Close(handle); if(ret) FSDIR_Close(handle);
FSLDR_CloseArchive(archive); FSLDR_CloseArchive(archive);
} }
@ -61,21 +61,16 @@ static u32 dirCheck(FS_ArchiveID archiveId, const char *path)
static bool openLumaFile(IFile *file, const char *path) static bool openLumaFile(IFile *file, const char *path)
{ {
Result res = fileOpen(file, ARCHIVE_SDMC, path, FS_OPEN_READ); FS_ArchiveID archiveId = ISSDMODE ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
if(R_SUCCEEDED(res)) return true; return R_SUCCEEDED(fileOpen(file, archiveId, path, FS_OPEN_READ));
//Returned if SD is not mounted
return (u32)res == 0xC88044AB && R_SUCCEEDED(fileOpen(file, ARCHIVE_NAND_RW, path, FS_OPEN_READ));
} }
static u32 checkLumaDir(const char *path) static u32 checkLumaDir(const char *path)
{ {
u32 res = dirCheck(ARCHIVE_SDMC, path); FS_ArchiveID archiveId = ISSDMODE ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
if(!res) return ARCHIVE_SDMC; return dirCheck(archiveId, path) ? archiveId : 0;
return res == 1 && !dirCheck(ARCHIVE_NAND_RW, path) ? ARCHIVE_NAND_RW : 0;
} }
static inline void loadCFWInfo(void) static inline void loadCFWInfo(void)

View File

@ -39,7 +39,8 @@ enum singleOptions
enum flags enum flags
{ {
ISN3DS = 0, ISN3DS = 0,
ISSAFEMODE ISSAFEMODE,
ISSDMODE
}; };
void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress); void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress);

View File

@ -72,7 +72,7 @@ void writeConfig(bool isPayloadLaunch)
error("Error writing the configuration file"); error("Error writing the configuration file");
} }
void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) void configMenu(bool oldPinStatus, u32 oldPinMode)
{ {
const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )", const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )",
"Screen brightness: 4( ) 3( ) 2( ) 1( )", "Screen brightness: 4( ) 3( ) 2( ) 1( )",

View File

@ -67,4 +67,4 @@ typedef enum ConfigurationStatus
bool readConfig(void); bool readConfig(void);
void writeConfig(bool isPayloadLaunch); void writeConfig(bool isPayloadLaunch);
void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode); void configMenu(bool oldPinStatus, u32 oldPinMode);

View File

@ -219,7 +219,7 @@ void loadPayload(u32 pressed, const char *payloadPath)
writeConfig(true); writeConfig(true);
if(memcmp(launchedPath, u"nand", 8) == 0) if(!isSdMode)
sprintf(absPath, "nand:/rw/luma/%s", path); sprintf(absPath, "nand:/rw/luma/%s", path);
else else
sprintf(absPath, "sdmc:/luma/%s", path); sprintf(absPath, "sdmc:/luma/%s", path);

View File

@ -38,7 +38,8 @@ extern CfgData configData;
extern ConfigurationStatus needConfig; extern ConfigurationStatus needConfig;
extern FirmwareSource firmSource; extern FirmwareSource firmSource;
bool isFirmlaunch; bool isFirmlaunch,
isSdMode;
u16 launchedPath[41]; u16 launchedPath[41];
void main(int argc, char **argv) void main(int argc, char **argv)
@ -85,9 +86,6 @@ void main(int argc, char **argv)
break; break;
} }
//Mount SD or CTRNAND
bool isSdMode;
if(memcmp(launchedPath, u"sdmc", 8) == 0) if(memcmp(launchedPath, u"sdmc", 8) == 0)
{ {
if(!mountFs(true, false)) error("Failed to mount SD."); if(!mountFs(true, false)) error("Failed to mount SD.");
@ -182,7 +180,7 @@ void main(int argc, char **argv)
if(shouldLoadConfigMenu) if(shouldLoadConfigMenu)
{ {
configMenu(isSdMode, pinExists, pinMode); configMenu(pinExists, pinMode);
//Update pressed buttons //Update pressed buttons
pressed = HID_PAD; pressed = HID_PAD;

View File

@ -313,6 +313,7 @@ u32 implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u32 baseK11VA, u8 **free
if(isRelease) info->flags = 1; if(isRelease) info->flags = 1;
if(ISN3DS) info->flags |= 1 << 4; if(ISN3DS) info->flags |= 1 << 4;
if(isSafeMode) info->flags |= 1 << 5; if(isSafeMode) info->flags |= 1 << 5;
if(isSdMode) info->flags |= 1 << 6;
arm11SvcTable[0x2E] = baseK11VA + *freeK11Space - pos; //Stubbed svc arm11SvcTable[0x2E] = baseK11VA + *freeK11Space - pos; //Stubbed svc
*freeK11Space += svcGetCFWInfo_bin_size; *freeK11Space += svcGetCFWInfo_bin_size;

View File

@ -110,7 +110,8 @@ typedef enum FirmwareType
NATIVE_FIRM1X2X NATIVE_FIRM1X2X
} FirmwareType; } FirmwareType;
extern bool isFirmlaunch; extern bool isFirmlaunch,
isSdMode;
extern u16 launchedFirmTidLow[8]; extern u16 launchedFirmTidLow[8];
extern u16 launchedPath[41]; extern u16 launchedPath[41];