1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Linus Nielsen Feltzing
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
28 #include "lcd-remote.h"
36 #include "backlight.h"
37 #include "backlight-target.h"
41 #include "powermgmt.h"
49 /* Maximum allowed firmware image size. 10MB is more than enough */
50 #define MAX_LOADSIZE (10*1024*1024)
52 #define DRAM_START 0x31000000
59 char version
[] = APPSVERSION
;
61 /* Reset the cookie for the crt0 crash check */
62 inline void __reset_cookie(void)
64 asm(" move.l #0,%d0");
65 asm(" move.l %d0,0x10017ffc");
68 void start_firmware(void)
71 asm(" move.w #0x2700,%sr");
73 asm(" move.l %0,%%d0" :: "i"(DRAM_START
));
74 asm(" movec.l %d0,%vbr");
75 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START
));
76 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START
+4)));
82 printf("Shutting down...");
84 /* We need to gracefully spin down the disk to prevent clicks. */
87 /* Make sure ATA has been initialized. */
90 /* And put the disk into sleep immediately. */
98 #ifdef HAVE_REMOTE_LCD
99 _remote_backlight_off();
106 /* Print the battery voltage (and a warning message). */
107 void check_battery(void)
109 int battery_voltage
, batt_int
, batt_frac
;
111 battery_voltage
= battery_adc_voltage();
112 batt_int
= battery_voltage
/ 1000;
113 batt_frac
= (battery_voltage
% 1000) / 10;
115 printf("Batt: %d.%02dV", batt_int
, batt_frac
);
117 if (battery_voltage
<= 3500)
119 printf("WARNING! BATTERY LOW!!");
128 bool rc_on_button
= false;
129 bool on_button
= false;
131 /* We want to read the buttons as early as possible, before the user
132 releases the ON button */
135 or_l(0x80000000, &GPIO_FUNCTION
); /* remote Play button */
136 and_l(~0x80000000, &GPIO_ENABLE
);
137 or_l(0x00000202, &GPIO1_FUNCTION
); /* main Hold & Play */
139 if ((GPIO1_READ
& 0x000000002) == 0)
142 if ((GPIO_READ
& 0x80000000) == 0)
144 #elif defined(IAUDIO_M5) || defined(IAUDIO_X5)
147 or_l(0x0e000000, &GPIO_FUNCTION
); /* main Hold & Power, remote Play */
148 and_l(~0x0e000000, &GPIO_ENABLE
);
152 if ((data
& 0x04000000) == 0)
155 if ((data
& 0x02000000) == 0)
164 set_cpu_frequency(CPUFREQ_NORMAL
);
165 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
169 #ifdef HAVE_REMOTE_LCD
177 if ((!on_button
|| button_hold())
178 && (!rc_on_button
|| remote_button_hold())
179 && !charger_inserted())
181 /* No need to check for USB connection here, as USB is handled
182 * in the cowon loader. */
183 if (on_button
|| rc_on_button
)
184 printf("Hold switch on");
188 printf("Rockbox boot loader");
189 printf("Version %s", version
);
196 printf("ATA error: %d", rc
);
203 rc
= disk_mount_all();
206 printf("No partition found");
211 printf("Loading firmware");
212 i
= load_firmware((unsigned char *)DRAM_START
, BOOTFILE
, MAX_LOADSIZE
);
213 printf("Result: %s", strerror(i
));
217 printf("Can't load rockbox.iaudio:");
218 printf(strerror(rc
));
226 /* These functions are present in the firmware library, but we reimplement
227 them here because the originals do a lot more than we want */
228 void screen_dump(void)