2007-09-09 11:20:20 +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
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-09-09 11:20:20 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-09-09 11:20:20 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "common.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "font.h"
|
2008-11-01 16:14:28 +00:00
|
|
|
#include "storage.h"
|
2007-09-09 11:20:20 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "disk.h"
|
|
|
|
#include "crc32-mi4.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "backlight-target.h"
|
2007-10-14 11:16:20 +00:00
|
|
|
#include "power.h"
|
2007-09-09 11:20:20 +00:00
|
|
|
|
|
|
|
/* Bootloader version */
|
|
|
|
char version[] = APPSVERSION;
|
|
|
|
|
|
|
|
#define START_SECTOR_OF_ROM 1
|
|
|
|
#define ROMSECTOR_TO_HACK 63
|
|
|
|
#define HACK_OFFSET 498
|
2007-11-08 20:37:16 +00:00
|
|
|
#define KNOWN_CRC32 0x5a09c266 /* E200R CRC before patching */
|
|
|
|
#define PATCHED_CRC32 0x0a162b34 /* E200R CRC after patching */
|
|
|
|
|
|
|
|
static unsigned char knownBytes[] = {0x00, 0x24, 0x07, 0xe1};
|
|
|
|
static unsigned char changedBytes[] = {0xc0, 0x46, 0xc0, 0x46 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
CRC32s of sector 63 from E200 bootloaders - so we can tell users if they're
|
|
|
|
trying to use e200rpatcher with a vanilla e200.
|
|
|
|
|
|
|
|
These are all known E200 bootloaders as of 8 November 2007.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static uint32_t e200_crcs[] =
|
|
|
|
{
|
|
|
|
0xbeceba58,
|
|
|
|
0x4e6b038f,
|
|
|
|
0x5e4f4219,
|
|
|
|
0xae087742,
|
|
|
|
0x3dd94852,
|
|
|
|
0x72fa69f3,
|
|
|
|
0x4ce0d10b
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_E200_CRCS ((int)((sizeof(e200_crcs) / sizeof(uint32_t))))
|
|
|
|
|
|
|
|
static bool is_e200(uint32_t crc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < NUM_E200_CRCS ; i++)
|
|
|
|
{
|
|
|
|
if (crc == e200_crcs[i])
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-09 11:20:20 +00:00
|
|
|
void* main(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int btn;
|
|
|
|
int num_partitions;
|
|
|
|
int crc32;
|
|
|
|
char sector[512];
|
|
|
|
struct partinfo* pinfo;
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-09-09 11:20:20 +00:00
|
|
|
chksum_crc32gentab ();
|
|
|
|
|
|
|
|
system_init();
|
|
|
|
kernel_init();
|
|
|
|
lcd_init();
|
|
|
|
font_init();
|
|
|
|
button_init();
|
|
|
|
i2c_init();
|
2007-11-12 18:49:53 +00:00
|
|
|
_backlight_on();
|
2007-09-09 11:20:20 +00:00
|
|
|
|
|
|
|
lcd_set_foreground(LCD_WHITE);
|
|
|
|
lcd_set_background(LCD_BLACK);
|
|
|
|
lcd_clear_display();
|
|
|
|
|
|
|
|
btn = button_read_device();
|
|
|
|
verbose = true;
|
|
|
|
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
|
|
|
printf("Rockbox e200R installer");
|
|
|
|
printf("Version: %s", version);
|
|
|
|
printf(MODEL_NAME);
|
2007-10-14 11:16:20 +00:00
|
|
|
printf("");
|
2007-09-09 11:20:20 +00:00
|
|
|
|
2008-11-01 16:14:28 +00:00
|
|
|
i=storage_init();
|
2007-09-09 11:20:20 +00:00
|
|
|
disk_init(IF_MV(0));
|
|
|
|
num_partitions = disk_mount_all();
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-09-09 11:20:20 +00:00
|
|
|
if (num_partitions<=0)
|
|
|
|
{
|
|
|
|
error(EDISK,num_partitions);
|
|
|
|
}
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-09-09 11:20:20 +00:00
|
|
|
pinfo = disk_partinfo(1);
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-10-14 11:16:20 +00:00
|
|
|
#if 0 /* not needed in release builds */
|
2007-09-09 11:20:20 +00:00
|
|
|
printf("--- Partition info ---");
|
|
|
|
printf("start: %x", pinfo->start);
|
|
|
|
printf("size: %x", pinfo->size);
|
|
|
|
printf("type: %x", pinfo->type);
|
|
|
|
printf("reading: %x", (START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK)*512);
|
2007-10-14 11:16:20 +00:00
|
|
|
#endif
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2010-04-03 22:18:16 +00:00
|
|
|
storage_read_sectors(pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
|
2008-11-24 04:43:31 +00:00
|
|
|
1 , sector);
|
2007-09-09 11:20:20 +00:00
|
|
|
crc32 = chksum_crc32 (sector, 512);
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-10-14 11:16:20 +00:00
|
|
|
#if 0 /* not needed in release builds */
|
2007-09-09 11:20:20 +00:00
|
|
|
printf("--- Hack Status ---");
|
|
|
|
printf("Sector checksum: %x", crc32);
|
2007-10-14 11:16:20 +00:00
|
|
|
#endif
|
2007-11-08 20:37:16 +00:00
|
|
|
|
|
|
|
if (crc32 == PATCHED_CRC32)
|
|
|
|
{
|
|
|
|
/* Bootloader already patched */
|
2007-11-09 08:37:14 +00:00
|
|
|
printf("Already unlocked");
|
2007-11-08 20:37:16 +00:00
|
|
|
printf("Proceed to Step 2");
|
|
|
|
} else if ((crc32 == KNOWN_CRC32) &&
|
|
|
|
!memcmp(§or[HACK_OFFSET], knownBytes,
|
2007-09-09 11:20:20 +00:00
|
|
|
sizeof(knownBytes)/sizeof(*knownBytes)))
|
|
|
|
{
|
2007-11-08 20:37:16 +00:00
|
|
|
/* E200R bootloader detected - patch it */
|
2007-09-09 11:20:20 +00:00
|
|
|
memcpy(§or[HACK_OFFSET], changedBytes,
|
|
|
|
sizeof(changedBytes)/sizeof(*changedBytes));
|
2010-04-03 22:18:16 +00:00
|
|
|
storage_write_sectors(
|
2007-09-09 11:20:20 +00:00
|
|
|
pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
|
|
|
|
1 , sector);
|
2007-11-09 08:37:14 +00:00
|
|
|
printf("Firmware unlocked");
|
2007-09-09 11:20:20 +00:00
|
|
|
printf("Proceed to Step 2");
|
2007-11-08 20:37:16 +00:00
|
|
|
} else if (is_e200(crc32))
|
|
|
|
{
|
|
|
|
printf("Vanilla E200 detected!");
|
|
|
|
printf("Please install using");
|
|
|
|
printf("Sansapatcher");
|
2007-09-09 11:20:20 +00:00
|
|
|
}
|
|
|
|
else
|
2007-10-14 11:16:20 +00:00
|
|
|
{
|
|
|
|
printf("Unknown bootloader");
|
|
|
|
printf("Rockbox installer cannot");
|
|
|
|
printf("continue");
|
|
|
|
}
|
2007-11-08 20:37:16 +00:00
|
|
|
|
|
|
|
/* Turn button lights off */
|
2007-09-09 11:20:20 +00:00
|
|
|
GPIOG_OUTPUT_VAL &=~0x80;
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-10-14 11:16:20 +00:00
|
|
|
printf("");
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-10-14 11:16:20 +00:00
|
|
|
if (button_hold())
|
|
|
|
printf("Release Hold and");
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-10-14 11:16:20 +00:00
|
|
|
printf("Press any key to shutdown");
|
2007-11-08 20:37:16 +00:00
|
|
|
|
|
|
|
while(button_read_device() == BUTTON_NONE);
|
|
|
|
|
2007-10-14 11:16:20 +00:00
|
|
|
power_off();
|
2007-11-08 20:37:16 +00:00
|
|
|
|
2007-09-09 11:20:20 +00:00
|
|
|
return NULL;
|
|
|
|
}
|