Correct search&replace error.
[kugel-rb.git] / bootloader / sansa_as3525.c
blob9248921eed7d3fa76450347d053e9bd05241ff48
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.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__((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 enable_irq();
53 lcd_init();
54 show_logo();
56 backlight_init();
58 button_init_device();
59 int btn = button_read_device();
61 #if !defined(SANSA_FUZE) && !defined(SANSA_CLIP) && !defined(SANSA_CLIPV2) \
62 && !defined(SANSA_CLIPPLUS)
63 if (button_hold())
65 verbose = true;
66 lcd_clear_display();
67 printf("Hold switch on");
68 printf("Shutting down...");
69 sleep(HZ);
70 power_off();
72 #endif
74 /* Enable bootloader messages if any button is pressed */
75 if (btn)
77 lcd_clear_display();
78 verbose = true;
81 ret = storage_init();
82 if(ret < 0)
83 error(EATA,ret);
85 if(!disk_init(IF_MV(0)))
86 panicf("disk_init failed!");
88 ret = disk_mount_all();
90 if(ret <= 0)
91 error(EDISK, ret);
93 printf("Loading firmware");
95 loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */
96 buffer_size = (int)(loadbuffer + (DRAM_SIZE) - TTB_SIZE);
98 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
99 if(ret < 0)
100 error(EBOOTFILE, ret);
102 disable_irq(); /* disable irq until we have copied the new vectors */
104 if (ret == EOK)
106 kernel_entry = (void*) loadbuffer;
107 printf("Executing");
108 kernel_entry();
109 printf("ERR: Failed to boot");
112 /* never returns */
113 while(1) ;