Poor mans workaround for hanging SDL app/sim on shutdown.
[maemo-rb.git] / bootloader / creativezvm.c
blob7dcbac7dcc1d05a69a3b069daaf18a03ac3f27e3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Maurus Cuelenaere
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 "usb.h"
32 #include "version.h"
35 static void load_fw(unsigned char* ptr, unsigned int len)
37 (void)ptr;
38 (void)len;
39 asm volatile("ldr pc, =0x1EE0000");
42 void main(void)
44 unsigned char* loadbuffer;
45 int buffer_size;
46 int(*kernel_entry)(void);
47 int ret;
49 /* Make sure interrupts are disabled */
50 set_irq_level(IRQ_DISABLED);
51 set_fiq_status(FIQ_DISABLED);
52 system_init();
53 kernel_init();
55 /* Now enable interrupts */
56 set_irq_level(IRQ_ENABLED);
57 set_fiq_status(FIQ_ENABLED);
58 backlight_init();
59 lcd_init();
60 font_init();
61 button_init();
62 usb_init();
64 #ifdef HAVE_LCD_ENABLE
65 lcd_enable(true);
66 #endif
67 lcd_setfont(FONT_SYSFIXED);
68 reset_screen();
69 printf("Rockbox boot loader");
70 printf("Version " RBVERSION);
72 ret = storage_init();
73 if(ret)
74 printf("ATA error: %d", ret);
76 /* If no button is held, start the OF */
77 if(button_read_device() == 0)
79 printf("Loading Creative firmware...");
81 loadbuffer = (unsigned char*)0x00A00000;
82 ret = load_minifs_file("creativeos.jrm", loadbuffer);
83 if(ret != -1)
85 set_irq_level(IRQ_DISABLED);
86 set_fiq_status(FIQ_DISABLED);
87 /* Doesn't return! */
88 load_fw(loadbuffer, ret);
90 else
91 printf("FAILED!");
93 else
95 disk_init();
97 ret = disk_mount_all();
98 if (ret <= 0)
99 error(EDISK, ret, true);
101 printf("Loading Rockbox firmware...");
103 loadbuffer = (unsigned char*)0x00900000;
104 buffer_size = (unsigned char*)0x01900000 - loadbuffer;
106 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
107 if(ret < 0)
108 error(EBOOTFILE, ret, true);
110 else if(ret == EOK)
112 kernel_entry = (void*) loadbuffer;
113 ret = kernel_entry();
114 printf("FAILED!");
118 storage_sleepnow();
120 while(1);