1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Maurus Cuelenaere
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 ****************************************************************************/
24 #include "backlight.h"
25 #include "backlight-target.h"
37 extern int show_logo(void);
39 static void show_splash(int timeout
, const char *msg
)
42 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* strlen(msg
))) / 2,
43 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
49 static void usb_mode(void)
55 usb_start_monitoring();
57 /* Wait for threads to connect */
58 show_splash(HZ
/2, "Waiting for USB");
62 button
= button_get_w_tmo(HZ
/2);
64 if (button
== SYS_USB_CONNECTED
)
68 if (button
== SYS_USB_CONNECTED
)
70 /* Got the message - wait for disconnect */
71 show_splash(0, "Bootloader USB mode");
73 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
77 button
= button_get(true);
78 if (button
== SYS_USB_DISCONNECTED
)
80 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
89 static int boot_of(void)
91 int fd
, rc
, len
, i
, checksum
= 0;
92 void (*kernel_entry
)(int, void*, void*);
94 /* TODO: get this from the NAND flash instead of SD */
95 fd
= open("/ccpmp.bin", O_RDONLY
);
97 return EFILE_NOT_FOUND
;
99 lseek(fd
, 4, SEEK_SET
);
100 rc
= read(fd
, (char*)&len
, 4); /* CPU is LE */
102 return EREAD_IMAGE_FAILED
;
105 printf("Reading %d bytes...", len
);
107 lseek(fd
, 0, SEEK_SET
);
108 rc
= read(fd
, (void*)0x80004000, len
);
110 return EREAD_IMAGE_FAILED
;
115 checksum
+= ((unsigned char*)0x80004000)[i
];
117 *((unsigned int*)0x80004000) = checksum
;
119 printf("Starting the OF...");
121 /* OF requires all clocks on */
125 __dcache_writeback_all();
126 __icache_invalidate_all();
128 for(i
=8000; i
>0; i
--)
129 asm volatile("nop\n");
131 kernel_entry
= (void*) 0x80004008;
132 kernel_entry(0, "Jan 10 2008", "15:34:42"); /* Reversed from the SPL */
140 #ifdef HAVE_TOUCHSCREEN
143 void (*kernel_entry
)(void);
148 lcd_setfont(FONT_SYSFIXED
);
158 #ifdef HAVE_TOUCHSCREEN
159 rc
= button_read_device(&dummy
);
161 rc
= button_read_device();
167 if(rc
& BUTTON_VOL_UP
)
172 printf(MODEL_NAME
" Rockbox Bootloader");
173 printf("Version "APPSVERSION
);
175 rc
= disk_mount_all();
183 printf("Error: %s", strerror(rc
));
186 printf("Loading firmware");
187 rc
= load_firmware((unsigned char *)CONFIG_SDRAM_START
, BOOTFILE
, 0x400000);
189 printf("Error: %s", strerror(rc
));
193 printf("Starting Rockbox...");
194 adc_close(); /* Disable SADC */
195 _backlight_off(); /* Force backlight off to prevent LCD 'flicker' */
198 kernel_entry
= (void*) CONFIG_SDRAM_START
;