[Bugfix][T800][task-view-514] tar buffer syslog in zip and add flush
switch

    Only Configure: No
    Affected branch: unknown
    Affected module: log
    Is it affected on both ZXIC and MTK: only MTK
    Self-test: yes
    Doc Update: no

Change-Id: I07c9e9cfb2d9eca694e793d26ae96fd744912666
diff --git a/LYNQ_PUBLIC/IC_src/mtk/packages/apps/lynq-log-transfer/lynq_inner_log_transfer.sh b/LYNQ_PUBLIC/IC_src/mtk/packages/apps/lynq-log-transfer/lynq_inner_log_transfer.sh
index 08f8d34..d5226a3 100755
--- a/LYNQ_PUBLIC/IC_src/mtk/packages/apps/lynq-log-transfer/lynq_inner_log_transfer.sh
+++ b/LYNQ_PUBLIC/IC_src/mtk/packages/apps/lynq-log-transfer/lynq_inner_log_transfer.sh
@@ -5,19 +5,11 @@
 ERROR_PARAM=1
 ERROR_FTP_SERVER_PING_NOT_OK=2
 ERROR_FTP_TRANSFER_FAIL=3
-ERROR_INNER_ERROR=4
+ERROR_INNER_EXE_ERROR=4
+ERROR_INNER_PARAM_ERROR=5
 
 
-ERROR_IS_IN_TRANSFER_LOG=20
-
-ERROR_IS_IN_TRANSFER_SYS_LOG=$((ERROR_IS_IN_TRANSFER_LOG+0))
-ERROR_IS_IN_TRANSFER_REMAIN_SYS_LOG=$((ERROR_IS_IN_TRANSFER_LOG+1))
-ERROR_IS_IN_WAIT_TRRANSFER_REMAIN_SYS_LOG=$((ERROR_IS_IN_TRANSFER_LOG+2))
-
-ERROR_IS_IN_TRANSFER_MTK_LOG=$((ERROR_IS_IN_TRANSFER_LOG+5))
-ERROR_IS_IN_TRANSFER_REMAIN_MTK_LOG=$((ERROR_IS_IN_TRANSFER_LOG+6))
-ERROR_IS_IN_WAIT_TRRANSFER_REMAIN_MTK_LOG=$((ERROR_IS_IN_TRANSFER_LOG+7))
-
+ERROR_IS_IN_TRANSFER_LOG=30
 
 DEBUG_FILE_PATH=/var/log/
 DEBUG_FILE_NAME=syslog.log
@@ -27,6 +19,10 @@
     mkdir -p ${DEBUG_FILE_PATH}
 fi    
 
+
+DEBUG_INDEX=71
+FLUSH_LOG_INDEX=72
+
 SYS_LOG_PATH="/var/log/"
 MTK_LOG_PATH="/var/log/mtklog/"
 TMP_LOG_PATH="/tmp/log_transfer_tmp/"
@@ -35,14 +31,17 @@
 CONTROL_FILE_PATH="${TMP_LOG_PATH}control/"
 LOG_IS_IN_TRANSFER=(
      "${CONTROL_FILE_PATH}is_in_transfer_sys_log"
+     "${CONTROL_FILE_PATH}is_in_transfer_sys_tar_log"
      "${CONTROL_FILE_PATH}is_in_transfer_mtk_log"
     )
 WAIT_TRANSFER_REMAIN_LOG=(      
       "${CONTROL_FILE_PATH}is_in_transfer_remain_sys_log"
+      "${CONTROL_FILE_PATH}is_in_transfer_remain_sys_tar_log"
       "${CONTROL_FILE_PATH}is_in_transfer_remain_mtk_log"
     )
     
-TARGET_DIR=(      
+TARGET_DIR=(   
+      ""   
       "lynq/log/lynq_log_1"
       "lynq/log/lynq_log_2"
     )
@@ -52,10 +51,12 @@
 
 log_print=(
     "sys log"
+    "sys tar log"
     "mtk log"
 )
 
 loop_time=(
+    7
     5
     1
 )
@@ -63,50 +64,92 @@
 transfer_log_tag=(
     0
     0
+    0
+)
+
+need_check_ftp_sever=(
+    0
+    1
+    1
 )
 
 LOG_PREFIX=(
+    "sys_tar_log"
     "archive_log"
     "MDLog"
 )
 log_prefix=""
 
-#unit 0.1M
-SINGLE_FILE_SIZE=(
-    21
+#unit 0.1M, syslog's size range is [1 281],  281 corresponding lynq_uci.lynq_log.syslog_flie_size is 200*1024*1024
+SINGLE_FILE_SIZE_TEN_TIMES=(
+    14
+    14
     100
 )
-single_file_size=10
+single_file_size_ten_times=10
 
 #unit M
 INIT_LOG_MAX_SIZE=(
+    16
     1000
     2700
 )
 log_num_max=0
+log_index_max=0
 LOG_DEL=$(($log_num_max/2))
 
 
 Q_CUR_NUM_UCI=(
+    "lynq_uci.lynq_log.log_0_cur_trf_num"
     "lynq_uci.lynq_log.log_1_cur_trf_num"
     "lynq_uci.lynq_log.log_2_cur_trf_num"
 )
 q_cur_num_uci=""
 
 Q_MAX_SIZE_UCI=(
+    "lynq_uci.lynq_log.log_0_max_size"
     "lynq_uci.lynq_log.log_1_max_size"
     "lynq_uci.lynq_log.log_2_max_size"
 )
 q_max_size_uci=""
 
 
+#lynq_uci.lynq_log.syslog_flie_size should not greater than 200*1024*1024*
+Q_SINGLE_FILE_SIZE_UCI=(
+    "lynq_uci.lynq_log.syslog_flie_size"	
+    "lynq_uci.lynq_log.syslog_flie_size"
+    "mdlog.property.md_log_size"
+)
+
+# 1048576 is 1024*1024  
+# syslog's single file size: lynq_uci.lynq_log.syslog_flie_size should not greater than 200*1024*1024*
+# single_file_size_ten_times=Q_SINGLE_FILE_SIZE_UCI*10/CONVERT_TO_M*10/COMPRESS_RATIO_TEN_TIME
+# Q_SINGLE_FILE_SIZE_UCI=SINGLE_FILE_SIZE_TEN_TIMES*COMPRESS_RATIO_TEN_TIME/10*CONVERT_TO_M/10 
+# first set Q_SINGLE_FILE_SIZE_UCI=SINGLE_FILE_SIZE_TEN_TIMES*COMPRESS_RATIO_TEN_TIME/10*CONVERT_TO_M/10
+# then single_file_size_ten_times=Q_SINGLE_FILE_SIZE_UCI*10/CONVERT_TO_M*10/COMPRESS_RATIO_TEN_TIME
+CONVERT_TO_M=(
+    1048576
+    1048576
+    1
+)
+
+COMPRESS_RATIO_TEN_TIME=(
+    71
+    71
+    10
+)
+
+
 TAR_CMD="gzip"
 TAR_ARG=" -f"
 TAR_EXT="gz"
 
+SYS_LOG_TMP="syslog.log.0"
+
 UP_LOAD_POSTFIX=(
     $TAR_EXT
-    "muxz"
+    $TAR_EXT
+    "muxz"	
 )
 q_max_size_uci=""
 
@@ -201,7 +244,7 @@
         #no need rm GPS_LOG_PATH and GPS_COF_PATH, because the GPS process cannot dynamically stop/start log output
         #rm -rf ${GPS_LOG_PATH}     
         #gpslog transfer to soc end@cz.li,20240314                  
-    if [ $1 -eq 1 ]; then
+    if [ $1 -eq 2 ]; then
         stop_mtk_log_and_clear_dir
      #LYNQ_MTK_BUG483_Q.HUANG_20241226_DONT_DELETE_TRANSFER_FAIL_FILE_BEGIN
      #  if [ -d ${MTK_LOG_BUFF_PATH} ]; then                    
@@ -279,7 +322,7 @@
         echo_debug_info "$MTK_LOG_BUFF_PATH not exists"        
     fi   
 	
-    if [ $1 -ne 0 ]; then
+    if [ $1 -gt 1 ]; then
         show_detail_relative_tag
     fi
 }
@@ -313,11 +356,12 @@
 
 function print_usage()
 {   
-    echo "Usage : lynq-log-transfer 0 | 1 | 2 | 3 | 101 | 102 " >&2
+    echo "Usage : lynq-log-transfer 0 | 1 | 2 | 101 | 102 | $DEBUG_INDEX | $FLUSH_LOG_INDEX" >&2
     echo "0 : Init, param like this: 0 config_id" >&2
     echo "1 : Start Transfer syslog, param like this: 1 192.168.10.10 21 username passwword" >&2
     echo "2 : Start Transfer mtklog,  param like this: 2 192.168.10.10 21 username passwword" >&2
-    echo "3 : Show Debug state info debug,   param like this: 3" >&2
+    echo "$DEBUG_INDEX : Show Debug state info debug,   param like this: $DEBUG_INDEX" >&2
+    echo "$FLUSH_LOG_INDEX : flush syslog, param like this: $FLUSH_LOG_INDEX" >&2
     echo "101 : Stop transfer sys log, param like this: 101" >&2
     echo "102 : Stop transfer mtk log, param like this: 102" >&2    
     echo " ">&2
@@ -340,29 +384,29 @@
       $ERROR_FTP_TRANSFER_FAIL)
         echo_debug_info "ftp transfer error"      
         ;; 
-      $ERROR_INNER_ERROR)
-        echo_debug_info "inner error"
+      $ERROR_INNER_EXE_RROR)
+        echo_debug_info "inner exe error"
         ;;
-      $ERROR_IS_IN_TRANSFER_SYS_LOG)
-        echo_debug_info "is still in transfering sys log"
-        ;;    
-      $ERROR_IS_IN_TRANSFER_REMAIN_SYS_LOG)  
-        echo_debug_info "is still in transfering remain sys log"
-        ;;  
-      $ERROR_IS_IN_WAIT_TRRANSFER_REMAIN_SYS_LOG)
-        echo_debug_info "is still waitting transfer remain sys log"
-        ;;       
-      $ERROR_IS_IN_TRANSFER_MTK_LOG)
-        echo_debug_info "is still in transfering mtk log"
-        ;;    
-      $ERROR_IS_IN_TRANSFER_REMAIN_MTK_LOG)  
-        echo_debug_info "is still in transfering remain mtk log"
-        ;;  
-      $ERROR_IS_IN_WAIT_TRRANSFER_REMAIN_MTK_LOG)
-        echo_debug_info "is still waitting transfer remain mtk log"
-        ;;                 
-      *)
-        echo_debug_info "other error"
+      $ERROR_INNER_PARAM_RROR)
+        echo_debug_info "inner parm error"
+        ;;
+	*)
+        log_index=$((($1-$ERROR_IS_IN_TRANSFER_LOG)/10))		
+        length=${#log_print[@]}
+        if [ $log_index -lt $length ]; then               
+            inner_index=$(($1-$log_index*10-$ERROR_IS_IN_TRANSFER_LOG))
+            if [ $inner_index -eq 0 ]; then
+                echo_debug_info "now in transfer ${log_print[$log_index]}"
+            elif [ $inner_index -eq 1 ]; then                
+                echo_debug_info "now in transfer remain ${log_print[$log_index]}"            
+            elif [ $inner_index -eq 2 ]; then
+                echo_debug_info "is still waitting transfer remain ${log_print[$log_index]}"    
+            else
+                echo_debug_info "other error: $1"    
+            fi            
+        else
+            echo_debug_info "other error: $1"                  
+        fi                        
         ;;
     esac       
     echo_debug_info "curIndex is $CUR_LOG_NUM, max index is $log_index_max"
@@ -442,52 +486,77 @@
     fi
 }
 
-function transfer_last_remain_syslog_file()
-{    
-    cd ${SYS_LOG_PATH}    
-    for syslog_file in  ${log_prefix}*.$TAR_EXT ; do  
-	if [ ! -e "$syslog_file" ]; then
-            continue
-        fi
-        file_index=$(echo ${syslog_file} | cut -d '_' -f 3 | cut -d '.' -f 1)	
-        get_del_num ${file_index} ${log_num_max}
-        ftp_delete_file ${log_prefix}_${LOG_DEL}.$TAR_EXT
-        ftp_transfer_file_then_delete $syslog_file 0
-        if [ $? -ne 0 ]; then          
-            exit_process $ERROR_FTP_TRANSFER_FAIL                
-        fi                
-    done 
-    rm -rf $SYS_LOG_PATH$log_prefix* 
+function do_single_sys_tar_log_transfer()
+{
+    file_index=$(echo $1 | cut -d '_' -f 3 | cut -d '.' -f 1)    
+    get_del_num ${file_index} ${log_num_max}
+    ftp_delete_file ${log_prefix}_${LOG_DEL}.$TAR_EXT
+    ftp_transfer_file_then_delete $1 0
+    if [ $? -ne 0 ]; then          
+        echo_debug_info "ftp error code is $?"     
+        exit_process $ERROR_FTP_TRANSFER_FAIL                
+    fi                
 }
 
-function do_sys_log_transfer()
+function transfer_last_remain_sys_tar_log_file()
+{    
+    cd ${SYS_LOG_PATH}    
+    for syslog_tar_file in  ${log_prefix}*.$TAR_EXT ; do  
+        if [ ! -e "$syslog_tar_file" ]; then
+            continue
+        fi
+        do_single_sys_tar_log_transfer $syslog_tar_file        
+    done 
+	
+    #ĬÈϰ´ÕÕÉú³Éʱ¼ä˳Ðò´«ÊäѹËõÎļþ£¬¿ÉÄÜѹËõÎļþ²úÉúÓÚrebootÆÚ¼ä£¬Ê±¼ä»áÓÐÌø±ä, ËùÒÔÕâÀïÒªPay attention Ò»ÏÂ
+    # By default, compressed files are transmitted in the order of generation time. Compressed files may be generated during reboot, and the time maybe jump, so need Pay attention"
+    echo_debug_info "Pay attention if file creat in time jump¡£if yes£¬ the log index need be adjust"
+    do_sys_tar_log_transfer $SYS_LOG_TMP.${TAR_EXT} 1    
+	
+    rm -rf $SYS_LOG_PATH$log_prefix* 
+    rm -rf $SYS_LOG_PATH$SYS_LOG_TMP.${TAR_EXT}
+}
+
+
+function do_sys_log_tar()
 {
     cd ${SYS_LOG_PATH}     
     EXIST_SYS_LONG_NUM=0
-    for SYS_LOG_FILE in ${SYS_LOG_FILES[@]} $1; do        
-        if [ -e "${SYS_LOG_PATH}/${SYS_LOG_FILE}" ]; then            
-            mv ${SYS_LOG_FILE} ${log_prefix}_${CUR_LOG_NUM}
-            SYSLOG_INDEX[$EXIST_SYS_LONG_NUM]=${CUR_LOG_NUM}
-            ((EXIST_SYS_LONG_NUM++))        
+    for SYS_LOG_FILE in ${SYS_LOG_FILES[@]} ; do        
+        if [ -e "${SYS_LOG_PATH}/${SYS_LOG_FILE}" ]; then                          
+            get_del_num ${CUR_LOG_NUM} $log_num_max    
+            rm -rf ${log_prefix}_${LOG_DEL}.$TAR_EXT
+            ${TAR_CMD} ${TAR_ARG} $SYS_LOG_FILE  
+            mv $SYS_LOG_FILE.$TAR_EXT ${log_prefix}_${CUR_LOG_NUM}.$TAR_EXT                                
             do_cur_log_num_plus                            
         fi
-    done    
+    done      
+}   
+
+function get_name_and_transfer_single_file()
+{    
+    to_be_transfer_name=${log_prefix}_${CUR_LOG_NUM}.$TAR_EXT	
+    mv $1 $to_be_transfer_name
+    if [ "$2" = "1" ]; then 
+        echo_debug_info "sys tar $syslog_tar_file is changed to $to_be_transfer_name"	
+    fi
+    do_single_sys_tar_log_transfer $to_be_transfer_name        
+    do_cur_log_num_plus
+}
+
+function do_sys_tar_log_transfer()
+{
+    cd ${SYS_LOG_PATH}    
+    for syslog_tar_file in $(ls -tr --time-style=long-iso ${LOG_PREFIX[0]}*.$TAR_EXT 2>/dev/null); do  
+        if [ ! -e "$syslog_tar_file" ]; then
+            continue    
+        fi            
+        get_name_and_transfer_single_file $syslog_tar_file $2
+    done  
     
-    for j in `seq 0 $(($EXIST_SYS_LONG_NUM-1))`
-    do          
-         ${TAR_CMD} ${TAR_ARG} ${log_prefix}_${SYSLOG_INDEX[$j]}         
-    done
-        
-    for j in `seq 0 $(($EXIST_SYS_LONG_NUM-1))`
-    do  
-        get_del_num ${SYSLOG_INDEX[$j]} $log_num_max
-        ftp_delete_file ${log_prefix}_${LOG_DEL}.$TAR_EXT
-        ftp_transfer_file_then_delete ${log_prefix}_${SYSLOG_INDEX[$j]}.$TAR_EXT    0    
-        if [ $? -ne 0 ]; then
-             echo_debug_info "ftp error code is $?"             
-             exit_process $ERROR_FTP_TRANSFER_FAIL        
-        fi              
-    done    
+    if [ -e "$1" ]; then        
+        get_name_and_transfer_single_file $1
+    fi            
 }    
 
 function do_backup_mtk_log()
@@ -519,25 +588,41 @@
             mv $file_name $MTK_LOG_BUFF_PATH${log_prefix}_${CUR_LOG_NUM}.muxz             
             do_backup_mtk_log "muxz"               
         else
-            break;
+            break
         fi    
     done
 }
 
+function wait_syslog_0_delete()
+{
+    second=0
+    while [ -e "syslog.log.0"  -a $second -lt $((${loop_time[0]}+10)) ]
+    do    
+        sleep 1
+        ((second=second+1))
+    done
+    
+    if [ -e "syslog.log.0" ]; then
+        echo_debug_info "wait_syslog_0_delete fail" 
+    fi    
+}
+
 
 function send_remain_log()
 {
-    if [ $1 -eq 0 ]; then        
-        do_sys_log_transfer "syslog.log"
-        echo "" > ${SYS_LOG_PATH}/syslog.log
+    if [ $1 -eq 1 ]; then    
+        cd ${SYS_LOG_PATH}  
+        wait_syslog_0_delete 
+        mv syslog.log $SYS_LOG_TMP    
+        ${TAR_CMD} ${TAR_ARG} $SYS_LOG_TMP                
+        do_sys_tar_log_transfer $SYS_LOG_TMP.${TAR_EXT}        
         #gpslog transfer to soc begin@cz.li,20240314
         if [ -d ${GPS_LOG_PATH} ]; then
             do_gps_log_transfer "nma" 
             do_gps_log_transfer "curf" 
         fi
         #gpslog transfer to soc end@cz.li,20240314
-    elif [ $1 -eq 1 ]; 
-    then
+    elif [ $1 -eq 2 ]; then
         do_mtk_log_transfer "muxz"
         do_mtk_log_transfer "muxz.tmp"       
     fi    
@@ -546,14 +631,15 @@
 function do_log_transfer()
 {
     if [ $1 -eq 0 ]; then
-        do_sys_log_transfer
+        do_sys_log_tar     
+    elif [ $1 -eq 1 ]; then
+        do_sys_tar_log_transfer
         #gpslog transfer to soc begin@cz.li,20240314
         if [ -d ${GPS_LOG_PATH} ]; then 
             do_gps_log_transfer "nma"
         fi
         #gpslog transfer to soc end@cz.li,20240314
-    elif [ $1 -eq 1 ]; 
-    then
+    elif [ $1 -eq 2 ]; then
         do_mtk_log_transfer "muxz"  
     fi
 }
@@ -630,10 +716,18 @@
 function delete_beyond_log()
 {
     post_fix=${UP_LOAD_POSTFIX[$1]}     
+	
+    if [ $1 -eq 0 ]; then
+        cd ${SYS_LOG_PATH}  	
+    fi
     
     for j in `seq $2 $3`
     do 
-        ftp_delete_file ${log_prefix}_${j}.${post_fix}
+        if [ $1 -eq 0 ]; then
+            rm -rf ${log_prefix}_${j}.${post_fix}
+        else
+            ftp_delete_file ${log_prefix}_${j}.${post_fix}
+        fi        
     done
 }
 
@@ -655,70 +749,124 @@
             CUR_LOG_NUM=$log_index_max
             uci set ${q_cur_num_uci}=${CUR_LOG_NUM}
             uci commit
+        elif [ $CUR_LOG_NUM -lt 0 ]; then
+            CUR_LOG_NUM=0
+            uci set ${q_cur_num_uci}=${CUR_LOG_NUM}
+            uci commit
         fi
     fi    
 }
 
+function set_single_size_uci()
+{
+    # Q_SINGLE_FILE_SIZE_UCI=SINGLE_FILE_SIZE_TEN_TIMES*COMPRESS_RATIO_TEN_TIME/10*CONVERT_TO_M/10
+    if  [ ${CONVERT_TO_M[$1]} -eq 1048576 ]; then
+       # add  /8192*8192 to  aligen 8K    
+       uci set ${Q_SINGLE_FILE_SIZE_UCI[$1]}=$((${SINGLE_FILE_SIZE_TEN_TIMES[$1]}*${COMPRESS_RATIO_TEN_TIME[$1]}/10*${CONVERT_TO_M[$1]}/10/8192*8192))
+    else       
+       uci set ${Q_SINGLE_FILE_SIZE_UCI[$1]}=$((${SINGLE_FILE_SIZE_TEN_TIMES[$1]}*${COMPRESS_RATIO_TEN_TIME[$1]}/10*${CONVERT_TO_M[$1]}/10))
+    fi
+    
+    uci commit
+}
+
 function get_single_file_size()
 {
-    single_file_size=${SINGLE_FILE_SIZE[$1]}          
-     
-    if [ $1 -eq 1 ]; then
-        q_uci_value=`uci get mdlog.property.md_log_size`
-        if [ ! -z $q_uci_value ];
-        then
-            single_file_size=$(($(($q_uci_value))*10))            
+    
+    q_single_size_uci=${Q_SINGLE_FILE_SIZE_UCI[$1]}    
+
+    q_uci_value=`uci get ${Q_SINGLE_FILE_SIZE_UCI[$1]}`
+    if [ -z $q_uci_value ];
+    then       
+        single_file_size_ten_times=${SINGLE_FILE_SIZE_TEN_TIMES[$1]}   
+        if [ ! $single_file_size_ten_times -gt 0 ]; then
+            echo_debug_info "error, index $1 single file size is ${single_file_size_ten_times}, not > 0"    
+            return 1
         fi
-    fi            
+        set_single_size_uci $1
+    else
+        # single_file_size_ten_times=Q_SINGLE_FILE_SIZE_UCI*10/CONVERT_TO_M*10/COMPRESS_RATIO_TEN_TIME
+        single_file_size_ten_times=$(($q_uci_value*10/${CONVERT_TO_M[$1]}*10/${COMPRESS_RATIO_TEN_TIME[$1]}))
+        if [ ! $single_file_size_ten_times -gt 0 ]; then
+            echo_debug_info "error, index $1 single file size is ${single_file_size_ten_times}, not > 0, qci value is $q_uci_value"    
+            return 1
+        fi
+    fi       
+    
 }
 
 function get_init_max_log_num()
 {
-    init_log_max_size=${INIT_LOG_MAX_SIZE[$1]}            
-    q_max_size_uci=${Q_MAX_SIZE_UCI[$1]}    
-    
-    get_single_file_size $1
-        
-    if [ ! -z $q_max_size_uci ]; then
-        q_uci_value=`uci get $q_max_size_uci`
-        if [ -z $q_uci_value ];
-        then
-            uci set ${q_max_size_uci}=$init_log_max_size
-            uci commit
-            log_num_max=$(($init_log_max_size*20/single_file_size))
-        else
-            log_num_max=$(($(($q_uci_value))*20/single_file_size))
-        fi    
+    get_single_file_size $1    
+    if [ ! $single_file_size_ten_times -gt 0 ]; then      
+       return $ERROR_INNER_PARAM_ERROR
     fi
-    log_index_max=$(($log_num_max-1))     
+    echo_debug_info "single file size ten times is $single_file_size_ten_times, unit 0.1 M"
+    
+    q_uci_value=`uci get ${Q_MAX_SIZE_UCI[$1]}`
+    if [ -z $q_uci_value ];
+    then
+        log_num_max=$((${INIT_LOG_MAX_SIZE[$1]}*10/$single_file_size_ten_times*2))
+        if [ ! $log_num_max -gt 0 ]; then
+           echo_debug_info "error, log num max is not greater than 0, initial max size is ${INIT_LOG_MAX_SIZE[$1]}"    
+           return $ERROR_INNER_PARAM_ERROR
+        fi               
+        uci set ${Q_MAX_SIZE_UCI[$1]}=${INIT_LOG_MAX_SIZE[$1]}
+        uci commit
+        
+    else
+        log_num_max=$(($q_uci_value*10/$single_file_size_ten_times*2))
+        if [ ! $log_num_max -gt 0 ]; then
+           echo_debug_info "error, log num max is not greater than 0, qci max size is $q_uci_value"    
+           return $ERROR_INNER_PARAM_ERROR
+        fi     
+    fi    
+    
+
+   
+    log_index_max=$(($log_num_max-1))  
+    echo_debug_info "curIndex is $CUR_LOG_NUM, log_index_max is $log_index_max"    
+    return 0
 }
 
 cur_uci_md_mod=0
 function is_mtk_log_start()
 {    
-    second=0	
+    second=0    
     while [ $second -lt 10 ]
     do    
         q_uci_value=`uci get mdlog.property.md_current_mode`
-	cur_uci_md_mod=$(($q_uci_value))
+        cur_uci_md_mod=$(($q_uci_value))
         if [ $cur_uci_md_mod -ne 0 ]; then 
           echo_debug_info "start mtk log ok"
-	  return 
+          return 
         fi
         sleep 1
         ((second=second+1))
     done
 }
 
-
-
 function loop_prepare()
-{
+{        
+    transfer_log_tag[$index]=1
+
+    target_dir=${TARGET_DIR[$1]}    
+    log_prefix=${LOG_PREFIX[$1]}   
+    get_init_max_log_num $1
+    ret=$?
+    if [ $ret -ne 0 ]; then 
+        show_relative_tag $DEBUG_INDEX
+        exit_process $ERROR_INNER_PARAM_ERROR  
+    fi
+    
+    get_init_cur_log_num $1   
+    
+
     #gpslog transfer to soc begin@cz.li,20240314
-    if [ $1 -eq 0 ]; then
+    if [ $1 -eq 1 ]; then
         init_gpslog
     #gpslog transfer to soc end@cz.li,20240314
-    elif [ $1 -eq 1 ]; then
+    elif [ $1 -eq 2 ]; then
         if [ ! -d ${MTK_LOG_BUFF_PATH} ]; then                    
             mkdir -p ${MTK_LOG_BUFF_PATH}
         fi      
@@ -728,15 +876,11 @@
             echo_debug_info "start mtk log fail"
             show_relative_tag $1
             stop_mtk_log_and_clear_dir
-            exit_process $ERROR_INNER_ERROR              
+            exit_process $ERROR_INNER_EXE_ERROR              
         fi        
-    fi     
-    target_dir=${TARGET_DIR[$1]}    
-    log_prefix=${LOG_PREFIX[$1]}   
-
-    
-    get_init_max_log_num $1
-    get_init_cur_log_num $1
+    fi          
+   
+  
     
     if [ ! -z $target_dir ]; then
         # 3 times for guarrantee
@@ -746,60 +890,52 @@
     fi    
 
 #LYNQ_MTK_BUG483_Q.HUANG_20241226_DONT_DELETE_TRANSFER_FAIL_FILE_BEGIN       
-    if [ $1 -eq 0 ]; then
-        transfer_last_remain_syslog_file
-    elif [ $1 -eq 1 ]; then
+    if [ $1 -eq 1 ]; then
+        transfer_last_remain_sys_tar_log_file
+    elif [ $1 -eq 2 ]; then
         do_backup_mtk_log "muxz"
     fi
 #LYNQ_MTK_BUG483_Q.HUANG_20241226_DONT_DELETE_TRANSFER_FAIL_FILE_END
+
+    touch ${LOG_IS_IN_TRANSFER[${index}]}
+    
+    show_relative_tag $index
 }
 
 
 function trigger_log_transfer()
 {
-    index=$((${1}-1))
-     
-    if [ $index -eq 2 ]; then
-         show_relative_tag $index
-         return
-    fi
-    
-    #afterwards index only have 0~1 
+    index=$1     
+ 
     
     if [ -e ${LOG_IS_IN_TRANSFER[$index]} ]; then                
-        exit_process $((ERROR_IS_IN_TRANSFER_LOG+${index}*5 ))
+        exit_process $((ERROR_IS_IN_TRANSFER_LOG+${index}*10 ))
     fi
     if [ -e ${WAIT_TRANSFER_REMAIN_LOG[$index]} ]; then                
-        exit_process $((ERROR_IS_IN_TRANSFER_LOG+${index}*5+1))    
+        exit_process $((ERROR_IS_IN_TRANSFER_LOG+${index}*10+1))    
     fi   
     
-    
-    
-    get_ftp_param $# $2 $3 $4 $5    
-        
-    transfer_log_tag[$index]=1
-    
-    loop_prepare $index
-   
-    touch ${LOG_IS_IN_TRANSFER[${index}]}
-    
-    show_relative_tag $index
+    if [ ${need_check_ftp_sever[$index]} -eq 1 ]; then
+        get_ftp_param $# $2 $3 $4 $5    
+    fi           
+     
+    loop_prepare $index       
 
     do_loop ${index} ${loop_time[$index]}           
 }
 
 function stop_log_transfer_ui()
 {
-    index=$((${1}-101))
+    index=$((${1}-100))
     if [ -e ${WAIT_TRANSFER_REMAIN_LOG[$index]} ]; then                
-        exit_process $((ERROR_IS_IN_TRANSFER_LOG+${index}*5+2 ))
+        exit_process $((ERROR_IS_IN_TRANSFER_LOG+${index}*10+2 ))
     fi          
     #gpslog transfer to soc begin@cz.li,20240314
     #no need rm GPS_LOG_PATH and GPS_COF_PATH, because the GPS process cannot dynamically stop/start log output
-    #if [ $index -eq 0 ]; then
+    #if [ $index -eq 1 ]; then
         #rm -rf ${GPS_LOG_PATH}
     #gpslog transfer to soc end@cz.li,20240314
-    if [ $index -eq 1 ]; then
+    if [ $index -eq 2 ]; then
         echo 7 | emdlogger_ctrl socket  
     fi
     
@@ -807,34 +943,52 @@
 }
 
 function init_md_log()
-{
-    if [ ! -d $MTK_LOG_MOUNT_PATH ];
-    then 
-        echo_debug_info "init md log start"
-        stop_mtk_log_and_clear_dir
-        mkdir -p $MTK_LOG_MOUNT_PATH
-        mount -o bind $MTK_LOG_MOUNT_PATH $MTK_LOG_PATH
-        rm -rf $MTK_LOG_PATH*
-        uci set mdlog.property.md_cyclic_size='36'
-        uci set mdlog.property.md_log_size=$((${SINGLE_FILE_SIZE[1]}/10))
-        uci commit
-        killall emdlogger1    
-        echo_debug_info "init md log end"
-    fi        
+{  
+    echo_debug_info "init md log start"
+    stop_mtk_log_and_clear_dir
+    mkdir -p $MTK_LOG_MOUNT_PATH
+    mount -o bind $MTK_LOG_MOUNT_PATH $MTK_LOG_PATH
+    rm -rf $MTK_LOG_PATH*
+    uci set mdlog.property.md_cyclic_size='36'
+    set_single_size_uci 2
+    uci commit
+    killall emdlogger1    
+    echo_debug_info "init md log end"            
 }
 
+function init_sys_log()
+{
+    echo_debug_info "init sys log start"
+    set_single_size_uci 1
+    killall syslogd        
+    echo_debug_info "init sys log end"    
+}
+
+
+
 function init_log_transfer_ui()
 {
     index=$2
     if [ $index -eq 1 ]; then
-        init_md_log
+        if [ ! -d $MTK_LOG_MOUNT_PATH ]; then 
+            init_md_log
+            init_sys_log
+            trigger_log_transfer "$@"
+        fi
     fi    
 }
 
+function flush_log()
+{
+    cd ${SYS_LOG_PATH}  
+    wait_syslog_0_delete 
+    mv syslog.log syslog.log.0    
+}
+
 echo_debug_info "log transfer param_num $# param $* start"
 
 case "$1" in  
-  [1-3])  
+  [1-2])  
     trigger_log_transfer "$@"
     ;;
   101|102)     
@@ -843,6 +997,12 @@
   0)
     init_log_transfer_ui "$@"
     ;;
+  $DEBUG_INDEX)
+    show_relative_tag $1    
+    ;;
+  $FLUSH_LOG_INDEX)
+    flush_log
+    ;;
   *)    
     exit_process $ERROR_PARAM
     ;;