1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 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 ****************************************************************************/
33 #include "backlight.h"
44 #define DRAM_START 0x31000000
53 char version
[] = APPSVERSION
;
57 void printf(const char *format
, ...)
65 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
68 lcd_puts(0, line
++, ptr
);
74 void start_iriver_fw(void)
76 asm(" move.w #0x2700,%sr");
77 /* Reset the cookie for the crt0 crash check */
78 asm(" move.l #0,%d0");
79 asm(" move.l %d0,0x10017ffc");
80 asm(" movec.l %d0,%vbr");
86 int load_firmware(void)
95 unsigned char *buf
= (unsigned char *)DRAM_START
;
97 fd
= open("/.rockbox/" BOOTFILE
, O_RDONLY
);
100 fd
= open("/" BOOTFILE
, O_RDONLY
);
105 len
= filesize(fd
) - 8;
107 printf("Length: %x", len
);
110 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
112 rc
= read(fd
, &chksum
, 4);
116 printf("Checksum: %x", chksum
);
119 rc
= read(fd
, model
, 4);
125 printf("Model name: %s", model
);
128 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
130 rc
= read(fd
, buf
, len
);
138 for(i
= 0;i
< len
;i
++) {
142 printf("Sum: %x", sum
);
152 void start_firmware(void)
154 asm(" move.w #0x2700,%sr");
155 /* Reset the cookie for the crt0 crash check */
156 asm(" move.l #0,%d0");
157 asm(" move.l %d0,0x10017ffc");
158 asm(" move.l %0,%%d0" :: "i"(DRAM_START
));
159 asm(" movec.l %d0,%vbr");
160 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START
));
161 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START
+4)));
169 bool rc_on_button
= false;
170 bool on_button
= false;
172 int adc_battery
, battery_voltage
, batt_int
, batt_frac
;
183 set_cpu_frequency(CPUFREQ_NORMAL
);
191 printf("Rockbox boot loader");
192 printf("Version %s", version
);
195 adc_battery
= adc_read(ADC_BATTERY
);
197 battery_voltage
= (adc_battery
* BATTERY_SCALE_FACTOR
) / 10000;
198 batt_int
= battery_voltage
/ 100;
199 batt_frac
= battery_voltage
% 100;
201 printf("Batt: %d.%02dV", batt_int
, batt_frac
);
207 printf("ATA error: %d", rc
);
214 rc
= disk_mount_all();
217 printf("No partition found");
222 printf("Loading firmware");
225 printf("Result: %d", i
);
234 /* We want to read the buttons as early as possible, before the user
235 releases the ON button */
237 /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs
238 (The ON and Hold buttons on the main unit and the remote) */
239 or_l(0x00100062, &GPIO1_FUNCTION
);
240 and_l(~0x00100062, &GPIO1_ENABLE
);
243 if ((data
& 0x20) == 0)
246 if ((data
& 0x40) == 0)
249 /* Set the default state of the hard drive power to OFF */
250 ide_power_enable(false);
254 /* Turn off if neither ON button is pressed */
255 if(!(on_button
|| rc_on_button
|| usb_detect()))
259 or_l(0x00020000, &GPIO1_ENABLE
);
260 or_l(0x00020000, &GPIO1_FUNCTION
);
261 and_l(~0x00020000, &GPIO1_OUT
);
263 /* Remote backlight ON */
264 #ifdef HAVE_REMOTE_LCD
265 #ifdef IRIVER_H300_SERIES
266 or_l(0x00000002, &GPIO1_ENABLE
);
267 and_l(~0x00000002, &GPIO1_OUT
);
269 or_l(0x00000800, &GPIO_ENABLE
);
270 or_l(0x00000800, &GPIO_FUNCTION
);
271 and_l(~0x00000800, &GPIO_OUT
);
275 /* Power on the hard drive early, to speed up the loading.
276 Some H300 don't like this, so we only do it for the H100 */
277 #ifndef IRIVER_H300_SERIES
278 if(!((on_button
&& button_hold()) ||
279 (rc_on_button
&& remote_button_hold()))) {
280 ide_power_enable(true);
287 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
288 /* Set up waitstates for the peripherals */
289 set_cpu_frequency(0); /* PLL off */
303 lcd_setfont(FONT_SYSFIXED
);
305 printf("Rockbox boot loader");
306 printf("Version %s", version
);
309 sleep(HZ
/50); /* Allow the button driver to check the buttons */
311 /* Holding REC while starting runs the original firmware */
312 if(((button_status() & BUTTON_REC
) == BUTTON_REC
) ||
313 ((button_status() & BUTTON_RC_REC
) == BUTTON_RC_REC
)) {
314 printf("Starting original firmware...");
319 /* Don't start if the Hold button is active on the device you
321 if(!usb_detect() && ((on_button
&& button_hold()) ||
322 (rc_on_button
&& remote_button_hold()))) {
323 printf("HOLD switch on, power off...");
328 #ifdef HAVE_REMOTE_LCD
329 #ifdef IRIVER_H300_SERIES
330 or_l(0x00000002, &GPIO1_OUT
);
332 or_l(0x00000800, &GPIO_OUT
);
335 /* Reset the cookie for the crt0 crash check */
336 asm(" move.l #0,%d0");
337 asm(" move.l %d0,0x10017ffc");
343 adc_battery
= adc_read(ADC_BATTERY
);
345 battery_voltage
= (adc_battery
* BATTERY_SCALE_FACTOR
) / 10000;
346 batt_int
= battery_voltage
/ 100;
347 batt_frac
= battery_voltage
% 100;
349 printf("Batt: %d.%02dV", batt_int
, batt_frac
);
352 if(battery_voltage
<= 300) {
353 printf("WARNING! BATTERY LOW!!");
362 printf("ATA error: %d", rc
);
363 printf("Insert USB cable and press");
366 while(!(button_get(true) & BUTTON_REL
));
369 /* A hack to enter USB mode without using the USB thread */
372 const char msg
[] = "Bootloader USB mode";
374 font_getstringsize(msg
, &w
, &h
, FONT_SYSFIXED
);
376 lcd_putsxy((LCD_WIDTH
-w
)/2, (LCD_HEIGHT
-h
)/2, msg
);
379 #ifdef IRIVER_H300_SERIES
389 ata_spin(); /* Prevent the drive from spinning down */
393 or_l(0x00020000, &GPIO1_OUT
);
396 cpu_idle_mode(false);
398 ata_init(); /* Reinitialize ATA and continue booting */
407 rc
= disk_mount_all();
411 printf("No partition found");
413 while(button_get(true) != SYS_USB_CONNECTED
) {};
416 printf("Loading firmware");
419 printf("Result: %d", i
);
426 #endif /* IAUDIO_X5 */
429 /* These functions are present in the firmware library, but we reimplement
430 them here because the originals do a lot more than we want */
432 void reset_poweroff_timer(void)
436 void screen_dump(void)
449 void sys_poweroff(void)