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" |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame^] | 32 | |
| 33 | /* Button definitions */ |
| 34 | #if CONFIG_KEYPAD == IRIVER_H10_PAD |
| 35 | #define BOOTLOADER_VERBOSE BUTTON_PLAY |
| 36 | #define BOOTLOADER_BOOT_OF BUTTON_LEFT |
| 37 | |
| 38 | #elif CONFIG_KEYPAD == SANSA_E200_PAD |
| 39 | #define BOOTLOADER_VERBOSE BUTTON_RIGHT |
| 40 | #define BOOTLOADER_BOOT_OF BUTTON_LEFT |
| 41 | |
| 42 | #endif |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 43 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 44 | /* Maximum allowed firmware image size. 10MB is more than enough */ |
Barry Wardell | 2f16d4f | 2006-12-19 11:33:53 +0000 | [diff] [blame] | 45 | #define MAX_LOADSIZE (10*1024*1024) |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 46 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 47 | /* A buffer to load the original firmware or Rockbox into */ |
| 48 | unsigned char *loadbuffer = (unsigned char *)DRAM_START; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 49 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 50 | /* Bootloader version */ |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 51 | char version[] = APPSVERSION; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 52 | |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 53 | void* main(void) |
| 54 | { |
| 55 | char buf[256]; |
| 56 | int i; |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame^] | 57 | int btn; |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 58 | int rc; |
| 59 | unsigned short* identify_info; |
| 60 | struct partinfo* pinfo; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 61 | |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 62 | system_init(); |
| 63 | kernel_init(); |
| 64 | lcd_init(); |
| 65 | font_init(); |
Barry Wardell | 2f16d4f | 2006-12-19 11:33:53 +0000 | [diff] [blame] | 66 | button_init(); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 67 | |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame^] | 68 | btn = button_read_device(); |
| 69 | |
| 70 | /* Enable bootloader messages */ |
| 71 | if (btn==BOOTLOADER_VERBOSE) |
| 72 | verbose = true; |
| 73 | |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 74 | lcd_setfont(FONT_SYSFIXED); |
| 75 | |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 76 | printf("Rockbox boot loader"); |
| 77 | printf("Version: 20%s", version); |
| 78 | printf(MODEL_NAME); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 79 | |
| 80 | i=ata_init(); |
| 81 | if (i==0) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 82 | identify_info=ata_get_identify(); |
| 83 | /* Show model */ |
| 84 | for (i=0; i < 20; i++) { |
| 85 | ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]); |
| 86 | } |
| 87 | buf[40]=0; |
| 88 | for (i=39; i && buf[i]==' '; i--) { |
| 89 | buf[i]=0; |
| 90 | } |
| 91 | printf(buf); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 92 | } else { |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame^] | 93 | error(EATA, i); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | disk_init(); |
| 97 | rc = disk_mount_all(); |
| 98 | if (rc<=0) |
| 99 | { |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame^] | 100 | error(EDISK,rc); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | pinfo = disk_partinfo(0); |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 104 | printf("Partition 0: 0x%02x %ld MB", pinfo->type, pinfo->size / 2048); |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 105 | |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame^] | 106 | if(btn==BOOTLOADER_BOOT_OF) |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 107 | { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 108 | /* Load original mi4 firmware. This expects a file called |
| 109 | "/System/OF.bin" on the player. It should be a mi4 firmware decrypted |
| 110 | and header stripped using mi4code. It reads the file in to a memory |
| 111 | buffer called loadbuffer. The rest of the loading is done in crt0.S |
| 112 | */ |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 113 | printf("Loading original firmware..."); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 114 | rc=load_raw_firmware(loadbuffer, "/System/OF.bin", MAX_LOADSIZE); |
| 115 | if (rc < EOK) { |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame^] | 116 | printf("Can't load /System/OF.bin"); |
| 117 | error(EBOOTFILE, rc); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 118 | } |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 119 | } else { |
Barry Wardell | f4709d0 | 2007-01-17 12:20:38 +0000 | [diff] [blame] | 120 | printf("Loading Rockbox..."); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 121 | rc=load_firmware(loadbuffer, BOOTFILE, MAX_LOADSIZE); |
| 122 | if (rc < EOK) { |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 123 | printf("Can't load %s:", BOOTFILE); |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame^] | 124 | error(EBOOTFILE, rc); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 125 | } |
Barry Wardell | 1920df3 | 2006-08-28 08:11:32 +0000 | [diff] [blame] | 126 | } |
Hristo Kovachev | 1204136 | 2006-08-11 09:51:04 +0000 | [diff] [blame] | 127 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 128 | return (void*)loadbuffer; |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /* These functions are present in the firmware library, but we reimplement |
| 132 | them here because the originals do a lot more than we want */ |
Hristo Kovachev | 9dc0e62 | 2006-08-11 08:35:27 +0000 | [diff] [blame] | 133 | void usb_acknowledge(void) |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | void usb_wait_for_disconnect(void) |
| 138 | { |
| 139 | } |