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"
36 extern int show_logo(void);
38 static void show_splash(int timeout
, const char *msg
)
41 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* strlen(msg
))) / 2,
42 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
48 static void usb_mode(void)
54 usb_start_monitoring();
56 /* Wait for threads to connect */
57 show_splash(HZ
/2, "Waiting for USB");
61 button
= button_get_w_tmo(HZ
/2);
63 if (button
== SYS_USB_CONNECTED
)
67 if (button
== SYS_USB_CONNECTED
)
69 /* Got the message - wait for disconnect */
70 show_splash(0, "Bootloader USB mode");
72 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
76 button
= button_get(true);
77 if (button
== SYS_USB_DISCONNECTED
)
79 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
88 static int boot_of(void)
90 int fd
, rc
, len
, i
, checksum
= 0;
91 void (*kernel_entry
)(int, void*, void*);
93 /* TODO: get this from the NAND flash instead of SD */
94 fd
= open("/ccpmp.bin", O_RDONLY
);
96 return EFILE_NOT_FOUND
;
98 lseek(fd
, 4, SEEK_SET
);
99 rc
= read(fd
, (char*)&len
, 4); /* CPU is LE */
101 return EREAD_IMAGE_FAILED
;
104 printf("Reading %d bytes...", len
);
106 lseek(fd
, 0, SEEK_SET
);
107 rc
= read(fd
, (void*)0x80004000, len
);
109 return EREAD_IMAGE_FAILED
;
114 checksum
+= ((unsigned char*)0x80004000)[i
];
116 *((unsigned int*)0x80004000) = checksum
;
118 printf("Starting the OF...");
120 /* OF requires all clocks on */
124 __dcache_writeback_all();
125 __icache_invalidate_all();
127 for(i
=8000; i
>0; i
--)
128 asm volatile("nop\n");
130 kernel_entry
= (void*) 0x80004008;
131 kernel_entry(0, "Jan 10 2008", "15:34:42"); /* Reversed from the SPL */
139 #ifdef HAVE_TOUCHSCREEN
142 void (*kernel_entry
)(void);
147 lcd_setfont(FONT_SYSFIXED
);
157 #ifdef HAVE_TOUCHSCREEN
158 rc
= button_read_device(&dummy
);
160 rc
= button_read_device();
166 if(rc
& BUTTON_VOL_UP
)
171 printf(MODEL_NAME
" Rockbox Bootloader");
172 printf("Version "APPSVERSION
);
174 rc
= disk_mount_all();
182 printf("Error: %s", strerror(rc
));
185 printf("Loading firmware");
186 rc
= load_firmware((unsigned char *)CONFIG_SDRAM_START
, BOOTFILE
, 0x400000);
188 printf("Error: %s", strerror(rc
));
192 printf("Starting Rockbox...");
193 adc_close(); /* Disable SADC */
196 kernel_entry
= (void*) CONFIG_SDRAM_START
;