Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id: $ |
| 9 | * |
| 10 | * Copyright (C) 2011 by Tomasz Moń |
| 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" |
Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 23 | #include "storage.h" |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 24 | #include "file_internal.h" |
Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 25 | #include "disk.h" |
| 26 | #include "font.h" |
| 27 | #include "backlight.h" |
| 28 | #include "button.h" |
| 29 | #include "common.h" |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 30 | #include "rb-loader.h" |
Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 31 | #include "version.h" |
| 32 | #include "uart-target.h" |
| 33 | #include "power.h" |
Marcin Bukat | 38032a4 | 2013-06-27 14:04:32 +0200 | [diff] [blame] | 34 | #include "loader_strerror.h" |
Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 35 | |
| 36 | extern void show_logo(void); |
| 37 | |
| 38 | void main(void) |
| 39 | { |
| 40 | unsigned char* loadbuffer; |
| 41 | int buffer_size; |
| 42 | int(*kernel_entry)(void); |
| 43 | int ret; |
| 44 | int btn; |
| 45 | |
| 46 | /* Make sure interrupts are disabled */ |
| 47 | set_irq_level(IRQ_DISABLED); |
| 48 | set_fiq_status(FIQ_DISABLED); |
| 49 | system_init(); |
| 50 | kernel_init(); |
| 51 | |
| 52 | /* Now enable interrupts */ |
| 53 | set_irq_level(IRQ_ENABLED); |
| 54 | set_fiq_status(FIQ_ENABLED); |
| 55 | backlight_init(); |
| 56 | lcd_init(); |
| 57 | font_init(); |
| 58 | button_init(); |
| 59 | |
| 60 | #ifdef HAVE_LCD_ENABLE |
| 61 | lcd_enable(true); |
| 62 | #endif |
| 63 | lcd_setfont(FONT_SYSFIXED); |
| 64 | reset_screen(); |
| 65 | show_logo(); |
| 66 | |
| 67 | btn = button_read_device(); |
| 68 | |
| 69 | printf("Rockbox boot loader"); |
Michael Sevakis | 95a4c3a | 2014-08-28 10:26:45 -0400 | [diff] [blame] | 70 | printf("Version %s", rbversion); |
Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 71 | |
| 72 | ret = storage_init(); |
| 73 | if(ret) |
| 74 | printf("SD error: %d", ret); |
| 75 | |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 76 | filesystem_init(); |
Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 77 | |
| 78 | ret = disk_mount_all(); |
| 79 | if (ret <= 0) |
| 80 | error(EDISK, ret, true); |
| 81 | |
| 82 | if (btn & BUTTON_PREV) |
| 83 | { |
| 84 | printf("Loading OF firmware..."); |
| 85 | printf("Loading vmlinux.bin..."); |
| 86 | loadbuffer = (unsigned char*)0x01008000; |
| 87 | buffer_size = 0x200000; |
| 88 | |
| 89 | ret = load_raw_firmware(loadbuffer, "/vmlinux.bin", buffer_size); |
| 90 | |
| 91 | if (ret < 0) |
| 92 | { |
| 93 | printf("Unable to load vmlinux.bin"); |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | printf("Loading initrd.bin..."); |
| 98 | loadbuffer = (unsigned char*)0x04400020; |
| 99 | buffer_size = 0x200000; |
| 100 | ret = load_raw_firmware(loadbuffer, "/initrd.bin", buffer_size); |
| 101 | } |
| 102 | |
| 103 | if (ret > 0) |
| 104 | { |
| 105 | system_prepare_fw_start(); |
| 106 | |
| 107 | kernel_entry = (void*)0x01008000; |
| 108 | ret = kernel_entry(); |
| 109 | printf("FAILED to boot OF"); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | printf("Loading Rockbox firmware..."); |
| 114 | |
| 115 | loadbuffer = (unsigned char*)CONFIG_SDRAM_START; |
| 116 | buffer_size = 0x1000000; |
| 117 | |
| 118 | ret = load_firmware(loadbuffer, BOOTFILE, buffer_size); |
| 119 | |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 120 | if(ret <= EFILE_EMPTY) |
Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 121 | { |
| 122 | error(EBOOTFILE, ret, true); |
| 123 | } |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 124 | else |
Tomasz Moń | e8a8a1b | 2011-11-16 14:08:01 +0000 | [diff] [blame] | 125 | { |
| 126 | system_prepare_fw_start(); |
| 127 | |
| 128 | kernel_entry = (void*) loadbuffer; |
| 129 | ret = kernel_entry(); |
| 130 | printf("FAILED!"); |
| 131 | } |
| 132 | |
| 133 | storage_sleepnow(); |
| 134 | |
| 135 | while(1); |
| 136 | } |