blob: e3d59051a16a2da2594d2a4f7ea5d87aaa2ad24a [file] [log] [blame]
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "inttypes.h"
23#include "string.h"
24#include "cpu.h"
25#include "system.h"
26#include "lcd.h"
Michael Sevakis4ea4cdf2014-08-08 02:28:11 -040027#include "../kernel-internal.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000028#include "storage.h"
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040029#include "file_internal.h"
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000030#include "disk.h"
31#include "font.h"
32#include "adc.h"
33#include "backlight.h"
34#include "backlight-target.h"
35#include "button.h"
36#include "panic.h"
37#include "power.h"
38#include "file.h"
39#include "common.h"
Marcin Bukat0b296912012-03-04 15:34:29 +010040#include "rb-loader.h"
41#include "loader_strerror.h"
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000042#include "rbunicode.h"
43#include "usb.h"
44#include "spi.h"
45#include "uart-target.h"
46#include "tsc2100.h"
47#include "time.h"
48#include "system-arm.h"
Rafaël Carré5d236b22010-05-27 09:41:46 +000049#include "version.h"
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000050
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000051void main(void)
52{
53 unsigned char* loadbuffer;
54 int buffer_size;
55 int rc;
56 int(*kernel_entry)(void);
57
Karl Kurbjun9e1d00c2009-02-26 21:24:40 +000058 /* Make sure interrupts are disabled */
59 set_irq_level(IRQ_DISABLED);
60 set_fiq_status(FIQ_DISABLED);
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000061 system_init();
62 kernel_init();
63
Karl Kurbjun9e1d00c2009-02-26 21:24:40 +000064 /* Now enable interrupts */
65 set_irq_level(IRQ_ENABLED);
66 set_fiq_status(FIQ_ENABLED);
67
Karl Kurbjun9e1d00c2009-02-26 21:24:40 +000068 lcd_init();
Karl Kurbjunfff80b02011-02-06 21:04:51 +000069 backlight_init();
Karl Kurbjun9e1d00c2009-02-26 21:24:40 +000070 font_init();
71 button_init();
72 usb_init();
73
74
75 power_init();
76// enable_irq();
77// enable_fiq();
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000078
79 adc_init();
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000080
81 lcd_setfont(FONT_SYSFIXED);
82
83 /* Show debug messages if button is pressed */
84// if(button_read_device())
85 verbose = true;
86
87 printf("Rockbox boot loader");
Michael Sevakis95a4c3a2014-08-28 10:26:45 -040088 printf("Version %s", rbversion);
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000089
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +000090 /* Enter USB mode without USB thread */
91 if(usb_detect() == USB_INSERTED)
92 {
93 const char msg[] = "Bootloader USB mode";
94 reset_screen();
95 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
96 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
97 lcd_update();
98
99 ide_power_enable(true);
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000100 storage_enable(false);
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000101 sleep(HZ/20);
102 usb_enable(true);
103
104 while (usb_detect() == USB_INSERTED)
105 {
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000106 storage_spin(); /* Prevent the drive from spinning down */
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000107 sleep(HZ);
108 }
109
110 usb_enable(false);
111
112 reset_screen();
113 lcd_update();
114 }
Karl Kurbjun9e1d00c2009-02-26 21:24:40 +0000115
Karl Kurbjun9e1d00c2009-02-26 21:24:40 +0000116 sleep(50);
117
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000118 printf("ATA");
Frank Gevaerts2f8a0082008-11-01 16:14:28 +0000119 rc = storage_init();
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000120 if(rc)
121 {
122 reset_screen();
Rafaël Carré1ec82122010-06-23 05:08:36 +0000123 error(EATA, rc, true);
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000124 }
125
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400126 printf("filesystem");
127 filesystem_init();
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000128
129 printf("mount");
130 rc = disk_mount_all();
131 if (rc<=0)
132 {
Rafaël Carré1ec82122010-06-23 05:08:36 +0000133 error(EDISK,rc, true);
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000134 }
135
136 printf("Loading firmware");
137
138 loadbuffer = (unsigned char*) 0x00900000;
139 buffer_size = (unsigned char*)0x01900000 - loadbuffer;
140
141 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
Marcin Bukat0b296912012-03-04 15:34:29 +0100142 if(rc <= EFILE_EMPTY)
Rafaël Carré1ec82122010-06-23 05:08:36 +0000143 error(EBOOTFILE, rc, true);
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000144
Marcin Bukat0b296912012-03-04 15:34:29 +0100145 kernel_entry = (void*) loadbuffer;
146 rc = kernel_entry();
147
148 /* Should not get here! */
149 return rc;
Maurus Cuelenaere1ff9ce22008-09-10 19:35:15 +0000150}