blob: 442fc61422741d119da07de56b8d9b73ef573ca5 [file] [log] [blame]
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Maurus Cuelenaere
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000022#include "config.h"
23#include "jz4740.h"
24#include "backlight.h"
25#include "font.h"
26#include "lcd.h"
Maurus Cuelenaere40ec5432008-12-19 11:13:58 +000027#include "usb.h"
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000028#include "system.h"
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000029#include "button.h"
Maurus Cuelenaere975261f2008-07-16 15:25:35 +000030#include "common.h"
Maurus Cuelenaere9da24562008-12-19 11:29:18 +000031#include "storage.h"
Maurus Cuelenaere04c73792009-02-09 10:02:38 +000032#include "disk.h"
33#include "string.h"
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000034
Maurus Cuelenaere04c73792009-02-09 10:02:38 +000035static void show_splash(int timeout, const char *msg)
36{
37 reset_screen();
38 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
39 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
40 lcd_update();
41
42 sleep(timeout);
43}
44
Maurus Cuelenaere04c73792009-02-09 10:02:38 +000045static void usb_mode(void)
46{
47 int button;
48
49 /* Init backlight */
50 backlight_init();
51
52 /* Init USB */
53 usb_init();
54 usb_start_monitoring();
55
56 /* Wait for threads to connect */
57 show_splash(HZ/2, "Waiting for USB");
58
59 while (1)
60 {
61 button = button_get_w_tmo(HZ/2);
62
63 if (button == SYS_USB_CONNECTED)
64 break; /* Hit */
65 }
66
67 if (button == SYS_USB_CONNECTED)
68 {
69 /* Got the message - wait for disconnect */
70 show_splash(0, "Bootloader USB mode");
71
72 usb_acknowledge(SYS_USB_CONNECTED_ACK);
73
74 while (1)
75 {
76 button = button_get(true);
77 if (button == SYS_USB_DISCONNECTED)
78 {
79 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
80 break;
81 }
82 }
83 }
84
85 reset_screen();
86}
87
88static void boot_of(void)
89{
90 /* Init backlight */
91 backlight_init();
92}
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000093
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000094int main(void)
Maurus Cuelenaere4bf4d2b2008-08-10 21:44:48 +000095{
Maurus Cuelenaere4532d142009-02-13 00:45:49 +000096 int rc, dummy;
Maurus Cuelenaere04c73792009-02-09 10:02:38 +000097 void (*kernel_entry)(void);
98
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +000099 kernel_init();
100 lcd_init();
101 font_init();
102 lcd_setfont(FONT_SYSFIXED);
103 button_init();
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000104 storage_init();
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +0000105
Maurus Cuelenaere1f692e52008-07-17 10:13:56 +0000106 reset_screen();
Maurus Cuelenaere62c4a282008-08-26 21:48:49 +0000107
Maurus Cuelenaere04c73792009-02-09 10:02:38 +0000108#ifdef HAVE_TOUCHSCREEN
Maurus Cuelenaere4532d142009-02-13 00:45:49 +0000109 rc = button_read_device(&dummy);
Maurus Cuelenaere9407ae82008-09-17 21:44:47 +0000110#else
Maurus Cuelenaere04c73792009-02-09 10:02:38 +0000111 rc = button_read_device();
Maurus Cuelenaeree1446382008-09-05 15:09:40 +0000112#endif
Maurus Cuelenaere04c73792009-02-09 10:02:38 +0000113
114 if(rc & BUTTON_VOL_UP)
115 usb_mode();
116 else if(button_hold())
117 boot_of();
118 else if(rc)
119 verbose = true;
120
Maurus Cuelenaere4b0ae102009-02-16 23:54:18 +0000121 /* Only enable backlight when button is pressed */
Maurus Cuelenaere04c73792009-02-09 10:02:38 +0000122 if(verbose)
Maurus Cuelenaere00baccd2009-02-17 20:40:58 +0000123 {
Maurus Cuelenaere04c73792009-02-09 10:02:38 +0000124 backlight_init();
Maurus Cuelenaere00baccd2009-02-17 20:40:58 +0000125 printf(MODEL_NAME" Rockbox Bootloader");
126 printf("Version "APPSVERSION);
127 }
Maurus Cuelenaere04c73792009-02-09 10:02:38 +0000128
129 rc = storage_init();
130 if(rc)
131 error(EATA, rc);
132
133 rc = disk_mount_all();
134 if (rc <= 0)
135 error(EDISK,rc);
136
137 printf("Loading firmware");
138 rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
139 if(rc < 0)
140 printf("Error: %s", strerror(rc));
141
142 if (rc == EOK)
143 {
144 printf("Starting Rockbox...");
145 disable_interrupt();
146 kernel_entry = (void*) CONFIG_SDRAM_START;
147 kernel_entry();
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +0000148 }
149
Maurus Cuelenaere04c73792009-02-09 10:02:38 +0000150 /* Halt */
151 while (1)
152 core_idle();
153
Maurus Cuelenaere0709f0a2008-07-14 15:03:10 +0000154 return 0;
155}