blob: 1385e47ff6d90faeca7a2998a625378be3aaf237 [file] [log] [blame]
Dave Chapmanda8bff12008-10-12 16:46:01 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Dave Chapman08c41d42008-10-19 14:11:01 +00008 * $Id$
Dave Chapmanda8bff12008-10-12 16:46:01 +00009 *
10 * Copyright (C) 2008 by Rafaël Carré
11 *
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
14 *
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.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#include <stdio.h>
26#include <system.h>
27#include <inttypes.h>
Dave Chapmanda8bff12008-10-12 16:46:01 +000028#include "config.h"
Dave Chapman8df1a7e2008-10-29 01:42:03 +000029#include "lcd.h"
30#include "backlight-target.h"
Bertrik Sikken95726a52008-10-26 13:28:52 +000031#include "as3525-codec.h"
Dave Chapman8df1a7e2008-10-29 01:42:03 +000032#include "common.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000033#include "storage.h"
Rafaël Carréaef27e12008-11-09 06:17:21 +000034#include "disk.h"
35#include "panic.h"
Dave Chapmanda8bff12008-10-12 16:46:01 +000036
37int show_logo(void);
38void main(void)
39{
Rafaël Carréaef27e12008-11-09 06:17:21 +000040 unsigned char* loadbuffer;
41 int buffer_size;
42 void(*kernel_entry)(void);
43 int ret;
44 int delay;
Bertrik Sikken95726a52008-10-26 13:28:52 +000045
Rafaël Carréb3ee07c2008-10-28 11:24:29 +000046 system_init();
Rafaël Carré6e645cc2008-11-06 15:24:19 +000047 kernel_init();
Rafaël Carréb3ee07c2008-10-28 11:24:29 +000048
Dave Chapman8df1a7e2008-10-29 01:42:03 +000049 lcd_init();
Dave Chapmanda8bff12008-10-12 16:46:01 +000050 show_logo();
51
Dave Chapman8df1a7e2008-10-29 01:42:03 +000052 as3525_codec_init(); /* Required for backlight on e200v2 */
Dave Chapman8df1a7e2008-10-29 01:42:03 +000053 _backlight_on();
54
Rafaël Carréaef27e12008-11-09 06:17:21 +000055 delay = 0x3000000;
56 while(delay--); /* show splash screen */
57 reset_screen();
58
59 asm volatile(
60 "mrs r0, cpsr \n"
61 "bic r0, r0, #0x80 \n" /* enable interrupts */
62 "msr cpsr, r0 \n"
63 : : : "r0" );
64
65 ret = storage_init();
66 if(ret < 0)
67 error(EATA,ret);
68
69 if(!disk_init(IF_MV(0)))
70 panicf("disk_init failed!");
71
72 ret = disk_mount_all();
73
74 if(ret <= 0)
75 error(EDISK, ret);
76
77 printf("Loading firmware");
78
79 loadbuffer = (unsigned char*)0x30000000; /* DRAM */
80 buffer_size = (int)(loadbuffer + (MEM * 0x100000));
81
82 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
83 if(ret < 0)
84 error(EBOOTFILE, ret);
85
86 asm volatile(
87 "mrs r0, cpsr \n"
88 "orr r0, r0, #0x80 \n" /* disable interrupts */
89 "msr cpsr, r0 \n"
90 : : : "r0" );
91
92 if (ret == EOK)
93 {
94 kernel_entry = (void*) loadbuffer;
95 printf("Executing");
96 kernel_entry();
97 printf("ERR: Failed to boot");
Bertrik Sikken95726a52008-10-26 13:28:52 +000098 }
Dave Chapmanda8bff12008-10-12 16:46:01 +000099
100 /* never returns */
101 while(1) ;
102}