Index: tools/configure =================================================================== --- tools/configure (revision 12755) +++ tools/configure (working copy) @@ -1164,16 +1164,16 @@ target="-DIRIVER_H10" memory=32 # always arm7tdmicc - tool="$rootdir/tools/scramble -add=h10" + tool="$rootdir/tools/scramble -mi4v3 -model=h10 -type=RBOS" bmp2rb_mono="$rootdir/tools/bmp2rb -f 0" bmp2rb_native="$rootdir/tools/bmp2rb -f 4" - output="rockbox.h10" + output="rockbox.mi4" appextra="recorder:gui" archosrom="" flash="" plugins="yes" codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" - boottool="$rootdir/tools/scramble -mi4v3" + boottool="$rootdir/tools/scramble -mi4v3 -model=h10 -type=RBBL" bootoutput="H10_20GC.mi4" # toolset is the tools within the tools directory that we build for # this particular target. @@ -1184,22 +1184,48 @@ t_model="h10" ;; + 15|h10_5gb) + target_id=24 + archos="h10_5gb" + target="-DIRIVER_H10_5GB" + memory=32 # always + arm7tdmicc + tool="$rootdir/tools/scramble -mi4v2 -model=h105 -type=RBOS" + bmp2rb_mono="$rootdir/tools/bmp2rb -f 0" + bmp2rb_native="$rootdir/tools/bmp2rb -f 5" + output="rockbox.mi4" + appextra="recorder:gui" + archosrom="" + flash="" + plugins="yes" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + boottool="$rootdir/tools/scramble -mi4v2 -model=h105 -type=RBBL" + bootoutput="H10.mi4" + # toolset is the tools within the tools directory that we build for + # this particular target. + toolset="$genericbitmaptools scramble" + # architecture, manufacturer and model for the target-tree build + t_cpu="arm" + t_manufacturer="iriver" + t_model="h10" + ;; + 50|e200) target_id=23 archos="e200" target="-DSANSA_E200" memory=32 # supposedly arm7tdmicc - tool="$rootdir/tools/scramble -add=e200" + tool="$rootdir/tools/scramble -mi4v3 -model=e200 -type=RBOS" bmp2rb_mono="$rootdir/tools/bmp2rb -f 0" bmp2rb_native="$rootdir/tools/bmp2rb -f 4" - output="rockbox.e200" + output="rockbox.mi4" appextra="recorder:gui" archosrom="" flash="" plugins="yes" codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" - boottool="$rootdir/tools/scramble -mi4v3" + boottool="$rootdir/tools/scramble -mi4v3 -model=e200 -type=RBBL" bootoutput="PP5022.mi4" # toolset is the tools within the tools directory that we build for # this particular target. @@ -1219,16 +1245,16 @@ target="-DSANSA_E200" memory=32 # supposedly arm7tdmicc - tool="$rootdir/tools/scramble -add=e200" + tool="$rootdir/tools/scramble -mi4v3 -model=e20r -type=RBOS" bmp2rb_mono="$rootdir/tools/bmp2rb -f 0" bmp2rb_native="$rootdir/tools/bmp2rb -f 4" - output="rockbox.e200" + output="rockbox.mi4" appextra="recorder:gui" archosrom="" flash="" plugins="yes" codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" - boottool="$rootdir/tools/scramble -mi4r" + boottool="$rootdir/tools/scramble -mi4r -model=e20r -type=RBBL" bootoutput="pp5022.mi4" # toolset is the tools within the tools directory that we build for # this particular target. @@ -1239,32 +1265,6 @@ t_model="sansa-e200" ;; - 15|h10_5gb) - target_id=24 - archos="h10_5gb" - target="-DIRIVER_H10_5GB" - memory=32 # always - arm7tdmicc - tool="$rootdir/tools/scramble -add=h10_5gb" - bmp2rb_mono="$rootdir/tools/bmp2rb -f 0" - bmp2rb_native="$rootdir/tools/bmp2rb -f 5" - output="rockbox.h10" - appextra="recorder:gui" - archosrom="" - flash="" - plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" - boottool="$rootdir/tools/scramble -mi4v2" - bootoutput="H10.mi4" - # toolset is the tools within the tools directory that we build for - # this particular target. - toolset="$genericbitmaptools scramble" - # architecture, manufacturer and model for the target-tree build - t_cpu="arm" - t_manufacturer="iriver" - t_model="h10" - ;; - 60|tpj1022) target_id=25 archos="tpj1022" Index: tools/mi4.c =================================================================== --- tools/mi4.c (revision 12760) +++ tools/mi4.c (working copy) @@ -152,8 +152,8 @@ int2le(0xaa55aa55, &outbuf[0x200+length]); /* More Magic */ - strncpy((char *)outbuf+0x1f8, type, 4); /* type of binary - RBBL, RBOS, ... */ - strncpy((char *)outbuf+0x1fc, model, 4); /* type of binary - RBBL, RBOS, ... */ + strncpy((char *)outbuf+0x1f8, type, 4); /* type of binary (RBBL, RBOS) */ + strncpy((char *)outbuf+0x1fc, model, 4); /* 4 character model id */ /* Calculate CRC32 checksum */ chksum_crc32gentab (); Index: bootloader/main-pp.c =================================================================== --- bootloader/main-pp.c (revision 12755) +++ bootloader/main-pp.c (working copy) @@ -111,7 +111,7 @@ buffer called loadbuffer. The rest of the loading is done in crt0.S */ printf("Loading original firmware..."); - rc=load_raw_firmware(loadbuffer, "/System/OF.bin", MAX_LOADSIZE); + rc=load_firmware(loadbuffer, "/System/OF.mi4", MAX_LOADSIZE); if (rc < EOK) { printf("Can't load /System/OF.bin"); error(EBOOTFILE, rc); Index: bootloader/common.c =================================================================== --- bootloader/common.c (revision 12755) +++ bootloader/common.c (working copy) @@ -28,6 +28,79 @@ #include "power.h" #include "kernel.h" +/* + * CRC32 implementation taken from: + * + * efone - Distributed internet phone system. + * + * (c) 1999,2000 Krzysztof Dabrowski + * (c) 1999,2000 ElysiuM deeZine + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + */ + +/* based on implementation by Finn Yannick Jacobs */ + +#include +#include + +/* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab(). + * so make sure, you call it before using the other + * functions! + */ +static unsigned int crc_tab[256]; + +/* chksum_crc() -- to a given block, this one calculates the + * crc32-checksum until the length is + * reached. the crc32-checksum will be + * the result. + */ +static unsigned int chksum_crc32 (unsigned char *block, unsigned int length) +{ + register unsigned long crc; + unsigned long i; + + crc = 0; + for (i = 0; i < length; i++) + { + crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF]; + } + return (crc); +} + +/* chksum_crc32gentab() -- to a global crc_tab[256], this one will + * calculate the crcTable for crc32-checksums. + * it is generated to the polynom [..] + */ + +static void chksum_crc32gentab (void) +{ + unsigned long crc, poly; + int i, j; + + poly = 0xEDB88320L; + for (i = 0; i < 256; i++) + { + crc = i; + for (j = 8; j > 0; j--) + { + if (crc & 1) + { + crc = (crc >> 1) ^ poly; + } + else + { + crc >>= 1; + } + } + crc_tab[i] = crc; + } +} + /* TODO: Other bootloaders need to be adjusted to set this variable to true on a button press - currently only the ipod, H10 and Sansa versions do. */ #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined(IRIVER_H10_5GB) || \ @@ -131,9 +204,8 @@ int rc; int len; unsigned long chksum; - char model[5]; + char model[5], type[5]; unsigned long sum; - int i; char filename[MAX_PATH]; snprintf(filename,sizeof(filename),"/.rockbox/%s",firmware); @@ -146,13 +218,21 @@ return EFILE_NOT_FOUND; } + /* Determinte firmware size */ +#ifdef FIRMWARE_OFFSET_FILE_LENGTH + lseek(fd, FIRMWARE_OFFSET_FILE_LENGTH, SEEK_SET); + read(fd, &len, 4); +#else len = filesize(fd) - 8; +#endif printf("Length: %x", len); if (len > buffer_size) return EFILE_TOO_BIG; + + /* Read CRC */ lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); rc = read(fd, &chksum, 4); @@ -162,6 +242,9 @@ printf("Checksum: %x", chksum); +#ifdef FIRMWARE_OFFSET_FILE_MODEL + /* Read model id */ + lseek(fd, FIRMWARE_OFFSET_FILE_MODEL, SEEK_SET); rc = read(fd, model, 4); if(rc < 4) return EREAD_MODEL_FAILED; @@ -169,27 +252,55 @@ model[4] = 0; printf("Model name: %s", model); +#endif + +#ifdef FIRMWARE_OFFSET_FILE_TYPE + /* Read binary type (RBOS, RBBL) */ + lseek(fd, FIRMWARE_OFFSET_FILE_TYPE, SEEK_SET); + rc = read(fd, type, 4); + if(rc < 4) + return EREAD_MODEL_FAILED; + + type[4] = 0; + + printf("Binary type: %s", type); +#endif + + /* Load firmware */ printf("Loading %s", firmware); - lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); + lseek(fd, 28, SEEK_SET); - rc = read(fd, buf, len); + rc = read(fd, buf, filesize(fd)-28); if(rc < len) return EREAD_IMAGE_FAILED; - close(fd); - + /* Check CRC to see if we have a valid file */ +#if defined(IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(SANSA_E200) + /* Calculate CRC32 checksum */ + chksum_crc32gentab (); + sum = chksum_crc32 (buf,filesize(fd)-28); +#else sum = MODEL_NUMBER; for(i = 0;i < len;i++) { sum += buf[i]; } +#endif printf("Sum: %x", sum); if(sum != chksum) return EBAD_CHKSUM; + lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); + + rc = read(fd, buf, len); + if(rc < len) + return EREAD_IMAGE_FAILED; + + close(fd); + return EOK; } Index: firmware/export/config-h10.h =================================================================== --- firmware/export/config-h10.h (revision 12755) +++ firmware/export/config-h10.h (working copy) @@ -138,13 +138,19 @@ #define HAVE_ATA_POWER_OFF /* Offset ( in the firmware file's header ) to the file length */ -#define FIRMWARE_OFFSET_FILE_LENGTH 0 +#define FIRMWARE_OFFSET_FILE_LENGTH 0x8 /* Offset ( in the firmware file's header ) to the file CRC */ -#define FIRMWARE_OFFSET_FILE_CRC 0 +#define FIRMWARE_OFFSET_FILE_CRC 0x0c +/* Offset ( in the firmware file's header ) to the file type */ +#define FIRMWARE_OFFSET_FILE_TYPE 0x1f8 + +/* Offset ( in the firmware file's header ) to the file model id */ +#define FIRMWARE_OFFSET_FILE_MODEL 0x1fc + /* Offset ( in the firmware file's header ) to the real data */ -#define FIRMWARE_OFFSET_FILE_DATA 8 +#define FIRMWARE_OFFSET_FILE_DATA 0x200 /* #define USB_IPODSTYLE */ @@ -160,7 +166,7 @@ /* Define this if you have adjustable CPU frequency */ /*#define HAVE_ADJUSTABLE_CPU_FREQ*/ -#define BOOTFILE_EXT "h10" +#define BOOTFILE_EXT "mi4" #define BOOTFILE "rockbox." BOOTFILE_EXT #define ICODE_ATTR_TREMOR_NOT_MDCT Index: firmware/export/config-e200.h =================================================================== --- firmware/export/config-e200.h (revision 12755) +++ firmware/export/config-e200.h (working copy) @@ -108,13 +108,19 @@ #define CONFIG_LCD LCD_X5 /* Offset ( in the firmware file's header ) to the file length */ -#define FIRMWARE_OFFSET_FILE_LENGTH 0 +#define FIRMWARE_OFFSET_FILE_LENGTH 0x8 /* Offset ( in the firmware file's header ) to the file CRC */ -#define FIRMWARE_OFFSET_FILE_CRC 0 +#define FIRMWARE_OFFSET_FILE_CRC 0x0c +/* Offset ( in the firmware file's header ) to the file type */ +#define FIRMWARE_OFFSET_FILE_TYPE 0x1f8 + +/* Offset ( in the firmware file's header ) to the file model id */ +#define FIRMWARE_OFFSET_FILE_MODEL 0x1fc + /* Offset ( in the firmware file's header ) to the real data */ -#define FIRMWARE_OFFSET_FILE_DATA 8 +#define FIRMWARE_OFFSET_FILE_DATA 0x200 /* #define USB_IPODSTYLE */ @@ -130,7 +136,7 @@ /* Define this if you have adjustable CPU frequency */ /*#define HAVE_ADJUSTABLE_CPU_FREQ Let's say we don't for now*/ -#define BOOTFILE_EXT "e200" +#define BOOTFILE_EXT "mi4" #define BOOTFILE "rockbox." BOOTFILE_EXT #define ICODE_ATTR_TREMOR_NOT_MDCT Index: firmware/export/config-h10_5gb.h =================================================================== --- firmware/export/config-h10_5gb.h (revision 12755) +++ firmware/export/config-h10_5gb.h (working copy) @@ -118,13 +118,19 @@ #define HAVE_ATA_POWER_OFF /* Offset ( in the firmware file's header ) to the file length */ -#define FIRMWARE_OFFSET_FILE_LENGTH 0 +#define FIRMWARE_OFFSET_FILE_LENGTH 0x8 /* Offset ( in the firmware file's header ) to the file CRC */ -#define FIRMWARE_OFFSET_FILE_CRC 0 +#define FIRMWARE_OFFSET_FILE_CRC 0x0c +/* Offset ( in the firmware file's header ) to the file type */ +#define FIRMWARE_OFFSET_FILE_TYPE 0x1f8 + +/* Offset ( in the firmware file's header ) to the file model id */ +#define FIRMWARE_OFFSET_FILE_MODEL 0x1fc + /* Offset ( in the firmware file's header ) to the real data */ -#define FIRMWARE_OFFSET_FILE_DATA 8 +#define FIRMWARE_OFFSET_FILE_DATA 0x200 /* #define USB_IPODSTYLE */ @@ -140,7 +146,7 @@ /* Define this if you have adjustable CPU frequency */ /*#define HAVE_ADJUSTABLE_CPU_FREQ*/ -#define BOOTFILE_EXT "h10" +#define BOOTFILE_EXT "mi4" #define BOOTFILE "rockbox." BOOTFILE_EXT #define ICODE_ATTR_TREMOR_NOT_MDCT Index: firmware/target/arm/crt0-pp.S =================================================================== --- firmware/target/arm/crt0-pp.S (revision 12755) +++ firmware/target/arm/crt0-pp.S (working copy) @@ -54,7 +54,7 @@ b pad_skip -.space 50*4 /* (more than enough) space for exception vectors */ +.space 60*4 /* (more than enough) space for exception vectors */ pad_skip: #ifdef SANSA_E200