Add iAudio M5 FM radio mod to the advanced build options. * Unify iAudio audio driver...
[kugel-rb.git] / bootloader / sansa_as3525.c
blob48f21bc196e31b9789c6d514db83c2e43cc4c9a8
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"
36 #include "power.h"
38 int show_logo(void);
40 void main(void) __attribute__((naked, noreturn));
41 void main(void)
43 unsigned char* loadbuffer;
44 int buffer_size;
45 void(*kernel_entry)(void);
46 int ret;
48 system_init();
49 kernel_init();
51 #ifdef SANSA_C200V2
52 /* stop here */
53 while(1);
54 #endif
55 lcd_init();
56 show_logo();
58 _backlight_on();
60 button_init_device();
61 int btn = button_read_device();
63 #if !defined(SANSA_FUZE) && !defined(SANSA_CLIP)
64 if (button_hold())
66 verbose = true;
67 lcd_clear_display();
68 printf("Hold switch on");
69 printf("Shutting down...");
70 sleep(HZ);
71 power_off();
73 #endif
75 /* Enable bootloader messages if any button is pressed */
76 if (btn)
78 lcd_clear_display();
79 verbose = true;
82 enable_irq();
84 ret = storage_init();
85 if(ret < 0)
86 error(EATA,ret);
88 if(!disk_init(IF_MV(0)))
89 panicf("disk_init failed!");
91 ret = disk_mount_all();
93 if(ret <= 0)
94 error(EDISK, ret);
96 printf("Loading firmware");
98 loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */
99 buffer_size = (int)(loadbuffer + (DRAM_SIZE) - TTB_SIZE);
101 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
102 if(ret < 0)
103 error(EBOOTFILE, ret);
105 disable_irq(); /* disable irq until we have copied the new vectors */
107 if (ret == EOK)
109 kernel_entry = (void*) loadbuffer;
110 printf("Executing");
111 kernel_entry();
112 printf("ERR: Failed to boot");
115 /* never returns */
116 while(1) ;