Allow retrieving the filename from the device list

Supports unlaunch/hiya booting
This commit is contained in:
Edoardo Lolletti 2024-04-26 23:20:15 +02:00
parent 3bb7f0f5e2
commit 9c01c0c464
5 changed files with 117 additions and 1 deletions

38
arm7/src/deviceList.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef DEVICE_LIST_H
#define DEVICE_LIST_H
#include <nds/memory.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PACKED Device {
char driveLetter;
struct PACKED {
u8 phisicalDrive : 1; // (0=External SD/MMC Slot, 1=Internal eMMC)
u8 zero1 : 2; // (maybe MSBs of Drive)
u8 deviceType : 2; // (0=Physical, 1=Virtual/File, 2=Virtual/Folder, 3=Reserved)
u8 partition : 1; // (0=1st, 1=2nd)
u8 zero2 : 1; // (maybe MSB of Partition)
u8 encrypt : 1; // (set for eMMC physical devices; not for virtual, not for SD)
};
u8 accessRights; // (bit1=Write, bit2=Read)
u8 zero;
char deviceName[0x10]; // (eg. "nand" or "dataPub") (zeropadded)
char path[0x40]; // (eg. "/" or "nand:/shared1") (zeropadded)
} Device;
typedef struct PACKED DeviceList {
Device devices[11];
u8 zerofilled[0x24];
char appname[0x40];
} DeviceList;
#define __DeviceList (((*(u32*)(((vu8*)__DSiHeader)+0x1D4)) >= 0x02000000) ? ((DeviceList*)((vu8*)(*(u32*)(((vu8*)__DSiHeader)+0x1D4)))) : NULL)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -29,6 +29,7 @@
---------------------------------------------------------------------------------*/ ---------------------------------------------------------------------------------*/
#include "my_sdmmc.h" #include "my_sdmmc.h"
#include "deviceList.h"
#include <nds.h> #include <nds.h>
#include <string.h> #include <string.h>
@ -96,10 +97,13 @@ void aes(void* in, void* out, void* iv, u32 method)
int my_sdmmc_nand_startup(); int my_sdmmc_nand_startup();
#define DEVICE_LIST_SENTINEL *(vu32*)0x02300020
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
int main() int main()
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
{ {
DEVICE_LIST_SENTINEL = 0;
// clear sound registers // clear sound registers
dmaFillWords(0, (void*)0x04000400, 0x100); dmaFillWords(0, (void*)0x04000400, 0x100);
@ -119,6 +123,12 @@ int main()
if (isDSiMode() /*|| ((REG_SCFG_EXT & BIT(17)) && (REG_SCFG_EXT & BIT(18)))*/) if (isDSiMode() /*|| ((REG_SCFG_EXT & BIT(17)) && (REG_SCFG_EXT & BIT(18)))*/)
{ {
if(__DeviceList)
memmove((vu8*)0x02300024, __DeviceList, sizeof(DeviceList));
else
memset((vu8*)0x02300024, 0, sizeof(DeviceList));
DEVICE_LIST_SENTINEL = 1;
vu8 *out=(vu8*)0x02300000; vu8 *out=(vu8*)0x02300000;
memset(out, 0, 16); memset(out, 0, 16);

27
arm9/src/deviceList.c Normal file
View File

@ -0,0 +1,27 @@
#include "deviceList.h"
#include <string.h>
#define DEVICE_LIST_SENTINEL *(vu32*)0x02300020
#define DEVICE_LIST_ADDR (vu8*)0x02300024
DeviceList* getDeviceList(void)
{
static bool gotDeviceList = false;
if(!gotDeviceList) {
while(!DEVICE_LIST_SENTINEL);
DeviceList* list = (DeviceList*)DEVICE_LIST_ADDR;
bool isSd = strncmp(list->appname, "sdmc", 4) == 0;
if(!isSd && strncmp(list->appname, "nand", 4) != 0)
return 0;
if(isSd)
{
//transform sdmc:/ to sd:/
memmove(list->appname + 2, list->appname + 4, sizeof(list->appname) - 4);
list->appname[sizeof(list->appname) - 1] = '\0';
list->appname[sizeof(list->appname) - 2] = '\0';
}
gotDeviceList = true;
}
return (DeviceList*)DEVICE_LIST_ADDR;
}

38
arm9/src/deviceList.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef DEVICE_LIST_H
#define DEVICE_LIST_H
#include <nds/memory.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PACKED Device {
char driveLetter;
struct PACKED {
u8 phisicalDrive : 1; // (0=External SD/MMC Slot, 1=Internal eMMC)
u8 zero1 : 2; // (maybe MSBs of Drive)
u8 deviceType : 2; // (0=Physical, 1=Virtual/File, 2=Virtual/Folder, 3=Reserved)
u8 partition : 1; // (0=1st, 1=2nd)
u8 zero2 : 1; // (maybe MSB of Partition)
u8 encrypt : 1; // (set for eMMC physical devices; not for virtual, not for SD)
};
u8 accessRights; // (bit1=Write, bit2=Read)
u8 zero;
char deviceName[0x10]; // (eg. "nand" or "dataPub") (zeropadded)
char path[0x40]; // (eg. "/" or "nand:/shared1") (zeropadded)
} Device;
typedef struct PACKED DeviceList {
Device devices[11];
u8 zerofilled[0x24];
char appname[0x40];
} DeviceList;
DeviceList* getDeviceList(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -7,6 +7,7 @@
#include "version.h" #include "version.h"
#include "unlaunch.h" #include "unlaunch.h"
#include "nitrofs.h" #include "nitrofs.h"
#include "deviceList.h"
volatile bool programEnd = false; volatile bool programEnd = false;
static volatile bool arm7Exiting = false; static volatile bool arm7Exiting = false;
@ -155,7 +156,9 @@ int main(int argc, char **argv)
return 0; return 0;
} }
const char* installerPath = (argc > 0) ? argv[0] : "sd:/ntrboot.nds"; DeviceList* deviceList = getDeviceList();
const char* installerPath = (argc > 0) ? argv[0] : (deviceList ? deviceList->appname : "sd:/ntrboot.nds");
if (!nitroFSInit(installerPath)) if (!nitroFSInit(installerPath))
{ {