Linus Nielsen Feltzing | c5df4f8 | 2007-02-23 09:30:09 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Greg White |
| 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 | ****************************************************************************/ |
Marcoen Hirschberg | 0a06824 | 2006-08-12 08:27:48 +0000 | [diff] [blame] | 19 | #include "config.h" |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 23 | #include "inttypes.h" |
| 24 | #include "string.h" |
Marcoen Hirschberg | 0a06824 | 2006-08-12 08:27:48 +0000 | [diff] [blame] | 25 | #include "cpu.h" |
| 26 | #include "system.h" |
| 27 | #include "lcd.h" |
| 28 | #include "kernel.h" |
| 29 | #include "thread.h" |
| 30 | #include "ata.h" |
| 31 | #include "fat.h" |
| 32 | #include "disk.h" |
| 33 | #include "font.h" |
| 34 | #include "adc.h" |
| 35 | #include "backlight.h" |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 36 | #include "backlight-target.h" |
| 37 | #include "button.h" |
Marcoen Hirschberg | 0a06824 | 2006-08-12 08:27:48 +0000 | [diff] [blame] | 38 | #include "panic.h" |
| 39 | #include "power.h" |
| 40 | #include "file.h" |
Linus Nielsen Feltzing | 46597c9 | 2007-02-22 15:09:49 +0000 | [diff] [blame] | 41 | #include "common.h" |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 42 | #include "rbunicode.h" |
| 43 | #include "usb.h" |
Karl Kurbjun | 5a9a2b7 | 2007-10-23 03:29:15 +0000 | [diff] [blame] | 44 | #include "mmu-arm.h" |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 45 | |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 46 | #include <stdarg.h> |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 47 | |
Marcoen Hirschberg | 0a06824 | 2006-08-12 08:27:48 +0000 | [diff] [blame] | 48 | char version[] = APPSVERSION; |
| 49 | |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 50 | void main(void) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 51 | { |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 52 | unsigned char* loadbuffer; |
| 53 | int buffer_size; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 54 | int rc; |
| 55 | int(*kernel_entry)(void); |
Marcoen Hirschberg | 0a06824 | 2006-08-12 08:27:48 +0000 | [diff] [blame] | 56 | |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 57 | memory_init(); |
| 58 | power_init(); |
| 59 | system_init(); |
| 60 | lcd_init(); |
| 61 | backlight_init(); |
| 62 | font_init(); |
Marcoen Hirschberg | 0a06824 | 2006-08-12 08:27:48 +0000 | [diff] [blame] | 63 | |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 64 | lcd_setfont(FONT_SYSFIXED); |
Marcoen Hirschberg | 0a06824 | 2006-08-12 08:27:48 +0000 | [diff] [blame] | 65 | |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 66 | usb_init(); |
| 67 | |
| 68 | /* Enter USB mode without USB thread */ |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 69 | if(usb_detect() == USB_INSERTED) |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 70 | { |
| 71 | const char msg[] = "Bootloader USB mode"; |
| 72 | reset_screen(); |
| 73 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, |
| 74 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); |
| 75 | lcd_update(); |
| 76 | |
| 77 | ata_enable(false); |
| 78 | sleep(HZ/20); |
| 79 | usb_enable(true); |
| 80 | |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 81 | while (usb_detect() == USB_INSERTED) |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 82 | sleep(HZ); |
| 83 | |
| 84 | usb_enable(false); |
| 85 | |
| 86 | reset_screen(); |
| 87 | lcd_update(); |
Greg White | 3b65fc2 | 2007-01-17 18:31:40 +0000 | [diff] [blame] | 88 | } |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 89 | |
| 90 | kernel_init(); |
| 91 | adc_init(); |
| 92 | button_init(); |
| 93 | |
| 94 | /* Show debug messages if button is pressed */ |
| 95 | if(button_read_device()) |
| 96 | verbose = true; |
| 97 | |
| 98 | printf("Rockbox boot loader"); |
| 99 | printf("Version %s", version); |
| 100 | |
| 101 | rc = ata_init(); |
| 102 | if(rc) |
| 103 | { |
| 104 | reset_screen(); |
| 105 | error(EATA, rc); |
Greg White | 8b3c879 | 2007-01-17 01:49:19 +0000 | [diff] [blame] | 106 | } |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 107 | |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 108 | disk_init(); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 109 | |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 110 | rc = disk_mount_all(); |
| 111 | if (rc<=0) |
| 112 | { |
| 113 | error(EDISK,rc); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 116 | printf("Loading firmware"); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 117 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 118 | loadbuffer = (unsigned char*) 0x100; |
| 119 | buffer_size = (unsigned char*)0x400000 - loadbuffer; |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 120 | |
| 121 | rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); |
| 122 | if(rc < 0) |
| 123 | error(EBOOTFILE, rc); |
| 124 | |
| 125 | if (rc == EOK) |
| 126 | { |
Greg White | 355be50 | 2007-01-13 02:24:15 +0000 | [diff] [blame] | 127 | kernel_entry = (void*) loadbuffer; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 128 | rc = kernel_entry(); |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 129 | } |
Marcoen Hirschberg | 0a06824 | 2006-08-12 08:27:48 +0000 | [diff] [blame] | 130 | } |
| 131 | |