2006-08-11 08:35:27 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Barry Wardell
|
|
|
|
*
|
|
|
|
* Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
|
|
|
|
* and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "ata.h"
|
|
|
|
#include "fat.h"
|
|
|
|
#include "disk.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "file.h"
|
|
|
|
|
2006-12-19 11:33:53 +00:00
|
|
|
/* Size of the buffer to store the loaded firmware image */
|
|
|
|
#define MAX_LOADSIZE (10*1024*1024)
|
2006-08-11 08:35:27 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
/* A buffer to load the iriver firmware or Rockbox into */
|
|
|
|
unsigned char loadbuffer[MAX_LOADSIZE];
|
|
|
|
|
|
|
|
char version[] = APPSVERSION;
|
|
|
|
|
|
|
|
#define DRAM_START 0x10000000
|
2006-08-11 08:35:27 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
int line=0;
|
2006-08-11 08:35:27 +00:00
|
|
|
|
2006-12-19 11:33:53 +00:00
|
|
|
/* Load original mi4 firmware. This function expects a file called
|
|
|
|
"/System/OF.bin" on the player. It should be a mi4 firmware decrypted
|
|
|
|
and header stripped using mi4code. It reads the file in to a memory
|
2006-08-28 08:11:32 +00:00
|
|
|
buffer called buf. The rest of the loading is done in main() and crt0.S
|
2006-08-11 08:35:27 +00:00
|
|
|
*/
|
2006-12-19 11:33:53 +00:00
|
|
|
int load_original_firmware(unsigned char* buf)
|
2006-08-11 08:35:27 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int rc;
|
|
|
|
int len;
|
|
|
|
|
2006-12-19 11:33:53 +00:00
|
|
|
fd = open("/System/OF.bin", O_RDONLY);
|
2006-08-11 08:35:27 +00:00
|
|
|
|
|
|
|
len = filesize(fd);
|
2006-08-28 08:11:32 +00:00
|
|
|
|
|
|
|
if (len > MAX_LOADSIZE)
|
|
|
|
return -6;
|
|
|
|
|
2006-08-11 08:35:27 +00:00
|
|
|
rc = read(fd, buf, len);
|
|
|
|
if(rc < len)
|
|
|
|
return -4;
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2006-12-19 11:33:53 +00:00
|
|
|
/* Load Rockbox firmware (rockbox.*) */
|
2006-08-28 08:11:32 +00:00
|
|
|
int load_rockbox(unsigned char* buf)
|
2006-08-11 08:35:27 +00:00
|
|
|
{
|
2006-08-28 08:11:32 +00:00
|
|
|
int fd;
|
2006-08-11 08:35:27 +00:00
|
|
|
int rc;
|
2006-08-28 08:11:32 +00:00
|
|
|
int len;
|
|
|
|
unsigned long chksum;
|
|
|
|
char model[5];
|
|
|
|
unsigned long sum;
|
|
|
|
int i;
|
|
|
|
char str[80];
|
2006-08-20 10:18:47 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
fd = open("/.rockbox/" BOOTFILE, O_RDONLY);
|
|
|
|
if(fd < 0)
|
|
|
|
{
|
|
|
|
fd = open("/" BOOTFILE, O_RDONLY);
|
|
|
|
if(fd < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
2006-08-11 08:35:27 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
len = filesize(fd) - 8;
|
2006-08-11 08:35:27 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
snprintf(str, sizeof(str), "Length: %x", len);
|
|
|
|
lcd_puts(0, line++ ,str);
|
|
|
|
lcd_update();
|
2006-08-11 09:51:04 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
if (len > MAX_LOADSIZE)
|
|
|
|
return -6;
|
|
|
|
|
|
|
|
lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
|
2006-08-11 09:51:04 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
rc = read(fd, &chksum, 4);
|
|
|
|
chksum=betoh32(chksum); /* Rockbox checksums are big-endian */
|
|
|
|
if(rc < 4)
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
snprintf(str, sizeof(str), "Checksum: %x", chksum);
|
|
|
|
lcd_puts(0, line++ ,str);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
rc = read(fd, model, 4);
|
|
|
|
if(rc < 4)
|
|
|
|
return -3;
|
|
|
|
|
|
|
|
model[4] = 0;
|
2006-08-11 09:51:04 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
snprintf(str, sizeof(str), "Model name: %s", model);
|
|
|
|
lcd_puts(0, line++ ,str);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
|
|
|
|
|
|
|
|
rc = read(fd, buf, len);
|
|
|
|
if(rc < len)
|
|
|
|
return -4;
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
sum = MODEL_NUMBER;
|
2006-08-11 09:51:04 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
for(i = 0;i < len;i++) {
|
|
|
|
sum += buf[i];
|
|
|
|
}
|
2006-08-11 08:35:27 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
snprintf(str, sizeof(str), "Sum: %x", sum);
|
|
|
|
lcd_puts(0, line++ ,str);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
if(sum != chksum)
|
|
|
|
return -5;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* main(void)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
unsigned short* identify_info;
|
|
|
|
struct partinfo* pinfo;
|
|
|
|
|
|
|
|
system_init();
|
|
|
|
kernel_init();
|
|
|
|
lcd_init();
|
|
|
|
font_init();
|
2006-12-19 11:33:53 +00:00
|
|
|
button_init();
|
2006-08-28 08:11:32 +00:00
|
|
|
|
|
|
|
line=0;
|
|
|
|
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
|
|
|
lcd_puts(0, line++, "Rockbox boot loader");
|
|
|
|
snprintf(buf, sizeof(buf), "Version: 20%s", version);
|
|
|
|
lcd_puts(0, line++, buf);
|
2006-12-19 11:33:53 +00:00
|
|
|
snprintf(buf, sizeof(buf), MODEL_NAME);
|
2006-08-28 08:11:32 +00:00
|
|
|
lcd_puts(0, line++, buf);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
i=ata_init();
|
|
|
|
if (i==0) {
|
|
|
|
identify_info=ata_get_identify();
|
|
|
|
/* Show model */
|
|
|
|
for (i=0; i < 20; i++) {
|
|
|
|
((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
|
|
|
|
}
|
|
|
|
buf[40]=0;
|
|
|
|
for (i=39; i && buf[i]==' '; i--) {
|
|
|
|
buf[i]=0;
|
|
|
|
}
|
|
|
|
lcd_puts(0, line++, buf);
|
|
|
|
lcd_update();
|
|
|
|
} else {
|
|
|
|
snprintf(buf, sizeof(buf), "ATA: %d", i);
|
|
|
|
lcd_puts(0, line++, buf);
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
disk_init();
|
|
|
|
rc = disk_mount_all();
|
|
|
|
if (rc<=0)
|
|
|
|
{
|
|
|
|
lcd_puts(0, line++, "No partition found");
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
pinfo = disk_partinfo(0);
|
|
|
|
snprintf(buf, sizeof(buf), "Partition 0: 0x%02x %ld MB",
|
|
|
|
pinfo->type, pinfo->size / 2048);
|
|
|
|
lcd_puts(0, line++, buf);
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
i=button_read_device();
|
|
|
|
if(i==BUTTON_LEFT)
|
|
|
|
{
|
2006-12-19 11:33:53 +00:00
|
|
|
lcd_puts(0, line++, "Loading original firmware...");
|
2006-08-28 08:11:32 +00:00
|
|
|
lcd_update();
|
2006-12-19 11:33:53 +00:00
|
|
|
rc=load_original_firmware(loadbuffer);
|
2006-08-28 08:11:32 +00:00
|
|
|
} else {
|
2006-12-19 11:33:53 +00:00
|
|
|
lcd_puts(0, line++, "Loading Rockbox...");
|
2006-08-28 08:11:32 +00:00
|
|
|
lcd_update();
|
|
|
|
rc=load_rockbox(loadbuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
snprintf(buf, sizeof(buf), "Rockbox error: %d",rc);
|
|
|
|
lcd_puts(0, line++, buf);
|
|
|
|
lcd_update();
|
2006-12-19 11:33:53 +00:00
|
|
|
while(1) {}
|
2006-08-11 09:51:04 +00:00
|
|
|
}
|
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
memcpy((void*)DRAM_START,loadbuffer,rc);
|
2006-08-11 09:51:04 +00:00
|
|
|
|
2006-08-28 08:11:32 +00:00
|
|
|
return (void*)DRAM_START;
|
2006-08-11 08:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* These functions are present in the firmware library, but we reimplement
|
|
|
|
them here because the originals do a lot more than we want */
|
|
|
|
|
|
|
|
void reset_poweroff_timer(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int dbg_ports(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mpeg_stop(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_acknowledge(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_wait_for_disconnect(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void sys_poweroff(void)
|
|
|
|
{
|
|
|
|
}
|