summaryrefslogtreecommitdiff
path: root/bootloader
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader')
-rw-r--r--bootloader/main.c129
1 files changed, 101 insertions, 28 deletions
diff --git a/bootloader/main.c b/bootloader/main.c
index 69993e4fe6..8d4c1e27aa 100644
--- a/bootloader/main.c
+++ b/bootloader/main.c
@@ -37,6 +37,10 @@
37#include "file.h" 37#include "file.h"
38#include "uda1380.h" 38#include "uda1380.h"
39 39
40#include "pcf50606.h"
41
42#include <stdarg.h>
43
40#define DRAM_START 0x31000000 44#define DRAM_START 0x31000000
41 45
42int line = 0; 46int line = 0;
@@ -48,6 +52,25 @@ int usb_screen(void)
48 52
49char version[] = APPSVERSION; 53char version[] = APPSVERSION;
50 54
55char printfbuf[256];
56
57void printf(const char *format, ...)
58{
59 int len;
60 unsigned char *ptr;
61 va_list ap;
62 va_start(ap, format);
63
64 ptr = printfbuf;
65 len = vsnprintf(ptr, sizeof(printfbuf), format, ap);
66 va_end(ap);
67
68 lcd_puts(0, line++, ptr);
69 lcd_update();
70 if(line >= 16)
71 line = 0;
72}
73
51void start_iriver_fw(void) 74void start_iriver_fw(void)
52{ 75{
53 asm(" move.w #0x2700,%sr"); 76 asm(" move.w #0x2700,%sr");
@@ -70,7 +93,6 @@ int load_firmware(void)
70 unsigned long sum; 93 unsigned long sum;
71 int i; 94 int i;
72 unsigned char *buf = (unsigned char *)DRAM_START; 95 unsigned char *buf = (unsigned char *)DRAM_START;
73 char str[80];
74 96
75 fd = open("/.rockbox/" BOOTFILE, O_RDONLY); 97 fd = open("/.rockbox/" BOOTFILE, O_RDONLY);
76 if(fd < 0) 98 if(fd < 0)
@@ -82,8 +104,7 @@ int load_firmware(void)
82 104
83 len = filesize(fd) - 8; 105 len = filesize(fd) - 8;
84 106
85 snprintf(str, 80, "Length: %x", len); 107 printf("Length: %x", len);
86 lcd_puts(0, line++, str);
87 lcd_update(); 108 lcd_update();
88 109
89 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); 110 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
@@ -92,8 +113,7 @@ int load_firmware(void)
92 if(rc < 4) 113 if(rc < 4)
93 return -2; 114 return -2;
94 115
95 snprintf(str, 80, "Checksum: %x", chksum); 116 printf("Checksum: %x", chksum);
96 lcd_puts(0, line++, str);
97 lcd_update(); 117 lcd_update();
98 118
99 rc = read(fd, model, 4); 119 rc = read(fd, model, 4);
@@ -102,8 +122,7 @@ int load_firmware(void)
102 122
103 model[4] = 0; 123 model[4] = 0;
104 124
105 snprintf(str, 80, "Model name: %s", model); 125 printf("Model name: %s", model);
106 lcd_puts(0, line++, str);
107 lcd_update(); 126 lcd_update();
108 127
109 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); 128 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
@@ -120,8 +139,7 @@ int load_firmware(void)
120 sum += buf[i]; 139 sum += buf[i];
121 } 140 }
122 141
123 snprintf(str, 80, "Sum: %x", sum); 142 printf("Sum: %x", sum);
124 lcd_puts(0, line++, str);
125 lcd_update(); 143 lcd_update();
126 144
127 if(sum != chksum) 145 if(sum != chksum)
@@ -148,12 +166,71 @@ void main(void)
148{ 166{
149 int i; 167 int i;
150 int rc; 168 int rc;
151 char buf[256];
152 bool rc_on_button = false; 169 bool rc_on_button = false;
153 bool on_button = false; 170 bool on_button = false;
154 int data; 171 int data;
155 int adc_battery, battery_voltage, batt_int, batt_frac; 172 int adc_battery, battery_voltage, batt_int, batt_frac;
156 173
174#ifdef IAUDIO_X5
175 (void)rc_on_button;
176 (void)on_button;
177 (void)data;
178 power_init();
179
180 system_init();
181 kernel_init();
182
183 set_cpu_frequency(CPUFREQ_NORMAL);
184
185 set_irq_level(0);
186 lcd_init();
187 font_init();
188 adc_init();
189 button_init();
190
191 printf("Rockbox boot loader");
192 printf("Version %s", version);
193 lcd_update();
194
195 adc_battery = adc_read(ADC_BATTERY);
196
197 battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000;
198 batt_int = battery_voltage / 100;
199 batt_frac = battery_voltage % 100;
200
201 printf("Batt: %d.%02dV", batt_int, batt_frac);
202 lcd_update();
203
204 rc = ata_init();
205 if(rc)
206 {
207 printf("ATA error: %d", rc);
208 sleep(HZ*5);
209 power_off();
210 }
211
212 disk_init();
213
214 rc = disk_mount_all();
215 if (rc<=0)
216 {
217 printf("No partition found");
218 sleep(HZ*5);
219 power_off();
220 }
221
222 printf("Loading firmware");
223 lcd_update();
224 i = load_firmware();
225 printf("Result: %d", i);
226 lcd_update();
227
228 if(i == 0)
229 start_firmware();
230
231 power_off();
232
233#else
157 /* We want to read the buttons as early as possible, before the user 234 /* We want to read the buttons as early as possible, before the user
158 releases the ON button */ 235 releases the ON button */
159 236
@@ -225,9 +302,8 @@ void main(void)
225 302
226 lcd_setfont(FONT_SYSFIXED); 303 lcd_setfont(FONT_SYSFIXED);
227 304
228 lcd_puts(0, line++, "Rockbox boot loader"); 305 printf("Rockbox boot loader");
229 snprintf(buf, sizeof(buf), "Version %s", version); 306 printf("Version %s", version);
230 lcd_puts(0, line++, buf);
231 lcd_update(); 307 lcd_update();
232 308
233 sleep(HZ/50); /* Allow the button driver to check the buttons */ 309 sleep(HZ/50); /* Allow the button driver to check the buttons */
@@ -235,7 +311,7 @@ void main(void)
235 /* Holding REC while starting runs the original firmware */ 311 /* Holding REC while starting runs the original firmware */
236 if(((button_status() & BUTTON_REC) == BUTTON_REC) || 312 if(((button_status() & BUTTON_REC) == BUTTON_REC) ||
237 ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC)) { 313 ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC)) {
238 lcd_puts(0, 8, "Starting original firmware..."); 314 printf("Starting original firmware...");
239 lcd_update(); 315 lcd_update();
240 start_iriver_fw(); 316 start_iriver_fw();
241 } 317 }
@@ -244,7 +320,7 @@ void main(void)
244 are starting with */ 320 are starting with */
245 if(!usb_detect() && ((on_button && button_hold()) || 321 if(!usb_detect() && ((on_button && button_hold()) ||
246 (rc_on_button && remote_button_hold()))) { 322 (rc_on_button && remote_button_hold()))) {
247 lcd_puts(0, 8, "HOLD switch on, power off..."); 323 printf("HOLD switch on, power off...");
248 lcd_update(); 324 lcd_update();
249 sleep(HZ*2); 325 sleep(HZ*2);
250 326
@@ -270,13 +346,11 @@ void main(void)
270 batt_int = battery_voltage / 100; 346 batt_int = battery_voltage / 100;
271 batt_frac = battery_voltage % 100; 347 batt_frac = battery_voltage % 100;
272 348
273 snprintf(buf, 32, "Batt: %d.%02dV", batt_int, batt_frac); 349 printf("Batt: %d.%02dV", batt_int, batt_frac);
274 lcd_puts(0, line++, buf);
275 lcd_update(); 350 lcd_update();
276 351
277 if(battery_voltage <= 300) { 352 if(battery_voltage <= 300) {
278 line++; 353 printf("WARNING! BATTERY LOW!!");
279 lcd_puts(0, line++, "WARNING! BATTERY LOW!!");
280 lcd_update(); 354 lcd_update();
281 sleep(HZ*2); 355 sleep(HZ*2);
282 } 356 }
@@ -284,12 +358,10 @@ void main(void)
284 rc = ata_init(); 358 rc = ata_init();
285 if(rc) 359 if(rc)
286 { 360 {
287 char str[32];
288 lcd_clear_display(); 361 lcd_clear_display();
289 snprintf(str, 31, "ATA error: %d", rc); 362 printf("ATA error: %d", rc);
290 lcd_puts(0, line++, str); 363 printf("Insert USB cable and press");
291 lcd_puts(0, line++, "Insert USB cable and press"); 364 printf("a button");
292 lcd_puts(0, line++, "a button");
293 lcd_update(); 365 lcd_update();
294 while(!(button_get(true) & BUTTON_REL)); 366 while(!(button_get(true) & BUTTON_REL));
295 } 367 }
@@ -336,21 +408,22 @@ void main(void)
336 if (rc<=0) 408 if (rc<=0)
337 { 409 {
338 lcd_clear_display(); 410 lcd_clear_display();
339 lcd_puts(0, 0, "No partition found"); 411 printf("No partition found");
412 lcd_update();
340 while(button_get(true) != SYS_USB_CONNECTED) {}; 413 while(button_get(true) != SYS_USB_CONNECTED) {};
341 } 414 }
342 415
343 lcd_puts(0, line++, "Loading firmware"); 416 printf("Loading firmware");
344 lcd_update(); 417 lcd_update();
345 i = load_firmware(); 418 i = load_firmware();
346 snprintf(buf, 256, "Result: %d", i); 419 printf("Result: %d", i);
347 lcd_puts(0, line++, buf);
348 lcd_update(); 420 lcd_update();
349 421
350 if(i == 0) 422 if(i == 0)
351 start_firmware(); 423 start_firmware();
352 424
353 start_iriver_fw(); 425 start_iriver_fw();
426#endif /* IAUDIO_X5 */
354} 427}
355 428
356/* These functions are present in the firmware library, but we reimplement 429/* These functions are present in the firmware library, but we reimplement