From c521ed128d1afeea9bfad134358f6c3a7df9f2c0 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Tue, 3 Sep 2002 09:44:08 +0000 Subject: Added Randy Wood's ROLO git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2149 a1c6a512-1295-4272-9138-f99709370657 --- firmware/app.lds | 12 ++++- firmware/crt0.S | 20 ++++++++ firmware/gdb.lds | 12 ++++- firmware/player.lds | 12 ++++- firmware/rolo.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++ firmware/rolo.h | 24 +++++++++ 6 files changed, 217 insertions(+), 6 deletions(-) create mode 100644 firmware/rolo.c create mode 100644 firmware/rolo.h (limited to 'firmware') diff --git a/firmware/app.lds b/firmware/app.lds index 2e594b6db1..49678d887e 100644 --- a/firmware/app.lds +++ b/firmware/app.lds @@ -39,7 +39,9 @@ SECTIONS _stackbegin = .; /* We put the copy of the .iram section here to save space */ _iramcopy = .; - . = 0x2000; + . += 0x2000; + _topramcopy = .; + . += 0x300; _stackend = .; } > DRAM @@ -56,11 +58,17 @@ SECTIONS _mp3buf = .; } > DRAM - .mp3end 0x09200000 : + .mp3end 0x09200000 - 0x300: { _mp3end = .; } > DRAM + .topram : AT ( _topramcopy ) { + _topramstart = .; + *(.topcode) + _topramend = .; + } > DRAM + .iram 0xf000000 : AT ( _iramcopy ) { _iramstart = .; diff --git a/firmware/crt0.S b/firmware/crt0.S index 99aab83867..0343fd1e23 100644 --- a/firmware/crt0.S +++ b/firmware/crt0.S @@ -112,6 +112,20 @@ copy_l: bf copy_l nop + /* copy the .topram section */ + mov.l topramcopy_k,r0 + mov.l topram_k,r1 + mov.l topramend_k,r2 +copy_l2: + mov.l @r0,r3 + mov.l r3,@r1 + add #4,r0 + add #4,r1 + cmp/ge r2,r1 + bf copy_l2 + nop + + /* Munge the main thread stack */ mov.l stack_k,r2 mov.l deadbeef_k,r0 @@ -150,6 +164,12 @@ iram_k: .long _iramstart iramend_k: .long _iramend +topramcopy_k: + .long _topramcopy +topram_k: + .long _topramstart +topramend_k: + .long _topramend main_k: .long _main vbr_k: diff --git a/firmware/gdb.lds b/firmware/gdb.lds index badb7856fc..c214cb2e69 100644 --- a/firmware/gdb.lds +++ b/firmware/gdb.lds @@ -39,7 +39,9 @@ SECTIONS _stackbegin = .; /* We put the copy of the .iram section here to save space */ _iramcopy = .; - . = 0x2000; + . += 0x2000; + _topramcopy = .; + . += 0x300; _stackend = .; } > DRAM @@ -63,11 +65,17 @@ SECTIONS _mp3buf = .; } > DRAM - .mp3end 0x09200000 : + .mp3end 0x09200000 - 0x300: { _mp3end = .; } > DRAM + .topram : AT ( _topramcopy ) { + _topramstart = .; + *(.topcode) + _topramend = .; + } > DRAM + .iram 0xf000000 : AT ( _iramcopy ) { _iramstart = .; diff --git a/firmware/player.lds b/firmware/player.lds index 2e594b6db1..49678d887e 100644 --- a/firmware/player.lds +++ b/firmware/player.lds @@ -39,7 +39,9 @@ SECTIONS _stackbegin = .; /* We put the copy of the .iram section here to save space */ _iramcopy = .; - . = 0x2000; + . += 0x2000; + _topramcopy = .; + . += 0x300; _stackend = .; } > DRAM @@ -56,11 +58,17 @@ SECTIONS _mp3buf = .; } > DRAM - .mp3end 0x09200000 : + .mp3end 0x09200000 - 0x300: { _mp3end = .; } > DRAM + .topram : AT ( _topramcopy ) { + _topramstart = .; + *(.topcode) + _topramend = .; + } > DRAM + .iram 0xf000000 : AT ( _iramcopy ) { _iramstart = .; diff --git a/firmware/rolo.c b/firmware/rolo.c new file mode 100644 index 0000000000..ed9fcff931 --- /dev/null +++ b/firmware/rolo.c @@ -0,0 +1,143 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ + +#include "lcd.h" +#include "kernel.h" +#include "sprintf.h" +#include "button.h" +#include "file.h" +#include "mpeg.h" +#include "system.h" +#include "i2c.h" +#include "string.h" + +#define IRQ0_EDGE_TRIGGER 0x80 + +static void rolo_error(char *text) +{ + lcd_clear_display(); + lcd_puts(0, 0, "ROLO error:"); + lcd_puts_scroll(0, 1, text); + lcd_update(); + button_get(true); + lcd_stop_scroll(); +} +/*************************************************************************** + * + * Name: rolo_load_app(char *filename,int scrambled) + * Filename must be a fully defined filename including the path and extension + * + ***************************************************************************/ +int rolo_load(char* filename) __attribute__ ((section (".topcode"))); +int rolo_load(char* filename) +{ + int fd,slen; + unsigned long length,file_length,i; + extern unsigned char mp3buf[],mp3end; + unsigned short checksum,file_checksum; + unsigned char* ramstart = (void*)0x09000000; + void (*start_func)(void) = (void*)ramstart + 0x200; + + lcd_clear_display(); + lcd_puts(0, 0, "ROLO..."); + lcd_puts(0, 1, "Loading"); + lcd_update(); + + mpeg_stop(); + + fd = open(filename, O_RDONLY); + if(-1 == fd) { + rolo_error("File not found"); + return -1; + } + + /* Read file length from header and compare to real file length */ + length=lseek(fd,0,SEEK_END)-6; + lseek(fd, 0, SEEK_SET); + 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; + } + + /* Read and save checksum */ + lseek(fd, 4, SEEK_SET); + if (read(fd, &file_checksum, 2) != 2) { + rolo_error("Error Reading checksum"); + return -1; + } + lseek(fd, 6, SEEK_SET); + + /* verify that file can be read and descrambled */ + if ((&mp3buf[0] + (2*length)+4) >= &mp3end) { + rolo_error("Not enough room to load file"); + return -1; + } + + if (read(fd, &mp3buf[length], length) != (int)length) { + rolo_error("Error Reading File"); + return -1; + } + + lcd_puts(0, 1, "Descrambling"); + lcd_update(); + + /* descramble */ + slen = length/4; + for (i = 0; i < length; i++) { + unsigned long addr = ((i % slen) << 2) + i/slen; + unsigned char data = mp3buf[i+length]; + data = ~((data >> 1) | ((data << 7) & 0x80)); /* poor man's ROR */ + mp3buf[addr] = data; + } + + /* Compute checksum and verify against checksum from file header */ + checksum=0; + for (i=0; i ) \___| < | \_\ ( <_> > < < + * 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. + * + ****************************************************************************/ +#ifndef __ROLO_H__ +#define __ROLO_H__ + +void rolo_load(char* file); + +#endif -- cgit v1.2.3