diff options
-rw-r--r-- | bootloader/main-e200r-installer.c | 82 |
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 @@ | |||
19 | * KIND, either express or implied. | 19 | * KIND, either express or implied. |
20 | * | 20 | * |
21 | ****************************************************************************/ | 21 | ****************************************************************************/ |
22 | |||
22 | #include <stdio.h> | 23 | #include <stdio.h> |
23 | #include <stdlib.h> | 24 | #include <stdlib.h> |
24 | #include "common.h" | 25 | #include "common.h" |
@@ -43,9 +44,47 @@ char version[] = APPSVERSION; | |||
43 | #define START_SECTOR_OF_ROM 1 | 44 | #define START_SECTOR_OF_ROM 1 |
44 | #define ROMSECTOR_TO_HACK 63 | 45 | #define ROMSECTOR_TO_HACK 63 |
45 | #define HACK_OFFSET 498 | 46 | #define HACK_OFFSET 498 |
46 | #define KNOWN_CRC32 0x5a09c266 | 47 | #define KNOWN_CRC32 0x5a09c266 /* E200R CRC before patching */ |
47 | char knownBytes[] = {0x00, 0x24, 0x07, 0xe1}; | 48 | #define PATCHED_CRC32 0x0a162b34 /* E200R CRC after patching */ |
48 | char changedBytes[] = {0xc0, 0x46, 0xc0, 0x46 }; | 49 | |
50 | static unsigned char knownBytes[] = {0x00, 0x24, 0x07, 0xe1}; | ||
51 | static unsigned char changedBytes[] = {0xc0, 0x46, 0xc0, 0x46 }; | ||
52 | |||
53 | /* | ||
54 | CRC32s of sector 63 from E200 bootloaders - so we can tell users if they're | ||
55 | trying to use e200rpatcher with a vanilla e200. | ||
56 | |||
57 | These are all known E200 bootloaders as of 8 November 2007. | ||
58 | |||
59 | */ | ||
60 | |||
61 | static uint32_t e200_crcs[] = | ||
62 | { | ||
63 | 0xbeceba58, | ||
64 | 0x4e6b038f, | ||
65 | 0x5e4f4219, | ||
66 | 0xae087742, | ||
67 | 0x3dd94852, | ||
68 | 0x72fa69f3, | ||
69 | 0x4ce0d10b | ||
70 | }; | ||
71 | |||
72 | #define NUM_E200_CRCS ((int)((sizeof(e200_crcs) / sizeof(uint32_t)))) | ||
73 | |||
74 | static bool is_e200(uint32_t crc) | ||
75 | { | ||
76 | int i; | ||
77 | |||
78 | for (i = 0 ; i < NUM_E200_CRCS ; i++) | ||
79 | { | ||
80 | if (crc == e200_crcs[i]) | ||
81 | return true; | ||
82 | } | ||
83 | |||
84 | return false; | ||
85 | } | ||
86 | |||
87 | |||
49 | void* main(void) | 88 | void* main(void) |
50 | { | 89 | { |
51 | int i; | 90 | int i; |
@@ -54,6 +93,7 @@ void* main(void) | |||
54 | int crc32; | 93 | int crc32; |
55 | char sector[512]; | 94 | char sector[512]; |
56 | struct partinfo* pinfo; | 95 | struct partinfo* pinfo; |
96 | |||
57 | chksum_crc32gentab (); | 97 | chksum_crc32gentab (); |
58 | 98 | ||
59 | system_init(); | 99 | system_init(); |
@@ -81,11 +121,14 @@ void* main(void) | |||
81 | i=ata_init(); | 121 | i=ata_init(); |
82 | disk_init(IF_MV(0)); | 122 | disk_init(IF_MV(0)); |
83 | num_partitions = disk_mount_all(); | 123 | num_partitions = disk_mount_all(); |
124 | |||
84 | if (num_partitions<=0) | 125 | if (num_partitions<=0) |
85 | { | 126 | { |
86 | error(EDISK,num_partitions); | 127 | error(EDISK,num_partitions); |
87 | } | 128 | } |
129 | |||
88 | pinfo = disk_partinfo(1); | 130 | pinfo = disk_partinfo(1); |
131 | |||
89 | #if 0 /* not needed in release builds */ | 132 | #if 0 /* not needed in release builds */ |
90 | printf("--- Partition info ---"); | 133 | printf("--- Partition info ---"); |
91 | printf("start: %x", pinfo->start); | 134 | printf("start: %x", pinfo->start); |
@@ -93,26 +136,39 @@ void* main(void) | |||
93 | printf("type: %x", pinfo->type); | 136 | printf("type: %x", pinfo->type); |
94 | printf("reading: %x", (START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK)*512); | 137 | printf("reading: %x", (START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK)*512); |
95 | #endif | 138 | #endif |
139 | |||
96 | ata_read_sectors(IF_MV2(0,) | 140 | ata_read_sectors(IF_MV2(0,) |
97 | pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK, | 141 | pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK, |
98 | 1 , sector); | 142 | 1 , sector); |
99 | crc32 = chksum_crc32 (sector, 512); | 143 | crc32 = chksum_crc32 (sector, 512); |
144 | |||
100 | #if 0 /* not needed in release builds */ | 145 | #if 0 /* not needed in release builds */ |
101 | printf("--- Hack Status ---"); | 146 | printf("--- Hack Status ---"); |
102 | printf("Sector checksum: %x", crc32); | 147 | printf("Sector checksum: %x", crc32); |
103 | #endif | 148 | #endif |
104 | if ((crc32 == KNOWN_CRC32) && | 149 | |
105 | !memcmp(§or[HACK_OFFSET], knownBytes, | 150 | if (crc32 == PATCHED_CRC32) |
151 | { | ||
152 | /* Bootloader already patched */ | ||
153 | printf("Firmware unlocked"); | ||
154 | printf("Proceed to Step 2"); | ||
155 | } else if ((crc32 == KNOWN_CRC32) && | ||
156 | !memcmp(§or[HACK_OFFSET], knownBytes, | ||
106 | sizeof(knownBytes)/sizeof(*knownBytes))) | 157 | sizeof(knownBytes)/sizeof(*knownBytes))) |
107 | { | 158 | { |
108 | 159 | /* E200R bootloader detected - patch it */ | |
109 | memcpy(§or[HACK_OFFSET], changedBytes, | 160 | memcpy(§or[HACK_OFFSET], changedBytes, |
110 | sizeof(changedBytes)/sizeof(*changedBytes)); | 161 | sizeof(changedBytes)/sizeof(*changedBytes)); |
111 | ata_write_sectors(IF_MV2(0,) | 162 | ata_write_sectors(IF_MV2(0,) |
112 | pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK, | 163 | pinfo->start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK, |
113 | 1 , sector); | 164 | 1 , sector); |
114 | printf("Firmware Unlocked"); | 165 | printf("Already unlocked"); |
115 | printf("Proceed to Step 2"); | 166 | printf("Proceed to Step 2"); |
167 | } else if (is_e200(crc32)) | ||
168 | { | ||
169 | printf("Vanilla E200 detected!"); | ||
170 | printf("Please install using"); | ||
171 | printf("Sansapatcher"); | ||
116 | } | 172 | } |
117 | else | 173 | else |
118 | { | 174 | { |
@@ -120,14 +176,20 @@ void* main(void) | |||
120 | printf("Rockbox installer cannot"); | 176 | printf("Rockbox installer cannot"); |
121 | printf("continue"); | 177 | printf("continue"); |
122 | } | 178 | } |
179 | |||
180 | /* Turn button lights off */ | ||
123 | GPIOG_OUTPUT_VAL &=~0x80; | 181 | GPIOG_OUTPUT_VAL &=~0x80; |
182 | |||
124 | printf(""); | 183 | printf(""); |
184 | |||
125 | if (button_hold()) | 185 | if (button_hold()) |
126 | printf("Release Hold and"); | 186 | printf("Release Hold and"); |
187 | |||
127 | printf("Press any key to shutdown"); | 188 | printf("Press any key to shutdown"); |
128 | while(button_read_device() == BUTTON_NONE) | 189 | |
129 | ; | 190 | while(button_read_device() == BUTTON_NONE); |
191 | |||
130 | power_off(); | 192 | power_off(); |
193 | |||
131 | return NULL; | 194 | return NULL; |
132 | } | 195 | } |
133 | |||