acd97174cd0e328a07f8d60d821cfb1022430db7
[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
28 #define MINIMUM_MINI_VERSION 0x00010001
29
30 otp_t otp;
31 seeprom_t seeprom;
32
33 static void dsp_reset(void)
34 {
35         write16(0x0c00500a, read16(0x0c00500a) & ~0x01f8);
36         write16(0x0c00500a, read16(0x0c00500a) | 0x0010);
37         write16(0x0c005036, 0);
38 }
39
40 static char ascii(char s) {
41   if(s < 0x20) return '.';
42   if(s > 0x7E) return '.';
43   return s;
44 }
45
46 void hexdump(void *d, int len) {
47   u8 *data;
48   int i, off;
49   data = (u8*)d;
50   for (off=0; off<len; off += 16) {
51     printf("%08x  ",off);
52     for(i=0; i<16; i++)
53       if((i+off)>=len) printf("   ");
54       else printf("%02x ",data[off+i]);
55
56     printf(" ");
57     for(i=0; i<16; i++)
58       if((i+off)>=len) printf(" ");
59       else printf("%c",ascii(data[off+i]));
60     printf("\n");
61   }
62 }
63         
64 void testOTP(void)
65 {
66         printf("reading OTP...\n");
67         getotp(&otp);
68         printf("read OTP!\n");
69         printf("OTP:\n");
70         hexdump(&otp, sizeof(otp));
71
72         printf("reading SEEPROM...\n");
73         getseeprom(&seeprom);
74         printf("read SEEPROM!\n");
75         printf("SEEPROM:\n");
76         hexdump(&seeprom, sizeof(seeprom));
77 }
78
79 int main(void)
80 {
81         int vmode = -1;
82         exception_init();
83         dsp_reset();
84
85         // clear interrupt mask
86         write32(0x0c003004, 0);
87
88         ipc_initialize();
89         ipc_slowping();
90
91         gecko_init();
92     input_init();
93         init_fb(vmode);
94
95         VIDEO_Init(vmode);
96         VIDEO_SetFrameBuffer(get_xfb());
97         VISetupEncoder();
98
99         u32 version = ipc_getvers();
100         u16 mini_version_major = version >> 16 & 0xFFFF;
101         u16 mini_version_minor = version & 0xFFFF;
102         printf("Mini version: %d.%0d\n", mini_version_major, mini_version_minor);
103
104         if (version < MINIMUM_MINI_VERSION) {
105                 printf("Sorry, this version of MINI (armboot.bin)\n"
106                         "is too old, please update to at least %d.%0d.\n", 
107                         (MINIMUM_MINI_VERSION >> 16), (MINIMUM_MINI_VERSION & 0xFFFF));
108                 for (;;) 
109                         ; // better ideas welcome!
110         }
111
112     print_str_noscroll(112, 112, "ohai, world!\n");
113
114         testOTP();
115
116         printf("bye, world!\n");
117
118         return 0;
119 }
120