Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Nicolas Pennequin | 357ffb3 | 2008-05-05 10:32:46 +0000 | [diff] [blame^] | 10 | * Copyright (C) 2005 by Jörg Hohensohn aka [IDC]Dragon |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 11 | * |
Jörg Hohensohn | 6aa8525 | 2005-06-22 07:19:55 +0000 | [diff] [blame] | 12 | * This is "Bootbox", a minimalistic loader, rescue firmware for just |
| 13 | * booting into a full features one. Aside from that it does charging |
| 14 | * and USB mode, to enable copying the desired firmware. |
| 15 | * |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 16 | * All files in this archive are subject to the GNU General Public License. |
| 17 | * See the file COPYING in the source tree root for full license agreement. |
| 18 | * |
| 19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 20 | * KIND, either express or implied. |
| 21 | * |
| 22 | ****************************************************************************/ |
| 23 | #include "config.h" |
| 24 | |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include "cpu.h" |
| 28 | #include "system.h" |
| 29 | #include "lcd.h" |
| 30 | #include "kernel.h" |
| 31 | #include "thread.h" |
| 32 | #include "ata.h" |
| 33 | #include "disk.h" |
| 34 | #include "font.h" |
| 35 | #include "adc.h" |
| 36 | #include "button.h" |
| 37 | #include "panic.h" |
| 38 | #include "power.h" |
| 39 | #include "file.h" |
Jörg Hohensohn | a0add0c | 2005-06-21 08:30:23 +0000 | [diff] [blame] | 40 | #include "buffer.h" |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 41 | #include "rolo.h" |
| 42 | #include "usb.h" |
| 43 | #include "powermgmt.h" |
| 44 | |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 45 | void usb_screen(void) |
| 46 | { |
| 47 | lcd_clear_display(); |
| 48 | lcd_puts(0, 0, "USB mode"); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 49 | lcd_update(); |
Jens Arnold | f9b90e9 | 2007-04-06 22:55:00 +0000 | [diff] [blame] | 50 | |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 51 | usb_acknowledge(SYS_USB_CONNECTED_ACK); |
| 52 | while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) { |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | int show_logo(void) |
| 57 | { |
| 58 | lcd_clear_display(); |
| 59 | lcd_puts(0, 0, "Rockbox"); |
| 60 | lcd_puts(0, 1, "Rescue boot"); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 61 | lcd_update(); |
Jens Arnold | f9b90e9 | 2007-04-06 22:55:00 +0000 | [diff] [blame] | 62 | |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
Jonathan Gordon | 9a6f419 | 2007-02-18 05:32:06 +0000 | [diff] [blame] | 66 | #if CONFIG_CHARGING |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 67 | /* |
| 68 | bool backlight_get_on_when_charging(void) |
| 69 | { |
| 70 | return false; |
| 71 | } |
| 72 | */ |
| 73 | void charging_screen(void) |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 74 | { |
| 75 | unsigned int button; |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 76 | const char* msg; |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 77 | |
| 78 | ide_power_enable(false); /* power down the disk, else would be spinning */ |
| 79 | |
| 80 | lcd_clear_display(); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 81 | |
| 82 | do |
| 83 | { |
Jens Arnold | 0dd1f8e | 2006-06-06 22:23:52 +0000 | [diff] [blame] | 84 | #if CONFIG_CHARGING == CHARGING_CONTROL |
| 85 | if (charge_state == CHARGING) |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 86 | msg = "charging"; |
Jens Arnold | 0dd1f8e | 2006-06-06 22:23:52 +0000 | [diff] [blame] | 87 | else if (charge_state == TOPOFF) |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 88 | msg = "topoff charge"; |
Jens Arnold | 0dd1f8e | 2006-06-06 22:23:52 +0000 | [diff] [blame] | 89 | else if (charge_state == TRICKLE) |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 90 | msg = "trickle charge"; |
| 91 | else |
| 92 | msg = "not charging"; |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 93 | |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 94 | #else |
| 95 | msg = "charging"; |
| 96 | #endif |
| 97 | lcd_puts(0, 0, msg); |
| 98 | { |
| 99 | char buf[32]; |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 100 | int battv = battery_voltage(); |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 101 | snprintf(buf, sizeof(buf), "%d.%02dV %d%%", |
Jens Arnold | 1d1d9a8 | 2007-08-15 23:57:27 +0000 | [diff] [blame] | 102 | battv / 1000, (battv % 1000) / 10, battery_level()); |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 103 | lcd_puts(0, 1, buf); |
| 104 | } |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 105 | lcd_update(); |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 106 | |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 107 | button = button_get_w_tmo(HZ/2); |
| 108 | #ifdef BUTTON_ON |
| 109 | if (button == (BUTTON_ON | BUTTON_REL)) |
| 110 | #else |
| 111 | if (button == (BUTTON_RIGHT | BUTTON_REL)) |
| 112 | #endif |
| 113 | break; /* start */ |
| 114 | else |
| 115 | { |
| 116 | if (usb_detect()) |
| 117 | break; |
| 118 | else if (!charger_inserted()) |
| 119 | power_off(); /* charger removed: power down */ |
| 120 | } |
| 121 | } while (1); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 122 | } |
Jens Arnold | 0dd1f8e | 2006-06-06 22:23:52 +0000 | [diff] [blame] | 123 | #endif /* CONFIG_CHARGING */ |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 124 | |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 125 | /* prompt user to plug USB and fix a problem */ |
| 126 | void prompt_usb(const char* msg1, const char* msg2) |
| 127 | { |
| 128 | int button; |
| 129 | lcd_clear_display(); |
| 130 | lcd_puts(0, 0, msg1); |
| 131 | lcd_puts(0, 1, msg2); |
| 132 | #ifdef HAVE_LCD_BITMAP |
| 133 | lcd_puts(0, 2, "Insert USB cable"); |
| 134 | lcd_puts(0, 3, "and fix it."); |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 135 | #endif |
Jens Arnold | f9b90e9 | 2007-04-06 22:55:00 +0000 | [diff] [blame] | 136 | lcd_update(); |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 137 | do |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 138 | { |
| 139 | button = button_get(true); |
Jens Arnold | 7c7dd43 | 2005-07-11 19:14:26 +0000 | [diff] [blame] | 140 | if (button == SYS_POWEROFF) |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 141 | { |
| 142 | power_off(); |
| 143 | } |
| 144 | } while (button != SYS_USB_CONNECTED); |
| 145 | usb_screen(); |
| 146 | system_reboot(); |
| 147 | } |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 148 | |
| 149 | void main(void) |
| 150 | { |
| 151 | int rc; |
| 152 | |
| 153 | power_init(); |
| 154 | system_init(); |
| 155 | kernel_init(); |
Jörg Hohensohn | a0add0c | 2005-06-21 08:30:23 +0000 | [diff] [blame] | 156 | buffer_init(); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 157 | lcd_init(); |
| 158 | show_logo(); |
Michael Sevakis | af395f4 | 2008-03-26 01:50:41 +0000 | [diff] [blame] | 159 | enable_irq(); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 160 | adc_init(); |
| 161 | usb_init(); |
| 162 | button_init(); |
| 163 | powermgmt_init(); |
| 164 | |
Jonathan Gordon | 9a6f419 | 2007-02-18 05:32:06 +0000 | [diff] [blame] | 165 | #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 166 | if (charger_inserted() |
| 167 | #ifdef ATA_POWER_PLAYERSTYLE |
| 168 | && !ide_powered() /* relies on probing result from bootloader */ |
| 169 | #endif |
| 170 | ) |
| 171 | { |
Jörg Hohensohn | 02cfd6a | 2005-08-23 07:24:21 +0000 | [diff] [blame] | 172 | charging_screen(); /* display a "charging" screen */ |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 173 | show_logo(); /* again, to provide better visual feedback */ |
| 174 | } |
| 175 | #endif |
| 176 | |
| 177 | rc = ata_init(); |
| 178 | if(rc) |
| 179 | { |
| 180 | #ifdef HAVE_LCD_BITMAP |
| 181 | char str[32]; |
| 182 | lcd_clear_display(); |
| 183 | snprintf(str, 31, "ATA error: %d", rc); |
| 184 | lcd_puts(0, 1, str); |
| 185 | lcd_update(); |
| 186 | while(!(button_get(true) & BUTTON_REL)); |
| 187 | #endif |
| 188 | panicf("ata: %d", rc); |
| 189 | } |
| 190 | |
| 191 | //disk_init(); |
| 192 | usb_start_monitoring(); |
| 193 | while (usb_detect()) |
| 194 | { /* enter USB mode early, before trying to mount */ |
| 195 | if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 196 | { |
| 197 | usb_screen(); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | rc = disk_mount_all(); |
| 202 | if (rc<=0) |
| 203 | { |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 204 | prompt_usb("No partition", "found."); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | { // rolo the firmware |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 208 | static const char filename[] = "/" BOOTFILE; |
Jörg Hohensohn | a0add0c | 2005-06-21 08:30:23 +0000 | [diff] [blame] | 209 | rolo_load((char*)filename); /* won't return if started */ |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 210 | |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 211 | prompt_usb("No firmware", filename); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | |
| 215 | } |
| 216 | |
| 217 | /* These functions are present in the firmware library, but we reimplement |
| 218 | them here because the originals do a lot more than we want */ |
| 219 | |
| 220 | void screen_dump(void) |
| 221 | { |
| 222 | } |
| 223 | |
| 224 | int dbg_ports(void) |
| 225 | { |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | void audio_stop(void) |
| 230 | { |
| 231 | } |
| 232 | |
| 233 | int audio_status(void) |
| 234 | { |
| 235 | return 0; |
| 236 | } |
| 237 | |
Barry Wardell | 8d2711b | 2006-11-11 01:18:57 +0000 | [diff] [blame] | 238 | void audio_stop_recording(void) |
| 239 | { |
| 240 | } |
| 241 | |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 242 | void mp3_shutdown(void) |
| 243 | { |
| 244 | } |
| 245 | /* |
| 246 | void i2c_init(void) |
| 247 | { |
| 248 | } |
| 249 | |
| 250 | void backlight_on(void) |
| 251 | { |
| 252 | } |
| 253 | */ |