Guard font functions against invalid font ids. These arguably should never be passed...
[maemo-rb.git] / bootloader / sansaconnect.c
blob9ef831f0b3ae00b652bb6a926d85da05c50511c4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
10 * Copyright (C) 2011 by Tomasz Moń
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "system.h"
21 #include "lcd.h"
22 #include "kernel.h"
23 #include "thread.h"
24 #include "storage.h"
25 #include "ata-target.h"
26 #include "disk.h"
27 #include "font.h"
28 #include "backlight.h"
29 #include "button.h"
30 #include "common.h"
31 #include "version.h"
32 #include "uart-target.h"
33 #include "power.h"
35 extern void show_logo(void);
37 void main(void)
39 unsigned char* loadbuffer;
40 int buffer_size;
41 int(*kernel_entry)(void);
42 int ret;
43 int btn;
45 /* Make sure interrupts are disabled */
46 set_irq_level(IRQ_DISABLED);
47 set_fiq_status(FIQ_DISABLED);
48 system_init();
49 kernel_init();
51 /* Now enable interrupts */
52 set_irq_level(IRQ_ENABLED);
53 set_fiq_status(FIQ_ENABLED);
54 backlight_init();
55 lcd_init();
56 font_init();
57 button_init();
59 #ifdef HAVE_LCD_ENABLE
60 lcd_enable(true);
61 #endif
62 lcd_setfont(FONT_SYSFIXED);
63 reset_screen();
64 show_logo();
66 btn = button_read_device();
68 printf("Rockbox boot loader");
69 printf("Version " RBVERSION);
71 ret = storage_init();
72 if(ret)
73 printf("SD error: %d", ret);
75 disk_init(IF_MD(0));
77 ret = disk_mount_all();
78 if (ret <= 0)
79 error(EDISK, ret, true);
81 if (btn & BUTTON_PREV)
83 printf("Loading OF firmware...");
84 printf("Loading vmlinux.bin...");
85 loadbuffer = (unsigned char*)0x01008000;
86 buffer_size = 0x200000;
88 ret = load_raw_firmware(loadbuffer, "/vmlinux.bin", buffer_size);
90 if (ret < 0)
92 printf("Unable to load vmlinux.bin");
94 else
96 printf("Loading initrd.bin...");
97 loadbuffer = (unsigned char*)0x04400020;
98 buffer_size = 0x200000;
99 ret = load_raw_firmware(loadbuffer, "/initrd.bin", buffer_size);
102 if (ret > 0)
104 system_prepare_fw_start();
106 kernel_entry = (void*)0x01008000;
107 ret = kernel_entry();
108 printf("FAILED to boot OF");
112 printf("Loading Rockbox firmware...");
114 loadbuffer = (unsigned char*)CONFIG_SDRAM_START;
115 buffer_size = 0x1000000;
117 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
119 if(ret < 0)
121 error(EBOOTFILE, ret, true);
123 else if(ret == EOK)
125 system_prepare_fw_start();
127 kernel_entry = (void*) loadbuffer;
128 ret = kernel_entry();
129 printf("FAILED!");
132 storage_sleepnow();
134 while(1);