Fix manual building for iPod 1G/2G/3G - scrollwheel is not defined for these in addit...
[maemo-rb.git] / bootloader / ondavx747.c
blob442fc61422741d119da07de56b8d9b73ef573ca5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include "config.h"
23 #include "jz4740.h"
24 #include "backlight.h"
25 #include "font.h"
26 #include "lcd.h"
27 #include "usb.h"
28 #include "system.h"
29 #include "button.h"
30 #include "common.h"
31 #include "storage.h"
32 #include "disk.h"
33 #include "string.h"
35 static void show_splash(int timeout, const char *msg)
37 reset_screen();
38 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
39 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
40 lcd_update();
42 sleep(timeout);
45 static void usb_mode(void)
47 int button;
49 /* Init backlight */
50 backlight_init();
52 /* Init USB */
53 usb_init();
54 usb_start_monitoring();
56 /* Wait for threads to connect */
57 show_splash(HZ/2, "Waiting for USB");
59 while (1)
61 button = button_get_w_tmo(HZ/2);
63 if (button == SYS_USB_CONNECTED)
64 break; /* Hit */
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);
74 while (1)
76 button = button_get(true);
77 if (button == SYS_USB_DISCONNECTED)
79 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
80 break;
85 reset_screen();
88 static void boot_of(void)
90 /* Init backlight */
91 backlight_init();
94 int main(void)
96 int rc, dummy;
97 void (*kernel_entry)(void);
99 kernel_init();
100 lcd_init();
101 font_init();
102 lcd_setfont(FONT_SYSFIXED);
103 button_init();
104 storage_init();
106 reset_screen();
108 #ifdef HAVE_TOUCHSCREEN
109 rc = button_read_device(&dummy);
110 #else
111 rc = button_read_device();
112 #endif
114 if(rc & BUTTON_VOL_UP)
115 usb_mode();
116 else if(button_hold())
117 boot_of();
118 else if(rc)
119 verbose = true;
121 /* Only enable backlight when button is pressed */
122 if(verbose)
124 backlight_init();
125 printf(MODEL_NAME" Rockbox Bootloader");
126 printf("Version "APPSVERSION);
129 rc = storage_init();
130 if(rc)
131 error(EATA, rc);
133 rc = disk_mount_all();
134 if (rc <= 0)
135 error(EDISK,rc);
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));
142 if (rc == EOK)
144 printf("Starting Rockbox...");
145 disable_interrupt();
146 kernel_entry = (void*) CONFIG_SDRAM_START;
147 kernel_entry();
150 /* Halt */
151 while (1)
152 core_idle();
154 return 0;