Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2008 by Maurus Cuelenaere |
| 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 | |
| 20 | #include "system.h" |
| 21 | #include "lcd.h" |
| 22 | #include "kernel.h" |
| 23 | #include "thread.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 24 | #include "storage.h" |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 25 | #include "ata-target.h" |
| 26 | #include "disk.h" |
| 27 | #include "font.h" |
| 28 | #include "backlight.h" |
| 29 | #include "button.h" |
| 30 | #include "common.h" |
| 31 | |
| 32 | |
| 33 | static void load_fw(unsigned char* ptr, unsigned int len) |
| 34 | { |
| 35 | (void)ptr; |
| 36 | (void)len; |
| 37 | asm volatile("ldr pc, =0x1EE0000"); |
| 38 | } |
| 39 | |
| 40 | void main(void) |
| 41 | { |
| 42 | unsigned char* loadbuffer; |
| 43 | int buffer_size; |
| 44 | int(*kernel_entry)(void); |
| 45 | int ret; |
| 46 | |
Maurus Cuelenaere | 78d4438 | 2008-08-27 20:35:41 +0000 | [diff] [blame] | 47 | /* Make sure interrupts are disabled */ |
| 48 | set_irq_level(IRQ_DISABLED); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 49 | set_fiq_status(FIQ_DISABLED); |
| 50 | system_init(); |
| 51 | kernel_init(); |
Maurus Cuelenaere | 78d4438 | 2008-08-27 20:35:41 +0000 | [diff] [blame] | 52 | |
| 53 | /* Now enable interrupts */ |
| 54 | set_irq_level(IRQ_ENABLED); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 55 | set_fiq_status(FIQ_ENABLED); |
| 56 | backlight_init(); |
| 57 | lcd_init(); |
| 58 | font_init(); |
| 59 | button_init(); |
| 60 | |
| 61 | lcd_enable(true); |
| 62 | lcd_setfont(FONT_SYSFIXED); |
| 63 | reset_screen(); |
| 64 | printf("Rockbox boot loader"); |
| 65 | printf("Version %s", APPSVERSION); |
| 66 | |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 67 | ret = storage_init(); |
Maurus Cuelenaere | 78d4438 | 2008-08-27 20:35:41 +0000 | [diff] [blame] | 68 | if(ret) |
| 69 | printf("ATA error: %d", ret); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 70 | |
Maurus Cuelenaere | 23fc923 | 2008-09-07 17:24:14 +0000 | [diff] [blame] | 71 | /* If no button is held, start the OF */ |
| 72 | if(button_read_device() == 0) |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 73 | { |
| 74 | printf("Loading Creative firmware..."); |
| 75 | |
| 76 | loadbuffer = (unsigned char*)0x00A00000; |
| 77 | ret = load_minifs_file("creativeos.jrm", loadbuffer); |
| 78 | if(ret != -1) |
| 79 | { |
Maurus Cuelenaere | 78d4438 | 2008-08-27 20:35:41 +0000 | [diff] [blame] | 80 | set_irq_level(IRQ_DISABLED); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 81 | set_fiq_status(FIQ_DISABLED); |
| 82 | /* Doesn't return! */ |
| 83 | load_fw(loadbuffer, ret); |
| 84 | } |
| 85 | else |
| 86 | printf("FAILED!"); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | disk_init(); |
| 91 | |
| 92 | ret = disk_mount_all(); |
| 93 | if (ret <= 0) |
| 94 | error(EDISK, ret); |
| 95 | |
| 96 | printf("Loading Rockbox firmware..."); |
| 97 | |
| 98 | loadbuffer = (unsigned char*)0x00900000; |
| 99 | buffer_size = (unsigned char*)0x01900000 - loadbuffer; |
| 100 | |
| 101 | ret = load_firmware(loadbuffer, BOOTFILE, buffer_size); |
| 102 | if(ret < 0) |
| 103 | error(EBOOTFILE, ret); |
| 104 | |
| 105 | else if(ret == EOK) |
| 106 | { |
| 107 | kernel_entry = (void*) loadbuffer; |
| 108 | ret = kernel_entry(); |
| 109 | printf("FAILED!"); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | while(1); |
| 114 | } |