summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/firmware_flash.c45
-rw-r--r--apps/plugins/iriver_flash.c49
2 files changed, 6 insertions, 88 deletions
diff --git a/apps/plugins/firmware_flash.c b/apps/plugins/firmware_flash.c
index ebf4242e2a..e6f6df431c 100644
--- a/apps/plugins/firmware_flash.c
+++ b/apps/plugins/firmware_flash.c
@@ -255,47 +255,6 @@ bool GetFlashInfo(tFlashInfo* pInfo)
255 return false; 255 return false;
256} 256}
257 257
258
259/*********** Utility Functions ************/
260
261
262/* Tool function to calculate a CRC32 across some buffer */
263/* third argument is either 0xFFFFFFFF to start or value from last piece */
264unsigned crc_32(unsigned char* buf, unsigned len, unsigned crc32)
265{
266 /* CCITT standard polynomial 0x04C11DB7 */
267 static const unsigned crc32_lookup[16] =
268 { /* lookup table for 4 bits at a time is affordable */
269 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9,
270 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005,
271 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
272 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD
273 };
274
275 unsigned char byte;
276 unsigned t;
277
278 while (len--)
279 {
280 byte = *buf++; /* get one byte of data */
281
282 /* upper nibble of our data */
283 t = crc32 >> 28; /* extract the 4 most significant bits */
284 t ^= byte >> 4; /* XOR in 4 bits of data into the extracted bits */
285 crc32 <<= 4; /* shift the CRC register left 4 bits */
286 crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */
287
288 /* lower nibble of our data */
289 t = crc32 >> 28; /* extract the 4 most significant bits */
290 t ^= byte & 0x0F; /* XOR in 4 bits of data into the extracted bits */
291 crc32 <<= 4; /* shift the CRC register left 4 bits */
292 crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */
293 }
294
295 return crc32;
296}
297
298
299/*********** Firmware File Functions + helpers ************/ 258/*********** Firmware File Functions + helpers ************/
300 259
301/* test if the version number is consistent with the platform */ 260/* test if the version number is consistent with the platform */
@@ -389,7 +348,7 @@ tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless)
389 348
390 if (has_crc) 349 if (has_crc)
391 { 350 {
392 crc32 = crc_32(sector, SEC_SIZE, crc32); /* checksum */ 351 crc32 = rb->crc_32(sector, SEC_SIZE, crc32); /* checksum */
393 352
394 /* in addition to the CRC, my files also have a platform ID */ 353 /* in addition to the CRC, my files also have a platform ID */
395 if (sector[PLATFORM_ADR] != PLATFORM_ID) /* for our hardware? */ 354 if (sector[PLATFORM_ADR] != PLATFORM_ID) /* for our hardware? */
@@ -442,7 +401,7 @@ tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless)
442 401
443 if (has_crc) 402 if (has_crc)
444 { 403 {
445 crc32 = crc_32(sector, got_now, crc32); /* checksum */ 404 crc32 = rb->crc_32(sector, got_now, crc32); /* checksum */
446 } 405 }
447 } while (fileleft); 406 } while (fileleft);
448 407
diff --git a/apps/plugins/iriver_flash.c b/apps/plugins/iriver_flash.c
index 0b3833b9cf..3f5490e754 100644
--- a/apps/plugins/iriver_flash.c
+++ b/apps/plugins/iriver_flash.c
@@ -177,47 +177,6 @@ bool cfi_get_flash_info(struct flash_info* pInfo)
177 return false; 177 return false;
178} 178}
179 179
180
181/*********** Utility Functions ************/
182
183
184/* Tool function to calculate a CRC32 across some buffer */
185/* third argument is either 0xFFFFFFFF to start or value from last piece */
186unsigned crc_32(const unsigned char* buf, unsigned len, unsigned crc32)
187{
188 /* CCITT standard polynomial 0x04C11DB7 */
189 static const unsigned crc32_lookup[16] =
190 { /* lookup table for 4 bits at a time is affordable */
191 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9,
192 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005,
193 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
194 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD
195 };
196
197 unsigned char byte;
198 unsigned t;
199
200 while (len--)
201 {
202 byte = *buf++; /* get one byte of data */
203
204 /* upper nibble of our data */
205 t = crc32 >> 28; /* extract the 4 most significant bits */
206 t ^= byte >> 4; /* XOR in 4 bits of data into the extracted bits */
207 crc32 <<= 4; /* shift the CRC register left 4 bits */
208 crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */
209
210 /* lower nibble of our data */
211 t = crc32 >> 28; /* extract the 4 most significant bits */
212 t ^= byte & 0x0F; /* XOR in 4 bits of data into the extracted bits */
213 crc32 <<= 4; /* shift the CRC register left 4 bits */
214 crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */
215 }
216
217 return crc32;
218}
219
220
221/***************** User Interface Functions *****************/ 180/***************** User Interface Functions *****************/
222int wait_for_button(void) 181int wait_for_button(void)
223{ 182{
@@ -357,18 +316,18 @@ bool detect_valid_bootloader(const unsigned char *addr, int len)
357{ 316{
358 int i; 317 int i;
359 unsigned long crc32; 318 unsigned long crc32;
360 319
361 /* Try to scan through all valid bootloaders. */ 320 /* Try to scan through all valid bootloaders. */
362 for (i = 0; valid_bootloaders[i][0]; i++) 321 for (i = 0; valid_bootloaders[i][0]; i++)
363 { 322 {
364 if (len > 0 && len != (long)valid_bootloaders[i][0]) 323 if (len > 0 && len != (long)valid_bootloaders[i][0])
365 continue; 324 continue;
366 325
367 crc32 = crc_32(addr, valid_bootloaders[i][0], 0xffffffff); 326 crc32 = rb->crc_32(addr, valid_bootloaders[i][0], 0xffffffff);
368 if (crc32 == valid_bootloaders[i][1]) 327 if (crc32 == valid_bootloaders[i][1])
369 return true; 328 return true;
370 } 329 }
371 330
372 return false; 331 return false;
373} 332}
374 333