oh, hello bluetooth dongle :D
[ppcskel.git] / main.c
1 /*
2         BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
3         Requires mini.
4
5 Copyright (C) 2008, 2009        Haxx Enterprises <bushing@gmail.com>
6 Copyright (C) 2009              Andre Heider "dhewg" <dhewg@wiibrew.org>
7 Copyright (C) 2008, 2009        Hector Martin "marcan" <marcan@marcansoft.com>
8 Copyright (C) 2008, 2009        Sven Peter <svenpeter@gmail.com>
9 Copyright (C) 2009              John Kelley <wiidev@kelley.ca>
10
11 # This code is licensed to you under the terms of the GNU GPL, version 2;
12 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
13 */
14
15 #include "bootmii_ppc.h"
16 #include "string.h"
17 #include "ipc.h"
18 #include "mini_ipc.h"
19 #include "nandfs.h"
20 #include "fat.h"
21 #include "malloc.h"
22 #include "diskio.h"
23 #include "printf.h"
24 #include "video_low.h"
25 #include "input.h"
26 #include "console.h"
27 #include "irq.h"
28 #include "usb/core/core.h"
29 #include "hollywood.h"
30
31 #define MINIMUM_MINI_VERSION 0x00010001
32
33 otp_t otp;
34 seeprom_t seeprom;
35
36 static void dsp_reset(void)
37 {
38         write16(0x0c00500a, read16(0x0c00500a) & ~0x01f8);
39         write16(0x0c00500a, read16(0x0c00500a) | 0x0010);
40         write16(0x0c005036, 0);
41 }
42
43 static char ascii(char s) {
44   if(s < 0x20) return '.';
45   if(s > 0x7E) return '.';
46   return s;
47 }
48
49 void hexdump(void *d, int len) {
50   u8 *data;
51   int i, off;
52   data = (u8*)d;
53   for (off=0; off<len; off += 16) {
54     printf("%08x  ",off);
55     for(i=0; i<16; i++)
56       if((i+off)>=len) printf("   ");
57       else printf("%02x ",data[off+i]);
58
59     printf(" ");
60     for(i=0; i<16; i++)
61       if((i+off)>=len) printf(" ");
62       else printf("%c",ascii(data[off+i]));
63     printf("\n");
64   }
65 }
66         
67 void testOTP(void)
68 {
69         printf("reading OTP...\n");
70         getotp(&otp);
71         printf("read OTP!\n");
72         printf("OTP:\n");
73         hexdump(&otp, sizeof(otp));
74
75         printf("reading SEEPROM...\n");
76         getseeprom(&seeprom);
77         printf("read SEEPROM!\n");
78         printf("SEEPROM:\n");
79         hexdump(&seeprom, sizeof(seeprom));
80 }
81
82 int main(void)
83 {
84         int vmode = -1;
85         exception_init();
86         dsp_reset();
87
88         irq_initialize();
89         irq_bw_enable(BW_PI_IRQ_RESET);
90         irq_bw_enable(BW_PI_IRQ_HW); //hollywood pic
91         irq_hw_enable(IRQ_OHCI0);
92
93         ipc_initialize();
94         ipc_slowping();
95
96         gecko_init();
97     input_init();
98         init_fb(vmode);
99
100         VIDEO_Init(vmode);
101         VIDEO_SetFrameBuffer(get_xfb());
102         VISetupEncoder();
103
104         u32 version = ipc_getvers();
105         u16 mini_version_major = version >> 16 & 0xFFFF;
106         u16 mini_version_minor = version & 0xFFFF;
107         printf("Mini version: %d.%0d\n", mini_version_major, mini_version_minor);
108
109         if (version < MINIMUM_MINI_VERSION) {
110                 printf("Sorry, this version of MINI (armboot.bin)\n"
111                         "is too old, please update to at least %d.%0d.\n", 
112                         (MINIMUM_MINI_VERSION >> 16), (MINIMUM_MINI_VERSION & 0xFFFF));
113                 for (;;) 
114                         ; // better ideas welcome!
115         }
116
117         usb_init(OHCI0_REG_BASE);
118         usb_init(OHCI1_REG_BASE);
119
120         /*
121     print_str_noscroll(112, 112, "ohai, world!\n");
122         testOTP();
123         printf("bye, world!\n");
124         */
125
126         return 0;
127 }
128