Fix version.sh when it's run outside of the git working directory.
[kugel-rb.git] / bootloader / mrobe500.c
blob9052cbdc3c5c8c1c4afe64d73126dc899fb7ab9c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Karl Kurbjun
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "inttypes.h"
23 #include "string.h"
24 #include "cpu.h"
25 #include "system.h"
26 #include "lcd.h"
27 #include "kernel.h"
28 #include "thread.h"
29 #include "storage.h"
30 #include "fat.h"
31 #include "disk.h"
32 #include "font.h"
33 #include "adc.h"
34 #include "backlight.h"
35 #include "backlight-target.h"
36 #include "button.h"
37 #include "panic.h"
38 #include "power.h"
39 #include "file.h"
40 #include "common.h"
41 #include "rbunicode.h"
42 #include "usb.h"
43 #include "spi.h"
44 #include "uart-target.h"
45 #include "tsc2100.h"
46 #include "time.h"
47 #include "system-arm.h"
49 void main(void)
51 unsigned char* loadbuffer;
52 int buffer_size;
53 int rc;
54 int(*kernel_entry)(void);
56 /* Make sure interrupts are disabled */
57 set_irq_level(IRQ_DISABLED);
58 set_fiq_status(FIQ_DISABLED);
59 system_init();
60 kernel_init();
62 /* Now enable interrupts */
63 set_irq_level(IRQ_ENABLED);
64 set_fiq_status(FIQ_ENABLED);
66 backlight_init();
67 lcd_init();
68 font_init();
69 button_init();
70 usb_init();
73 power_init();
74 // enable_irq();
75 // enable_fiq();
77 adc_init();
79 lcd_setfont(FONT_SYSFIXED);
81 /* Show debug messages if button is pressed */
82 // if(button_read_device())
83 verbose = true;
85 printf("Rockbox boot loader");
86 printf("Version %s", APPSVERSION);
88 /* Enter USB mode without USB thread */
89 if(usb_detect() == USB_INSERTED)
91 const char msg[] = "Bootloader USB mode";
92 reset_screen();
93 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
94 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
95 lcd_update();
97 ide_power_enable(true);
98 storage_enable(false);
99 sleep(HZ/20);
100 usb_enable(true);
102 while (usb_detect() == USB_INSERTED)
104 storage_spin(); /* Prevent the drive from spinning down */
105 sleep(HZ);
108 usb_enable(false);
110 reset_screen();
111 lcd_update();
114 sleep(50);
116 printf("ATA");
117 rc = storage_init();
118 if(rc)
120 reset_screen();
121 error(EATA, rc);
124 printf("disk");
125 disk_init();
127 printf("mount");
128 rc = disk_mount_all();
129 if (rc<=0)
131 error(EDISK,rc);
134 printf("Loading firmware");
136 loadbuffer = (unsigned char*) 0x00900000;
137 buffer_size = (unsigned char*)0x01900000 - loadbuffer;
139 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
140 if(rc < 0)
141 error(EBOOTFILE, rc);
143 if (rc == EOK)
145 kernel_entry = (void*) loadbuffer;
146 rc = kernel_entry();