summaryrefslogtreecommitdiff
path: root/firmware/rolo.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/rolo.c')
-rw-r--r--firmware/rolo.c138
1 files changed, 35 insertions, 103 deletions
diff --git a/firmware/rolo.c b/firmware/rolo.c
index 567c880bd4..325e17e97f 100644
--- a/firmware/rolo.c
+++ b/firmware/rolo.c
@@ -37,16 +37,17 @@
37#include "storage.h" 37#include "storage.h"
38#include "rolo.h" 38#include "rolo.h"
39 39
40#ifdef MI4_FORMAT 40#include "loader_strerror.h"
41#if defined(MI4_FORMAT)
41#include "crc32-mi4.h" 42#include "crc32-mi4.h"
42#undef FIRMWARE_OFFSET_FILE_CRC 43#include "mi4-loader.h"
43#undef FIRMWARE_OFFSET_FILE_DATA 44#define LOAD_FIRMWARE(a,b,c) load_mi4(a,b,c)
44#define FIRMWARE_OFFSET_FILE_CRC 0xC 45#elif defined(RKW_FORMAT)
45#define FIRMWARE_OFFSET_FILE_DATA 0x200
46#endif
47
48#ifdef RKW_FORMAT
49#include "rkw-loader.h" 46#include "rkw-loader.h"
47#define LOAD_FIRMWARE(a,b,c) load_rkw(a,b,c)
48#else
49#include "rb-loader.h"
50#define LOAD_FIRMWARE(a,b,c) load_firmware(a,b,c)
50#endif 51#endif
51 52
52#if !defined(IRIVER_IFP7XX_SERIES) 53#if !defined(IRIVER_IFP7XX_SERIES)
@@ -206,7 +207,7 @@ extern unsigned long loadaddress;
206 * Filename must be a fully defined filename including the path and extension 207 * Filename must be a fully defined filename including the path and extension
207 * 208 *
208 ***************************************************************************/ 209 ***************************************************************************/
209#ifdef RKW_FORMAT 210#if defined(CPU_COLDFIRE) || defined(CPU_ARM) || defined(CPU_MIPS)
210int rolo_load(const char* filename) 211int rolo_load(const char* filename)
211{ 212{
212 unsigned char* ramstart = (void*)&loadaddress; 213 unsigned char* ramstart = (void*)&loadaddress;
@@ -232,15 +233,26 @@ int rolo_load(const char* filename)
232 rolo_handle = core_alloc_maximum("rolo", &filebuf_size, NULL); 233 rolo_handle = core_alloc_maximum("rolo", &filebuf_size, NULL);
233 filebuf = core_get_data(rolo_handle); 234 filebuf = core_get_data(rolo_handle);
234 235
235 errno = load_rkw(filebuf, filename, filebuf_size); 236 errno = LOAD_FIRMWARE(filebuf, filename, filebuf_size);
236 if (errno < 0) 237
238 if (errno <= 0)
237 { 239 {
238 rolo_error(rkw_strerror(errno)); 240 rolo_error(loader_strerror(errno));
239 return -1; 241 return -1;
240 } 242 }
241 else 243 else
242 length = errno; 244 length = errno;
243 245
246#if defined(CPU_PP) && NUM_CORES > 1
247 lcd_puts(0, 2, "Waiting for coprocessor...");
248 lcd_update();
249 rolo_restart_cop();
250 /* Wait for COP to be in safe code */
251 while(cpu_reply != 1);
252 lcd_puts(0, 2, " ");
253 lcd_update();
254#endif
255
244#ifdef HAVE_STORAGE_FLUSH 256#ifdef HAVE_STORAGE_FLUSH
245 lcd_puts(0, 1, "Flushing storage buffers"); 257 lcd_puts(0, 1, "Flushing storage buffers");
246 lcd_update(); 258 lcd_update();
@@ -255,27 +267,29 @@ int rolo_load(const char* filename)
255#endif 267#endif
256 adc_close(); 268 adc_close();
257 269
270#if CONFIG_CPU != IMX31L /* We're not finished yet */
271#ifdef CPU_ARM
272 /* Should do these together since some ARM version should never have
273 * FIQ disabled and not IRQ (imx31 errata). */
258 disable_interrupt(IRQ_FIQ_STATUS); 274 disable_interrupt(IRQ_FIQ_STATUS);
275#else
276 /* Some targets have a higher disable level than HIGEST_IRQ_LEVEL */
277 set_irq_level(DISABLE_INTERRUPTS);
278#endif
279#endif /* CONFIG_CPU == IMX31L */
259 280
260 rolo_restart(filebuf, ramstart, length); 281 rolo_restart(filebuf, ramstart, length);
261 282
262 /* never reached */ 283 /* never reached */
263 return 0; 284 return 0;
264} 285}
265#else 286#else /* defined(CPU_SH) */
266int rolo_load(const char* filename) 287int rolo_load(const char* filename)
267{ 288{
268 int fd; 289 int fd;
269 long length; 290 long length;
270#if defined(CPU_COLDFIRE) || defined(CPU_ARM) || defined(CPU_MIPS)
271#if !defined(MI4_FORMAT)
272 int i;
273#endif
274 unsigned long checksum,file_checksum;
275#else
276 long file_length; 291 long file_length;
277 unsigned short checksum,file_checksum; 292 unsigned short checksum,file_checksum;
278#endif
279 unsigned char* ramstart = (void*)&loadaddress; 293 unsigned char* ramstart = (void*)&loadaddress;
280 unsigned char* filebuf; 294 unsigned char* filebuf;
281 size_t filebuf_size; 295 size_t filebuf_size;
@@ -306,87 +320,6 @@ int rolo_load(const char* filename)
306 rolo_handle = core_alloc_maximum("rolo", &filebuf_size, NULL); 320 rolo_handle = core_alloc_maximum("rolo", &filebuf_size, NULL);
307 filebuf = core_get_data(rolo_handle); 321 filebuf = core_get_data(rolo_handle);
308 322
309#if CONFIG_CPU != SH7034
310 /* Read and save checksum */
311 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
312 if (read(fd, &file_checksum, 4) != 4) {
313 rolo_error("Error Reading checksum");
314 return -1;
315 }
316
317#if !defined(MI4_FORMAT)
318 /* Rockbox checksums are big-endian */
319 file_checksum = betoh32(file_checksum);
320#endif
321
322#if defined(CPU_PP) && NUM_CORES > 1
323 lcd_puts(0, 2, "Waiting for coprocessor...");
324 lcd_update();
325 rolo_restart_cop();
326 /* Wait for COP to be in safe code */
327 while(cpu_reply != 1);
328 lcd_puts(0, 2, " ");
329 lcd_update();
330#endif
331
332 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
333
334 /* this shouldn't happen, but well */
335 if ((long)filebuf_size < length)
336 {
337 rolo_error("File too big");
338 return -1;
339 }
340
341 if (read(fd, filebuf, length) != length) {
342 rolo_error("Error Reading File");
343 return -1;
344 }
345
346#ifdef MI4_FORMAT
347 /* Check CRC32 to see if we have a valid file */
348 chksum_crc32gentab();
349 checksum = chksum_crc32 (filebuf, length);
350#else
351 checksum = MODEL_NUMBER;
352
353 for(i = 0;i < length;i++) {
354 checksum += filebuf[i];
355 }
356#endif
357
358 /* Verify checksum against file header */
359 if (checksum != file_checksum) {
360 rolo_error("Checksum Error");
361 return -1;
362 }
363
364#ifdef HAVE_STORAGE_FLUSH
365 lcd_puts(0, 1, "Flushing storage buffers");
366 lcd_update();
367 storage_flush();
368#endif
369
370 lcd_puts(0, 1, "Executing");
371 lcd_update();
372#ifdef HAVE_REMOTE_LCD
373 lcd_remote_puts(0, 1, "Executing");
374 lcd_remote_update();
375#endif
376 adc_close();
377
378#if CONFIG_CPU != IMX31L /* We're not finished yet */
379#ifdef CPU_ARM
380 /* Should do these together since some ARM version should never have
381 * FIQ disabled and not IRQ (imx31 errata). */
382 disable_interrupt(IRQ_FIQ_STATUS);
383#else
384 /* Some targets have a higher disable level than HIGEST_IRQ_LEVEL */
385 set_irq_level(DISABLE_INTERRUPTS);
386#endif
387#endif /* CONFIG_CPU == IMX31L */
388
389#else /* CONFIG_CPU == SH7034 */
390 /* Read file length from header and compare to real file length */ 323 /* Read file length from header and compare to real file length */
391 lseek(fd, FIRMWARE_OFFSET_FILE_LENGTH, SEEK_SET); 324 lseek(fd, FIRMWARE_OFFSET_FILE_LENGTH, SEEK_SET);
392 if(read(fd, &file_length, 4) != 4) { 325 if(read(fd, &file_length, 4) != 4) {
@@ -451,13 +384,12 @@ int rolo_load(const char* filename)
451 defined(ARCHOS_FMRECORDER) 384 defined(ARCHOS_FMRECORDER)
452 PAIOR = 0x0FA0; 385 PAIOR = 0x0FA0;
453#endif 386#endif
454#endif
455 rolo_restart(filebuf, ramstart, length); 387 rolo_restart(filebuf, ramstart, length);
456 388
457 return 0; /* this is never reached */ 389 return 0; /* this is never reached */
458 (void)checksum; (void)file_checksum; 390 (void)checksum; (void)file_checksum;
459} 391}
460#endif /* ifdef RKW_FORMAT */ 392#endif /* */
461#else /* !defined(IRIVER_IFP7XX_SERIES) */ 393#else /* !defined(IRIVER_IFP7XX_SERIES) */
462int rolo_load(const char* filename) 394int rolo_load(const char* filename)
463{ 395{