blob: d59e7e7183e75a1290588b91c1b22227d6da8ab4 [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"
Jonathan Gordonce505b82008-11-11 11:01:55 +000031#include "button-target.h"
Rafaël Carréf7b1d802008-11-10 20:36:02 +000032#include "ascodec-target.h"
Dave Chapman8df1a7e2008-10-29 01:42:03 +000033#include "common.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000034#include "storage.h"
Rafaël Carréaef27e12008-11-09 06:17:21 +000035#include "disk.h"
36#include "panic.h"
Dave Chapmanda8bff12008-10-12 16:46:01 +000037
38int show_logo(void);
39void main(void)
40{
Rafaël Carréaef27e12008-11-09 06:17:21 +000041 unsigned char* loadbuffer;
42 int buffer_size;
43 void(*kernel_entry)(void);
44 int ret;
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
Bertrik Sikken4ca4e522008-11-09 09:25:53 +000052 ascodec_init(); /* Required for backlight on e200v2 */
Dave Chapman8df1a7e2008-10-29 01:42:03 +000053 _backlight_on();
54
Jonathan Gordonce505b82008-11-11 11:01:55 +000055#if 0 /* remove me when the bootloader can be considered finished */
56 int btn = button_read_device();
57
58 /* Enable bootloader messages if any button is pressed */
59 if (btn)
60#endif
61 {
62 lcd_clear_display();
63 verbose = true;
64 }
Rafaël Carréaef27e12008-11-09 06:17:21 +000065
66 asm volatile(
67 "mrs r0, cpsr \n"
68 "bic r0, r0, #0x80 \n" /* enable interrupts */
69 "msr cpsr, r0 \n"
70 : : : "r0" );
71
72 ret = storage_init();
73 if(ret < 0)
74 error(EATA,ret);
75
76 if(!disk_init(IF_MV(0)))
77 panicf("disk_init failed!");
78
79 ret = disk_mount_all();
80
81 if(ret <= 0)
82 error(EDISK, ret);
83
84 printf("Loading firmware");
85
86 loadbuffer = (unsigned char*)0x30000000; /* DRAM */
87 buffer_size = (int)(loadbuffer + (MEM * 0x100000));
88
89 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
90 if(ret < 0)
91 error(EBOOTFILE, ret);
92
93 asm volatile(
94 "mrs r0, cpsr \n"
95 "orr r0, r0, #0x80 \n" /* disable interrupts */
96 "msr cpsr, r0 \n"
97 : : : "r0" );
98
99 if (ret == EOK)
100 {
101 kernel_entry = (void*) loadbuffer;
102 printf("Executing");
103 kernel_entry();
104 printf("ERR: Failed to boot");
Bertrik Sikken95726a52008-10-26 13:28:52 +0000105 }
Dave Chapmanda8bff12008-10-12 16:46:01 +0000106
107 /* never returns */
108 while(1) ;
109}