summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2007-06-04 13:48:21 +0000
committerBarry Wardell <rockbox@barrywardell.net>2007-06-04 13:48:21 +0000
commit54c73a24b6841efb06ee812831892960e5584e26 (patch)
treef235c11a81ee29a8b826cef7908b8a5fd50dfc8c
parent3611b4c8d8498c808bb0c6c26975e166e637a0aa (diff)
downloadrockbox-54c73a24b6841efb06ee812831892960e5584e26.tar.gz
rockbox-54c73a24b6841efb06ee812831892960e5584e26.zip
Bring back rolo for mi4-based targets (H10 and Sansa).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13550 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--bootloader/main-pp.c76
-rw-r--r--firmware/SOURCES3
-rw-r--r--firmware/common/crc32-mi4.c93
-rw-r--r--firmware/export/config-e200.h1
-rw-r--r--firmware/export/config-h10.h1
-rw-r--r--firmware/export/config-h10_5gb.h1
-rw-r--r--firmware/include/crc32-mi4.h25
-rw-r--r--firmware/rolo.c19
8 files changed, 144 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 */
diff --git a/firmware/SOURCES b/firmware/SOURCES
index ad802dabcb..fdb457cbed 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -23,6 +23,9 @@ debug.c
23/* Common */ 23/* Common */
24common/atoi.c 24common/atoi.c
25common/crc32.c 25common/crc32.c
26#ifdef MI4_FORMAT
27common/crc32-mi4.c
28#endif
26common/ctype.c 29common/ctype.c
27#ifndef SIMULATOR 30#ifndef SIMULATOR
28common/dir.c 31common/dir.c
diff --git a/firmware/common/crc32-mi4.c b/firmware/common/crc32-mi4.c
new file mode 100644
index 0000000000..8956364f10
--- /dev/null
+++ b/firmware/common/crc32-mi4.c
@@ -0,0 +1,93 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: crc32.c 10464 2006-08-05 20:19:10Z miipekk $
9 *
10 * Copyright (C) 2007 Barry Wardell
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20/*
21 * We can't use the CRC32 implementation in the firmware library as it uses a
22 * different polynomial. The polynomial needed is 0xEDB88320L
23 *
24 * CRC32 implementation taken from:
25 *
26 * efone - Distributed internet phone system.
27 *
28 * (c) 1999,2000 Krzysztof Dabrowski
29 * (c) 1999,2000 ElysiuM deeZine
30 *
31 * This program is free software; you can redistribute it and/or
32 * modify it under the terms of the GNU General Public License
33 * as published by the Free Software Foundation; either version
34 * 2 of the License, or (at your option) any later version.
35 *
36 */
37
38/* based on implementation by Finn Yannick Jacobs */
39
40
41
42/* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab().
43 * so make sure, you call it before using the other
44 * functions!
45 */
46static unsigned int crc_tab[256];
47
48/* chksum_crc() -- to a given block, this one calculates the
49 * crc32-checksum until the length is
50 * reached. the crc32-checksum will be
51 * the result.
52 */
53unsigned int chksum_crc32 (unsigned char *block, unsigned int length)
54{
55 register unsigned long crc;
56 unsigned long i;
57
58 crc = 0;
59 for (i = 0; i < length; i++)
60 {
61 crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF];
62 }
63 return (crc);
64}
65
66/* chksum_crc32gentab() -- to a global crc_tab[256], this one will
67 * calculate the crcTable for crc32-checksums.
68 * it is generated to the polynom [..]
69 */
70
71void chksum_crc32gentab (void)
72{
73 unsigned long crc, poly;
74 int i, j;
75
76 poly = 0xEDB88320L;
77 for (i = 0; i < 256; i++)
78 {
79 crc = i;
80 for (j = 8; j > 0; j--)
81 {
82 if (crc & 1)
83 {
84 crc = (crc >> 1) ^ poly;
85 }
86 else
87 {
88 crc >>= 1;
89 }
90 }
91 crc_tab[i] = crc;
92 }
93}
diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h
index 73ff2e69ba..9d4fb1ccef 100644
--- a/firmware/export/config-e200.h
+++ b/firmware/export/config-e200.h
@@ -136,6 +136,7 @@
136/* Define this if you have adjustable CPU frequency */ 136/* Define this if you have adjustable CPU frequency */
137/*#define HAVE_ADJUSTABLE_CPU_FREQ*/ 137/*#define HAVE_ADJUSTABLE_CPU_FREQ*/
138 138
139#define MI4_FORMAT
139#define BOOTFILE_EXT "mi4" 140#define BOOTFILE_EXT "mi4"
140#define BOOTFILE "rockbox." BOOTFILE_EXT 141#define BOOTFILE "rockbox." BOOTFILE_EXT
141#define OLD_BOOTFILE "rockbox.e200" 142#define OLD_BOOTFILE "rockbox.e200"
diff --git a/firmware/export/config-h10.h b/firmware/export/config-h10.h
index a5d32ebeaa..b0617eb71e 100644
--- a/firmware/export/config-h10.h
+++ b/firmware/export/config-h10.h
@@ -158,6 +158,7 @@
158/* Define this if you have adjustable CPU frequency */ 158/* Define this if you have adjustable CPU frequency */
159/*#define HAVE_ADJUSTABLE_CPU_FREQ*/ 159/*#define HAVE_ADJUSTABLE_CPU_FREQ*/
160 160
161#define MI4_FORMAT
161#define BOOTFILE_EXT "mi4" 162#define BOOTFILE_EXT "mi4"
162#define BOOTFILE "rockbox." BOOTFILE_EXT 163#define BOOTFILE "rockbox." BOOTFILE_EXT
163#define OLD_BOOTFILE "rockbox.h10" 164#define OLD_BOOTFILE "rockbox.h10"
diff --git a/firmware/export/config-h10_5gb.h b/firmware/export/config-h10_5gb.h
index 48d73173ce..37a1a47c7f 100644
--- a/firmware/export/config-h10_5gb.h
+++ b/firmware/export/config-h10_5gb.h
@@ -141,6 +141,7 @@
141/* Define this if you have adjustable CPU frequency */ 141/* Define this if you have adjustable CPU frequency */
142/*#define HAVE_ADJUSTABLE_CPU_FREQ*/ 142/*#define HAVE_ADJUSTABLE_CPU_FREQ*/
143 143
144#define MI4_FORMAT
144#define BOOTFILE_EXT "mi4" 145#define BOOTFILE_EXT "mi4"
145#define BOOTFILE "rockbox." BOOTFILE_EXT 146#define BOOTFILE "rockbox." BOOTFILE_EXT
146#define OLD_BOOTFILE "rockbox.h10" 147#define OLD_BOOTFILE "rockbox.h10"
diff --git a/firmware/include/crc32-mi4.h b/firmware/include/crc32-mi4.h
new file mode 100644
index 0000000000..e7f3229d5b
--- /dev/null
+++ b/firmware/include/crc32-mi4.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: crc32.h 10464 2006-08-05 20:19:10Z miipekk $
9 *
10 * Copyright (C) 2007 Barry Wardell
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _CRC32_MI4_H
20#define _CRC32_MI4_H
21
22unsigned int chksum_crc32 (unsigned char *block, unsigned int length);
23void chksum_crc32gentab (void);
24
25#endif
diff --git a/firmware/rolo.c b/firmware/rolo.c
index 0375a7ac82..0b8a4f28ba 100644
--- a/firmware/rolo.c
+++ b/firmware/rolo.c
@@ -30,6 +30,14 @@
30#include "string.h" 30#include "string.h"
31#include "buffer.h" 31#include "buffer.h"
32 32
33#ifdef MI4_FORMAT
34#include "crc32-mi4.h"
35#undef FIRMWARE_OFFSET_FILE_CRC
36#undef FIRMWARE_OFFSET_FILE_DATA
37#define FIRMWARE_OFFSET_FILE_CRC 0xC
38#define FIRMWARE_OFFSET_FILE_DATA 0x200
39#endif
40
33#if !defined(IRIVER_IFP7XX_SERIES) && \ 41#if !defined(IRIVER_IFP7XX_SERIES) && \
34 (CONFIG_CPU != PP5002) && (CONFIG_CPU != S3C2440) 42 (CONFIG_CPU != PP5002) && (CONFIG_CPU != S3C2440)
35/* FIX: this doesn't work on iFP, 3rd Gen ipods */ 43/* FIX: this doesn't work on iFP, 3rd Gen ipods */
@@ -152,7 +160,9 @@ int rolo_load(const char* filename)
152 int fd; 160 int fd;
153 long length; 161 long length;
154#if defined(CPU_COLDFIRE) || defined(CPU_PP) 162#if defined(CPU_COLDFIRE) || defined(CPU_PP)
163#if !defined(MI4_FORMAT)
155 int i; 164 int i;
165#endif
156 unsigned long checksum,file_checksum; 166 unsigned long checksum,file_checksum;
157#else 167#else
158 long file_length; 168 long file_length;
@@ -189,8 +199,11 @@ int rolo_load(const char* filename)
189 return -1; 199 return -1;
190 } 200 }
191 201
202#if !defined(MI4_FORMAT)
192 /* Rockbox checksums are big-endian */ 203 /* Rockbox checksums are big-endian */
193 file_checksum = betoh32(file_checksum); 204 file_checksum = betoh32(file_checksum);
205#endif
206
194#ifdef CPU_PP 207#ifdef CPU_PP
195 cpu_message = COP_REBOOT; 208 cpu_message = COP_REBOOT;
196 COP_CTL = PROC_WAKE; 209 COP_CTL = PROC_WAKE;
@@ -208,11 +221,17 @@ int rolo_load(const char* filename)
208 return -1; 221 return -1;
209 } 222 }
210 223
224#ifdef MI4_FORMAT
225 /* Check CRC32 to see if we have a valid file */
226 chksum_crc32gentab();
227 checksum = chksum_crc32 (audiobuf, length);
228#else
211 checksum = MODEL_NUMBER; 229 checksum = MODEL_NUMBER;
212 230
213 for(i = 0;i < length;i++) { 231 for(i = 0;i < length;i++) {
214 checksum += audiobuf[i]; 232 checksum += audiobuf[i];
215 } 233 }
234#endif
216 235
217 /* Verify checksum against file header */ 236 /* Verify checksum against file header */
218 if (checksum != file_checksum) { 237 if (checksum != file_checksum) {