2 * Copyright (C) 2008 svpe, #wiidev at efnet
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define FILES_PER_PAGE 24
33 #include "processor.h"
35 static void *xfb
= NULL
;
36 static GXRModeObj
*rmode
= NULL
;
38 extern void __exception_closeall();
39 extern s32
__IOS_ShutdownSubsystems();
41 #define USB_ALIGN __attribute__((aligned(32)))
42 static const char *usb_path USB_ALIGN
= "/dev/usb/oh1/57e/305";
43 char bluetoothResetData1
[] USB_ALIGN
= {
48 char bluetoothResetData2
[] USB_ALIGN
= {
53 char bluetoothResetData3
[] USB_ALIGN
= {
58 char bluetoothResetData4
[] USB_ALIGN
= {
63 char bluetoothResetData5
[] USB_ALIGN
= {
68 char bluetoothResetData6
[] USB_ALIGN
= {
69 /* unknown; set to zero. */
73 char bluetoothResetData7
[] USB_ALIGN
= {
78 /** Vectors of data transfered. */
79 ioctlv bluetoothReset
[] USB_ALIGN
= {
82 sizeof(bluetoothResetData1
)
86 sizeof(bluetoothResetData2
)
90 sizeof(bluetoothResetData3
)
94 sizeof(bluetoothResetData4
)
98 sizeof(bluetoothResetData5
)
102 sizeof(bluetoothResetData6
)
106 sizeof(bluetoothResetData7
)
112 int main(int argc
, char **argv
) {
118 char filename
[4+13+1];
120 char filelist
[999][13]; // FIXME: use a dynamic filelist here
125 u32 bytes_read_total
;
126 u8
*data
= (u8
*)0x92000000;
146 AUDIO_RegisterDMACallback(NULL
);
148 switch(VIDEO_GetCurrentTvMode()) {
150 rmode
= &TVNtsc480IntDf
;
153 rmode
= &TVPal528IntDf
;
156 rmode
= &TVMpal480IntDf
;
159 rmode
= &TVNtsc480IntDf
;
163 xfb
= MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode
));
164 console_init(xfb
,20,20,rmode
->fbWidth
,rmode
->xfbHeight
,rmode
->fbWidth
*VI_DISPLAY_PIX_SZ
);
166 VIDEO_Configure(rmode
);
167 VIDEO_SetNextFramebuffer(xfb
);
168 VIDEO_SetBlack(FALSE
);
171 if(rmode
->viTVMode
&VI_NON_INTERLACE
) VIDEO_WaitVSync();
175 printf("Front SD ELF Loader\n");
176 printf("(c) 2008 Sven Peter (svpe, #wiidev at blitzed/efnet)\n");
177 printf("Internal SD stuff by bushing, marcan and maybe some more ppl i don't know about.\n");
178 printf("TinyFAT FS by elm-chan.org\n");
179 printf("Some ELF loader code by dhewg and tmbinc\n");
182 printf("Press A to continue\n");
187 if(PAD_ButtonsDown(0) & PAD_BUTTON_A
)
192 printf("Shutting down wiimote\n");
193 // printf("Open Bluetooth Dongle\n");
194 usb_fd
= IOS_Open(usb_path
, 2 /* 2 = write, 1 = read */);
195 printf("fd = %d\n", usb_fd
);
197 // printf("Closing connection to blutooth\n");
198 res
= IOS_Ioctlv(usb_fd
, 0, 6, 1, bluetoothReset
);
199 // printf("ret = %d\n", res);
205 if(f_mount(0, &ffs
) != FR_OK
)
207 printf("f_mount() failed. No FAT filesystem on the SD card?\n");
211 res
= f_opendir(&elfdir
, "elf");
214 printf("f_opendir() failed with %d. Does elf/ exist?\n", res
);
218 printf("Loading filelist...\n");
220 memset(&finfo
, 0, sizeof(finfo
));
221 f_readdir(&elfdir
, &finfo
);
222 while(strlen(finfo
.fname
) != 0)
224 if(!(finfo
.fattrib
& AM_DIR
))
226 printf("Adding %s\n", finfo
.fname
);
227 memcpy(filelist
[files
], finfo
.fname
, 13);
230 f_readdir(&elfdir
, &finfo
);
237 printf("Press A..\n");
242 if(PAD_ButtonsDown(0) & PAD_BUTTON_A
)
247 offset
= selection
= 0;
252 for(i
= offset
; i
< (offset
+ FILES_PER_PAGE
) && i
< files
; i
++)
255 printf(">>%s\n", filelist
[i
]);
257 printf("%s\n", filelist
[i
]);
264 buttons
= PAD_ButtonsDown(0);
265 if(buttons
& PAD_BUTTON_A
)
267 snprintf(filename
, 4+13, "elf/%s", filelist
[selection
]);
268 if(f_stat(filename
, &finfo
) != FR_OK
)
270 printf("error: f_stat() failed :/\n");
273 if(f_open(&fp
, filename
, FA_READ
) != FR_OK
)
275 printf("error: f_open() failed\n");
278 printf("Reading %u bytes\n", (unsigned int)finfo
.fsize
);
279 bytes_read
= bytes_read_total
= 0;
280 while(bytes_read_total
< finfo
.fsize
)
282 if(f_read(&fp
, data
+ bytes_read_total
, 0x200, &bytes_read
) != FR_OK
)
284 printf("error: f_read failed.\n");
289 bytes_read_total
+= bytes_read
;
290 // printf("%d/%d bytes read (%d this time)\n", bytes_read_total, (unsigned int)finfo.fsize, bytes_read);
292 if(bytes_read_total
< finfo
.fsize
)
294 printf("error: read %u of %u bytes.\n", bytes_read_total
, (unsigned int)finfo
.fsize
);
297 res
= valid_elf_image(data
);
300 printf("ELF image found.\n");
301 ep
= (void(*)())load_elf_image(data
);
305 printf("Assuming that this is a DOL file. Your Wii will crash if it isn't...\n");
306 ep
= (void(*)())load_dol_image(data
);
311 printf("entry point: 0x%X\n", (unsigned int)ep
);
314 // code from geckoloader
315 __IOS_ShutdownSubsystems ();
316 printf("IOS_ShutdownSubsystems() done\n");
317 _CPU_ISR_Disable (level
);
318 printf("_CPU_ISR_Disable() done\n");
319 __exception_closeall ();
320 printf("__exception_closeall() done. Jumping to ep now...\n");
322 _CPU_ISR_Restore (level
);
324 printf("binaries really shouldn't return here...\n");
328 else if(buttons
& PAD_BUTTON_DOWN
)
330 if(selection
+1 < files
)
332 if(selection
>= offset
+ FILES_PER_PAGE
)
333 offset
+= FILES_PER_PAGE
;
336 else if(buttons
& PAD_BUTTON_UP
)
340 if(selection
< offset
)
342 if(FILES_PER_PAGE
> offset
)
345 offset
-= FILES_PER_PAGE
;
353 printf("this should not happen\n");