blob: 77866573e900a2b31b371943ddb901cde7898ed3 [file] [log] [blame]
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20
21#include <stdlib.h>
22#include <stdio.h>
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +000023#include "inttypes.h"
24#include "string.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000025#include "cpu.h"
26#include "system.h"
27#include "lcd.h"
28#include "kernel.h"
29#include "thread.h"
30#include "ata.h"
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +000031#include "usb.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000032#include "disk.h"
33#include "font.h"
34#include "adc.h"
35#include "backlight.h"
Rani Hod78f425d2006-07-29 13:31:43 +000036#ifdef IAUDIO_X5
37#include "backlight-target.h"
38#endif
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000039#include "button.h"
40#include "panic.h"
41#include "power.h"
42#include "file.h"
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +000043#include "uda1380.h"
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +000044#include "eeprom_settings.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000045
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +000046#include "pcf50606.h"
47
48#include <stdarg.h>
49
Linus Nielsen Feltzing62c768c2005-07-09 07:46:42 +000050#define DRAM_START 0x31000000
51
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000052int line = 0;
53
54int usb_screen(void)
55{
56 return 0;
57}
58
Linus Nielsen Feltzinga2e8cf72005-07-15 07:42:25 +000059char version[] = APPSVERSION;
60
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +000061char printfbuf[256];
62
63void printf(const char *format, ...)
64{
65 int len;
66 unsigned char *ptr;
67 va_list ap;
68 va_start(ap, format);
69
70 ptr = printfbuf;
71 len = vsnprintf(ptr, sizeof(printfbuf), format, ap);
72 va_end(ap);
73
74 lcd_puts(0, line++, ptr);
75 lcd_update();
76 if(line >= 16)
77 line = 0;
78}
79
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000080void start_iriver_fw(void)
81{
82 asm(" move.w #0x2700,%sr");
Linus Nielsen Feltzingf1530d82005-02-04 18:24:58 +000083 /* Reset the cookie for the crt0 crash check */
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000084 asm(" move.l #0,%d0");
Linus Nielsen Feltzingf1530d82005-02-04 18:24:58 +000085 asm(" move.l %d0,0x10017ffc");
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000086 asm(" movec.l %d0,%vbr");
87 asm(" move.l 0,%sp");
88 asm(" lea.l 8,%a0");
89 asm(" jmp (%a0)");
90}
91
92int load_firmware(void)
93{
94 int fd;
95 int rc;
96 int len;
97 unsigned long chksum;
Linus Nielsen Feltzinga75f0e52005-07-09 09:04:37 +000098 char model[5];
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000099 unsigned long sum;
100 int i;
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000101 unsigned char *buf = (unsigned char *)DRAM_START;
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000102
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000103 fd = open("/.rockbox/" BOOTFILE, O_RDONLY);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000104 if(fd < 0)
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000105 {
106 fd = open("/" BOOTFILE, O_RDONLY);
107 if(fd < 0)
108 return -1;
109 }
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000110
Linus Nielsen Feltzingb8a00d22005-02-10 21:55:48 +0000111 len = filesize(fd) - 8;
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000112
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000113 printf("Length: %x", len);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000114 lcd_update();
115
Linus Nielsen Feltzing2a77d3a2005-01-28 13:27:58 +0000116 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000117
118 rc = read(fd, &chksum, 4);
119 if(rc < 4)
120 return -2;
121
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000122 printf("Checksum: %x", chksum);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000123 lcd_update();
124
Linus Nielsen Feltzinga75f0e52005-07-09 09:04:37 +0000125 rc = read(fd, model, 4);
126 if(rc < 4)
127 return -3;
128
129 model[4] = 0;
130
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000131 printf("Model name: %s", model);
Linus Nielsen Feltzinga75f0e52005-07-09 09:04:37 +0000132 lcd_update();
133
Linus Nielsen Feltzing2a77d3a2005-01-28 13:27:58 +0000134 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000135
136 rc = read(fd, buf, len);
137 if(rc < len)
138 return -4;
139
140 close(fd);
141
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000142 sum = MODEL_NUMBER;
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000143
144 for(i = 0;i < len;i++) {
145 sum += buf[i];
146 }
147
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000148 printf("Sum: %x", sum);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000149 lcd_update();
150
151 if(sum != chksum)
152 return -5;
153
154 return 0;
155}
156
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000157int load_flashed_rockbox(void)
158{
159 struct flash_header hdr;
160 unsigned char *buf = (unsigned char *)DRAM_START;
161 uint8_t *src = (uint8_t *)FLASH_ENTRYPOINT;
162
163 cpu_boost(true);
164 memcpy(&hdr, src, sizeof(struct flash_header));
165 src += sizeof(struct flash_header);
166 memcpy(buf, src, hdr.length);
167 cpu_boost(false);
168
169 return 0;
170}
171
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000172
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000173void start_firmware(void)
174{
175 asm(" move.w #0x2700,%sr");
Linus Nielsen Feltzingf1530d82005-02-04 18:24:58 +0000176 /* Reset the cookie for the crt0 crash check */
177 asm(" move.l #0,%d0");
178 asm(" move.l %d0,0x10017ffc");
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000179 asm(" move.l %0,%%d0" :: "i"(DRAM_START));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000180 asm(" movec.l %d0,%vbr");
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000181 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START));
182 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4)));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000183 asm(" jmp (%a0)");
184}
185
Linus Nielsen Feltzingb8a00d22005-02-10 21:55:48 +0000186void main(void)
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000187{
188 int i;
189 int rc;
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000190 bool rc_on_button = false;
191 bool on_button = false;
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000192 bool rec_button = false;
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000193 int data;
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000194 int adc_battery, battery_voltage, batt_int, batt_frac;
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000195
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000196#ifdef IAUDIO_X5
197 (void)rc_on_button;
198 (void)on_button;
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000199 (void)rec_button;
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000200 (void)data;
201 power_init();
202
203 system_init();
204 kernel_init();
205
206 set_cpu_frequency(CPUFREQ_NORMAL);
207
208 set_irq_level(0);
209 lcd_init();
Rani Hod78f425d2006-07-29 13:31:43 +0000210 __backlight_on();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000211 font_init();
212 adc_init();
213 button_init();
214
215 printf("Rockbox boot loader");
216 printf("Version %s", version);
217 lcd_update();
218
219 adc_battery = adc_read(ADC_BATTERY);
220
221 battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000;
222 batt_int = battery_voltage / 100;
223 batt_frac = battery_voltage % 100;
224
225 printf("Batt: %d.%02dV", batt_int, batt_frac);
226 lcd_update();
227
228 rc = ata_init();
229 if(rc)
230 {
231 printf("ATA error: %d", rc);
232 sleep(HZ*5);
233 power_off();
234 }
235
236 disk_init();
237
238 rc = disk_mount_all();
239 if (rc<=0)
240 {
241 printf("No partition found");
242 sleep(HZ*5);
243 power_off();
244 }
245
246 printf("Loading firmware");
247 lcd_update();
248 i = load_firmware();
249 printf("Result: %d", i);
250 lcd_update();
251
252 if(i == 0)
253 start_firmware();
254
255 power_off();
256
257#else
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000258 /* We want to read the buttons as early as possible, before the user
259 releases the ON button */
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000260
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000261 /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs
262 (The ON and Hold buttons on the main unit and the remote) */
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +0000263 or_l(0x00100062, &GPIO1_FUNCTION);
264 and_l(~0x00100062, &GPIO1_ENABLE);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000265
266 data = GPIO1_READ;
267 if ((data & 0x20) == 0)
268 on_button = true;
269
270 if ((data & 0x40) == 0)
271 rc_on_button = true;
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000272
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000273 /* Set the default state of the hard drive power to OFF */
274 ide_power_enable(false);
275
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000276 power_init();
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000277
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000278 /* Turn off if neither ON button is pressed */
Linus Nielsen Feltzing54da9242006-01-10 23:11:57 +0000279 if(!(on_button || rc_on_button || usb_detect()))
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000280 power_off();
281
282 /* Backlight ON */
283 or_l(0x00020000, &GPIO1_ENABLE);
284 or_l(0x00020000, &GPIO1_FUNCTION);
285 and_l(~0x00020000, &GPIO1_OUT);
286
287 /* Remote backlight ON */
288#ifdef HAVE_REMOTE_LCD
289#ifdef IRIVER_H300_SERIES
290 or_l(0x00000002, &GPIO1_ENABLE);
291 and_l(~0x00000002, &GPIO1_OUT);
292#else
293 or_l(0x00000800, &GPIO_ENABLE);
294 or_l(0x00000800, &GPIO_FUNCTION);
295 and_l(~0x00000800, &GPIO_OUT);
296#endif
297#endif
298
Linus Nielsen Feltzingb68cb9b2005-12-03 00:54:59 +0000299 /* Power on the hard drive early, to speed up the loading.
300 Some H300 don't like this, so we only do it for the H100 */
301#ifndef IRIVER_H300_SERIES
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000302 if(!((on_button && button_hold()) ||
303 (rc_on_button && remote_button_hold()))) {
304 ide_power_enable(true);
305 }
Linus Nielsen Feltzingb68cb9b2005-12-03 00:54:59 +0000306#endif
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000307
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000308 system_init();
309 kernel_init();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000310
311#ifdef HAVE_ADJUSTABLE_CPU_FREQ
312 /* Set up waitstates for the peripherals */
313 set_cpu_frequency(0); /* PLL off */
314#endif
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +0000315
Linus Nielsen Feltzing2fcd1b02006-02-04 23:09:56 +0000316#ifdef HAVE_UDA1380
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +0000317 uda1380_reset();
Linus Nielsen Feltzing2fcd1b02006-02-04 23:09:56 +0000318#endif
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000319
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000320 backlight_init();
321 set_irq_level(0);
322 lcd_init();
323 font_init();
324 adc_init();
325 button_init();
326
327 lcd_setfont(FONT_SYSFIXED);
328
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000329 printf("Rockbox boot loader");
330 printf("Version %s", version);
Linus Nielsen Feltzingd1af08f2005-07-09 19:48:22 +0000331 lcd_update();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000332
Linus Nielsen Feltzingb8a00d22005-02-10 21:55:48 +0000333 sleep(HZ/50); /* Allow the button driver to check the buttons */
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000334 rec_button = ((button_status() & BUTTON_REC) == BUTTON_REC)
335 || ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC);
336
Miika Pekkarinen22860a92006-08-11 19:59:16 +0000337 /* Don't start if the Hold button is active on the device you
338 are starting with */
339 if (!usb_detect() && ((on_button && button_hold()) ||
340 (rc_on_button && remote_button_hold())))
341 {
342 printf("HOLD switch on, power off...");
343 lcd_update();
344 sleep(HZ*2);
345
346 /* Backlight OFF */
347#ifdef HAVE_REMOTE_LCD
348#ifdef IRIVER_H300_SERIES
349 or_l(0x00000002, &GPIO1_OUT);
350#else
351 or_l(0x00000800, &GPIO_OUT);
352#endif
353#endif
354 /* Reset the cookie for the crt0 crash check */
355 asm(" move.l #0,%d0");
356 asm(" move.l %d0,0x10017ffc");
357 power_off();
358 }
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000359
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000360#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000361 firmware_settings.initialized = false;
362#endif
363 if (detect_flashed_rockbox())
364 {
365 bool load_from_flash;
366
367 load_from_flash = !rec_button;
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000368#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000369 if (eeprom_settings_init())
370 {
371 /* If bootloader version has not been reset, disk might
372 * not be intact. */
373 if (firmware_settings.bl_version)
374 firmware_settings.disk_clean = false;
375
376 firmware_settings.bl_version = 7;
377 /* Invert the record button if we want to load from disk
378 * by default. */
379 if (firmware_settings.boot_disk)
380 load_from_flash = rec_button;
381 }
382#endif
383
384 if (load_from_flash)
385 {
386 /* Load firmware from flash */
387 i = load_flashed_rockbox();
388 printf("Result: %d", i);
389 lcd_update();
390 if (i == 0)
391 {
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000392#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000393 eeprom_settings_store();
394#endif
395 start_firmware();
396 printf("Fatal: Corrupted firmware");
397 printf("Hold down REC on next boot");
398 lcd_update();
399 sleep(HZ*2);
400 power_off();
401 }
402 }
403
404 printf("Loading from disk...");
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000405 lcd_update();
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000406 }
407 else
408 {
409 /* Holding REC while starting runs the original firmware */
410 if (rec_button)
411 {
412 printf("Starting original firmware...");
413 lcd_update();
414 start_iriver_fw();
415 }
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000416 }
417
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000418 usb_init();
419
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000420 adc_battery = adc_read(ADC_BATTERY);
421
422 battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000;
423 batt_int = battery_voltage / 100;
424 batt_frac = battery_voltage % 100;
425
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000426 printf("Batt: %d.%02dV", batt_int, batt_frac);
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000427 lcd_update();
428
429 if(battery_voltage <= 300) {
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000430 printf("WARNING! BATTERY LOW!!");
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000431 lcd_update();
432 sleep(HZ*2);
433 }
434
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000435 rc = ata_init();
436 if(rc)
437 {
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000438 lcd_clear_display();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000439 printf("ATA error: %d", rc);
440 printf("Insert USB cable and press");
441 printf("a button");
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000442 lcd_update();
443 while(!(button_get(true) & BUTTON_REL));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000444 }
445
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000446 /* A hack to enter USB mode without using the USB thread */
447 if(usb_detect())
448 {
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000449 const char msg[] = "Bootloader USB mode";
450 int w, h;
451 font_getstringsize(msg, &w, &h, FONT_SYSFIXED);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000452 lcd_clear_display();
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000453 lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, msg);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000454 lcd_update();
455
Linus Nielsen Feltzing780cfff2006-01-11 15:37:08 +0000456#ifdef IRIVER_H300_SERIES
457 sleep(HZ);
458#endif
459
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000460#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000461 if (firmware_settings.initialized)
462 {
463 firmware_settings.disk_clean = false;
464 eeprom_settings_store();
465 }
466#endif
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000467 ata_spin();
468 ata_enable(false);
469 usb_enable(true);
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000470 cpu_idle_mode(true);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000471 while(usb_detect())
472 {
473 ata_spin(); /* Prevent the drive from spinning down */
474 sleep(HZ);
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000475
476 /* Backlight OFF */
477 or_l(0x00020000, &GPIO1_OUT);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000478 }
479
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000480 cpu_idle_mode(false);
Linus Nielsen Feltzing13103902005-07-19 11:03:00 +0000481 usb_enable(false);
482 ata_init(); /* Reinitialize ATA and continue booting */
483
484 lcd_clear_display();
485 line = 0;
486 lcd_update();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000487 }
488
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000489 disk_init();
490
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000491 rc = disk_mount_all();
492 if (rc<=0)
493 {
494 lcd_clear_display();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000495 printf("No partition found");
496 lcd_update();
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000497 while(button_get(true) != SYS_USB_CONNECTED) {};
498 }
499
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000500 printf("Loading firmware");
Linus Nielsen Feltzing2a3856f2005-02-07 01:47:47 +0000501 lcd_update();
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000502 i = load_firmware();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000503 printf("Result: %d", i);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000504 lcd_update();
505
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000506#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000507 if (firmware_settings.initialized)
508 eeprom_settings_store();
509#endif
510
Miika Pekkarinen973ee5d2006-09-04 16:06:11 +0000511 if (i == 0)
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000512 start_firmware();
513
Miika Pekkarinen973ee5d2006-09-04 16:06:11 +0000514 if (detect_flashed_rockbox())
515 {
516 printf("No firmware found on disk");
517 printf("Powering off...");
518 lcd_update();
519 ata_sleep();
520 sleep(HZ*4);
521 power_off();
522 }
523 else
524 start_iriver_fw();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000525#endif /* IAUDIO_X5 */
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000526}
527
528/* These functions are present in the firmware library, but we reimplement
529 them here because the originals do a lot more than we want */
530
531void reset_poweroff_timer(void)
532{
533}
534
535void screen_dump(void)
536{
537}
538
539int dbg_ports(void)
540{
541 return 0;
542}
543
544void mpeg_stop(void)
545{
546}
547
Linus Nielsen Feltzinge244f7f2005-09-14 09:44:45 +0000548void sys_poweroff(void)
549{
550}