From 590501cfe404b5463adecc70628e5bc7c8f142a2 Mon Sep 17 00:00:00 2001 From: Will Robertson Date: Fri, 21 Sep 2007 15:51:53 +0000 Subject: Merge the Gigabeat S branch back into trunk. Fingers crossed nothing breaks. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14805 a1c6a512-1295-4272-9138-f99709370657 --- tools/Makefile | 3 +- tools/configure | 30 +++++++++- tools/gigabeats.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/gigabeats.h | 20 +++++++ tools/scramble.c | 12 +++- 5 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 tools/gigabeats.c create mode 100644 tools/gigabeats.h (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index b7f445e..74d82af 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -16,13 +16,14 @@ CLEANALL := scramble descramble iriver sh2d bmp2rb rdf2binary convbdf \ all: @echo "Run make in your build directory!" -scramble: scramble.o iriver.o mi4.o gigabeat.o +scramble: scramble.o iriver.o mi4.o gigabeat.o gigabeats.o descramble: descramble.o iriver.o gigabeat.o scramble.o: scramble.c iriver.h mi4.h gigabeat.h descramble.o: descramble.c iriver.h gigabeat.h iriver.o: iriver.c iriver.h gigabeat.o: gigabeat.c gigabeat.h +gigabeats.o: gigabeats.c gigabeats.h mi4.o: mi4.c mi4.h sh2d: sh2d.c diff --git a/tools/configure b/tools/configure index 63e5512..73e6a50 100755 --- a/tools/configure +++ b/tools/configure @@ -615,7 +615,7 @@ cat < ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Will Robertson + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include + +static FILE * openinfile( const char * filename ) +{ + FILE * F = fopen( filename, "rb" ); + if( F == NULL ) + { + fprintf( stderr, "Couldn't open input file %s\n", filename ); + perror( "Error was " ); + exit( -1 ); + }; + return F; +}; + +static FILE * openoutfile( const char * filename ) +{ + FILE * F = fopen( filename, "wb" ); + if( F == NULL ) + { + fprintf( stderr, "Couldn't open output file %s\n", filename ); + perror( "Error was " ); + exit( -1 ); + }; + return F; +}; + +unsigned long calc_csum(const unsigned char* pb, int cb) +{ + unsigned long l = 0; + while (cb--) + l += *pb++; + return l; +} + +int gigabeat_s_code(char *infile, char *outfile) +{ + FILE *in, *out; + unsigned long size = 0; + unsigned long data; + int imagelength; + + in = openinfile(infile); + out = openoutfile(outfile); + + fseek(in, 0, SEEK_END); + size = ftell(in); + fseek(in, 0, SEEK_SET); + unsigned long *binptr = malloc(size); + if(binptr == NULL) { + fprintf(stderr, "Not enough memory to perform the requested operation. Aborting.\n" ); + return 0; + } + fread(binptr, size/4, 4, in); + /* 15 bytes for header, three 12 byte headers, the data for the first three + * records, 12 byte header for code, code and the 12 byte footer + * However, the original nk.bin's length doesn't correspond with + * the length of the file, so I don't know what's up... + */ + + unsigned long header[2]; + header[0] = 0x88200000; + /* header[1] = 15 + 12 + 4 + 12 + 8 + 12 + 4 + 12 + size + 12; */ + header[1] = 0xCC0CD8; /* The bootloader checks this value and compares */ + fwrite("B000FF\n", 7, 1, out); + fwrite(header, sizeof(header), 1, out); + + unsigned long record[4]; + unsigned long extra; + + /*First record*/ + record[0] = 0x88200000; + record[1] = 4; + record[2] = 0x1eb; + record[3] = 0xEA0003FE; + fwrite(record, sizeof(record), 1, out); + + /*Second record*/ + record[0] = 0x88200040; + record[1] = 8; + record[2] = 0x3e9; + record[3] = 0x43454345; + extra = 0x88EBF274; + fwrite(record, sizeof(record), 1, out); + fwrite(&extra, sizeof(extra), 1, out); + + /*Third record*/ + record[0] = 0x88200048; + record[1] = 4; + record[2] = 0x231; + record[3] = 0x00CBF274; + fwrite(record, sizeof(record), 1, out); + + /*Signature bypass record*/ + unsigned long magic = 0xE3A00001; + record[0] = 0x88065A10; + record[1] = 4; + record[2] = calc_csum((unsigned char*)&magic,4); + record[3] = magic; + fwrite(record, sizeof(record), 1, out); + + /*The actual code*/ + header[0] = 0x88201000; + header[1] = size; + extra = calc_csum((unsigned char*)binptr, size); + fwrite(header, sizeof(header), 1, out); + fwrite(&extra, sizeof(extra), 1, out); + fwrite(binptr, size, 1, out); + + /* Table of contents. It's a start, but it still won't boot. + * Looks like it needs the file/module info as well... */ + binptr[0] = 0x02000000; + binptr[1] = 0x02000000; + binptr[2] = 0x88040000; + binptr[3] = 0x88076338; + binptr[4] = 0x1; + binptr[5] = 0x88080000; + binptr[6] = 0x8809C000; + binptr[7] = 0x88100000; + binptr[8] = 0x0; + binptr[9] = 0x0; + binptr[10] = 0x0; + binptr[11] = 0x0; + binptr[12] = 0x0; + binptr[13] = 0x0; + binptr[14] = 0x80808080; + binptr[15] = 0x0; + binptr[16] = 0x0; + binptr[17] = 0x201C2; + binptr[18] = 0x88050940; + binptr[19] = 0x0; + binptr[20] = 0x0; + header[0] = 0x88EBF274; + header[1] = 0x54; + extra = calc_csum((unsigned char*)binptr, 84); + fwrite(header, sizeof(header), 1, out); + fwrite(&extra, sizeof(extra), 1, out); + fwrite(binptr, 84, 1, out); + + /*The footer*/ + header[0] = 0; + header[1] = 0x88201000; + extra = 0; + fwrite(header, sizeof(header), 1, out); + fwrite(&extra, sizeof(extra), 1, out); + + fprintf(stderr, "File processed successfully\n" ); + + fclose(in); + fclose(out); + return(0); +} diff --git a/tools/gigabeats.h b/tools/gigabeats.h new file mode 100644 index 0000000..f682a9d --- /dev/null +++ b/tools/gigabeats.h @@ -0,0 +1,20 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Marcoen Hirschberg + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +int gigabeat_s_code(char *infile, char *outfile); diff --git a/tools/scramble.c b/tools/scramble.c index 9f18e96..8534d41 100644 --- a/tools/scramble.c +++ b/tools/scramble.c @@ -23,6 +23,7 @@ #include #include "iriver.h" #include "gigabeat.h" +#include "gigabeats.h" #include "mi4.h" int iaudio_encode(char *iname, char *oname, char *idstring); @@ -92,7 +93,8 @@ void usage(void) "\t-ipod3g ipod firmware partition format (3rd Gen)\n" "\t-ipod4g ipod firmware partition format (4th Gen, Mini, Nano, Photo/Color)\n" "\t-ipod5g ipod firmware partition format (5th Gen - aka Video)\n" - "\t-gigabeat Toshiba Gigabeat format\n" + "\t-gigabeat Toshiba Gigabeat F/X format\n" + "\t-gigabeats Toshiba Gigabeat S format\n" "\t-mi4v2 PortalPlayer .mi4 format (revision 010201)\n" "\t-mi4v3 PortalPlayer .mi4 format (revision 010301)\n" "\t-mi4r Sandisk Rhapsody .mi4 format\n" @@ -231,6 +233,8 @@ int main (int argc, char** argv) modelnum = 19; else if(!strcmp(&argv[1][5], "c200")) modelnum = 20; + else if(!strcmp(&argv[1][5], "gigs")) + modelnum = 21; else { fprintf(stderr, "unsupported model: %s\n", &argv[1][5]); return 2; @@ -254,6 +258,12 @@ int main (int argc, char** argv) gigabeat_code(iname, oname); return 0; } + else if(!strcmp(argv[1], "-gigabeats")) { + iname = argv[2]; + oname = argv[3]; + gigabeat_s_code(iname, oname); + return 0; + } else if(!strcmp(argv[1], "-iaudiox5")) { iname = argv[2]; oname = argv[3]; -- cgit v1.1