summaryrefslogtreecommitdiff
path: root/bootloader
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader')
-rw-r--r--bootloader/SOURCES4
-rw-r--r--bootloader/e200.c353
2 files changed, 357 insertions, 0 deletions
diff --git a/bootloader/SOURCES b/bootloader/SOURCES
index 0c9aa8ba2f..8c3a9b8ee4 100644
--- a/bootloader/SOURCES
+++ b/bootloader/SOURCES
@@ -1,5 +1,9 @@
1#if (CONFIG_CPU == PP5002) || (CONFIG_CPU == PP5020) 1#if (CONFIG_CPU == PP5002) || (CONFIG_CPU == PP5020)
2ipod.c 2ipod.c
3#elif defined(SANSA_E200)
4e200.c
5#elif defined(IRIVER_H10)
6h10.c
3#else 7#else
4main.c 8main.c
5#endif 9#endif
diff --git a/bootloader/e200.c b/bootloader/e200.c
new file mode 100644
index 0000000000..2cf78942a2
--- /dev/null
+++ b/bootloader/e200.c
@@ -0,0 +1,353 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Dave Chapman
11 *
12 * Based on ipod.c by Dave Chapman
13 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
14 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
15 *
16 * All files in this archive are subject to the GNU General Public License.
17 * See the file COPYING in the source tree root for full license agreement.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#include "config.h"
24
25#include <stdlib.h>
26#include <stdio.h>
27#include <string.h>
28#include "cpu.h"
29#include "system.h"
30#include "lcd.h"
31#include "kernel.h"
32#include "thread.h"
33#include "ata.h"
34#include "fat.h"
35#include "disk.h"
36#include "font.h"
37#include "adc.h"
38#include "backlight.h"
39#include "panic.h"
40#include "power.h"
41#include "file.h"
42
43#define XSC(X) #X
44#define SC(X) XSC(X)
45
46#define DRAM_START 0x10000000
47
48#define BUTTON_LEFT 1
49#define BUTTON_MENU 2
50#define BUTTON_RIGHT 3
51#define BUTTON_PLAY 4
52#define BUTTON_HOLD 5
53
54/* Size of the buffer to store the loaded Rockbox/Linux image */
55#define MAX_LOADSIZE (4*1024*1024)
56
57char version[] = APPSVERSION;
58
59typedef struct _image {
60 unsigned type; /* '' */
61 unsigned id; /* */
62 unsigned pad1; /* 0000 0000 */
63 unsigned devOffset; /* byte offset of start of image code */
64 unsigned len; /* length in bytes of image */
65 void *addr; /* load address */
66 unsigned entryOffset; /* execution start within image */
67 unsigned chksum; /* checksum for image */
68 unsigned vers; /* image version */
69 unsigned loadAddr; /* load address for image */
70} image_t;
71
72extern image_t boot_table[];
73
74int line=0;
75
76static void memmove16(void *dest, const void *src, unsigned count)
77{
78 struct bufstr {
79 unsigned _buf[4];
80 } *d, *s;
81
82 if (src >= dest) {
83 count = (count + 15) >> 4;
84 d = (struct bufstr *) dest;
85 s = (struct bufstr *) src;
86 while (count--)
87 *d++ = *s++;
88 } else {
89 count = (count + 15) >> 4;
90 d = (struct bufstr *)(dest + (count <<4));
91 s = (struct bufstr *)(src + (count <<4));
92 while (count--)
93 *--d = *--s;
94 }
95}
96
97#if CONFIG_KEYPAD == IPOD_4G_PAD && !defined(IPOD_MINI)
98/* check if number of seconds has past */
99int timer_check(int clock_start, unsigned int usecs)
100{
101 if ((USEC_TIMER - clock_start) >= usecs) {
102 return 1;
103 } else {
104 return 0;
105 }
106}
107
108static void ser_opto_keypad_cfg(int val)
109{
110 int start_time;
111
112 outl(inl(0x6000d004) & ~0x80, 0x6000d004);
113
114 outl(inl(0x7000c104) | 0xc000000, 0x7000c104);
115 outl(val, 0x7000c120);
116 outl(inl(0x7000c100) | 0x80000000, 0x7000c100);
117
118 outl(inl(0x6000d024) & ~0x10, 0x6000d024);
119 outl(inl(0x6000d014) | 0x10, 0x6000d014);
120
121 start_time = USEC_TIMER;
122 do {
123 if ((inl(0x7000c104) & 0x80000000) == 0) {
124 break;
125 }
126 } while (timer_check(start_time, 1500) != 0);
127
128 outl(inl(0x7000c100) & ~0x80000000, 0x7000c100);
129
130 outl(inl(0x6000d004) | 0x80, 0x6000d004);
131 outl(inl(0x6000d024) | 0x10, 0x6000d024);
132 outl(inl(0x6000d014) & ~0x10, 0x6000d014);
133
134 outl(inl(0x7000c104) | 0xc000000, 0x7000c104);
135 outl(inl(0x7000c100) | 0x60000000, 0x7000c100);
136}
137
138int opto_keypad_read(void)
139{
140 int loop_cnt, had_io = 0;
141
142 for (loop_cnt = 5; loop_cnt != 0;)
143 {
144 int key_pressed = 0;
145 int start_time;
146 unsigned int key_pad_val;
147
148 ser_opto_keypad_cfg(0x8000023a);
149
150 start_time = USEC_TIMER;
151 do {
152 if (inl(0x7000c104) & 0x4000000) {
153 had_io = 1;
154 break;
155 }
156
157 if (had_io != 0) {
158 break;
159 }
160 } while (timer_check(start_time, 1500) != 0);
161
162 key_pad_val = inl(0x7000c140);
163 if ((key_pad_val & ~0x7fff0000) != 0x8000023a) {
164 loop_cnt--;
165 } else {
166 key_pad_val = (key_pad_val << 11) >> 27;
167 key_pressed = 1;
168 }
169
170 outl(inl(0x7000c100) | 0x60000000, 0x7000c100);
171 outl(inl(0x7000c104) | 0xc000000, 0x7000c104);
172
173 if (key_pressed != 0) {
174 return key_pad_val ^ 0x1f;
175 }
176 }
177
178 return 0;
179}
180#endif
181
182static int key_pressed(void)
183{
184 unsigned char state;
185
186#if CONFIG_KEYPAD == IPOD_4G_PAD
187#ifdef IPOD_MINI /* mini 1G only */
188 state = GPIOA_INPUT_VAL & 0x3f;
189 if ((state & 0x10) == 0) return BUTTON_LEFT;
190 if ((state & 0x2) == 0) return BUTTON_MENU;
191 if ((state & 0x4) == 0) return BUTTON_PLAY;
192 if ((state & 0x8) == 0) return BUTTON_RIGHT;
193#else
194 state = opto_keypad_read();
195 if ((state & 0x4) == 0) return BUTTON_LEFT;
196 if ((state & 0x10) == 0) return BUTTON_MENU;
197 if ((state & 0x8) == 0) return BUTTON_PLAY;
198 if ((state & 0x2) == 0) return BUTTON_RIGHT;
199#endif
200#elif CONFIG_KEYPAD == IPOD_3G_PAD
201 state = inb(0xcf000030);
202 if (((state & 0x20) == 0)) return BUTTON_HOLD; /* hold on */
203 if ((state & 0x08) == 0) return BUTTON_LEFT;
204 if ((state & 0x10) == 0) return BUTTON_MENU;
205 if ((state & 0x04) == 0) return BUTTON_PLAY;
206 if ((state & 0x01) == 0) return BUTTON_RIGHT;
207#endif
208 return 0;
209}
210
211int load_rockbox(unsigned char* buf)
212{
213 int fd;
214 int rc;
215 int len;
216 unsigned long chksum;
217 char model[5];
218 unsigned long sum;
219 int i;
220 char str[80];
221
222 fd = open("/.rockbox/" BOOTFILE, O_RDONLY);
223 if(fd < 0)
224 {
225 fd = open("/" BOOTFILE, O_RDONLY);
226 if(fd < 0)
227 return -1;
228 }
229
230 len = filesize(fd) - 8;
231
232 if (len > MAX_LOADSIZE)
233 return -6;
234
235 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
236
237 rc = read(fd, &chksum, 4);
238 chksum=betoh32(chksum); /* Rockbox checksums are big-endian */
239 if(rc < 4)
240 return -2;
241
242 rc = read(fd, model, 4);
243 if(rc < 4)
244 return -3;
245
246 model[4] = 0;
247
248 snprintf(str, 80, "Model: %s", model);
249 lcd_puts(0, line++, str);
250 snprintf(str, 80, "Checksum: %x", chksum);
251 lcd_puts(0, line++, str);
252 lcd_update();
253
254 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
255
256 rc = read(fd, buf, len);
257 if(rc < len)
258 return -4;
259
260 close(fd);
261
262 sum = MODEL_NUMBER;
263
264 for(i = 0;i < len;i++) {
265 sum += buf[i];
266 }
267
268 snprintf(str, 80, "Sum: %x", sum);
269 lcd_puts(0, line++, str);
270 lcd_update();
271
272 if(sum != chksum)
273 return -5;
274
275 return len;
276}
277
278
279/* A buffer to load the Linux kernel or Rockbox into */
280unsigned char loadbuffer[MAX_LOADSIZE];
281
282void* main(void)
283{
284 char buf[256];
285 int imageno=0;
286 int i;
287 int rc;
288 int padding = 0x4400;
289 image_t *tblp = boot_table;
290 void* entry;
291 struct partinfo* pinfo;
292 unsigned short* identify_info;
293
294 /* Turn on the backlight */
295
296#if CONFIG_BACKLIGHT==BL_IPOD4G
297 /* brightness full */
298 outl(0x80000000 | (0xff << 16), 0x7000a010);
299
300 /* set port B03 on */
301 outl(((0x100 | 1) << 3), 0x6000d824);
302
303#elif CONFIG_BACKLIGHT==BL_IPODMINI
304 /* set port B03 on */
305 outl(((0x100 | 1) << 3), 0x6000d824);
306
307#elif CONFIG_BACKLIGHT==BL_IPODNANO
308
309 /* set port B03 on */
310 outl(((0x100 | 1) << 3), 0x6000d824);
311
312 /* set port L07 on */
313 outl(((0x100 | 1) << 7), 0x6000d12c);
314#elif CONFIG_BACKLIGHT==BL_IPOD3G
315 outl(inl(IPOD_LCD_BASE) | 0x2, IPOD_LCD_BASE);
316#endif
317
318 /* Return the start address in loaded image */
319 return entry;
320}
321
322/* These functions are present in the firmware library, but we reimplement
323 them here because the originals do a lot more than we want */
324
325void reset_poweroff_timer(void)
326{
327}
328
329int dbg_ports(void)
330{
331 return 0;
332}
333
334void mpeg_stop(void)
335{
336}
337
338void usb_acknowledge(void)
339{
340}
341
342void usb_wait_for_disconnect(void)
343{
344}
345
346void sys_poweroff(void)
347{
348}
349
350void system_reboot(void)
351{
352
353}