1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Randy D. Wood
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
31 #define IRQ0_EDGE_TRIGGER 0x80
33 static void rolo_error(const char *text
)
36 lcd_puts(0, 0, "ROLO error:");
37 lcd_puts_scroll(0, 1, text
);
45 /* these are in assembler file "descramble.S" */
46 extern unsigned short descramble(const unsigned char* source
,
47 unsigned char* dest
, int length
);
48 extern void rolo_restart(const unsigned char* source
, unsigned char* dest
,
51 /***************************************************************************
53 * Name: rolo_load_app(char *filename,int scrambled)
54 * Filename must be a fully defined filename including the path and extension
56 ***************************************************************************/
57 int rolo_load(const char* filename
)
61 unsigned long file_length
;
62 unsigned short checksum
,file_checksum
;
63 unsigned char* ramstart
= (void*)0x09000000;
66 lcd_puts(0, 0, "ROLO...");
67 lcd_puts(0, 1, "Loading");
72 fd
= open(filename
, O_RDONLY
);
74 rolo_error("File not found");
78 /* Read file length from header and compare to real file length */
79 length
=lseek(fd
,0,SEEK_END
)-FIRMWARE_OFFSET_FILE_DATA
;
80 lseek(fd
, FIRMWARE_OFFSET_FILE_LENGTH
, SEEK_SET
);
81 if(read(fd
, &file_length
, 4) != 4) {
82 rolo_error("Error Reading File Length");
85 if (length
!= file_length
) {
86 rolo_error("File length mismatch");
90 /* Read and save checksum */
91 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
92 if (read(fd
, &file_checksum
, 2) != 2) {
93 rolo_error("Error Reading checksum");
96 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
98 /* verify that file can be read and descrambled */
99 if ((mp3buf
+ (2*length
)+4) >= mp3end
) {
100 rolo_error("Not enough room to load file");
104 if (read(fd
, &mp3buf
[length
], length
) != (int)length
) {
105 rolo_error("Error Reading File");
109 lcd_puts(0, 1, "Descramble");
112 checksum
= descramble(mp3buf
+ length
, mp3buf
, length
);
114 /* Verify checksum against file header */
116 if (checksum
!= file_checksum
) {
117 rolo_error("Checksum Error");
121 lcd_puts(0, 1, "Executing ");
124 /* Disable interrupts */
125 asm("mov #15<<4,r6\n"
128 /* Calling these 2 initialization routines was necessary to get the
129 the origional Archos version of the firmware to load and execute. */
130 system_init(); /* Initialize system for restart */
131 i2c_init(); /* Init i2c bus - it seems like a good idea */
132 ICR
= IRQ0_EDGE_TRIGGER
; /* Make IRQ0 edge triggered */
133 TSTR
= 0xE0; /* disable all timers */
134 /* model-specific de-init, needed when flashed */
135 /* Especially the Archos software is picky about this */
136 #if defined(ARCHOS_RECORDER) || defined(ARCHOS_RECORDERV2) || defined(ARCHOS_FMRECORDER)
140 rolo_restart(mp3buf
, ramstart
, length
);
142 return 0; /* this is never reached */