From 360d00f6000eb9fe3ee15e86b7bcd991c9758802 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Sun, 22 Nov 2009 19:08:29 +0000 Subject: Fix reds. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23712 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/firmware_flash.c | 45 ++------------------------------------- apps/plugins/iriver_flash.c | 49 ++++--------------------------------------- 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) return false; } - -/*********** Utility Functions ************/ - - -/* Tool function to calculate a CRC32 across some buffer */ -/* third argument is either 0xFFFFFFFF to start or value from last piece */ -unsigned crc_32(unsigned char* buf, unsigned len, unsigned crc32) -{ - /* CCITT standard polynomial 0x04C11DB7 */ - static const unsigned crc32_lookup[16] = - { /* lookup table for 4 bits at a time is affordable */ - 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, - 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, - 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, - 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD - }; - - unsigned char byte; - unsigned t; - - while (len--) - { - byte = *buf++; /* get one byte of data */ - - /* upper nibble of our data */ - t = crc32 >> 28; /* extract the 4 most significant bits */ - t ^= byte >> 4; /* XOR in 4 bits of data into the extracted bits */ - crc32 <<= 4; /* shift the CRC register left 4 bits */ - crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */ - - /* lower nibble of our data */ - t = crc32 >> 28; /* extract the 4 most significant bits */ - t ^= byte & 0x0F; /* XOR in 4 bits of data into the extracted bits */ - crc32 <<= 4; /* shift the CRC register left 4 bits */ - crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */ - } - - return crc32; -} - - /*********** Firmware File Functions + helpers ************/ /* test if the version number is consistent with the platform */ @@ -389,7 +348,7 @@ tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless) if (has_crc) { - crc32 = crc_32(sector, SEC_SIZE, crc32); /* checksum */ + crc32 = rb->crc_32(sector, SEC_SIZE, crc32); /* checksum */ /* in addition to the CRC, my files also have a platform ID */ if (sector[PLATFORM_ADR] != PLATFORM_ID) /* for our hardware? */ @@ -442,7 +401,7 @@ tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless) if (has_crc) { - crc32 = crc_32(sector, got_now, crc32); /* checksum */ + crc32 = rb->crc_32(sector, got_now, crc32); /* checksum */ } } while (fileleft); 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) return false; } - -/*********** Utility Functions ************/ - - -/* Tool function to calculate a CRC32 across some buffer */ -/* third argument is either 0xFFFFFFFF to start or value from last piece */ -unsigned crc_32(const unsigned char* buf, unsigned len, unsigned crc32) -{ - /* CCITT standard polynomial 0x04C11DB7 */ - static const unsigned crc32_lookup[16] = - { /* lookup table for 4 bits at a time is affordable */ - 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, - 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, - 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, - 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD - }; - - unsigned char byte; - unsigned t; - - while (len--) - { - byte = *buf++; /* get one byte of data */ - - /* upper nibble of our data */ - t = crc32 >> 28; /* extract the 4 most significant bits */ - t ^= byte >> 4; /* XOR in 4 bits of data into the extracted bits */ - crc32 <<= 4; /* shift the CRC register left 4 bits */ - crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */ - - /* lower nibble of our data */ - t = crc32 >> 28; /* extract the 4 most significant bits */ - t ^= byte & 0x0F; /* XOR in 4 bits of data into the extracted bits */ - crc32 <<= 4; /* shift the CRC register left 4 bits */ - crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */ - } - - return crc32; -} - - /***************** User Interface Functions *****************/ int wait_for_button(void) { @@ -357,18 +316,18 @@ bool detect_valid_bootloader(const unsigned char *addr, int len) { int i; unsigned long crc32; - + /* Try to scan through all valid bootloaders. */ for (i = 0; valid_bootloaders[i][0]; i++) { if (len > 0 && len != (long)valid_bootloaders[i][0]) continue; - - crc32 = crc_32(addr, valid_bootloaders[i][0], 0xffffffff); + + crc32 = rb->crc_32(addr, valid_bootloaders[i][0], 0xffffffff); if (crc32 == valid_bootloaders[i][1]) return true; } - + return false; } -- cgit v1.2.3