Add to 11U68 11E68

Dependencies:   DirectoryList MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Fri Sep 13 03:49:11 2013 +0000
Parent:
23:017f306cf3ca
Child:
25:33cb5ad8ae24
Commit message:
deviding code into modules

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
verification.cpp Show annotated file Show diff for this revision Revisions of this file
verification.h Show annotated file Show diff for this revision Revisions of this file
writing.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Sep 13 03:41:11 2013 +0000
+++ b/main.cpp	Fri Sep 13 03:49:11 2013 +0000
@@ -28,6 +28,7 @@
 #include    "writing.h"
 #include    "uu_coding.h"
 #include    "target_handling.h"
+#include    "verification.h"
 #include    "ika.h"
 
 
@@ -56,15 +57,11 @@
 
 int     error_state         = 0;
 
-int     verify_flash( FILE *fp, target_param *tpp );
 int     post_writing_process( target_param *tpp );
 
 int     file_size( FILE *fp );
 char    read_byte( void );
 void    erase_sectors( int last_sector );
-int     verify_binary_data( FILE *fp );
-int     verify_uucoded_data( FILE *fp );
-void    get_binary_from_uucode_str( char *b, int size );
 
 void    success_indicator();
 
@@ -139,15 +136,6 @@
 }
 
 
-int verify_flash( FILE *fp, target_param *tpp )
-{
-    if ( tpp->write_type == BINARY )
-        verify_binary_data( fp );
-    else
-        verify_uucoded_data( fp );
-}
-
-
 int post_writing_process( target_param *tpp )
 {
     if ( tpp->write_type == UUENCODE )
@@ -182,189 +170,6 @@
 }
 
 
-int verify_binary_data( FILE *fp )
-{
-    char    command_str[ STR_BUFF_SIZE ];
-    int     read_size   = 0;
-    int     size;
-    int     flash_reading_size;
-    char    *bf;
-    char    *br;
-    int     error_flag  = 0;
-    unsigned long   checksum        = 0;
-    unsigned long   checksum_count  = 0;
-
-    fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
-
-    flash_reading_size  = 128;
-
-    if ( NULL == (bf    = (char *)malloc( flash_reading_size * sizeof( char ) )) )
-        error( "malloc error happened (in verify process, file data buffer)\r\n" );
-
-    if ( NULL == (br    = (char *)malloc( flash_reading_size * sizeof( char ) )) )
-        error( "malloc error happened (in verify process, read data buffer)\r\n" );
-
-
-    printf( "\r\n  ==== flash reading and verifying ====\r\n" );
-
-    while ( size    = fread( bf, sizeof( char ), flash_reading_size, fp ) ) {
-
-        if ( read_size < 0x20 ) {
-            for ( int i = 0; i < flash_reading_size; i += 4 ) {
-
-                if ( checksum_count == 7 ) {
-                    checksum    = 0xFFFFFFFF - checksum + 1;
-                    *((unsigned int *)(bf + i)) = checksum;
-                  //printf( "\r\n\r\n  -- calculated checksum    : 0x%08X\r\n", checksum );
-                } else {
-                    checksum    += *((unsigned int *)(bf + i));
-                }
-                
-                checksum_count++;
-            }
-        }
-
-
-        sprintf( command_str, "R %ld %ld\r\n", read_size, size );
-//        try_and_check( command_str, "0", MODE_SILENT );
-        try_and_check( command_str, "0", 0 );
-
-        get_binary( br, 1 );
-        get_binary( br, size );
-
-        for ( int i = 0; i < size; i++ ) {
-//            printf( "   %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : "   ", *(bf + i), *(br + i) );
-            if ( (*(bf + i) != *(br + i)) ) {
-//                printf( "   %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : "   ", *(bf + i), *(br + i) );
-                error_flag++;
-            }
-        }
-
-        if ( error_flag )
-            break;
-            
-        read_size   += size;
-
-//        printf( "  total %d bytes read\r\n", read_size );
-    }
-    
-    error_state |= error_flag;
-
-    printf( "  total %d bytes read\r", read_size );
-    printf( "  verification result : \"%s\"\r\n", error_flag ? "Fail" : "Pass" );
-
-    free( bf );
-    free( br );
-
-    return ( read_size );
-}
-
-
-int verify_uucoded_data( FILE *fp )
-{
-    char    command_str[ STR_BUFF_SIZE ];
-    int     read_size   = 0;
-    int     size;
-    int     flash_reading_size;
-    char    *bf;
-    char    *br;
-    int     error_flag  = 0;
-
-    flash_reading_size  = 176;
-
-    initialize_uud_table();
-
-    if ( NULL == (bf    = (char *)malloc( flash_reading_size * sizeof( char ) )) )
-        error( "malloc error happened (in verify process, file data buffer)\r\n" );
-
-    if ( NULL == (br    = (char *)malloc( flash_reading_size * sizeof( char ) )) )
-        error( "malloc error happened (in verify process, read data buffer)\r\n" );
-
-    fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
-
-    while ( size    = fread( bf, sizeof( char ), flash_reading_size, fp ) ) {
-
-        if ( !read_size ) {
-            //  overwriting 4 bytes data for address=0x1C
-            //  there is a slot for checksum that is checked in (target's) boot process
-            add_isp_checksum( bf );
-        }
-
-        sprintf( command_str, "R %ld %ld\r\n", read_size, size );
-        try_and_check( command_str, "0", 0 );
-
-        get_binary_from_uucode_str( br, size );
-
-        for ( int i = 0; i < size; i++ ) {
-//            printf( "   %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : "   ", *(bf + i), *(br + i) );
-            if ( (*(bf + i) != *(br + i)) ) {
-                printf( "   %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : "   ", *(bf + i), *(br + i) );
-                error_flag++;
-            }
-        }
-
-        if ( error_flag )
-            break;
-            
-        read_size   += size;
-//        printf( "  total %d bytes read\r", read_size );
-    }
-
-    error_state |= error_flag;
-
-    printf( "  total %d bytes read\r", read_size );
-    printf( "  verification result : \"%s\"\r\n", error_flag ? "Fail" : "Pass" );
-
-    free( bf );
-    free( br );
-
-    return ( read_size );
-}
-
-
-void get_binary_from_uucode_str( char *b, int size )
-{
-#define N   4
-
-    char    s[ N ][ STR_BUFF_SIZE ];
-    char    ss[ STR_BUFF_SIZE ];
-    long    checksum    = 0;
-    int     line_count  = 0;
-    int     read_size   = 0;
-    int     retry_count = 3;
-
-
-    while ( retry_count-- ) {
-
-        for ( int i = 0; i < N; i++ )
-            get_string( s[ i ] );
-
-        get_string( ss );
-
-
-        while ( size ) {
-            read_size   = uudecode_a_line( b, s[ line_count ] );
-
-            for ( int i = 0; i < read_size; i++ )
-                checksum    += *b++;
-
-            size    -= read_size;
-            line_count++;
-        }
-
-//        printf( "  checksum -- %s (internal = %ld)\r\n", ss, checksum );
-
-        if ( checksum == atol( ss ) ) {
-            put_string( "OK\r\n" );
-            return;
-//            printf( "  checksum OK\r\n" );
-        } else {
-            printf( "  checksum RESEND\r\n" );
-            put_string( "RESEND\r\n" );
-        }
-    }
-}
-
 
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/verification.cpp	Fri Sep 13 03:49:11 2013 +0000
@@ -0,0 +1,204 @@
+#include    "mbed.h"
+#include    "verification.h"
+#include    "command_interface.h"
+#include    "uu_coding.h"
+#include    "serial_utilities.h"
+#include    "writing.h"
+#include    "ika.h"
+
+int     verify_binary_data( FILE *fp );
+int     verify_uucoded_data( FILE *fp );
+void    get_binary_from_uucode_str( char *b, int size );
+
+
+int verify_flash( FILE *fp, target_param *tpp )
+{
+    if ( tpp->write_type == BINARY )
+        verify_binary_data( fp );
+    else
+        verify_uucoded_data( fp );
+}
+
+
+int verify_binary_data( FILE *fp )
+{
+    char    command_str[ STR_BUFF_SIZE ];
+    int     read_size   = 0;
+    int     size;
+    int     flash_reading_size;
+    char    *bf;
+    char    *br;
+    int     error_flag  = 0;
+    unsigned long   checksum        = 0;
+    unsigned long   checksum_count  = 0;
+
+    fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
+
+    flash_reading_size  = 128;
+
+    if ( NULL == (bf    = (char *)malloc( flash_reading_size * sizeof( char ) )) )
+        error( "malloc error happened (in verify process, file data buffer)\r\n" );
+
+    if ( NULL == (br    = (char *)malloc( flash_reading_size * sizeof( char ) )) )
+        error( "malloc error happened (in verify process, read data buffer)\r\n" );
+
+
+    printf( "\r\n  ==== flash reading and verifying ====\r\n" );
+
+    while ( size    = fread( bf, sizeof( char ), flash_reading_size, fp ) ) {
+
+        if ( read_size < 0x20 ) {
+            for ( int i = 0; i < flash_reading_size; i += 4 ) {
+
+                if ( checksum_count == 7 ) {
+                    checksum    = 0xFFFFFFFF - checksum + 1;
+                    *((unsigned int *)(bf + i)) = checksum;
+                  //printf( "\r\n\r\n  -- calculated checksum    : 0x%08X\r\n", checksum );
+                } else {
+                    checksum    += *((unsigned int *)(bf + i));
+                }
+                
+                checksum_count++;
+            }
+        }
+
+
+        sprintf( command_str, "R %ld %ld\r\n", read_size, size );
+//        try_and_check( command_str, "0", MODE_SILENT );
+        try_and_check( command_str, "0", 0 );
+
+        get_binary( br, 1 );
+        get_binary( br, size );
+
+        for ( int i = 0; i < size; i++ ) {
+//            printf( "   %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : "   ", *(bf + i), *(br + i) );
+            if ( (*(bf + i) != *(br + i)) ) {
+//                printf( "   %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : "   ", *(bf + i), *(br + i) );
+                error_flag++;
+            }
+        }
+
+        if ( error_flag )
+            break;
+            
+        read_size   += size;
+
+//        printf( "  total %d bytes read\r\n", read_size );
+    }
+    
+    error_state |= error_flag;
+
+    printf( "  total %d bytes read\r", read_size );
+    printf( "  verification result : \"%s\"\r\n", error_flag ? "Fail" : "Pass" );
+
+    free( bf );
+    free( br );
+
+    return ( read_size );
+}
+
+
+int verify_uucoded_data( FILE *fp )
+{
+    char    command_str[ STR_BUFF_SIZE ];
+    int     read_size   = 0;
+    int     size;
+    int     flash_reading_size;
+    char    *bf;
+    char    *br;
+    int     error_flag  = 0;
+
+    flash_reading_size  = 176;
+
+    initialize_uud_table();
+
+    if ( NULL == (bf    = (char *)malloc( flash_reading_size * sizeof( char ) )) )
+        error( "malloc error happened (in verify process, file data buffer)\r\n" );
+
+    if ( NULL == (br    = (char *)malloc( flash_reading_size * sizeof( char ) )) )
+        error( "malloc error happened (in verify process, read data buffer)\r\n" );
+
+    fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
+
+    while ( size    = fread( bf, sizeof( char ), flash_reading_size, fp ) ) {
+
+        if ( !read_size ) {
+            //  overwriting 4 bytes data for address=0x1C
+            //  there is a slot for checksum that is checked in (target's) boot process
+            add_isp_checksum( bf );
+        }
+
+        sprintf( command_str, "R %ld %ld\r\n", read_size, size );
+        try_and_check( command_str, "0", 0 );
+
+        get_binary_from_uucode_str( br, size );
+
+        for ( int i = 0; i < size; i++ ) {
+//            printf( "   %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : "   ", *(bf + i), *(br + i) );
+            if ( (*(bf + i) != *(br + i)) ) {
+                printf( "   %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : "   ", *(bf + i), *(br + i) );
+                error_flag++;
+            }
+        }
+
+        if ( error_flag )
+            break;
+            
+        read_size   += size;
+//        printf( "  total %d bytes read\r", read_size );
+    }
+
+    error_state |= error_flag;
+
+    printf( "  total %d bytes read\r", read_size );
+    printf( "  verification result : \"%s\"\r\n", error_flag ? "Fail" : "Pass" );
+
+    free( bf );
+    free( br );
+
+    return ( read_size );
+}
+
+
+void get_binary_from_uucode_str( char *b, int size )
+{
+#define N   4
+
+    char    s[ N ][ STR_BUFF_SIZE ];
+    char    ss[ STR_BUFF_SIZE ];
+    long    checksum    = 0;
+    int     line_count  = 0;
+    int     read_size   = 0;
+    int     retry_count = 3;
+
+
+    while ( retry_count-- ) {
+
+        for ( int i = 0; i < N; i++ )
+            get_string( s[ i ] );
+
+        get_string( ss );
+
+
+        while ( size ) {
+            read_size   = uudecode_a_line( b, s[ line_count ] );
+
+            for ( int i = 0; i < read_size; i++ )
+                checksum    += *b++;
+
+            size    -= read_size;
+            line_count++;
+        }
+
+//        printf( "  checksum -- %s (internal = %ld)\r\n", ss, checksum );
+
+        if ( checksum == atol( ss ) ) {
+            put_string( "OK\r\n" );
+            return;
+//            printf( "  checksum OK\r\n" );
+        } else {
+            printf( "  checksum RESEND\r\n" );
+            put_string( "RESEND\r\n" );
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/verification.h	Fri Sep 13 03:49:11 2013 +0000
@@ -0,0 +1,4 @@
+#include    "target_table.h"
+
+
+int     verify_flash( FILE *fp, target_param *tpp );
--- a/writing.cpp	Fri Sep 13 03:41:11 2013 +0000
+++ b/writing.cpp	Fri Sep 13 03:49:11 2013 +0000
@@ -4,6 +4,7 @@
 #include    "command_interface.h"
 #include    "uu_coding.h"
 #include    "serial_utilities.h"
+#include    "ika.h"
 
 
 int     write_uuencoded_data( FILE *fp, int ram_size, int sector_size, unsigned int  );