Skip to content

Commit

Permalink
Add og R4 SRL to Stage2 files ...
Browse files Browse the repository at this point in the history
* Original R4 rom now available in default pack of NDS files available
to Stage2 filebrowser.
* R4i SDHC varient's bootloader rom now available to stage2 filebrowser.
* Order of header/chip ID commands changed in main read_card code to
match order used in bootloader. Reads header before chip ID like
bootloader does. This triggers some carts to use DS/DS Lite rom insteat
of white listed spoof game instead. The main consequence is that this
makes DSTwo a bit more functional. Cart loader now actually boots the
DSTwo correctly provided you wait till NTR Launcher is booted before
inserting it. (or eject/reinsert while in stage 2 menu).
  • Loading branch information
ApacheThunder committed Aug 16, 2024
1 parent 5a337c0 commit 3c362f5
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 60 deletions.
2 changes: 1 addition & 1 deletion BootLoader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SPECS := specs
#---------------------------------------------------------------------------------
ARCH := -mthumb-interwork -march=armv4t -mtune=arm7tdmi

CFLAGS := -g -Wall -Oz \
CFLAGS := -g -Wall -O2 \
-fomit-frame-pointer \
-ffast-math \
-Wall -Wextra -Werror \
Expand Down
3 changes: 2 additions & 1 deletion BootLoader/source/read_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ u32 cardInit (sNDSHeaderExt* ndsHeader, u32* chipID) {

// 1st Get ROM Chip ID
cardParamCommand (CARD_CMD_HEADER_CHIPID, 0, (ndsHeader->cardControl13 & (CARD_WR|CARD_nRESET|CARD_CLK_SLOW)) | CARD_ACTIVATE | CARD_BLK_SIZE(7), chipID, sizeof(u32));

while (REG_ROMCTRL & CARD_BUSY);

// Adjust card transfer method depending on the most significant bit of the chip ID
normalChip = ((*chipID) & 0x80000000) != 0; // ROM chip ID MSB
if (!normalChip)portFlagsKey1 |= CARD_SEC_LARGE;
Expand Down
Binary file added CartFiles/NTR_Launcher/R4DS.nds
Binary file not shown.
File renamed without changes.
16 changes: 9 additions & 7 deletions arm9/common/read_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,21 @@ int cardInit (sNDSHeaderExt* ndsHeader) {

toncset(headerData, 0, 0x1000);

iCardId=cardReadID(CARD_CLK_SLOW);
while(REG_ROMCTRL & CARD_BUSY);

normalChip = (iCardId & BIT(31)) != 0; // ROM chip ID MSB
nandChip = (iCardId & BIT(27)) != 0; // Card has a NAND chip

// Read the header
cardParamCommand (CARD_CMD_HEADER_READ, 0,
CARD_ACTIVATE | CARD_nRESET | CARD_CLK_SLOW | CARD_BLK_SIZE(1) | CARD_DELAY1(0x1FFF) | CARD_DELAY2(0x3F),
(void*)headerData, 0x200/sizeof(u32));

while(REG_ROMCTRL&CARD_BUSY);

tonccpy(ndsHeader, headerData, 0x200);

iCardId=cardReadID(CARD_CLK_SLOW);
while(REG_ROMCTRL & CARD_BUSY);

normalChip = (iCardId & BIT(31)) != 0; // ROM chip ID MSB
nandChip = (iCardId & BIT(27)) != 0; // Card has a NAND chip


if ((ndsHeader->unitCode != 0) || (ndsHeader->dsi_flags != 0)) {
// Extended header found
if(normalChip) {
Expand Down
14 changes: 8 additions & 6 deletions arm9/hbmenu/hbmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,27 @@ static char gameTitle[13] = {0};
static u8* fileBuffer;


static const char* NitroSourceFileList[7] = {
static const char* NitroSourceFileList[9] = {
"nitro:/NTR_Launcher/Acekard2i.nds",
"nitro:/NTR_Launcher/ActionReplayDS.nds",
"nitro:/NTR_Launcher/DSTwo.nds",
"nitro:/NTR_Launcher/EZFlashV.nds",
"nitro:/NTR_Launcher/R4DS_Ultra.nds",
"nitro:/NTR_Launcher/R4i_SDHC_AVRJ.nds",
"nitro:/NTR_Launcher/R4iGold_Launcher.nds",
"nitro:/NTR_Launcher/R4iSDHC_Demon.nds",
"nitro:/NTR_Launcher/R4DS_Ultra.nds",
"nitro:/NTR_Launcher/TTDS.nds"
};

static const char* NitroDestFileList[7] = {
static const char* NitroDestFileList[9] = {
"sd:/NTR_Launcher/Acekard2i.nds",
"sd:/NTR_Launcher/ActionReplayDS.nds",
"sd:/NTR_Launcher/DSTwo.nds",
"sd:/NTR_Launcher/EZFlashV.nds",
"sd:/NTR_Launcher/R4DS_Ultra.nds",
"sd:/NTR_Launcher/R4i_SDHC_AVRJ.nds",
"sd:/NTR_Launcher/R4iGold_Launcher.nds",
"sd:/NTR_Launcher/R4iSDHC_Demon.nds",
"sd:/NTR_Launcher/R4DS_Ultra.nds",
"sd:/NTR_Launcher/TTDS.nds"
};

Expand Down Expand Up @@ -119,9 +121,9 @@ static int stop(void) {
}

static void CheckFolder() {
if (sizeof(NitroSourceFileList) != sizeof(NitroDestFileList))return;
// if (sizeof(NitroSourceFileList) != sizeof(NitroDestFileList))return;
bool copyNeeded = false;
int listSize = 7;
int listSize = 8;
for (int i = 0; i < listSize; i++) {
if (access(NitroDestFileList[i], F_OK) != 0) {
copyNeeded = true;
Expand Down
86 changes: 41 additions & 45 deletions ndsbootloader/source/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,58 @@ typedef struct sLauncherSettings {
#define FW_READ 0x03

void boot_readFirmware (uint32 address, uint8 * buffer, uint32 size) {
uint32 index;

// Read command
while (REG_SPICNT & SPI_BUSY);
REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM;
REG_SPIDATA = FW_READ;
while (REG_SPICNT & SPI_BUSY);

// Set the address
REG_SPIDATA = (address>>16) & 0xFF;
while (REG_SPICNT & SPI_BUSY);
REG_SPIDATA = (address>>8) & 0xFF;
while (REG_SPICNT & SPI_BUSY);
REG_SPIDATA = (address) & 0xFF;
while (REG_SPICNT & SPI_BUSY);

for (index = 0; index < size; index++) {
REG_SPIDATA = 0;
while (REG_SPICNT & SPI_BUSY);
buffer[index] = REG_SPIDATA & 0xFF;
}
REG_SPICNT = 0;
uint32 index;
// Read command
while (REG_SPICNT & SPI_BUSY);
REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM;
REG_SPIDATA = FW_READ;
while (REG_SPICNT & SPI_BUSY);
// Set the address
REG_SPIDATA = (address>>16) & 0xFF;
while (REG_SPICNT & SPI_BUSY);
REG_SPIDATA = (address>>8) & 0xFF;
while (REG_SPICNT & SPI_BUSY);
REG_SPIDATA = (address) & 0xFF;
while (REG_SPICNT & SPI_BUSY);
for (index = 0; index < size; index++) {
REG_SPIDATA = 0;
while (REG_SPICNT & SPI_BUSY);
buffer[index] = REG_SPIDATA & 0xFF;
}
REG_SPICNT = 0;
}


static inline void copyLoop (u32* dest, const u32* src, u32 size) {
size = (size +3) & ~3;
do {
*dest++ = *src++;
} while (size -= 4);
do { *dest++ = *src++; } while (size -= 4);
}

//#define resetCpu() __asm volatile("\tswi 0x000000\n");

void mpu_reset();
void mpu_reset_end();

static char boot_nds[] = "fat:/boot.nds";
static unsigned long argbuf[4];

#ifndef NO_SDMMC
int sdmmc_sd_readsectors(u32 sector_no, u32 numsectors, void *out);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Main function
bool sdmmc_inserted() { return true; }

bool sdmmc_startup() {
sdmmc_controller_init(true);
return sdmmc_sdcard_init() == 0;
}

bool sdmmc_readsectors(u32 sector_no, u32 numsectors, void *out) { return sdmmc_sdcard_readsectors(sector_no, numsectors, out) == 0; }
#endif


/*-------------------------------------------------------------------------
passArgs_ARM7
Copies the command line arguments to the end of the ARM9 binary,
Expand All @@ -138,10 +153,8 @@ void passArgs_ARM7 (void) {
u32* argDst;

if (!argStart || !argSize) {

char *arg = boot_nds;
argSize = __builtin_strlen(boot_nds);

if (dsiSD) {
arg++;
arg[0] = 's';
Expand All @@ -158,7 +171,6 @@ void passArgs_ARM7 (void) {
ARM9_LEN = *((u32*)(NDS_HEAD + 0x03C));
}


argDst = (u32*)((ARM9_DST + ARM9_LEN + 3) & ~3); // Word aligned

/* if (dsiMode && (*(u8*)(NDS_HEAD + 0x012) & BIT(1))) {
Expand Down Expand Up @@ -238,7 +250,6 @@ void resetMemory_ARM7 (void) {

}


void loadBinary_ARM7 (u32 fileCluster) {
u32 ndsHeader[0x170>>2];

Expand Down Expand Up @@ -297,21 +308,6 @@ void startBinary_ARM7 (void) {
VoidFn arm7code = *(VoidFn*)(0x2FFFE34);
arm7code();
}
#ifndef NO_SDMMC
int sdmmc_sd_readsectors(u32 sector_no, u32 numsectors, void *out);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Main function
bool sdmmc_inserted() { return true; }

bool sdmmc_startup() {
sdmmc_controller_init(true);
return sdmmc_sdcard_init() == 0;
}

bool sdmmc_readsectors(u32 sector_no, u32 numsectors, void *out) { return sdmmc_sdcard_readsectors(sector_no, numsectors, out) == 0; }
#endif
void mpu_reset();
void mpu_reset_end();

int main (void) {

Expand Down

0 comments on commit 3c362f5

Please sign in to comment.