blob: 11c552866b1bfd2df221c73306d7c8ee40aa5060 [file] [log] [blame]
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Linus Nielsen Feltzing4fb389f2007-02-22 21:44:12 +00008 * $Id$
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +00009 *
10 * Copyright (C) 2007 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20
21#include <stdlib.h>
22#include <stdio.h>
23#include "inttypes.h"
24#include "string.h"
25#include "cpu.h"
26#include "system.h"
27#include "lcd.h"
28#include "lcd-remote.h"
29#include "kernel.h"
30#include "thread.h"
31#include "ata.h"
32#include "usb.h"
33#include "disk.h"
34#include "font.h"
35#include "adc.h"
36#include "backlight.h"
37#include "backlight-target.h"
38#include "button.h"
39#include "panic.h"
40#include "power.h"
41#include "file.h"
42
43#include "pcf50606.h"
44#include "common.h"
45
46#include <stdarg.h>
47
48/* Maximum allowed firmware image size. 10MB is more than enough */
49#define MAX_LOADSIZE (10*1024*1024)
50
51#define DRAM_START 0x31000000
52
53int usb_screen(void)
54{
55 return 0;
56}
57
58char version[] = APPSVERSION;
59
60/* Reset the cookie for the crt0 crash check */
61inline void __reset_cookie(void)
62{
63 asm(" move.l #0,%d0");
64 asm(" move.l %d0,0x10017ffc");
65}
66
67void start_firmware(void)
68{
69 asm(" move.w #0x2700,%sr");
70 __reset_cookie();
71 asm(" move.l %0,%%d0" :: "i"(DRAM_START));
72 asm(" movec.l %d0,%vbr");
73 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START));
74 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4)));
75 asm(" jmp (%a0)");
76}
77
78void shutdown(void)
79{
80 printf("Shutting down...");
81
82 /* We need to gracefully spin down the disk to prevent clicks. */
83 if (ide_powered())
84 {
85 /* Make sure ATA has been initialized. */
86 ata_init();
87
88 /* And put the disk into sleep immediately. */
89 ata_sleepnow();
90 }
91
92 sleep(HZ*2);
93
94 /* Backlight OFF */
95 __backlight_off();
96#ifdef HAVE_REMOTE_LCD
97 __remote_backlight_off();
98#endif
99
100 __reset_cookie();
101 power_off();
102}
103
104/* Print the battery voltage (and a warning message). */
105void check_battery(void)
106{
Jens Arnold0fac4922007-08-17 06:45:18 +0000107 int battery_voltage, batt_int, batt_frac;
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000108
Jens Arnold0fac4922007-08-17 06:45:18 +0000109 battery_voltage = battery_adc_voltage();
110 batt_int = battery_voltage / 1000;
111 batt_frac = (battery_voltage % 1000) / 10;
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000112
113 printf("Batt: %d.%02dV", batt_int, batt_frac);
114
115 if (battery_voltage <= 350)
116 {
117 printf("WARNING! BATTERY LOW!!");
118 sleep(HZ*2);
119 }
120}
121
122void main(void)
123{
124 int i;
125 int rc;
126 bool rc_on_button = false;
127 bool on_button = false;
128 bool rec_button = false;
129 bool hold_status = false;
130 int data;
131
132 (void)rc_on_button;
133 (void)on_button;
134 (void)rec_button;
135 (void)hold_status;
136 (void)data;
137 power_init();
138
139 system_init();
140 kernel_init();
141
142 set_cpu_frequency(CPUFREQ_NORMAL);
143 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
144
145 set_irq_level(0);
146 lcd_init();
147#ifdef HAVE_REMOTE_LCD
148 lcd_remote_init();
149#endif
150 backlight_init();
151 font_init();
152 adc_init();
153 button_init();
154
155 printf("Rockbox boot loader");
156 printf("Version %s", version);
157
158 check_battery();
159
160 rc = ata_init();
161 if(rc)
162 {
163 printf("ATA error: %d", rc);
164 sleep(HZ*5);
165 power_off();
166 }
167
168 disk_init();
169
170 rc = disk_mount_all();
171 if (rc<=0)
172 {
173 printf("No partition found");
174 sleep(HZ*5);
175 power_off();
176 }
177
178 printf("Loading firmware");
179 i = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE);
180 printf("Result: %s", strerror(i));
181
182 if (i < EOK) {
183 printf("Error!");
Jens Arnoldf8ffca42007-03-05 00:14:14 +0000184 printf("Can't load rockbox.iaudio:");
Linus Nielsen Feltzingec549ec2007-02-22 21:38:59 +0000185 printf(strerror(rc));
186 sleep(HZ*3);
187 power_off();
188 } else {
189 start_firmware();
190 }
191}
192
193/* These functions are present in the firmware library, but we reimplement
194 them here because the originals do a lot more than we want */
195void screen_dump(void)
196{
197}