Skip to content

Commit 174f4e2

Browse files
committed
simplify dldi : faster boot time
1 parent 5be84f6 commit 174f4e2

File tree

4 files changed

+8
-233
lines changed

4 files changed

+8
-233
lines changed

arm7/source/main.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ int main(void) {
138138
// Switch to NTR Mode
139139
//REG_SCFG_ROM = 0x703;
140140

141-
// Find the DLDI reserved space in the file
142-
u32 patchOffset = quickFind (__DSiHeader->ndshdr.arm9destination, dldiMagicString, __DSiHeader->ndshdr.arm9binarySize, sizeof(dldiMagicString));
143-
if(patchOffset == -1) {
144-
nocashMessage("dldi not found");
145-
}
146-
wordCommandAddr = myMemUncached((u32 *) (((u32)__DSiHeader->ndshdr.arm9destination)+patchOffset+0x80));
147-
148141
// read User Settings from firmware
149142
readUserSettings();
150143
irqInit();
@@ -164,14 +157,6 @@ int main(void) {
164157
i2cWriteRegister(0x4A, 0x12, 0x00); // Press power-button for auto-reset
165158
i2cWriteRegister(0x4A, 0x70, 0x01); // Bootflag = Warmboot/SkipHealthSafety
166159

167-
nocashMessage("waiting dldi command");
168-
//nocashMessage(tohex(wordCommandAddr));
169-
// disable dldi sdmmc driver
170-
while(*wordCommandAddr != (vu32)0x027FEE04){}
171-
nocashMessage("sdmmc value received");
172-
wordCommandAddr[1] = 0;
173-
wordCommandAddr[0] = (vu32)0x027FEE08;
174-
175160
swiIntrWait(0,IRQ_FIFO_NOT_EMPTY);
176161
//
177162
int romread_LED = fifoGetValue32(FIFO_USER_05);

dldi/source/iointerface.c

Lines changed: 6 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -41,219 +41,11 @@
4141
#include "sdmmc.h"
4242
#include "memcpy.h"
4343

44-
extern vu32 word_command;
45-
extern vu32 word_params;
46-
extern vu32 words_msg;
47-
48-
// Use the dldi remaining space as temporary buffer : 28k usually available
49-
extern vu32* tmp_buf_addr;
50-
extern vu8 allocated_space;
51-
52-
static char hexbuffer [9];
53-
54-
char* tohex(u32 n)
55-
{
56-
unsigned size = 9;
57-
char *buffer = hexbuffer;
58-
unsigned index = size - 2;
59-
60-
for (int i=0; i<size; i++) {
61-
buffer[i] = '0';
62-
}
63-
64-
while (n > 0)
65-
{
66-
unsigned mod = n % 16;
67-
68-
if (mod >= 10)
69-
buffer[index--] = (mod - 10) + 'A';
70-
else
71-
buffer[index--] = mod + '0';
72-
73-
n /= 16;
74-
}
75-
buffer[size - 1] = '\0';
76-
return buffer;
77-
}
78-
79-
void sendValue32(u32 value32) {
80-
//nocashMessage("sendValue32");
81-
//nocashMessage(tohex(myMemUncached(&word_command)));
82-
*((vu32*)myMemUncached(&word_params)) = value32;
83-
*((vu32*)myMemUncached(&word_command)) = (vu32)0x027FEE04;
84-
IPC_SendSync(0xEE24);
85-
}
86-
87-
void sendMsg(int size, u8* msg) {
88-
//nocashMessage("sendMsg");
89-
*((vu32*)myMemUncached(&word_params)) = size;
90-
for(int i=0;i<size;i++) {
91-
*((u8*)myMemUncached(&words_msg)+i) = msg[i];
92-
}
93-
*((vu32*)myMemUncached(&word_command)) = (vu32)0x027FEE05;
94-
IPC_SendSync(0xEE24);
95-
}
96-
97-
void waitValue32() {
98-
nocashMessage("waitValue32");
99-
while(*((vu32*)myMemUncached(&word_command)) != (vu32)0x027FEE08);
100-
}
101-
102-
u32 getValue32() {
103-
nocashMessage("getValue32");
104-
return *((vu32*)myMemUncached(&word_params));
105-
}
106-
107-
void goodOldCopy32(u32* src, u32* dst, int size) {
108-
for(int i = 0 ; i<size/4; i++) {
109-
dst[i]=src[i];
110-
}
111-
}
112-
113-
void __custom_mpu_setup();
114-
void __custom_mpu_restore();
115-
116-
//---------------------------------------------------------------------------------
117-
bool sd_Startup() {
118-
//---------------------------------------------------------------------------------
119-
nocashMessage("sdio_Startup");
120-
//if (!isSDAcessible()) return false;
121-
122-
//REG_SCFG_EXT &= 0xC000;
123-
124-
//__custom_mpu_setup();
125-
126-
sendValue32(SDMMC_HAVE_SD);
127-
128-
waitValue32();
129-
130-
int result = getValue32();
131-
132-
if(result==0) return false;
133-
134-
sendValue32(SDMMC_SD_START);
135-
136-
waitValue32();
137-
138-
result = getValue32();
139-
140-
//__custom_mpu_restore();
141-
142-
return result == 0;
143-
}
144-
145-
//---------------------------------------------------------------------------------
146-
bool sd_IsInserted() {
147-
//---------------------------------------------------------------------------------
148-
/*if (!isSDAcessible()) return false;
149-
150-
fifoSendValue32(FIFO_SDMMCDSI,SDMMC_SD_IS_INSERTED);
151-
152-
fifoWaitValue32(FIFO_SDMMCDSI);
153-
154-
int result = fifoGetValue32(FIFO_SDMMCDSI);*/
155-
156-
return true;
157-
}
158-
159-
//---------------------------------------------------------------------------------
160-
bool sd_ReadSectors(sec_t sector, sec_t numSectors,void* buffer) {
161-
//---------------------------------------------------------------------------------
162-
nocashMessage("sd_ReadSectors");
163-
//if (!isSDAcessible()) return false;
164-
FifoMessage msg;
165-
int result = 0;
166-
sec_t startsector, readsectors;
167-
168-
//__custom_mpu_setup();
169-
170-
int max_reads = ((1 << allocated_space) / 512) - 11;
171-
172-
for(int numreads =0; numreads<numSectors; numreads+=max_reads) {
173-
startsector = sector+numreads;
174-
if(numSectors - numreads < max_reads) readsectors = numSectors - numreads ;
175-
else readsectors = max_reads;
176-
177-
vu32* mybuffer = myMemUncached(tmp_buf_addr);
178-
179-
msg.type = SDMMC_SD_READ_SECTORS;
180-
msg.sdParams.startsector = startsector;
181-
msg.sdParams.numsectors = readsectors;
182-
msg.sdParams.buffer = mybuffer;
183-
184-
sendMsg(sizeof(msg), (u8*)&msg);
185-
186-
waitValue32();
187-
188-
result = getValue32();
189-
190-
memcpy(mybuffer, buffer+numreads*512, readsectors*512);
191-
}
192-
193-
//__custom_mpu_restore();
194-
195-
return result == 0;
196-
}
197-
198-
//---------------------------------------------------------------------------------
199-
bool sd_WriteSectors(sec_t sector, sec_t numSectors,const void* buffer) {
200-
//---------------------------------------------------------------------------------
201-
nocashMessage("sd_ReadSectors");
202-
//if (!isSDAcessible()) return false;
203-
FifoMessage msg;
204-
int result = 0;
205-
sec_t startsector, readsectors;
206-
207-
//__custom_mpu_setup();
208-
209-
int max_reads = ((1 << allocated_space) / 512) - 11;
210-
211-
for(int numreads =0; numreads<numSectors; numreads+=max_reads) {
212-
startsector = sector+numreads;
213-
if(numSectors - numreads < max_reads) readsectors = numSectors - numreads ;
214-
else readsectors = max_reads;
215-
216-
vu32* mybuffer = myMemUncached(tmp_buf_addr);
217-
218-
memcpy(buffer+numreads*512, mybuffer, readsectors*512);
219-
220-
msg.type = SDMMC_SD_WRITE_SECTORS;
221-
msg.sdParams.startsector = startsector;
222-
msg.sdParams.numsectors = readsectors;
223-
msg.sdParams.buffer = mybuffer;
224-
225-
sendMsg(sizeof(msg), (u8*)&msg);
226-
227-
waitValue32();
228-
229-
result = getValue32();
230-
}
231-
232-
//__custom_mpu_restore();
233-
234-
return result == 0;
235-
}
236-
23744
bool isArm7() {
23845
return sdmmc_read16(REG_SDSTATUS0)!=0;
23946
}
24047

24148

242-
//---------------------------------------------------------------------------------
243-
bool sd_ClearStatus() {
244-
//---------------------------------------------------------------------------------
245-
//if (!isSDAcessible()) return false;
246-
return true;
247-
}
248-
249-
//---------------------------------------------------------------------------------
250-
bool sd_Shutdown() {
251-
//---------------------------------------------------------------------------------
252-
//if (!isSDAcessible()) return false;
253-
return true;
254-
}
255-
256-
25749
/*-----------------------------------------------------------------
25850
startUp
25951
Initialize the interface, geting it into an idle, ready state
@@ -265,7 +57,7 @@ bool startup(void) {
26557
sdmmc_controller_init();
26658
return sdmmc_sdcard_init()==0;
26759
} else {
268-
return sd_Startup();
60+
return false;
26961
}
27062
}
27163

@@ -276,7 +68,7 @@ return true if a card is inserted and usable
27668
-----------------------------------------------------------------*/
27769
bool isInserted (void) {
27870
nocashMessage("isInserted");
279-
return sd_IsInserted();
71+
return true;
28072
}
28173

28274

@@ -287,7 +79,7 @@ return true if the card is idle and ready
28779
-----------------------------------------------------------------*/
28880
bool clearStatus (void) {
28981
nocashMessage("clearStatus");
290-
return sd_ClearStatus();
82+
return true;
29183
}
29284

29385

@@ -303,12 +95,10 @@ bool readSectors (u32 sector, u32 numSectors, void* buffer) {
30395
if(isArm7()) {
30496
return sdmmc_sdcard_readsectors(sector,numSectors,buffer)==0;
30597
} else {
306-
return sd_ReadSectors(sector,numSectors,buffer);
98+
return false;
30799
}
308100
}
309101

310-
311-
312102
/*-----------------------------------------------------------------
313103
writeSectors
314104
Write "numSectors" 512-byte sized sectors from "buffer" to the card,
@@ -321,7 +111,7 @@ bool writeSectors (u32 sector, u32 numSectors, void* buffer) {
321111
if(isArm7()) {
322112
return sdmmc_sdcard_writesectors(sector,numSectors,buffer)==0;
323113
} else {
324-
return sd_WriteSectors(sector,numSectors,buffer);
114+
return false;
325115
}
326116
}
327117

@@ -334,5 +124,5 @@ return true if the card is no longer active
334124
-----------------------------------------------------------------*/
335125
bool shutdown(void) {
336126
nocashMessage("shutdown");
337-
return sd_Shutdown();
127+
return true;
338128
}

nds-bootstrap.pnproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<Project name="nds-bootstrap"><Folder name="bootloader"><Folder name="source"><File path="bootloader\source\arm7clear.s"></File><File path="bootloader\source\bios.s"></File><File path="bootloader\source\card.h"></File><File path="bootloader\source\cheat_engine.s"></File><File path="bootloader\source\common.h"></File><File path="bootloader\source\disc_io.h"></File><File path="bootloader\source\dldi_patcher.c"></File><File path="bootloader\source\dldi_patcher.h"></File><File path="bootloader\source\encryption.c"></File><File path="bootloader\source\encryption.h"></File><File path="bootloader\source\fat.c"></File><File path="bootloader\source\fat.h"></File><File path="bootloader\source\io_dldi.h"></File><File path="bootloader\source\io_dldi.s"></File><File path="bootloader\source\load_crt0.s"></File><File path="bootloader\source\read_bios.h"></File><File path="bootloader\source\read_bios.s"></File><File path="bootloader\source\sdmmc.c"></File><File path="bootloader\source\hook.c"></File><File path="bootloader\source\hook.h"></File><File path="bootloader\source\mpu_setup.s"></File><File path="bootloader\source\card_patcher.c"></File><File path="bootloader\source\card_patcher.h"></File><File path="bootloader\source\debugToFile.c"></File><File path="bootloader\source\debugToFile.h"></File><File path="bootloader\source\clear_cache.arm9.s"></File><File path="bootloader\source\crt0.arm9.s"></File><File path="bootloader\source\main.arm7.c"></File><File path="bootloader\source\main.arm9.c"></File></Folder><File path="bootloader\Makefile"></File><File path="bootloader\load.ld"></File></Folder><Folder name="arm7"><Folder name="source"><File path="arm7\source\main.c"></File></Folder><File path="arm7\Makefile"></File></Folder><Folder name="arm9"><Folder name="source"><File path="arm9\source\inifile.cpp"></File><File path="arm9\source\inifile.h"></File><File path="arm9\source\nds_loader_arm9.c"></File><File path="arm9\source\nds_loader_arm9.h"></File><File path="arm9\source\main.cpp"></File><File path="arm9\source\crc.h"></File><File path="arm9\source\stringtool.cpp"></File><File path="arm9\source\stringtool.h"></File></Folder><File path="arm9\Makefile"></File></Folder><Folder name="conf"><Folder name="no$gba"><File path="conf\no$gba\nds-bootstrap.ini"></File></Folder><File path="conf\bootstrap.argv"></File><File path="conf\nds-bootstrap.ini"></File></Folder><Folder name="cardengine_arm7"><Folder name="source"><File path="cardengine_arm7\source\bios.s"></File><File path="cardengine_arm7\source\card.h"></File><File path="cardengine_arm7\source\card_engine_header.s"></File><File path="cardengine_arm7\source\cardEngine.c"></File><File path="cardengine_arm7\source\cardEngine.h"></File><File path="cardengine_arm7\source\debugprint.s"></File><File path="cardengine_arm7\source\debugToFile.c"></File><File path="cardengine_arm7\source\debugToFile.h"></File><File path="cardengine_arm7\source\disc_io.h"></File><File path="cardengine_arm7\source\fat.c"></File><File path="cardengine_arm7\source\fat.h"></File><File path="cardengine_arm7\source\sdmmc.c"></File><File path="cardengine_arm7\source\sdmmc.h"></File></Folder><File path="cardengine_arm7\cardengine.ld"></File><File path="cardengine_arm7\Makefile"></File></Folder><Folder name="cardengine_arm9"><Folder name="source"><File path="cardengine_arm9\source\card_engine_header.s"></File><File path="cardengine_arm9\source\cardEngine.c"></File><File path="cardengine_arm9\source\cardEngine.h"></File><File path="cardengine_arm9\source\debugprint.s"></File></Folder><File path="cardengine_arm9\cardengine.ld"></File><File path="cardengine_arm9\Makefile"></File></Folder><Folder name="dldiengine"><Folder name="source"><File path="dldiengine\source\bios.s"></File><File path="dldiengine\source\card.h"></File><File path="dldiengine\source\debugprint.s"></File><File path="dldiengine\source\debugToFile.c"></File><File path="dldiengine\source\debugToFile.h"></File><File path="dldiengine\source\disc_io.h"></File><File path="dldiengine\source\fat.c"></File><File path="dldiengine\source\fat.h"></File><File path="dldiengine\source\sdmmc.c"></File><File path="dldiengine\source\sdmmc.h"></File><File path="dldiengine\source\sdmmc_engine_header.s"></File><File path="dldiengine\source\sdmmcEngine.c"></File><File path="dldiengine\source\sdmmcEngine.h"></File></Folder><File path="dldiengine\sdengine.ld"></File><File path="dldiengine\Makefile"></File></Folder><Folder name="dldi"><Folder name="source"><File path="dldi\source\dldi_header.s"></File><File path="dldi\source\iointerface.c"></File><File path="dldi\source\sdmmc.c"></File><File path="dldi\source\sdmmc.h"></File><File path="dldi\source\mpu_setup.s"></File><File path="dldi\source\memcpy.c"></File><File path="dldi\source\util.s"></File></Folder><File path="dldi\dldi.ld"></File><File path="dldi\dsisd.ini"></File><File path="dldi\Makefile"></File></Folder><File path="Makefile"></File><File path="build_cia.sh"></File><File path="icon.bmp"></File><File path="patch_ndsheader_dsiware.py"></File><File path=".travis.yml"></File></Project>
1+
<Project name="nds-bootstrap"><Folder name="bootloader"><Folder name="source"><File path="bootloader\source\arm7clear.s"></File><File path="bootloader\source\bios.s"></File><File path="bootloader\source\card.h"></File><File path="bootloader\source\cheat_engine.s"></File><File path="bootloader\source\common.h"></File><File path="bootloader\source\disc_io.h"></File><File path="bootloader\source\dldi_patcher.c"></File><File path="bootloader\source\dldi_patcher.h"></File><File path="bootloader\source\encryption.c"></File><File path="bootloader\source\encryption.h"></File><File path="bootloader\source\fat.c"></File><File path="bootloader\source\fat.h"></File><File path="bootloader\source\io_dldi.h"></File><File path="bootloader\source\io_dldi.s"></File><File path="bootloader\source\load_crt0.s"></File><File path="bootloader\source\read_bios.h"></File><File path="bootloader\source\read_bios.s"></File><File path="bootloader\source\sdmmc.c"></File><File path="bootloader\source\hook.c"></File><File path="bootloader\source\hook.h"></File><File path="bootloader\source\mpu_setup.s"></File><File path="bootloader\source\card_patcher.c"></File><File path="bootloader\source\card_patcher.h"></File><File path="bootloader\source\debugToFile.c"></File><File path="bootloader\source\debugToFile.h"></File><File path="bootloader\source\clear_cache.arm9.s"></File><File path="bootloader\source\crt0.arm9.s"></File><File path="bootloader\source\main.arm7.c"></File><File path="bootloader\source\main.arm9.c"></File></Folder><File path="bootloader\Makefile"></File><File path="bootloader\load.ld"></File></Folder><Folder name="arm7"><Folder name="source"><File path="arm7\source\main.c"></File></Folder><File path="arm7\Makefile"></File></Folder><Folder name="arm9"><Folder name="source"><File path="arm9\source\inifile.cpp"></File><File path="arm9\source\inifile.h"></File><File path="arm9\source\nds_loader_arm9.c"></File><File path="arm9\source\nds_loader_arm9.h"></File><File path="arm9\source\main.cpp"></File><File path="arm9\source\crc.h"></File><File path="arm9\source\stringtool.cpp"></File><File path="arm9\source\stringtool.h"></File></Folder><File path="arm9\Makefile"></File></Folder><Folder name="conf"><Folder name="no$gba"><File path="conf\no$gba\nds-bootstrap.ini"></File></Folder><File path="conf\bootstrap.argv"></File><File path="conf\nds-bootstrap.ini"></File></Folder><Folder name="cardengine_arm7"><Folder name="source"><File path="cardengine_arm7\source\bios.s"></File><File path="cardengine_arm7\source\card.h"></File><File path="cardengine_arm7\source\card_engine_header.s"></File><File path="cardengine_arm7\source\cardEngine.c"></File><File path="cardengine_arm7\source\cardEngine.h"></File><File path="cardengine_arm7\source\debugprint.s"></File><File path="cardengine_arm7\source\debugToFile.c"></File><File path="cardengine_arm7\source\debugToFile.h"></File><File path="cardengine_arm7\source\disc_io.h"></File><File path="cardengine_arm7\source\fat.c"></File><File path="cardengine_arm7\source\fat.h"></File><File path="cardengine_arm7\source\sdmmc.c"></File><File path="cardengine_arm7\source\sdmmc.h"></File></Folder><File path="cardengine_arm7\cardengine.ld"></File><File path="cardengine_arm7\Makefile"></File></Folder><Folder name="cardengine_arm9"><Folder name="source"><File path="cardengine_arm9\source\card_engine_header.s"></File><File path="cardengine_arm9\source\cardEngine.c"></File><File path="cardengine_arm9\source\cardEngine.h"></File><File path="cardengine_arm9\source\debugprint.s"></File></Folder><File path="cardengine_arm9\cardengine.ld"></File><File path="cardengine_arm9\Makefile"></File></Folder><Folder name="dldi"><Folder name="source"><File path="dldi\source\dldi_header.s"></File><File path="dldi\source\iointerface.c"></File><File path="dldi\source\sdmmc.c"></File><File path="dldi\source\sdmmc.h"></File><File path="dldi\source\mpu_setup.s"></File><File path="dldi\source\memcpy.c"></File><File path="dldi\source\util.s"></File></Folder><File path="dldi\dldi.ld"></File><File path="dldi\dsisd.ini"></File><File path="dldi\Makefile"></File></Folder><File path="Makefile"></File><File path="build_cia.sh"></File><File path="icon.bmp"></File><File path="patch_ndsheader_dsiware.py"></File><File path=".travis.yml"></File></Project>

nds-bootstrap.pnps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<pd><ViewState><e p="nds-bootstrap\arm9\source" x="true"></e><e p="nds-bootstrap\bootloader" x="true"></e><e p="nds-bootstrap\cardengine_arm7" x="false"></e><e p="nds-bootstrap" x="true"></e><e p="nds-bootstrap\arm7" x="false"></e><e p="nds-bootstrap\arm9" x="true"></e><e p="nds-bootstrap\bootloader\source" x="true"></e><e p="nds-bootstrap\cardengine_arm9" x="false"></e><e p="nds-bootstrap\conf" x="false"></e><e p="nds-bootstrap\dldi" x="false"></e><e p="nds-bootstrap\dldiengine" x="false"></e></ViewState></pd>
1+
<pd><ViewState><e p="nds-bootstrap\arm9\source" x="true"></e><e p="nds-bootstrap\bootloader" x="true"></e><e p="nds-bootstrap\cardengine_arm7" x="false"></e><e p="nds-bootstrap" x="true"></e><e p="nds-bootstrap\arm7" x="false"></e><e p="nds-bootstrap\arm9" x="true"></e><e p="nds-bootstrap\bootloader\source" x="true"></e><e p="nds-bootstrap\cardengine_arm9" x="false"></e><e p="nds-bootstrap\conf" x="false"></e><e p="nds-bootstrap\dldi" x="true"></e><e p="nds-bootstrap\dldi\source" x="true"></e></ViewState></pd>

0 commit comments

Comments
 (0)