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