Dave Chapman | da8bff1 | 2008-10-12 16:46:01 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Dave Chapman | 08c41d4 | 2008-10-19 14:11:01 +0000 | [diff] [blame] | 8 | * $Id$ |
Dave Chapman | da8bff1 | 2008-10-12 16:46:01 +0000 | [diff] [blame] | 9 | * |
| 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 Chapman | da8bff1 | 2008-10-12 16:46:01 +0000 | [diff] [blame] | 28 | #include "config.h" |
Dave Chapman | 8df1a7e | 2008-10-29 01:42:03 +0000 | [diff] [blame] | 29 | #include "lcd.h" |
| 30 | #include "backlight-target.h" |
Jonathan Gordon | ce505b8 | 2008-11-11 11:01:55 +0000 | [diff] [blame] | 31 | #include "button-target.h" |
Rafaël Carré | f7b1d80 | 2008-11-10 20:36:02 +0000 | [diff] [blame] | 32 | #include "ascodec-target.h" |
Dave Chapman | 8df1a7e | 2008-10-29 01:42:03 +0000 | [diff] [blame] | 33 | #include "common.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 34 | #include "storage.h" |
Rafaël Carré | aef27e1 | 2008-11-09 06:17:21 +0000 | [diff] [blame] | 35 | #include "disk.h" |
| 36 | #include "panic.h" |
Dave Chapman | da8bff1 | 2008-10-12 16:46:01 +0000 | [diff] [blame] | 37 | |
| 38 | int show_logo(void); |
| 39 | void main(void) |
| 40 | { |
Rafaël Carré | aef27e1 | 2008-11-09 06:17:21 +0000 | [diff] [blame] | 41 | unsigned char* loadbuffer; |
| 42 | int buffer_size; |
| 43 | void(*kernel_entry)(void); |
| 44 | int ret; |
Bertrik Sikken | 95726a5 | 2008-10-26 13:28:52 +0000 | [diff] [blame] | 45 | |
Rafaël Carré | b3ee07c | 2008-10-28 11:24:29 +0000 | [diff] [blame] | 46 | system_init(); |
Rafaël Carré | 6e645cc | 2008-11-06 15:24:19 +0000 | [diff] [blame] | 47 | kernel_init(); |
Rafaël Carré | b3ee07c | 2008-10-28 11:24:29 +0000 | [diff] [blame] | 48 | |
Dave Chapman | 8df1a7e | 2008-10-29 01:42:03 +0000 | [diff] [blame] | 49 | lcd_init(); |
Dave Chapman | da8bff1 | 2008-10-12 16:46:01 +0000 | [diff] [blame] | 50 | show_logo(); |
| 51 | |
Bertrik Sikken | 4ca4e52 | 2008-11-09 09:25:53 +0000 | [diff] [blame] | 52 | ascodec_init(); /* Required for backlight on e200v2 */ |
Dave Chapman | 8df1a7e | 2008-10-29 01:42:03 +0000 | [diff] [blame] | 53 | _backlight_on(); |
| 54 | |
Rafaël Carré | 2b39cb4 | 2008-11-25 15:43:38 +0000 | [diff] [blame] | 55 | button_init_device(); |
Jonathan Gordon | ce505b8 | 2008-11-11 11:01:55 +0000 | [diff] [blame] | 56 | int btn = button_read_device(); |
| 57 | |
| 58 | /* Enable bootloader messages if any button is pressed */ |
| 59 | if (btn) |
Jonathan Gordon | ce505b8 | 2008-11-11 11:01:55 +0000 | [diff] [blame] | 60 | { |
| 61 | lcd_clear_display(); |
| 62 | verbose = true; |
| 63 | } |
Rafaël Carré | aef27e1 | 2008-11-09 06:17:21 +0000 | [diff] [blame] | 64 | |
Rafaël Carré | 2b39cb4 | 2008-11-25 15:43:38 +0000 | [diff] [blame] | 65 | enable_irq(); |
Rafaël Carré | aef27e1 | 2008-11-09 06:17:21 +0000 | [diff] [blame] | 66 | |
| 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é | 2b39cb4 | 2008-11-25 15:43:38 +0000 | [diff] [blame] | 88 | disable_irq(); /* disable irq until we have copied the new vectors */ |
Rafaël Carré | aef27e1 | 2008-11-09 06:17:21 +0000 | [diff] [blame] | 89 | |
| 90 | if (ret == EOK) |
| 91 | { |
| 92 | kernel_entry = (void*) loadbuffer; |
| 93 | printf("Executing"); |
| 94 | kernel_entry(); |
| 95 | printf("ERR: Failed to boot"); |
Bertrik Sikken | 95726a5 | 2008-10-26 13:28:52 +0000 | [diff] [blame] | 96 | } |
Dave Chapman | da8bff1 | 2008-10-12 16:46:01 +0000 | [diff] [blame] | 97 | |
| 98 | /* never returns */ |
| 99 | while(1) ; |
| 100 | } |