2008-07-14 15:03:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Maurus Cuelenaere
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "jz4740.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "lcd.h"
|
2008-12-19 11:13:58 +00:00
|
|
|
#include "usb.h"
|
2008-07-14 15:03:10 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "button.h"
|
2008-07-16 15:25:35 +00:00
|
|
|
#include "common.h"
|
2008-12-19 11:29:18 +00:00
|
|
|
#include "storage.h"
|
2009-02-09 10:02:38 +00:00
|
|
|
#include "disk.h"
|
|
|
|
#include "string.h"
|
2009-04-20 18:28:51 +00:00
|
|
|
#include "adc.h"
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2009-02-09 10:02:38 +00:00
|
|
|
static void show_splash(int timeout, const char *msg)
|
|
|
|
{
|
|
|
|
reset_screen();
|
|
|
|
lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
|
|
|
|
(LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
sleep(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_mode(void)
|
|
|
|
{
|
|
|
|
int button;
|
|
|
|
|
|
|
|
/* Init backlight */
|
|
|
|
backlight_init();
|
|
|
|
|
|
|
|
/* Init USB */
|
|
|
|
usb_init();
|
|
|
|
usb_start_monitoring();
|
|
|
|
|
|
|
|
/* Wait for threads to connect */
|
|
|
|
show_splash(HZ/2, "Waiting for USB");
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
button = button_get_w_tmo(HZ/2);
|
|
|
|
|
|
|
|
if (button == SYS_USB_CONNECTED)
|
|
|
|
break; /* Hit */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (button == SYS_USB_CONNECTED)
|
|
|
|
{
|
|
|
|
/* Got the message - wait for disconnect */
|
|
|
|
show_splash(0, "Bootloader USB mode");
|
|
|
|
|
|
|
|
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
button = button_get(true);
|
|
|
|
if (button == SYS_USB_DISCONNECTED)
|
|
|
|
{
|
|
|
|
usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_screen();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void boot_of(void)
|
|
|
|
{
|
|
|
|
/* Init backlight */
|
|
|
|
backlight_init();
|
|
|
|
}
|
2008-07-14 15:03:10 +00:00
|
|
|
|
|
|
|
int main(void)
|
2008-08-10 21:44:48 +00:00
|
|
|
{
|
2009-04-21 15:47:39 +00:00
|
|
|
int rc;
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
int dummy;
|
|
|
|
#endif
|
2009-02-09 10:02:38 +00:00
|
|
|
void (*kernel_entry)(void);
|
|
|
|
|
2008-07-14 15:03:10 +00:00
|
|
|
kernel_init();
|
|
|
|
lcd_init();
|
|
|
|
font_init();
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
button_init();
|
2009-04-20 18:28:51 +00:00
|
|
|
adc_init();
|
2008-11-01 16:14:28 +00:00
|
|
|
storage_init();
|
2009-02-09 10:02:38 +00:00
|
|
|
|
|
|
|
reset_screen();
|
|
|
|
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2009-02-13 00:45:49 +00:00
|
|
|
rc = button_read_device(&dummy);
|
2008-12-19 11:13:58 +00:00
|
|
|
#else
|
2009-02-09 10:02:38 +00:00
|
|
|
rc = button_read_device();
|
2008-12-19 11:13:58 +00:00
|
|
|
#endif
|
2009-02-09 10:02:38 +00:00
|
|
|
|
|
|
|
if(rc & BUTTON_VOL_UP)
|
|
|
|
usb_mode();
|
|
|
|
else if(button_hold())
|
|
|
|
boot_of();
|
|
|
|
else if(rc)
|
|
|
|
verbose = true;
|
|
|
|
|
2009-02-16 23:54:18 +00:00
|
|
|
/* Only enable backlight when button is pressed */
|
2009-02-09 10:02:38 +00:00
|
|
|
if(verbose)
|
2009-02-17 20:40:58 +00:00
|
|
|
{
|
2009-02-09 10:02:38 +00:00
|
|
|
backlight_init();
|
2009-02-17 20:40:58 +00:00
|
|
|
printf(MODEL_NAME" Rockbox Bootloader");
|
|
|
|
printf("Version "APPSVERSION);
|
|
|
|
}
|
2008-08-26 21:48:49 +00:00
|
|
|
|
2009-02-09 10:02:38 +00:00
|
|
|
rc = storage_init();
|
|
|
|
if(rc)
|
|
|
|
error(EATA, rc);
|
|
|
|
|
|
|
|
rc = disk_mount_all();
|
|
|
|
if (rc <= 0)
|
|
|
|
error(EDISK,rc);
|
2008-12-19 11:13:58 +00:00
|
|
|
|
2009-02-09 10:02:38 +00:00
|
|
|
printf("Loading firmware");
|
|
|
|
rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
|
|
|
|
if(rc < 0)
|
|
|
|
printf("Error: %s", strerror(rc));
|
|
|
|
|
|
|
|
if (rc == EOK)
|
2008-07-14 15:03:10 +00:00
|
|
|
{
|
2009-02-09 10:02:38 +00:00
|
|
|
printf("Starting Rockbox...");
|
2009-04-20 18:28:51 +00:00
|
|
|
adc_close(); /* Disable SADC */
|
2009-02-09 10:02:38 +00:00
|
|
|
disable_interrupt();
|
|
|
|
kernel_entry = (void*) CONFIG_SDRAM_START;
|
|
|
|
kernel_entry();
|
2008-07-14 15:03:10 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 10:02:38 +00:00
|
|
|
/* Halt */
|
|
|
|
while (1)
|
|
|
|
core_idle();
|
|
|
|
|
2008-07-14 15:03:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|