Will Robertson | 590501c | 2007-09-21 15:51:53 +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 | ****************************************************************************/ |
| 19 | #include "config.h" |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | #include "inttypes.h" |
| 24 | #include "string.h" |
| 25 | #include "cpu.h" |
| 26 | #include "system.h" |
| 27 | #include "lcd.h" |
| 28 | #include "kernel.h" |
| 29 | #include "thread.h" |
| 30 | #include "ata.h" |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 31 | #include "dir.h" |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 32 | #include "fat.h" |
| 33 | #include "disk.h" |
| 34 | #include "font.h" |
| 35 | #include "adc.h" |
| 36 | #include "backlight.h" |
| 37 | #include "backlight-target.h" |
| 38 | #include "button.h" |
| 39 | #include "panic.h" |
| 40 | #include "power.h" |
| 41 | #include "file.h" |
| 42 | #include "common.h" |
| 43 | #include "rbunicode.h" |
| 44 | #include "usb.h" |
| 45 | #include "mmu-imx31.h" |
| 46 | #include "lcd-target.h" |
| 47 | #include "avic-imx31.h" |
| 48 | #include <stdarg.h> |
| 49 | |
| 50 | char version[] = APPSVERSION; |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 51 | char buf[MAX_PATH]; |
| 52 | char basedir[] = "/Content/0b00/00/"; /* Where files sent via MTP are stored */ |
| 53 | char model[5]; |
| 54 | int (*kernel_entry)(void); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 55 | |
| 56 | void main(void) |
| 57 | { |
| 58 | lcd_clear_display(); |
| 59 | printf("Hello world!"); |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 60 | printf("Gigabeat S Rockbox Bootloader v.00000001"); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 61 | kernel_init(); |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 62 | printf("kernel init done"); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 63 | int rc; |
| 64 | |
| 65 | rc = ata_init(); |
| 66 | if(rc) |
| 67 | { |
| 68 | reset_screen(); |
| 69 | error(EATA, rc); |
| 70 | } |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 71 | printf("ata init done"); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 72 | |
| 73 | disk_init(); |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 74 | printf("disk init done"); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 75 | |
| 76 | rc = disk_mount_all(); |
| 77 | if (rc<=0) |
| 78 | { |
| 79 | error(EDISK,rc); |
| 80 | } |
| 81 | |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 82 | /* Look for the first valid firmware file */ |
| 83 | struct dirent_uncached* entry; |
| 84 | DIR_UNCACHED* dir; |
| 85 | int fd; |
| 86 | dir = opendir_uncached(basedir); |
| 87 | while ((entry = readdir_uncached(dir))) |
| 88 | { |
| 89 | if (*entry->d_name != '.') |
| 90 | { |
| 91 | snprintf(buf, sizeof(buf), "%s%s", basedir, entry->d_name); |
| 92 | fd = open(buf, O_RDONLY); |
| 93 | if (fd >= 0) |
| 94 | { |
| 95 | lseek(fd, 4, SEEK_SET); |
| 96 | rc = read(fd, model, 4); |
| 97 | close(fd); |
| 98 | if (rc == 4) |
| 99 | { |
| 100 | model[4] = 0; |
| 101 | if (strcmp(model, "gigs") == 0) |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 107 | |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 108 | printf("Firmware file: %s", buf); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 109 | printf("Loading firmware"); |
| 110 | |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 111 | unsigned char *loadbuffer = (unsigned char *)0x88000000; |
| 112 | int buffer_size = 1024*1024; |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 113 | |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 114 | rc = load_firmware(loadbuffer, buf, buffer_size); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 115 | if(rc < 0) |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 116 | error(buf, rc); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 117 | |
| 118 | if (rc == EOK) |
| 119 | { |
| 120 | kernel_entry = (void*) loadbuffer; |
| 121 | rc = kernel_entry(); |
| 122 | } |
Nicolas Pennequin | c2ca8c7 | 2007-11-27 15:40:29 +0000 | [diff] [blame^] | 123 | |
| 124 | while (1); |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 125 | } |
| 126 | |