blob: 6597448193a5a5087787d84e5b410d39c9f98b03 [file] [log] [blame]
Maurus Cuelenaere944c3342008-08-27 20:32:12 +00001/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2008 by Maurus Cuelenaere
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
20#include "system.h"
21#include "lcd.h"
Michael Sevakis4ea4cdf2014-08-08 02:28:11 -040022#include "../kernel-internal.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000023#include "storage.h"
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000024#include "ata-target.h"
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040025#include "file_internal.h"
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000026#include "disk.h"
27#include "font.h"
28#include "backlight.h"
29#include "button.h"
30#include "common.h"
Marcin Bukat0b296912012-03-04 15:34:29 +010031#include "loader_strerror.h"
32#include "rb-loader.h"
Maurus Cuelenaereee1e8be2009-02-05 21:47:54 +000033#include "usb.h"
Rafaël Carré5d236b22010-05-27 09:41:46 +000034#include "version.h"
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000035
36
37static void load_fw(unsigned char* ptr, unsigned int len)
38{
39 (void)ptr;
40 (void)len;
41 asm volatile("ldr pc, =0x1EE0000");
42}
43
44void main(void)
45{
46 unsigned char* loadbuffer;
47 int buffer_size;
48 int(*kernel_entry)(void);
49 int ret;
50
Maurus Cuelenaere78d44382008-08-27 20:35:41 +000051 /* Make sure interrupts are disabled */
52 set_irq_level(IRQ_DISABLED);
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000053 set_fiq_status(FIQ_DISABLED);
54 system_init();
55 kernel_init();
Maurus Cuelenaere78d44382008-08-27 20:35:41 +000056
57 /* Now enable interrupts */
58 set_irq_level(IRQ_ENABLED);
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000059 set_fiq_status(FIQ_ENABLED);
60 backlight_init();
61 lcd_init();
62 font_init();
63 button_init();
Maurus Cuelenaereee1e8be2009-02-05 21:47:54 +000064 usb_init();
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000065
Thomas Martitzb5e6eec2009-03-17 21:23:02 +000066#ifdef HAVE_LCD_ENABLE
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000067 lcd_enable(true);
Thomas Martitzb5e6eec2009-03-17 21:23:02 +000068#endif
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000069 lcd_setfont(FONT_SYSFIXED);
70 reset_screen();
71 printf("Rockbox boot loader");
Michael Sevakis95a4c3a2014-08-28 10:26:45 -040072 printf("Version %s", rbversion);
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000073
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000074 ret = storage_init();
Maurus Cuelenaere78d44382008-08-27 20:35:41 +000075 if(ret)
76 printf("ATA error: %d", ret);
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040077
78 filesystem_init();
Maurus Cuelenaereee1e8be2009-02-05 21:47:54 +000079
Maurus Cuelenaere23fc9232008-09-07 17:24:14 +000080 /* If no button is held, start the OF */
81 if(button_read_device() == 0)
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000082 {
83 printf("Loading Creative firmware...");
84
85 loadbuffer = (unsigned char*)0x00A00000;
86 ret = load_minifs_file("creativeos.jrm", loadbuffer);
87 if(ret != -1)
88 {
Maurus Cuelenaere78d44382008-08-27 20:35:41 +000089 set_irq_level(IRQ_DISABLED);
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000090 set_fiq_status(FIQ_DISABLED);
91 /* Doesn't return! */
92 load_fw(loadbuffer, ret);
93 }
94 else
95 printf("FAILED!");
96 }
97 else
98 {
Maurus Cuelenaere944c3342008-08-27 20:32:12 +000099 ret = disk_mount_all();
100 if (ret <= 0)
Rafaël Carré1ec82122010-06-23 05:08:36 +0000101 error(EDISK, ret, true);
Maurus Cuelenaere944c3342008-08-27 20:32:12 +0000102
103 printf("Loading Rockbox firmware...");
104
105 loadbuffer = (unsigned char*)0x00900000;
106 buffer_size = (unsigned char*)0x01900000 - loadbuffer;
107
108 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
Marcin Bukat0b296912012-03-04 15:34:29 +0100109 if(ret <= EFILE_EMPTY)
Rafaël Carré1ec82122010-06-23 05:08:36 +0000110 error(EBOOTFILE, ret, true);
Marcin Bukat0b296912012-03-04 15:34:29 +0100111
112 kernel_entry = (void*) loadbuffer;
113 ret = kernel_entry();
114 printf("FAILED!");
Maurus Cuelenaere944c3342008-08-27 20:32:12 +0000115 }
116
Maurus Cuelenaereee1e8be2009-02-05 21:47:54 +0000117 storage_sleepnow();
118
Maurus Cuelenaere944c3342008-08-27 20:32:12 +0000119 while(1);
120}