Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 by Dave Chapman |
| 11 | * |
| 12 | * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing |
| 13 | * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach |
| 14 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version 2 |
| 18 | * of the License, or (at your option) any later version. |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 19 | * |
| 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 21 | * KIND, either express or implied. |
| 22 | * |
| 23 | ****************************************************************************/ |
| 24 | #include "config.h" |
| 25 | |
| 26 | #include <stdlib.h> |
| 27 | #include <stdio.h> |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 28 | #include <string.h> |
Linus Nielsen Feltzing | f3f0d1c | 2007-01-16 23:12:02 +0000 | [diff] [blame] | 29 | #include <stdarg.h> |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 30 | #include "cpu.h" |
| 31 | #include "system.h" |
| 32 | #include "lcd.h" |
Michael Sevakis | 4ea4cdf | 2014-08-08 02:28:11 -0400 | [diff] [blame] | 33 | #include "../kernel-internal.h" |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 34 | #include "ata.h" |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 35 | #include "file_internal.h" |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 36 | #include "disk.h" |
| 37 | #include "font.h" |
| 38 | #include "adc.h" |
Jens Arnold | afd5174 | 2007-11-21 21:28:46 +0000 | [diff] [blame] | 39 | #include "backlight.h" |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 40 | #include "panic.h" |
| 41 | #include "power.h" |
| 42 | #include "file.h" |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 43 | #include "common.h" |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 44 | #include "rb-loader.h" |
| 45 | #include "loader_strerror.h" |
Dave Chapman | ebc076b | 2007-07-25 13:12:38 +0000 | [diff] [blame] | 46 | #include "hwcompat.h" |
Torne Wuff | 0d24df8 | 2010-04-13 22:17:42 +0000 | [diff] [blame] | 47 | #include "usb.h" |
Rafaël Carré | 5d236b2 | 2010-05-27 09:41:46 +0000 | [diff] [blame] | 48 | #include "version.h" |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 49 | |
Dave Chapman | 8adc81d | 2006-02-21 21:13:03 +0000 | [diff] [blame] | 50 | #define XSC(X) #X |
| 51 | #define SC(X) XSC(X) |
| 52 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 53 | /* Maximum allowed firmware image size. The largest known current |
| 54 | (December 2006) firmware is about 7.5MB (Apple's firmware for the ipod video) |
| 55 | so we set this to 8MB. */ |
| 56 | #define MAX_LOADSIZE (8*1024*1024) |
| 57 | |
| 58 | /* A buffer to load the Linux kernel or Rockbox into */ |
| 59 | unsigned char *loadbuffer = (unsigned char *)DRAM_START; |
| 60 | |
Frank Dischner | 5d9eccd | 2006-04-19 18:06:56 +0000 | [diff] [blame] | 61 | #if CONFIG_KEYPAD == IPOD_4G_PAD && !defined(IPOD_MINI) |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 62 | /* check if number of seconds has past */ |
| 63 | int timer_check(int clock_start, unsigned int usecs) |
| 64 | { |
Dave Chapman | fa74356 | 2006-02-05 19:05:55 +0000 | [diff] [blame] | 65 | if ((USEC_TIMER - clock_start) >= usecs) { |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 66 | return 1; |
| 67 | } else { |
| 68 | return 0; |
| 69 | } |
| 70 | } |
| 71 | |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 72 | static void ser_opto_keypad_cfg(int val) |
| 73 | { |
| 74 | int start_time; |
| 75 | |
Barry Wardell | 8b06125 | 2007-03-03 17:25:20 +0000 | [diff] [blame] | 76 | GPIOB_ENABLE &=~ 0x80; |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 77 | |
| 78 | outl(inl(0x7000c104) | 0xc000000, 0x7000c104); |
| 79 | outl(val, 0x7000c120); |
| 80 | outl(inl(0x7000c100) | 0x80000000, 0x7000c100); |
| 81 | |
Barry Wardell | 8b06125 | 2007-03-03 17:25:20 +0000 | [diff] [blame] | 82 | GPIOB_OUTPUT_VAL &=~ 0x10; |
| 83 | GPIOB_OUTPUT_EN |= 0x10; |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 84 | |
Dave Chapman | fa74356 | 2006-02-05 19:05:55 +0000 | [diff] [blame] | 85 | start_time = USEC_TIMER; |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 86 | do { |
| 87 | if ((inl(0x7000c104) & 0x80000000) == 0) { |
| 88 | break; |
| 89 | } |
| 90 | } while (timer_check(start_time, 1500) != 0); |
| 91 | |
| 92 | outl(inl(0x7000c100) & ~0x80000000, 0x7000c100); |
| 93 | |
Barry Wardell | 8b06125 | 2007-03-03 17:25:20 +0000 | [diff] [blame] | 94 | GPIOB_ENABLE |= 0x80; |
| 95 | GPIOB_OUTPUT_VAL |= 0x10; |
| 96 | GPIOB_OUTPUT_EN &=~0x10; |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 97 | |
| 98 | outl(inl(0x7000c104) | 0xc000000, 0x7000c104); |
| 99 | outl(inl(0x7000c100) | 0x60000000, 0x7000c100); |
| 100 | } |
| 101 | |
| 102 | int opto_keypad_read(void) |
| 103 | { |
| 104 | int loop_cnt, had_io = 0; |
| 105 | |
| 106 | for (loop_cnt = 5; loop_cnt != 0;) |
| 107 | { |
| 108 | int key_pressed = 0; |
| 109 | int start_time; |
| 110 | unsigned int key_pad_val; |
| 111 | |
| 112 | ser_opto_keypad_cfg(0x8000023a); |
| 113 | |
Dave Chapman | fa74356 | 2006-02-05 19:05:55 +0000 | [diff] [blame] | 114 | start_time = USEC_TIMER; |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 115 | do { |
| 116 | if (inl(0x7000c104) & 0x4000000) { |
| 117 | had_io = 1; |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | if (had_io != 0) { |
| 122 | break; |
| 123 | } |
| 124 | } while (timer_check(start_time, 1500) != 0); |
| 125 | |
| 126 | key_pad_val = inl(0x7000c140); |
| 127 | if ((key_pad_val & ~0x7fff0000) != 0x8000023a) { |
| 128 | loop_cnt--; |
| 129 | } else { |
| 130 | key_pad_val = (key_pad_val << 11) >> 27; |
| 131 | key_pressed = 1; |
| 132 | } |
| 133 | |
| 134 | outl(inl(0x7000c100) | 0x60000000, 0x7000c100); |
| 135 | outl(inl(0x7000c104) | 0xc000000, 0x7000c104); |
| 136 | |
| 137 | if (key_pressed != 0) { |
| 138 | return key_pad_val ^ 0x1f; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
Dave Chapman | fa74356 | 2006-02-05 19:05:55 +0000 | [diff] [blame] | 144 | #endif |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 145 | |
| 146 | static int key_pressed(void) |
| 147 | { |
| 148 | unsigned char state; |
| 149 | |
Dave Chapman | fa74356 | 2006-02-05 19:05:55 +0000 | [diff] [blame] | 150 | #if CONFIG_KEYPAD == IPOD_4G_PAD |
Jens Arnold | 7f88088 | 2006-04-02 00:20:11 +0000 | [diff] [blame] | 151 | #ifdef IPOD_MINI /* mini 1G only */ |
Dave Chapman | 2850791 | 2006-02-27 12:35:05 +0000 | [diff] [blame] | 152 | state = GPIOA_INPUT_VAL & 0x3f; |
Frank Dischner | 5d9eccd | 2006-04-19 18:06:56 +0000 | [diff] [blame] | 153 | if ((state & 0x10) == 0) return BUTTON_LEFT; |
| 154 | if ((state & 0x2) == 0) return BUTTON_MENU; |
| 155 | if ((state & 0x4) == 0) return BUTTON_PLAY; |
| 156 | if ((state & 0x8) == 0) return BUTTON_RIGHT; |
Dave Chapman | 2850791 | 2006-02-27 12:35:05 +0000 | [diff] [blame] | 157 | #else |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 158 | state = opto_keypad_read(); |
| 159 | if ((state & 0x4) == 0) return BUTTON_LEFT; |
| 160 | if ((state & 0x10) == 0) return BUTTON_MENU; |
| 161 | if ((state & 0x8) == 0) return BUTTON_PLAY; |
| 162 | if ((state & 0x2) == 0) return BUTTON_RIGHT; |
Frank Dischner | 5d9eccd | 2006-04-19 18:06:56 +0000 | [diff] [blame] | 163 | #endif |
Jens Arnold | 90eacb2 | 2007-07-27 07:32:55 +0000 | [diff] [blame] | 164 | #elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_1G2G_PAD) |
| 165 | state = GPIOA_INPUT_VAL; |
Dave Chapman | fa74356 | 2006-02-05 19:05:55 +0000 | [diff] [blame] | 166 | if ((state & 0x08) == 0) return BUTTON_LEFT; |
| 167 | if ((state & 0x10) == 0) return BUTTON_MENU; |
| 168 | if ((state & 0x04) == 0) return BUTTON_PLAY; |
| 169 | if ((state & 0x01) == 0) return BUTTON_RIGHT; |
| 170 | #endif |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 174 | bool button_hold(void) |
| 175 | { |
Jens Arnold | 90eacb2 | 2007-07-27 07:32:55 +0000 | [diff] [blame] | 176 | #if CONFIG_KEYPAD == IPOD_1G2G_PAD |
| 177 | return (GPIOA_INPUT_VAL & 0x20); |
| 178 | #else |
| 179 | return !(GPIOA_INPUT_VAL & 0x20); |
| 180 | #endif |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 183 | void fatal_error(void) |
| 184 | { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 185 | extern int line; |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 186 | bool holdstatus=false; |
| 187 | |
Dave Chapman | 0025a97 | 2006-12-17 10:23:51 +0000 | [diff] [blame] | 188 | /* System font is 6 pixels wide */ |
Jens Arnold | 90eacb2 | 2007-07-27 07:32:55 +0000 | [diff] [blame] | 189 | #if defined(IPOD_1G2G) || defined(IPOD_3G) |
Torne Wuff | 0d24df8 | 2010-04-13 22:17:42 +0000 | [diff] [blame] | 190 | printf("Insert Firewire cable, or"); |
| 191 | printf("hold MENU+PLAY to reboot"); |
| 192 | printf("then REW+FF for disk mode"); |
Jens Arnold | 90eacb2 | 2007-07-27 07:32:55 +0000 | [diff] [blame] | 193 | #elif LCD_WIDTH >= (30*6) |
Torne Wuff | 0d24df8 | 2010-04-13 22:17:42 +0000 | [diff] [blame] | 194 | printf("Insert USB cable, or"); |
| 195 | printf("hold MENU+SELECT to reboot"); |
Linus Nielsen Feltzing | f3f0d1c | 2007-01-16 23:12:02 +0000 | [diff] [blame] | 196 | printf("then SELECT+PLAY for disk mode"); |
Dave Chapman | 0025a97 | 2006-12-17 10:23:51 +0000 | [diff] [blame] | 197 | #else |
Torne Wuff | 0d24df8 | 2010-04-13 22:17:42 +0000 | [diff] [blame] | 198 | printf("Insert USB cable, or"); |
| 199 | printf("hold MENU+SELECT to"); |
Linus Nielsen Feltzing | f3f0d1c | 2007-01-16 23:12:02 +0000 | [diff] [blame] | 200 | printf("reboot then SELECT+PLAY"); |
| 201 | printf("for disk mode"); |
Dave Chapman | 0025a97 | 2006-12-17 10:23:51 +0000 | [diff] [blame] | 202 | #endif |
Dave Chapman | 7d79db2 | 2007-05-22 19:05:14 +0000 | [diff] [blame] | 203 | lcd_update(); |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 204 | |
Torne Wuff | 0d24df8 | 2010-04-13 22:17:42 +0000 | [diff] [blame] | 205 | usb_init(); |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 206 | while (1) { |
| 207 | if (button_hold() != holdstatus) { |
| 208 | if (button_hold()) { |
| 209 | holdstatus=true; |
| 210 | lcd_puts(0, line, "Hold switch on!"); |
| 211 | } else { |
| 212 | holdstatus=false; |
| 213 | lcd_puts(0, line, " "); |
| 214 | } |
| 215 | lcd_update(); |
| 216 | } |
Torne Wuff | 0d24df8 | 2010-04-13 22:17:42 +0000 | [diff] [blame] | 217 | if (usb_detect() == USB_INSERTED) { |
| 218 | ata_sleepnow(); /* Immediately spindown the disk. */ |
| 219 | sleep(HZ*2); |
| 220 | #if CONFIG_CPU == PP5020 |
| 221 | memcpy((void *)0x40017f00, "diskmode\0\0hotstuff\0\0\1", 21); |
| 222 | #elif CONFIG_CPU == PP5022 |
| 223 | memcpy((void *)0x4001ff00, "diskmode\0\0hotstuff\0\0\1", 21); |
| 224 | #elif CONFIG_CPU == PP5002 |
| 225 | memcpy((void *)0x40017f00, "diskmodehotstuff\1", 17); |
| 226 | #endif /* CONFIG_CPU */ |
| 227 | system_reboot(); /* Reboot */ |
| 228 | } |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 229 | udelay(100000); /* 100ms */ |
| 230 | } |
| 231 | |
| 232 | } |
| 233 | |
Dave Chapman | 49fccaf | 2009-05-12 20:41:44 +0000 | [diff] [blame] | 234 | /* The bootloader is started from the OSOS image on the firmware |
| 235 | * partition. There are several ways it can be installed there: |
| 236 | * appended to the Apple firmware, on its own, or appended to |
| 237 | * Rockbox itself. The Apple ROM loader loads the entire OSOS |
| 238 | * image to DRAM_START, whatever it contains. If the bootloader |
| 239 | * is appended to another image then it will've modified the |
| 240 | * entry point in the OSOS header such that the ROM will call the |
| 241 | * bootloader rather than the main image. |
| 242 | * |
| 243 | * So, once the bootloader has control: |
| 244 | * |
| 245 | * 1) If the hold switch is on, or the menu button is being held, |
| 246 | * try to boot the Apple firmware. |
| 247 | * 1a) First, it looks for apple_os.ipod on the FAT32 partition, |
| 248 | * in .rockbox or the root directory. If found it loads that |
| 249 | * without further checking and runs it. |
| 250 | * 1b) Next, it checks to see if the OSOS image already loaded |
| 251 | * into RAM is in fact the Apple firmware with the bootloader |
| 252 | * appended. It looks at DRAM_START+0x20 for the string |
| 253 | * "portalplayer", and if it's there, just jumps back to |
| 254 | * DRAM_START where the entry point was before the bootloader |
| 255 | * was appended. |
| 256 | * 1c) If neither of those worked, it displays an error and dies. |
| 257 | * |
| 258 | * 2) If the play button is being held, try to boot Linux. It looks |
| 259 | * for linux.bin in the root directory, and if it's not there, |
| 260 | * it displays an error and dies. |
| 261 | * |
| 262 | * 3) Otherwise, try to boot Rockbox. |
| 263 | * 3a) First, it looks for rockbox.ipod on the FAT32 partition, |
| 264 | * in .rockbox or the root directory. If found it loads that |
| 265 | * without further checking and runs it. |
| 266 | * 3b) Next, it checks to see if the OSOS image already loaded |
| 267 | * into RAM is in fact Rockbox with the bootloader appended. |
| 268 | * It looks at DRAM_START+0x20 for the string "Rockbox\1" |
| 269 | * (which is inserted there in crt0-pp.S), and if it's there, |
| 270 | * just humps back to DRAM_START where the entry point was |
| 271 | * before the bootloader was appended. |
| 272 | * 3c) If neither of those worked, it displays an error and dies. |
| 273 | * |
| 274 | * The result is that any of the three install configurations work, |
| 275 | * and that images of apple_os.ipod or rockbox.ipod on the FAT32 |
| 276 | * partition take priority over the contents of OSOS (this avoids |
| 277 | * upgrades failing to work if OSOS is not updated). |
| 278 | * |
| 279 | * Loading from OSOS is somewhat faster than loading from FAT32, |
| 280 | * because the Apple ROM doesn't have to deal with filesystems or |
| 281 | * fragmentation, and is already loading from OSOS anyway. Thus, |
| 282 | * the fastest boot configuration that still allows dual booting |
| 283 | * is to install Rockbox into OSOS with the bootloader appended |
| 284 | * (and delete/rename rockbox.ipod from the FAT32 partition). |
| 285 | * |
| 286 | * It is of course faster to just install Rockbox to OSOS alone, |
| 287 | * but then it's impossible to boot the Apple firmware. |
| 288 | */ |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 289 | |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 290 | void* main(void) |
| 291 | { |
| 292 | char buf[256]; |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 293 | int i; |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 294 | int btn; |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 295 | int rc; |
Dave Chapman | 49fccaf | 2009-05-12 20:41:44 +0000 | [diff] [blame] | 296 | bool haveramos; |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 297 | bool button_was_held; |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 298 | struct partinfo pinfo; |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 299 | unsigned short* identify_info; |
| 300 | |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 301 | /* Check the button hold status as soon as possible - to |
| 302 | give the user maximum chance to turn it off in order to |
| 303 | reset the settings in rockbox. */ |
| 304 | button_was_held = button_hold(); |
| 305 | |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 306 | system_init(); |
| 307 | kernel_init(); |
Jens Arnold | afd5174 | 2007-11-21 21:28:46 +0000 | [diff] [blame] | 308 | |
| 309 | #ifndef HAVE_BACKLIGHT_INVERSION |
| 310 | backlight_init(); /* Turns on the backlight */ |
| 311 | #endif |
| 312 | |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 313 | lcd_init(); |
| 314 | font_init(); |
| 315 | |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 316 | #ifdef HAVE_LCD_COLOR |
| 317 | lcd_set_foreground(LCD_WHITE); |
| 318 | lcd_set_background(LCD_BLACK); |
| 319 | lcd_clear_display(); |
| 320 | #endif |
| 321 | |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 322 | #if 0 |
| 323 | /* ADC and button drivers are not yet implemented */ |
| 324 | adc_init(); |
| 325 | button_init(); |
| 326 | #endif |
| 327 | |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 328 | btn=key_pressed(); |
| 329 | |
| 330 | /* Enable bootloader messages */ |
| 331 | if (btn==BUTTON_RIGHT) |
| 332 | verbose = true; |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 333 | |
| 334 | lcd_setfont(FONT_SYSFIXED); |
| 335 | |
Linus Nielsen Feltzing | f3f0d1c | 2007-01-16 23:12:02 +0000 | [diff] [blame] | 336 | printf("Rockbox boot loader"); |
Michael Sevakis | 95a4c3a | 2014-08-28 10:26:45 -0400 | [diff] [blame] | 337 | printf("Version: %s", rbversion); |
Linus Nielsen Feltzing | f3f0d1c | 2007-01-16 23:12:02 +0000 | [diff] [blame] | 338 | printf("IPOD version: 0x%08x", IPOD_HW_REVISION); |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 339 | |
| 340 | i=ata_init(); |
| 341 | if (i==0) { |
| 342 | identify_info=ata_get_identify(); |
| 343 | /* Show model */ |
| 344 | for (i=0; i < 20; i++) { |
| 345 | ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]); |
| 346 | } |
| 347 | buf[40]=0; |
| 348 | for (i=39; i && buf[i]==' '; i--) { |
| 349 | buf[i]=0; |
| 350 | } |
Linus Nielsen Feltzing | f3f0d1c | 2007-01-16 23:12:02 +0000 | [diff] [blame] | 351 | printf(buf); |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 352 | } else { |
Linus Nielsen Feltzing | f3f0d1c | 2007-01-16 23:12:02 +0000 | [diff] [blame] | 353 | printf("ATA: %d", i); |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 356 | filesystem_init(); |
| 357 | |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 358 | rc = disk_mount_all(); |
| 359 | if (rc<=0) |
| 360 | { |
Linus Nielsen Feltzing | f3f0d1c | 2007-01-16 23:12:02 +0000 | [diff] [blame] | 361 | printf("No partition found"); |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 362 | fatal_error(); |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 365 | disk_partinfo(1, &pinfo); |
Frank Gevaerts | ac355de | 2008-11-21 15:20:25 +0000 | [diff] [blame] | 366 | printf("Partition 1: 0x%02x %ld sectors", |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 367 | pinfo.type, pinfo.size); |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 368 | |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 369 | if (button_was_held || (btn==BUTTON_MENU)) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 370 | /* If either the hold switch was on, or the Menu button was held, then |
| 371 | try the Apple firmware */ |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 372 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 373 | printf("Loading original firmware..."); |
| 374 | |
| 375 | /* First try an apple_os.ipod file on the FAT32 partition |
| 376 | (either in .rockbox or the root) |
| 377 | */ |
| 378 | |
| 379 | rc=load_firmware(loadbuffer, "apple_os.ipod", MAX_LOADSIZE); |
| 380 | |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 381 | if (rc > 0) { |
Dave Chapman | a02c426 | 2007-03-06 14:05:43 +0000 | [diff] [blame] | 382 | printf("apple_os.ipod loaded."); |
| 383 | return (void*)DRAM_START; |
| 384 | } else if (rc == EFILE_NOT_FOUND) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 385 | /* If apple_os.ipod doesn't exist, then check if there is an Apple |
| 386 | firmware image in RAM */ |
Dave Chapman | 49fccaf | 2009-05-12 20:41:44 +0000 | [diff] [blame] | 387 | haveramos = (memcmp((void*)(DRAM_START+0x20),"portalplayer",12)==0); |
| 388 | if (haveramos) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 389 | /* We have a copy of the retailos in RAM, lets just run it. */ |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 390 | return (void*)DRAM_START; |
| 391 | } |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 392 | } else { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 393 | printf("Error!"); |
| 394 | printf("Can't load apple_os.ipod:"); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 395 | printf(loader_strerror(rc)); |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 396 | } |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 397 | |
| 398 | /* Everything failed - just loop forever */ |
| 399 | printf("No RetailOS detected"); |
| 400 | |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 401 | } else if (btn==BUTTON_PLAY) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 402 | printf("Loading Linux..."); |
| 403 | rc=load_raw_firmware(loadbuffer, "/linux.bin", MAX_LOADSIZE); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 404 | if (rc <= EFILE_EMPTY) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 405 | printf("Error!"); |
| 406 | printf("Can't load linux.bin:"); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 407 | printf(loader_strerror(rc)); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 408 | } else { |
| 409 | return (void*)DRAM_START; |
| 410 | } |
| 411 | } else { |
| 412 | printf("Loading Rockbox..."); |
| 413 | rc=load_firmware(loadbuffer, BOOTFILE, MAX_LOADSIZE); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 414 | if (rc > 0) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 415 | printf("Rockbox loaded."); |
| 416 | return (void*)DRAM_START; |
Dave Chapman | 49fccaf | 2009-05-12 20:41:44 +0000 | [diff] [blame] | 417 | } else if (rc == EFILE_NOT_FOUND) { |
| 418 | /* if rockbox.ipod doesn't exist, then check if there is a Rockbox |
| 419 | image in RAM */ |
| 420 | haveramos = (memcmp((void*)(DRAM_START+0x20),"Rockbox\1",8)==0); |
| 421 | if (haveramos) { |
| 422 | /* We have a copy of Rockbox in RAM, lets just run it. */ |
| 423 | return (void*)DRAM_START; |
| 424 | } |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 425 | } |
Dave Chapman | 49fccaf | 2009-05-12 20:41:44 +0000 | [diff] [blame] | 426 | |
| 427 | printf("Error!"); |
| 428 | printf("Can't load " BOOTFILE ": "); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 429 | printf(loader_strerror(rc)); |
Dave Chapman | 061f380 | 2005-11-13 20:59:30 +0000 | [diff] [blame] | 430 | } |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 431 | |
| 432 | /* If we get to here, then we haven't been able to load any firmware */ |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 433 | fatal_error(); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 434 | |
Dave Chapman | 02aeacb | 2006-12-17 00:32:54 +0000 | [diff] [blame] | 435 | /* We never get here, but keep gcc happy */ |
| 436 | return (void*)0; |
Dave Chapman | 38e8fb6 | 2005-11-08 00:52:39 +0000 | [diff] [blame] | 437 | } |