summaryrefslogtreecommitdiff
path: root/bootloader/main-pp.c
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader/main-pp.c')
-rw-r--r--bootloader/main-pp.c76
1 files changed, 1 insertions, 75 deletions
diff --git a/bootloader/main-pp.c b/bootloader/main-pp.c
index b95b7a10f4..49d7f0a2f7 100644
--- a/bootloader/main-pp.c
+++ b/bootloader/main-pp.c
@@ -31,6 +31,7 @@
31#include "ata.h" 31#include "ata.h"
32#include "button.h" 32#include "button.h"
33#include "disk.h" 33#include "disk.h"
34#include "crc32-mi4.h"
34#include <string.h> 35#include <string.h>
35#ifdef SANSA_E200 36#ifdef SANSA_E200
36#include "usb.h" 37#include "usb.h"
@@ -250,81 +251,6 @@ static int tea_find_key(struct mi4header_t *mi4header, int fd)
250 251
251 return key_found; 252 return key_found;
252} 253}
253
254/*
255 * We can't use the CRC32 implementation in the firmware library as it uses a
256 * different polynomial. The polynomial needed is 0xEDB88320L
257 *
258 * CRC32 implementation taken from:
259 *
260 * efone - Distributed internet phone system.
261 *
262 * (c) 1999,2000 Krzysztof Dabrowski
263 * (c) 1999,2000 ElysiuM deeZine
264 *
265 * This program is free software; you can redistribute it and/or
266 * modify it under the terms of the GNU General Public License
267 * as published by the Free Software Foundation; either version
268 * 2 of the License, or (at your option) any later version.
269 *
270 */
271
272/* based on implementation by Finn Yannick Jacobs */
273
274
275
276/* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab().
277 * so make sure, you call it before using the other
278 * functions!
279 */
280static unsigned int crc_tab[256];
281
282/* chksum_crc() -- to a given block, this one calculates the
283 * crc32-checksum until the length is
284 * reached. the crc32-checksum will be
285 * the result.
286 */
287unsigned int chksum_crc32 (unsigned char *block, unsigned int length)
288{
289 register unsigned long crc;
290 unsigned long i;
291
292 crc = 0;
293 for (i = 0; i < length; i++)
294 {
295 crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF];
296 }
297 return (crc);
298}
299
300/* chksum_crc32gentab() -- to a global crc_tab[256], this one will
301 * calculate the crcTable for crc32-checksums.
302 * it is generated to the polynom [..]
303 */
304
305static void chksum_crc32gentab (void)
306{
307 unsigned long crc, poly;
308 int i, j;
309
310 poly = 0xEDB88320L;
311 for (i = 0; i < 256; i++)
312 {
313 crc = i;
314 for (j = 8; j > 0; j--)
315 {
316 if (crc & 1)
317 {
318 crc = (crc >> 1) ^ poly;
319 }
320 else
321 {
322 crc >>= 1;
323 }
324 }
325 crc_tab[i] = crc;
326 }
327}
328 254
329 255
330/* Load mi4 format firmware image */ 256/* Load mi4 format firmware image */