Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 by Karl Kurbjun |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include "inttypes.h" |
| 23 | #include "string.h" |
| 24 | #include "cpu.h" |
| 25 | #include "system.h" |
| 26 | #include "lcd.h" |
Michael Sevakis | 4ea4cdf | 2014-08-08 02:28:11 -0400 | [diff] [blame] | 27 | #include "../kernel-internal.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 28 | #include "storage.h" |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 29 | #include "file_internal.h" |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 30 | #include "disk.h" |
| 31 | #include "font.h" |
| 32 | #include "adc.h" |
| 33 | #include "backlight.h" |
| 34 | #include "backlight-target.h" |
| 35 | #include "button.h" |
| 36 | #include "panic.h" |
| 37 | #include "power.h" |
| 38 | #include "file.h" |
| 39 | #include "common.h" |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 40 | #include "rb-loader.h" |
| 41 | #include "loader_strerror.h" |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 42 | #include "rbunicode.h" |
| 43 | #include "usb.h" |
| 44 | #include "spi.h" |
| 45 | #include "uart-target.h" |
| 46 | #include "tsc2100.h" |
| 47 | #include "time.h" |
| 48 | #include "system-arm.h" |
Rafaël Carré | 5d236b2 | 2010-05-27 09:41:46 +0000 | [diff] [blame] | 49 | #include "version.h" |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 50 | |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 51 | void main(void) |
| 52 | { |
| 53 | unsigned char* loadbuffer; |
| 54 | int buffer_size; |
| 55 | int rc; |
| 56 | int(*kernel_entry)(void); |
| 57 | |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 58 | /* Make sure interrupts are disabled */ |
| 59 | set_irq_level(IRQ_DISABLED); |
| 60 | set_fiq_status(FIQ_DISABLED); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 61 | system_init(); |
| 62 | kernel_init(); |
| 63 | |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 64 | /* Now enable interrupts */ |
| 65 | set_irq_level(IRQ_ENABLED); |
| 66 | set_fiq_status(FIQ_ENABLED); |
| 67 | |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 68 | lcd_init(); |
Karl Kurbjun | fff80b0 | 2011-02-06 21:04:51 +0000 | [diff] [blame] | 69 | backlight_init(); |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 70 | font_init(); |
| 71 | button_init(); |
| 72 | usb_init(); |
| 73 | |
| 74 | |
| 75 | power_init(); |
| 76 | // enable_irq(); |
| 77 | // enable_fiq(); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 78 | |
| 79 | adc_init(); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 80 | |
| 81 | lcd_setfont(FONT_SYSFIXED); |
| 82 | |
| 83 | /* Show debug messages if button is pressed */ |
| 84 | // if(button_read_device()) |
| 85 | verbose = true; |
| 86 | |
| 87 | printf("Rockbox boot loader"); |
Michael Sevakis | 95a4c3a | 2014-08-28 10:26:45 -0400 | [diff] [blame] | 88 | printf("Version %s", rbversion); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 89 | |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 90 | /* Enter USB mode without USB thread */ |
| 91 | if(usb_detect() == USB_INSERTED) |
| 92 | { |
| 93 | const char msg[] = "Bootloader USB mode"; |
| 94 | reset_screen(); |
| 95 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, |
| 96 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); |
| 97 | lcd_update(); |
| 98 | |
| 99 | ide_power_enable(true); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 100 | storage_enable(false); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 101 | sleep(HZ/20); |
| 102 | usb_enable(true); |
| 103 | |
| 104 | while (usb_detect() == USB_INSERTED) |
| 105 | { |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 106 | storage_spin(); /* Prevent the drive from spinning down */ |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 107 | sleep(HZ); |
| 108 | } |
| 109 | |
| 110 | usb_enable(false); |
| 111 | |
| 112 | reset_screen(); |
| 113 | lcd_update(); |
| 114 | } |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 115 | |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 116 | sleep(50); |
| 117 | |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 118 | printf("ATA"); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 119 | rc = storage_init(); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 120 | if(rc) |
| 121 | { |
| 122 | reset_screen(); |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 123 | error(EATA, rc, true); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 126 | printf("filesystem"); |
| 127 | filesystem_init(); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 128 | |
| 129 | printf("mount"); |
| 130 | rc = disk_mount_all(); |
| 131 | if (rc<=0) |
| 132 | { |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 133 | error(EDISK,rc, true); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | printf("Loading firmware"); |
| 137 | |
| 138 | loadbuffer = (unsigned char*) 0x00900000; |
| 139 | buffer_size = (unsigned char*)0x01900000 - loadbuffer; |
| 140 | |
| 141 | rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 142 | if(rc <= EFILE_EMPTY) |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 143 | error(EBOOTFILE, rc, true); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 144 | |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 145 | kernel_entry = (void*) loadbuffer; |
| 146 | rc = kernel_entry(); |
| 147 | |
| 148 | /* Should not get here! */ |
| 149 | return rc; |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 150 | } |