From bd42d31e5eb1eed61da6c25064de1eed23c7163e Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 31 Mar 2005 08:47:02 +0000 Subject: RoLo now works on the iRiver git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6238 a1c6a512-1295-4272-9138-f99709370657 --- firmware/rolo.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 16 deletions(-) (limited to 'firmware/rolo.c') diff --git a/firmware/rolo.c b/firmware/rolo.c index fccc9f38da..ceb70791cf 100644 --- a/firmware/rolo.c +++ b/firmware/rolo.c @@ -29,8 +29,8 @@ #include "string.h" #include "buffer.h" -#if (CONFIG_CPU != MCF5249) && (CONFIG_CPU != TCC730) -/* FIX: this doesn't work on iRiver or Gmini yet */ +#if CONFIG_CPU != TCC730 +/* FIX: this doesn't work on Gmini yet */ #define IRQ0_EDGE_TRIGGER 0x80 @@ -46,11 +46,36 @@ static void rolo_error(const char *text) lcd_stop_scroll(); } +#if CONFIG_CPU == SH7034 /* these are in assembler file "descramble.S" */ 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); +#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; + + for(i = 0;i < length;i++) + *dest++ = *source++; + +#if CONFIG_CPU == MCF5249 + asm volatile (" move.l #0,%d0"); + asm volatile (" move.l #0x30000000,%d0"); + asm volatile (" movec.l %d0,%vbr"); + asm volatile (" move.l 0x30000000,%sp"); + asm volatile (" move.l 0x30000004,%a0"); + asm volatile (" jmp (%a0)"); +#endif +} +#endif + +/* This is assigned in the linker control file */ +extern unsigned long loadaddress; /*************************************************************************** * @@ -61,10 +86,15 @@ extern void rolo_restart(const unsigned char* source, unsigned char* dest, int rolo_load(const char* filename) { int fd; - unsigned long length; - unsigned long file_length; + long length; +#ifdef IRIVER_H100 + int i; + unsigned long checksum,file_checksum; +#else + long file_length; unsigned short checksum,file_checksum; - unsigned char* ramstart = (void*)0x09000000; +#endif + unsigned char* ramstart = (void*)&loadaddress; lcd_clear_display(); lcd_puts(0, 0, "ROLO..."); @@ -79,8 +109,40 @@ int rolo_load(const char* filename) return -1; } + length = filesize(fd) - FIRMWARE_OFFSET_FILE_DATA; + +#if CONFIG_CPU == MCF5249 + /* 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; + } + lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); + + if (read(fd, mp3buf, length) != length) { + rolo_error("Error Reading File"); + return -1; + } + + checksum = 0; + + for(i = 0;i < length;i++) { + checksum += mp3buf[i]; + } + + /* Verify checksum against file header */ + if (checksum != file_checksum) { + rolo_error("Checksum Error"); + return -1; + } + + lcd_puts(0, 1, "Executing "); + lcd_update(); + + set_irq_level(HIGHEST_IRQ_LEVEL); +#else /* Read file length from header and compare to real file length */ - length=lseek(fd,0,SEEK_END)-FIRMWARE_OFFSET_FILE_DATA; lseek(fd, FIRMWARE_OFFSET_FILE_LENGTH, SEEK_SET); if(read(fd, &file_length, 4) != 4) { rolo_error("Error Reading File Length"); @@ -90,7 +152,7 @@ int rolo_load(const char* filename) rolo_error("File length mismatch"); return -1; } - + /* Read and save checksum */ lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); if (read(fd, &file_checksum, 2) != 2) { @@ -114,9 +176,8 @@ int rolo_load(const char* filename) lcd_update(); checksum = descramble(mp3buf + length, mp3buf, length); - + /* Verify checksum against file header */ - if (checksum != file_checksum) { rolo_error("Checksum Error"); return -1; @@ -125,10 +186,8 @@ int rolo_load(const char* filename) lcd_puts(0, 1, "Executing "); lcd_update(); - /* Disable interrupts */ - asm("mov #15<<4,r6\n" - "ldc r6,sr"); - + set_irq_level(HIGHEST_IRQ_LEVEL); + /* 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 */ @@ -141,12 +200,12 @@ int rolo_load(const char* filename) defined(ARCHOS_FMRECORDER) PAIOR = 0x0FA0; #endif - +#endif rolo_restart(mp3buf, ramstart, length); return 0; /* this is never reached */ } -#else /* (CONFIG_CPU != MCF5249) && (CONFIG_CPU != TCC730) */ +#else /* CONFIG_CPU != TCC730 */ int rolo_load(const char* filename) { /* dummy */ @@ -154,4 +213,4 @@ int rolo_load(const char* filename) return 0; } -#endif /* ! (CONFIG_CPU != MCF5249) && (CONFIG_CPU != TCC730) */ +#endif /* ! CONFIG_CPU != TCC730 */ -- cgit v1.2.3