Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Barry Wardell |
| 11 | * |
| 12 | * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing |
| 13 | * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach |
| 14 | * |
| 15 | * All files in this archive are subject to the GNU General Public License. |
| 16 | * See the file COPYING in the source tree root for full license agreement. |
| 17 | * |
| 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | * KIND, either express or implied. |
| 20 | * |
| 21 | ****************************************************************************/ |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 22 | #include "common.h" |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 23 | #include "cpu.h" |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 24 | #include "file.h" |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 25 | #include "system.h" |
| 26 | #include "kernel.h" |
| 27 | #include "lcd.h" |
| 28 | #include "font.h" |
| 29 | #include "ata.h" |
| 30 | #include "button.h" |
| 31 | #include "disk.h" |
| 32 | #include "power.h" |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 33 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 34 | /* Maximum allowed firmware image size. 10MB is more than enough */ |
Barry Wardell | 2f16d4f | 2006-12-19 11:33:53 +0000 | [diff] [blame] | 35 | #define MAX_LOADSIZE (10*1024*1024) |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 36 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 37 | /* A buffer to load the original firmware or Rockbox into */ |
| 38 | unsigned char *loadbuffer = (unsigned char *)DRAM_START; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 39 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 40 | /* Bootloader version */ |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 41 | char version[] = APPSVERSION; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 42 | |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 43 | void* main(void) |
| 44 | { |
| 45 | char buf[256]; |
| 46 | int i; |
| 47 | int rc; |
| 48 | unsigned short* identify_info; |
| 49 | struct partinfo* pinfo; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 50 | |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 51 | system_init(); |
| 52 | kernel_init(); |
| 53 | lcd_init(); |
| 54 | font_init(); |
Barry Wardell | 2f16d4f | 2006-12-19 11:33:53 +0000 | [diff] [blame] | 55 | button_init(); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 56 | |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 57 | lcd_setfont(FONT_SYSFIXED); |
| 58 | |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 59 | printf("Rockbox boot loader"); |
| 60 | printf("Version: 20%s", version); |
| 61 | printf(MODEL_NAME); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 62 | |
| 63 | i=ata_init(); |
| 64 | if (i==0) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 65 | identify_info=ata_get_identify(); |
| 66 | /* Show model */ |
| 67 | for (i=0; i < 20; i++) { |
| 68 | ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]); |
| 69 | } |
| 70 | buf[40]=0; |
| 71 | for (i=39; i && buf[i]==' '; i--) { |
| 72 | buf[i]=0; |
| 73 | } |
| 74 | printf(buf); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 75 | } else { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 76 | printf("ATA error: %d", i); |
| 77 | sleep(HZ*5); |
| 78 | power_off(); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | disk_init(); |
| 82 | rc = disk_mount_all(); |
| 83 | if (rc<=0) |
| 84 | { |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 85 | printf("No partition found"); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 86 | sleep(HZ*5); |
| 87 | power_off(); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | pinfo = disk_partinfo(0); |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 91 | printf("Partition 0: 0x%02x %ld MB", pinfo->type, pinfo->size / 2048); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 92 | |
| 93 | i=button_read_device(); |
| 94 | if(i==BUTTON_LEFT) |
| 95 | { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 96 | /* Load original mi4 firmware. This expects a file called |
| 97 | "/System/OF.bin" on the player. It should be a mi4 firmware decrypted |
| 98 | and header stripped using mi4code. It reads the file in to a memory |
| 99 | buffer called loadbuffer. The rest of the loading is done in crt0.S |
| 100 | */ |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 101 | printf("Loading original firmware..."); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 102 | rc=load_raw_firmware(loadbuffer, "/System/OF.bin", MAX_LOADSIZE); |
| 103 | if (rc < EOK) { |
| 104 | printf("Error!"); |
| 105 | printf("Can't load /System/OF.bin:"); |
| 106 | printf(strerror(rc)); |
| 107 | sleep(HZ*5); |
| 108 | power_off(); |
| 109 | } |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 110 | } else { |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 111 | printf("Loading Rockbox..."); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 112 | rc=load_firmware(loadbuffer, BOOTFILE, MAX_LOADSIZE); |
| 113 | if (rc < EOK) { |
| 114 | printf("Error!"); |
| 115 | printf("Can't load %s:", BOOTFILE); |
| 116 | printf(strerror(rc)); |
| 117 | sleep(HZ*5); |
| 118 | power_off(); |
| 119 | } |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 120 | } |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 121 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame^] | 122 | return (void*)loadbuffer; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* These functions are present in the firmware library, but we reimplement |
| 126 | them here because the originals do a lot more than we want */ |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 127 | void usb_acknowledge(void) |
| 128 | { |
| 129 | } |
| 130 | |
| 131 | void usb_wait_for_disconnect(void) |
| 132 | { |
| 133 | } |