blob: e4be785beb4a59d06982c6b7015be06832334c1e [file] [log] [blame]
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Nicolas Pennequin357ffb32008-05-05 10:32:46 +000010 * Copyright (C) 2005 by Jörg Hohensohn aka [IDC]Dragon
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000011 *
Jörg Hohensohn6aa85252005-06-22 07:19:55 +000012 * 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 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000016 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000020 *
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
23 *
24 ****************************************************************************/
25#include "config.h"
26
27#include <stdlib.h>
28#include <stdio.h>
29#include "cpu.h"
30#include "system.h"
31#include "lcd.h"
32#include "kernel.h"
33#include "thread.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000034#include "storage.h"
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000035#include "disk.h"
36#include "font.h"
37#include "adc.h"
38#include "button.h"
39#include "panic.h"
40#include "power.h"
41#include "file.h"
Jörg Hohensohna0add0c2005-06-21 08:30:23 +000042#include "buffer.h"
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000043#include "rolo.h"
44#include "usb.h"
45#include "powermgmt.h"
46
Jens Arnoldca99f8e2008-10-12 22:10:22 +000047static void usb_screen(void)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000048{
49 lcd_clear_display();
50 lcd_puts(0, 0, "USB mode");
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000051 lcd_update();
Jens Arnoldf9b90e92007-04-06 22:55:00 +000052
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000053 usb_acknowledge(SYS_USB_CONNECTED_ACK);
54 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
55 }
56}
57
Jens Arnoldca99f8e2008-10-12 22:10:22 +000058static void show_logo(void)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000059{
60 lcd_clear_display();
61 lcd_puts(0, 0, "Rockbox");
62 lcd_puts(0, 1, "Rescue boot");
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000063 lcd_update();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000064}
65
Jonathan Gordon9a6f4192007-02-18 05:32:06 +000066#if CONFIG_CHARGING
Jens Arnoldca99f8e2008-10-12 22:10:22 +000067static void charging_screen(void)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000068{
69 unsigned int button;
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000070 const char* msg;
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000071
72 ide_power_enable(false); /* power down the disk, else would be spinning */
73
74 lcd_clear_display();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000075
76 do
77 {
Michael Sevakis3157e132008-12-24 16:58:41 +000078#ifdef ARCHOS_RECORDER
Jens Arnold0dd1f8e2006-06-06 22:23:52 +000079 if (charge_state == CHARGING)
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000080 msg = "charging";
Jens Arnold0dd1f8e2006-06-06 22:23:52 +000081 else if (charge_state == TOPOFF)
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000082 msg = "topoff charge";
Jens Arnold0dd1f8e2006-06-06 22:23:52 +000083 else if (charge_state == TRICKLE)
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000084 msg = "trickle charge";
85 else
86 msg = "not charging";
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000087#else
88 msg = "charging";
89#endif
90 lcd_puts(0, 0, msg);
91 {
92 char buf[32];
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +000093 int battv = battery_voltage();
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000094 snprintf(buf, sizeof(buf), "%d.%02dV %d%%",
Jens Arnold1d1d9a82007-08-15 23:57:27 +000095 battv / 1000, (battv % 1000) / 10, battery_level());
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000096 lcd_puts(0, 1, buf);
97 }
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000098 lcd_update();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +000099
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +0000100 button = button_get_w_tmo(HZ/2);
101#ifdef BUTTON_ON
102 if (button == (BUTTON_ON | BUTTON_REL))
103#else
104 if (button == (BUTTON_RIGHT | BUTTON_REL))
105#endif
106 break; /* start */
107 else
108 {
Jens Arnoldb1e16d22008-07-06 12:14:13 +0000109 if (usb_detect() == USB_INSERTED)
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +0000110 break;
111 else if (!charger_inserted())
112 power_off(); /* charger removed: power down */
113 }
114 } while (1);
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000115}
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000116#endif /* CONFIG_CHARGING */
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000117
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000118/* prompt user to plug USB and fix a problem */
Jens Arnoldca99f8e2008-10-12 22:10:22 +0000119static void prompt_usb(const char* msg1, const char* msg2)
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000120{
121 int button;
122 lcd_clear_display();
123 lcd_puts(0, 0, msg1);
124 lcd_puts(0, 1, msg2);
125#ifdef HAVE_LCD_BITMAP
126 lcd_puts(0, 2, "Insert USB cable");
127 lcd_puts(0, 3, "and fix it.");
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000128#endif
Jens Arnoldf9b90e92007-04-06 22:55:00 +0000129 lcd_update();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000130 do
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000131 {
132 button = button_get(true);
Jens Arnold7c7dd432005-07-11 19:14:26 +0000133 if (button == SYS_POWEROFF)
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000134 {
135 power_off();
136 }
137 } while (button != SYS_USB_CONNECTED);
138 usb_screen();
139 system_reboot();
140}
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000141
142void main(void)
143{
144 int rc;
145
146 power_init();
147 system_init();
148 kernel_init();
Jörg Hohensohna0add0c2005-06-21 08:30:23 +0000149 buffer_init();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000150 lcd_init();
151 show_logo();
Michael Sevakisaf395f42008-03-26 01:50:41 +0000152 enable_irq();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000153 adc_init();
154 usb_init();
155 button_init();
156 powermgmt_init();
157
Jonathan Gordon9a6f4192007-02-18 05:32:06 +0000158#if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000159 if (charger_inserted()
160#ifdef ATA_POWER_PLAYERSTYLE
161 && !ide_powered() /* relies on probing result from bootloader */
162#endif
163 )
164 {
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +0000165 charging_screen(); /* display a "charging" screen */
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000166 show_logo(); /* again, to provide better visual feedback */
167 }
168#endif
169
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000170 rc = storage_init();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000171 if(rc)
172 {
173#ifdef HAVE_LCD_BITMAP
174 char str[32];
175 lcd_clear_display();
176 snprintf(str, 31, "ATA error: %d", rc);
177 lcd_puts(0, 1, str);
178 lcd_update();
179 while(!(button_get(true) & BUTTON_REL));
180#endif
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000181 panicf("storage: %d", rc);
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000182 }
183
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000184 usb_start_monitoring();
Jens Arnoldb1e16d22008-07-06 12:14:13 +0000185 while (usb_detect() == USB_INSERTED)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000186 { /* enter USB mode early, before trying to mount */
187 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000188 {
189 usb_screen();
190 }
191 }
192
193 rc = disk_mount_all();
194 if (rc<=0)
195 {
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000196 prompt_usb("No partition", "found.");
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000197 }
198
199 { // rolo the firmware
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000200 static const char filename[] = "/" BOOTFILE;
Jörg Hohensohna0add0c2005-06-21 08:30:23 +0000201 rolo_load((char*)filename); /* won't return if started */
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000202
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000203 prompt_usb("No firmware", filename);
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000204 }
205
206
207}
208
209/* These functions are present in the firmware library, but we reimplement
210 them here because the originals do a lot more than we want */
211
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000212void audio_stop(void)
213{
214}
215
216int audio_status(void)
217{
218 return 0;
219}
220
Barry Wardell8d2711b2006-11-11 01:18:57 +0000221void audio_stop_recording(void)
222{
223}
224
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000225void mp3_shutdown(void)
226{
227}