Permalink
Browse files

initial revision

  • Loading branch information...
comex committed Jun 17, 2009
0 parents commit 31ac9fe8b7f6f9832e2da18a217181ef5598b436
Showing with 20,901 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +340 −0 COPYING
  3. +20 −0 Makefile
  4. +47 −0 aes.c
  5. +23 −0 aes.h
  6. +122 −0 bootmii_ppc.h
  7. +12 −0 broadway.mk
  8. +60 −0 common.mk
  9. +252 −0 console.c
  10. +24 −0 console.h
  11. +289 −0 crt0.S
  12. +161 −0 diskio.c
  13. +53 −0 diskio.h
  14. +176 −0 es.c
  15. +74 −0 es.h
  16. +63 −0 exception.c
  17. +31 −0 exception_2200.S
  18. +43 −0 fat.c
  19. +21 −0 fat.h
  20. +2,966 −0 ff.c
  21. +550 −0 ff.h
  22. +4,613 −0 font.c
  23. +115 −0 fs_hmac.c
  24. +19 −0 fs_hmac.h
  25. +218 −0 gecko.c
  26. +142 −0 input.c
  27. +52 −0 input.h
  28. +234 −0 ipc.c
  29. +184 −0 ipc.h
  30. +280 −0 main.c
  31. +5,085 −0 malloc.c
  32. +529 −0 malloc.h
  33. +53 −0 mini.ld
  34. +226 −0 mini_ipc.c
  35. +127 −0 mini_ipc.h
  36. +826 −0 nandfs.c
  37. +53 −0 nandfs.h
  38. +19 −0 otp.c
  39. +39 −0 otp.h
  40. +798 −0 printf.c
  41. +30 −0 printf.h
  42. +112 −0 realmode.S
  43. +398 −0 rijndael.c
  44. +27 −0 setting_txt.h
  45. +380 −0 sha1.c
  46. +72 −0 sha1.h
  47. +170 −0 string.c
  48. +30 −0 string.h
  49. +51 −0 sync.c
  50. +38 −0 time.c
  51. +61 −0 types.h
  52. +421 −0 video_low.c
  53. +56 −0 video_low.h
  54. +90 −0 wad.c
  55. +25 −0 wad.h
@@ -0,0 +1 @@
+ppcboot.elf
340 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,20 @@
+include broadway.mk
+
+DEFINES = -DLACKS_SYS_TYPES_H -DLACKS_ERRNO_H -DLACKS_STDLIB_H -DLACKS_STRING_H -DLACKS_STRINGS_H -DLACKS_UNISTD_H
+LDSCRIPT = mini.ld
+LIBS = -lgcc
+
+TARGET = ppcboot.elf
+
+OBJS = realmode.o crt0.o main.o string.o sync.o time.o printf.o input.o \
+ exception.o exception_2200.o malloc.o gecko.o video_low.o \
+ ipc.o mini_ipc.o nandfs.o ff.o diskio.o fat.o font.o console.o \
+ fs_hmac.o sha1.o otp.o es.o wad.o rijndael.o aes.o
+
+include common.mk
+
+upload: $(TARGET)
+ @$(WIIDEV)/bin/bootmii -p $<
+
+.PHONY: upload
+
47 aes.c
@@ -0,0 +1,47 @@
+/*
+ BootMii - a Free Software replacement for the Nintendo/BroadOn IOS.
+ Requires mini.
+
+ aes
+
+# 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 "aes.h"
+
+#if !HARDWARE_AES
+
+static u8 aes_iv[16];
+
+void aes_reset(void) {}
+void aes_set_iv(u8 *iv)
+{
+ memcpy(aes_iv, iv, 16);
+}
+void aes_set_key(u8 *key)
+{
+ my_aes_set_key(key);
+}
+void aes_decrypt(u8 *src, u8 *dst, u32 blocks, u8 keep_iv)
+{
+ if(src == dst) {
+ u8 *p = (u8 *) 0x92000000;
+ my_aes_decrypt(aes_iv, src, p, 16*blocks);
+ memcpy(dst, p, 16*blocks);
+ } else
+ my_aes_decrypt(aes_iv, src, dst, 16*blocks);
+}
+void aes_encrypt(u8 *src, u8 *dst, u32 blocks, u8 keep_iv)
+{
+ if(src == dst) {
+ u8 *p = (u8 *) 0x92000000;
+ my_aes_encrypt(aes_iv, src, p, 16*blocks);
+ memcpy(dst, p, 16*blocks);
+ } else
+ my_aes_encrypt(aes_iv, src, dst, 16*blocks);
+}
+#endif
23 aes.h
@@ -0,0 +1,23 @@
+/*
+ BootMii - a Free Software replacement for the Nintendo/BroadOn IOS.
+ Requires mini.
+
+# 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
+*/
+
+#ifndef __AES_H__
+#define __AES_H__
+#define HARDWARE_AES 0
+void my_aes_set_key(u8 *key);
+void my_aes_decrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len);
+void my_aes_encrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len);
+
+void aes_reset(void);
+void aes_set_key(u8 *key);
+void aes_set_iv(u8 *iv);
+void aes_decrypt(u8 *src, u8 *dst, u32 blocks, u8 keep_iv);
+void aes_encrypt(u8 *src, u8 *dst, u32 blocks, u8 keep_iv);
+
+#endif
+
@@ -0,0 +1,122 @@
+/*
+ BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
+ Requires mini.
+
+Copyright (C) 2008 Segher Boessenkool <segher@kernel.crashing.org>
+
+# 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
+*/
+
+#ifndef __PPC_H__
+#define __PPC_H__
+
+#include "types.h"
+#include "printf.h"
+
+#define OK 0
+#define EFAIL 1
+#define ENOSPACE 2
+#define ECANCELLED 3
+
+#define MEM2_BSS __attribute__ ((section (".bss.mem2")))
+#define MEM2_DATA __attribute__ ((section (".data.mem2")))
+#define MEM2_RODATA __attribute__ ((section (".rodata.mem2")))
+#define ALIGNED(x) __attribute__((aligned(x)))
+
+#define STACK_ALIGN(type, name, cnt, alignment) \
+ u8 _al__##name[((sizeof(type)*(cnt)) + (alignment) + \
+ (((sizeof(type)*(cnt))%(alignment)) > 0 ? ((alignment) - \
+ ((sizeof(type)*(cnt))%(alignment))) : 0))]; \
+ type *name = (type*)(((u32)(_al__##name)) + ((alignment) - (( \
+ (u32)(_al__##name))&((alignment)-1))))
+
+// Basic I/O.
+
+static inline u32 read32(u32 addr)
+{
+ u32 x;
+
+ asm volatile("lwz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
+
+ return x;
+}
+
+static inline void write32(u32 addr, u32 x)
+{
+ asm("stw %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
+}
+
+static inline void mask32(u32 addr, u32 clear, u32 set)
+{
+ write32(addr, (read32(addr)&(~clear)) | set);
+}
+
+static inline u16 read16(u32 addr)
+{
+ u16 x;
+
+ asm volatile("lhz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
+
+ return x;
+}
+
+static inline void write16(u32 addr, u16 x)
+{
+ asm("sth %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
+}
+
+
+// Address mapping.
+
+static inline u32 virt_to_phys(const void *p)
+{
+ return (u32)p & 0x7fffffff;
+}
+
+static inline void *phys_to_virt(u32 x)
+{
+ return (void *)(x | 0x80000000);
+}
+
+
+// Cache synchronisation.
+
+void sync_before_read(void *p, u32 len);
+void sync_after_write(const void *p, u32 len);
+void sync_before_exec(const void *p, u32 len);
+
+
+// Time.
+
+void udelay(u32 us);
+u64 mftb(void);
+
+
+// Special purpose registers.
+
+#define mtspr(n, x) do { asm("mtspr %1,%0" : : "r"(x), "i"(n)); } while (0)
+#define mfspr(n) ({ \
+ u32 x; asm volatile("mfspr %0,%1" : "=r"(x) : "i"(n)); x; \
+})
+
+
+// Exceptions.
+
+void exception_init(void);
+
+
+// Console.
+
+void gecko_init(void);
+int printf(const char *fmt, ...);
+
+
+// Debug: blink the tray led.
+
+static inline void blink(void)
+{
+ write32(0x0d8000c0, read32(0x0d8000c0) ^ 0x20);
+}
+
+#endif
@@ -0,0 +1,12 @@
+ifeq ($(strip $(WIIDEV)),)
+$(error "Set WIIDEV in your environment.")
+endif
+
+PREFIX = $(WIIDEV)/bin/powerpc-elf-
+
+CFLAGS = -mcpu=750 -mpaired -m32 -mhard-float -mno-eabi -mno-sdata
+CFLAGS += -ffreestanding -ffunction-sections
+CFLAGS += -Wall -Wextra -Os -pipe
+ASFLAGS =
+LDFLAGS = -mcpu=750 -m32 -n -nostartfiles -nodefaultlibs -Wl,-gc-sections
+
@@ -0,0 +1,60 @@
+AR = $(PREFIX)ar
+AS = $(PREFIX)as
+CC = $(PREFIX)gcc
+CXX = $(PREFIX)g++
+LD = $(PREFIX)ld
+OBJCOPY = $(PREFIX)objcopy
+RANLIB = $(PREFIX)ranlib
+STRIP = $(PREFIX)strip
+
+BIN2S = $(DEVKITPPC)/bin/bin2s
+
+ifeq ($(NOMAPFILE),)
+LDFLAGS += -Wl,-Map,$(TARGET).map
+endif
+
+ifneq ($(LDSCRIPT),)
+LDFLAGS += -Wl,-T$(LDSCRIPT)
+endif
+
+DEPDIR = .deps
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+ @echo " LINK $@"
+ @$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
+
+ifneq ($(LDSCRIPT),)
+$(TARGET): $(LDSCRIPT)
+endif
+
+%.o: %.c
+ @echo " COMPILE $<"
+ @mkdir -p $(DEPDIR)
+ @$(CC) $(CFLAGS) $(DEFINES) -Wp,-MMD,$(DEPDIR)/$(*F).d,-MQ,"$@",-MP -c $< -o $@
+
+%.o: %.s
+ @echo " ASSEMBLE $<"
+ @$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@
+
+%.o: %.S
+ @echo " ASSEMBLE $<"
+ @$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@
+
+clean:
+ rm -rf $(DEPDIR)
+ rm -f $(TARGET) $(TARGET).map $(OBJS)
+
+define bin2o
+ @echo " BIN2S $(notdir $<)"
+ @$(BIN2S) -a 32 $< | $(AS) -o $(@)
+ @echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(<F) | tr . _)`.h
+ @echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(<F) | tr . _)`.h
+ @echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(<F) | tr . _)`.h
+endef
+
+-include $(DEPDIR)/*
+
+.PHONY: clean
+
Oops, something went wrong.

0 comments on commit 31ac9fe

Please sign in to comment.