diff --git a/arm7/src/deviceList.h b/arm7/src/deviceList.h new file mode 100644 index 0000000..3716acf --- /dev/null +++ b/arm7/src/deviceList.h @@ -0,0 +1,38 @@ +#ifndef DEVICE_LIST_H +#define DEVICE_LIST_H +#include + +#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 \ No newline at end of file diff --git a/arm7/src/main.c b/arm7/src/main.c index 4105204..c822a41 100644 --- a/arm7/src/main.c +++ b/arm7/src/main.c @@ -29,6 +29,7 @@ ---------------------------------------------------------------------------------*/ #include "my_sdmmc.h" +#include "deviceList.h" #include #include @@ -96,10 +97,13 @@ void aes(void* in, void* out, void* iv, u32 method) int my_sdmmc_nand_startup(); +#define DEVICE_LIST_SENTINEL *(vu32*)0x02300020 + //--------------------------------------------------------------------------------- int main() //--------------------------------------------------------------------------------- { + DEVICE_LIST_SENTINEL = 0; // clear sound registers dmaFillWords(0, (void*)0x04000400, 0x100); @@ -119,6 +123,12 @@ int main() 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; memset(out, 0, 16); diff --git a/arm9/src/deviceList.c b/arm9/src/deviceList.c new file mode 100644 index 0000000..83c7351 --- /dev/null +++ b/arm9/src/deviceList.c @@ -0,0 +1,27 @@ +#include "deviceList.h" +#include + +#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; +} \ No newline at end of file diff --git a/arm9/src/deviceList.h b/arm9/src/deviceList.h new file mode 100644 index 0000000..378e7c6 --- /dev/null +++ b/arm9/src/deviceList.h @@ -0,0 +1,38 @@ +#ifndef DEVICE_LIST_H +#define DEVICE_LIST_H +#include + +#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 \ No newline at end of file diff --git a/arm9/src/main.c b/arm9/src/main.c index b43ba5b..4b66db7 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -7,6 +7,7 @@ #include "version.h" #include "unlaunch.h" #include "nitrofs.h" +#include "deviceList.h" volatile bool programEnd = false; static volatile bool arm7Exiting = false; @@ -155,7 +156,9 @@ int main(int argc, char **argv) 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)) {