/* BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader. Requires mini. Copyright (C) 2008, 2009 Haxx Enterprises Copyright (C) 2009 Andre Heider "dhewg" Copyright (C) 2008, 2009 Hector Martin "marcan" Copyright (C) 2008, 2009 Sven Peter Copyright (C) 2009 John Kelley # This code is licensed to you under the terms of the GNU GPL, version 2; # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt */ #include "bootmii_ppc.h" #include "string.h" #include "ipc.h" #include "mini_ipc.h" #include "nandfs.h" #include "fat.h" #include "malloc.h" #include "diskio.h" #include "printf.h" #include "video_low.h" #include "input.h" #include "console.h" #include "irq.h" #include "usb/core/core.h" #include "usb/drivers/class/hid.h" #include "sha1.h" #include "hollywood.h" #define MINIMUM_MINI_VERSION 0x00010001 otp_t otp; seeprom_t seeprom; static void dsp_reset(void) { write16(0x0c00500a, read16(0x0c00500a) & ~0x01f8); write16(0x0c00500a, read16(0x0c00500a) | 0x0010); write16(0x0c005036, 0); } static char ascii(char s) { if(s < 0x20) return '.'; if(s > 0x7E) return '.'; return s; } void hexdump(void *d, int len) { u8 *data; int i, off; data = (u8*)d; for (off=0; off=len) printf(" "); else printf("%02x ",data[off+i]); printf(" "); for(i=0; i<16; i++) if((i+off)>=len) printf(" "); else printf("%c",ascii(data[off+i])); printf("\n"); } } void testOTP(void) { printf("reading OTP...\n"); getotp(&otp); printf("read OTP!\n"); printf("OTP:\n"); hexdump(&otp, sizeof(otp)); printf("reading SEEPROM...\n"); getseeprom(&seeprom); printf("read SEEPROM!\n"); printf("SEEPROM:\n"); hexdump(&seeprom, sizeof(seeprom)); } int main(void) { int vmode = -1; exception_init(); dsp_reset(); irq_initialize(); irq_bw_enable(BW_PI_IRQ_RESET); irq_bw_enable(BW_PI_IRQ_HW); //hollywood pic /* external ohci */ irq_hw_enable(IRQ_OHCI0); /* internal ohci */ //irq_hw_enable(IRQ_OHCI1); ipc_initialize(); ipc_slowping(); gecko_init(); input_init(); init_fb(vmode); VIDEO_Init(vmode); VIDEO_SetFrameBuffer(get_xfb()); VISetupEncoder(); u32 version = ipc_getvers(); u16 mini_version_major = version >> 16 & 0xFFFF; u16 mini_version_minor = version & 0xFFFF; printf("Mini version: %d.%0d\n", mini_version_major, mini_version_minor); if (version < MINIMUM_MINI_VERSION) { printf("Sorry, this version of MINI (armboot.bin)\n" "is too old, please update to at least %d.%0d.\n", (MINIMUM_MINI_VERSION >> 16), (MINIMUM_MINI_VERSION & 0xFFFF)); for (;;) ; // better ideas welcome! } /* external ohci */ usb_init(OHCI0_REG_BASE); /* internal ohci */ usb_init(OHCI1_REG_BASE); /* load HID keyboard driver */ usb_hidkb_init(); /* wait for usb keyboard plugged in */ if(!usb_hidkb_inuse()) { print_str("plug in an usb keyboard", 23); } while(!usb_hidkb_inuse()); /* you are welcome to make this nice :) */ char str[7]; u16 i, j, y=20, x=20; struct kbrep *k; while(1) { memset(str, '\0', 8); j=0; k = usb_hidkb_getChars(); for(i=0; k->keys[i]>0; i++) { if(x>650) { x = 20; y += 15; } if(y>440) { y=20; } if((k->keys[i] >= 4) && k->keys[i] <= 4+'z'-'a') { str[j] = k->keys[i] - 4 + (k->mod & MOD_lshift || k->mod & MOD_rshift ? 'A' : 'a'); } else if ((k->keys[i] >= 0x1e) && (k->keys[i] <= 0x26)) { str[j] = k->keys[i] - 0x1e + '1'; } else if (k->keys[i] == 0x27) { str[j] = '0'; } else if (k->keys[i] == 0x28) { y += 15; x = 20; } j++; } if(j > 0) { print_str_noscroll(x, y, str); printf("y: %d\n", y); } while(j--) { x += 13; } } #if 0 printf("===============================\n"); SHA1TestCases(); printf("bye, world!\n"); #endif return 0; }