소스 검색

resolve some bug

zhangbo 3 년 전
부모
커밋
3f3e5ecdf4

+ 58 - 20
app/UpdateFirmware/main.c

@@ -30,6 +30,7 @@ int main()
 	FILE *fpVerify;
 	uint8_t progressStr[10] = {0};
 	uint8_t rate = 0;
+	int retry = 3;
 
 	buf = malloc(32*1024 + 50);
 //	chkBuf = malloc(64*1024);
@@ -48,24 +49,45 @@ int main()
 	printf("Image size: %d\n", totalSize);
 
 	//开始擦除
-	fpErase = fopen("/var/www/goahead/tmp/Erase.log", "w");
-	if(NULL == fpErase)
+	retry = 3;
+	do
 	{
-		printf("Create Erase.log file fail!\n");
-	}
-	fputs("Erasing", fpErase);	
+		fpErase = fopen("/var/www/goahead/tmp/Erase.log", "w");
+		if(NULL == fpErase)
+		{
+			printf("Create Erase.log file fail! retry...\n");
+			retry--;
+			usleep(10);
+		}
+		else
+			break;
+	}while(retry);
+
+	if(fpErase != NULL)
+		fputs("Erasing", fpErase);	
+
 	fclose(fpErase);	
 
 	printf("Chip erase ...\n");
 	sf_chip_erase(5);
 	printf("Chip erase finished!\n");
 
-	fpErase = fopen("/var/www/goahead/tmp/Erase.log", "w");
-	if(NULL == fpErase)
-	{
-		printf("Create Erase.log file fail!\n");
-	}
-	fputs("Erase OK", fpErase);	
+	retry = 3;
+	do{
+		fpErase = fopen("/var/www/goahead/tmp/Erase.log", "w");
+		if(NULL == fpErase)
+		{
+			printf("Create Erase.log file fail! retry...\n");
+			retry--;
+			usleep(10);
+		}
+		else
+			break;
+	}while(retry);
+
+	if(fpErase != NULL)
+		fputs("Erase OK", fpErase);	
+
 	fclose(fpErase);	
 
 
@@ -77,7 +99,10 @@ int main()
 		printf("Create UpdateProgress.log file fail!\n");
 		//return -1;
 	}
-	fputs("0", fprogress);	
+	else
+	{
+		fputs("0", fprogress);	
+	}
 	fclose(fprogress);	
 
 	do{
@@ -111,8 +136,11 @@ int main()
 			printf("Create UpdateProgress.log file fail!\n");
 			//return -1;
 		}
-		sprintf(progressStr, "%d", rate);
-		fputs(progressStr, fprogress);	
+		else
+		{
+			sprintf(progressStr, "%d", rate);
+			fputs(progressStr, fprogress);	
+		}
 		fclose(fprogress);	
 	}while(writeSize < totalSize);
 	
@@ -123,12 +151,22 @@ int main()
 	//Verify
 	printf("Verigy successful.\n");
 	//用来保存校验结果
-	fpVerify = fopen("/var/www/goahead/tmp/Verify.log", "w");
-	if(NULL == fpVerify)
-	{
-		printf("Create UpdateProgress.log file fail!\n");
-	}
-	fputs("Verify OK", fpVerify);
+	retry = 3;
+	do{
+		fpVerify = fopen("/var/www/goahead/tmp/Verify.log", "w");
+		if(NULL == fpVerify)
+		{
+			printf("Create UpdateProgress.log file fail! retry...\n");
+			retry--;
+			usleep(10);
+		}
+		else
+			break;
+	}while(retry);
+
+	if(fpVerify != NULL)
+		fputs("Verify OK", fpVerify);
+
 	fclose(fpVerify);
 
 	fclose(fp);

BIN
app/UpdateFirmware/updateFW_app


+ 1 - 0
app/bmc/Api.h

@@ -52,5 +52,6 @@ int API_BridgeInternal(MsgPkt_T* pReqPkt, MsgPkt_T* pResPkt, uint8_t DestAddr, i
 
 extern pthread_mutex_t api_bridge_mutex;
 extern pthread_mutex_t Flash_Mutex;
+extern const char FirstPowerOnStr[];
 
 #endif /* __API_H__ */

+ 10 - 0
app/bmc/msghndlr/Storlead/Storlead.c

@@ -739,7 +739,17 @@ int Storlead_RestoreConfig(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
 {
     pRes[0] = CC_NORMAL;    
     int i;
+    uint8_t buf[32] = {0};
     /**** IpmiConfig + user info + FRU + SDR ****/
+    memcpy(buf, (uint8_t*)0x08080000, 32);
+    if(strcmp(buf, FirstPowerOnStr) != 0)
+    {
+        printf("No invalid config data!\n");
+        return 1;
+    }
+
+
+
     //IpmiConfig    4KB
     memcpy(&g_BMCInfo.IpmiConfig, (uint8_t*)0x08080000, sizeof(IPMIConfig_T));
     FlushIPMIToFlash();

+ 1 - 1
app/goahead-3.6.5/src/libipmi/inc/libipmi_storlead_OEM.h

@@ -80,7 +80,7 @@ typedef struct
 		In some cases sensor_name length is more than 17 characters. webgo was giving some special character to web page in those cases and webpage was giving some weird behaviour when it found that special character.
 	*/
     uint8_t sensor_num;
-    char sensor_name[ 20 ];
+    char sensor_name[ 16+1 ];
     float sensor_history[ 480 ];
     
 }sensor_history_st;

+ 6 - 2
app/goahead-3.6.5/src/web_interface/src/server_health.c

@@ -175,8 +175,12 @@ void webGetSensorHistory(Webs *wp)
         return;
     }
 
+    
     pSensorHistory->sensor_num = SensorNumber;
-    strcpy(pSensorHistory->sensor_name, sdr_record->IDStr);
+    //不能用strcpy,如果sensor_name是16个字节,没有传结束符
+    //strcpy(pSensorHistory->sensor_name, sdr_record->IDStr);
+    memcpy(pSensorHistory->sensor_name, sdr_record->IDStr, 16);
+    pSensorHistory->sensor_name[16] = 0;
     
     if(target_addr == 0x20)
     {
@@ -235,7 +239,7 @@ void webGetSensorHistory(Webs *wp)
     websSetStatus(wp, 200);
     websWriteHeaders(wp, -1, 0);
     websWriteEndHeaders(wp); 
-    websWrite(wp, "{\"SensorNum\":%d,\"SensorName\":\"%s\",\"history\":\"", SensorNumber, sdr_record->IDStr);
+    websWrite(wp, "{\"SensorNum\":%d,\"SensorName\":\"%s\",\"history\":\"", pSensorHistory->sensor_num, pSensorHistory->sensor_name);
 
     //char *strBuf = historyBuf;
     for(i=0;i<HISTORY_DATA_SIZE;i++)