summaryrefslogtreecommitdiff
path: root/bootloader/gigabeat.c
diff options
context:
space:
mode:
authorGreg White <gwhite@rockbox.org>2007-01-17 01:49:19 +0000
committerGreg White <gwhite@rockbox.org>2007-01-17 01:49:19 +0000
commit8b3c8791f9cec1df3ace5082d0ffba6c281963f6 (patch)
tree46614cb8d174ce52a18bb2e82b0c7524edef59c0 /bootloader/gigabeat.c
parent708431da88b7afb5b101443a628b7a8657454369 (diff)
downloadrockbox-8b3c8791f9cec1df3ace5082d0ffba6c281963f6.tar.gz
rockbox-8b3c8791f9cec1df3ace5082d0ffba6c281963f6.zip
Created bootsplash image
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12035 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'bootloader/gigabeat.c')
-rw-r--r--bootloader/gigabeat.c310
1 files changed, 73 insertions, 237 deletions
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c
index 38e8bbf63e..d82ee971d9 100644
--- a/bootloader/gigabeat.c
+++ b/bootloader/gigabeat.c
@@ -18,132 +18,17 @@
18#include "power.h" 18#include "power.h"
19#include "file.h" 19#include "file.h"
20#include "button-target.h" 20#include "button-target.h"
21#include "bootsplash-gigabeat.h"
21 22
22void map_memory(void); 23extern void map_memory(void);
23 24
24int line = 0; 25int line = 0;
25 26
26char version[] = APPSVERSION; 27char version[] = APPSVERSION;
27 28
28/* This section allows you to toggle bits of any memory location */ 29static void go_usb_mode(void)
29/* Touchpad to move around the bits. Select to toggle the red bit */
30typedef struct {
31 unsigned int address;
32 char *desc;
33} memlocation_struct;
34
35/* Just add any address and descriptions here */
36/* Must finish with 0xFFFFFFFF */
37const memlocation_struct memlocations[] = {
38/* Address Description */
39{ 0x56000000, "GPACON" },
40{ 0x56000004, "GPADAT" },
41{ 0x56000010, "GPBCON" },
42{ 0x56000014, "GPBDAT" },
43{ 0x56000020, "GPCCON" },
44{ 0x56000024, "GPCDAT" },
45{ 0x56000030, "GPDCON" },
46{ 0x56000034, "GPDDAT" },
47{ 0x56000040, "GPECON" },
48{ 0x56000044, "GPEDAT" },
49{ 0x56000050, "GPFCON" },
50{ 0x56000054, "GPFDAT" },
51{ 0x56000060, "GPGCON" },
52{ 0x56000064, "GPGDAT" },
53{ 0x56000070, "GPHCON" },
54{ 0x56000074, "GPHDAT" },
55{ 0xFFFFFFFF, 0 }
56};
57
58void memdump(void)
59{ 30{
60 int i, j; 31 /* Drop into USB mode. This does not check for disconnection. */
61 int current=0, bit=0;
62 char * bitval;
63 int data;
64 char tmp[40];
65
66 while(1) {
67 i = 0;
68
69 while(memlocations[i].address != 0xFFFFFFFF) {
70
71 data = *(volatile int *)memlocations[i].address;
72
73 snprintf(tmp, sizeof(tmp), "%s %s 0x%08X",
74 (i==current) ? "*" : " ",
75 memlocations[i].desc,
76 data);
77 lcd_puts(0, i*2+5, tmp);
78
79 /* print out in binary, current bit in red */
80 for (j=31; j>=0; j--) {
81 if ((bit == j) && (current == i))
82 lcd_set_foreground(LCD_RGBPACK(255,0,0));
83 lcd_puts((31-j) + ((31-j) / 8), i*2+6, (data & (1 << j)) ? "1" : "0" );
84 lcd_set_foreground(LCD_RGBPACK(0,0,0));
85 }
86
87 i++;
88 }
89
90 data = *(volatile int *)memlocations[current].address;
91 bitval = (data & (1 << bit)) ? "1" : "0";
92 snprintf(tmp, sizeof(tmp), "%s bit %ld = %s", memlocations[current].desc, bit, bitval);
93 lcd_puts(0, (i*2)+7, tmp);
94
95 lcd_update();
96
97 /* touchpad controls */
98
99 /* Up */
100 if (GPJDAT & 0x01) {
101 if (current > 0)
102 current--;
103 while(GPJDAT & 0x01);
104 }
105
106 /* Down */
107 if (GPJDAT & 0x40) {
108 if (current < (i-1))
109 current++;
110 while(GPJDAT & 0x40);
111 }
112
113 /* Left */
114 if (GPJDAT & 0x80) {
115 if (bit < 31)
116 bit++;
117 while(GPJDAT & 0x80);
118 }
119
120 /* Right */
121 if (GPJDAT & 0x1000) {
122 if (bit > 0)
123 bit--;
124 while(GPJDAT & 0x1000);
125 }
126
127 /* Centre - Toggle Bit */
128 if (GPJDAT & 0x08) {
129 data = *(volatile int *)memlocations[current].address;
130 data = data ^ (1 << bit);
131 *(volatile int *)memlocations[current].address = data;
132 while(GPJDAT & 0x08);
133 }
134
135 /* Bail out if the power button is pressed */
136 if (GPGDAT & 1) {
137 break;
138 }
139 }
140}
141
142
143static void go_usb_mode(void) {
144 /* Drop into USB mode. This does not check for disconnection. */
145
146
147 int i; 32 int i;
148 33
149 GPBDAT &= 0x7EF; 34 GPBDAT &= 0x7EF;
@@ -152,7 +37,9 @@ static void go_usb_mode(void) {
152 GPGDAT &= 0xE7FF; 37 GPGDAT &= 0xE7FF;
153 GPGDAT |= 1<<11; 38 GPGDAT |= 1<<11;
154 39
155 for (i = 0; i < 10000000; i++) {continue;} 40 for(i = 0; i < 10000000; i++) {
41 continue;
42 }
156 43
157 GPBCON &= 0x2FFCFF; 44 GPBCON &= 0x2FFCFF;
158 GPBDAT |= 1<<5; 45 GPBDAT |= 1<<5;
@@ -168,11 +55,11 @@ int restore_fwimg01dat(void)
168{ 55{
169 int orig_file = 0, dest_file = 0; 56 int orig_file = 0, dest_file = 0;
170 int size = 0, size_read; 57 int size = 0, size_read;
171 char buf[256]; 58 static char buf[4096];
172 char lcd_buf[64]; 59 char lcd_buf[64];
173 60
174 orig_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT.ORIG", O_RDONLY); 61 orig_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT.ORIG", O_RDONLY);
175 if (orig_file < 0) { 62 if(orig_file < 0) {
176 /* Couldn't open source file */ 63 /* Couldn't open source file */
177 lcd_puts(0, line++, "Couldn't open FWIMG01.DAT.ORIG for reading"); 64 lcd_puts(0, line++, "Couldn't open FWIMG01.DAT.ORIG for reading");
178 lcd_update(); 65 lcd_update();
@@ -183,7 +70,7 @@ int restore_fwimg01dat(void)
183 lcd_update(); 70 lcd_update();
184 71
185 dest_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT", O_RDWR); 72 dest_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT", O_RDWR);
186 if (dest_file < 0) { 73 if(dest_file < 0) {
187 /* Couldn't open destination file */ 74 /* Couldn't open destination file */
188 lcd_puts(0, line++, "Couldn't open FWIMG01.DAT.ORIG for writing"); 75 lcd_puts(0, line++, "Couldn't open FWIMG01.DAT.ORIG for writing");
189 lcd_update(); 76 lcd_update();
@@ -197,14 +84,14 @@ int restore_fwimg01dat(void)
197 do { 84 do {
198 /* Copy in chunks */ 85 /* Copy in chunks */
199 size_read = read(orig_file, buf, sizeof(buf)); 86 size_read = read(orig_file, buf, sizeof(buf));
200 if (size_read != write(dest_file, buf, size_read)) { 87 if(size_read != write(dest_file, buf, size_read)) {
201 close(orig_file); 88 close(orig_file);
202 close(dest_file); 89 close(dest_file);
203 return(3); 90 return(3);
204 } 91 }
205 size += size_read; 92 size += size_read;
206 93
207 } while (size_read > 0); 94 } while(size_read > 0);
208 95
209 close(orig_file); 96 close(orig_file);
210 close(dest_file); 97 close(dest_file);
@@ -223,15 +110,9 @@ int load_rockbox(const char* file_name, unsigned char* buf, int buffer_size)
223 int rc; 110 int rc;
224 int len; 111 int len;
225 char str[256]; 112 char str[256];
226 //unsigned long chksum;
227 //char model[5];
228 //unsigned long sum;
229 //int i;
230 //char str[80];
231 113
232 fd = open("/.rockbox/" BOOTFILE, O_RDONLY); 114 fd = open("/.rockbox/" BOOTFILE, O_RDONLY);
233 if(fd < 0) 115 if(fd < 0) {
234 {
235 fd = open("/" BOOTFILE, O_RDONLY); 116 fd = open("/" BOOTFILE, O_RDONLY);
236 if(fd < 0) 117 if(fd < 0)
237 return -1; 118 return -1;
@@ -242,68 +123,33 @@ int load_rockbox(const char* file_name, unsigned char* buf, int buffer_size)
242 123
243 len = filesize(fd); 124 len = filesize(fd);
244 125
245 if (len > buffer_size) { 126 if(len > buffer_size) {
246 snprintf(str, sizeof(str), "len: %d buf: %d", len, buffer_size); 127 snprintf(str, sizeof(str), "len: %d buf: %d", len, buffer_size);
247 lcd_puts(0, line++, str); 128 lcd_puts(0, line++, str);
248 lcd_update(); 129 lcd_update();
249 return -6; 130 return -6;
250 } 131 }
251 132
252 /*lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
253
254 rc = read(fd, &chksum, 4);
255 chksum=betoh32(chksum);*/ /* Rockbox checksums are big-endian */
256 /*if(rc < 4)
257 return -2;
258
259 rc = read(fd, model, 4);
260 if(rc < 4)
261 return -3;
262
263 model[4] = 0;
264
265 snprintf(str, 80, "Model: %s", model);
266 lcd_puts(0, line++, str);
267 snprintf(str, 80, "Checksum: %x", chksum);
268 lcd_puts(0, line++, str);
269 lcd_update();
270
271 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
272*/
273
274 rc = read(fd, buf, len); 133 rc = read(fd, buf, len);
275 if(rc < len) { 134 if(rc < len) {
276 snprintf(str, sizeof(str), "len: %d rc: %d", len, rc); 135 snprintf(str, sizeof(str), "len: %d rc: %d", len, rc);
277 lcd_puts(0, line++, str); 136 lcd_puts(0, line++, str);
278 lcd_update(); 137 lcd_update();
279 return -4; 138 return -4;
280 } 139 }
281 140
282 close(fd); 141 close(fd);
283 142
284 /*sum = MODEL_NUMBER;
285
286 for(i = 0;i < len;i++) {
287 sum += buf[i];
288 }
289
290 snprintf(str, 80, "Sum: %x", sum);
291 lcd_puts(0, line++, str);
292 lcd_update();
293
294 if(sum != chksum)
295 return -5;*/
296
297 return len; 143 return len;
298} 144}
299 145
146
300void * main(void) 147void * main(void)
301{ 148{
302 int i; 149 int i;
303 char buf[256]; 150 char buf[256];
304 struct partinfo* pinfo; 151 struct partinfo* pinfo;
305 unsigned short* identify_info; 152 unsigned short* identify_info;
306 //int testfile;
307 unsigned char* loadbuffer; 153 unsigned char* loadbuffer;
308 int buffer_size; 154 int buffer_size;
309 bool load_original = false; 155 bool load_original = false;
@@ -311,55 +157,50 @@ void * main(void)
311 int(*kernel_entry)(void); 157 int(*kernel_entry)(void);
312 158
313 lcd_init(); 159 lcd_init();
314 lcd_setfont(FONT_SYSFIXED); 160 bool show_bootsplash = true;
315/* 161
316 lcd_puts(0, line++, "Rockbox boot loader"); 162 if(GPGDAT & 2)
317 snprintf(buf, sizeof(buf), "Version: 20%s", version); 163 show_bootsplash = false;
318 lcd_puts(0, line++, buf); 164
319 snprintf(buf, sizeof(buf), "Gigabeat version: 0x%08x", 1); 165 if(!show_bootsplash) {
320 lcd_puts(0, line++, buf); 166 lcd_setfont(FONT_SYSFIXED);
321*/ 167 lcd_puts(0, line++, "Hold MENU when booting for rescue mode.");
322 168 lcd_puts(0, line++, " \"VOL+\" button to restore original kernel");
323 lcd_puts(0, line++, "Hold MENU when booting for rescue mode."); 169 lcd_puts(0, line++, " \"A\" button to load original firmware");
324 lcd_puts(0, line++, " \"VOL+\" button to restore original kernel"); 170 line++;
325 lcd_puts(0, line++, " \"A\" button to load original firmware"); 171 snprintf(buf, sizeof(buf), "FRAME %x TTB %x", FRAME, TTB_BASE);
326 line++; 172 lcd_puts(0, line++, buf);
327 snprintf(buf, sizeof(buf), "FRAME %x TTB %x", FRAME, TTB_BASE); 173 lcd_update();
328 lcd_puts(0, line++, buf); 174 sleep(2*HZ);
329 lcd_update(); 175 } else
330 sleep(1*HZ); 176 memcpy(FRAME, bootsplash, LCD_WIDTH*LCD_HEIGHT*2);
331 177 if(GPGDAT & 2) {
332 /* hold MENU to enter rescue mode */
333 if (GPGDAT & 2) {
334 lcd_puts(0, line++, "Entering rescue mode.."); 178 lcd_puts(0, line++, "Entering rescue mode..");
335 lcd_update(); 179 lcd_update();
336 go_usb_mode(); 180 go_usb_mode();
337 while(1); 181 while(1);
338 } 182 }
339
340 sleep(1*HZ);
341
342 if(GPGDAT & 0x10) { 183 if(GPGDAT & 0x10) {
343 load_original = true; 184 load_original = true;
344 lcd_puts(0, line++, "Loading original firmware..."); 185 lcd_puts(0, line++, "Loading original firmware...");
345 lcd_update(); 186 lcd_update();
346 } 187 }
347 188
348 i = ata_init(); 189 i = ata_init();
349 i = disk_mount_all(); 190 i = disk_mount_all();
350 191 if(!show_bootsplash) {
351 snprintf(buf, sizeof(buf), "disk_mount_all: %d", i); 192 snprintf(buf, sizeof(buf), "disk_mount_all: %d", i);
352 lcd_puts(0, line++, buf); 193 lcd_puts(0, line++, buf);
353 194 }
354 /* hold VOL+ to enter rescue mode to copy old image */ 195 /* hold VOL+ to enter rescue mode to copy old image */
355 /* needs to be after ata_init and disk_mount_all */ 196 /* needs to be after ata_init and disk_mount_all */
356 if (GPGDAT & 4) { 197 if(GPGDAT & 4) {
357 198
358 /* Try to restore the original kernel/bootloader if a copy is found */ 199 /* Try to restore the original kernel/bootloader if a copy is found */
359 lcd_puts(0, line++, "Restoring FWIMG01.DAT..."); 200 lcd_puts(0, line++, "Restoring FWIMG01.DAT...");
360 lcd_update(); 201 lcd_update();
361 202
362 if (!restore_fwimg01dat()) { 203 if(!restore_fwimg01dat()) {
363 lcd_puts(0, line++, "Restoring FWIMG01.DAT successful."); 204 lcd_puts(0, line++, "Restoring FWIMG01.DAT successful.");
364 } else { 205 } else {
365 lcd_puts(0, line++, "Restoring FWIMG01.DAT failed."); 206 lcd_puts(0, line++, "Restoring FWIMG01.DAT failed.");
@@ -370,45 +211,41 @@ void * main(void)
370 while(1); 211 while(1);
371 } 212 }
372 213
373 /* Memory dump mode if Vol- pressed */ 214 if(!show_bootsplash) {
374 if (GPGDAT & 8) { 215 identify_info = ata_get_identify();
375 memdump();
376 }
377
378 identify_info = ata_get_identify();
379
380 for (i=0; i < 20; i++)
381 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
382 216
383 buf[40]=0; 217 for(i=0; i < 20; i++)
218 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
384 219
385 /* kill trailing space */ 220 buf[40]=0;
386 for (i=39; i && buf[i]==' '; i--)
387 buf[i] = 0;
388 221
389 lcd_puts(0, line++, "Model"); 222 /* kill trailing space */
390 lcd_puts(0, line++, buf); 223 for(i=39; i && buf[i]==' '; i--)
224 buf[i] = 0;
391 225
392 for (i=0; i < 4; i++) 226 lcd_puts(0, line++, "Model");
393 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]); 227 lcd_puts(0, line++, buf);
394 228
395 buf[8]=0; 229 for(i=0; i < 4; i++)
230 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
396 231
397 lcd_puts(0, line++, "Firmware"); 232 buf[8]=0;
398 lcd_puts(0, line++, buf);
399 233
400 pinfo = disk_partinfo(0); 234 lcd_puts(0, line++, "Firmware");
401 snprintf(buf, sizeof(buf), "Partition 0: 0x%02x %ld MB", 235 lcd_puts(0, line++, buf);
402 pinfo->type, pinfo->size / 2048);
403 lcd_puts(0, line++, buf);
404 lcd_update();
405 236
237 pinfo = disk_partinfo(0);
238 snprintf(buf, sizeof(buf), "Partition 0: 0x%02x %ld MB",
239 pinfo->type, pinfo->size / 2048);
240 lcd_puts(0, line++, buf);
241 lcd_update();
242 }
406 /* Load original firmware */ 243 /* Load original firmware */
407 if(load_original) { 244 if(load_original) {
408 loadbuffer = (unsigned char*)0x30008000; 245 loadbuffer = (unsigned char*)0x30008000;
409 buffer_size =(unsigned char*)0x31000000 - loadbuffer; 246 buffer_size =(unsigned char*)0x31000000 - loadbuffer;
410 rc = load_rockbox("/rockbox.gigabeat", loadbuffer, buffer_size); 247 rc = load_rockbox("/rockbox.gigabeat", loadbuffer, buffer_size);
411 if (rc < 0) { 248 if(rc < 0) {
412 lcd_puts(0, line++, "failed to load original firmware. Loading rockbox"); 249 lcd_puts(0, line++, "failed to load original firmware. Loading rockbox");
413 lcd_update(); 250 lcd_update();
414 sleep(2*HZ); 251 sleep(2*HZ);
@@ -420,7 +257,6 @@ void * main(void)
420 lcd_update(); 257 lcd_update();
421 sleep(2*HZ); 258 sleep(2*HZ);
422 259
423
424 (*((int*)0x7000000)) = 333; 260 (*((int*)0x7000000)) = 333;
425 rc = *((int*)0x7000000+0x8000000); 261 rc = *((int*)0x7000000+0x8000000);
426 snprintf(buf, sizeof(buf), "Bank0 mem test: %d", rc); 262 snprintf(buf, sizeof(buf), "Bank0 mem test: %d", rc);
@@ -435,21 +271,23 @@ void * main(void)
435 271
436load_rockbox: 272load_rockbox:
437 map_memory(); 273 map_memory();
438 lcd_puts(0, line, "Loading Rockbox..."); 274 if(!show_bootsplash) {
439 lcd_update(); 275 lcd_puts(0, line, "Loading Rockbox...");
440 /* sleep(HZ*4); */ 276 lcd_update();
277 }
441 278
442 // TODO: read those values from somwhere
443 loadbuffer = (unsigned char*) 0x100; 279 loadbuffer = (unsigned char*) 0x100;
444 buffer_size = (unsigned char*)0x400000 - loadbuffer; 280 buffer_size = (unsigned char*)0x400000 - loadbuffer;
445 rc=load_rockbox("/rockbox.gigabeat", loadbuffer, buffer_size); 281 rc=load_rockbox("/rockbox.gigabeat", loadbuffer, buffer_size);
446 if (rc < 0) { 282 if(rc < 0) {
447 snprintf(buf, sizeof(buf), "Rockbox error: %d",rc); 283 snprintf(buf, sizeof(buf), "Rockbox error: %d",rc);
448 lcd_puts(0, line++, buf); 284 lcd_puts(0, line++, buf);
449 lcd_update(); 285 lcd_update();
450 } else { 286 } else {
451 lcd_puts(0, line++, "Rockbox loaded."); 287 if(!show_bootsplash) {
452 lcd_update(); 288 lcd_puts(0, line++, "Rockbox loaded.");
289 lcd_update();
290 }
453 kernel_entry = (void*) loadbuffer; 291 kernel_entry = (void*) loadbuffer;
454 rc = kernel_entry(); 292 rc = kernel_entry();
455 snprintf(buf, sizeof(buf), "Woops, should not return from firmware: %d", rc); 293 snprintf(buf, sizeof(buf), "Woops, should not return from firmware: %d", rc);
@@ -457,13 +295,11 @@ load_rockbox:
457 lcd_update(); 295 lcd_update();
458 goto usb; 296 goto usb;
459 } 297 }
460
461
462usb: 298usb:
463 /* now wait in USB mode so the bootloader can be updated */ 299 /* now wait in USB mode so the bootloader can be updated */
464 go_usb_mode(); 300 go_usb_mode();
465 while(1); 301 while(1);
466 302
467 return((void *)0); 303 return((void *)0);
468} 304}
469 305