Rework and improve http download cache: check cache against file on the server and...
[Rockbox.git] / bootloader / gigabeat.c
blobac560afd6440fc764af485ac38749dceb1e6b0ba
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Greg White
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "inttypes.h"
24 #include "string.h"
25 #include "cpu.h"
26 #include "system.h"
27 #include "lcd.h"
28 #include "kernel.h"
29 #include "thread.h"
30 #include "ata.h"
31 #include "fat.h"
32 #include "disk.h"
33 #include "font.h"
34 #include "adc.h"
35 #include "backlight.h"
36 #include "backlight-target.h"
37 #include "button.h"
38 #include "panic.h"
39 #include "power.h"
40 #include "file.h"
41 #include "common.h"
42 #include "rbunicode.h"
43 #include "usb.h"
44 #include "mmu-arm.h"
46 #include <stdarg.h>
48 char version[] = APPSVERSION;
50 void main(void)
52 unsigned char* loadbuffer;
53 int buffer_size;
54 int rc;
55 int(*kernel_entry)(void);
57 power_init();
58 system_init();
59 lcd_init();
60 backlight_init();
61 font_init();
63 lcd_setfont(FONT_SYSFIXED);
65 usb_init();
67 /* Enter USB mode without USB thread */
68 if(usb_detect() == USB_INSERTED)
70 const char msg[] = "Bootloader USB mode";
71 reset_screen();
72 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
73 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
74 lcd_update();
76 ata_enable(false);
77 sleep(HZ/20);
78 usb_enable(true);
80 while (usb_detect() == USB_INSERTED)
81 sleep(HZ);
83 usb_enable(false);
85 reset_screen();
86 lcd_update();
89 kernel_init();
90 adc_init();
91 button_init();
93 /* Show debug messages if button is pressed */
94 if(button_read_device())
95 verbose = true;
97 printf("Rockbox boot loader");
98 printf("Version %s", version);
100 sleep(50); /* ATA seems to error without this pause */
102 rc = ata_init();
103 if(rc)
105 reset_screen();
106 error(EATA, rc);
109 disk_init();
111 rc = disk_mount_all();
112 if (rc<=0)
114 error(EDISK,rc);
117 printf("Loading firmware");
119 loadbuffer = (unsigned char*) 0x31000000;
120 buffer_size = (unsigned char*)0x31400000 - loadbuffer;
122 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
123 if(rc < 0)
124 error(EBOOTFILE, rc);
126 if (rc == EOK)
128 kernel_entry = (void*) loadbuffer;
129 rc = kernel_entry();