Added the screenshots for the Sansa Clip Zip manual.
[maemo-rb.git] / flash / bootbox / main.c
blobff6b8374e9ef363f10fa59a1c932396a2dfc732d
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 "rolo.h"
43 #include "usb.h"
44 #include "powermgmt.h"
46 static void usb_screen(void)
48 lcd_clear_display();
49 lcd_puts(0, 0, "USB mode");
50 lcd_update();
52 usb_acknowledge(SYS_USB_CONNECTED_ACK);
53 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
57 static void show_logo(void)
59 lcd_clear_display();
60 lcd_puts(0, 0, "Rockbox");
61 lcd_puts(0, 1, "Rescue boot");
62 lcd_update();
65 #if CONFIG_CHARGING
66 static void charging_screen(void)
68 unsigned int button;
69 const char* msg;
71 ide_power_enable(false); /* power down the disk, else would be spinning */
73 lcd_clear_display();
77 #ifdef ARCHOS_RECORDER
78 if (charge_state == CHARGING)
79 msg = "charging";
80 else if (charge_state == TOPOFF)
81 msg = "topoff charge";
82 else if (charge_state == TRICKLE)
83 msg = "trickle charge";
84 else
85 msg = "not charging";
86 #else
87 msg = "charging";
88 #endif
89 lcd_puts(0, 0, msg);
91 char buf[32];
92 int battv = battery_voltage();
93 snprintf(buf, sizeof(buf), "%d.%02dV %d%%",
94 battv / 1000, (battv % 1000) / 10, battery_level());
95 lcd_puts(0, 1, buf);
97 lcd_update();
99 button = button_get_w_tmo(HZ/2);
100 #ifdef BUTTON_ON
101 if (button == (BUTTON_ON | BUTTON_REL))
102 #else
103 if (button == (BUTTON_RIGHT | BUTTON_REL))
104 #endif
105 break; /* start */
106 else
108 if (usb_detect() == USB_INSERTED)
109 break;
110 else if (!charger_inserted())
111 power_off(); /* charger removed: power down */
113 } while (1);
115 #endif /* CONFIG_CHARGING */
117 /* prompt user to plug USB and fix a problem */
118 static void prompt_usb(const char* msg1, const char* msg2)
120 int button;
121 lcd_clear_display();
122 lcd_puts(0, 0, msg1);
123 lcd_puts(0, 1, msg2);
124 #ifdef HAVE_LCD_BITMAP
125 lcd_puts(0, 2, "Insert USB cable");
126 lcd_puts(0, 3, "and fix it.");
127 #endif
128 lcd_update();
131 button = button_get(true);
132 if (button == SYS_POWEROFF)
134 power_off();
136 } while (button != SYS_USB_CONNECTED);
137 usb_screen();
138 system_reboot();
141 void main(void)
143 int rc;
145 power_init();
146 system_init();
147 kernel_init();
148 lcd_init();
149 show_logo();
150 enable_irq();
151 adc_init();
152 usb_init();
153 button_init();
154 powermgmt_init();
156 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
157 if (charger_inserted()
158 #ifdef ATA_POWER_PLAYERSTYLE
159 && !ide_powered() /* relies on probing result from bootloader */
160 #endif
163 charging_screen(); /* display a "charging" screen */
164 show_logo(); /* again, to provide better visual feedback */
166 #endif
168 rc = storage_init();
169 if(rc)
171 #ifdef HAVE_LCD_BITMAP
172 char str[32];
173 lcd_clear_display();
174 snprintf(str, 31, "ATA error: %d", rc);
175 lcd_puts(0, 1, str);
176 lcd_update();
177 while(!(button_get(true) & BUTTON_REL));
178 #endif
179 panicf("storage: %d", rc);
182 usb_start_monitoring();
183 while (usb_detect() == USB_INSERTED)
184 { /* enter USB mode early, before trying to mount */
185 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
187 usb_screen();
191 rc = disk_mount_all();
192 if (rc<=0)
194 prompt_usb("No partition", "found.");
197 { // rolo the firmware
198 static const char filename[] = "/" BOOTFILE;
199 rolo_load((char*)filename); /* won't return if started */
201 prompt_usb("No firmware", filename);
207 /* These functions are present in the firmware library, but we reimplement
208 them here because the originals do a lot more than we want */
210 void audio_stop(void)
214 int audio_status(void)
216 return 0;
219 void audio_stop_recording(void)
223 void mp3_shutdown(void)