blob: 0f85404fc7657bdd35eb94b9b93744b31c0a39cf [file] [log] [blame]
Hristo Kovachev9dc0e622006-08-11 08:35:27 +00001/***************************************************************************
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 Wardell84b509d2007-01-28 18:42:11 +000022#include "common.h"
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000023#include "cpu.h"
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000024#include "file.h"
Barry Wardell84b509d2007-01-28 18:42:11 +000025#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 Wardell23709982007-03-12 22:12:20 +000032
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 Kovachev9dc0e622006-08-11 08:35:27 +000043
Barry Wardell84b509d2007-01-28 18:42:11 +000044/* Maximum allowed firmware image size. 10MB is more than enough */
Barry Wardell2f16d4f2006-12-19 11:33:53 +000045#define MAX_LOADSIZE (10*1024*1024)
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000046
Barry Wardell84b509d2007-01-28 18:42:11 +000047/* A buffer to load the original firmware or Rockbox into */
48unsigned char *loadbuffer = (unsigned char *)DRAM_START;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000049
Barry Wardell84b509d2007-01-28 18:42:11 +000050/* Bootloader version */
Barry Wardell1920df32006-08-28 08:11:32 +000051char version[] = APPSVERSION;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000052
Barry Wardell1920df32006-08-28 08:11:32 +000053void* main(void)
54{
55 char buf[256];
56 int i;
Barry Wardell23709982007-03-12 22:12:20 +000057 int btn;
Barry Wardell1920df32006-08-28 08:11:32 +000058 int rc;
59 unsigned short* identify_info;
60 struct partinfo* pinfo;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000061
Barry Wardell1920df32006-08-28 08:11:32 +000062 system_init();
63 kernel_init();
64 lcd_init();
65 font_init();
Barry Wardell2f16d4f2006-12-19 11:33:53 +000066 button_init();
Barry Wardell1920df32006-08-28 08:11:32 +000067
Barry Wardell23709982007-03-12 22:12:20 +000068 btn = button_read_device();
69
70 /* Enable bootloader messages */
71 if (btn==BOOTLOADER_VERBOSE)
72 verbose = true;
73
Barry Wardell1920df32006-08-28 08:11:32 +000074 lcd_setfont(FONT_SYSFIXED);
75
Barry Wardellf4709d02007-01-17 12:20:38 +000076 printf("Rockbox boot loader");
77 printf("Version: 20%s", version);
78 printf(MODEL_NAME);
Barry Wardell1920df32006-08-28 08:11:32 +000079
80 i=ata_init();
81 if (i==0) {
Barry Wardell84b509d2007-01-28 18:42:11 +000082 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 Wardell1920df32006-08-28 08:11:32 +000092 } else {
Barry Wardell23709982007-03-12 22:12:20 +000093 error(EATA, i);
Barry Wardell1920df32006-08-28 08:11:32 +000094 }
95
96 disk_init();
97 rc = disk_mount_all();
98 if (rc<=0)
99 {
Barry Wardell23709982007-03-12 22:12:20 +0000100 error(EDISK,rc);
Barry Wardell1920df32006-08-28 08:11:32 +0000101 }
102
103 pinfo = disk_partinfo(0);
Barry Wardellf4709d02007-01-17 12:20:38 +0000104 printf("Partition 0: 0x%02x %ld MB", pinfo->type, pinfo->size / 2048);
Barry Wardell1920df32006-08-28 08:11:32 +0000105
Barry Wardell23709982007-03-12 22:12:20 +0000106 if(btn==BOOTLOADER_BOOT_OF)
Barry Wardell1920df32006-08-28 08:11:32 +0000107 {
Barry Wardell84b509d2007-01-28 18:42:11 +0000108 /* 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 Wardellf4709d02007-01-17 12:20:38 +0000113 printf("Loading original firmware...");
Barry Wardell84b509d2007-01-28 18:42:11 +0000114 rc=load_raw_firmware(loadbuffer, "/System/OF.bin", MAX_LOADSIZE);
115 if (rc < EOK) {
Barry Wardell23709982007-03-12 22:12:20 +0000116 printf("Can't load /System/OF.bin");
117 error(EBOOTFILE, rc);
Barry Wardell84b509d2007-01-28 18:42:11 +0000118 }
Barry Wardell1920df32006-08-28 08:11:32 +0000119 } else {
Barry Wardellf4709d02007-01-17 12:20:38 +0000120 printf("Loading Rockbox...");
Barry Wardell84b509d2007-01-28 18:42:11 +0000121 rc=load_firmware(loadbuffer, BOOTFILE, MAX_LOADSIZE);
122 if (rc < EOK) {
Barry Wardell84b509d2007-01-28 18:42:11 +0000123 printf("Can't load %s:", BOOTFILE);
Barry Wardell23709982007-03-12 22:12:20 +0000124 error(EBOOTFILE, rc);
Barry Wardell84b509d2007-01-28 18:42:11 +0000125 }
Barry Wardell1920df32006-08-28 08:11:32 +0000126 }
Hristo Kovachev12041362006-08-11 09:51:04 +0000127
Barry Wardell84b509d2007-01-28 18:42:11 +0000128 return (void*)loadbuffer;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +0000129}
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 Kovachev9dc0e622006-08-11 08:35:27 +0000133void usb_acknowledge(void)
134{
135}
136
137void usb_wait_for_disconnect(void)
138{
139}