blob: 27e3a8b3032f70a452231cac2d1a9029d0d93e0a [file] [log] [blame]
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20
21#include <stdlib.h>
22#include <stdio.h>
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +000023#include "inttypes.h"
24#include "string.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000025#include "cpu.h"
26#include "system.h"
27#include "lcd.h"
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +000028#include "lcd-remote.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000029#include "kernel.h"
30#include "thread.h"
31#include "ata.h"
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +000032#include "usb.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000033#include "disk.h"
34#include "font.h"
35#include "adc.h"
36#include "backlight.h"
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +000037#include "backlight-target.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000038#include "button.h"
39#include "panic.h"
40#include "power.h"
41#include "file.h"
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +000042#include "uda1380.h"
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +000043#include "eeprom_settings.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000044
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +000045#include "pcf50606.h"
Linus Nielsen Feltzing46597c92007-02-22 15:09:49 +000046#include "common.h"
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +000047
48#include <stdarg.h>
49
Linus Nielsen Feltzing46597c92007-02-22 15:09:49 +000050/* Maximum allowed firmware image size. 10MB is more than enough */
51#define MAX_LOADSIZE (10*1024*1024)
52
Linus Nielsen Feltzing62c768c2005-07-09 07:46:42 +000053#define DRAM_START 0x31000000
54
Miika Pekkarinen886c3022007-01-13 08:16:02 +000055#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +000056static bool recovery_mode = false;
Miika Pekkarinen886c3022007-01-13 08:16:02 +000057#endif
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +000058
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000059int usb_screen(void)
60{
61 return 0;
62}
63
Linus Nielsen Feltzinga2e8cf72005-07-15 07:42:25 +000064char version[] = APPSVERSION;
65
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +000066/* Reset the cookie for the crt0 crash check */
67inline void __reset_cookie(void)
68{
69 asm(" move.l #0,%d0");
70 asm(" move.l %d0,0x10017ffc");
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +000071}
72
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000073void start_iriver_fw(void)
74{
75 asm(" move.w #0x2700,%sr");
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +000076 __reset_cookie();
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000077 asm(" movec.l %d0,%vbr");
78 asm(" move.l 0,%sp");
79 asm(" lea.l 8,%a0");
80 asm(" jmp (%a0)");
81}
82
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000083void start_firmware(void)
84{
85 asm(" move.w #0x2700,%sr");
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +000086 __reset_cookie();
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +000087 asm(" move.l %0,%%d0" :: "i"(DRAM_START));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000088 asm(" movec.l %d0,%vbr");
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +000089 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START));
90 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4)));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000091 asm(" jmp (%a0)");
92}
93
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +000094#ifdef IRIVER_H100_SERIES
95void start_flashed_romimage(void)
96{
97 uint8_t *src = (uint8_t *)FLASH_ROMIMAGE_ENTRY;
98 int *reset_vector;
99
100 if (!detect_flashed_romimage())
101 return ;
102
103 reset_vector = (int *)(&src[sizeof(struct flash_header)+4]);
104
105 asm(" move.w #0x2700,%sr");
106 __reset_cookie();
107
108 asm(" move.l %0,%%d0" :: "i"(DRAM_START));
109 asm(" movec.l %d0,%vbr");
110 asm(" move.l %0,%%sp" :: "m"(reset_vector[0]));
111 asm(" move.l %0,%%a0" :: "m"(reset_vector[1]));
112 asm(" jmp (%a0)");
113
114 /* Failure */
115 power_off();
116}
117
118void start_flashed_ramimage(void)
119{
120 struct flash_header hdr;
121 unsigned char *buf = (unsigned char *)DRAM_START;
122 uint8_t *src = (uint8_t *)FLASH_RAMIMAGE_ENTRY;
123
124 if (!detect_flashed_ramimage())
125 return;
126
127 /* Load firmware from flash */
128 cpu_boost(true);
129 memcpy(&hdr, src, sizeof(struct flash_header));
130 src += sizeof(struct flash_header);
131 memcpy(buf, src, hdr.length);
132 cpu_boost(false);
133
134 start_firmware();
135
136 /* Failure */
137 power_off();
138}
139#endif /* IRIVER_H100_SERIES */
140
141void shutdown(void)
142{
143 printf("Shutting down...");
144#ifdef HAVE_EEPROM_SETTINGS
145 /* Reset the rockbox crash check. */
146 firmware_settings.bl_version = 0;
147 eeprom_settings_store();
148#endif
149
150 /* We need to gracefully spin down the disk to prevent clicks. */
151 if (ide_powered())
152 {
153 /* Make sure ATA has been initialized. */
154 ata_init();
155
156 /* And put the disk into sleep immediately. */
157 ata_sleepnow();
158 }
159
160 sleep(HZ*2);
161
162 /* Backlight OFF */
163 __backlight_off();
164#ifdef HAVE_REMOTE_LCD
165 __remote_backlight_off();
166#endif
167
168 __reset_cookie();
169 power_off();
170}
171
172/* Print the battery voltage (and a warning message). */
173void check_battery(void)
174{
175 int adc_battery, battery_voltage, batt_int, batt_frac;
176
177 adc_battery = adc_read(ADC_BATTERY);
178
179 battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000;
180 batt_int = battery_voltage / 100;
181 batt_frac = battery_voltage % 100;
182
183 printf("Batt: %d.%02dV", batt_int, batt_frac);
184
185 if (battery_voltage <= 310)
186 {
187 printf("WARNING! BATTERY LOW!!");
188 sleep(HZ*2);
189 }
190}
191
192#ifdef HAVE_EEPROM_SETTINGS
193void initialize_eeprom(void)
194{
195 if (detect_original_firmware())
196 return ;
197
198 if (!eeprom_settings_init())
199 {
200 recovery_mode = true;
201 return ;
202 }
203
204 /* If bootloader version has not been reset, disk might
205 * not be intact. */
206 if (firmware_settings.bl_version || !firmware_settings.disk_clean)
207 {
208 firmware_settings.disk_clean = false;
209 recovery_mode = true;
210 }
211
212 firmware_settings.bl_version = EEPROM_SETTINGS_BL_MINVER;
213 eeprom_settings_store();
214}
215
216void try_flashboot(void)
217{
218 if (!firmware_settings.initialized)
219 return ;
220
221 switch (firmware_settings.bootmethod)
222 {
223 case BOOT_DISK:
224 return;
225
226 case BOOT_ROM:
227 start_flashed_romimage();
228 recovery_mode = true;
229 break;
230
231 case BOOT_RAM:
232 start_flashed_ramimage();
233 recovery_mode = true;
234 break;
235
236 default:
237 recovery_mode = true;
238 return;
239 }
240}
241
242static const char *options[] = {
243 "Boot from disk",
244 "Boot RAM image",
245 "Boot ROM image",
246 "Shutdown"
247};
248
249#define FAILSAFE_OPTIONS 4
250void failsafe_menu(void)
251{
252 int timeout = 15;
253 int option = 3;
254 int button;
255 int defopt = -1;
256 char buf[32];
257 int i;
Linus Nielsen Feltzing46597c92007-02-22 15:09:49 +0000258 extern int line;
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000259
260 reset_screen();
261 printf("Bootloader %s", version);
262 check_battery();
263 printf("=========================");
264 line += FAILSAFE_OPTIONS;
265 printf("");
266 printf(" [NAVI] to confirm.");
267 printf(" [REC] to set as default.");
268 printf("");
269
270 if (firmware_settings.initialized)
271 {
272 defopt = firmware_settings.bootmethod;
273 if (defopt < 0 || defopt >= FAILSAFE_OPTIONS)
274 defopt = option;
275 }
276
277 while (timeout > 0)
278 {
279 /* Draw the menu. */
280 line = 3;
281 for (i = 0; i < FAILSAFE_OPTIONS; i++)
282 {
283 char *def = "[DEF]";
284 char *arrow = "->";
285
286 if (i != defopt)
287 def = "";
288 if (i != option)
289 arrow = " ";
290
291 printf("%s %s %s", arrow, options[i], def);
292 }
293
294 snprintf(buf, sizeof(buf), "Time left: %ds", timeout);
295 lcd_puts(0, 10, buf);
296 lcd_update();
297 button = button_get_w_tmo(HZ);
298
299 if (button == BUTTON_NONE)
300 {
301 timeout--;
302 continue ;
303 }
304
305 timeout = 15;
306 /* Ignore the ON/PLAY -button because it can cause trouble
307 with the RTC alarm mod. */
308 switch (button & ~(BUTTON_ON))
309 {
310 case BUTTON_UP:
311 case BUTTON_RC_REW:
312 if (option > 0)
313 option--;
314 break ;
315
316 case BUTTON_DOWN:
317 case BUTTON_RC_FF:
318 if (option < FAILSAFE_OPTIONS-1)
319 option++;
320 break ;
321
322 case BUTTON_SELECT:
323 case BUTTON_RC_ON:
324 timeout = 0;
325 break ;
326
327 case BUTTON_REC:
328 case BUTTON_RC_REC:
329 if (firmware_settings.initialized)
330 {
331 firmware_settings.bootmethod = option;
332 eeprom_settings_store();
333 defopt = option;
334 }
335 break ;
336 }
337 }
338
339 lcd_puts(0, 10, "Executing command...");
340 lcd_update();
341 sleep(HZ);
342 reset_screen();
343
344 switch (option)
345 {
346 case BOOT_DISK:
347 return ;
348
349 case BOOT_RAM:
350 start_flashed_ramimage();
351 printf("Image not found");
352 break;
353
354 case BOOT_ROM:
355 start_flashed_romimage();
356 printf("Image not found");
357 break;
358 }
359
360 shutdown();
361}
362#endif
363
Linus Nielsen Feltzingb8a00d22005-02-10 21:55:48 +0000364void main(void)
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000365{
366 int i;
367 int rc;
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000368 bool rc_on_button = false;
369 bool on_button = false;
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000370 bool rec_button = false;
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000371 bool hold_status = false;
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000372 int data;
Linus Nielsen Feltzing46597c92007-02-22 15:09:49 +0000373 extern int line;
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000374
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000375 /* We want to read the buttons as early as possible, before the user
376 releases the ON button */
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000377
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000378 /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs
379 (The ON and Hold buttons on the main unit and the remote) */
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +0000380 or_l(0x00100062, &GPIO1_FUNCTION);
381 and_l(~0x00100062, &GPIO1_ENABLE);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000382
383 data = GPIO1_READ;
384 if ((data & 0x20) == 0)
385 on_button = true;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000386
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000387 if ((data & 0x40) == 0)
388 rc_on_button = true;
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000389
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000390 /* Set the default state of the hard drive power to OFF */
391 ide_power_enable(false);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000392
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000393 power_init();
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000394
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000395 /* Turn off if neither ON button is pressed */
Linus Nielsen Feltzing54da9242006-01-10 23:11:57 +0000396 if(!(on_button || rc_on_button || usb_detect()))
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000397 {
398 __reset_cookie();
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000399 power_off();
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000400 }
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000401
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000402 /* Start with the main backlight OFF. */
403 __backlight_init();
404 __backlight_off();
405
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000406 /* Remote backlight ON */
407#ifdef HAVE_REMOTE_LCD
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000408 __remote_backlight_on();
Linus Nielsen Feltzingb68cb9b2005-12-03 00:54:59 +0000409#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000410
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000411 system_init();
412 kernel_init();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000413
414#ifdef HAVE_ADJUSTABLE_CPU_FREQ
415 /* Set up waitstates for the peripherals */
416 set_cpu_frequency(0); /* PLL off */
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000417#ifdef CPU_COLDFIRE
418 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
419#endif
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000420#endif
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000421 set_irq_level(0);
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +0000422
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000423#ifdef HAVE_EEPROM_SETTINGS
424 initialize_eeprom();
425#endif
426
427 adc_init();
428 button_init();
429
430 if ((on_button && button_hold()) ||
431 (rc_on_button && remote_button_hold()))
432 {
433 hold_status = true;
434 }
435
436 /* Power on the hard drive early, to speed up the loading.
437 Some H300 don't like this, so we only do it for the H100 */
438#ifndef IRIVER_H300_SERIES
Miika Pekkarinen20171c12007-01-13 09:08:18 +0000439 if (!hold_status
440# ifdef HAVE_EEPROM_SETTINGS
441 && !recovery_mode
442# endif
443 )
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000444 {
445 ide_power_enable(true);
446 }
447
Miika Pekkarinen20171c12007-01-13 09:08:18 +0000448# ifdef EEPROM_SETTINGS
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000449 if (!hold_status && !usb_detect() && !recovery_mode)
450 try_flashboot();
Miika Pekkarinen20171c12007-01-13 09:08:18 +0000451# endif
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000452#endif
453
454 backlight_init();
Linus Nielsen Feltzing2fcd1b02006-02-04 23:09:56 +0000455#ifdef HAVE_UDA1380
Marcoen Hirschberg6c2e1b82006-12-06 10:36:20 +0000456 audiohw_reset();
Linus Nielsen Feltzing2fcd1b02006-02-04 23:09:56 +0000457#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000458
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000459 lcd_init();
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000460#ifdef HAVE_REMOTE_LCD
461 lcd_remote_init();
462#endif
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000463 font_init();
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000464
465 lcd_setfont(FONT_SYSFIXED);
466
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000467 printf("Rockbox boot loader");
468 printf("Version %s", version);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000469
Linus Nielsen Feltzingb8a00d22005-02-10 21:55:48 +0000470 sleep(HZ/50); /* Allow the button driver to check the buttons */
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000471 rec_button = ((button_status() & BUTTON_REC) == BUTTON_REC)
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000472 || ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000473
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000474 check_battery();
475
Miika Pekkarinen22860a92006-08-11 19:59:16 +0000476 /* Don't start if the Hold button is active on the device you
477 are starting with */
Miika Pekkarinen20171c12007-01-13 09:08:18 +0000478 if (!usb_detect() && (hold_status
479#ifdef HAVE_EEPROM_SETTINGS
480 || recovery_mode
481#endif
482 ))
Miika Pekkarinen22860a92006-08-11 19:59:16 +0000483 {
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000484 if (detect_original_firmware())
485 {
486 printf("Hold switch on");
487 shutdown();
488 }
489
Miika Pekkarinen20171c12007-01-13 09:08:18 +0000490#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000491 failsafe_menu();
Miika Pekkarinen22860a92006-08-11 19:59:16 +0000492#endif
Miika Pekkarinen22860a92006-08-11 19:59:16 +0000493 }
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000494
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000495 /* Holding REC while starting runs the original firmware */
496 if (detect_original_firmware() && rec_button)
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000497 {
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000498 printf("Starting original firmware...");
499 start_iriver_fw();
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000500 }
501
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000502 usb_init();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000503
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000504 rc = ata_init();
505 if(rc)
506 {
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000507 reset_screen();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000508 printf("ATA error: %d", rc);
509 printf("Insert USB cable and press");
510 printf("a button");
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000511 while(!(button_get(true) & BUTTON_REL));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000512 }
513
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000514 /* A hack to enter USB mode without using the USB thread */
515 if(usb_detect())
516 {
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000517 const char msg[] = "Bootloader USB mode";
518 int w, h;
519 font_getstringsize(msg, &w, &h, FONT_SYSFIXED);
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000520 reset_screen();
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000521 lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, msg);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000522 lcd_update();
523
Linus Nielsen Feltzing780cfff2006-01-11 15:37:08 +0000524#ifdef IRIVER_H300_SERIES
525 sleep(HZ);
526#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000527
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000528#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000529 if (firmware_settings.initialized)
530 {
531 firmware_settings.disk_clean = false;
532 eeprom_settings_store();
533 }
534#endif
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000535 ata_spin();
536 ata_enable(false);
537 usb_enable(true);
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000538 cpu_idle_mode(true);
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000539 while (usb_detect())
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000540 {
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000541 /* Print the battery status. */
542 line = 0;
543 check_battery();
544
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000545 ata_spin(); /* Prevent the drive from spinning down */
546 sleep(HZ);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000547
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000548 /* Backlight OFF */
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000549 __backlight_off();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000550 }
551
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000552 cpu_idle_mode(false);
Linus Nielsen Feltzing13103902005-07-19 11:03:00 +0000553 usb_enable(false);
554 ata_init(); /* Reinitialize ATA and continue booting */
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000555
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000556 reset_screen();
Linus Nielsen Feltzing13103902005-07-19 11:03:00 +0000557 lcd_update();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000558 }
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000559
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000560 disk_init();
561
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000562 rc = disk_mount_all();
563 if (rc<=0)
564 {
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000565 reset_screen();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000566 printf("No partition found");
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000567 while(button_get(true) != SYS_USB_CONNECTED) {};
568 }
569
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000570 printf("Loading firmware");
Linus Nielsen Feltzing46597c92007-02-22 15:09:49 +0000571 i = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE);
572 printf("Result: %d", strerror(i));
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000573
Linus Nielsen Feltzing46597c92007-02-22 15:09:49 +0000574 if (i == EOK)
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000575 start_firmware();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000576
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000577 if (!detect_original_firmware())
Miika Pekkarinen973ee5d2006-09-04 16:06:11 +0000578 {
579 printf("No firmware found on disk");
Linus Nielsen Feltzing46597c92007-02-22 15:09:49 +0000580 sleep(HZ*2);
Miika Pekkarinen35b0c3f2007-01-12 20:45:37 +0000581 shutdown();
Miika Pekkarinen973ee5d2006-09-04 16:06:11 +0000582 }
583 else
584 start_iriver_fw();
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000585}
586
587/* These functions are present in the firmware library, but we reimplement
588 them here because the originals do a lot more than we want */
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000589void screen_dump(void)
590{
591}