diff options
Diffstat (limited to 'bootloader/main.c')
-rw-r--r-- | bootloader/main.c | 150 |
1 files changed, 21 insertions, 129 deletions
diff --git a/bootloader/main.c b/bootloader/main.c index fd878ac5f6..c2e3cce302 100644 --- a/bootloader/main.c +++ b/bootloader/main.c | |||
@@ -43,20 +43,19 @@ | |||
43 | #include "eeprom_settings.h" | 43 | #include "eeprom_settings.h" |
44 | 44 | ||
45 | #include "pcf50606.h" | 45 | #include "pcf50606.h" |
46 | #include "common.h" | ||
46 | 47 | ||
47 | #include <stdarg.h> | 48 | #include <stdarg.h> |
48 | 49 | ||
50 | /* Maximum allowed firmware image size. 10MB is more than enough */ | ||
51 | #define MAX_LOADSIZE (10*1024*1024) | ||
52 | |||
49 | #define DRAM_START 0x31000000 | 53 | #define DRAM_START 0x31000000 |
50 | 54 | ||
51 | #ifdef HAVE_EEPROM_SETTINGS | 55 | #ifdef HAVE_EEPROM_SETTINGS |
52 | static bool recovery_mode = false; | 56 | static bool recovery_mode = false; |
53 | #endif | 57 | #endif |
54 | 58 | ||
55 | int line = 0; | ||
56 | #ifdef HAVE_REMOTE_LCD | ||
57 | int remote_line = 0; | ||
58 | #endif | ||
59 | |||
60 | int usb_screen(void) | 59 | int usb_screen(void) |
61 | { | 60 | { |
62 | return 0; | 61 | return 0; |
@@ -64,41 +63,6 @@ int usb_screen(void) | |||
64 | 63 | ||
65 | char version[] = APPSVERSION; | 64 | char version[] = APPSVERSION; |
66 | 65 | ||
67 | char printfbuf[256]; | ||
68 | |||
69 | void reset_screen(void) | ||
70 | { | ||
71 | lcd_clear_display(); | ||
72 | line = 0; | ||
73 | #ifdef HAVE_REMOTE_LCD | ||
74 | lcd_remote_clear_display(); | ||
75 | remote_line = 0; | ||
76 | #endif | ||
77 | } | ||
78 | |||
79 | void printf(const char *format, ...) | ||
80 | { | ||
81 | int len; | ||
82 | unsigned char *ptr; | ||
83 | va_list ap; | ||
84 | va_start(ap, format); | ||
85 | |||
86 | ptr = printfbuf; | ||
87 | len = vsnprintf(ptr, sizeof(printfbuf), format, ap); | ||
88 | va_end(ap); | ||
89 | |||
90 | lcd_puts(0, line++, ptr); | ||
91 | lcd_update(); | ||
92 | if(line >= 16) | ||
93 | line = 0; | ||
94 | #ifdef HAVE_REMOTE_LCD | ||
95 | lcd_remote_puts(0, remote_line++, ptr); | ||
96 | lcd_remote_update(); | ||
97 | if(remote_line >= 8) | ||
98 | remote_line = 0; | ||
99 | #endif | ||
100 | } | ||
101 | |||
102 | /* Reset the cookie for the crt0 crash check */ | 66 | /* Reset the cookie for the crt0 crash check */ |
103 | inline void __reset_cookie(void) | 67 | inline void __reset_cookie(void) |
104 | { | 68 | { |
@@ -116,68 +80,6 @@ void start_iriver_fw(void) | |||
116 | asm(" jmp (%a0)"); | 80 | asm(" jmp (%a0)"); |
117 | } | 81 | } |
118 | 82 | ||
119 | int load_firmware(void) | ||
120 | { | ||
121 | int fd; | ||
122 | int rc; | ||
123 | int len; | ||
124 | unsigned long chksum; | ||
125 | char model[5]; | ||
126 | unsigned long sum; | ||
127 | int i; | ||
128 | unsigned char *buf = (unsigned char *)DRAM_START; | ||
129 | |||
130 | fd = open("/.rockbox/" BOOTFILE, O_RDONLY); | ||
131 | if(fd < 0) | ||
132 | { | ||
133 | fd = open("/" BOOTFILE, O_RDONLY); | ||
134 | if(fd < 0) | ||
135 | return -1; | ||
136 | } | ||
137 | |||
138 | len = filesize(fd) - 8; | ||
139 | |||
140 | printf("Length: %x", len); | ||
141 | |||
142 | lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); | ||
143 | |||
144 | rc = read(fd, &chksum, 4); | ||
145 | if(rc < 4) | ||
146 | return -2; | ||
147 | |||
148 | printf("Checksum: %x", chksum); | ||
149 | |||
150 | rc = read(fd, model, 4); | ||
151 | if(rc < 4) | ||
152 | return -3; | ||
153 | |||
154 | model[4] = 0; | ||
155 | |||
156 | printf("Model name: %s", model); | ||
157 | lcd_update(); | ||
158 | |||
159 | lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); | ||
160 | |||
161 | rc = read(fd, buf, len); | ||
162 | if(rc < len) | ||
163 | return -4; | ||
164 | |||
165 | close(fd); | ||
166 | |||
167 | sum = MODEL_NUMBER; | ||
168 | |||
169 | for(i = 0;i < len;i++) { | ||
170 | sum += buf[i]; | ||
171 | } | ||
172 | |||
173 | printf("Sum: %x", sum); | ||
174 | |||
175 | if(sum != chksum) | ||
176 | return -5; | ||
177 | |||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | void start_firmware(void) | 83 | void start_firmware(void) |
182 | { | 84 | { |
183 | asm(" move.w #0x2700,%sr"); | 85 | asm(" move.w #0x2700,%sr"); |
@@ -353,6 +255,7 @@ void failsafe_menu(void) | |||
353 | int defopt = -1; | 255 | int defopt = -1; |
354 | char buf[32]; | 256 | char buf[32]; |
355 | int i; | 257 | int i; |
258 | extern int line; | ||
356 | 259 | ||
357 | reset_screen(); | 260 | reset_screen(); |
358 | printf("Bootloader %s", version); | 261 | printf("Bootloader %s", version); |
@@ -516,15 +419,21 @@ void main(void) | |||
516 | } | 419 | } |
517 | 420 | ||
518 | printf("Loading firmware"); | 421 | printf("Loading firmware"); |
519 | i = load_firmware(); | 422 | i = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE); |
520 | printf("Result: %d", i); | 423 | printf("Result: %s", strerror(i)); |
521 | 424 | ||
522 | if(i == 0) | 425 | if (i < EOK) { |
426 | printf("Error!"); | ||
427 | printf("Can't load rockbox.ipod:"); | ||
428 | printf(strerror(rc)); | ||
429 | sleep(HZ*3); | ||
430 | power_off(); | ||
431 | } else { | ||
523 | start_firmware(); | 432 | start_firmware(); |
524 | 433 | } | |
525 | power_off(); | ||
526 | 434 | ||
527 | #else | 435 | #else |
436 | extern int line; | ||
528 | /* We want to read the buttons as early as possible, before the user | 437 | /* We want to read the buttons as early as possible, before the user |
529 | releases the ON button */ | 438 | releases the ON button */ |
530 | 439 | ||
@@ -721,15 +630,16 @@ void main(void) | |||
721 | } | 630 | } |
722 | 631 | ||
723 | printf("Loading firmware"); | 632 | printf("Loading firmware"); |
724 | i = load_firmware(); | 633 | i = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE); |
725 | printf("Result: %d", i); | 634 | printf("Result: %d", strerror(i)); |
726 | 635 | ||
727 | if (i == 0) | 636 | if (i == EOK) |
728 | start_firmware(); | 637 | start_firmware(); |
729 | 638 | ||
730 | if (!detect_original_firmware()) | 639 | if (!detect_original_firmware()) |
731 | { | 640 | { |
732 | printf("No firmware found on disk"); | 641 | printf("No firmware found on disk"); |
642 | sleep(HZ*2); | ||
733 | shutdown(); | 643 | shutdown(); |
734 | } | 644 | } |
735 | else | 645 | else |
@@ -739,24 +649,6 @@ void main(void) | |||
739 | 649 | ||
740 | /* These functions are present in the firmware library, but we reimplement | 650 | /* These functions are present in the firmware library, but we reimplement |
741 | them here because the originals do a lot more than we want */ | 651 | them here because the originals do a lot more than we want */ |
742 | |||
743 | void reset_poweroff_timer(void) | ||
744 | { | ||
745 | } | ||
746 | |||
747 | void screen_dump(void) | 652 | void screen_dump(void) |
748 | { | 653 | { |
749 | } | 654 | } |
750 | |||
751 | int dbg_ports(void) | ||
752 | { | ||
753 | return 0; | ||
754 | } | ||
755 | |||
756 | void mpeg_stop(void) | ||
757 | { | ||
758 | } | ||
759 | |||
760 | void sys_poweroff(void) | ||
761 | { | ||
762 | } | ||