Make 'Backlight mod' an Advanced build option for the Ondios (largely inspired by...
[kugel-rb.git] / bootloader / sansa_as3525.c
blobdbe6218d48269ce28cc0abb4fa2c18781ebda703
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);
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 _backlight_on();
58 button_init_device();
59 int btn = button_read_device();
61 #if !defined(SANSA_FUZE) && !defined(SANSA_CLIP)
62 if (button_hold())
64 verbose = true;
65 lcd_clear_display();
66 printf("Hold switch on");
67 printf("Shutting down...");
68 sleep(HZ);
69 power_off();
71 #endif
73 /* Enable bootloader messages if any button is pressed */
74 if (btn)
76 lcd_clear_display();
77 verbose = true;
80 enable_irq();
82 ret = storage_init();
83 if(ret < 0)
84 error(EATA,ret);
86 if(!disk_init(IF_MV(0)))
87 panicf("disk_init failed!");
89 ret = disk_mount_all();
91 if(ret <= 0)
92 error(EDISK, ret);
94 printf("Loading firmware");
96 loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */
97 buffer_size = (int)(loadbuffer + (DRAM_SIZE) - TTB_SIZE);
99 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
100 if(ret < 0)
101 error(EBOOTFILE, ret);
103 disable_irq(); /* disable irq until we have copied the new vectors */
105 if (ret == EOK)
107 kernel_entry = (void*) loadbuffer;
108 printf("Executing");
109 kernel_entry();
110 printf("ERR: Failed to boot");
113 /* never returns */
114 while(1) ;