blob: f3e2917131f436704a42f449cc71dae0bcb877f8 [file] [log] [blame]
Will Robertson590501c2007-09-21 15:51:53 +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 ****************************************************************************/
19#include "config.h"
20
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"
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +000031#include "dir.h"
Will Robertson590501c2007-09-21 15:51:53 +000032#include "fat.h"
33#include "disk.h"
34#include "font.h"
35#include "adc.h"
36#include "backlight.h"
37#include "backlight-target.h"
38#include "button.h"
39#include "panic.h"
40#include "power.h"
41#include "file.h"
42#include "common.h"
43#include "rbunicode.h"
44#include "usb.h"
45#include "mmu-imx31.h"
46#include "lcd-target.h"
47#include "avic-imx31.h"
48#include <stdarg.h>
49
50char version[] = APPSVERSION;
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +000051char buf[MAX_PATH];
52char basedir[] = "/Content/0b00/00/"; /* Where files sent via MTP are stored */
53char model[5];
54int (*kernel_entry)(void);
Michael Sevakisa07c0342008-02-08 02:20:05 +000055extern void reference_system_c(void);
56
57/* Dummy stub that creates C references for C functions only used by
58 assembly - never called */
59void reference_files(void)
60{
61 reference_system_c();
62}
Will Robertson590501c2007-09-21 15:51:53 +000063
64void main(void)
65{
66 lcd_clear_display();
67 printf("Hello world!");
Michael Sevakisa07c0342008-02-08 02:20:05 +000068 printf("Gigabeat S Rockbox Bootloader v.00000003");
69 system_init();
Will Robertson590501c2007-09-21 15:51:53 +000070 kernel_init();
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +000071 printf("kernel init done");
Will Robertson590501c2007-09-21 15:51:53 +000072 int rc;
73
Michael Sevakisa07c0342008-02-08 02:20:05 +000074 set_interrupt_status(IRQ_FIQ_ENABLED, IRQ_FIQ_STATUS);
75
Will Robertson590501c2007-09-21 15:51:53 +000076 rc = ata_init();
77 if(rc)
78 {
79 reset_screen();
80 error(EATA, rc);
81 }
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +000082 printf("ata init done");
Will Robertson590501c2007-09-21 15:51:53 +000083
84 disk_init();
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +000085 printf("disk init done");
Will Robertson590501c2007-09-21 15:51:53 +000086
87 rc = disk_mount_all();
88 if (rc<=0)
89 {
90 error(EDISK,rc);
91 }
92
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +000093 /* Look for the first valid firmware file */
94 struct dirent_uncached* entry;
95 DIR_UNCACHED* dir;
96 int fd;
97 dir = opendir_uncached(basedir);
98 while ((entry = readdir_uncached(dir)))
99 {
100 if (*entry->d_name != '.')
101 {
102 snprintf(buf, sizeof(buf), "%s%s", basedir, entry->d_name);
103 fd = open(buf, O_RDONLY);
104 if (fd >= 0)
105 {
106 lseek(fd, 4, SEEK_SET);
107 rc = read(fd, model, 4);
108 close(fd);
109 if (rc == 4)
110 {
111 model[4] = 0;
112 if (strcmp(model, "gigs") == 0)
113 break;
114 }
115 }
116 }
117 }
Will Robertson590501c2007-09-21 15:51:53 +0000118
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +0000119 printf("Firmware file: %s", buf);
Will Robertson590501c2007-09-21 15:51:53 +0000120 printf("Loading firmware");
121
Will Robertson32f61092007-12-23 12:19:40 +0000122 unsigned char *loadbuffer = (unsigned char *)0x0;
Michael Sevakisa07c0342008-02-08 02:20:05 +0000123 int buffer_size = 31*1024*1024;
Will Robertson590501c2007-09-21 15:51:53 +0000124
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +0000125 rc = load_firmware(loadbuffer, buf, buffer_size);
Will Robertson590501c2007-09-21 15:51:53 +0000126 if(rc < 0)
Michael Sevakisa07c0342008-02-08 02:20:05 +0000127 error((int)buf, rc);
128
129 system_prepare_fw_start();
Will Robertson590501c2007-09-21 15:51:53 +0000130
131 if (rc == EOK)
132 {
133 kernel_entry = (void*) loadbuffer;
Michael Sevakis1f021af2008-02-05 04:43:19 +0000134 invalidate_icache();
Will Robertson590501c2007-09-21 15:51:53 +0000135 rc = kernel_entry();
136 }
Nicolas Pennequinc2ca8c72007-11-27 15:40:29 +0000137
138 while (1);
Will Robertson590501c2007-09-21 15:51:53 +0000139}
140