summaryrefslogtreecommitdiff
path: root/firmware/rolo.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/rolo.c')
-rw-r--r--firmware/rolo.c91
1 files changed, 75 insertions, 16 deletions
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 @@
29#include "string.h" 29#include "string.h"
30#include "buffer.h" 30#include "buffer.h"
31 31
32#if (CONFIG_CPU != MCF5249) && (CONFIG_CPU != TCC730) 32#if CONFIG_CPU != TCC730
33/* FIX: this doesn't work on iRiver or Gmini yet */ 33/* FIX: this doesn't work on Gmini yet */
34 34
35#define IRQ0_EDGE_TRIGGER 0x80 35#define IRQ0_EDGE_TRIGGER 0x80
36 36
@@ -46,11 +46,36 @@ static void rolo_error(const char *text)
46 lcd_stop_scroll(); 46 lcd_stop_scroll();
47} 47}
48 48
49#if CONFIG_CPU == SH7034
49/* these are in assembler file "descramble.S" */ 50/* these are in assembler file "descramble.S" */
50extern unsigned short descramble(const unsigned char* source, 51extern unsigned short descramble(const unsigned char* source,
51 unsigned char* dest, int length); 52 unsigned char* dest, int length);
52extern void rolo_restart(const unsigned char* source, unsigned char* dest, 53extern void rolo_restart(const unsigned char* source, unsigned char* dest,
53 int length); 54 int length);
55#else
56void rolo_restart(const unsigned char* source, unsigned char* dest,
57 long length) __attribute__ ((section (".icode")));
58void rolo_restart(const unsigned char* source, unsigned char* dest,
59 long length)
60{
61 long i;
62
63 for(i = 0;i < length;i++)
64 *dest++ = *source++;
65
66#if CONFIG_CPU == MCF5249
67 asm volatile (" move.l #0,%d0");
68 asm volatile (" move.l #0x30000000,%d0");
69 asm volatile (" movec.l %d0,%vbr");
70 asm volatile (" move.l 0x30000000,%sp");
71 asm volatile (" move.l 0x30000004,%a0");
72 asm volatile (" jmp (%a0)");
73#endif
74}
75#endif
76
77/* This is assigned in the linker control file */
78extern unsigned long loadaddress;
54 79
55/*************************************************************************** 80/***************************************************************************
56 * 81 *
@@ -61,10 +86,15 @@ extern void rolo_restart(const unsigned char* source, unsigned char* dest,
61int rolo_load(const char* filename) 86int rolo_load(const char* filename)
62{ 87{
63 int fd; 88 int fd;
64 unsigned long length; 89 long length;
65 unsigned long file_length; 90#ifdef IRIVER_H100
91 int i;
92 unsigned long checksum,file_checksum;
93#else
94 long file_length;
66 unsigned short checksum,file_checksum; 95 unsigned short checksum,file_checksum;
67 unsigned char* ramstart = (void*)0x09000000; 96#endif
97 unsigned char* ramstart = (void*)&loadaddress;
68 98
69 lcd_clear_display(); 99 lcd_clear_display();
70 lcd_puts(0, 0, "ROLO..."); 100 lcd_puts(0, 0, "ROLO...");
@@ -79,8 +109,40 @@ int rolo_load(const char* filename)
79 return -1; 109 return -1;
80 } 110 }
81 111
112 length = filesize(fd) - FIRMWARE_OFFSET_FILE_DATA;
113
114#if CONFIG_CPU == MCF5249
115 /* Read and save checksum */
116 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
117 if (read(fd, &file_checksum, 4) != 4) {
118 rolo_error("Error Reading checksum");
119 return -1;
120 }
121 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
122
123 if (read(fd, mp3buf, length) != length) {
124 rolo_error("Error Reading File");
125 return -1;
126 }
127
128 checksum = 0;
129
130 for(i = 0;i < length;i++) {
131 checksum += mp3buf[i];
132 }
133
134 /* Verify checksum against file header */
135 if (checksum != file_checksum) {
136 rolo_error("Checksum Error");
137 return -1;
138 }
139
140 lcd_puts(0, 1, "Executing ");
141 lcd_update();
142
143 set_irq_level(HIGHEST_IRQ_LEVEL);
144#else
82 /* Read file length from header and compare to real file length */ 145 /* Read file length from header and compare to real file length */
83 length=lseek(fd,0,SEEK_END)-FIRMWARE_OFFSET_FILE_DATA;
84 lseek(fd, FIRMWARE_OFFSET_FILE_LENGTH, SEEK_SET); 146 lseek(fd, FIRMWARE_OFFSET_FILE_LENGTH, SEEK_SET);
85 if(read(fd, &file_length, 4) != 4) { 147 if(read(fd, &file_length, 4) != 4) {
86 rolo_error("Error Reading File Length"); 148 rolo_error("Error Reading File Length");
@@ -90,7 +152,7 @@ int rolo_load(const char* filename)
90 rolo_error("File length mismatch"); 152 rolo_error("File length mismatch");
91 return -1; 153 return -1;
92 } 154 }
93 155
94 /* Read and save checksum */ 156 /* Read and save checksum */
95 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); 157 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
96 if (read(fd, &file_checksum, 2) != 2) { 158 if (read(fd, &file_checksum, 2) != 2) {
@@ -114,9 +176,8 @@ int rolo_load(const char* filename)
114 lcd_update(); 176 lcd_update();
115 177
116 checksum = descramble(mp3buf + length, mp3buf, length); 178 checksum = descramble(mp3buf + length, mp3buf, length);
117 179
118 /* Verify checksum against file header */ 180 /* Verify checksum against file header */
119
120 if (checksum != file_checksum) { 181 if (checksum != file_checksum) {
121 rolo_error("Checksum Error"); 182 rolo_error("Checksum Error");
122 return -1; 183 return -1;
@@ -125,10 +186,8 @@ int rolo_load(const char* filename)
125 lcd_puts(0, 1, "Executing "); 186 lcd_puts(0, 1, "Executing ");
126 lcd_update(); 187 lcd_update();
127 188
128 /* Disable interrupts */ 189 set_irq_level(HIGHEST_IRQ_LEVEL);
129 asm("mov #15<<4,r6\n" 190
130 "ldc r6,sr");
131
132 /* Calling these 2 initialization routines was necessary to get the 191 /* Calling these 2 initialization routines was necessary to get the
133 the origional Archos version of the firmware to load and execute. */ 192 the origional Archos version of the firmware to load and execute. */
134 system_init(); /* Initialize system for restart */ 193 system_init(); /* Initialize system for restart */
@@ -141,12 +200,12 @@ int rolo_load(const char* filename)
141 defined(ARCHOS_FMRECORDER) 200 defined(ARCHOS_FMRECORDER)
142 PAIOR = 0x0FA0; 201 PAIOR = 0x0FA0;
143#endif 202#endif
144 203#endif
145 rolo_restart(mp3buf, ramstart, length); 204 rolo_restart(mp3buf, ramstart, length);
146 205
147 return 0; /* this is never reached */ 206 return 0; /* this is never reached */
148} 207}
149#else /* (CONFIG_CPU != MCF5249) && (CONFIG_CPU != TCC730) */ 208#else /* CONFIG_CPU != TCC730 */
150int rolo_load(const char* filename) 209int rolo_load(const char* filename)
151{ 210{
152 /* dummy */ 211 /* dummy */
@@ -154,4 +213,4 @@ int rolo_load(const char* filename)
154 return 0; 213 return 0;
155} 214}
156 215
157#endif /* ! (CONFIG_CPU != MCF5249) && (CONFIG_CPU != TCC730) */ 216#endif /* ! CONFIG_CPU != TCC730 */