1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Greg White
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
37 #include "backlight.h"
38 #include "backlight-target.h"
44 #include "rbunicode.h"
54 /* We need to gracefully spin down the disk to prevent clicks. */
57 /* Make sure ATA has been initialized. */
60 /* And put the disk into sleep immediately. */
71 unsigned char* loadbuffer
;
74 int(*kernel_entry
)(void);
77 kernel_init(); /* Need the kernel to sleep */
79 enable_interrupt(IRQ_FIQ_STATUS
);
87 lcd_setfont(FONT_SYSFIXED
);
89 /* These checks should only run if the bootloader is flashed */
93 if(!(GPGDAT
&BUTTON_POWER
) && charger_inserted())
95 while(!(GPGDAT
&BUTTON_POWER
) && charger_inserted())
100 snprintf(msg
,sizeof(msg
),"Charging");
104 snprintf(msg
,sizeof(msg
),"Charge Complete");
107 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* strlen(msg
))) / 2,
108 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
111 #if defined(HAVE_RTC_ALARM)
112 /* Check if the alarm went off while charging */
113 if(rtc_check_alarm_flag())
115 GSTATUS3
=1; /* Normally this is set in crt0.s */
120 if(!(GPGDAT
&BUTTON_POWER
)
121 #if defined(HAVE_RTC_ALARM)
132 const char msg
[] = "HOLD is enabled";
134 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* strlen(msg
))) / 2,
135 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
147 /* Enter USB mode without USB thread */
148 if(usb_detect() == USB_INSERTED
)
150 const char msg
[] = "Bootloader USB mode";
152 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* strlen(msg
))) / 2,
153 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
156 storage_enable(false);
160 while (usb_detect() == USB_INSERTED
)
171 /* Show debug messages if button is pressed */
172 if(button_read_device()&BUTTON_A
)
175 printf("Rockbox boot loader");
176 printf("Version " RBVERSION
);
178 sleep(50); /* ATA seems to error without this pause */
184 error(EATA
, rc
, true);
189 rc
= disk_mount_all();
192 error(EDISK
, rc
, true);
195 printf("Loading firmware");
197 /* Flush out anything pending first */
198 cpucache_invalidate();
200 loadbuffer
= (unsigned char*) 0x31000000;
201 buffer_size
= (unsigned char*)0x31400000 - loadbuffer
;
203 rc
= load_firmware(loadbuffer
, BOOTFILE
, buffer_size
);
205 error(EBOOTFILE
, rc
, true);
208 system_prepare_fw_start();
212 cpucache_invalidate();
213 kernel_entry
= (void*) loadbuffer
;
222 /* Return and restart */