blob: 6da546fcacfed28d15dfe4fef590a85d6e2bdb06 [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
Rafaël Carré2b39cb42008-11-25 15:43:38 +000055 button_init_device();
Jonathan Gordonce505b82008-11-11 11:01:55 +000056 int btn = button_read_device();
57
58 /* Enable bootloader messages if any button is pressed */
59 if (btn)
Jonathan Gordonce505b82008-11-11 11:01:55 +000060 {
61 lcd_clear_display();
62 verbose = true;
63 }
Rafaël Carréaef27e12008-11-09 06:17:21 +000064
Rafaël Carré2b39cb42008-11-25 15:43:38 +000065 enable_irq();
Rafaël Carréaef27e12008-11-09 06:17:21 +000066
67 ret = storage_init();
68 if(ret < 0)
69 error(EATA,ret);
70
71 if(!disk_init(IF_MV(0)))
72 panicf("disk_init failed!");
73
74 ret = disk_mount_all();
75
76 if(ret <= 0)
77 error(EDISK, ret);
78
79 printf("Loading firmware");
80
81 loadbuffer = (unsigned char*)0x30000000; /* DRAM */
82 buffer_size = (int)(loadbuffer + (MEM * 0x100000));
83
84 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
85 if(ret < 0)
86 error(EBOOTFILE, ret);
87
Rafaël Carré2b39cb42008-11-25 15:43:38 +000088 disable_irq(); /* disable irq until we have copied the new vectors */
Rafaël Carréaef27e12008-11-09 06:17:21 +000089
90 if (ret == EOK)
91 {
92 kernel_entry = (void*) loadbuffer;
93 printf("Executing");
94 kernel_entry();
95 printf("ERR: Failed to boot");
Bertrik Sikken95726a52008-10-26 13:28:52 +000096 }
Dave Chapmanda8bff12008-10-12 16:46:01 +000097
98 /* never returns */
99 while(1) ;
100}