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" |
Michael Sevakis | 4ea4cdf | 2014-08-08 02:28:11 -0400 | [diff] [blame] | 22 | #include "../kernel-internal.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 23 | #include "storage.h" |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 24 | #include "ata-target.h" |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 25 | #include "file_internal.h" |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 26 | #include "disk.h" |
| 27 | #include "font.h" |
| 28 | #include "backlight.h" |
| 29 | #include "button.h" |
| 30 | #include "common.h" |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 31 | #include "loader_strerror.h" |
| 32 | #include "rb-loader.h" |
Maurus Cuelenaere | ee1e8be | 2009-02-05 21:47:54 +0000 | [diff] [blame] | 33 | #include "usb.h" |
Rafaël Carré | 5d236b2 | 2010-05-27 09:41:46 +0000 | [diff] [blame] | 34 | #include "version.h" |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | static void load_fw(unsigned char* ptr, unsigned int len) |
| 38 | { |
| 39 | (void)ptr; |
| 40 | (void)len; |
| 41 | asm volatile("ldr pc, =0x1EE0000"); |
| 42 | } |
| 43 | |
| 44 | void main(void) |
| 45 | { |
| 46 | unsigned char* loadbuffer; |
| 47 | int buffer_size; |
| 48 | int(*kernel_entry)(void); |
| 49 | int ret; |
| 50 | |
Maurus Cuelenaere | 78d4438 | 2008-08-27 20:35:41 +0000 | [diff] [blame] | 51 | /* Make sure interrupts are disabled */ |
| 52 | set_irq_level(IRQ_DISABLED); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 53 | set_fiq_status(FIQ_DISABLED); |
| 54 | system_init(); |
| 55 | kernel_init(); |
Maurus Cuelenaere | 78d4438 | 2008-08-27 20:35:41 +0000 | [diff] [blame] | 56 | |
| 57 | /* Now enable interrupts */ |
| 58 | set_irq_level(IRQ_ENABLED); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 59 | set_fiq_status(FIQ_ENABLED); |
| 60 | backlight_init(); |
| 61 | lcd_init(); |
| 62 | font_init(); |
| 63 | button_init(); |
Maurus Cuelenaere | ee1e8be | 2009-02-05 21:47:54 +0000 | [diff] [blame] | 64 | usb_init(); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 65 | |
Thomas Martitz | b5e6eec | 2009-03-17 21:23:02 +0000 | [diff] [blame] | 66 | #ifdef HAVE_LCD_ENABLE |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 67 | lcd_enable(true); |
Thomas Martitz | b5e6eec | 2009-03-17 21:23:02 +0000 | [diff] [blame] | 68 | #endif |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 69 | lcd_setfont(FONT_SYSFIXED); |
| 70 | reset_screen(); |
| 71 | printf("Rockbox boot loader"); |
Michael Sevakis | 95a4c3a | 2014-08-28 10:26:45 -0400 | [diff] [blame] | 72 | printf("Version %s", rbversion); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 73 | |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 74 | ret = storage_init(); |
Maurus Cuelenaere | 78d4438 | 2008-08-27 20:35:41 +0000 | [diff] [blame] | 75 | if(ret) |
| 76 | printf("ATA error: %d", ret); |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 77 | |
| 78 | filesystem_init(); |
Maurus Cuelenaere | ee1e8be | 2009-02-05 21:47:54 +0000 | [diff] [blame] | 79 | |
Maurus Cuelenaere | 23fc923 | 2008-09-07 17:24:14 +0000 | [diff] [blame] | 80 | /* If no button is held, start the OF */ |
| 81 | if(button_read_device() == 0) |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 82 | { |
| 83 | printf("Loading Creative firmware..."); |
| 84 | |
| 85 | loadbuffer = (unsigned char*)0x00A00000; |
| 86 | ret = load_minifs_file("creativeos.jrm", loadbuffer); |
| 87 | if(ret != -1) |
| 88 | { |
Maurus Cuelenaere | 78d4438 | 2008-08-27 20:35:41 +0000 | [diff] [blame] | 89 | set_irq_level(IRQ_DISABLED); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 90 | set_fiq_status(FIQ_DISABLED); |
| 91 | /* Doesn't return! */ |
| 92 | load_fw(loadbuffer, ret); |
| 93 | } |
| 94 | else |
| 95 | printf("FAILED!"); |
| 96 | } |
| 97 | else |
| 98 | { |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 99 | ret = disk_mount_all(); |
| 100 | if (ret <= 0) |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 101 | error(EDISK, ret, true); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 102 | |
| 103 | printf("Loading Rockbox firmware..."); |
| 104 | |
| 105 | loadbuffer = (unsigned char*)0x00900000; |
| 106 | buffer_size = (unsigned char*)0x01900000 - loadbuffer; |
| 107 | |
| 108 | ret = load_firmware(loadbuffer, BOOTFILE, buffer_size); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 109 | if(ret <= EFILE_EMPTY) |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 110 | error(EBOOTFILE, ret, true); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 111 | |
| 112 | kernel_entry = (void*) loadbuffer; |
| 113 | ret = kernel_entry(); |
| 114 | printf("FAILED!"); |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Maurus Cuelenaere | ee1e8be | 2009-02-05 21:47:54 +0000 | [diff] [blame] | 117 | storage_sleepnow(); |
| 118 | |
Maurus Cuelenaere | 944c334 | 2008-08-27 20:32:12 +0000 | [diff] [blame] | 119 | while(1); |
| 120 | } |