Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 22 | #include "config.h" |
| 23 | #include "jz4740.h" |
| 24 | #include "backlight.h" |
| 25 | #include "font.h" |
| 26 | #include "lcd.h" |
Maurus Cuelenaere | 40ec543 | 2008-12-19 11:13:58 +0000 | [diff] [blame] | 27 | #include "usb.h" |
Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 28 | #include "system.h" |
Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 29 | #include "button.h" |
Maurus Cuelenaere | 975261f | 2008-07-16 15:25:35 +0000 | [diff] [blame] | 30 | #include "common.h" |
Maurus Cuelenaere | 9da2456 | 2008-12-19 11:29:18 +0000 | [diff] [blame] | 31 | #include "storage.h" |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 32 | #include "disk.h" |
| 33 | #include "string.h" |
Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 34 | |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 35 | static 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 Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 45 | static 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 | |
| 88 | static void boot_of(void) |
| 89 | { |
| 90 | /* Init backlight */ |
| 91 | backlight_init(); |
| 92 | } |
Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 93 | |
Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 94 | int main(void) |
Maurus Cuelenaere | 4bf4d2b | 2008-08-10 21:44:48 +0000 | [diff] [blame] | 95 | { |
Maurus Cuelenaere | 4532d14 | 2009-02-13 00:45:49 +0000 | [diff] [blame] | 96 | int rc, dummy; |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 97 | void (*kernel_entry)(void); |
| 98 | |
Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 99 | kernel_init(); |
| 100 | lcd_init(); |
| 101 | font_init(); |
| 102 | lcd_setfont(FONT_SYSFIXED); |
| 103 | button_init(); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 104 | storage_init(); |
Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 105 | |
Maurus Cuelenaere | 1f692e5 | 2008-07-17 10:13:56 +0000 | [diff] [blame] | 106 | reset_screen(); |
Maurus Cuelenaere | 62c4a28 | 2008-08-26 21:48:49 +0000 | [diff] [blame] | 107 | |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 108 | #ifdef HAVE_TOUCHSCREEN |
Maurus Cuelenaere | 4532d14 | 2009-02-13 00:45:49 +0000 | [diff] [blame] | 109 | rc = button_read_device(&dummy); |
Maurus Cuelenaere | 9407ae8 | 2008-09-17 21:44:47 +0000 | [diff] [blame] | 110 | #else |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 111 | rc = button_read_device(); |
Maurus Cuelenaere | e144638 | 2008-09-05 15:09:40 +0000 | [diff] [blame] | 112 | #endif |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 113 | |
| 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 Cuelenaere | 4b0ae10 | 2009-02-16 23:54:18 +0000 | [diff] [blame] | 121 | /* Only enable backlight when button is pressed */ |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 122 | if(verbose) |
Maurus Cuelenaere | 00baccd | 2009-02-17 20:40:58 +0000 | [diff] [blame] | 123 | { |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 124 | backlight_init(); |
Maurus Cuelenaere | 00baccd | 2009-02-17 20:40:58 +0000 | [diff] [blame] | 125 | printf(MODEL_NAME" Rockbox Bootloader"); |
| 126 | printf("Version "APPSVERSION); |
| 127 | } |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 128 | |
| 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 Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Maurus Cuelenaere | 04c7379 | 2009-02-09 10:02:38 +0000 | [diff] [blame] | 150 | /* Halt */ |
| 151 | while (1) |
| 152 | core_idle(); |
| 153 | |
Maurus Cuelenaere | 0709f0a | 2008-07-14 15:03:10 +0000 | [diff] [blame] | 154 | return 0; |
| 155 | } |