blob: 5bd59b3ac4900fd4fa371d58fea12dc3a1c5d098 [file] [log] [blame]
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +00001/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id: $
9*
10* Copyright (C) 2011 by Tomasz Moń
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"
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +000023#include "storage.h"
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040024#include "file_internal.h"
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +000025#include "disk.h"
26#include "font.h"
27#include "backlight.h"
28#include "button.h"
29#include "common.h"
Marcin Bukat0b296912012-03-04 15:34:29 +010030#include "rb-loader.h"
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +000031#include "version.h"
32#include "uart-target.h"
33#include "power.h"
Marcin Bukat38032a42013-06-27 14:04:32 +020034#include "loader_strerror.h"
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +000035
36extern void show_logo(void);
37
38void main(void)
39{
40 unsigned char* loadbuffer;
41 int buffer_size;
42 int(*kernel_entry)(void);
43 int ret;
44 int btn;
45
46 /* Make sure interrupts are disabled */
47 set_irq_level(IRQ_DISABLED);
48 set_fiq_status(FIQ_DISABLED);
49 system_init();
50 kernel_init();
51
52 /* Now enable interrupts */
53 set_irq_level(IRQ_ENABLED);
54 set_fiq_status(FIQ_ENABLED);
55 backlight_init();
56 lcd_init();
57 font_init();
58 button_init();
59
60#ifdef HAVE_LCD_ENABLE
61 lcd_enable(true);
62#endif
63 lcd_setfont(FONT_SYSFIXED);
64 reset_screen();
65 show_logo();
66
67 btn = button_read_device();
68
69 printf("Rockbox boot loader");
Michael Sevakis95a4c3a2014-08-28 10:26:45 -040070 printf("Version %s", rbversion);
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +000071
72 ret = storage_init();
73 if(ret)
74 printf("SD error: %d", ret);
75
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040076 filesystem_init();
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +000077
78 ret = disk_mount_all();
79 if (ret <= 0)
80 error(EDISK, ret, true);
81
82 if (btn & BUTTON_PREV)
83 {
84 printf("Loading OF firmware...");
85 printf("Loading vmlinux.bin...");
86 loadbuffer = (unsigned char*)0x01008000;
87 buffer_size = 0x200000;
88
89 ret = load_raw_firmware(loadbuffer, "/vmlinux.bin", buffer_size);
90
91 if (ret < 0)
92 {
93 printf("Unable to load vmlinux.bin");
94 }
95 else
96 {
97 printf("Loading initrd.bin...");
98 loadbuffer = (unsigned char*)0x04400020;
99 buffer_size = 0x200000;
100 ret = load_raw_firmware(loadbuffer, "/initrd.bin", buffer_size);
101 }
102
103 if (ret > 0)
104 {
105 system_prepare_fw_start();
106
107 kernel_entry = (void*)0x01008000;
108 ret = kernel_entry();
109 printf("FAILED to boot OF");
110 }
111 }
112
113 printf("Loading Rockbox firmware...");
114
115 loadbuffer = (unsigned char*)CONFIG_SDRAM_START;
116 buffer_size = 0x1000000;
117
118 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
119
Marcin Bukat0b296912012-03-04 15:34:29 +0100120 if(ret <= EFILE_EMPTY)
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +0000121 {
122 error(EBOOTFILE, ret, true);
123 }
Marcin Bukat0b296912012-03-04 15:34:29 +0100124 else
Tomasz Mońe8a8a1b2011-11-16 14:08:01 +0000125 {
126 system_prepare_fw_start();
127
128 kernel_entry = (void*) loadbuffer;
129 ret = kernel_entry();
130 printf("FAILED!");
131 }
132
133 storage_sleepnow();
134
135 while(1);
136}