diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2007-01-16 23:12:02 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2007-01-16 23:12:02 +0000 |
commit | f3f0d1c9bb71c9e747fd21c2a2a2970eddea7433 (patch) | |
tree | 861b5172e623cde268f939a5fbcf09e1588fb751 /bootloader/ipod.c | |
parent | d1e2ce291897853eb04cf0d112a92471ed73e90d (diff) | |
download | rockbox-f3f0d1c9bb71c9e747fd21c2a2a2970eddea7433.tar.gz rockbox-f3f0d1c9bb71c9e747fd21c2a2a2970eddea7433.zip |
Added printf() instead of snprintf/lcd_puts/lcd_update
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12033 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'bootloader/ipod.c')
-rw-r--r-- | bootloader/ipod.c | 112 |
1 files changed, 54 insertions, 58 deletions
diff --git a/bootloader/ipod.c b/bootloader/ipod.c index f274c82364..5f7060a526 100644 --- a/bootloader/ipod.c +++ b/bootloader/ipod.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <stdarg.h> | ||
27 | #include "cpu.h" | 28 | #include "cpu.h" |
28 | #include "system.h" | 29 | #include "system.h" |
29 | #include "lcd.h" | 30 | #include "lcd.h" |
@@ -156,6 +157,31 @@ int opto_keypad_read(void) | |||
156 | } | 157 | } |
157 | #endif | 158 | #endif |
158 | 159 | ||
160 | char printfbuf[256]; | ||
161 | |||
162 | void reset_screen(void) | ||
163 | { | ||
164 | lcd_clear_display(); | ||
165 | line = 0; | ||
166 | } | ||
167 | |||
168 | void printf(const char *format, ...) | ||
169 | { | ||
170 | int len; | ||
171 | unsigned char *ptr; | ||
172 | va_list ap; | ||
173 | va_start(ap, format); | ||
174 | |||
175 | ptr = printfbuf; | ||
176 | len = vsnprintf(ptr, sizeof(printfbuf), format, ap); | ||
177 | va_end(ap); | ||
178 | |||
179 | lcd_puts(0, line++, ptr); | ||
180 | lcd_update(); | ||
181 | if(line >= 30) | ||
182 | line = 0; | ||
183 | } | ||
184 | |||
159 | static int key_pressed(void) | 185 | static int key_pressed(void) |
160 | { | 186 | { |
161 | unsigned char state; | 187 | unsigned char state; |
@@ -200,7 +226,6 @@ int load_rockbox(unsigned char* buf, char* firmware) | |||
200 | char model[5]; | 226 | char model[5]; |
201 | unsigned long sum; | 227 | unsigned long sum; |
202 | int i; | 228 | int i; |
203 | char str[80]; | ||
204 | char filename[MAX_PATH]; | 229 | char filename[MAX_PATH]; |
205 | 230 | ||
206 | snprintf(filename,sizeof(filename),"/.rockbox/%s",firmware); | 231 | snprintf(filename,sizeof(filename),"/.rockbox/%s",firmware); |
@@ -231,13 +256,9 @@ int load_rockbox(unsigned char* buf, char* firmware) | |||
231 | 256 | ||
232 | model[4] = 0; | 257 | model[4] = 0; |
233 | 258 | ||
234 | snprintf(str, 80, "Model: %s", model); | 259 | printf("Model: %s", model); |
235 | lcd_puts(0, line++, str); | 260 | printf("Checksum: %x", chksum); |
236 | snprintf(str, 80, "Checksum: %x", chksum); | 261 | printf("Loading %s", firmware); |
237 | lcd_puts(0, line++, str); | ||
238 | snprintf(str, 80, "Loading %s", firmware); | ||
239 | lcd_puts(0, line++, str); | ||
240 | lcd_update(); | ||
241 | 262 | ||
242 | lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); | 263 | lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); |
243 | 264 | ||
@@ -253,12 +274,10 @@ int load_rockbox(unsigned char* buf, char* firmware) | |||
253 | sum += buf[i]; | 274 | sum += buf[i]; |
254 | } | 275 | } |
255 | 276 | ||
256 | snprintf(str, 80, "Sum: %x", sum); | 277 | printf("Sum: %x", sum); |
257 | lcd_puts(0, line++, str); | ||
258 | lcd_update(); | ||
259 | 278 | ||
260 | if(sum != chksum) | 279 | if(sum != chksum) |
261 | return -5; | 280 | return -5; |
262 | 281 | ||
263 | return len; | 282 | return len; |
264 | } | 283 | } |
@@ -268,7 +287,6 @@ int load_linux(unsigned char* buf) { | |||
268 | int fd; | 287 | int fd; |
269 | int rc; | 288 | int rc; |
270 | int len; | 289 | int len; |
271 | char str[80]; | ||
272 | 290 | ||
273 | fd=open("/linux.bin",O_RDONLY); | 291 | fd=open("/linux.bin",O_RDONLY); |
274 | if (fd < 0) | 292 | if (fd < 0) |
@@ -283,9 +301,7 @@ int load_linux(unsigned char* buf) { | |||
283 | if (rc < len) | 301 | if (rc < len) |
284 | return -4; | 302 | return -4; |
285 | 303 | ||
286 | snprintf(str, 80, "Loaded Linux: %d bytes", len); | 304 | printf("Loaded Linux: %d bytes", len); |
287 | lcd_puts(0, line++, str); | ||
288 | lcd_update(); | ||
289 | 305 | ||
290 | return len; | 306 | return len; |
291 | } | 307 | } |
@@ -300,14 +316,13 @@ void fatal_error(void) | |||
300 | 316 | ||
301 | /* System font is 6 pixels wide */ | 317 | /* System font is 6 pixels wide */ |
302 | #if LCD_WIDTH >= (30*6) | 318 | #if LCD_WIDTH >= (30*6) |
303 | lcd_puts(0, line++, "Press MENU+SELECT to reboot"); | 319 | printf("Press MENU+SELECT to reboot"); |
304 | lcd_puts(0, line++, "then SELECT+PLAY for disk mode"); | 320 | printf("then SELECT+PLAY for disk mode"); |
305 | #else | 321 | #else |
306 | lcd_puts(0, line++, "Press MENU+SELECT to"); | 322 | printf("Press MENU+SELECT to"); |
307 | lcd_puts(0, line++, "reboot then SELECT+PLAY"); | 323 | printf("reboot then SELECT+PLAY"); |
308 | lcd_puts(0, line++, "for disk mode"); | 324 | printf("for disk mode"); |
309 | #endif | 325 | #endif |
310 | lcd_update(); | ||
311 | 326 | ||
312 | while (1) { | 327 | while (1) { |
313 | if (button_hold() != holdstatus) { | 328 | if (button_hold() != holdstatus) { |
@@ -389,12 +404,9 @@ void* main(void) | |||
389 | 404 | ||
390 | lcd_setfont(FONT_SYSFIXED); | 405 | lcd_setfont(FONT_SYSFIXED); |
391 | 406 | ||
392 | lcd_puts(0, line++, "Rockbox boot loader"); | 407 | printf("Rockbox boot loader"); |
393 | snprintf(buf, sizeof(buf), "Version: 20%s", version); | 408 | printf("Version: 20%s", version); |
394 | lcd_puts(0, line++, buf); | 409 | printf("IPOD version: 0x%08x", IPOD_HW_REVISION); |
395 | snprintf(buf, sizeof(buf), "IPOD version: 0x%08x", IPOD_HW_REVISION); | ||
396 | lcd_puts(0, line++, buf); | ||
397 | lcd_update(); | ||
398 | 410 | ||
399 | i=ata_init(); | 411 | i=ata_init(); |
400 | if (i==0) { | 412 | if (i==0) { |
@@ -407,27 +419,22 @@ void* main(void) | |||
407 | for (i=39; i && buf[i]==' '; i--) { | 419 | for (i=39; i && buf[i]==' '; i--) { |
408 | buf[i]=0; | 420 | buf[i]=0; |
409 | } | 421 | } |
410 | lcd_puts(0, line++, buf); | 422 | printf(buf); |
411 | lcd_update(); | ||
412 | } else { | 423 | } else { |
413 | snprintf(buf, sizeof(buf), "ATA: %d", i); | 424 | printf("ATA: %d", i); |
414 | lcd_puts(0, line++, buf); | ||
415 | lcd_update(); | ||
416 | } | 425 | } |
417 | 426 | ||
418 | disk_init(); | 427 | disk_init(); |
419 | rc = disk_mount_all(); | 428 | rc = disk_mount_all(); |
420 | if (rc<=0) | 429 | if (rc<=0) |
421 | { | 430 | { |
422 | lcd_puts(0, line++, "No partition found"); | 431 | printf("No partition found"); |
423 | fatal_error(); | 432 | fatal_error(); |
424 | } | 433 | } |
425 | 434 | ||
426 | pinfo = disk_partinfo(1); | 435 | pinfo = disk_partinfo(1); |
427 | snprintf(buf, sizeof(buf), "Partition 1: 0x%02x %ld MB", | 436 | printf("Partition 1: 0x%02x %ld MB", |
428 | pinfo->type, pinfo->size / 2048); | 437 | pinfo->type, pinfo->size / 2048); |
429 | lcd_puts(0, line++, buf); | ||
430 | lcd_update(); | ||
431 | 438 | ||
432 | /* See if there is an Apple firmware image in RAM */ | 439 | /* See if there is an Apple firmware image in RAM */ |
433 | haveretailos = (memcmp((void*)(DRAM_START+0x20),"portalplayer",12)==0); | 440 | haveretailos = (memcmp((void*)(DRAM_START+0x20),"portalplayer",12)==0); |
@@ -438,29 +445,22 @@ void* main(void) | |||
438 | i=key_pressed(); | 445 | i=key_pressed(); |
439 | 446 | ||
440 | if ((i!=BUTTON_MENU) && (i!=BUTTON_PLAY)) { | 447 | if ((i!=BUTTON_MENU) && (i!=BUTTON_PLAY)) { |
441 | lcd_puts(0, line, "Loading Rockbox..."); | 448 | printf("Loading Rockbox..."); |
442 | lcd_update(); | ||
443 | rc=load_rockbox(loadbuffer, BOOTFILE); | 449 | rc=load_rockbox(loadbuffer, BOOTFILE); |
444 | if (rc < 0) { | 450 | if (rc < 0) { |
445 | snprintf(buf, sizeof(buf), "Rockbox error: %d",rc); | 451 | printf("Rockbox error: %d",rc); |
446 | lcd_puts(0, line++, buf); | ||
447 | lcd_update(); | ||
448 | } else { | 452 | } else { |
449 | lcd_puts(0, line++, "Rockbox loaded."); | 453 | printf("Rockbox loaded."); |
450 | lcd_update(); | ||
451 | memcpy((void*)DRAM_START,loadbuffer,rc); | 454 | memcpy((void*)DRAM_START,loadbuffer,rc); |
452 | return (void*)DRAM_START; | 455 | return (void*)DRAM_START; |
453 | } | 456 | } |
454 | } | 457 | } |
455 | 458 | ||
456 | if (i==BUTTON_PLAY) { | 459 | if (i==BUTTON_PLAY) { |
457 | lcd_puts(0, line, "Loading Linux..."); | 460 | printf("Loading Linux..."); |
458 | lcd_update(); | ||
459 | rc=load_linux(loadbuffer); | 461 | rc=load_linux(loadbuffer); |
460 | if (rc < 0) { | 462 | if (rc < 0) { |
461 | snprintf(buf, sizeof(buf), "Linux error: %d",rc); | 463 | printf("Linux error: %d",rc); |
462 | lcd_puts(0, line++, buf); | ||
463 | lcd_update(); | ||
464 | } else { | 464 | } else { |
465 | memcpy((void*)DRAM_START,loadbuffer,rc); | 465 | memcpy((void*)DRAM_START,loadbuffer,rc); |
466 | return (void*)DRAM_START; | 466 | return (void*)DRAM_START; |
@@ -472,8 +472,7 @@ void* main(void) | |||
472 | /* If either the hold switch was on, or loading Rockbox/IPL | 472 | /* If either the hold switch was on, or loading Rockbox/IPL |
473 | failed, then try the Apple firmware */ | 473 | failed, then try the Apple firmware */ |
474 | 474 | ||
475 | lcd_puts(0, line, "Loading original firmware..."); | 475 | printf("Loading original firmware..."); |
476 | lcd_update(); | ||
477 | 476 | ||
478 | /* First try an apple_os.ipod file on the FAT32 partition | 477 | /* First try an apple_os.ipod file on the FAT32 partition |
479 | (either in .rockbox or the root) | 478 | (either in .rockbox or the root) |
@@ -483,12 +482,9 @@ void* main(void) | |||
483 | 482 | ||
484 | /* Only report errors if the file was found */ | 483 | /* Only report errors if the file was found */ |
485 | if (rc < -1) { | 484 | if (rc < -1) { |
486 | snprintf(buf, sizeof(buf), "apple_os.ipod error: %d",rc); | 485 | printf("apple_os.ipod error: %d",rc); |
487 | lcd_puts(0, line++, buf); | ||
488 | lcd_update(); | ||
489 | } else if (rc > 0) { | 486 | } else if (rc > 0) { |
490 | lcd_puts(0, line++, "apple_os.ipod loaded."); | 487 | printf("apple_os.ipod loaded."); |
491 | lcd_update(); | ||
492 | memcpy((void*)DRAM_START,loadbuffer,rc); | 488 | memcpy((void*)DRAM_START,loadbuffer,rc); |
493 | return (void*)DRAM_START; | 489 | return (void*)DRAM_START; |
494 | } | 490 | } |
@@ -499,7 +495,7 @@ void* main(void) | |||
499 | } | 495 | } |
500 | 496 | ||
501 | /* Everything failed - just loop forever */ | 497 | /* Everything failed - just loop forever */ |
502 | lcd_puts(0, line++, "No RetailOS detected"); | 498 | printf("No RetailOS detected"); |
503 | 499 | ||
504 | fatal_error(); | 500 | fatal_error(); |
505 | 501 | ||