summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2011-09-02 21:34:28 +0000
committerFrank Gevaerts <frank@gevaerts.be>2011-09-02 21:34:28 +0000
commit2b9e9440211cb4167767e2a3492f8b0b937a7689 (patch)
treef078e68468784af34ec97bc94a4a842e789c44c5
parente9eb5b31ad3b288fbc36ec9421c473fde0c59f38 (diff)
downloadrockbox-2b9e9440211cb4167767e2a3492f8b0b937a7689.tar.gz
rockbox-2b9e9440211cb4167767e2a3492f8b0b937a7689.zip
Rework c200wipe to use proper partitioning and formatting code, which makes the code size-independent.
Also support the e200 with this code. Apparently it's also possible to get the e200 in a state where .fmt files don't help. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30413 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--bootloader/SOURCES7
-rw-r--r--bootloader/fat32format.c504
-rw-r--r--bootloader/main-c240wipe.c220
-rw-r--r--bootloader/main-c250wipe.c287
-rw-r--r--bootloader/main-ppsansawipe.c250
-rw-r--r--firmware/target/arm/sandisk/boot.lds2
-rwxr-xr-xtools/configure18
7 files changed, 763 insertions, 525 deletions
diff --git a/bootloader/SOURCES b/bootloader/SOURCES
index 9fd532b55d..bc9dc855b1 100644
--- a/bootloader/SOURCES
+++ b/bootloader/SOURCES
@@ -18,10 +18,9 @@ show_logo.c
18 defined(SAMSUNG_YH925) || defined(SANSA_VIEW) 18 defined(SAMSUNG_YH925) || defined(SANSA_VIEW)
19#ifdef E200R_INSTALLER 19#ifdef E200R_INSTALLER
20main-e200r-installer.c 20main-e200r-installer.c
21#elif defined(C240_ERASE) 21#elif defined(SANSA_PP_ERASE)
22main-c240wipe.c 22main-ppsansawipe.c
23#elif defined(C250_ERASE) 23fat32format.c
24main-c250wipe.c
25#else 24#else
26show_logo.c 25show_logo.c
27main-pp.c 26main-pp.c
diff --git a/bootloader/fat32format.c b/bootloader/fat32format.c
new file mode 100644
index 0000000000..540ee89b54
--- /dev/null
+++ b/bootloader/fat32format.c
@@ -0,0 +1,504 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: fat32format.c 30351 2011-08-25 19:58:47Z thomasjfox $
9 *
10 *
11 * FAT32 formatting functions. Based on:
12 *
13 * Fat32 formatter version 1.03
14 * (c) Tom Thornhill 2005
15 * This software is covered by the GPL.
16 * By using this tool, you agree to absolve Ridgecrop of an liabilities for
17 * lost data.
18 * Please backup any data you value before using this tool.
19 *
20 *
21 * Modified June 2007 by Dave Chapman for use in ipodpatcher
22 * Modified September 2011 by Frank Gevaerts for use in sansa eraser
23 *
24 *
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version 2
28 * of the License, or (at your option) any later version.
29 *
30 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
31 * KIND, either express or implied.
32 *
33 ****************************************************************************/
34
35#include <stdio.h>
36#include <stdlib.h>
37#include "common.h"
38#include "cpu.h"
39#include "file.h"
40#include "system.h"
41#include "kernel.h"
42#include "lcd.h"
43#include "font.h"
44#include "storage.h"
45#include "button.h"
46#include "disk.h"
47#include "crc32-mi4.h"
48#include <string.h>
49#include "i2c.h"
50#include "backlight-target.h"
51#include "power.h"
52
53#define SECTOR_SIZE 512
54
55/* The following functions are not the most efficient, but are
56 self-contained and don't require needing to know endianness of CPU
57 at compile-time.
58
59 Note that htole16/htole32 exist on some platforms, so for
60 simplicity we use different names.
61
62*/
63
64static uint16_t rb_htole16(uint16_t x)
65{
66 uint16_t test = 0x1234;
67 unsigned char* p = (unsigned char*)&test;
68
69 if (p[0]==0x12) {
70 /* Big-endian */
71 return swap16(x);
72 } else {
73 return x;
74 }
75}
76
77static uint32_t rb_htole32(uint32_t x)
78{
79 uint32_t test = 0x12345678;
80 unsigned char* p = (unsigned char*)&test;
81
82 if (p[0]==0x12) {
83 /* Big-endian */
84 return swap32(x);
85 } else {
86 return x;
87 }
88}
89
90
91/* A large aligned buffer for disk I/O */
92unsigned char sectorbuf[128*SECTOR_SIZE];
93
94/* TODO: Pass these as parameters to the various create_ functions */
95
96/* can be zero for default or 1,2,4,8,16,32 or 64 */
97static int sectors_per_cluster = 0;
98
99/* Recommended values */
100static uint32_t ReservedSectCount = 32;
101static uint32_t NumFATs = 2;
102static uint32_t BackupBootSect = 6;
103static uint32_t VolumeId=0; /* calculated before format */
104
105/* Calculated later */
106static uint32_t FatSize=0;
107static uint32_t BytesPerSect=0;
108static uint32_t SectorsPerCluster=0;
109static uint32_t TotalSectors=0;
110static uint32_t SystemAreaSize=0;
111static uint32_t UserAreaSize=0;
112static uint8_t VolId[12] = "NO NAME ";
113
114
115struct FAT_BOOTSECTOR32
116{
117 /* Common fields. */
118 uint8_t sJmpBoot[3];
119 char sOEMName[8];
120 uint16_t wBytsPerSec;
121 uint8_t bSecPerClus;
122 uint16_t wRsvdSecCnt;
123 uint8_t bNumFATs;
124 uint16_t wRootEntCnt;
125 uint16_t wTotSec16; /* if zero, use dTotSec32 instead */
126 uint8_t bMedia;
127 uint16_t wFATSz16;
128 uint16_t wSecPerTrk;
129 uint16_t wNumHeads;
130 uint32_t dHiddSec;
131 uint32_t dTotSec32;
132
133 /* Fat 32/16 only */
134 uint32_t dFATSz32;
135 uint16_t wExtFlags;
136 uint16_t wFSVer;
137 uint32_t dRootClus;
138 uint16_t wFSInfo;
139 uint16_t wBkBootSec;
140 uint8_t Reserved[12];
141 uint8_t bDrvNum;
142 uint8_t Reserved1;
143 uint8_t bBootSig; /* == 0x29 if next three fields are ok */
144 uint32_t dBS_VolID;
145 uint8_t sVolLab[11];
146 uint8_t sBS_FilSysType[8];
147} __attribute__((packed));
148
149struct FAT_FSINFO {
150 uint32_t dLeadSig; // 0x41615252
151 uint8_t sReserved1[480]; // zeros
152 uint32_t dStrucSig; // 0x61417272
153 uint32_t dFree_Count; // 0xFFFFFFFF
154 uint32_t dNxt_Free; // 0xFFFFFFFF
155 uint8_t sReserved2[12]; // zeros
156 uint32_t dTrailSig; // 0xAA550000
157} __attribute__((packed));
158
159
160/* Write "count" zero sectors, starting at sector "sector" */
161static int zero_sectors(uint32_t sector, int count)
162{
163 int n;
164
165 memset(sectorbuf, 0, 128 * SECTOR_SIZE);
166
167 /* Write 128 sectors at a time */
168 while (count) {
169 if (count >= 128)
170 n = 128;
171 else
172 n = count;
173
174 if (storage_write_sectors(sector,n,sectorbuf) < 0) {
175 printf("[ERR] Write failed in zero_sectors\n");
176 return -1;
177 }
178 sector += n;
179 count -= n;
180 }
181
182 return 0;
183}
184
185
186/*
18728.2 CALCULATING THE VOLUME SERIAL NUMBER
188
189For example, say a disk was formatted on 26 Dec 95 at 9:55 PM and 41.94
190seconds. DOS takes the date and time just before it writes it to the
191disk.
192
193Low order word is calculated: Volume Serial Number is:
194 Month & Day 12/26 0c1ah
195 Sec & Hundrenths 41:94 295eh 3578:1d02
196 -----
197 3578h
198
199High order word is calculated:
200 Hours & Minutes 21:55 1537h
201 Year 1995 07cbh
202 -----
203 1d02h
204*/
205static uint32_t get_volume_id ( void )
206{
207 /* TODO */
208#if 0
209 SYSTEMTIME s;
210 uint32_t d;
211 uint16_t lo,hi,tmp;
212
213 GetLocalTime( &s );
214
215 lo = s.wDay + ( s.wMonth << 8 );
216 tmp = (s.wMilliseconds/10) + (s.wSecond << 8 );
217 lo += tmp;
218
219 hi = s.wMinute + ( s.wHour << 8 );
220 hi += s.wYear;
221
222 d = lo + (hi << 16);
223 return(d);
224#endif
225 return(0);
226}
227
228/*
229This is the Microsoft calculation from FATGEN
230
231 uint32_t RootDirSectors = 0;
232 uint32_t TmpVal1, TmpVal2, FATSz;
233
234 TmpVal1 = DskSize - ( ReservedSecCnt + RootDirSectors);
235 TmpVal2 = (256 * SecPerClus) + NumFATs;
236 TmpVal2 = TmpVal2 / 2;
237 FATSz = (TmpVal1 + (TmpVal2 - 1)) / TmpVal2;
238
239 return( FatSz );
240*/
241
242
243static uint32_t get_fat_size_sectors(uint32_t DskSize, uint32_t ReservedSecCnt,
244 uint32_t SecPerClus, uint32_t NumFATs,
245 uint32_t BytesPerSect)
246{
247 uint32_t Numerator, Denominator;
248 uint32_t FatElementSize = 4;
249 uint32_t FatSz;
250
251 /* This is based on
252 http://hjem.get2net.dk/rune_moeller_barnkob/filesystems/fat.html
253 I've made the obvious changes for FAT32
254 */
255
256 Numerator = FatElementSize * ( DskSize - ReservedSecCnt );
257 Denominator = ( SecPerClus * BytesPerSect ) + ( FatElementSize * NumFATs );
258 FatSz = Numerator / Denominator;
259
260 /* round up */
261 FatSz += 1;
262
263 return((uint32_t)FatSz);
264}
265
266static uint8_t get_spc(uint32_t ClusterSizeKB, uint32_t BytesPerSect)
267{
268 uint32_t spc = ( ClusterSizeKB * 1024 ) / BytesPerSect;
269 return( (uint8_t) spc );
270}
271
272static uint8_t get_sectors_per_cluster(uint32_t DiskSizeSectors,
273 uint32_t BytesPerSect)
274{
275 uint8_t ret = 0x01; /* 1 sector per cluster */
276 int32_t DiskSizeMB = DiskSizeSectors / ( 1024*1024 / SECTOR_SIZE);
277
278 /* 512 MB to 8,191 MB 4 KB */
279 if ( DiskSizeMB > 512 )
280 ret = get_spc( 4, BytesPerSect ); /* ret = 0x8; */
281
282 /* 8,192 MB to 16,383 MB 8 KB */
283 if ( DiskSizeMB > 8192 )
284 ret = get_spc( 8, BytesPerSect ); /* ret = 0x10; */
285
286 /* 16,384 MB to 32,767 MB 16 KB */
287 if ( DiskSizeMB > 16384 )
288 ret = get_spc( 16, BytesPerSect ); /* ret = 0x20; */
289
290 /* Larger than 32,768 MB 32 KB */
291 if ( DiskSizeMB > 32768 )
292 ret = get_spc( 32, BytesPerSect ); /* ret = 0x40; */
293
294 return( ret );
295
296}
297
298static void create_boot_sector(unsigned char* buf)
299{
300 struct FAT_BOOTSECTOR32* pFAT32BootSect = (struct FAT_BOOTSECTOR32*)buf;
301
302 /* fill out the boot sector and fs info */
303 pFAT32BootSect->sJmpBoot[0]=0xEB;
304 pFAT32BootSect->sJmpBoot[1]=0x5A;
305 pFAT32BootSect->sJmpBoot[2]=0x90;
306 memcpy(pFAT32BootSect->sOEMName, "MSWIN4.1", 8 );
307 pFAT32BootSect->wBytsPerSec = rb_htole16(BytesPerSect);
308 pFAT32BootSect->bSecPerClus = SectorsPerCluster ;
309 pFAT32BootSect->wRsvdSecCnt = rb_htole16(ReservedSectCount);
310 pFAT32BootSect->bNumFATs = NumFATs;
311 pFAT32BootSect->wRootEntCnt = rb_htole16(0);
312 pFAT32BootSect->wTotSec16 = rb_htole16(0);
313 pFAT32BootSect->bMedia = 0xF8;
314 pFAT32BootSect->wFATSz16 = rb_htole16(0);
315 pFAT32BootSect->wSecPerTrk = 63;
316 pFAT32BootSect->wNumHeads = 255;
317 pFAT32BootSect->dHiddSec = 0;
318 pFAT32BootSect->dTotSec32 = rb_htole32(TotalSectors);
319 pFAT32BootSect->dFATSz32 = rb_htole32(FatSize);
320 pFAT32BootSect->wExtFlags = rb_htole16(0);
321 pFAT32BootSect->wFSVer = rb_htole16(0);
322 pFAT32BootSect->dRootClus = rb_htole32(2);
323 pFAT32BootSect->wFSInfo = rb_htole16(1);
324 pFAT32BootSect->wBkBootSec = rb_htole16(BackupBootSect);
325 pFAT32BootSect->bDrvNum = 0x80;
326 pFAT32BootSect->Reserved1 = 0;
327 pFAT32BootSect->bBootSig = 0x29;
328 pFAT32BootSect->dBS_VolID = rb_htole32(VolumeId);
329 memcpy(pFAT32BootSect->sVolLab, VolId, 11);
330 memcpy(pFAT32BootSect->sBS_FilSysType, "FAT32 ", 8 );
331
332 buf[510] = 0x55;
333 buf[511] = 0xaa;
334}
335
336static void create_fsinfo(unsigned char* buf)
337{
338 struct FAT_FSINFO* pFAT32FsInfo = (struct FAT_FSINFO*)buf;
339
340 /* FSInfo sect */
341 pFAT32FsInfo->dLeadSig = rb_htole32(0x41615252);
342 pFAT32FsInfo->dStrucSig = rb_htole32(0x61417272);
343 pFAT32FsInfo->dFree_Count = rb_htole32((uint32_t) -1);
344 pFAT32FsInfo->dNxt_Free = rb_htole32((uint32_t) -1);
345 pFAT32FsInfo->dTrailSig = rb_htole32(0xaa550000);
346 pFAT32FsInfo->dFree_Count = rb_htole32((UserAreaSize/SectorsPerCluster)-1);
347
348 /* clusters 0-1 reserved, we used cluster 2 for the root dir */
349 pFAT32FsInfo->dNxt_Free = rb_htole32(3);
350}
351
352static void create_firstfatsector(unsigned char* buf)
353{
354 uint32_t* p = (uint32_t*)buf; /* We know the buffer is aligned */
355
356 /* First FAT Sector */
357 p[0] = rb_htole32(0x0ffffff8); /* Reserved cluster 1 media id in low byte */
358 p[1] = rb_htole32(0x0fffffff); /* Reserved cluster 2 EOC */
359 p[2] = rb_htole32(0x0fffffff); /* end of cluster chain for root dir */
360}
361
362int format_partition(int start, int size)
363{
364 uint32_t i;
365 uint32_t qTotalSectors=0;
366 uint32_t FatNeeded;
367
368 VolumeId = get_volume_id( );
369
370 /* Only support hard disks at the moment */
371 if ( SECTOR_SIZE != 512 )
372 {
373 printf("[ERR] Only disks with 512 bytes per sector are supported.\n");
374 return -1;
375 }
376 BytesPerSect = SECTOR_SIZE;
377
378 /* Checks on Disk Size */
379 qTotalSectors = size;
380
381 /* low end limit - 65536 sectors */
382 if ( qTotalSectors < 65536 )
383 {
384 /* I suspect that most FAT32 implementations would mount this
385 volume just fine, but the spec says that we shouldn't do
386 this, so we won't */
387
388 printf("[ERR] This drive is too small for FAT32 - there must be at least 64K clusters\n" );
389 return -1;
390 }
391
392 if ( qTotalSectors >= 0xffffffff )
393 {
394 /* This is a more fundamental limitation on FAT32 - the total
395 sector count in the root dir is 32bit. With a bit of
396 creativity, FAT32 could be extended to handle at least 2^28
397 clusters There would need to be an extra field in the
398 FSInfo sector, and the old sector count could be set to
399 0xffffffff. This is non standard though, the Windows FAT
400 driver FASTFAT.SYS won't understand this. Perhaps a future
401 version of FAT32 and FASTFAT will handle this. */
402
403 printf("[ERR] This drive is too big for FAT32 - max 2TB supported\n");
404 }
405
406 if ( sectors_per_cluster ) {
407 SectorsPerCluster = sectors_per_cluster;
408 } else {
409 SectorsPerCluster = get_sectors_per_cluster(size,
410 BytesPerSect );
411 }
412
413 TotalSectors = (uint32_t) qTotalSectors;
414
415 FatSize = get_fat_size_sectors(TotalSectors, ReservedSectCount,
416 SectorsPerCluster, NumFATs, BytesPerSect );
417
418 UserAreaSize = TotalSectors - ReservedSectCount - (NumFATs*FatSize);
419
420 /* First zero out ReservedSect + FatSize * NumFats + SectorsPerCluster */
421 SystemAreaSize = (ReservedSectCount+(NumFATs*FatSize) + SectorsPerCluster);
422
423 /* Work out the Cluster count */
424 FatNeeded = UserAreaSize/SectorsPerCluster;
425
426 /* check for a cluster count of >2^28, since the upper 4 bits of
427 the cluster values in the FAT are reserved. */
428 if (FatNeeded > 0x0FFFFFFF) {
429 printf("[ERR] This drive has more than 2^28 clusters, try to specify a larger cluster size\n" );
430 return -1;
431 }
432
433 /* Sanity check, make sure the fat is big enough.
434 Convert the cluster count into a Fat sector count, and check
435 the fat size value we calculated earlier is OK. */
436
437 FatNeeded *=4;
438 FatNeeded += (BytesPerSect-1);
439 FatNeeded /= BytesPerSect;
440
441 if ( FatNeeded > FatSize ) {
442 printf("[ERR] Drive too big to format\n");
443 return -1;
444 }
445
446 /*
447 Write boot sector, fats
448 Sector 0 Boot Sector
449 Sector 1 FSInfo
450 Sector 2 More boot code - we write zeros here
451 Sector 3 unused
452 Sector 4 unused
453 Sector 5 unused
454 Sector 6 Backup boot sector
455 Sector 7 Backup FSInfo sector
456 Sector 8 Backup 'more boot code'
457 zero'd sectors upto ReservedSectCount
458 FAT1 ReservedSectCount to ReservedSectCount + FatSize
459 ...
460 FATn ReservedSectCount to ReservedSectCount + FatSize
461 RootDir - allocated to cluster2
462 */
463
464
465 printf("[INFO] Formatting partition:...");
466
467 /* Once zero_sectors has run, any data on the drive is basically lost... */
468 printf("[INFO] Clearing out %d sectors for Reserved sectors, fats and root cluster...\n", SystemAreaSize );
469
470 zero_sectors(start, SystemAreaSize);
471
472 printf("[INFO] Initialising reserved sectors and FATs...\n" );
473
474 /* Create the boot sector structure */
475 create_boot_sector(sectorbuf);
476 create_fsinfo(sectorbuf + 512);
477
478 if (storage_write_sectors(start,2,sectorbuf)) {
479 printf("[ERR] Write failed (first copy of bootsect/fsinfo)\n");
480 return -1;
481 }
482
483 if (storage_write_sectors(start + BackupBootSect,2,sectorbuf)) {
484 printf("[ERR] Write failed (first copy of bootsect/fsinfo)\n");
485 return -1;
486 }
487
488 /* Create the first FAT sector */
489 create_firstfatsector(sectorbuf);
490
491 /* Write the first fat sector in the right places */
492 for ( i=0; i<NumFATs; i++ ) {
493 int SectorStart = ReservedSectCount + (i * FatSize );
494
495 if (storage_write_sectors(start + SectorStart,1,sectorbuf)) {
496 printf("[ERR] Write failed (first copy of bootsect/fsinfo)\n");
497 return -1;
498 }
499 }
500
501 printf("[INFO] Format successful\n");
502
503 return 0;
504}
diff --git a/bootloader/main-c240wipe.c b/bootloader/main-c240wipe.c
deleted file mode 100644
index 556907b34a..0000000000
--- a/bootloader/main-c240wipe.c
+++ /dev/null
@@ -1,220 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: main-e200r-installer.c 15599 2007-11-12 18:49:53Z amiconn $
9 *
10 * Copyright (C) 2006 by Barry Wardell
11 *
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
14 *
15 * All files in this archive are subject to the GNU General Public License.
16 * See the file COPYING in the source tree root for full license agreement.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include <stdio.h>
24#include <stdlib.h>
25#include "common.h"
26#include "cpu.h"
27#include "file.h"
28#include "system.h"
29#include "kernel.h"
30#include "lcd.h"
31#include "font.h"
32#include "storage.h"
33#include "button.h"
34#include "disk.h"
35#include "crc32-mi4.h"
36#include <string.h>
37#include "i2c.h"
38#include "backlight-target.h"
39#include "power.h"
40
41
42unsigned char mbr[] = {
43 0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0xfb, 0x50, 0x07, 0x50, 0x1f, 0xfc, 0xbe, 0x1b, 0x7c,
44 0xbf, 0x1b, 0x06, 0x50, 0x57, 0xb9, 0xe5, 0x01, 0xf3, 0xa4, 0xcb, 0xbe, 0xbe, 0x07, 0xb1, 0x04,
45 0x38, 0x2c, 0x7c, 0x09, 0x75, 0x15, 0x83, 0xc6, 0x10, 0xe2, 0xf5, 0xcd, 0x18, 0x8b, 0x14, 0x8b,
46 0xee, 0x83, 0xc6, 0x10, 0x49, 0x74, 0x16, 0x38, 0x2c, 0x74, 0xf6, 0xbe, 0x10, 0x07, 0x4e, 0xac,
47 0x3c, 0x00, 0x74, 0xfa, 0xbb, 0x07, 0x00, 0xb4, 0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0x89, 0x46, 0x25,
48 0x96, 0x8a, 0x46, 0x04, 0xb4, 0x06, 0x3c, 0x0e, 0x74, 0x11, 0xb4, 0x0b, 0x3c, 0x0c, 0x74, 0x05,
49 0x3a, 0xc4, 0x75, 0x2b, 0x40, 0xc6, 0x46, 0x25, 0x06, 0x75, 0x24, 0xbb, 0xaa, 0x55, 0x50, 0xb4,
50 0x41, 0xcd, 0x13, 0x58, 0x72, 0x16, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x10, 0xf6, 0xc1, 0x01, 0x74,
51 0x0b, 0x8a, 0xe0, 0x88, 0x56, 0x24, 0xc7, 0x06, 0xa1, 0x06, 0xeb, 0x1e, 0x88, 0x66, 0x04, 0xbf,
52 0x0a, 0x00, 0xb8, 0x01, 0x02, 0x8b, 0xdc, 0x33, 0xc9, 0x83, 0xff, 0x05, 0x7f, 0x03, 0x8b, 0x4e,
53 0x25, 0x03, 0x4e, 0x02, 0xcd, 0x13, 0x72, 0x29, 0xbe, 0x75, 0x07, 0x81, 0x3e, 0xfe, 0x7d, 0x55,
54 0xaa, 0x74, 0x5a, 0x83, 0xef, 0x05, 0x7f, 0xda, 0x85, 0xf6, 0x75, 0x83, 0xbe, 0x3f, 0x07, 0xeb,
55 0x8a, 0x98, 0x91, 0x52, 0x99, 0x03, 0x46, 0x08, 0x13, 0x56, 0x0a, 0xe8, 0x12, 0x00, 0x5a, 0xeb,
56 0xd5, 0x4f, 0x74, 0xe4, 0x33, 0xc0, 0xcd, 0x13, 0xeb, 0xb8, 0x00, 0x00, 0x80, 0x32, 0x22, 0x16,
57 0x56, 0x33, 0xf6, 0x56, 0x56, 0x52, 0x50, 0x06, 0x53, 0x51, 0xbe, 0x10, 0x00, 0x56, 0x8b, 0xf4,
58 0x50, 0x52, 0xb8, 0x00, 0x42, 0x8a, 0x56, 0x24, 0xcd, 0x13, 0x5a, 0x58, 0x8d, 0x64, 0x10, 0x72,
59 0x0a, 0x40, 0x75, 0x01, 0x42, 0x80, 0xc7, 0x02, 0xe2, 0xf7, 0xf8, 0x5e, 0xc3, 0xeb, 0x74, 0x49,
60 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e,
61 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x20, 0x53, 0x65, 0x74, 0x75, 0x70, 0x20, 0x63, 0x61,
62 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x2e, 0x00, 0x45,
63 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65,
64 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x20, 0x53,
65 0x65, 0x74, 0x75, 0x70, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74,
66 0x69, 0x6e, 0x75, 0x65, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0x00, 0x8b, 0xfc, 0x1e, 0x57, 0x8b, 0xf5, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x10,
71 0x10, 0x00, 0x06, 0x59, 0x1f, 0x7a, 0xff, 0x03, 0x00, 0x00, 0x01, 0xfa, 0x1d, 0x00, 0x00, 0x59,
72 0x20, 0x7a, 0x84, 0xe5, 0x29, 0x7c, 0x00, 0xfe, 0x1d, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
75};
76
77unsigned char fat[]={
780xeb,0x3c,0x90,0x6d,0x6b,0x64,0x6f,0x73,0x66,0x73,0x00,0x00,0x02,0x20,0x01,0x00,
790x02,0x00,0x02,0x00,0x00,0xf8,0xf0,0x00,0x20,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
800x00,0xfa,0x1d,0x00,0x00,0x00,0x29,0x3d,0xa7,0x07,0x48,0x20,0x20,0x20,0x20,0x20,
810x20,0x20,0x20,0x20,0x20,0x20,0x46,0x41,0x54,0x31,0x36,0x20,0x20,0x20,0x0e,0x1f,
820xbe,0x5b,0x7c,0xac,0x22,0xc0,0x74,0x0b,0x56,0xb4,0x0e,0xbb,0x07,0x00,0xcd,0x10,
830x5e,0xeb,0xf0,0x32,0xe4,0xcd,0x16,0xcd,0x19,0xeb,0xfe,0x54,0x68,0x69,0x73,0x20,
840x69,0x73,0x20,0x6e,0x6f,0x74,0x20,0x61,0x20,0x62,0x6f,0x6f,0x74,0x61,0x62,0x6c,
850x65,0x20,0x64,0x69,0x73,0x6b,0x2e,0x20,0x20,0x50,0x6c,0x65,0x61,0x73,0x65,0x20,
860x69,0x6e,0x73,0x65,0x72,0x74,0x20,0x61,0x20,0x62,0x6f,0x6f,0x74,0x61,0x62,0x6c,
870x65,0x20,0x66,0x6c,0x6f,0x70,0x70,0x79,0x20,0x61,0x6e,0x64,0x0d,0x0a,0x70,0x72,
880x65,0x73,0x73,0x20,0x61,0x6e,0x79,0x20,0x6b,0x65,0x79,0x20,0x74,0x6f,0x20,0x74,
890x72,0x79,0x20,0x61,0x67,0x61,0x69,0x6e,0x20,0x2e,0x2e,0x2e,0x20,0x0d,0x0a,0x00,
900x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
910x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
920x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
930x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
940x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
950x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
960x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
970x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
980x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
990x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1000x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1010x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1020x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1030x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1040x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1050x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1060x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1070x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1080x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1090x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0xaa,
110};
111
112
113unsigned char backupfat[] = {
114 0xf8, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
118 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
146};
147#define NUM_E200_CRCS ((int)((sizeof(e200_crcs) / sizeof(uint32_t))))
148
149#define REG_USBCMD (*(volatile unsigned int *)(USB_BASE+0x140))
150#define REG_USBSTS (*(volatile unsigned int *)(USB_BASE+0x144))
151#define REG_CONFIGFLAG (*(volatile unsigned int *)(USB_BASE+0x180))
152#define REG_PORTSC1 (*(volatile unsigned int *)(USB_BASE+0x184))
153#define REG_OTGSC (*(volatile unsigned int *)(USB_BASE+0x1a4))
154#define REG_USBMODE (*(volatile unsigned int *)(USB_BASE+0x1a8))
155
156unsigned char zero[1024*16];
157
158
159
160void* main(void)
161{
162 int i;
163 int btn;
164
165 chksum_crc32gentab ();
166
167 system_init();
168 kernel_init();
169 lcd_init();
170 font_init();
171 button_init();
172 i2c_init();
173 _backlight_on();
174
175 lcd_set_foreground(LCD_WHITE);
176 lcd_set_background(LCD_BLACK);
177 lcd_clear_display();
178
179 btn = button_read_device();
180 verbose = true;
181
182 lcd_setfont(FONT_SYSFIXED);
183
184 printf("Rockbox c240 initializer");
185 printf("");
186
187
188 i=storage_init();
189 disk_init(IF_MV(0));
190
191 memset(zero,0,16*1024);
192 printf("Zeroing flash");
193 for(i=0;i<250816;i++)
194 {
195 storage_write_sectors(i*32,32,zero);
196 if(i%64 == 0)
197 {
198 printf("%d kB left",(250816-i)/2);
199 }
200 }
201
202 printf("Writing MBR");
203 storage_write_sectors(0,1,mbr);
204 printf("Writing FAT bootsector");
205 storage_write_sectors(1023,1,fat);
206 printf("Writing more FAT");
207 storage_write_sectors(1024,1,backupfat);
208 printf("Writing more FAT");
209 storage_write_sectors(1264,1,backupfat);
210 if (button_hold())
211 printf("Release Hold and");
212
213 printf("Press any key to shutdown");
214
215 while(button_read_device() == BUTTON_NONE);
216
217 power_off();
218
219 return NULL;
220}
diff --git a/bootloader/main-c250wipe.c b/bootloader/main-c250wipe.c
deleted file mode 100644
index c64bbee92e..0000000000
--- a/bootloader/main-c250wipe.c
+++ /dev/null
@@ -1,287 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: main-e200r-installer.c 15599 2007-11-12 18:49:53Z amiconn $
9 *
10 * Copyright (C) 2006 by Barry Wardell
11 *
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
14 *
15 * All files in this archive are subject to the GNU General Public License.
16 * See the file COPYING in the source tree root for full license agreement.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include <stdio.h>
24#include <stdlib.h>
25#include "common.h"
26#include "cpu.h"
27#include "file.h"
28#include "system.h"
29#include "kernel.h"
30#include "lcd.h"
31#include "font.h"
32#include "storage.h"
33#include "button.h"
34#include "disk.h"
35#include "crc32-mi4.h"
36#include <string.h>
37#include "i2c.h"
38#include "backlight-target.h"
39#include "power.h"
40
41unsigned char mbr[] = {
42 0x33, 0xc0, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0xfb, 0x50, 0x07, 0x50, 0x1f, 0xfc, 0xbe, 0x1b, 0x7c,
43 0xbf, 0x1b, 0x06, 0x50, 0x57, 0xb9, 0xe5, 0x01, 0xf3, 0xa4, 0xcb, 0xbe, 0xbe, 0x07, 0xb1, 0x04,
44 0x38, 0x2c, 0x7c, 0x09, 0x75, 0x15, 0x83, 0xc6, 0x10, 0xe2, 0xf5, 0xcd, 0x18, 0x8b, 0x14, 0x8b,
45 0xee, 0x83, 0xc6, 0x10, 0x49, 0x74, 0x16, 0x38, 0x2c, 0x74, 0xf6, 0xbe, 0x10, 0x07, 0x4e, 0xac,
46 0x3c, 0x00, 0x74, 0xfa, 0xbb, 0x07, 0x00, 0xb4, 0x0e, 0xcd, 0x10, 0xeb, 0xf2, 0x89, 0x46, 0x25,
47 0x96, 0x8a, 0x46, 0x04, 0xb4, 0x06, 0x3c, 0x0e, 0x74, 0x11, 0xb4, 0x0b, 0x3c, 0x0c, 0x74, 0x05,
48 0x3a, 0xc4, 0x75, 0x2b, 0x40, 0xc6, 0x46, 0x25, 0x06, 0x75, 0x24, 0xbb, 0xaa, 0x55, 0x50, 0xb4,
49 0x41, 0xcd, 0x13, 0x58, 0x72, 0x16, 0x81, 0xfb, 0x55, 0xaa, 0x75, 0x10, 0xf6, 0xc1, 0x01, 0x74,
50 0x0b, 0x8a, 0xe0, 0x88, 0x56, 0x24, 0xc7, 0x06, 0xa1, 0x06, 0xeb, 0x1e, 0x88, 0x66, 0x04, 0xbf,
51 0x0a, 0x00, 0xb8, 0x01, 0x02, 0x8b, 0xdc, 0x33, 0xc9, 0x83, 0xff, 0x05, 0x7f, 0x03, 0x8b, 0x4e,
52 0x25, 0x03, 0x4e, 0x02, 0xcd, 0x13, 0x72, 0x29, 0xbe, 0x75, 0x07, 0x81, 0x3e, 0xfe, 0x7d, 0x55,
53 0xaa, 0x74, 0x5a, 0x83, 0xef, 0x05, 0x7f, 0xda, 0x85, 0xf6, 0x75, 0x83, 0xbe, 0x3f, 0x07, 0xeb,
54 0x8a, 0x98, 0x91, 0x52, 0x99, 0x03, 0x46, 0x08, 0x13, 0x56, 0x0a, 0xe8, 0x12, 0x00, 0x5a, 0xeb,
55 0xd5, 0x4f, 0x74, 0xe4, 0x33, 0xc0, 0xcd, 0x13, 0xeb, 0xb8, 0x00, 0x00, 0x80, 0x32, 0x22, 0x16,
56 0x56, 0x33, 0xf6, 0x56, 0x56, 0x52, 0x50, 0x06, 0x53, 0x51, 0xbe, 0x10, 0x00, 0x56, 0x8b, 0xf4,
57 0x50, 0x52, 0xb8, 0x00, 0x42, 0x8a, 0x56, 0x24, 0xcd, 0x13, 0x5a, 0x58, 0x8d, 0x64, 0x10, 0x72,
58 0x0a, 0x40, 0x75, 0x01, 0x42, 0x80, 0xc7, 0x02, 0xe2, 0xf7, 0xf8, 0x5e, 0xc3, 0xeb, 0x74, 0x49,
59 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e,
60 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x20, 0x53, 0x65, 0x74, 0x75, 0x70, 0x20, 0x63, 0x61,
61 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x69, 0x6e, 0x75, 0x65, 0x2e, 0x00, 0x45,
62 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65,
63 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x20, 0x53,
64 0x65, 0x74, 0x75, 0x70, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74,
65 0x69, 0x6e, 0x75, 0x65, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0x00, 0x8b, 0xfc, 0x1e, 0x57, 0x8b, 0xf5, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x10,
70 0x0a, 0x00, 0x06, 0x40, 0x09, 0xf7, 0xf9, 0x03, 0x00, 0x00, 0x07, 0x98, 0x3c, 0x00, 0x00, 0x40,
71 0x0a, 0xf7, 0x84, 0xcc, 0x13, 0xf9, 0x00, 0x9c, 0x3c, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00,
72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
74};
75
76unsigned char bootsector[]={
770xeb,0x58,0x90,0x6d,0x6b,0x64,0x6f,0x73,0x66,0x73,0x00,0x00,0x02,0x08,0x20,0x00,
780x02,0x00,0x00,0x00,0x00,0xf8,0x00,0x00,0x20,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
790x06,0x98,0x3c,0x00,0x1f,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
800x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
810x00,0x00,0x29,0xe5,0xbf,0xac,0x47,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
820x20,0x20,0x46,0x41,0x54,0x33,0x32,0x20,0x20,0x20,0x0e,0x1f,0xbe,0x77,0x7c,0xac,
830x22,0xc0,0x74,0x0b,0x56,0xb4,0x0e,0xbb,0x07,0x00,0xcd,0x10,0x5e,0xeb,0xf0,0x32,
840xe4,0xcd,0x16,0xcd,0x19,0xeb,0xfe,0x54,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x6e,
850x6f,0x74,0x20,0x61,0x20,0x62,0x6f,0x6f,0x74,0x61,0x62,0x6c,0x65,0x20,0x64,0x69,
860x73,0x6b,0x2e,0x20,0x20,0x50,0x6c,0x65,0x61,0x73,0x65,0x20,0x69,0x6e,0x73,0x65,
870x72,0x74,0x20,0x61,0x20,0x62,0x6f,0x6f,0x74,0x61,0x62,0x6c,0x65,0x20,0x66,0x6c,
880x6f,0x70,0x70,0x79,0x20,0x61,0x6e,0x64,0x0d,0x0a,0x70,0x72,0x65,0x73,0x73,0x20,
890x61,0x6e,0x79,0x20,0x6b,0x65,0x79,0x20,0x74,0x6f,0x20,0x74,0x72,0x79,0x20,0x61,
900x67,0x61,0x69,0x6e,0x20,0x2e,0x2e,0x2e,0x20,0x0d,0x0a,0x00,0x00,0x00,0x00,0x00,
910x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
920x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
930x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
940x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
950x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
960x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
970x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
980x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
990x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1000x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1010x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1020x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1030x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1040x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1050x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1060x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1070x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1080x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0xaa,
1090x52,0x52,0x61,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1100x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1110x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1120x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1130x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1140x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1150x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1160x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1170x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1180x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1190x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1200x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1210x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1220x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1230x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1240x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1250x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1260x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1270x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1280x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1290x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1300x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1310x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1320x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1330x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1340x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1350x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1360x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1370x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1380x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1390x00,0x00,0x00,0x00,0x72,0x72,0x41,0x61,0x34,0x8f,0x07,0x00,0x02,0x00,0x00,0x00,
1400x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0xaa,
141};
142
143unsigned char fat[]={
1440xeb,0x58,0x90,0x6d,0x6b,0x64,0x6f,0x73,0x66,0x73,0x00,0x00,0x02,0x08,0x20,0x00,
1450x02,0x00,0x00,0x00,0x00,0xf8,0x00,0x00,0x20,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
1460x06,0x98,0x3c,0x00,0x1f,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
1470x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1480x00,0x00,0x29,0xe5,0xbf,0xac,0x47,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
1490x20,0x20,0x46,0x41,0x54,0x33,0x32,0x20,0x20,0x20,0x0e,0x1f,0xbe,0x77,0x7c,0xac,
1500x22,0xc0,0x74,0x0b,0x56,0xb4,0x0e,0xbb,0x07,0x00,0xcd,0x10,0x5e,0xeb,0xf0,0x32,
1510xe4,0xcd,0x16,0xcd,0x19,0xeb,0xfe,0x54,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x6e,
1520x6f,0x74,0x20,0x61,0x20,0x62,0x6f,0x6f,0x74,0x61,0x62,0x6c,0x65,0x20,0x64,0x69,
1530x73,0x6b,0x2e,0x20,0x20,0x50,0x6c,0x65,0x61,0x73,0x65,0x20,0x69,0x6e,0x73,0x65,
1540x72,0x74,0x20,0x61,0x20,0x62,0x6f,0x6f,0x74,0x61,0x62,0x6c,0x65,0x20,0x66,0x6c,
1550x6f,0x70,0x70,0x79,0x20,0x61,0x6e,0x64,0x0d,0x0a,0x70,0x72,0x65,0x73,0x73,0x20,
1560x61,0x6e,0x79,0x20,0x6b,0x65,0x79,0x20,0x74,0x6f,0x20,0x74,0x72,0x79,0x20,0x61,
1570x67,0x61,0x69,0x6e,0x20,0x2e,0x2e,0x2e,0x20,0x0d,0x0a,0x00,0x00,0x00,0x00,0x00,
1580x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1590x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1600x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1610x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1620x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1630x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1640x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1650x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1660x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1670x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1680x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1690x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1700x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1710x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1720x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1730x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1740x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1750x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0xaa
176};
177
178unsigned char backupfat[]={
1790xf8,0xff,0xff,0x0f,0xff,0xff,0xff,0x0f,0xf8,0xff,0xff,0x0f,0x00,0x00,0x00,0x00,
1800x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1810x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1820x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1830x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1840x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1850x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1860x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1870x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1880x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1890x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1900x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1910x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1920x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1930x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1940x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1950x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1960x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1970x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1980x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1990x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2000x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2010x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2020x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2030x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2040x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2050x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2060x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2070x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2080x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2090x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2100x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
211};
212#define NUM_E200_CRCS ((int)((sizeof(e200_crcs) / sizeof(uint32_t))))
213
214#define REG_USBCMD (*(volatile unsigned int *)(USB_BASE+0x140))
215#define REG_USBSTS (*(volatile unsigned int *)(USB_BASE+0x144))
216#define REG_CONFIGFLAG (*(volatile unsigned int *)(USB_BASE+0x180))
217#define REG_PORTSC1 (*(volatile unsigned int *)(USB_BASE+0x184))
218#define REG_OTGSC (*(volatile unsigned int *)(USB_BASE+0x1a4))
219#define REG_USBMODE (*(volatile unsigned int *)(USB_BASE+0x1a8))
220
221unsigned char zero[1024*16];
222
223
224
225void* main(void)
226{
227 int i;
228 int btn;
229
230 chksum_crc32gentab ();
231
232 system_init();
233 kernel_init();
234 lcd_init();
235 font_init();
236 button_init();
237 i2c_init();
238 _backlight_on();
239
240 lcd_set_foreground(LCD_WHITE);
241 lcd_set_background(LCD_BLACK);
242 lcd_clear_display();
243
244 btn = button_read_device();
245 verbose = true;
246
247 lcd_setfont(FONT_SYSFIXED);
248
249 printf("Rockbox c250 initializer");
250 printf("");
251
252
253 i=storage_init();
254 disk_init(IF_MV(0));
255
256 memset(zero,0,16*1024);
257 printf("Zeroing flash");
258 for(i=0;i<250816;i++)
259 {
260 storage_write_sectors(i*32,32,zero);
261 if(i%64 == 0)
262 {
263 printf("%d kB left",(250816-i)/2);
264 }
265 }
266
267 printf("Writing MBR");
268 storage_write_sectors(0,1,mbr);
269 printf("Writing FAT bootsector");
270 storage_write_sectors(1017,2,bootsector);
271 printf("Writing more FAT");
272 storage_write_sectors(1023,1,fat);
273 printf("Writing more FAT");
274 storage_write_sectors(1049,1,backupfat);
275 printf("Writing more FAT");
276 storage_write_sectors(4920,1,backupfat);
277 if (button_hold())
278 printf("Release Hold and");
279
280 printf("Press any key to shutdown");
281
282 while(button_read_device() == BUTTON_NONE);
283
284 power_off();
285
286 return NULL;
287}
diff --git a/bootloader/main-ppsansawipe.c b/bootloader/main-ppsansawipe.c
new file mode 100644
index 0000000000..3221a09682
--- /dev/null
+++ b/bootloader/main-ppsansawipe.c
@@ -0,0 +1,250 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: main-e200r-installer.c 15599 2007-11-12 18:49:53Z amiconn $
9 *
10 * Copyright (C) 2011 by Frank Gevaerts
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#include <stdio.h>
21#include <stdlib.h>
22#include "common.h"
23#include "cpu.h"
24#include "file.h"
25#include "system.h"
26#include "kernel.h"
27#include "lcd.h"
28#include "font.h"
29#include "storage.h"
30#include "button.h"
31#include "disk.h"
32#include "crc32-mi4.h"
33#include <string.h>
34#include "i2c.h"
35#include "backlight-target.h"
36#include "power.h"
37
38unsigned char zero[1024*64];
39unsigned char nonzero[1024*64];
40unsigned char scratch[1024*64];
41struct storage_info info;
42
43int format_partition(int start, int size);
44
45#define SPT 63
46#define HPC 255
47
48int c(int lba)
49{
50 return lba/(SPT * HPC);
51}
52int h(int lba)
53{
54 return (lba/SPT)%HPC;
55}
56int s(int lba)
57{
58 return (lba%SPT) + 1;
59}
60
61int write_mbr(int datastart,int datasize, int firmwarestart, int firmwaresize)
62{
63 unsigned char mbr[512];
64 memset(mbr,0,512);
65 mbr[446]=0x80; /* flags */
66 mbr[447]=h(datastart); /* chs1[0] (h) */
67 mbr[448]=s(datastart); /* chs1[1] (s) */
68 mbr[449]=c(datastart); /* chs1[2] (c) */
69 mbr[450]=0x0b; /* type */
70 mbr[451]=h(datastart+datasize-1); /* chs2[0] (h) */
71 mbr[452]=s(datastart+datasize-1); /* chs2[1] (s) */
72 mbr[453]=c(datastart+datasize-1); /* chs2[2] (c) */
73 mbr[454]=(datastart&0x000000ff); /* lba[0] */
74 mbr[455]=(datastart&0x0000ff00) >>8; /* lba[1] */
75 mbr[456]=(datastart&0x00ff0000) >>16; /* lba[2] */
76 mbr[457]=(datastart&0xff000000) >>24; /* lba[3] */
77 mbr[458]=(datasize&0x000000ff); /* size[0] */
78 mbr[459]=(datasize&0x0000ff00) >>8; /* size[1] */
79 mbr[460]=(datasize&0x00ff0000) >>16; /* size[2] */
80 mbr[461]=(datasize&0xff000000) >>24; /* size[3] */
81
82 mbr[462]=0; /* flags */
83 mbr[463]=h(firmwarestart); /* chs1[0] (h) */
84 mbr[464]=s(firmwarestart); /* chs1[1] (s) */
85 mbr[465]=c(firmwarestart); /* chs1[2] (c) */
86 mbr[466]=0x84; /* type */
87 mbr[467]=h(firmwarestart+firmwaresize-1); /* chs2[0] (h) */
88 mbr[468]=s(firmwarestart+firmwaresize-1); /* chs2[1] (s) */
89 mbr[469]=c(firmwarestart+firmwaresize-1); /* chs2[2] (c) */
90 mbr[470]=(firmwarestart&0x000000ffu); /* lba[0] */
91 mbr[471]=(firmwarestart&0x0000ff00u) >>8; /* lba[1] */
92 mbr[472]=(firmwarestart&0x00ff0000u) >>16; /* lba[2] */
93 mbr[473]=(firmwarestart&0xff000000u) >>24; /* lba[3] */
94 mbr[474]=(firmwaresize&0x000000ffu); /* size[0] */
95 mbr[475]=(firmwaresize&0x0000ff00u) >>8; /* size[1] */
96 mbr[476]=(firmwaresize&0x00ff0000u) >>16; /* size[2] */
97 mbr[477]=(firmwaresize&0xff000000u) >>24; /* size[3] */
98
99 mbr[510]=0x55;
100 mbr[511]=0xaa;
101
102 int res = storage_write_sectors(0,1,mbr);
103 if(res != 0)
104 {
105 return -1;
106 }
107 return 0;
108}
109
110/* Hack. We "steal" line from common.c to reset the line number
111 * so we can overwrite the previous line for nicer progress info
112 */
113extern int line;
114int wipe(int size, int verify)
115{
116 int i;
117 int res;
118 int sectors = sizeof(nonzero)/512;
119 for(i=0;i<size;i+=sectors)
120 {
121 if(verify)
122 {
123 res = storage_write_sectors(i,sectors,nonzero);
124 if(res != 0)
125 {
126 printf("write error (1) on sector %d (of %d)!",i,size);
127 return -1;
128 }
129 res = storage_read_sectors(i,sectors,scratch);
130 if(res != 0)
131 {
132 printf("read error (1) on sector %d (of %d)!",i,size);
133 return -1;
134 }
135 res = memcmp(nonzero, scratch, sizeof(nonzero));
136 if(res != 0)
137 {
138 printf("compare error (1) on sector %d (of %d)!",i,size);
139 return -1;
140 }
141 }
142 res = storage_write_sectors(i,sectors,zero);
143 if(res != 0)
144 {
145 printf("write error (2) on sector %d (of %d)!",i,size);
146 return -1;
147 }
148 if(verify)
149 {
150 res = storage_read_sectors(i,sectors,scratch);
151 if(res != 0)
152 {
153 printf("read error (2) on sector %d (of %d)!",i,size);
154 return -1;
155 }
156 res = memcmp(zero, scratch, sizeof(nonzero));
157 if(res != 0)
158 {
159 printf("compare error (2) on sector %d (of %d)!",i,size);
160 return -1;
161 }
162 }
163
164 if(i%2048 == 0)
165 {
166 printf("%d of %d MB done",i/2048, size/2048);
167 /* Hack to overwrite the previous line */
168 line--;
169 }
170 }
171 return 0;
172}
173
174void* main(void)
175{
176 int i;
177 int btn;
178
179 chksum_crc32gentab ();
180
181 system_init();
182 kernel_init();
183 lcd_init();
184 font_init();
185 button_init();
186 i2c_init();
187 _backlight_on();
188
189 lcd_set_foreground(LCD_WHITE);
190 lcd_set_background(LCD_BLACK);
191 lcd_clear_display();
192
193 btn = button_read_device();
194 verbose = true;
195
196 lcd_setfont(FONT_SYSFIXED);
197
198 printf("Sansa initialiser");
199 printf("");
200
201
202 i=storage_init();
203 disk_init(IF_MD(0));
204
205 storage_get_info(0,&info);
206 int size = info.num_sectors;
207 memset(zero,0,sizeof(zero));
208 memset(nonzero,0xff,sizeof(nonzero));
209 printf("Zeroing flash");
210 int res;
211
212 res = wipe(size, 0);
213 if(res != 0)
214 {
215 printf("error wiping flash");
216 }
217
218 int firmwaresize = 0xa000;
219 int firmwarestart = size - firmwaresize;
220 int datastart = 600;
221 int datasize = firmwarestart - datastart;
222
223 res = write_mbr(datastart,datasize,firmwarestart,firmwaresize);
224 if(res != 0)
225 {
226 printf("error writing mbr");
227 }
228 res = format_partition(datastart, datasize);
229 if(res != 0)
230 {
231 printf("error formatting");
232 }
233
234 printf("Wipe done.");
235 if (button_hold())
236 printf("Release Hold and");
237 printf("press any key to");
238 printf("shutdown.");
239
240 printf("Remember to use");
241 printf("manufacturing");
242 printf("mode to recover");
243 printf("further");
244
245 while(button_read_device() == BUTTON_NONE);
246
247 power_off();
248
249 return NULL;
250}
diff --git a/firmware/target/arm/sandisk/boot.lds b/firmware/target/arm/sandisk/boot.lds
index 4b8adc8991..e3f952660c 100644
--- a/firmware/target/arm/sandisk/boot.lds
+++ b/firmware/target/arm/sandisk/boot.lds
@@ -33,7 +33,7 @@ MEMORY
33 33
34SECTIONS 34SECTIONS
35{ 35{
36#ifdef C200_ERASE 36#ifdef SANSA_PP_ERASE
37 . = IRAMORIG+0x4000; 37 . = IRAMORIG+0x4000;
38#else 38#else
39 . = IRAMORIG; 39 . = IRAMORIG;
diff --git a/tools/configure b/tools/configure
index 57d747bed8..d9324fdb82 100755
--- a/tools/configure
+++ b/tools/configure
@@ -3232,6 +3232,9 @@ case $modelname in
3232 sansac200) 3232 sansac200)
3233 gdbstub=", (E)raser" 3233 gdbstub=", (E)raser"
3234 ;; 3234 ;;
3235 sansae200)
3236 gdbstub=", (E)raser"
3237 ;;
3235 *) 3238 *)
3236 ;; 3239 ;;
3237esac 3240esac
@@ -3253,20 +3256,9 @@ fi
3253 [Ee]) 3256 [Ee])
3254 appsdir='$(ROOTDIR)/bootloader' 3257 appsdir='$(ROOTDIR)/bootloader'
3255 apps="bootloader" 3258 apps="bootloader"
3256 echo "C2(4)0 or C2(5)0" 3259 extradefines="$extradefines -DBOOTLOADER -DSANSA_PP_ERASE -ffunction-sections -fdata-sections"
3257 variant=`input`
3258 case $variant in
3259 4)
3260 extradefines="$extradefines -DBOOTLOADER -DC200_ERASE -DC240_ERASE -ffunction-sections -fdata-sections"
3261 echo "c240 eraser build selected"
3262 ;;
3263 5)
3264 extradefines="$extradefines -DBOOTLOADER -DC200_ERASE -DC250_ERASE -ffunction-sections -fdata-sections"
3265 echo "c240 eraser build selected"
3266 ;;
3267 esac
3268 bootloader="1" 3260 bootloader="1"
3269 echo "c200 eraser build selected" 3261 echo "sansa eraser build selected"
3270 ;; 3262 ;;
3271 [Bb]) 3263 [Bb])
3272 if test $t_manufacturer = "archos"; then 3264 if test $t_manufacturer = "archos"; then