Undo revert of r20653
[kugel-rb.git] / bootloader / sansa_as3525.c
blob02f040aaa3ddf98b2742520d06872108833f2711
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 "common.h"
33 #include "storage.h"
34 #include "disk.h"
35 #include "panic.h"
37 int show_logo(void);
38 void main(void)
40 unsigned char* loadbuffer;
41 int buffer_size;
42 void(*kernel_entry)(void);
43 int ret;
45 system_init();
46 kernel_init();
48 #ifdef SANSA_C200V2
49 /* stop here */
50 while(1);
51 #endif
52 lcd_init();
53 show_logo();
55 _backlight_on();
57 button_init_device();
58 int btn = button_read_device();
60 /* Enable bootloader messages if any button is pressed */
61 if (btn)
63 lcd_clear_display();
64 verbose = true;
67 enable_irq();
69 ret = storage_init();
70 if(ret < 0)
71 error(EATA,ret);
73 if(!disk_init(IF_MV(0)))
74 panicf("disk_init failed!");
76 ret = disk_mount_all();
78 if(ret <= 0)
79 error(EDISK, ret);
81 printf("Loading firmware");
83 loadbuffer = (unsigned char*)0x30000000; /* DRAM */
84 buffer_size = (int)(loadbuffer + (MEM * 0x100000));
86 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
87 if(ret < 0)
88 error(EBOOTFILE, ret);
90 disable_irq(); /* disable irq until we have copied the new vectors */
92 if (ret == EOK)
94 kernel_entry = (void*) loadbuffer;
95 printf("Executing");
96 kernel_entry();
97 printf("ERR: Failed to boot");
100 /* never returns */
101 while(1) ;