2007-02-23 09:30:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Greg White
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-02-23 09:30:09 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2006-08-12 08:27:48 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2007-04-21 04:48:20 +00:00
|
|
|
#include "inttypes.h"
|
|
|
|
#include "string.h"
|
2006-08-12 08:27:48 +00:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
2008-11-01 16:14:28 +00:00
|
|
|
#include "storage.h"
|
2006-08-12 08:27:48 +00:00
|
|
|
#include "fat.h"
|
|
|
|
#include "disk.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "backlight.h"
|
2007-04-21 04:48:20 +00:00
|
|
|
#include "backlight-target.h"
|
|
|
|
#include "button.h"
|
2006-08-12 08:27:48 +00:00
|
|
|
#include "panic.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "file.h"
|
2007-02-22 15:09:49 +00:00
|
|
|
#include "common.h"
|
2007-04-21 04:48:20 +00:00
|
|
|
#include "rbunicode.h"
|
|
|
|
#include "usb.h"
|
2007-10-23 03:29:15 +00:00
|
|
|
#include "mmu-arm.h"
|
2008-11-12 05:11:18 +00:00
|
|
|
#include "rtc.h"
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
#include <stdarg.h>
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2006-08-12 08:27:48 +00:00
|
|
|
char version[] = APPSVERSION;
|
|
|
|
|
2008-11-12 05:11:18 +00:00
|
|
|
void shutdown(void)
|
|
|
|
{
|
|
|
|
/* We need to gracefully spin down the disk to prevent clicks. */
|
|
|
|
if (ide_powered())
|
|
|
|
{
|
|
|
|
/* Make sure ATA has been initialized. */
|
|
|
|
ata_init();
|
|
|
|
|
|
|
|
/* And put the disk into sleep immediately. */
|
|
|
|
ata_sleepnow();
|
|
|
|
}
|
|
|
|
|
|
|
|
_backlight_off();
|
|
|
|
|
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
void main(void)
|
2006-12-29 02:49:12 +00:00
|
|
|
{
|
|
|
|
unsigned char* loadbuffer;
|
|
|
|
int buffer_size;
|
|
|
|
int rc;
|
|
|
|
int(*kernel_entry)(void);
|
2006-08-12 08:27:48 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
system_init();
|
2008-12-08 23:31:05 +00:00
|
|
|
kernel_init(); /* Need the kernel to sleep */
|
|
|
|
|
|
|
|
enable_interrupt(IRQ_FIQ_STATUS);
|
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
lcd_init();
|
|
|
|
backlight_init();
|
2008-11-12 05:11:18 +00:00
|
|
|
button_init();
|
2007-04-21 04:48:20 +00:00
|
|
|
font_init();
|
2008-11-12 05:11:18 +00:00
|
|
|
adc_init();
|
2007-01-17 01:49:19 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
2008-11-12 05:11:18 +00:00
|
|
|
|
|
|
|
/* These checks should only run if the bootloader is flashed */
|
|
|
|
if(GSTATUS3&0x02)
|
|
|
|
{
|
|
|
|
GSTATUS3&=0xFFFFFFFD;
|
|
|
|
if(!(GPGDAT&BUTTON_POWER) && charger_inserted())
|
|
|
|
{
|
|
|
|
while(!(GPGDAT&BUTTON_POWER) && charger_inserted())
|
|
|
|
{
|
|
|
|
char msg[20];
|
|
|
|
if(charging_state())
|
|
|
|
{
|
|
|
|
snprintf(msg,sizeof(msg),"Charging");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(msg,sizeof(msg),"Charge Complete");
|
|
|
|
}
|
|
|
|
reset_screen();
|
|
|
|
lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
|
|
|
|
(LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
#if defined(HAVE_RTC_ALARM)
|
|
|
|
/* Check if the alarm went off while charging */
|
|
|
|
if(rtc_check_alarm_flag())
|
|
|
|
{
|
|
|
|
GSTATUS3=1; /* Normally this is set in crt0.s */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if(!(GPGDAT&BUTTON_POWER)
|
|
|
|
#if defined(HAVE_RTC_ALARM)
|
|
|
|
&& !GSTATUS3
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(button_hold())
|
|
|
|
{
|
|
|
|
const char msg[] = "HOLD is enabled";
|
|
|
|
reset_screen();
|
|
|
|
lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
|
|
|
|
(LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
sleep(2*HZ);
|
|
|
|
|
|
|
|
shutdown();
|
|
|
|
}
|
|
|
|
}
|
2006-08-12 08:27:48 +00:00
|
|
|
|
2008-11-12 05:11:18 +00:00
|
|
|
power_init();
|
2007-04-21 04:48:20 +00:00
|
|
|
usb_init();
|
2006-08-12 08:27:48 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
/* Enter USB mode without USB thread */
|
2007-09-04 08:03:07 +00:00
|
|
|
if(usb_detect() == USB_INSERTED)
|
2007-04-21 04:48:20 +00:00
|
|
|
{
|
|
|
|
const char msg[] = "Bootloader USB mode";
|
|
|
|
reset_screen();
|
|
|
|
lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
|
|
|
|
(LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
|
|
|
|
lcd_update();
|
2006-08-12 08:27:48 +00:00
|
|
|
|
2008-11-01 16:14:28 +00:00
|
|
|
storage_enable(false);
|
2007-04-21 04:48:20 +00:00
|
|
|
sleep(HZ/20);
|
|
|
|
usb_enable(true);
|
2006-08-12 08:27:48 +00:00
|
|
|
|
2007-09-04 08:03:07 +00:00
|
|
|
while (usb_detect() == USB_INSERTED)
|
2007-04-21 04:48:20 +00:00
|
|
|
sleep(HZ);
|
2006-08-12 08:27:48 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
usb_enable(false);
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
reset_screen();
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
2008-11-12 05:11:18 +00:00
|
|
|
reset_screen();
|
2007-04-21 04:48:20 +00:00
|
|
|
|
|
|
|
/* Show debug messages if button is pressed */
|
2009-04-21 04:36:46 +00:00
|
|
|
if(button_read_device()&BUTTON_A)
|
2007-04-21 04:48:20 +00:00
|
|
|
verbose = true;
|
|
|
|
|
|
|
|
printf("Rockbox boot loader");
|
|
|
|
printf("Version %s", version);
|
|
|
|
|
2008-04-22 04:34:25 +00:00
|
|
|
sleep(50); /* ATA seems to error without this pause */
|
|
|
|
|
2008-11-01 16:14:28 +00:00
|
|
|
rc = storage_init();
|
2007-04-21 04:48:20 +00:00
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
reset_screen();
|
|
|
|
error(EATA, rc);
|
2007-01-17 01:49:19 +00:00
|
|
|
}
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
disk_init();
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
rc = disk_mount_all();
|
|
|
|
if (rc<=0)
|
|
|
|
{
|
|
|
|
error(EDISK,rc);
|
2006-12-29 02:49:12 +00:00
|
|
|
}
|
2006-08-12 08:27:48 +00:00
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
printf("Loading firmware");
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2008-12-08 23:31:05 +00:00
|
|
|
/* Flush out anything pending first */
|
2009-02-11 12:55:51 +00:00
|
|
|
cpucache_invalidate();
|
2008-12-08 23:31:05 +00:00
|
|
|
|
2008-04-22 04:34:25 +00:00
|
|
|
loadbuffer = (unsigned char*) 0x31000000;
|
|
|
|
buffer_size = (unsigned char*)0x31400000 - loadbuffer;
|
2007-04-21 04:48:20 +00:00
|
|
|
|
|
|
|
rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
|
|
|
|
if(rc < 0)
|
|
|
|
error(EBOOTFILE, rc);
|
|
|
|
|
2008-12-08 23:31:05 +00:00
|
|
|
storage_close();
|
|
|
|
system_prepare_fw_start();
|
|
|
|
|
2007-04-21 04:48:20 +00:00
|
|
|
if (rc == EOK)
|
|
|
|
{
|
2009-02-11 12:55:51 +00:00
|
|
|
cpucache_invalidate();
|
2007-01-13 02:24:15 +00:00
|
|
|
kernel_entry = (void*) loadbuffer;
|
2006-12-29 02:49:12 +00:00
|
|
|
rc = kernel_entry();
|
|
|
|
}
|
2008-12-08 23:31:05 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Halt */
|
|
|
|
while (1)
|
|
|
|
core_idle();
|
|
|
|
#else
|
|
|
|
/* Return and restart */
|
|
|
|
#endif
|
2006-08-12 08:27:48 +00:00
|
|
|
}
|
|
|
|
|