summaryrefslogtreecommitdiffstats
path: root/bootloader
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-11-08 20:37:16 +0000
committerDave Chapman <dave@dchapman.com>2007-11-08 20:37:16 +0000
commit82a1f8e514e66331dc89ad5bec9513e1589c9a8a (patch)
tree1af2d213ef7ba6af21280f2d96d67ab34d051fbd /bootloader
parentdc0f497a4fb73148ff9107cb8f8e49243ac5d3fb (diff)
downloadrockbox-82a1f8e514e66331dc89ad5bec9513e1589c9a8a.tar.gz
rockbox-82a1f8e514e66331dc89ad5bec9513e1589c9a8a.tar.bz2
rockbox-82a1f8e514e66331dc89ad5bec9513e1589c9a8a.zip
Add check for e200 bootloaders and also for an already-patched e200r bootloader, so we can display more useful messages to the user, instead of simply "Unknown Bootloader". Also a bit of code cleaning and whitespace insertion.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15543 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'bootloader')
-rw-r--r--bootloader/main-e200r-installer.c82
1 files changed, 72 insertions, 10 deletions
diff --git a/bootloader/main-e200r-installer.c b/bootloader/main-e200r-installer.c
index c1162c9ebf..518f1db87f 100644
--- a/bootloader/main-e200r-installer.c
+++ b/bootloader/main-e200r-installer.c
@@ -19,6 +19,7 @@
* KIND, either express or implied.
*
****************************************************************************/
+
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
@@ -43,9 +44,47 @@ char version[] = APPSVERSION;
#define START_SECTOR_OF_ROM 1
#define ROMSECTOR_TO_HACK 63
#define HACK_OFFSET 498
-#define KNOWN_CRC32 0x5a09c266
-char knownBytes[] = {0x00, 0x24, 0x07, 0xe1};
-char changedBytes[] = {0xc0, 0x46, 0xc0, 0x46 };
+#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;
+}
+
+
void* main(void)
{
int i;
@@ -54,6 +93,7 @@ void* main(void)
int crc32;
char sector[512];
struct partinfo* pinfo;
+
chksum_crc32gentab ();
system_init();
@@ -81,11 +121,14 @@ void* main(void)
i=ata_init();
disk_init(IF_MV(0));
num_partitions = disk_mount_all();
+
if (num_partitions<=0)
{
error(EDISK,num_partitions);
}
+
pinfo = disk_partinfo(1);
+
#if 0 /* not needed in release builds */
printf("--- Partition info ---");
printf("start: %x", pinfo->start);
@@ -93,26 +136,39 @@ void* main(void)
printf("type: %x", pinfo->type);
printf("reading: %x", (START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK)*512);
#endif
+
ata_read_sectors(IF_MV2(0,)
pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
1 , sector);
crc32 = chksum_crc32 (sector, 512);
+
#if 0 /* not needed in release builds */
printf("--- Hack Status ---");
printf("Sector checksum: %x", crc32);
#endif
- if ((crc32 == KNOWN_CRC32) &&
- !memcmp(&sector[HACK_OFFSET], knownBytes,
+
+ if (crc32 == PATCHED_CRC32)
+ {
+ /* Bootloader already patched */
+ printf("Firmware unlocked");
+ printf("Proceed to Step 2");
+ } else if ((crc32 == KNOWN_CRC32) &&
+ !memcmp(&sector[HACK_OFFSET], knownBytes,
sizeof(knownBytes)/sizeof(*knownBytes)))
{
-
+ /* E200R bootloader detected - patch it */
memcpy(&sector[HACK_OFFSET], changedBytes,
sizeof(changedBytes)/sizeof(*changedBytes));
ata_write_sectors(IF_MV2(0,)
pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
1 , sector);
- printf("Firmware Unlocked");
+ printf("Already unlocked");
printf("Proceed to Step 2");
+ } else if (is_e200(crc32))
+ {
+ printf("Vanilla E200 detected!");
+ printf("Please install using");
+ printf("Sansapatcher");
}
else
{
@@ -120,14 +176,20 @@ void* main(void)
printf("Rockbox installer cannot");
printf("continue");
}
+
+ /* Turn button lights off */
GPIOG_OUTPUT_VAL &=~0x80;
+
printf("");
+
if (button_hold())
printf("Release Hold and");
+
printf("Press any key to shutdown");
- while(button_read_device() == BUTTON_NONE)
- ;
+
+ while(button_read_device() == BUTTON_NONE);
+
power_off();
+
return NULL;
}
-