u8 bootTest( void ) { // This function pre-tests every row in firmware file for corruption before erase and program u32 i; u8 ucBuffer[ 64 ], *ucSubString; //if( !fileOpen( &pygmyFile, (u8*)BOOT_filename, READ ) ){ // return( FALSE ); //} for( ; !( pygmyFile.Properties.Attributes & EOF ); ){ // Get an IHEX packet for( i = 0; i < 64; i++ ){ ucBuffer[ i ] = fileGetChar( &pygmyFile ); if( ucBuffer[ i ] == '\r' ){ ucBuffer[ i ] = '\0'; break; } // if } // for ucSubString = getNextSubString( ucBuffer, WHITESPACE|NEWLINE ); if( *(ucSubString++) != ':' ){ return( 0 ); } // if // Following works because the output cannot be longer than the input being converted convertHexEncodedStringToBuffer( ucSubString, ucSubString ); if( ucSubString[ 3 ] == IHEX_EOF ){ break; // We have reached EOF without error } //for( i = 0, ucCalculatedSum = 0; i < ucSubString[ 0 ]+4; i++ ){ // ucCalculatedSum += ucSubString[ i ]; //} // for //ucCalculatedSum = 1 + ( 0xFF ^ (u8)ucCalculatedSum ); //if( (u8)ucCalculatedSum != ucSubString[ i ] ){ // Last short is checksum if( sysCRC8( ucSubString, ucSubString[ 0 ]+4 ) != ucSubString[ i ] ){ // Last short is checksum return( FALSE ); // Corrupt HEX Row } // if i = ( (u16)ucSubString[ 1 ] << 8 ) + ucSubString[ 2 ]; if( ucSubString[ 3 ] == IHEX_DATA && i < 0x2000 ){ return( 0 ); } // if } // for //putstr( (u8*)BOOT_OK ); print( STDIO, (u8*)BOOT_OK ); return( 1 ); }
u8 bootTest( PYGMYFILE *pygmyFile ) { // This function pre-tests every row in firmware file for corruption before erase and program u32 i; u8 ucBuffer[ 64 ], ucCalculatedSum, *ucSubString; for( ; !( fileIsEOF( pygmyFile ) ); ){ // Get an IHEX packet for( i = 0; i < 64; i++ ){ ucBuffer[ i ] = fileGetChar( pygmyFile ); if( ucBuffer[ i ] == '\r' ){ ucBuffer[ i ] = '\0'; break; } // if } // for ucSubString = getNextSubString( ucBuffer, WHITESPACE|NEWLINE ); if( *(ucSubString++) != ':' ){ return( 0 ); } // if // Following works because the output cannot be longer than the input being converted convertHexEncodedStringToBuffer( ucSubString, ucSubString ); if( ucSubString[ 3 ] == IHEX_EOF ){ break; // We have reached EOF without error } for( i = 0, ucCalculatedSum = 0; i < ucSubString[ 0 ]+4; i++ ){ ucCalculatedSum += ucSubString[ i ]; } // for ucCalculatedSum = 1 + ( 0xFF ^ (u8)ucCalculatedSum ); if( (u8)ucCalculatedSum != ucSubString[ i ] ){ // Last short is checksum return( 0 ); // Corrupt HEX Row } // if i = ( (u16)ucSubString[ 1 ] << 8 ) + ucSubString[ 2 ]; //if( ucSubString[ 3 ] == IHEX_DATA && i > 0x2000 ){ // return( 0 ); //} // if } // for return( 1 ); }
u8 pftp_handler( u8 *ucBuffer ) { u8 *ucParams[ 5 ], ucLen, *ucSubString, *ucPayload; u16 uiCRC, uiLen, uiChunk; u32 i, ulPDIA; ucLen = getAllSubStrings( ucBuffer, ucParams, 5, WHITESPACE|PUNCT|SEPARATORS ); if( isStringSame( ucParams[ 0 ], "PFTP" ) ){ if( isStringSame( ucParams[ 1 ], (u8*)AT_ERROR ) ){ // ERROR is returned when resource is unavailable, such as incorrect filename globalModemStatus &= ~(MODEM_PFTPINPROGRESS|MODEM_BUSY); modem_close( "now" ); // Clear command queue return( TRUE ); // was 0, must test, but 1 cancels }else if( !isStringSame( ucSubString, "EOF" ) ){ uiChunk = convertStringToInt( ucParams[ 1 ] ); print( MODEM_DEBUG, "\rChunkReq: %d", globalModemPFTP.CurrentChunk ); print( MODEM_DEBUG, "\rChunkRcv: %d", uiChunk ); uiLen = convertStringToInt( ucParams[ 2 ] ); ucPayload = ucParams[ 3 ]; //getNextSubString( "", PYGMY_STRING_WHITE|PYGMY_STRING_SEPARATORS ); print( MODEM_DEBUG, "\rPayLen: %d", ucParams[ 3 ] ); if( convertHexEncodedStringToBuffer( ucPayload, ucPayload ) != uiLen ){ print( MODEM_DEBUG, "\rLEN Fail!" ); return( FALSE ); } // if // Updated to 32bit PDIA, single frame in HEX n 03/17/2011 pdiaEncode( 0, PDIA_NEW, 0 ); for( i = 0, ulPDIA = 0, uiCRC = 0; i < uiLen; i++ ){ pdiaEncode( ucPayload[ i ], PDIA_ADD, (u32*)&ulPDIA ); } // for pdiaEncode( 0, PDIA_END, (u32*)&ulPDIA ); //Next append h to mark string as hexadecimal i = len( ucParams[ 4 ] ); ucParams[ 4 ][ i++ ] = 'h'; ucParams[ 4 ][ i ] = '\0'; // Then convert hexadecimal string to integer // Now compare integer against that produced by PDIA encoder if( ulPDIA != convertStringToInt( ucParams[ 4 ] ) ){ // Contains CRC print( MODEM_DEBUG, "\rData Corrupt!" ); return( FALSE ); } // if if( uiChunk == globalModemPFTP.CurrentChunk ){ if( globalModemPFTP.CurrentChunk == 1 ){ //if( !Pygmy_PCMP_DecompressStreamToFile( ucPayload, uiLen, PYGMY_PCMP_START, // backlinkData.PFTP_Compressed, backlinkData.PFTP_File.Name ) ){ // return( 0 ); //} ++globalModemPFTP.CurrentChunk; pftp_get( "" ); return( TRUE ); } else{ //if( !Pygmy_PCMP_DecompressStreamToFile( ucPayload, uiLen, PYGMY_PCMP_DATA, // backlinkData.PFTP_Compressed, "" ) ){ // return( FALSE ); //} ++globalModemPFTP.CurrentChunk; pftp_get( "" ); return( TRUE ); } // else print( MODEM_DEBUG, "." ); } return( FALSE ); } else{ //Pygmy_PCMP_DecompressStreamToFile( "", uiLen, PYGMY_PCMP_STOP, backlinkData.PFTP_Compressed, "" ); globalModemStatus &= ~(MODEM_PFTPINPROGRESS|MODEM_BUSY); modem_close( "now" ); // Clear command queue } // else return( TRUE ); } // if return( FALSE ); }