Remove .a files before running ar, to avoid problems with renamed files remaining...
[kugel-rb.git] / flash / bootbox / main.c
blobf53a5edda281d7c52c3d83e27a762efe0964874f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Jörg Hohensohn aka [IDC]Dragon
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.
16 * 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.
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
24 ****************************************************************************/
25 #include "config.h"
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"
34 #include "storage.h"
35 #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"
42 #include "buffer.h"
43 #include "rolo.h"
44 #include "usb.h"
45 #include "powermgmt.h"
47 static void usb_screen(void)
49 lcd_clear_display();
50 lcd_puts(0, 0, "USB mode");
51 lcd_update();
53 usb_acknowledge(SYS_USB_CONNECTED_ACK);
54 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
58 static void show_logo(void)
60 lcd_clear_display();
61 lcd_puts(0, 0, "Rockbox");
62 lcd_puts(0, 1, "Rescue boot");
63 lcd_update();
66 #if CONFIG_CHARGING
67 static void charging_screen(void)
69 unsigned int button;
70 const char* msg;
72 ide_power_enable(false); /* power down the disk, else would be spinning */
74 lcd_clear_display();
78 #if CONFIG_CHARGING == CHARGING_CONTROL
79 if (charge_state == CHARGING)
80 msg = "charging";
81 else if (charge_state == TOPOFF)
82 msg = "topoff charge";
83 else if (charge_state == TRICKLE)
84 msg = "trickle charge";
85 else
86 msg = "not charging";
88 #else
89 msg = "charging";
90 #endif
91 lcd_puts(0, 0, msg);
93 char buf[32];
94 int battv = battery_voltage();
95 snprintf(buf, sizeof(buf), "%d.%02dV %d%%",
96 battv / 1000, (battv % 1000) / 10, battery_level());
97 lcd_puts(0, 1, buf);
99 lcd_update();
101 button = button_get_w_tmo(HZ/2);
102 #ifdef BUTTON_ON
103 if (button == (BUTTON_ON | BUTTON_REL))
104 #else
105 if (button == (BUTTON_RIGHT | BUTTON_REL))
106 #endif
107 break; /* start */
108 else
110 if (usb_detect() == USB_INSERTED)
111 break;
112 else if (!charger_inserted())
113 power_off(); /* charger removed: power down */
115 } while (1);
117 #endif /* CONFIG_CHARGING */
119 /* prompt user to plug USB and fix a problem */
120 static void prompt_usb(const char* msg1, const char* msg2)
122 int button;
123 lcd_clear_display();
124 lcd_puts(0, 0, msg1);
125 lcd_puts(0, 1, msg2);
126 #ifdef HAVE_LCD_BITMAP
127 lcd_puts(0, 2, "Insert USB cable");
128 lcd_puts(0, 3, "and fix it.");
129 #endif
130 lcd_update();
133 button = button_get(true);
134 if (button == SYS_POWEROFF)
136 power_off();
138 } while (button != SYS_USB_CONNECTED);
139 usb_screen();
140 system_reboot();
143 void main(void)
145 int rc;
147 power_init();
148 system_init();
149 kernel_init();
150 buffer_init();
151 lcd_init();
152 show_logo();
153 enable_irq();
154 adc_init();
155 usb_init();
156 button_init();
157 powermgmt_init();
159 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
160 if (charger_inserted()
161 #ifdef ATA_POWER_PLAYERSTYLE
162 && !ide_powered() /* relies on probing result from bootloader */
163 #endif
166 charging_screen(); /* display a "charging" screen */
167 show_logo(); /* again, to provide better visual feedback */
169 #endif
171 rc = storage_init();
172 if(rc)
174 #ifdef HAVE_LCD_BITMAP
175 char str[32];
176 lcd_clear_display();
177 snprintf(str, 31, "ATA error: %d", rc);
178 lcd_puts(0, 1, str);
179 lcd_update();
180 while(!(button_get(true) & BUTTON_REL));
181 #endif
182 panicf("storage: %d", rc);
185 usb_start_monitoring();
186 while (usb_detect() == USB_INSERTED)
187 { /* enter USB mode early, before trying to mount */
188 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
190 usb_screen();
194 rc = disk_mount_all();
195 if (rc<=0)
197 prompt_usb("No partition", "found.");
200 { // rolo the firmware
201 static const char filename[] = "/" BOOTFILE;
202 rolo_load((char*)filename); /* won't return if started */
204 prompt_usb("No firmware", filename);
210 /* These functions are present in the firmware library, but we reimplement
211 them here because the originals do a lot more than we want */
213 void audio_stop(void)
217 int audio_status(void)
219 return 0;
222 void audio_stop_recording(void)
226 void mp3_shutdown(void)