2002-09-03 09:44:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Randy D. Wood
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-02-02 21:47:08 +00:00
|
|
|
#include "config.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
#include "lcd.h"
|
2006-04-24 06:45:27 +00:00
|
|
|
#include "lcd-remote.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "sprintf.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "file.h"
|
2005-04-04 12:06:29 +00:00
|
|
|
#include "audio.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "string.h"
|
2003-05-09 16:01:21 +00:00
|
|
|
#include "buffer.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
|
2006-11-10 20:26:01 +00:00
|
|
|
#if !defined(IRIVER_IFP7XX_SERIES) && \
|
2006-10-23 13:11:57 +00:00
|
|
|
(CONFIG_CPU != PP5002) && !defined(IRIVER_H10) && \
|
2006-11-22 00:41:30 +00:00
|
|
|
!defined(IRIVER_H10_5GB) && (CONFIG_CPU != S3C2440) && \
|
|
|
|
!defined(SANSA_E200)
|
2006-11-10 20:26:01 +00:00
|
|
|
/* FIX: this doesn't work on iFP, 3rd Gen ipods, or H10 yet */
|
2006-11-22 00:41:30 +00:00
|
|
|
/* TODO: Test on the Sansa */
|
2005-02-02 21:47:08 +00:00
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
#define IRQ0_EDGE_TRIGGER 0x80
|
|
|
|
|
2004-08-16 23:37:23 +00:00
|
|
|
static void rolo_error(const char *text)
|
2002-09-03 09:44:08 +00:00
|
|
|
{
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0, 0, "ROLO error:");
|
|
|
|
lcd_puts_scroll(0, 1, text);
|
|
|
|
lcd_update();
|
|
|
|
button_get(true);
|
2003-05-09 16:01:21 +00:00
|
|
|
button_get(true);
|
|
|
|
button_get(true);
|
2002-09-03 09:44:08 +00:00
|
|
|
lcd_stop_scroll();
|
|
|
|
}
|
2003-10-12 16:40:45 +00:00
|
|
|
|
2005-03-31 08:47:02 +00:00
|
|
|
#if CONFIG_CPU == SH7034
|
2003-10-12 16:40:45 +00:00
|
|
|
/* these are in assembler file "descramble.S" */
|
2004-08-16 23:37:23 +00:00
|
|
|
extern unsigned short descramble(const unsigned char* source,
|
|
|
|
unsigned char* dest, int length);
|
|
|
|
extern void rolo_restart(const unsigned char* source, unsigned char* dest,
|
|
|
|
int length);
|
2005-03-31 08:47:02 +00:00
|
|
|
#else
|
|
|
|
void rolo_restart(const unsigned char* source, unsigned char* dest,
|
|
|
|
long length) __attribute__ ((section (".icode")));
|
|
|
|
void rolo_restart(const unsigned char* source, unsigned char* dest,
|
|
|
|
long length)
|
|
|
|
{
|
|
|
|
long i;
|
2005-06-22 16:53:12 +00:00
|
|
|
unsigned char* localdest = dest;
|
2006-07-23 14:30:10 +00:00
|
|
|
#if (CONFIG_CPU==PP5020)
|
|
|
|
unsigned long* memmapregs = (unsigned long*)0xf000f000;
|
|
|
|
#endif
|
2005-03-31 08:47:02 +00:00
|
|
|
|
|
|
|
for(i = 0;i < length;i++)
|
2005-06-22 16:53:12 +00:00
|
|
|
*localdest++ = *source++;
|
2005-03-31 08:47:02 +00:00
|
|
|
|
2006-07-13 21:11:20 +00:00
|
|
|
#if defined(CPU_COLDFIRE)
|
2005-06-22 16:53:12 +00:00
|
|
|
asm (
|
|
|
|
"movec.l %0,%%vbr \n"
|
|
|
|
"move.l (%0)+,%%sp \n"
|
|
|
|
"move.l (%0),%0 \n"
|
|
|
|
"jmp (%0) \n"
|
|
|
|
: : "a"(dest)
|
|
|
|
);
|
2006-07-23 14:30:10 +00:00
|
|
|
#elif (CONFIG_CPU==PP5020)
|
|
|
|
/* Copy a further 8KB of data to try and ensure the cache is flushed */
|
|
|
|
for(i = length; i < length+8192; i++)
|
|
|
|
*localdest++ = *source++;
|
|
|
|
|
|
|
|
/* Disable cache */
|
|
|
|
outl(0x0, 0x6000C000);
|
|
|
|
|
|
|
|
/* Reset the memory mapping registers to zero */
|
|
|
|
for (i=0;i<8;i++)
|
|
|
|
memmapregs[i]=0;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
"mov r0, #0x10000000 \n"
|
|
|
|
"mov pc, r0 \n"
|
|
|
|
);
|
2005-11-11 17:51:35 +00:00
|
|
|
#endif
|
2005-03-31 08:47:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* This is assigned in the linker control file */
|
|
|
|
extern unsigned long loadaddress;
|
2003-10-12 16:40:45 +00:00
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Name: rolo_load_app(char *filename,int scrambled)
|
|
|
|
* Filename must be a fully defined filename including the path and extension
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2004-08-16 23:37:23 +00:00
|
|
|
int rolo_load(const char* filename)
|
2002-09-03 09:44:08 +00:00
|
|
|
{
|
2003-10-12 16:40:45 +00:00
|
|
|
int fd;
|
2005-03-31 08:47:02 +00:00
|
|
|
long length;
|
2006-11-22 00:41:30 +00:00
|
|
|
#if defined(CPU_COLDFIRE) || defined(CPU_PP)
|
2005-03-31 08:47:02 +00:00
|
|
|
int i;
|
|
|
|
unsigned long checksum,file_checksum;
|
|
|
|
#else
|
|
|
|
long file_length;
|
2002-09-03 09:44:08 +00:00
|
|
|
unsigned short checksum,file_checksum;
|
2005-03-31 08:47:02 +00:00
|
|
|
#endif
|
|
|
|
unsigned char* ramstart = (void*)&loadaddress;
|
2002-09-03 09:44:08 +00:00
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0, 0, "ROLO...");
|
|
|
|
lcd_puts(0, 1, "Loading");
|
|
|
|
lcd_update();
|
2006-04-24 06:45:27 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
lcd_remote_clear_display();
|
|
|
|
lcd_remote_puts(0, 0, "ROLO...");
|
|
|
|
lcd_remote_puts(0, 1, "Loading");
|
|
|
|
lcd_remote_update();
|
|
|
|
#endif
|
2002-09-03 09:44:08 +00:00
|
|
|
|
2005-04-04 12:06:29 +00:00
|
|
|
audio_stop();
|
2002-09-03 09:44:08 +00:00
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if(-1 == fd) {
|
|
|
|
rolo_error("File not found");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-03-31 08:47:02 +00:00
|
|
|
length = filesize(fd) - FIRMWARE_OFFSET_FILE_DATA;
|
|
|
|
|
2006-11-22 00:41:30 +00:00
|
|
|
#if defined(CPU_COLDFIRE) || defined(CPU_PP)
|
2005-03-31 08:47:02 +00:00
|
|
|
/* Read and save checksum */
|
|
|
|
lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
|
|
|
|
if (read(fd, &file_checksum, 4) != 4) {
|
|
|
|
rolo_error("Error Reading checksum");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-23 14:30:10 +00:00
|
|
|
|
|
|
|
/* Rockbox checksums are big-endian */
|
|
|
|
file_checksum = betoh32(file_checksum);
|
|
|
|
|
2005-03-31 08:47:02 +00:00
|
|
|
lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
|
|
|
|
|
2005-04-05 11:33:58 +00:00
|
|
|
if (read(fd, audiobuf, length) != length) {
|
2005-03-31 08:47:02 +00:00
|
|
|
rolo_error("Error Reading File");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-07-18 15:50:06 +00:00
|
|
|
checksum = MODEL_NUMBER;
|
2005-03-31 08:47:02 +00:00
|
|
|
|
|
|
|
for(i = 0;i < length;i++) {
|
2005-04-05 11:33:58 +00:00
|
|
|
checksum += audiobuf[i];
|
2005-03-31 08:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify checksum against file header */
|
|
|
|
if (checksum != file_checksum) {
|
|
|
|
rolo_error("Checksum Error");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-04-24 06:45:27 +00:00
|
|
|
lcd_puts(0, 1, "Executing");
|
2005-03-31 08:47:02 +00:00
|
|
|
lcd_update();
|
2006-04-24 06:45:27 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
lcd_remote_puts(0, 1, "Executing");
|
|
|
|
lcd_remote_update();
|
|
|
|
#endif
|
2005-03-31 08:47:02 +00:00
|
|
|
|
|
|
|
set_irq_level(HIGHEST_IRQ_LEVEL);
|
2005-11-07 23:07:19 +00:00
|
|
|
#elif CONFIG_CPU == SH7034
|
2002-09-03 09:44:08 +00:00
|
|
|
/* Read file length from header and compare to real file length */
|
2003-01-22 18:47:35 +00:00
|
|
|
lseek(fd, FIRMWARE_OFFSET_FILE_LENGTH, SEEK_SET);
|
2002-09-03 09:44:08 +00:00
|
|
|
if(read(fd, &file_length, 4) != 4) {
|
|
|
|
rolo_error("Error Reading File Length");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (length != file_length) {
|
|
|
|
rolo_error("File length mismatch");
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-31 08:47:02 +00:00
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
/* Read and save checksum */
|
2003-01-22 18:47:35 +00:00
|
|
|
lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
|
2002-09-03 09:44:08 +00:00
|
|
|
if (read(fd, &file_checksum, 2) != 2) {
|
|
|
|
rolo_error("Error Reading checksum");
|
|
|
|
return -1;
|
|
|
|
}
|
2003-01-22 18:47:35 +00:00
|
|
|
lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
|
2002-09-03 09:44:08 +00:00
|
|
|
|
|
|
|
/* verify that file can be read and descrambled */
|
2005-04-05 11:33:58 +00:00
|
|
|
if ((audiobuf + (2*length)+4) >= audiobufend) {
|
2002-09-03 09:44:08 +00:00
|
|
|
rolo_error("Not enough room to load file");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-04-05 11:33:58 +00:00
|
|
|
if (read(fd, &audiobuf[length], length) != (int)length) {
|
2002-09-03 09:44:08 +00:00
|
|
|
rolo_error("Error Reading File");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-09-09 12:59:06 +00:00
|
|
|
lcd_puts(0, 1, "Descramble");
|
2002-09-03 09:44:08 +00:00
|
|
|
lcd_update();
|
|
|
|
|
2005-04-05 11:33:58 +00:00
|
|
|
checksum = descramble(audiobuf + length, audiobuf, length);
|
2005-03-31 08:47:02 +00:00
|
|
|
|
2003-10-12 16:40:45 +00:00
|
|
|
/* Verify checksum against file header */
|
2002-09-03 09:44:08 +00:00
|
|
|
if (checksum != file_checksum) {
|
|
|
|
rolo_error("Checksum Error");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-09-09 12:59:06 +00:00
|
|
|
lcd_puts(0, 1, "Executing ");
|
2002-09-03 09:44:08 +00:00
|
|
|
lcd_update();
|
|
|
|
|
2005-03-31 08:47:02 +00:00
|
|
|
set_irq_level(HIGHEST_IRQ_LEVEL);
|
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
/* Calling these 2 initialization routines was necessary to get the
|
|
|
|
the origional Archos version of the firmware to load and execute. */
|
|
|
|
system_init(); /* Initialize system for restart */
|
|
|
|
i2c_init(); /* Init i2c bus - it seems like a good idea */
|
|
|
|
ICR = IRQ0_EDGE_TRIGGER; /* Make IRQ0 edge triggered */
|
2005-02-02 21:47:08 +00:00
|
|
|
TSTR = 0xE0; /* disable all timers */
|
2004-10-14 23:40:58 +00:00
|
|
|
/* model-specific de-init, needed when flashed */
|
|
|
|
/* Especially the Archos software is picky about this */
|
2005-02-02 21:47:08 +00:00
|
|
|
#if defined(ARCHOS_RECORDER) || defined(ARCHOS_RECORDERV2) || \
|
|
|
|
defined(ARCHOS_FMRECORDER)
|
|
|
|
PAIOR = 0x0FA0;
|
2003-10-12 16:40:45 +00:00
|
|
|
#endif
|
2005-03-31 08:47:02 +00:00
|
|
|
#endif
|
2005-04-05 11:33:58 +00:00
|
|
|
rolo_restart(audiobuf, ramstart, length);
|
2002-09-03 09:44:08 +00:00
|
|
|
|
|
|
|
return 0; /* this is never reached */
|
|
|
|
}
|
2006-11-10 20:26:01 +00:00
|
|
|
#else /* !defined(IRIVER_IFP7XX_SERIES) */
|
2005-02-02 21:47:08 +00:00
|
|
|
int rolo_load(const char* filename)
|
|
|
|
{
|
|
|
|
/* dummy */
|
2005-02-03 10:07:11 +00:00
|
|
|
(void)filename;
|
|
|
|
return 0;
|
2005-02-02 21:47:08 +00:00
|
|
|
}
|
|
|
|
|
2006-11-10 20:26:01 +00:00
|
|
|
#endif /* !defined(IRIVER_IFP7XX_SERIES) */
|