diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-09-03 09:44:08 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-09-03 09:44:08 +0000 |
commit | c521ed128d1afeea9bfad134358f6c3a7df9f2c0 (patch) | |
tree | 0ea712643dabad159946129606393858626f53cc /firmware/rolo.c | |
parent | 3d641c92a5886554b181cec78b8d83f870154d6d (diff) | |
download | rockbox-c521ed128d1afeea9bfad134358f6c3a7df9f2c0.tar.gz rockbox-c521ed128d1afeea9bfad134358f6c3a7df9f2c0.zip |
Added Randy Wood's ROLO
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2149 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/rolo.c')
-rw-r--r-- | firmware/rolo.c | 143 |
1 files changed, 143 insertions, 0 deletions
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Randy D. Wood | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "lcd.h" | ||
21 | #include "kernel.h" | ||
22 | #include "sprintf.h" | ||
23 | #include "button.h" | ||
24 | #include "file.h" | ||
25 | #include "mpeg.h" | ||
26 | #include "system.h" | ||
27 | #include "i2c.h" | ||
28 | #include "string.h" | ||
29 | |||
30 | #define IRQ0_EDGE_TRIGGER 0x80 | ||
31 | |||
32 | static void rolo_error(char *text) | ||
33 | { | ||
34 | lcd_clear_display(); | ||
35 | lcd_puts(0, 0, "ROLO error:"); | ||
36 | lcd_puts_scroll(0, 1, text); | ||
37 | lcd_update(); | ||
38 | button_get(true); | ||
39 | lcd_stop_scroll(); | ||
40 | } | ||
41 | /*************************************************************************** | ||
42 | * | ||
43 | * Name: rolo_load_app(char *filename,int scrambled) | ||
44 | * Filename must be a fully defined filename including the path and extension | ||
45 | * | ||
46 | ***************************************************************************/ | ||
47 | int rolo_load(char* filename) __attribute__ ((section (".topcode"))); | ||
48 | int rolo_load(char* filename) | ||
49 | { | ||
50 | int fd,slen; | ||
51 | unsigned long length,file_length,i; | ||
52 | extern unsigned char mp3buf[],mp3end; | ||
53 | unsigned short checksum,file_checksum; | ||
54 | unsigned char* ramstart = (void*)0x09000000; | ||
55 | void (*start_func)(void) = (void*)ramstart + 0x200; | ||
56 | |||
57 | lcd_clear_display(); | ||
58 | lcd_puts(0, 0, "ROLO..."); | ||
59 | lcd_puts(0, 1, "Loading"); | ||
60 | lcd_update(); | ||
61 | |||
62 | mpeg_stop(); | ||
63 | |||
64 | fd = open(filename, O_RDONLY); | ||
65 | if(-1 == fd) { | ||
66 | rolo_error("File not found"); | ||
67 | return -1; | ||
68 | } | ||
69 | |||
70 | /* Read file length from header and compare to real file length */ | ||
71 | length=lseek(fd,0,SEEK_END)-6; | ||
72 | lseek(fd, 0, SEEK_SET); | ||
73 | if(read(fd, &file_length, 4) != 4) { | ||
74 | rolo_error("Error Reading File Length"); | ||
75 | return -1; | ||
76 | } | ||
77 | if (length != file_length) { | ||
78 | rolo_error("File length mismatch"); | ||
79 | return -1; | ||
80 | } | ||
81 | |||
82 | /* Read and save checksum */ | ||
83 | lseek(fd, 4, SEEK_SET); | ||
84 | if (read(fd, &file_checksum, 2) != 2) { | ||
85 | rolo_error("Error Reading checksum"); | ||
86 | return -1; | ||
87 | } | ||
88 | lseek(fd, 6, SEEK_SET); | ||
89 | |||
90 | /* verify that file can be read and descrambled */ | ||
91 | if ((&mp3buf[0] + (2*length)+4) >= &mp3end) { | ||
92 | rolo_error("Not enough room to load file"); | ||
93 | return -1; | ||
94 | } | ||
95 | |||
96 | if (read(fd, &mp3buf[length], length) != (int)length) { | ||
97 | rolo_error("Error Reading File"); | ||
98 | return -1; | ||
99 | } | ||
100 | |||
101 | lcd_puts(0, 1, "Descrambling"); | ||
102 | lcd_update(); | ||
103 | |||
104 | /* descramble */ | ||
105 | slen = length/4; | ||
106 | for (i = 0; i < length; i++) { | ||
107 | unsigned long addr = ((i % slen) << 2) + i/slen; | ||
108 | unsigned char data = mp3buf[i+length]; | ||
109 | data = ~((data >> 1) | ((data << 7) & 0x80)); /* poor man's ROR */ | ||
110 | mp3buf[addr] = data; | ||
111 | } | ||
112 | |||
113 | /* Compute checksum and verify against checksum from file header */ | ||
114 | checksum=0; | ||
115 | for (i=0; i<length; i++) | ||
116 | checksum += mp3buf[i]; | ||
117 | |||
118 | if (checksum != file_checksum) { | ||
119 | rolo_error("Checksum Error"); | ||
120 | return -1; | ||
121 | } | ||
122 | |||
123 | lcd_puts(0, 1, "Executing "); | ||
124 | lcd_update(); | ||
125 | |||
126 | /* Disable interrupts */ | ||
127 | asm("mov #15<<4,r6\n" | ||
128 | "ldc r6,sr"); | ||
129 | |||
130 | /* Calling these 2 initialization routines was necessary to get the | ||
131 | the origional Archos version of the firmware to load and execute. */ | ||
132 | system_init(); /* Initialize system for restart */ | ||
133 | i2c_init(); /* Init i2c bus - it seems like a good idea */ | ||
134 | ICR = IRQ0_EDGE_TRIGGER; /* Make IRQ0 edge triggered */ | ||
135 | |||
136 | /* move firmware to start of ram */ | ||
137 | for ( i=0; i < length/4+1; i++ ) | ||
138 | ((unsigned int*)ramstart)[i] = ((unsigned int*)mp3buf)[i]; | ||
139 | |||
140 | start_func(); /* start new firmware */ | ||
141 | |||
142 | return 0; /* this is never reached */ | ||
143 | } | ||