blob: ac90d603360b360b614f07ae63b184b282400944 [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"
Michael Sevakis9a3400a2014-08-08 03:23:29 -040032#include "../kernel-internal.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000033#include "storage.h"
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000034#include "disk.h"
35#include "font.h"
36#include "adc.h"
37#include "button.h"
38#include "panic.h"
39#include "power.h"
40#include "file.h"
41#include "rolo.h"
42#include "usb.h"
43#include "powermgmt.h"
44
Jens Arnoldca99f8e2008-10-12 22:10:22 +000045static void usb_screen(void)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000046{
47 lcd_clear_display();
48 lcd_puts(0, 0, "USB mode");
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000049 lcd_update();
Jens Arnoldf9b90e92007-04-06 22:55:00 +000050
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000051 usb_acknowledge(SYS_USB_CONNECTED_ACK);
52 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
53 }
54}
55
Jens Arnoldca99f8e2008-10-12 22:10:22 +000056static void show_logo(void)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000057{
58 lcd_clear_display();
59 lcd_puts(0, 0, "Rockbox");
60 lcd_puts(0, 1, "Rescue boot");
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000061 lcd_update();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000062}
63
Jonathan Gordon9a6f4192007-02-18 05:32:06 +000064#if CONFIG_CHARGING
Jens Arnoldca99f8e2008-10-12 22:10:22 +000065static void charging_screen(void)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000066{
67 unsigned int button;
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000068 const char* msg;
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000069
70 ide_power_enable(false); /* power down the disk, else would be spinning */
71
72 lcd_clear_display();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000073
74 do
75 {
Michael Sevakis3157e132008-12-24 16:58:41 +000076#ifdef ARCHOS_RECORDER
Jens Arnold0dd1f8e2006-06-06 22:23:52 +000077 if (charge_state == CHARGING)
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000078 msg = "charging";
Jens Arnold0dd1f8e2006-06-06 22:23:52 +000079 else if (charge_state == TOPOFF)
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000080 msg = "topoff charge";
Jens Arnold0dd1f8e2006-06-06 22:23:52 +000081 else if (charge_state == TRICKLE)
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000082 msg = "trickle charge";
83 else
84 msg = "not charging";
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000085#else
86 msg = "charging";
87#endif
88 lcd_puts(0, 0, msg);
89 {
90 char buf[32];
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +000091 int battv = battery_voltage();
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000092 snprintf(buf, sizeof(buf), "%d.%02dV %d%%",
Jens Arnold1d1d9a82007-08-15 23:57:27 +000093 battv / 1000, (battv % 1000) / 10, battery_level());
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000094 lcd_puts(0, 1, buf);
95 }
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000096 lcd_update();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +000097
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +000098 button = button_get_w_tmo(HZ/2);
99#ifdef BUTTON_ON
100 if (button == (BUTTON_ON | BUTTON_REL))
101#else
102 if (button == (BUTTON_RIGHT | BUTTON_REL))
103#endif
104 break; /* start */
105 else
106 {
Jens Arnoldb1e16d22008-07-06 12:14:13 +0000107 if (usb_detect() == USB_INSERTED)
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +0000108 break;
109 else if (!charger_inserted())
110 power_off(); /* charger removed: power down */
111 }
112 } while (1);
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000113}
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000114#endif /* CONFIG_CHARGING */
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000115
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000116/* prompt user to plug USB and fix a problem */
Jens Arnoldca99f8e2008-10-12 22:10:22 +0000117static void prompt_usb(const char* msg1, const char* msg2)
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000118{
119 int button;
120 lcd_clear_display();
121 lcd_puts(0, 0, msg1);
122 lcd_puts(0, 1, msg2);
123#ifdef HAVE_LCD_BITMAP
124 lcd_puts(0, 2, "Insert USB cable");
125 lcd_puts(0, 3, "and fix it.");
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000126#endif
Jens Arnoldf9b90e92007-04-06 22:55:00 +0000127 lcd_update();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000128 do
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000129 {
130 button = button_get(true);
Jens Arnold7c7dd432005-07-11 19:14:26 +0000131 if (button == SYS_POWEROFF)
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000132 {
133 power_off();
134 }
135 } while (button != SYS_USB_CONNECTED);
136 usb_screen();
137 system_reboot();
138}
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000139
140void main(void)
141{
142 int rc;
143
144 power_init();
145 system_init();
146 kernel_init();
147 lcd_init();
148 show_logo();
Michael Sevakisaf395f42008-03-26 01:50:41 +0000149 enable_irq();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000150 adc_init();
151 usb_init();
152 button_init();
153 powermgmt_init();
154
Jonathan Gordon9a6f4192007-02-18 05:32:06 +0000155#if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000156 if (charger_inserted()
157#ifdef ATA_POWER_PLAYERSTYLE
158 && !ide_powered() /* relies on probing result from bootloader */
159#endif
160 )
161 {
Jörg Hohensohn02cfd6a2005-08-23 07:24:21 +0000162 charging_screen(); /* display a "charging" screen */
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000163 show_logo(); /* again, to provide better visual feedback */
164 }
165#endif
166
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000167 rc = storage_init();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000168 if(rc)
169 {
170#ifdef HAVE_LCD_BITMAP
171 char str[32];
172 lcd_clear_display();
173 snprintf(str, 31, "ATA error: %d", rc);
174 lcd_puts(0, 1, str);
175 lcd_update();
176 while(!(button_get(true) & BUTTON_REL));
177#endif
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000178 panicf("storage: %d", rc);
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000179 }
180
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000181 usb_start_monitoring();
Jens Arnoldb1e16d22008-07-06 12:14:13 +0000182 while (usb_detect() == USB_INSERTED)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000183 { /* enter USB mode early, before trying to mount */
184 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000185 {
186 usb_screen();
187 }
188 }
189
190 rc = disk_mount_all();
191 if (rc<=0)
192 {
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000193 prompt_usb("No partition", "found.");
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000194 }
195
196 { // rolo the firmware
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000197 static const char filename[] = "/" BOOTFILE;
Jörg Hohensohna0add0c2005-06-21 08:30:23 +0000198 rolo_load((char*)filename); /* won't return if started */
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000199
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000200 prompt_usb("No firmware", filename);
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000201 }
202
203
204}
205
206/* These functions are present in the firmware library, but we reimplement
207 them here because the originals do a lot more than we want */
208
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000209void audio_stop(void)
210{
211}
212
213int audio_status(void)
214{
215 return 0;
216}
217
Barry Wardell8d2711b2006-11-11 01:18:57 +0000218void audio_stop_recording(void)
219{
220}
221
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000222void mp3_shutdown(void)
223{
224}