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" |
| 27 | #include "kernel.h" |
| 28 | #include "thread.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 29 | #include "storage.h" |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 30 | #include "fat.h" |
| 31 | #include "disk.h" |
| 32 | #include "font.h" |
| 33 | #include "adc.h" |
| 34 | #include "backlight.h" |
| 35 | #include "backlight-target.h" |
| 36 | #include "button.h" |
| 37 | #include "panic.h" |
| 38 | #include "power.h" |
| 39 | #include "file.h" |
| 40 | #include "common.h" |
| 41 | #include "rbunicode.h" |
| 42 | #include "usb.h" |
| 43 | #include "spi.h" |
| 44 | #include "uart-target.h" |
| 45 | #include "tsc2100.h" |
| 46 | #include "time.h" |
| 47 | #include "system-arm.h" |
Rafaël Carré | 5d236b2 | 2010-05-27 09:41:46 +0000 | [diff] [blame] | 48 | #include "version.h" |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 49 | |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 50 | void main(void) |
| 51 | { |
| 52 | unsigned char* loadbuffer; |
| 53 | int buffer_size; |
| 54 | int rc; |
| 55 | int(*kernel_entry)(void); |
| 56 | |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 57 | /* Make sure interrupts are disabled */ |
| 58 | set_irq_level(IRQ_DISABLED); |
| 59 | set_fiq_status(FIQ_DISABLED); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 60 | system_init(); |
| 61 | kernel_init(); |
| 62 | |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 63 | /* Now enable interrupts */ |
| 64 | set_irq_level(IRQ_ENABLED); |
| 65 | set_fiq_status(FIQ_ENABLED); |
| 66 | |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 67 | lcd_init(); |
Karl Kurbjun | fff80b0 | 2011-02-06 21:04:51 +0000 | [diff] [blame] | 68 | backlight_init(); |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 69 | font_init(); |
| 70 | button_init(); |
| 71 | usb_init(); |
| 72 | |
| 73 | |
| 74 | power_init(); |
| 75 | // enable_irq(); |
| 76 | // enable_fiq(); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 77 | |
| 78 | adc_init(); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 79 | |
| 80 | lcd_setfont(FONT_SYSFIXED); |
| 81 | |
| 82 | /* Show debug messages if button is pressed */ |
| 83 | // if(button_read_device()) |
| 84 | verbose = true; |
| 85 | |
| 86 | printf("Rockbox boot loader"); |
Rafaël Carré | 5d236b2 | 2010-05-27 09:41:46 +0000 | [diff] [blame] | 87 | printf("Version " RBVERSION); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 88 | |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 89 | /* Enter USB mode without USB thread */ |
| 90 | if(usb_detect() == USB_INSERTED) |
| 91 | { |
| 92 | const char msg[] = "Bootloader USB mode"; |
| 93 | reset_screen(); |
| 94 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, |
| 95 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); |
| 96 | lcd_update(); |
| 97 | |
| 98 | ide_power_enable(true); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 99 | storage_enable(false); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 100 | sleep(HZ/20); |
| 101 | usb_enable(true); |
| 102 | |
| 103 | while (usb_detect() == USB_INSERTED) |
| 104 | { |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 105 | storage_spin(); /* Prevent the drive from spinning down */ |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 106 | sleep(HZ); |
| 107 | } |
| 108 | |
| 109 | usb_enable(false); |
| 110 | |
| 111 | reset_screen(); |
| 112 | lcd_update(); |
| 113 | } |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 114 | |
Karl Kurbjun | 9e1d00c | 2009-02-26 21:24:40 +0000 | [diff] [blame] | 115 | sleep(50); |
| 116 | |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 117 | printf("ATA"); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 118 | rc = storage_init(); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 119 | if(rc) |
| 120 | { |
| 121 | reset_screen(); |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 122 | error(EATA, rc, true); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | printf("disk"); |
| 126 | disk_init(); |
| 127 | |
| 128 | printf("mount"); |
| 129 | rc = disk_mount_all(); |
| 130 | if (rc<=0) |
| 131 | { |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 132 | error(EDISK,rc, true); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | printf("Loading firmware"); |
| 136 | |
| 137 | loadbuffer = (unsigned char*) 0x00900000; |
| 138 | buffer_size = (unsigned char*)0x01900000 - loadbuffer; |
| 139 | |
| 140 | rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); |
| 141 | if(rc < 0) |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 142 | error(EBOOTFILE, rc, true); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 143 | |
| 144 | if (rc == EOK) |
| 145 | { |
| 146 | kernel_entry = (void*) loadbuffer; |
| 147 | rc = kernel_entry(); |
| 148 | } |
| 149 | } |