1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Barry Wardell
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
37 #include "crc32-mi4.h"
40 #include "backlight-target.h"
43 /* Bootloader version */
44 char version
[] = APPSVERSION
;
46 #define START_SECTOR_OF_ROM 1
47 #define ROMSECTOR_TO_HACK 63
48 #define HACK_OFFSET 498
49 #define KNOWN_CRC32 0x5a09c266 /* E200R CRC before patching */
50 #define PATCHED_CRC32 0x0a162b34 /* E200R CRC after patching */
52 static unsigned char knownBytes
[] = {0x00, 0x24, 0x07, 0xe1};
53 static unsigned char changedBytes
[] = {0xc0, 0x46, 0xc0, 0x46 };
56 CRC32s of sector 63 from E200 bootloaders - so we can tell users if they're
57 trying to use e200rpatcher with a vanilla e200.
59 These are all known E200 bootloaders as of 8 November 2007.
63 static uint32_t e200_crcs
[] =
74 #define NUM_E200_CRCS ((int)((sizeof(e200_crcs) / sizeof(uint32_t))))
76 static bool is_e200(uint32_t crc
)
80 for (i
= 0 ; i
< NUM_E200_CRCS
; i
++)
82 if (crc
== e200_crcs
[i
])
97 struct partinfo
* pinfo
;
99 chksum_crc32gentab ();
109 lcd_set_foreground(LCD_WHITE
);
110 lcd_set_background(LCD_BLACK
);
113 btn
= button_read_device();
116 lcd_setfont(FONT_SYSFIXED
);
118 printf("Rockbox e200R installer");
119 printf("Version: %s", version
);
125 num_partitions
= disk_mount_all();
127 if (num_partitions
<=0)
129 error(EDISK
,num_partitions
);
132 pinfo
= disk_partinfo(1);
134 #if 0 /* not needed in release builds */
135 printf("--- Partition info ---");
136 printf("start: %x", pinfo
->start
);
137 printf("size: %x", pinfo
->size
);
138 printf("type: %x", pinfo
->type
);
139 printf("reading: %x", (START_SECTOR_OF_ROM
+ ROMSECTOR_TO_HACK
)*512);
142 storage_read_sectors(0,
143 pinfo
->start
+ START_SECTOR_OF_ROM
+ ROMSECTOR_TO_HACK
,
145 crc32
= chksum_crc32 (sector
, 512);
147 #if 0 /* not needed in release builds */
148 printf("--- Hack Status ---");
149 printf("Sector checksum: %x", crc32
);
152 if (crc32
== PATCHED_CRC32
)
154 /* Bootloader already patched */
155 printf("Already unlocked");
156 printf("Proceed to Step 2");
157 } else if ((crc32
== KNOWN_CRC32
) &&
158 !memcmp(§or
[HACK_OFFSET
], knownBytes
,
159 sizeof(knownBytes
)/sizeof(*knownBytes
)))
161 /* E200R bootloader detected - patch it */
162 memcpy(§or
[HACK_OFFSET
], changedBytes
,
163 sizeof(changedBytes
)/sizeof(*changedBytes
));
164 storage_write_sectors(0,
165 pinfo
->start
+ START_SECTOR_OF_ROM
+ ROMSECTOR_TO_HACK
,
167 printf("Firmware unlocked");
168 printf("Proceed to Step 2");
169 } else if (is_e200(crc32
))
171 printf("Vanilla E200 detected!");
172 printf("Please install using");
173 printf("Sansapatcher");
177 printf("Unknown bootloader");
178 printf("Rockbox installer cannot");
182 /* Turn button lights off */
183 GPIOG_OUTPUT_VAL
&=~0x80;
188 printf("Release Hold and");
190 printf("Press any key to shutdown");
192 while(button_read_device() == BUTTON_NONE
);