1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
30 #include "lcd-remote.h"
38 #include "backlight.h"
39 #include "backlight-target.h"
43 #include "powermgmt.h"
53 /* Maximum allowed firmware image size. 10MB is more than enough */
54 #define MAX_LOADSIZE (10*1024*1024)
56 #define DRAM_START 0x31000000
63 /* Reset the cookie for the crt0 crash check */
64 inline void __reset_cookie(void)
66 asm(" move.l #0,%d0");
67 asm(" move.l %d0,0x10017ffc");
70 void start_firmware(void)
73 asm(" move.w #0x2700,%sr");
75 asm(" move.l %0,%%d0" :: "i"(DRAM_START
));
76 asm(" movec.l %d0,%vbr");
77 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START
));
78 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START
+4)));
84 printf("Shutting down...");
86 /* We need to gracefully spin down the disk to prevent clicks. */
89 /* Make sure ATA has been initialized. */
92 /* And put the disk into sleep immediately. */
100 #ifdef HAVE_REMOTE_LCD
101 _remote_backlight_off();
108 /* Print the battery voltage (and a warning message). */
109 void check_battery(void)
111 int battery_voltage
, batt_int
, batt_frac
;
113 battery_voltage
= _battery_voltage();
114 batt_int
= battery_voltage
/ 1000;
115 batt_frac
= (battery_voltage
% 1000) / 10;
117 printf("Batt: %d.%02dV", batt_int
, batt_frac
);
119 if (battery_voltage
<= 3500)
121 printf("WARNING! BATTERY LOW!!");
126 #if defined(IAUDIO_M5) || defined(IAUDIO_X5)
127 int initial_gpio_read
;
134 bool rc_on_button
= false;
135 bool on_button
= false;
137 /* We want to read the buttons as early as possible, before the user
138 releases the ON button */
141 or_l(0x80000000, &GPIO_FUNCTION
); /* remote Play button */
142 and_l(~0x80000000, &GPIO_ENABLE
);
143 or_l(0x00000202, &GPIO1_FUNCTION
); /* main Hold & Play */
145 if ((GPIO1_READ
& 0x000000002) == 0)
148 if ((GPIO_READ
& 0x80000000) == 0)
150 #elif defined(IAUDIO_M5) || defined(IAUDIO_X5)
151 or_l(0x0e000000, &GPIO_FUNCTION
); /* main Hold & Power, remote Play */
152 and_l(~0x0e000000, &GPIO_ENABLE
);
154 if ((initial_gpio_read
& 0x04000000) == 0)
157 if ((initial_gpio_read
& 0x02000000) == 0)
166 set_cpu_frequency(CPUFREQ_NORMAL
);
167 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
171 #ifdef HAVE_REMOTE_LCD
179 if ((!on_button
|| button_hold())
180 && (!rc_on_button
|| remote_button_hold())
181 && !charger_inserted())
183 /* No need to check for USB connection here, as USB is handled
184 * in the cowon loader. */
185 if (on_button
|| rc_on_button
)
186 printf("Hold switch on");
190 printf("Rockbox boot loader");
191 printf("Version " RBVERSION
);
198 printf("ATA error: %d", rc
);
205 rc
= disk_mount_all();
208 printf("No partition found");
213 printf("Loading firmware");
214 i
= load_firmware((unsigned char *)DRAM_START
, BOOTFILE
, MAX_LOADSIZE
);
215 printf("Result: %s", strerror(i
));
219 printf("Can't load " BOOTFILE
": ");
220 printf(strerror(rc
));
228 /* These functions are present in the firmware library, but we reimplement
229 them here because the originals do a lot more than we want */
230 void screen_dump(void)