1 // Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
2 // This code is licensed to you under the terms of the GNU GPL, version 2;
3 // see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
8 static u8 *const code_buffer = (u8 *)0x90100000;
9 static u8 *const trampoline_buffer = (u8 *)0x80001800;
11 static void dsp_reset(void)
13 write16(0x0c00500a, read16(0x0c00500a) & ~0x01f8);
14 write16(0x0c00500a, read16(0x0c00500a) | 0x0010);
15 write16(0x0c005036, 0);
18 static u32 reboot_trampoline[] = {
19 0x3c209000, // lis 1,0x9000
20 0x60210020, // ori 1,1,0x0020
21 0x7c2903a6, // mtctr 1
31 printf("SD card not found (%d)\n", err);
37 printf("SD card detected\n");
39 printf("SD card not detected (%d)\n", err);
43 // if (usbgecko_checkgecko())
44 // printf("USBGecko serial interface detected\n");
46 // printf("USBGecko serial interface not detected\n");
48 printf("Opening boot.elf:\n");
49 err = fat_open("boot.elf");
52 printf("boot.elf not found (%d)\n", err);
56 extern u32 fat_file_size;
58 printf("reading %d bytes...\n", fat_file_size);
59 err = fat_read(code_buffer, fat_file_size);
61 printf("Error %d reading file\n", err);
69 int try_usbgecko_load(void)
71 if (!usbgecko_checkgecko()) {
72 printf("USBGecko not found\n");
76 #define FLASH_OFFSET 0x30000
77 int i, size = usbgecko_flash_read32(FLASH_OFFSET);
79 printf("Invalid code size in usbgecko flash (%d)\n", size);
82 printf("Loading %d bytes from USBGecko flash (offset=%x)\n",
83 size, FLASH_OFFSET+4);
85 for (i=0; i < size; i++)
86 code_buffer[i] = usbgecko_flash_read8(FLASH_OFFSET + 4 + i);
97 // Install trampoline at 80001800; some payloads like to jump
98 // there to restart. Sometimes this can even work.
99 memcpy(trampoline_buffer, reboot_trampoline, sizeof(reboot_trampoline));
101 // Clear interrupt mask.
102 write32(0x0c003004, 0);
105 write32(0x0d00643c, 0);
110 printf("savezelda %s\n", version);
112 printf("Copyright 2008,2009 Segher Boessenkool\n");
113 printf("Copyright 2008 Haxx Enterprises\n");
114 printf("Copyright 2008 Hector Martin (\"marcan\")\n");
115 printf("Copyright 2003,2004 Felix Domke\n");
117 printf("This code is licensed to you under the terms of the\n");
118 printf("GNU GPL, version 2; see the file COPYING\n");
120 printf("Font and graphics by Freddy Leitner\n");
124 printf("Cleaning up environment... ");
137 err = try_usbgecko_load();
140 printf("No code found to load, hanging.\n");
146 if (valid_elf_image(code_buffer)) {
147 printf("Valid ELF image detected.\n");
148 void (*entry)() = load_elf_image(code_buffer);
150 printf("Program returned to loader, reloading.\n");
152 printf("No valid ELF image detected, retrying.\n");