blob: a02510e31c5d4ffd8d6f331fda6e168f8ea8c6c7 [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"
32#include "power.h"
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000033
Barry Wardell84b509d2007-01-28 18:42:11 +000034/* Maximum allowed firmware image size. 10MB is more than enough */
Barry Wardell2f16d4f2006-12-19 11:33:53 +000035#define MAX_LOADSIZE (10*1024*1024)
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000036
Barry Wardell84b509d2007-01-28 18:42:11 +000037/* A buffer to load the original firmware or Rockbox into */
38unsigned char *loadbuffer = (unsigned char *)DRAM_START;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000039
Barry Wardell84b509d2007-01-28 18:42:11 +000040/* Bootloader version */
Barry Wardell1920df32006-08-28 08:11:32 +000041char version[] = APPSVERSION;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000042
Barry Wardell1920df32006-08-28 08:11:32 +000043void* main(void)
44{
45 char buf[256];
46 int i;
47 int rc;
48 unsigned short* identify_info;
49 struct partinfo* pinfo;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000050
Barry Wardell1920df32006-08-28 08:11:32 +000051 system_init();
52 kernel_init();
53 lcd_init();
54 font_init();
Barry Wardell2f16d4f2006-12-19 11:33:53 +000055 button_init();
Barry Wardell1920df32006-08-28 08:11:32 +000056
Barry Wardell1920df32006-08-28 08:11:32 +000057 lcd_setfont(FONT_SYSFIXED);
58
Barry Wardellf4709d02007-01-17 12:20:38 +000059 printf("Rockbox boot loader");
60 printf("Version: 20%s", version);
61 printf(MODEL_NAME);
Barry Wardell1920df32006-08-28 08:11:32 +000062
63 i=ata_init();
64 if (i==0) {
Barry Wardell84b509d2007-01-28 18:42:11 +000065 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 Wardell1920df32006-08-28 08:11:32 +000075 } else {
Barry Wardell84b509d2007-01-28 18:42:11 +000076 printf("ATA error: %d", i);
77 sleep(HZ*5);
78 power_off();
Barry Wardell1920df32006-08-28 08:11:32 +000079 }
80
81 disk_init();
82 rc = disk_mount_all();
83 if (rc<=0)
84 {
Barry Wardellf4709d02007-01-17 12:20:38 +000085 printf("No partition found");
Barry Wardell84b509d2007-01-28 18:42:11 +000086 sleep(HZ*5);
87 power_off();
Barry Wardell1920df32006-08-28 08:11:32 +000088 }
89
90 pinfo = disk_partinfo(0);
Barry Wardellf4709d02007-01-17 12:20:38 +000091 printf("Partition 0: 0x%02x %ld MB", pinfo->type, pinfo->size / 2048);
Barry Wardell1920df32006-08-28 08:11:32 +000092
93 i=button_read_device();
94 if(i==BUTTON_LEFT)
95 {
Barry Wardell84b509d2007-01-28 18:42:11 +000096 /* 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 Wardellf4709d02007-01-17 12:20:38 +0000101 printf("Loading original firmware...");
Barry Wardell84b509d2007-01-28 18:42:11 +0000102 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 Wardell1920df32006-08-28 08:11:32 +0000110 } else {
Barry Wardellf4709d02007-01-17 12:20:38 +0000111 printf("Loading Rockbox...");
Barry Wardell84b509d2007-01-28 18:42:11 +0000112 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 Wardell1920df32006-08-28 08:11:32 +0000120 }
Hristo Kovachev12041362006-08-11 09:51:04 +0000121
Barry Wardell84b509d2007-01-28 18:42:11 +0000122 return (void*)loadbuffer;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +0000123}
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 Kovachev9dc0e622006-08-11 08:35:27 +0000127void usb_acknowledge(void)
128{
129}
130
131void usb_wait_for_disconnect(void)
132{
133}