blob: d4e326025ed6d6fc5f3ed39ac6b6859358def528 [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 *
10 * Copyright (C) 2005 by Jörg Hohensohn aka [IDC]Dragon
11 *
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 *
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000016 * 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 Hohensohna0add0c2005-06-21 08:30:23 +000040#include "buffer.h"
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000041#include "rolo.h"
42#include "usb.h"
43#include "powermgmt.h"
44
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000045void 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
57int 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
69int charging_screen(void)
70{
71 unsigned int button;
72 int rc = 0;
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000073
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 Arnold8831a0a2005-07-11 19:16:14 +000085 if (button == BUTTON_ON)
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000086 rc = 2;
Jens Arnold7c7dd432005-07-11 19:14:26 +000087 else if (usb_detect())
88 rc = 3;
89 else if (!charger_inserted())
90 rc = 1;
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +000091 } while (!rc);
92
93 return rc;
94}
95#endif /* HAVE_CHARGING */
96
Jörg Hohensohn6aa85252005-06-22 07:19:55 +000097#ifdef HAVE_MMC
98int 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 Hohensohn1a7f1f42005-07-10 05:11:07 +0000106/* prompt user to plug USB and fix a problem */
107void 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 Arnold7c7dd432005-07-11 19:14:26 +0000121 if (button == SYS_POWEROFF)
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000122 {
123 power_off();
124 }
125 } while (button != SYS_USB_CONNECTED);
126 usb_screen();
127 system_reboot();
128}
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000129
130void main(void)
131{
132 int rc;
133
134 power_init();
135 system_init();
136 kernel_init();
Jörg Hohensohna0add0c2005-06-21 08:30:23 +0000137 buffer_init();
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000138 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 Arnold7c7dd432005-07-11 19:14:26 +0000154 if (rc == 1) /* charger removed */
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000155 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 Hohensohn9cfa47a2005-06-21 00:11:14 +0000180 {
181 usb_screen();
182 }
183 }
184
185 rc = disk_mount_all();
186 if (rc<=0)
187 {
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000188 prompt_usb("No partition", "found.");
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000189 }
190
191 { // rolo the firmware
Jörg Hohensohna0add0c2005-06-21 08:30:23 +0000192 static const char filename[] = "/" BOOTFILE;
193 rolo_load((char*)filename); /* won't return if started */
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000194
Jörg Hohensohn1a7f1f42005-07-10 05:11:07 +0000195 prompt_usb("No firmware", filename);
Jörg Hohensohn9cfa47a2005-06-21 00:11:14 +0000196 }
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
204void screen_dump(void)
205{
206}
207
208int dbg_ports(void)
209{
210 return 0;
211}
212
213void audio_stop(void)
214{
215}
216
217int audio_status(void)
218{
219 return 0;
220}
221
222void mp3_shutdown(void)
223{
224}
225/*
226void i2c_init(void)
227{
228}
229
230void backlight_on(void)
231{
232}
233*/