blob: ac560afd6440fc764af485ac38749dceb1e6b0ba [file] [log] [blame]
Linus Nielsen Feltzingc5df4f82007-02-23 09:30:09 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Greg White
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
Marcoen Hirschberg0a068242006-08-12 08:27:48 +000019#include "config.h"
20
21#include <stdlib.h>
22#include <stdio.h>
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000023#include "inttypes.h"
24#include "string.h"
Marcoen Hirschberg0a068242006-08-12 08:27:48 +000025#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"
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000036#include "backlight-target.h"
37#include "button.h"
Marcoen Hirschberg0a068242006-08-12 08:27:48 +000038#include "panic.h"
39#include "power.h"
40#include "file.h"
Linus Nielsen Feltzing46597c92007-02-22 15:09:49 +000041#include "common.h"
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000042#include "rbunicode.h"
43#include "usb.h"
Karl Kurbjun5a9a2b72007-10-23 03:29:15 +000044#include "mmu-arm.h"
Marcoen Hirschberg29536762006-12-29 02:49:12 +000045
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000046#include <stdarg.h>
Marcoen Hirschberg29536762006-12-29 02:49:12 +000047
Marcoen Hirschberg0a068242006-08-12 08:27:48 +000048char version[] = APPSVERSION;
49
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000050void main(void)
Marcoen Hirschberg29536762006-12-29 02:49:12 +000051{
Marcoen Hirschberg29536762006-12-29 02:49:12 +000052 unsigned char* loadbuffer;
53 int buffer_size;
Marcoen Hirschberg29536762006-12-29 02:49:12 +000054 int rc;
55 int(*kernel_entry)(void);
Marcoen Hirschberg0a068242006-08-12 08:27:48 +000056
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000057 power_init();
58 system_init();
59 lcd_init();
60 backlight_init();
61 font_init();
Marcoen Hirschberg0a068242006-08-12 08:27:48 +000062
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000063 lcd_setfont(FONT_SYSFIXED);
Marcoen Hirschberg0a068242006-08-12 08:27:48 +000064
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000065 usb_init();
66
67 /* Enter USB mode without USB thread */
Dave Chapman16723502007-09-04 08:03:07 +000068 if(usb_detect() == USB_INSERTED)
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000069 {
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();
75
76 ata_enable(false);
77 sleep(HZ/20);
78 usb_enable(true);
79
Dave Chapman16723502007-09-04 08:03:07 +000080 while (usb_detect() == USB_INSERTED)
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000081 sleep(HZ);
82
83 usb_enable(false);
84
85 reset_screen();
86 lcd_update();
Greg White3b65fc22007-01-17 18:31:40 +000087 }
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000088
89 kernel_init();
90 adc_init();
91 button_init();
92
93 /* Show debug messages if button is pressed */
94 if(button_read_device())
95 verbose = true;
96
97 printf("Rockbox boot loader");
98 printf("Version %s", version);
99
Karl Kurbjun75103352008-04-22 04:34:25 +0000100 sleep(50); /* ATA seems to error without this pause */
101
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +0000102 rc = ata_init();
103 if(rc)
104 {
105 reset_screen();
106 error(EATA, rc);
Greg White8b3c8792007-01-17 01:49:19 +0000107 }
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000108
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +0000109 disk_init();
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000110
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +0000111 rc = disk_mount_all();
112 if (rc<=0)
113 {
114 error(EDISK,rc);
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000115 }
116
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +0000117 printf("Loading firmware");
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000118
Karl Kurbjun75103352008-04-22 04:34:25 +0000119 loadbuffer = (unsigned char*) 0x31000000;
120 buffer_size = (unsigned char*)0x31400000 - loadbuffer;
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +0000121
122 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
123 if(rc < 0)
124 error(EBOOTFILE, rc);
125
126 if (rc == EOK)
127 {
Greg White355be502007-01-13 02:24:15 +0000128 kernel_entry = (void*) loadbuffer;
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000129 rc = kernel_entry();
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000130 }
Marcoen Hirschberg0a068242006-08-12 08:27:48 +0000131}
132