blob: 3b3e6ecae4a2c83c785eb974ffe9b1f1ef007260 [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"
36#include "button.h"
37#include "panic.h"
38#include "power.h"
39#include "file.h"
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +000040#include "uda1380.h"
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +000041#include "eeprom_settings.h"
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000042
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +000043#include "pcf50606.h"
44
45#include <stdarg.h>
46
Linus Nielsen Feltzing62c768c2005-07-09 07:46:42 +000047#define DRAM_START 0x31000000
48
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000049int line = 0;
50
51int usb_screen(void)
52{
53 return 0;
54}
55
Linus Nielsen Feltzinga2e8cf72005-07-15 07:42:25 +000056char version[] = APPSVERSION;
57
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +000058char printfbuf[256];
59
60void printf(const char *format, ...)
61{
62 int len;
63 unsigned char *ptr;
64 va_list ap;
65 va_start(ap, format);
66
67 ptr = printfbuf;
68 len = vsnprintf(ptr, sizeof(printfbuf), format, ap);
69 va_end(ap);
70
71 lcd_puts(0, line++, ptr);
72 lcd_update();
73 if(line >= 16)
74 line = 0;
75}
76
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000077void start_iriver_fw(void)
78{
79 asm(" move.w #0x2700,%sr");
Linus Nielsen Feltzingf1530d82005-02-04 18:24:58 +000080 /* Reset the cookie for the crt0 crash check */
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000081 asm(" move.l #0,%d0");
Linus Nielsen Feltzingf1530d82005-02-04 18:24:58 +000082 asm(" move.l %d0,0x10017ffc");
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000083 asm(" movec.l %d0,%vbr");
84 asm(" move.l 0,%sp");
85 asm(" lea.l 8,%a0");
86 asm(" jmp (%a0)");
87}
88
89int load_firmware(void)
90{
91 int fd;
92 int rc;
93 int len;
94 unsigned long chksum;
Linus Nielsen Feltzinga75f0e52005-07-09 09:04:37 +000095 char model[5];
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +000096 unsigned long sum;
97 int i;
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +000098 unsigned char *buf = (unsigned char *)DRAM_START;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +000099
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000100 fd = open("/.rockbox/" BOOTFILE, O_RDONLY);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000101 if(fd < 0)
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000102 {
103 fd = open("/" BOOTFILE, O_RDONLY);
104 if(fd < 0)
105 return -1;
106 }
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000107
Linus Nielsen Feltzingb8a00d22005-02-10 21:55:48 +0000108 len = filesize(fd) - 8;
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000109
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000110 printf("Length: %x", len);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000111 lcd_update();
112
Linus Nielsen Feltzing2a77d3a2005-01-28 13:27:58 +0000113 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000114
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000115 rc = read(fd, &chksum, 4);
116 if(rc < 4)
117 return -2;
118
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000119 printf("Checksum: %x", chksum);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000120 lcd_update();
121
Linus Nielsen Feltzinga75f0e52005-07-09 09:04:37 +0000122 rc = read(fd, model, 4);
123 if(rc < 4)
124 return -3;
125
126 model[4] = 0;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000127
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000128 printf("Model name: %s", model);
Linus Nielsen Feltzinga75f0e52005-07-09 09:04:37 +0000129 lcd_update();
130
Linus Nielsen Feltzing2a77d3a2005-01-28 13:27:58 +0000131 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000132
133 rc = read(fd, buf, len);
134 if(rc < len)
135 return -4;
136
137 close(fd);
138
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000139 sum = MODEL_NUMBER;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000140
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000141 for(i = 0;i < len;i++) {
142 sum += buf[i];
143 }
144
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000145 printf("Sum: %x", sum);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000146 lcd_update();
147
148 if(sum != chksum)
149 return -5;
150
151 return 0;
152}
153
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000154int load_flashed_rockbox(void)
155{
156 struct flash_header hdr;
157 unsigned char *buf = (unsigned char *)DRAM_START;
158 uint8_t *src = (uint8_t *)FLASH_ENTRYPOINT;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000159
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000160 cpu_boost(true);
161 memcpy(&hdr, src, sizeof(struct flash_header));
162 src += sizeof(struct flash_header);
163 memcpy(buf, src, hdr.length);
164 cpu_boost(false);
165
166 return 0;
167}
168
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000169
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000170void start_firmware(void)
171{
172 asm(" move.w #0x2700,%sr");
Linus Nielsen Feltzingf1530d82005-02-04 18:24:58 +0000173 /* Reset the cookie for the crt0 crash check */
174 asm(" move.l #0,%d0");
175 asm(" move.l %d0,0x10017ffc");
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000176 asm(" move.l %0,%%d0" :: "i"(DRAM_START));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000177 asm(" movec.l %d0,%vbr");
Linus Nielsen Feltzinge82df4e2005-07-08 15:09:44 +0000178 asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START));
179 asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4)));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000180 asm(" jmp (%a0)");
181}
182
Linus Nielsen Feltzingb8a00d22005-02-10 21:55:48 +0000183void main(void)
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000184{
185 int i;
186 int rc;
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000187 bool rc_on_button = false;
188 bool on_button = false;
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000189 bool rec_button = false;
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000190 int data;
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000191 int adc_battery, battery_voltage, batt_int, batt_frac;
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000192
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000193#ifdef IAUDIO_X5
194 (void)rc_on_button;
195 (void)on_button;
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000196 (void)rec_button;
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000197 (void)data;
198 power_init();
199
200 system_init();
201 kernel_init();
202
203 set_cpu_frequency(CPUFREQ_NORMAL);
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000204 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000205
206 set_irq_level(0);
207 lcd_init();
Michael Sevakis58825f62006-11-10 18:47:41 +0000208 backlight_init();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000209 font_init();
210 adc_init();
211 button_init();
212
213 printf("Rockbox boot loader");
214 printf("Version %s", version);
215 lcd_update();
216
217 adc_battery = adc_read(ADC_BATTERY);
218
219 battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000;
220 batt_int = battery_voltage / 100;
221 batt_frac = battery_voltage % 100;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000222
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000223 printf("Batt: %d.%02dV", batt_int, batt_frac);
224 lcd_update();
225
226 rc = ata_init();
227 if(rc)
228 {
229 printf("ATA error: %d", rc);
230 sleep(HZ*5);
231 power_off();
232 }
233
234 disk_init();
235
236 rc = disk_mount_all();
237 if (rc<=0)
238 {
239 printf("No partition found");
240 sleep(HZ*5);
241 power_off();
242 }
243
244 printf("Loading firmware");
245 lcd_update();
246 i = load_firmware();
247 printf("Result: %d", i);
248 lcd_update();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000249
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000250 if(i == 0)
251 start_firmware();
252
253 power_off();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000254
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000255#else
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000256 /* We want to read the buttons as early as possible, before the user
257 releases the ON button */
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000258
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000259 /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs
260 (The ON and Hold buttons on the main unit and the remote) */
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +0000261 or_l(0x00100062, &GPIO1_FUNCTION);
262 and_l(~0x00100062, &GPIO1_ENABLE);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000263
264 data = GPIO1_READ;
265 if ((data & 0x20) == 0)
266 on_button = true;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000267
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000268 if ((data & 0x40) == 0)
269 rc_on_button = true;
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000270
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000271 /* Set the default state of the hard drive power to OFF */
272 ide_power_enable(false);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000273
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000274 power_init();
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000275
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000276 /* Turn off if neither ON button is pressed */
Linus Nielsen Feltzing54da9242006-01-10 23:11:57 +0000277 if(!(on_button || rc_on_button || usb_detect()))
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000278 power_off();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000279
Linus Nielsen Feltzingbbe919b2005-11-19 01:33:28 +0000280 /* Backlight ON */
281 or_l(0x00020000, &GPIO1_ENABLE);
282 or_l(0x00020000, &GPIO1_FUNCTION);
283 and_l(~0x00020000, &GPIO1_OUT);
284
285 /* Remote backlight ON */
286#ifdef HAVE_REMOTE_LCD
287#ifdef IRIVER_H300_SERIES
288 or_l(0x00000002, &GPIO1_ENABLE);
289 and_l(~0x00000002, &GPIO1_OUT);
290#else
291 or_l(0x00000800, &GPIO_ENABLE);
292 or_l(0x00000800, &GPIO_FUNCTION);
293 and_l(~0x00000800, &GPIO_OUT);
294#endif
295#endif
296
Linus Nielsen Feltzingb68cb9b2005-12-03 00:54:59 +0000297 /* Power on the hard drive early, to speed up the loading.
298 Some H300 don't like this, so we only do it for the H100 */
299#ifndef IRIVER_H300_SERIES
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000300 if(!((on_button && button_hold()) ||
301 (rc_on_button && remote_button_hold()))) {
302 ide_power_enable(true);
303 }
Linus Nielsen Feltzingb68cb9b2005-12-03 00:54:59 +0000304#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000305
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000306 system_init();
307 kernel_init();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000308
309#ifdef HAVE_ADJUSTABLE_CPU_FREQ
310 /* Set up waitstates for the peripherals */
311 set_cpu_frequency(0); /* PLL off */
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000312#ifdef CPU_COLDFIRE
313 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
314#endif
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000315#endif
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +0000316
Linus Nielsen Feltzing2fcd1b02006-02-04 23:09:56 +0000317#ifdef HAVE_UDA1380
Linus Nielsen Feltzingd2ca7fc2005-07-12 05:25:42 +0000318 uda1380_reset();
Linus Nielsen Feltzing2fcd1b02006-02-04 23:09:56 +0000319#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000320
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000321 backlight_init();
322 set_irq_level(0);
323 lcd_init();
324 font_init();
325 adc_init();
326 button_init();
327
328 lcd_setfont(FONT_SYSFIXED);
329
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000330 printf("Rockbox boot loader");
331 printf("Version %s", version);
Linus Nielsen Feltzingd1af08f2005-07-09 19:48:22 +0000332 lcd_update();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000333
Linus Nielsen Feltzingb8a00d22005-02-10 21:55:48 +0000334 sleep(HZ/50); /* Allow the button driver to check the buttons */
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000335 rec_button = ((button_status() & BUTTON_REC) == BUTTON_REC)
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000336 || ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000337
Miika Pekkarinen22860a92006-08-11 19:59:16 +0000338 /* Don't start if the Hold button is active on the device you
339 are starting with */
340 if (!usb_detect() && ((on_button && button_hold()) ||
341 (rc_on_button && remote_button_hold())))
342 {
343 printf("HOLD switch on, power off...");
344 lcd_update();
345 sleep(HZ*2);
346
347 /* Backlight OFF */
348#ifdef HAVE_REMOTE_LCD
349#ifdef IRIVER_H300_SERIES
350 or_l(0x00000002, &GPIO1_OUT);
351#else
352 or_l(0x00000800, &GPIO_OUT);
353#endif
354#endif
355 /* Reset the cookie for the crt0 crash check */
356 asm(" move.l #0,%d0");
357 asm(" move.l %d0,0x10017ffc");
358 power_off();
359 }
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000360
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000361#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000362 firmware_settings.initialized = false;
363#endif
364 if (detect_flashed_rockbox())
365 {
366 bool load_from_flash;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000367
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000368 load_from_flash = !rec_button;
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000369#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000370 if (eeprom_settings_init())
371 {
372 /* If bootloader version has not been reset, disk might
373 * not be intact. */
374 if (firmware_settings.bl_version)
375 firmware_settings.disk_clean = false;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000376
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000377 firmware_settings.bl_version = 7;
378 /* Invert the record button if we want to load from disk
379 * by default. */
380 if (firmware_settings.boot_disk)
381 load_from_flash = rec_button;
382 }
383#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000384
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000385 if (load_from_flash)
386 {
387 /* Load firmware from flash */
388 i = load_flashed_rockbox();
389 printf("Result: %d", i);
390 lcd_update();
391 if (i == 0)
392 {
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000393#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000394 eeprom_settings_store();
395#endif
396 start_firmware();
397 printf("Fatal: Corrupted firmware");
398 printf("Hold down REC on next boot");
399 lcd_update();
400 sleep(HZ*2);
401 power_off();
402 }
403 }
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000404
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000405 printf("Loading from disk...");
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000406 lcd_update();
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000407 }
408 else
409 {
410 /* Holding REC while starting runs the original firmware */
411 if (rec_button)
412 {
413 printf("Starting original firmware...");
414 lcd_update();
415 start_iriver_fw();
416 }
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000417 }
418
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000419 usb_init();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000420
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000421 adc_battery = adc_read(ADC_BATTERY);
422
423 battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000;
424 batt_int = battery_voltage / 100;
425 batt_frac = battery_voltage % 100;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000426
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000427 printf("Batt: %d.%02dV", batt_int, batt_frac);
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000428 lcd_update();
429
430 if(battery_voltage <= 300) {
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000431 printf("WARNING! BATTERY LOW!!");
Linus Nielsen Feltzingdfa8ecb2005-07-11 14:01:45 +0000432 lcd_update();
433 sleep(HZ*2);
434 }
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000435
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000436 rc = ata_init();
437 if(rc)
438 {
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000439 lcd_clear_display();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000440 printf("ATA error: %d", rc);
441 printf("Insert USB cable and press");
442 printf("a button");
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000443 lcd_update();
444 while(!(button_get(true) & BUTTON_REL));
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000445 }
446
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000447 /* A hack to enter USB mode without using the USB thread */
448 if(usb_detect())
449 {
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000450 const char msg[] = "Bootloader USB mode";
451 int w, h;
452 font_getstringsize(msg, &w, &h, FONT_SYSFIXED);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000453 lcd_clear_display();
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000454 lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, msg);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000455 lcd_update();
456
Linus Nielsen Feltzing780cfff2006-01-11 15:37:08 +0000457#ifdef IRIVER_H300_SERIES
458 sleep(HZ);
459#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000460
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000461#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000462 if (firmware_settings.initialized)
463 {
464 firmware_settings.disk_clean = false;
465 eeprom_settings_store();
466 }
467#endif
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000468 ata_spin();
469 ata_enable(false);
470 usb_enable(true);
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000471 cpu_idle_mode(true);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000472 while(usb_detect())
473 {
474 ata_spin(); /* Prevent the drive from spinning down */
475 sleep(HZ);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000476
Linus Nielsen Feltzinge628b5c2005-07-19 08:08:33 +0000477 /* Backlight OFF */
478 or_l(0x00020000, &GPIO1_OUT);
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000479 }
480
Linus Nielsen Feltzing01917ec2005-12-06 12:12:29 +0000481 cpu_idle_mode(false);
Linus Nielsen Feltzing13103902005-07-19 11:03:00 +0000482 usb_enable(false);
483 ata_init(); /* Reinitialize ATA and continue booting */
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000484
Linus Nielsen Feltzing13103902005-07-19 11:03:00 +0000485 lcd_clear_display();
486 line = 0;
487 lcd_update();
Linus Nielsen Feltzing8e958b52005-05-20 18:16:45 +0000488 }
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000489
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000490 disk_init();
491
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000492 rc = disk_mount_all();
493 if (rc<=0)
494 {
495 lcd_clear_display();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000496 printf("No partition found");
497 lcd_update();
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000498 while(button_get(true) != SYS_USB_CONNECTED) {};
499 }
500
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000501 printf("Loading firmware");
Linus Nielsen Feltzing2a3856f2005-02-07 01:47:47 +0000502 lcd_update();
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000503 i = load_firmware();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000504 printf("Result: %d", i);
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000505 lcd_update();
506
Peter D'Hoyec4a59a22006-08-15 22:54:06 +0000507#ifdef HAVE_EEPROM_SETTINGS
Miika Pekkarinene1eb91b2006-08-09 12:04:13 +0000508 if (firmware_settings.initialized)
509 eeprom_settings_store();
510#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000511
Miika Pekkarinen973ee5d2006-09-04 16:06:11 +0000512 if (i == 0)
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000513 start_firmware();
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000514
Miika Pekkarinen973ee5d2006-09-04 16:06:11 +0000515 if (detect_flashed_rockbox())
516 {
517 printf("No firmware found on disk");
518 printf("Powering off...");
519 lcd_update();
520 ata_sleep();
521 sleep(HZ*4);
522 power_off();
523 }
524 else
525 start_iriver_fw();
Linus Nielsen Feltzingce6527b2006-03-22 11:45:33 +0000526#endif /* IAUDIO_X5 */
Linus Nielsen Feltzingd3971452005-01-28 12:51:10 +0000527}
528
529/* These functions are present in the firmware library, but we reimplement
530 them here because the originals do a lot more than we want */
531
532void reset_poweroff_timer(void)
533{
534}
535
536void screen_dump(void)
537{
538}
539
540int dbg_ports(void)
541{
542 return 0;
543}
544
545void mpeg_stop(void)
546{
547}
548
Linus Nielsen Feltzinge244f7f2005-09-14 09:44:45 +0000549void sys_poweroff(void)
550{
551}