Ver Fonte

add oem sel

zhangbo há 3 anos atrás
pai
commit
03cd551d9e

+ 76 - 28
app/bmc/Api.c

@@ -15,6 +15,7 @@
 #include "SELRecord.h"
 #include "SEL.h"
 #include "MsgHndlr.h"
+#include "driver.h"
 
 pthread_mutex_t Flash_Mutex;
 
@@ -223,7 +224,6 @@ int Init_IPMI_FRU_SDR_SEL(void)
 	
 	GetIPMIFromFlash();
 	if(strncmp(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr)) != 0)
-//	if(1)
 	{
 		//first power on
 		printf("\n\n*** BMC first power on! ***\n\n");
@@ -283,20 +283,7 @@ int Init_IPMI_FRU_SDR_SEL(void)
 		
 		
 		
-		/******************************* Init SEL *************************************/	    
-		pSEL = g_BMCInfo.pSEL;
-		((SELRepository_T*)pSEL)->Signature[0] 	= 0x00;
-		((SELRepository_T*)pSEL)->Signature[1] 	= 0x11;
-		((SELRepository_T*)pSEL)->Signature[2] 	= 0x22;
-		((SELRepository_T*)pSEL)->Signature[3] 	= 0x33;
-		((SELRepository_T*)pSEL)->NumRecords	= 0;
-		((SELRepository_T*)pSEL)->Padding		= 0;
-		((SELRepository_T*)pSEL)->AddTimeStamp	= 0;
-		((SELRepository_T*)pSEL)->EraseTimeStamp = 0;
-		((SELRepository_T*)pSEL)->FirstRecID	= 0;
-		((SELRepository_T*)pSEL)->LastRecID		= 0;
-		((SELRepository_T*)pSEL)->SELIndex		= 0;
-		((SELRepository_T*)pSEL)->SELRecord		= (SELRec_T*)(pSEL + sizeof(SELRepository_T));
+		
 		
 		g_BMCInfo.IpmiConfig.SELConfig.SelReservationID = 0;;
 	    g_BMCInfo.IpmiConfig.SELConfig.LastEvtTS		=	0;
@@ -361,9 +348,9 @@ int Init_IPMI_FRU_SDR_SEL(void)
 		//Init SDR
 		GetSDRFromFlash();
 		
-		//Init SEL
-		GetSELFromFlash();
-		((SELRepository_T*)g_BMCInfo.pSEL)->SELRecord		= (SELRec_T*)(g_BMCInfo.pSEL + sizeof(SELRepository_T));
+		// //Init SEL
+		// GetSELFromFlash();
+		// ((SELRepository_T*)g_BMCInfo.pSEL)->SELRecord		= (SELRec_T*)(g_BMCInfo.pSEL + sizeof(SELRepository_T));
 
 		
 
@@ -391,6 +378,31 @@ int Init_IPMI_FRU_SDR_SEL(void)
 		g_BMCInfo.pUserInfo = NULL;
 	}
 
+
+	//Init sel
+	GetSELFromFlash();
+	((SELRepository_T*)g_BMCInfo.pSEL)->SELRecord		= (SELRec_T*)(g_BMCInfo.pSEL + sizeof(SELRepository_T));
+	if( (((SELRepository_T*)g_BMCInfo.pSEL)->Signature[0] != 0x00) ||
+		(((SELRepository_T*)g_BMCInfo.pSEL)->Signature[1] != 0x11) ||
+		(((SELRepository_T*)g_BMCInfo.pSEL)->Signature[2] != 0x22) ||
+		(((SELRepository_T*)g_BMCInfo.pSEL)->Signature[3] != 0x33)	)
+	{
+		/******************************* Init SEL *************************************/	    
+		pSEL = g_BMCInfo.pSEL;
+		((SELRepository_T*)pSEL)->Signature[0] 	= 0x00;
+		((SELRepository_T*)pSEL)->Signature[1] 	= 0x11;
+		((SELRepository_T*)pSEL)->Signature[2] 	= 0x22;
+		((SELRepository_T*)pSEL)->Signature[3] 	= 0x33;
+		((SELRepository_T*)pSEL)->NumRecords	= 0;
+		((SELRepository_T*)pSEL)->Padding		= 0;
+		((SELRepository_T*)pSEL)->AddTimeStamp	= 0;
+		((SELRepository_T*)pSEL)->EraseTimeStamp = 0;
+		((SELRepository_T*)pSEL)->FirstRecID	= 0;
+		((SELRepository_T*)pSEL)->LastRecID		= 0;
+		((SELRepository_T*)pSEL)->SELIndex		= 0;
+		FlushSELToFlash();
+	}
+
 	g_BMCInfo.IpmiConfig.SDRConfig.UpdatingSDR	=	FALSE;
 	g_BMCInfo.IpmiConfig.SDRConfig.UpdatingChannel	=	0;
 	g_BMCInfo.IpmiConfig.SDRConfig.TrackPOffset	=	0;
@@ -994,29 +1006,65 @@ int FlushSELToFlash()
 	uint32_t 	offset = 0;
 	uint32_t	selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;	
 
-	pthread_mutex_lock(&Flash_Mutex);
+    iflash_t iflash_arg;
+    int ret = 0;
+    int fd = open("/dev/iflash", O_RDWR);
+    ret = ioctl(fd, IFLASH_UNLOCK, NULL);
+    if(ret != 0)
+    {
+        printf("error: ret = %d\n", ret);
+    }
+
+    iflash_arg.sector = 6;
+    ret = ioctl(fd, IFLASH_ERASESECTOR, &iflash_arg);
+    if(ret != 0)
+    {
+        printf("error: ret = %d\n", ret);
+    }
+
+    /**** SEL ****/
+	//pthread_mutex_lock(&Flash_Mutex);
 	while(selSize > 0)
 	{
-		if(selSize > 4*1024)
-			writeLen = 4*1024;
+		if(selSize > 256)
+			writeLen = 256;
 		else
 			writeLen = selSize;
 
-		sf_sector_erase(5, SEL_FLASH_ADDR+offset);
-		sf_write(5, SEL_FLASH_ADDR+offset, g_BMCInfo.pSEL+offset, writeLen);
+		iflash_arg.address = 0x08040000+offset;
+		iflash_arg.len = writeLen;
+	    memcpy(iflash_arg.data, (uint8_t*)g_BMCInfo.pSEL+offset, writeLen);
+	    ret = ioctl(fd, IFLASH_WRITEBYTE, &iflash_arg);
+	    if(ret != 0)
+	    {
+	        printf("error: ret = %d\n", ret);
+	    }
+
+		// sf_sector_erase(5, SEL_FLASH_ADDR+offset);
+		// sf_write(5, SEL_FLASH_ADDR+offset, g_BMCInfo.pSEL+offset, writeLen);
 		offset += writeLen;
 		selSize -= writeLen;
 	}
-	pthread_mutex_unlock(&Flash_Mutex);
+	//pthread_mutex_unlock(&Flash_Mutex);
+	ret = ioctl(fd, IFLASH_LOCK, NULL);
+    if(ret != 0)
+    {
+        printf("error: ret = %d\n", ret);
+    }
+    
+    close(fd);
+	
 	return 0;
 }
 
 int GetSELFromFlash()
 {
 	uint32_t	selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;	
-	pthread_mutex_lock(&Flash_Mutex);
-	sf_read(5, SEL_FLASH_ADDR, g_BMCInfo.pSEL, selSize);
-	pthread_mutex_unlock(&Flash_Mutex);
+
+	// pthread_mutex_lock(&Flash_Mutex);
+	// sf_read(5, SEL_FLASH_ADDR, g_BMCInfo.pSEL, selSize);
+	// pthread_mutex_unlock(&Flash_Mutex);
+	memcpy(g_BMCInfo.pSEL, (uint8_t*)0x08040000, selSize);
 	return 0;
 }
 
@@ -1125,7 +1173,7 @@ int UpdateUserInfoTble(void)
 int UpdateFlash(void)
 {
 	FlushSDRToFlash();
-	FlushSELToFlash();
+	//FlushSELToFlash();
 	FlushIPMIToFlash();
 	FlushFRUToFlash();
 	return 0;

+ 3 - 2
app/bmc/readme.txt

@@ -23,5 +23,6 @@
 6. 机箱管理使能改由前端网页控制,默认是打开的。网页在下发获取机箱信息的时候多下发一个参数,机箱管理是否使能。
 
 7. GD32F450内部flash:
-		Sector 6 放License											0x08060000~0x0807ffff 128KB
-		Sector 7 放配置信息,IpmiConfig + user info + FRU + SDR 		0x08080000~0x0809ffff 128KB
+		Sector 6 放SEL												0x08040000~0x0805ffff 128KB
+		Sector 7 放License											0x08060000~0x0807ffff 128KB
+		Sector 8 放配置信息,IpmiConfig + user info + FRU + SDR 		0x08080000~0x0809ffff 128KB

BIN
app/driver/I2C/i2c.ko


+ 7 - 3
app/driver/I2C/i2c_main.c

@@ -57,6 +57,7 @@ static int i2c_close(struct inode *inode, struct file *filep);
 static ssize_t i2c_read(struct file *filep, char __user *buf, size_t size, loff_t *offset);
 static ssize_t i2c_write(struct file *filep, const char __user *buf, size_t size, loff_t *offset);
 static int i2c_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg);
+void i2c_hw_init(void);
 
 static struct file_operations i2c_ops = 
 {
@@ -142,12 +143,15 @@ irqreturn_t i2cErrIRQHandler(int irqno, void *dev_id)
 		return IRQ_HANDLED;
 	}
 
-	printk("SR1: %#x, SR2: %#x\n", hi2c.Instance->SR1, hi2c.Instance->SR2);
+	printk("SR1: %#lx, SR2: %#lx\n", hi2c.Instance->SR1, hi2c.Instance->SR2);
 
 	//restart i2c
 	hi2c.State	= HAL_I2C_STATE_READY;
-	__HAL_I2C_DISABLE(&hi2c);
-	__HAL_I2C_ENABLE(&hi2c);
+	hi2c.Instance->CR1 |= 0x8000;
+	hi2c.Instance->CR1 &= ~0x8000;
+	i2c_hw_init();
+	// __HAL_I2C_DISABLE(&hi2c);
+	// __HAL_I2C_ENABLE(&hi2c);
 	
 	return IRQ_HANDLED;
 }

+ 25 - 15
app/goahead-3.6.5/src/web_interface/src/sel.c

@@ -73,7 +73,7 @@ void GetAllSELEntriesSorted(Webs *wp)
     int wRet = 0;
     unsigned short nEntries = 0;
     SELEventRecordWithSensorName_T *pSELBuff = NULL;
-    int i;
+    int i,j;
     IPMI20_UDS_SESSION_T    UDSSession;
     uint8_t         target_addr;
     SensorNumNameTab_T senNumNameTab[MAX_SENSOR_NUMBERS];   //之前获取到的传感器名称暂存在这里,避免反复获取,浪费总线带宽。
@@ -142,6 +142,7 @@ void GetAllSELEntriesSorted(Webs *wp)
             goto error_out;
         }
 
+        printf("Reserve SEL, sel number %d\n", nEntries);
         //Reserve SEL
         if(target_addr == 0x20)
         {
@@ -189,12 +190,15 @@ void GetAllSELEntriesSorted(Webs *wp)
                 // cJSON_AddNumberToObject(pJsonsub, "D10", SELEventData.EvtData2);     //EventData2    -> D10
                 // cJSON_AddNumberToObject(pJsonsub, "D11", SELEventData.EvtData3);     //EventData3    -> D11
 
+                if(i!=0)
+                {
+                    websWrite(wp, ",");
+                }
+
+                printf("Get sel i = %d\n", i);
                 if(SELEventData.hdr.Type == 0x02)
                 {
-                    if(i!=0)
-                    {
-                        websWrite(wp, ",");
-                    }
+                    printf("system sel\n");
                     websWrite(wp, "{\"D1\":%d,\"D2\":%d,\"D3\":%d,\"D4\":%d,\"D5\":%d,\"D6\":%d,\"D7\":%d,\"D8\":%d,\"D9\":%d,\"D10\":%d,\"D11\":%d,",
                         SELEventData.hdr.ID, SELEventData.hdr.Type, SELEventData.hdr.TimeStamp, 
                         SELEventData.body.sysEventRecord.GenID[0],  SELEventData.body.sysEventRecord.GenID[1], 
@@ -207,15 +211,15 @@ void GetAllSELEntriesSorted(Webs *wp)
                     if(SELEventData.body.sysEventRecord.SensorNum != 0xff)
                     {
                         found_flag = 0;
-                        for(i=0;i<MAX_SENSOR_NUMBERS;i++)   //先从之前的缓存里查找传感器名称
+                        for(j=0;j<MAX_SENSOR_NUMBERS;j++)   //先从之前的缓存里查找传感器名称
                         {
-                            if(senNumNameTab[i].sensor_number == 0xff)  //再往后没有内容了。
+                            if(senNumNameTab[j].sensor_number == 0xff)  //再往后没有内容了。
                                 break;
 
-                            if(senNumNameTab[i].sensor_number == SELEventData.body.sysEventRecord.SensorNum)
+                            if(senNumNameTab[j].sensor_number == SELEventData.body.sysEventRecord.SensorNum)
                             {                                                
                                 //cJSON_AddStringToObject(pJsonsub, "D12", senNumNameTab[i].sensor_name);  //SensorName -> D12
-                                websWrite(wp, "\"D12\":\"%s\"}", senNumNameTab[i].sensor_name);
+                                websWrite(wp, "\"D12\":\"%s\"}", senNumNameTab[j].sensor_name);
                                 found_flag = 1;
                                 break;
                             }
@@ -233,16 +237,16 @@ void GetAllSELEntriesSorted(Webs *wp)
                                 wRet = IPMC_GetSensorName(&UDSSession, target_addr,SELEventData.body.sysEventRecord.SensorNum, sensorName, DEFAULT_TIMEOUT);
                             }
                             //cJSON_AddStringToObject(pJsonsub, "D12", senNumNameTab[i].sensor_name);     //SensorName->D12
-                            websWrite(wp, "\"D12\":\"%s\"}", senNumNameTab[i].sensor_name);
+                            websWrite(wp, "\"D12\":\"%s\"}", sensorName);
                             if(wRet == 0)
                             {
                                 //将得到的传感器名称保存到缓存中
-                                for(i=0;i<MAX_SENSOR_NUMBERS;i++)
+                                for(j=0;j<MAX_SENSOR_NUMBERS;j++)
                                 {
-                                    if(senNumNameTab[i].sensor_number == 0xff)
+                                    if(senNumNameTab[j].sensor_number == 0xff)
                                     {
-                                        senNumNameTab[i].sensor_number = SELEventData.body.sysEventRecord.SensorNum;
-                                        strcpy(senNumNameTab[i].sensor_name, sensorName);                                
+                                        senNumNameTab[j].sensor_number = SELEventData.body.sysEventRecord.SensorNum;
+                                        strcpy(senNumNameTab[j].sensor_name, sensorName);                                
                                         break;
                                     }
                                 }
@@ -257,7 +261,13 @@ void GetAllSELEntriesSorted(Webs *wp)
                 }
                 else if(SELEventData.hdr.Type == 0xC0)
                 {
-                    //TODO:
+                    printf("oem sel\n");
+                    websWrite(wp, "{\"D1\":%d,\"D2\":%d,\"D3\":%d,\"D4\":%d,\"D5\":%d,\"D6\":%d,\"D7\":%d,\"D8\":%d,\"D9\":%d,\"D10\":0,\"D11\":0,\"D12\":0}",
+                        SELEventData.hdr.ID, SELEventData.hdr.Type, SELEventData.hdr.TimeStamp, 
+                        SELEventData.body.oemEventRecord.OEMDefined[0], SELEventData.body.oemEventRecord.OEMDefined[1],
+                        SELEventData.body.oemEventRecord.OEMDefined[2], SELEventData.body.oemEventRecord.OEMDefined[3],
+                        SELEventData.body.oemEventRecord.OEMDefined[4], SELEventData.body.oemEventRecord.OEMDefined[5]);
+                                
                 }
 
                 if(RecID == 0xffff) //last record

+ 2 - 2
local/rc

@@ -17,8 +17,8 @@ insmod /usr/bin/platform.ko
 insmod /usr/bin/adc.ko
 insmod /usr/bin/spi.ko
 #insmod /usr/bin/gpio_i2c.ko
-insmod /usr/bin/crypto.ko
-insmod /usr/bin/iwdg.ko
+#insmod /usr/bin/crypto.ko
+#insmod /usr/bin/iwdg.ko
 insmod /usr/bin/iflash.ko
 
 #################### create node ########################