/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * 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); /* 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... */ imagelength = 15 + 12 + 4 + 12 + 8 + 12 + 4 + 12 + size + 12; fwrite("B000FF\n", 7, 1, out); fwrite(0x88200000, 4, 1, out); fwrite(imagelength, 4, 1, out); /*First record*/ fwrite(0x88200000, 4, 1, out); fwrite(4, 4, 1, out); fwrite(0x1eb, 4, 1, out); fwrite(0xEA0003FE, 4, 1, out); /*Second record*/ fwrite(0x88200040, 4, 1, out); fwrite(8, 4, 1, out); fwrite(0x3e9, 4, 1, out); fwrite(0x43454345, 4, 1, out); fwrite(0x88EBF274, 4, 1, out); /*Third record*/ fwrite(0x88200048, 4, 1, out); fwrite(4, 4, 1, out); fwrite(0x231, 4, 1, out); fwrite(0x00CBF274, 4, 1, out); /*Signature bypass record*/ unsigned long magic = 0xE3A00001; fwrite(0x88065A10, 4, 1, out); fwrite(4, 4, 1, out); fwrite(calc_csum((unsigned char*)&magic,4), 4, 1, out); fwrite(magic, 4, 1, out); /*The actual code*/ fwrite(0x88201000, 4, 1, out); /*TODO*/ /*The footer*/ fwrite(0, 4, 1, out); fwrite(0x88201000, 4, 1, out); fwrite(0, 4, 1, out); fprintf(stderr, "File processed successfully\n" ); fclose(in); fclose(out); return(0); }