Cleaner solution to plugin-included core files.
[kugel-rb.git] / bootloader / sansa_as3525.c
blob4537c4b43ff9c080bb359ed728e19d7f3a25572e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Rafaël Carré
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
25 #include <stdio.h>
26 #include <system.h>
27 #include <inttypes.h>
28 #include "config.h"
29 #include "lcd.h"
30 #include "backlight-target.h"
31 #include "button-target.h"
32 #include "ascodec-target.h"
33 #include "common.h"
34 #include "storage.h"
35 #include "disk.h"
36 #include "panic.h"
38 int show_logo(void);
39 void main(void)
41 unsigned char* loadbuffer;
42 int buffer_size;
43 void(*kernel_entry)(void);
44 int ret;
46 system_init();
47 kernel_init();
49 #ifdef SANSA_C200V2
50 /* stop here */
51 while(1);
52 #endif
53 lcd_init();
54 show_logo();
56 ascodec_init(); /* Required for backlight on e200v2 */
57 _backlight_on();
59 button_init_device();
60 int btn = button_read_device();
62 /* Enable bootloader messages if any button is pressed */
63 if (btn)
65 lcd_clear_display();
66 verbose = true;
69 enable_irq();
71 ret = storage_init();
72 if(ret < 0)
73 error(EATA,ret);
75 if(!disk_init(IF_MV(0)))
76 panicf("disk_init failed!");
78 ret = disk_mount_all();
80 if(ret <= 0)
81 error(EDISK, ret);
83 printf("Loading firmware");
85 loadbuffer = (unsigned char*)0x30000000; /* DRAM */
86 buffer_size = (int)(loadbuffer + (MEM * 0x100000));
88 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
89 if(ret < 0)
90 error(EBOOTFILE, ret);
92 disable_irq(); /* disable irq until we have copied the new vectors */
94 if (ret == EOK)
96 kernel_entry = (void*) loadbuffer;
97 printf("Executing");
98 kernel_entry();
99 printf("ERR: Failed to boot");
102 /* never returns */
103 while(1) ;