diff options
Diffstat (limited to 'bootloader/gigabeat.c')
-rw-r--r-- | bootloader/gigabeat.c | 148 |
1 files changed, 42 insertions, 106 deletions
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c index a466f9498f..f9073028fb 100644 --- a/bootloader/gigabeat.c +++ b/bootloader/gigabeat.c | |||
@@ -18,11 +18,10 @@ | |||
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 "common.h" | ||
21 | 22 | ||
22 | extern void map_memory(void); | 23 | extern void map_memory(void); |
23 | 24 | ||
24 | int line = 0; | ||
25 | |||
26 | char version[] = APPSVERSION; | 25 | char version[] = APPSVERSION; |
27 | 26 | ||
28 | static void go_usb_mode(void) | 27 | static void go_usb_mode(void) |
@@ -55,30 +54,25 @@ int restore_fwimg01dat(void) | |||
55 | int orig_file = 0, dest_file = 0; | 54 | int orig_file = 0, dest_file = 0; |
56 | int size = 0, size_read; | 55 | int size = 0, size_read; |
57 | static char buf[4096]; | 56 | static char buf[4096]; |
58 | char lcd_buf[64]; | 57 | |
59 | |||
60 | orig_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT.ORIG", O_RDONLY); | 58 | orig_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT.ORIG", O_RDONLY); |
61 | if(orig_file < 0) { | 59 | if(orig_file < 0) { |
62 | /* Couldn't open source file */ | 60 | /* Couldn't open source file */ |
63 | lcd_puts(0, line++, "Couldn't open FWIMG01.DAT.ORIG for reading"); | 61 | printf("Couldn't open FWIMG01.DAT.ORIG for reading"); |
64 | lcd_update(); | ||
65 | return(1); | 62 | return(1); |
66 | } | 63 | } |
67 | 64 | ||
68 | lcd_puts(0, line++, "FWIMG01.DAT.ORIG opened for reading"); | 65 | printf("FWIMG01.DAT.ORIG opened for reading"); |
69 | lcd_update(); | ||
70 | 66 | ||
71 | dest_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT", O_RDWR); | 67 | dest_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT", O_RDWR); |
72 | if(dest_file < 0) { | 68 | if(dest_file < 0) { |
73 | /* Couldn't open destination file */ | 69 | /* Couldn't open destination file */ |
74 | lcd_puts(0, line++, "Couldn't open FWIMG01.DAT.ORIG for writing"); | 70 | printf("Couldn't open FWIMG01.DAT.ORIG for writing"); |
75 | lcd_update(); | ||
76 | close(orig_file); | 71 | close(orig_file); |
77 | return(2); | 72 | return(2); |
78 | } | 73 | } |
79 | 74 | ||
80 | lcd_puts(0, line++, "FWIMG01.DAT opened for writing"); | 75 | printf("FWIMG01.DAT opened for writing"); |
81 | lcd_update(); | ||
82 | 76 | ||
83 | do { | 77 | do { |
84 | /* Copy in chunks */ | 78 | /* Copy in chunks */ |
@@ -95,65 +89,22 @@ int restore_fwimg01dat(void) | |||
95 | close(orig_file); | 89 | close(orig_file); |
96 | close(dest_file); | 90 | close(dest_file); |
97 | 91 | ||
98 | snprintf(lcd_buf, sizeof(lcd_buf), "Finished copying %ld bytes from", size); | 92 | printf("Finished copying %ld bytes from", size); |
99 | lcd_puts(0, line++, lcd_buf); | 93 | printf("FWIMG01.DAT.ORIG to FWIMG01.DAT"); |
100 | lcd_puts(0, line++, "FWIMG01.DAT.ORIG to FWIMG01.DAT"); | ||
101 | 94 | ||
102 | return(0); | 95 | return(0); |
103 | } | 96 | } |
104 | 97 | ||
105 | |||
106 | int load_rockbox(const char* file_name, unsigned char* buf, int buffer_size) | ||
107 | { | ||
108 | int fd; | ||
109 | int rc; | ||
110 | int len; | ||
111 | char str[256]; | ||
112 | |||
113 | fd = open("/.rockbox/" BOOTFILE, O_RDONLY); | ||
114 | if(fd < 0) { | ||
115 | fd = open("/" BOOTFILE, O_RDONLY); | ||
116 | if(fd < 0) | ||
117 | return -1; | ||
118 | } | ||
119 | fd = open(file_name, O_RDONLY); | ||
120 | if(fd < 0) | ||
121 | return -2; | ||
122 | |||
123 | len = filesize(fd); | ||
124 | |||
125 | if(len > buffer_size) { | ||
126 | snprintf(str, sizeof(str), "len: %d buf: %d", len, buffer_size); | ||
127 | lcd_puts(0, line++, str); | ||
128 | lcd_update(); | ||
129 | return -6; | ||
130 | } | ||
131 | |||
132 | rc = read(fd, buf, len); | ||
133 | if(rc < len) { | ||
134 | snprintf(str, sizeof(str), "len: %d rc: %d", len, rc); | ||
135 | lcd_puts(0, line++, str); | ||
136 | lcd_update(); | ||
137 | return -4; | ||
138 | } | ||
139 | |||
140 | close(fd); | ||
141 | |||
142 | return len; | ||
143 | } | ||
144 | |||
145 | char buf[256]; | 98 | char buf[256]; |
146 | 99 | ||
147 | void display_instructions(void) | 100 | void display_instructions(void) |
148 | { | 101 | { |
149 | lcd_setfont(FONT_SYSFIXED); | 102 | lcd_setfont(FONT_SYSFIXED); |
150 | lcd_puts(0, line++, "Hold MENU when booting for rescue mode."); | 103 | printf("Hold MENU when booting for rescue mode."); |
151 | lcd_puts(0, line++, " \"VOL+\" button to restore original kernel"); | 104 | printf(" \"VOL+\" button to restore original kernel"); |
152 | lcd_puts(0, line++, " \"A\" button to load original firmware"); | 105 | printf(" \"A\" button to load original firmware"); |
153 | line++; | 106 | printf(""); |
154 | snprintf(buf, sizeof(buf), "FRAME %x TTB %x", FRAME, TTB_BASE); | 107 | printf("FRAME %x TTB %x", FRAME, TTB_BASE); |
155 | lcd_puts(0, line++, buf); | ||
156 | lcd_update(); | ||
157 | } | 108 | } |
158 | 109 | ||
159 | void * main(void) | 110 | void * main(void) |
@@ -179,23 +130,20 @@ void * main(void) | |||
179 | } | 130 | } |
180 | if(GPGDAT & 2) { | 131 | if(GPGDAT & 2) { |
181 | lcd_init(); | 132 | lcd_init(); |
182 | lcd_puts(0, line++, "Entering rescue mode.."); | 133 | printf("Entering rescue mode.."); |
183 | lcd_update(); | ||
184 | go_usb_mode(); | 134 | go_usb_mode(); |
185 | while(1); | 135 | while(1); |
186 | } | 136 | } |
187 | if(GPGDAT & 0x10) { | 137 | if(GPGDAT & 0x10) { |
188 | lcd_init(); | 138 | lcd_init(); |
189 | load_original = true; | 139 | load_original = true; |
190 | lcd_puts(0, line++, "Loading original firmware..."); | 140 | printf("Loading original firmware..."); |
191 | lcd_update(); | ||
192 | } | 141 | } |
193 | 142 | ||
194 | i = ata_init(); | 143 | i = ata_init(); |
195 | i = disk_mount_all(); | 144 | i = disk_mount_all(); |
196 | if(!show_bootsplash) { | 145 | if(!show_bootsplash) { |
197 | snprintf(buf, sizeof(buf), "disk_mount_all: %d", i); | 146 | printf("disk_mount_all: %d", i); |
198 | lcd_puts(0, line++, buf); | ||
199 | } | 147 | } |
200 | if(show_bootsplash) { | 148 | if(show_bootsplash) { |
201 | int fd = open("/bootsplash.raw", O_RDONLY); | 149 | int fd = open("/bootsplash.raw", O_RDONLY); |
@@ -216,17 +164,15 @@ void * main(void) | |||
216 | if(GPGDAT & 4) { | 164 | if(GPGDAT & 4) { |
217 | 165 | ||
218 | /* Try to restore the original kernel/bootloader if a copy is found */ | 166 | /* Try to restore the original kernel/bootloader if a copy is found */ |
219 | lcd_puts(0, line++, "Restoring FWIMG01.DAT..."); | 167 | printf("Restoring FWIMG01.DAT..."); |
220 | lcd_update(); | ||
221 | 168 | ||
222 | if(!restore_fwimg01dat()) { | 169 | if(!restore_fwimg01dat()) { |
223 | lcd_puts(0, line++, "Restoring FWIMG01.DAT successful."); | 170 | printf("Restoring FWIMG01.DAT successful."); |
224 | } else { | 171 | } else { |
225 | lcd_puts(0, line++, "Restoring FWIMG01.DAT failed."); | 172 | printf("Restoring FWIMG01.DAT failed."); |
226 | } | 173 | } |
227 | 174 | ||
228 | lcd_puts(0, line++, "Now power cycle to boot original"); | 175 | printf("Now power cycle to boot original"); |
229 | lcd_update(); | ||
230 | while(1); | 176 | while(1); |
231 | } | 177 | } |
232 | 178 | ||
@@ -242,76 +188,66 @@ void * main(void) | |||
242 | for(i=39; i && buf[i]==' '; i--) | 188 | for(i=39; i && buf[i]==' '; i--) |
243 | buf[i] = 0; | 189 | buf[i] = 0; |
244 | 190 | ||
245 | lcd_puts(0, line++, "Model"); | 191 | printf("Model"); |
246 | lcd_puts(0, line++, buf); | 192 | printf(buf); |
247 | 193 | ||
248 | for(i=0; i < 4; i++) | 194 | for(i=0; i < 4; i++) |
249 | ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]); | 195 | ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]); |
250 | 196 | ||
251 | buf[8]=0; | 197 | buf[8]=0; |
252 | 198 | ||
253 | lcd_puts(0, line++, "Firmware"); | 199 | printf("Firmware"); |
254 | lcd_puts(0, line++, buf); | 200 | printf(buf); |
255 | 201 | ||
256 | pinfo = disk_partinfo(0); | 202 | pinfo = disk_partinfo(0); |
257 | snprintf(buf, sizeof(buf), "Partition 0: 0x%02x %ld MB", | 203 | printf("Partition 0: 0x%02x %ld MB", pinfo->type, pinfo->size / 2048); |
258 | pinfo->type, pinfo->size / 2048); | ||
259 | lcd_puts(0, line++, buf); | ||
260 | lcd_update(); | ||
261 | } | 204 | } |
262 | /* Load original firmware */ | 205 | /* Load original firmware */ |
263 | if(load_original) { | 206 | if(load_original) { |
264 | loadbuffer = (unsigned char*)0x30008000; | 207 | loadbuffer = (unsigned char*)0x30008000; |
265 | buffer_size =(unsigned char*)0x31000000 - loadbuffer; | 208 | buffer_size =(unsigned char*)0x31000000 - loadbuffer; |
266 | rc = load_rockbox("/rockbox.gigabeat", loadbuffer, buffer_size); | 209 | rc = load_firmware("rockbox.gigabeat", loadbuffer, buffer_size); |
267 | if(rc < 0) { | 210 | if(rc < EOK) { |
268 | lcd_puts(0, line++, "failed to load original firmware. Loading rockbox"); | 211 | printf("Error!"); |
269 | lcd_update(); | 212 | printf("Failed to load original firmware:"); |
213 | printf(strerror(rc)); | ||
214 | printf("Loading rockbox"); | ||
270 | sleep(2*HZ); | 215 | sleep(2*HZ); |
271 | goto load_rockbox; | 216 | goto load_rockbox; |
272 | } | 217 | } |
273 | 218 | ||
274 | snprintf(buf, sizeof(buf), "Loaded: %d", rc); | 219 | printf("Loaded: %d", rc); |
275 | lcd_puts(0, line++, buf); | ||
276 | lcd_update(); | ||
277 | sleep(2*HZ); | 220 | sleep(2*HZ); |
278 | 221 | ||
279 | (*((int*)0x7000000)) = 333; | 222 | (*((int*)0x7000000)) = 333; |
280 | rc = *((int*)0x7000000+0x8000000); | 223 | rc = *((int*)0x7000000+0x8000000); |
281 | snprintf(buf, sizeof(buf), "Bank0 mem test: %d", rc); | 224 | printf("Bank0 mem test: %d", rc); |
282 | lcd_puts(0, line++, buf); | ||
283 | lcd_update(); | ||
284 | sleep(3*HZ); | 225 | sleep(3*HZ); |
285 | 226 | ||
286 | lcd_puts(0, line++, "Woops, should not return from firmware!"); | 227 | printf("Woops, should not return from firmware!"); |
287 | lcd_update(); | ||
288 | goto usb; | 228 | goto usb; |
289 | } | 229 | } |
290 | 230 | ||
291 | load_rockbox: | 231 | load_rockbox: |
292 | map_memory(); | 232 | map_memory(); |
293 | if(!show_bootsplash) { | 233 | if(!show_bootsplash) { |
294 | lcd_puts(0, line, "Loading Rockbox..."); | 234 | printf("Loading Rockbox..."); |
295 | lcd_update(); | ||
296 | } | 235 | } |
297 | 236 | ||
298 | loadbuffer = (unsigned char*) 0x100; | 237 | loadbuffer = (unsigned char*) 0x100; |
299 | buffer_size = (unsigned char*)0x400000 - loadbuffer; | 238 | buffer_size = (unsigned char*)0x400000 - loadbuffer; |
300 | rc=load_rockbox("/rockbox.gigabeat", loadbuffer, buffer_size); | 239 | rc=load_firmware("rockbox.gigabeat", loadbuffer, buffer_size); |
301 | if(rc < 0) { | 240 | if(rc < EOK) { |
302 | snprintf(buf, sizeof(buf), "Rockbox error: %d",rc); | 241 | printf("Error!"); |
303 | lcd_puts(0, line++, buf); | 242 | printf("Can't load rockbox.gigabeat:"); |
304 | lcd_update(); | 243 | printf(strerror(rc)); |
305 | } else { | 244 | } else { |
306 | if(!show_bootsplash) { | 245 | if(!show_bootsplash) { |
307 | lcd_puts(0, line++, "Rockbox loaded."); | 246 | printf("Rockbox loaded."); |
308 | lcd_update(); | ||
309 | } | 247 | } |
310 | kernel_entry = (void*) loadbuffer; | 248 | kernel_entry = (void*) loadbuffer; |
311 | rc = kernel_entry(); | 249 | rc = kernel_entry(); |
312 | snprintf(buf, sizeof(buf), "Woops, should not return from firmware: %d", rc); | 250 | printf("Woops, should not return from firmware: %d", rc); |
313 | lcd_puts(0, line++, buf); | ||
314 | lcd_update(); | ||
315 | goto usb; | 251 | goto usb; |
316 | } | 252 | } |
317 | usb: | 253 | usb: |