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"
51 char version
[] = APPSVERSION
;
55 /* We need to gracefully spin down the disk to prevent clicks. */
58 /* Make sure ATA has been initialized. */
61 /* And put the disk into sleep immediately. */
72 unsigned char* loadbuffer
;
75 int(*kernel_entry
)(void);
82 kernel_init(); /* Need the kernel to sleep */
85 lcd_setfont(FONT_SYSFIXED
);
87 /* These checks should only run if the bootloader is flashed */
91 if(!(GPGDAT
&BUTTON_POWER
) && charger_inserted())
93 while(!(GPGDAT
&BUTTON_POWER
) && charger_inserted())
98 snprintf(msg
,sizeof(msg
),"Charging");
102 snprintf(msg
,sizeof(msg
),"Charge Complete");
105 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* strlen(msg
))) / 2,
106 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
109 #if defined(HAVE_RTC_ALARM)
110 /* Check if the alarm went off while charging */
111 if(rtc_check_alarm_flag())
113 GSTATUS3
=1; /* Normally this is set in crt0.s */
118 if(!(GPGDAT
&BUTTON_POWER
)
119 #if defined(HAVE_RTC_ALARM)
130 const char msg
[] = "HOLD is enabled";
132 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* strlen(msg
))) / 2,
133 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
145 /* Enter USB mode without USB thread */
146 if(usb_detect() == USB_INSERTED
)
148 const char msg
[] = "Bootloader USB mode";
150 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* strlen(msg
))) / 2,
151 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
154 storage_enable(false);
158 while (usb_detect() == USB_INSERTED
)
169 /* Show debug messages if button is pressed */
170 if(button_read_device())
173 printf("Rockbox boot loader");
174 printf("Version %s", version
);
176 sleep(50); /* ATA seems to error without this pause */
187 rc
= disk_mount_all();
193 printf("Loading firmware");
195 loadbuffer
= (unsigned char*) 0x31000000;
196 buffer_size
= (unsigned char*)0x31400000 - loadbuffer
;
198 rc
= load_firmware(loadbuffer
, BOOTFILE
, buffer_size
);
200 error(EBOOTFILE
, rc
);
204 kernel_entry
= (void*) loadbuffer
;