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 | * |
| 10 | * Copyright (C) 2005 by Jörg Hohensohn aka [IDC]Dragon |
| 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"); |
| 49 | #ifdef HAVE_LCD_BITMAP |
| 50 | lcd_update(); |
| 51 | #endif |
| 52 | usb_acknowledge(SYS_USB_CONNECTED_ACK); |
| 53 | while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) { |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | int show_logo(void) |
| 58 | { |
| 59 | lcd_clear_display(); |
| 60 | lcd_puts(0, 0, "Rockbox"); |
| 61 | lcd_puts(0, 1, "Rescue boot"); |
| 62 | #ifdef HAVE_LCD_BITMAP |
| 63 | lcd_update(); |
| 64 | #endif |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | #ifdef HAVE_CHARGING |
| 69 | int charging_screen(void) |
| 70 | { |
| 71 | unsigned int button; |
| 72 | int rc = 0; |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 73 | |
| 74 | ide_power_enable(false); /* power down the disk, else would be spinning */ |
| 75 | |
| 76 | lcd_clear_display(); |
| 77 | lcd_puts(0, 0, "charging..."); |
| 78 | #ifdef HAVE_LCD_BITMAP |
| 79 | lcd_update(); |
| 80 | #endif |
| 81 | |
| 82 | do |
| 83 | { |
| 84 | button = button_get_w_tmo(HZ/2); |
Jens Arnold | 8831a0a | 2005-07-11 19:16:14 +0000 | [diff] [blame] | 85 | if (button == BUTTON_ON) |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 86 | rc = 2; |
Jens Arnold | 7c7dd43 | 2005-07-11 19:14:26 +0000 | [diff] [blame] | 87 | else if (usb_detect()) |
| 88 | rc = 3; |
| 89 | else if (!charger_inserted()) |
| 90 | rc = 1; |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 91 | } while (!rc); |
| 92 | |
| 93 | return rc; |
| 94 | } |
| 95 | #endif /* HAVE_CHARGING */ |
| 96 | |
Jörg Hohensohn | 6aa8525 | 2005-06-22 07:19:55 +0000 | [diff] [blame] | 97 | #ifdef HAVE_MMC |
| 98 | int mmc_remove_request(void) |
| 99 | { |
| 100 | /* A dummy function here, we won't access the card |
| 101 | before entering USB mode */ |
| 102 | return 0; |
| 103 | } |
| 104 | #endif /* HAVE_MMC */ |
| 105 | |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 106 | /* prompt user to plug USB and fix a problem */ |
| 107 | void prompt_usb(const char* msg1, const char* msg2) |
| 108 | { |
| 109 | int button; |
| 110 | lcd_clear_display(); |
| 111 | lcd_puts(0, 0, msg1); |
| 112 | lcd_puts(0, 1, msg2); |
| 113 | #ifdef HAVE_LCD_BITMAP |
| 114 | lcd_puts(0, 2, "Insert USB cable"); |
| 115 | lcd_puts(0, 3, "and fix it."); |
| 116 | lcd_update(); |
| 117 | #endif |
| 118 | do |
| 119 | { |
| 120 | button = button_get(true); |
Jens Arnold | 7c7dd43 | 2005-07-11 19:14:26 +0000 | [diff] [blame] | 121 | if (button == SYS_POWEROFF) |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 122 | { |
| 123 | power_off(); |
| 124 | } |
| 125 | } while (button != SYS_USB_CONNECTED); |
| 126 | usb_screen(); |
| 127 | system_reboot(); |
| 128 | } |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 129 | |
| 130 | void main(void) |
| 131 | { |
| 132 | int rc; |
| 133 | |
| 134 | power_init(); |
| 135 | system_init(); |
| 136 | kernel_init(); |
Jörg Hohensohn | a0add0c | 2005-06-21 08:30:23 +0000 | [diff] [blame] | 137 | buffer_init(); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 138 | lcd_init(); |
| 139 | show_logo(); |
| 140 | set_irq_level(0); |
| 141 | adc_init(); |
| 142 | usb_init(); |
| 143 | button_init(); |
| 144 | powermgmt_init(); |
| 145 | |
| 146 | #if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034) |
| 147 | if (charger_inserted() |
| 148 | #ifdef ATA_POWER_PLAYERSTYLE |
| 149 | && !ide_powered() /* relies on probing result from bootloader */ |
| 150 | #endif |
| 151 | ) |
| 152 | { |
| 153 | rc = charging_screen(); /* display a "charging" screen */ |
Jens Arnold | 7c7dd43 | 2005-07-11 19:14:26 +0000 | [diff] [blame] | 154 | if (rc == 1) /* charger removed */ |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 155 | power_off(); |
| 156 | /* "On" pressed or USB connected: proceed */ |
| 157 | show_logo(); /* again, to provide better visual feedback */ |
| 158 | } |
| 159 | #endif |
| 160 | |
| 161 | rc = ata_init(); |
| 162 | if(rc) |
| 163 | { |
| 164 | #ifdef HAVE_LCD_BITMAP |
| 165 | char str[32]; |
| 166 | lcd_clear_display(); |
| 167 | snprintf(str, 31, "ATA error: %d", rc); |
| 168 | lcd_puts(0, 1, str); |
| 169 | lcd_update(); |
| 170 | while(!(button_get(true) & BUTTON_REL)); |
| 171 | #endif |
| 172 | panicf("ata: %d", rc); |
| 173 | } |
| 174 | |
| 175 | //disk_init(); |
| 176 | usb_start_monitoring(); |
| 177 | while (usb_detect()) |
| 178 | { /* enter USB mode early, before trying to mount */ |
| 179 | if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 180 | { |
| 181 | usb_screen(); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | rc = disk_mount_all(); |
| 186 | if (rc<=0) |
| 187 | { |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 188 | prompt_usb("No partition", "found."); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | { // rolo the firmware |
Jörg Hohensohn | a0add0c | 2005-06-21 08:30:23 +0000 | [diff] [blame] | 192 | static const char filename[] = "/" BOOTFILE; |
| 193 | rolo_load((char*)filename); /* won't return if started */ |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 194 | |
Jörg Hohensohn | 1a7f1f4 | 2005-07-10 05:11:07 +0000 | [diff] [blame] | 195 | prompt_usb("No firmware", filename); |
Jörg Hohensohn | 9cfa47a | 2005-06-21 00:11:14 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | |
| 199 | } |
| 200 | |
| 201 | /* These functions are present in the firmware library, but we reimplement |
| 202 | them here because the originals do a lot more than we want */ |
| 203 | |
| 204 | void screen_dump(void) |
| 205 | { |
| 206 | } |
| 207 | |
| 208 | int dbg_ports(void) |
| 209 | { |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | void audio_stop(void) |
| 214 | { |
| 215 | } |
| 216 | |
| 217 | int audio_status(void) |
| 218 | { |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | void mp3_shutdown(void) |
| 223 | { |
| 224 | } |
| 225 | /* |
| 226 | void i2c_init(void) |
| 227 | { |
| 228 | } |
| 229 | |
| 230 | void backlight_on(void) |
| 231 | { |
| 232 | } |
| 233 | */ |