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"
|
2010-05-27 09:41:46 +00:00
|
|
|
#include "version.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
|
|
|
|
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");
|
2010-05-27 09:41:46 +00:00
|
|
|
printf("Version " RBVERSION);
|
2007-04-21 04:48:20 +00:00
|
|
|
|
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();
|
2010-06-23 05:08:36 +00:00
|
|
|
error(EATA, rc, true);
|
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)
|
|
|
|
{
|
2010-06-23 05:08:36 +00:00
|
|
|
error(EDISK, rc, true);
|
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 */
|
2011-12-17 07:27:24 +00:00
|
|
|
commit_discard_idcache();
|
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)
|
2010-06-23 05:08:36 +00:00
|
|
|
error(EBOOTFILE, rc, true);
|
2007-04-21 04:48:20 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2011-12-17 07:27:24 +00:00
|
|
|
commit_discard_idcache();
|
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
|
|
|
}
|
|
|
|
|