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 ****************************************************************************/
22 #include "lcd-remote.h"
34 #include "crc32-mi4.h"
35 #undef FIRMWARE_OFFSET_FILE_CRC
36 #undef FIRMWARE_OFFSET_FILE_DATA
37 #define FIRMWARE_OFFSET_FILE_CRC 0xC
38 #define FIRMWARE_OFFSET_FILE_DATA 0x200
41 #if !defined(IRIVER_IFP7XX_SERIES) && \
42 (CONFIG_CPU != PP5002) && (CONFIG_CPU != S3C2440)
43 /* FIX: this doesn't work on iFP, 3rd Gen ipods */
45 #define IRQ0_EDGE_TRIGGER 0x80
48 /* Handle the COP properly - it needs to jump to a function outside SDRAM while
49 * the new firmware is being loaded, and then jump to the start of SDRAM
50 * TODO: Use the mailboxes built into the PP processor for this
53 volatile unsigned char IDATA_ATTR cpu_message
= 0;
54 volatile unsigned char IDATA_ATTR cpu_reply
= 0;
56 void rolo_restart_cop(void) ICODE_ATTR
;
57 void rolo_restart_cop(void)
59 /* Invalidate cache */
63 CACHE_CTL
= CACHE_DISABLE
;
65 /* Tell the main core that we're ready to reload */
68 /* Wait while RoLo loads the image into SDRAM */
69 /* TODO: Accept checksum failure gracefully */
70 while(cpu_message
== 1) {}
72 /* Acknowledge the CPU and then reload */
76 "mov r0, #0x10000000 \n"
82 static void rolo_error(const char *text
)
85 lcd_puts(0, 0, "ROLO error:");
86 lcd_puts_scroll(0, 1, text
);
94 #if CONFIG_CPU == SH7034
95 /* these are in assembler file "descramble.S" */
96 extern unsigned short descramble(const unsigned char* source
,
97 unsigned char* dest
, int length
);
98 extern void rolo_restart(const unsigned char* source
, unsigned char* dest
,
101 void rolo_restart(const unsigned char* source
, unsigned char* dest
,
102 long length
) __attribute__ ((section (".icode")));
103 void rolo_restart(const unsigned char* source
, unsigned char* dest
,
107 unsigned char* localdest
= dest
;
108 #if (CONFIG_CPU==PP5020) || (CONFIG_CPU==PP5024)
109 unsigned long* memmapregs
= (unsigned long*)0xf000f000;
112 for(i
= 0;i
< length
;i
++)
113 *localdest
++ = *source
++;
115 #if defined(CPU_COLDFIRE)
117 "movec.l %0,%%vbr \n"
118 "move.l (%0)+,%%sp \n"
123 #elif (CONFIG_CPU==PP5020) || (CONFIG_CPU==PP5024)
125 /* Tell the COP that we've finished loading and started rebooting */
132 CACHE_CTL
= CACHE_DISABLE
;
134 /* Reset the memory mapping registers to zero */
138 /* Wait for the COP to tell us it is rebooting */
139 while(cpu_reply
!= 1) {}
142 "mov r0, #0x10000000 \n"
149 /* This is assigned in the linker control file */
150 extern unsigned long loadaddress
;
152 /***************************************************************************
154 * Name: rolo_load_app(char *filename,int scrambled)
155 * Filename must be a fully defined filename including the path and extension
157 ***************************************************************************/
158 int rolo_load(const char* filename
)
162 #if defined(CPU_COLDFIRE) || defined(CPU_PP)
163 #if !defined(MI4_FORMAT)
166 unsigned long checksum
,file_checksum
;
169 unsigned short checksum
,file_checksum
;
171 unsigned char* ramstart
= (void*)&loadaddress
;
174 lcd_puts(0, 0, "ROLO...");
175 lcd_puts(0, 1, "Loading");
177 #ifdef HAVE_REMOTE_LCD
178 lcd_remote_clear_display();
179 lcd_remote_puts(0, 0, "ROLO...");
180 lcd_remote_puts(0, 1, "Loading");
186 fd
= open(filename
, O_RDONLY
);
188 rolo_error("File not found");
192 length
= filesize(fd
) - FIRMWARE_OFFSET_FILE_DATA
;
194 #if defined(CPU_COLDFIRE) || defined(CPU_PP)
195 /* Read and save checksum */
196 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
197 if (read(fd
, &file_checksum
, 4) != 4) {
198 rolo_error("Error Reading checksum");
202 #if !defined(MI4_FORMAT)
203 /* Rockbox checksums are big-endian */
204 file_checksum
= betoh32(file_checksum
);
208 cpu_message
= COP_REBOOT
;
210 lcd_puts(0, 2, "Waiting for coprocessor...");
212 while(cpu_reply
!= 2) {}
217 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
219 if (read(fd
, audiobuf
, length
) != length
) {
220 rolo_error("Error Reading File");
225 /* Check CRC32 to see if we have a valid file */
226 chksum_crc32gentab();
227 checksum
= chksum_crc32 (audiobuf
, length
);
229 checksum
= MODEL_NUMBER
;
231 for(i
= 0;i
< length
;i
++) {
232 checksum
+= audiobuf
[i
];
236 /* Verify checksum against file header */
237 if (checksum
!= file_checksum
) {
238 rolo_error("Checksum Error");
242 lcd_puts(0, 1, "Executing");
244 #ifdef HAVE_REMOTE_LCD
245 lcd_remote_puts(0, 1, "Executing");
249 set_irq_level(HIGHEST_IRQ_LEVEL
);
250 #elif CONFIG_CPU == SH7034
251 /* Read file length from header and compare to real file length */
252 lseek(fd
, FIRMWARE_OFFSET_FILE_LENGTH
, SEEK_SET
);
253 if(read(fd
, &file_length
, 4) != 4) {
254 rolo_error("Error Reading File Length");
257 if (length
!= file_length
) {
258 rolo_error("File length mismatch");
262 /* Read and save checksum */
263 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
264 if (read(fd
, &file_checksum
, 2) != 2) {
265 rolo_error("Error Reading checksum");
268 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
270 /* verify that file can be read and descrambled */
271 if ((audiobuf
+ (2*length
)+4) >= audiobufend
) {
272 rolo_error("Not enough room to load file");
276 if (read(fd
, &audiobuf
[length
], length
) != (int)length
) {
277 rolo_error("Error Reading File");
281 lcd_puts(0, 1, "Descramble");
284 checksum
= descramble(audiobuf
+ length
, audiobuf
, length
);
286 /* Verify checksum against file header */
287 if (checksum
!= file_checksum
) {
288 rolo_error("Checksum Error");
292 lcd_puts(0, 1, "Executing ");
295 set_irq_level(HIGHEST_IRQ_LEVEL
);
297 /* Calling these 2 initialization routines was necessary to get the
298 the origional Archos version of the firmware to load and execute. */
299 system_init(); /* Initialize system for restart */
300 i2c_init(); /* Init i2c bus - it seems like a good idea */
301 ICR
= IRQ0_EDGE_TRIGGER
; /* Make IRQ0 edge triggered */
302 TSTR
= 0xE0; /* disable all timers */
303 /* model-specific de-init, needed when flashed */
304 /* Especially the Archos software is picky about this */
305 #if defined(ARCHOS_RECORDER) || defined(ARCHOS_RECORDERV2) || \
306 defined(ARCHOS_FMRECORDER)
310 rolo_restart(audiobuf
, ramstart
, length
);
312 return 0; /* this is never reached */
314 #else /* !defined(IRIVER_IFP7XX_SERIES) */
315 int rolo_load(const char* filename
)
322 #endif /* !defined(IRIVER_IFP7XX_SERIES) */