123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239 |
- #include <stdint.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/socket.h>
- #include <fcntl.h>
- #include <net/if.h>
- #include <netinet/in.h>
- #include <sys/ioctl.h>
- #include "main.h"
- #include "Api.h"
- #include "SDRRecord.h"
- #include "SELRecord.h"
- #include "SEL.h"
- #include "MsgHndlr.h"
- #include "driver.h"
- pthread_mutex_t Flash_Mutex;
- int PlatformInit(void)
- {
- uint8_t PrimaryIPMBBusNum, SecondaryIPMBBusNum;
- printf("Init Platform...\r\n");
- //hardware init
- //槽位号识别
- GPIO_InitTypeDef GPIO_InitStruct;
- GPIO_InitStruct.Pin = GA0_PIN | GA1_PIN | GA2_PIN | GA3_PIN | GA4_PIN | RACKID2_PIN;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- stm32_gpio_init(GPIOH, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = GAP_PIN | RACKID1_PIN | RACKID3_PIN | RACKID4_PIN | RACKID5_PIN;
- stm32_gpio_init(GPIOI, &GPIO_InitStruct);
- //LED灯
- GPIO_InitStruct.Pin = IDENTIFY_PIN;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
- stm32_gpio_init(IDENTIFY_PORT, &GPIO_InitStruct);
- g_BMCInfo.SelfTestByte = 0;
- g_BMCInfo.SlotID = PDK_GetSlotID();
- g_BMCInfo.ChassisID = PDK_GetChassisID();
-
-
-
- //机箱及刀片信息
- g_BMCInfo.ChassisIdentify = FALSE;
- g_BMCInfo.ChassisIdentifyForce = FALSE;
- g_BMCInfo.ChassisIdentifyTimeout = 0;
- g_BMCInfo.PowerGoodFlag = 1;
- g_BMCInfo.BladeManageEn = 0;
- g_BMCInfo.BladeHealthSta = 1;
- memset(g_BMCInfo.BladeName, 0, 31);
- sprintf(g_BMCInfo.BladeName, "板卡%d", g_BMCInfo.SlotID);
- switch(g_BMCInfo.SlotID)
- {
- case 0x1:
- g_BMCInfo.IndexInChassis = 0;
- break;
- case 0x2:
- g_BMCInfo.IndexInChassis = 1;
- break;
- case 0x3:
- g_BMCInfo.IndexInChassis = 2;
- break;
- case 0x4:
- g_BMCInfo.IndexInChassis = 3;
- break;
- case 0x5:
- g_BMCInfo.IndexInChassis = 4;
- break;
- case 0x6:
- g_BMCInfo.IndexInChassis = 5;
- break;
- case 0x7:
- g_BMCInfo.IndexInChassis = 6;
- break;
- case 0x8:
- g_BMCInfo.IndexInChassis = 7;
- break;
- case 0x9:
- g_BMCInfo.IndexInChassis = 8;
- break;
- case 0xA:
- g_BMCInfo.IndexInChassis = 9;
- break;
- default:
- printf("\n\n\nWarning: Invalid SlotID %#x\n\n\n", g_BMCInfo.SlotID);
- g_BMCInfo.IndexInChassis = 0xff;
- break;
- }
- if(g_BMCInfo.SlotID == 1)
- {
- g_BMCInfo.isChMC = 1;
- //IPMB地址
- g_BMCInfo.PrimaryIPMBAddr = 0x20;
- g_BMCInfo.SecondaryIPMBAddr = 0x20;
- if(g_BMCInfo.IndexInChassis < BLADE_NUMBERS)
- {
- gChassisIPMBAddr[g_BMCInfo.IndexInChassis] = 0x20;
- }
- }
- else
- {
- g_BMCInfo.isChMC = 0;
- //IPMB地址
- g_BMCInfo.PrimaryIPMBAddr = (0x40+(g_BMCInfo.SlotID&0x1F))<<1;
- g_BMCInfo.SecondaryIPMBAddr = (0x40+(g_BMCInfo.SlotID&0x1F))<<1;
- }
- //init DevGUID
- g_BMCInfo.DeviceGUID[0] = 0x01;
- g_BMCInfo.DeviceGUID[1] = 0x01;
- g_BMCInfo.DeviceGUID[2] = 0x01;
- g_BMCInfo.DeviceGUID[3] = 0x01;
- g_BMCInfo.DeviceGUID[4] = 0x01;
- g_BMCInfo.DeviceGUID[5] = 0x01;
- g_BMCInfo.DeviceGUID[6] = 0x01;
- g_BMCInfo.DeviceGUID[7] = 0x01;
- g_BMCInfo.DeviceGUID[8] = 0x01;
- g_BMCInfo.DeviceGUID[9] = 0x01;
- g_BMCInfo.DeviceGUID[10] = 0x01;
- g_BMCInfo.DeviceGUID[11] = 0x01;
- g_BMCInfo.DeviceGUID[12] = 0x01;
- g_BMCInfo.DeviceGUID[13] = 0x01;
- g_BMCInfo.DeviceGUID[14] = 0x01;
- g_BMCInfo.DeviceGUID[15] = 0x01;
-
- g_BMCInfo.FwMajorVer = FW_VERSION_MAJOR;
- g_BMCInfo.FwMinorVer = FW_VERSION_MINOR;
- g_BMCInfo.SendMsgSeqNum = 0;
-
- // g_BMCInfo.OemFlags.BladeWorkMode = BLADE_IPMC;
- // g_BMCInfo.OemFlags.chassisManageFnEnable = 0;
- // g_BMCInfo.OemFlags.thisBladeIndex = 0;
- // g_BMCInfo.OemFlags.bladeStatus = 1; //0: not present, 1: normal, 2: error, others: reserved.
-
- g_BMCInfo.HealthLevel = SENSOR_STATUS_NORMAL;
- g_BMCInfo.SensorSharedMem.SensorTick= 0;
- g_BMCInfo.SenConfig.PowerOnTick = 0;
- g_BMCInfo.SenConfig.SysResetTick = 0;
- g_BMCInfo.CurTimerTick = 0;
- g_BMCInfo.CurTimerSecond = 0;
- g_BMCInfo.BootValidMinutes = 0;
- g_BMCInfo.m_Lan_SetInProgress = 0;
- g_BMCInfo.BootValidMinutesCount = 0;
- return 0;
- }
- int InitTimerTaskTbl(void)
- {
- printf("InitTimerTaskTbl...\n");
- g_BMCInfo.TimerTaskTblSize = 2;
- memcpy(g_BMCInfo.TimerTaskTbl, m_TimerTaskTbl, sizeof(TimerTaskTbl_T)*g_BMCInfo.TimerTaskTblSize);
- }
- int Init_SessionTbl(void)
- {
- printf("Init_SessionTbl...\n");
- g_BMCInfo.SessionHandle = 0;
- g_BMCInfo.UDSSessionHandle = 0;
- g_BMCInfo.IpmiConfig.MaxSession = 10;
- g_BMCInfo.IpmiConfig.SessionTimeOut = 10; //10s
- g_BMCInfo.IpmiConfig.SendMsgTimeout = 10; //10s
-
- /*Allocating Memory to hold session Table informations */
- g_BMCInfo.SessionTblInfo.SessionTbl = (SessionInfo_T *) malloc(sizeof(SessionInfo_T)*( g_BMCInfo.IpmiConfig.MaxSession + 1));
- if(g_BMCInfo.SessionTblInfo.SessionTbl == NULL)
- {
- printf("Error in allocating memory for SessionTbl \n");
- return 1;
- }
- g_BMCInfo.SessionTblInfo.Count = 0;
- /*Initialize the Session Table memory */
- memset(g_BMCInfo.SessionTblInfo.SessionTbl,0,sizeof(SessionInfo_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
- /*Allocating Memory to hold UDS session Table informations */
- g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl = (UDSSessionTbl_T *) malloc(sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
- if(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl == NULL)
- {
- printf("Error in allocating memory for SessionTbl \n");
- return 1;
- }
- g_BMCInfo.UDSSessionTblInfo.SessionCount = 0;
- /*Initialize the UDS Session Table memory */
- memset(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl,0,sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
- }
- const char FirstPowerOnStr[] = "First power on the bmc";
- int Init_IPMI_FRU_SDR_SEL(void)
- {
- int i;
- uint32_t sdrSize =
- sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
- uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
- uint8_t* pSDR = NULL;
- uint8_t* pSEL = NULL;
-
-
- g_BMCInfo.pSDR = malloc(sdrSize);
- if((g_BMCInfo.pSDR == NULL) && (sdrSize != 0))
- {
- printf("g_BMCInfo.pSDR Malloc failed!\r\n");
- }
- g_BMCInfo.pSEL = malloc(selSize);
- if((g_BMCInfo.pSEL == NULL) && (selSize != 0))
- {
- printf("g_BMCInfo.pSEL Malloc failed!\r\n");
- }
-
- /************** Sensor History ****************/
- memset(gSensorHistoryInfo, 0, sizeof(SensorHistoryInfo_T)*SENSOR_NUMBERS);
- //FlushSensorHistoryToFlash();
-
- GetIPMIFromFlash();
- if(strncmp(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr)) != 0)
- {
- //first power on
- printf("\n\n*** BMC first power on! ***\n\n");
- /************************** Init IPMI ******************************/
- memcpy(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr));
-
- g_BMCInfo.IpmiConfig.SerialIfcSupport = SERIAL_IFC_SUPPORT;
- g_BMCInfo.IpmiConfig.SerialTerminalSupport = SERIAL_TERMINAL_SUPPORT;
- g_BMCInfo.IpmiConfig.LANIfcSupport = LAN_IFC_SUPPORT;
- g_BMCInfo.IpmiConfig.SYSIfcSupport = SYS_IFC_SUPPORT;
- g_BMCInfo.IpmiConfig.GrpExtnSupport = GROUP_EXTERN_SUPPORT;
- g_BMCInfo.IpmiConfig.UDSIfcSupport = UDS_IFC_SUPPORT;
- g_BMCInfo.IpmiConfig.ChassisTimerInterval = CHASSIS_TIMER_INTERVAL;
- g_BMCInfo.IpmiConfig.PowerCycleInterval = PWR_CYCLE_INTERVAL;
- g_BMCInfo.IpmiConfig.FanControlInterval = FAN_CONTROL_INTERVAL;
- g_BMCInfo.IpmiConfig.RearmSetSensorThreshold = REARM_SET_SENSOR_THRESHOLD;
- g_BMCInfo.IpmiConfig.SELTimeUTCOffset = 8*60;
- g_BMCInfo.IpmiConfig.totalRunTimeCount = 0;
-
- //IPMB
- g_BMCInfo.IpmiConfig.PrimaryIPMBSupport = PRIMARY_IPMB_SUPPORT;
- g_BMCInfo.IpmiConfig.SecondaryIPMBSupport = SECONDARY_IPMB_SUPPORT;
- g_BMCInfo.IpmiConfig.PrimaryIPMBBus = PRIMARY_IPMB_BUS;
- g_BMCInfo.IpmiConfig.SecondaryIPMBBus = SECONDARY_IPMB_BUS;
-
- //Init FRU
- memcpy(&g_BMCInfo.FRU, &Default_FRUData, sizeof(OemFRUData_T));
-
- /************************ Init SDR *************************************/
- pSDR = g_BMCInfo.pSDR;
- //init SDR repository header
- ((SDRRepository_T*)pSDR)->Signature[0] = 0x00;
- ((SDRRepository_T*)pSDR)->Signature[1] = 0x11;
- ((SDRRepository_T*)pSDR)->Signature[2] = 0x22;
- ((SDRRepository_T*)pSDR)->Signature[3] = 0x33;
-
- ((SDRRepository_T*)pSDR)->NumRecords = SENSOR_NUMBERS + 1;
- ((SDRRepository_T*)pSDR)->Size = sdrSize;
- ((SDRRepository_T*)pSDR)->AddTimeStamp = 0;
- ((SDRRepository_T*)pSDR)->EraseTimeStamp = 0;
- //init MgmtCtrlrDevLocator SDR
- pSDR += sizeof(SDRRepository_T);
- ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Valid = 1;
- ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Len = sizeof(HdrMgmtCtrlrDevLocator_T);
- memcpy(&(((HdrMgmtCtrlrDevLocator_T*)pSDR)->MgmtCtrlrDevLocator), &bmc_sdr, sizeof(MgmtCtrlrDevLocator_T));
- //init FullSensorRec SDR
- pSDR += sizeof(HdrMgmtCtrlrDevLocator_T);
- for(i=0;i<SENSOR_NUMBERS;i++)
- {
- ((HdrFullSensorRec_T*)pSDR)->Valid = 1;
- ((HdrFullSensorRec_T*)pSDR)->Len = sizeof(HdrFullSensorRec_T);
- memcpy(&(((HdrFullSensorRec_T*)pSDR)->FullSensorRec), &full_sdr_tbl[i], sizeof(FullSensorRec_T));
- pSDR += sizeof(HdrFullSensorRec_T);
- }
- g_BMCInfo.IpmiConfig.SELConfig.SelReservationID = 0;;
- g_BMCInfo.IpmiConfig.SELConfig.LastEvtTS = 0;
- g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecordID = 0;
- g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecOffset = 0;
- g_BMCInfo.IpmiConfig.SELConfig.PartialAdd = 0;
- g_BMCInfo.IpmiConfig.SELConfig.SenMonSELFlag = 0;
- g_BMCInfo.IpmiConfig.SELConfig.MaxSELRecord = MAX_SEL_RECORD;
- // g_BMCInfo.SELConfig.RsrvIDCancelled = FALSE;
- g_BMCInfo.IpmiConfig.SELConfig.SELOverFlow = FALSE;
- g_BMCInfo.IpmiConfig.SELConfig.selalmostfull = 0;
-
- memset(g_BMCInfo.UserInfoTbl, 0x0, sizeof(UserInfo_T)*MAX_USER_NUM);
- g_BMCInfo.UserInfoTbl[2].UserId = 3;
- strcpy(g_BMCInfo.UserInfoTbl[2].UserName, "admin");
- strcpy(g_BMCInfo.UserInfoTbl[2].UserPassword, "admin");
- g_BMCInfo.UserInfoTbl[2].UserStatus = TRUE;
- g_BMCInfo.CurrentNoUser = 1;
- g_BMCInfo.pUserInfo = NULL;
-
- /************** Lan info ********************/
- //LAN地址
- LanInfo_T *pSetLanInfo = &g_BMCInfo.IpmiConfig.LanInfo[0];
- pSetLanInfo->IPAddr[0] = 192;
- pSetLanInfo->IPAddr[1] = 168;
- pSetLanInfo->IPAddr[2] = 1; //网段
- pSetLanInfo->IPAddr[3] = 120+g_BMCInfo.SlotID;
- pSetLanInfo->BroadCast[0] = 192;
- pSetLanInfo->BroadCast[1] = 168;
- pSetLanInfo->BroadCast[2] = 1; //网段
- pSetLanInfo->BroadCast[3] = 255;
- pSetLanInfo->NetMask[0] = 255;
- pSetLanInfo->NetMask[1] = 255;
- pSetLanInfo->NetMask[2] = 255;
- pSetLanInfo->NetMask[3] = 0;
- pSetLanInfo->DefaultGW[0] = pSetLanInfo->IPAddr[0];
- pSetLanInfo->DefaultGW[1] = pSetLanInfo->IPAddr[1];
- pSetLanInfo->DefaultGW[2] = pSetLanInfo->IPAddr[2];
- pSetLanInfo->DefaultGW[3] = 1;
- pSetLanInfo->MACAddr[0] = 0; //no default mac
- pSetLanInfo->MACAddr[1] = 0;
- pSetLanInfo->MACAddr[2] = 0;
- pSetLanInfo->MACAddr[3] = 0;
- pSetLanInfo->MACAddr[4] = 0;
- pSetLanInfo->MACAddr[5] = 0;
- FlushUserInfoTbl();
- UpdateFlash();
- }
- else
- {
- //Init FRU
- GetFRUFromFlash();
-
- //Init SDR
- GetSDRFromFlash();
-
- // //Init SEL
- // GetSELFromFlash();
- // ((SELRepository_T*)g_BMCInfo.pSEL)->SELRecord = (SELRec_T*)(g_BMCInfo.pSEL + sizeof(SELRepository_T));
-
- g_BMCInfo.IpmiConfig.SELConfig.SelReservationID = 0;;
- g_BMCInfo.IpmiConfig.SELConfig.LastEvtTS = 0;
- g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecordID = 0;
- g_BMCInfo.IpmiConfig.SELConfig.PartialAddRecOffset = 0;
- g_BMCInfo.IpmiConfig.SELConfig.PartialAdd = 0;
- g_BMCInfo.IpmiConfig.SELConfig.SenMonSELFlag = 0;
- g_BMCInfo.IpmiConfig.SELConfig.MaxSELRecord = MAX_SEL_RECORD;
- // g_BMCInfo.SELConfig.RsrvIDCancelled = FALSE;
- g_BMCInfo.IpmiConfig.SELConfig.SELOverFlow = FALSE;
- g_BMCInfo.IpmiConfig.SELConfig.selalmostfull = 0;
- //Init SensorHistory
- //GetSensorHistoryFromFlash();
- UpdateUserInfoTble();
- g_BMCInfo.CurrentNoUser = 0;
- for(i=0;i<MAX_USER_NUM;i++)
- {
- if((g_BMCInfo.UserInfoTbl[i].UserId != 0) && (g_BMCInfo.UserInfoTbl[i].UserStatus == TRUE))
- g_BMCInfo.CurrentNoUser++;
- }
- 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;
- g_BMCInfo.IpmiConfig.SDRConfig.TrackRecID = 0;
- g_BMCInfo.IpmiConfig.SDRConfig.IPMB_Seqnum = 0;
- g_BMCInfo.IpmiConfig.SDRConfig.PartAddbytes = 0;
- g_BMCInfo.IpmiConfig.SDRConfig.LatestRecordID = 0;
- g_BMCInfo.IpmiConfig.SDRConfig.NumMarkedRecords = 0;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.Version = 0x51;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.FreeSpace = 0xffff;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.AddTimeStamp = 0;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.EraseTimeStamp = 0;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.OpSupport = 0x23;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.NumAllocUnits = MAX_SENSOR_NUMBERS+1;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.AllocUnitSize = SDR_ALLOC_UNIT_SIZE;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.NumFreeAllocUnits = MAX_SENSOR_NUMBERS - SENSOR_NUMBERS;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.LargestFreeBlock = SDR_MAX_RECORD_SIZE;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryAllocInfo.MaxRecSize = SDR_MAX_RECORD_SIZE; //Maximum record size in allocation units
- g_BMCInfo.IpmiConfig.SDRConfig.SDRRAM = (SDRRepository_T*)g_BMCInfo.pSDR;
- g_BMCInfo.IpmiConfig.SDRConfig.RepositoryInfo.RecCt = ((SDRRepository_T*)g_BMCInfo.IpmiConfig.SDRConfig.SDRRAM)->NumRecords;
- g_BMCInfo.IpmiConfig.SDRConfig.SDRError = 0;
- g_BMCInfo.IpmiConfig.SDRConfig.ReservationID = 0;
-
- return 0;
- }
- int SetSysTime(uint32_t *timeSecond)
- {
- time_t tt;
- tt = *timeSecond;
- stime(&tt); //TODO:注意时区
- return 0;
- }
- long int GetSysTime(void)
- {
- time_t tt;
- time(&tt);
- //TODO: 注意时区
- //tt += 8*60*60; UTC+8
- return tt;
- }
- int PostEventMessage (uint8_t *EventMsg,uint8_t size)
- {
- uint8_t SelReq [sizeof(SELEventRecord_T)];
- uint8_t SelRes [sizeof(AddSELRes_T)];
- SELEventRecord_T* SelRecord = ( SELEventRecord_T*) SelReq;
- SelRecord->hdr.Type = 0x02;
- SelRecord->hdr.TimeStamp = GetSysTime ();
- memcpy (&SelRecord->body, EventMsg, size);
-
- LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
- return 0;
- }
- /*
- EventMsg共6个字节。
- */
- int PostOemEventMessage (uint8_t *EventMsg)
- {
- uint8_t SelReq [sizeof(SELEventRecord_T)];
- uint8_t SelRes [sizeof(AddSELRes_T)];
- SELEventRecord_T* SelRecord = ( SELEventRecord_T*) SelReq;
- SelRecord->hdr.Type = 0xC0; //storlead oem event Record ID
- SelRecord->hdr.TimeStamp = GetSysTime ();
- SelRecord->body.oemEventRecord.ManufacturerID[0] = 0x30;
- SelRecord->body.oemEventRecord.ManufacturerID[1] = 0x30;
- SelRecord->body.oemEventRecord.ManufacturerID[2] = 0x0f;
- memcpy (SelRecord->body.oemEventRecord.OEMDefined, EventMsg, 6);
-
- LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
- return 0;
- }
- uint8_t PDK_GetSlotID(void)
- {
- uint8_t SlotID = 0;
- // uint8_t check = 0;
- if(stm32_gpio_read(GA0_PORT, GA0_PIN) == GPIO_PIN_RESET)
- SlotID |= 0x01;
- if(stm32_gpio_read(GA1_PORT, GA1_PIN) == GPIO_PIN_RESET)
- SlotID |= 0x02;
- if(stm32_gpio_read(GA2_PORT, GA2_PIN) == GPIO_PIN_RESET)
- SlotID |= 0x04;
- if(stm32_gpio_read(GA3_PORT, GA3_PIN) == GPIO_PIN_RESET)
- SlotID |= 0x08;
- if(stm32_gpio_read(GA4_PORT, GA4_PIN) == GPIO_PIN_RESET)
- SlotID |= 0x10;
- // if(stm32_gpio_read(GAP_PORT, GAP_PIN) == GPIO_PIN_RESET)
- // SlotID |= 0x20;
- // int i;
- // for(i=0;i<6;i++)
- // check ^= (SlotID>>i)&0x01;
- // if(check == 0)
- // printf("Slot ID check error! GAP = %#x, GA[4:0] = %#x.\n", (SlotID>>5), (SlotID&0x1f));
- // return SlotID&0x1f;
- return SlotID;
- }
- uint8_t PDK_GetChassisID(void)
- {
- uint8_t ChassisID = 0;
- // if(stm32_gpio_read(RACKID0_PORT, RACKID0_PIN) == GPIO_PIN_SET)
- // ChassisID |= 0x01;
- // if(stm32_gpio_read(RACKID1_PORT, RACKID1_PIN) == GPIO_PIN_SET)
- // ChassisID |= 0x02;
- // if(stm32_gpio_read(RACKID2_PORT, RACKID2_PIN) == GPIO_PIN_SET)
- // ChassisID |= 0x04;
- // if(stm32_gpio_read(RACKID3_PORT, RACKID3_PIN) == GPIO_PIN_SET)
- // ChassisID |= 0x08;
- // if(stm32_gpio_read(RACKID4_PORT, RACKID4_PIN) == GPIO_PIN_SET)
- // ChassisID |= 0x10;
- // if(stm32_gpio_read(RACKID5_PORT, RACKID5_PIN) == GPIO_PIN_SET)
- // ChassisID |= 0x20;
- return ChassisID;
- }
- int PDK_PowerOffChassis(void)
- {
- printf("Api power off chassis\n");
- uint8_t EventMsg[6];
- EventMsg[0] = 1; //命令类1
- EventMsg[1] = 2; //命令,chassis
- EventMsg[2] = 2; //power off
- EventMsg[3] = 2; //命令来源:BMC CMD
- EventMsg[4] = 0; //Reserve
- EventMsg[5] = 0; //Reserve
- PostOemEventMessage (EventMsg);
- g_BMCInfo.PowerGoodFlag = 0;
- printf("Not support power control!\n");
- return 0;
- }
- int PDK_PowerOnChassis(void)
- {
- printf("power on chassis\n");
- uint8_t EventMsg[6];
- EventMsg[0] = 1; //命令类1
- EventMsg[1] = 2; //命令,chassis
- EventMsg[2] = 1; //power on
- EventMsg[3] = 2; //命令来源:BMC CMD
- EventMsg[4] = 0; //Reserve
- EventMsg[5] = 0; //Reserve
- PostOemEventMessage (EventMsg);
- g_BMCInfo.PowerGoodFlag = 1;
- printf("Not support power control!\n");
- }
- int PDK_SoftOffChassis(void)
- {
- //printf("soft off chassis\n");
- g_BMCInfo.PowerGoodFlag = 0;
- printf("Not support power control!\n");
- }
- int PDK_GetPowerStatus(void)
- {
- //TODO:
- // if(g_BMCInfo.PowerGoodFlag != retval)
- // {
- // uint8_t EventMsg[6];
- // EventMsg[0] = 2; //命令类2
- // EventMsg[1] = 1; //命令,power good
- // if(retval == 0) //power down
- // EventMsg[2] = 0; //power goes down
- // else
- // EventMsg[2] = 1; //power goes up
- // EventMsg[3] = 0; //命令来源:BMC CMD
- // EventMsg[4] = 0; //Reserve
- // EventMsg[5] = 0; //Reserve
- // PostOemEventMessage (EventMsg);
- // }
- return 1;
- }
- int PDK_PowerCycleChassis(void)
- {
- //printf("power cycle chassis\n");
- // uint8_t EventMsg[6];
- // EventMsg[0] = 1; //命令类1
- // EventMsg[1] = 2; //命令,chassis
- // EventMsg[2] = 4; //power cycle
- // EventMsg[3] = 2; //命令来源:BMC CMD
- // EventMsg[4] = 0; //Reserve
- // EventMsg[5] = 0; //Reserve
- // PostOemEventMessage (EventMsg);
- printf("Not support power control!\n");
- return 0;
- }
- int PDK_ResetChassis(void)
- {
- //printf("power reset chassis\n");
- // uint8_t EventMsg[6];
- // EventMsg[0] = 1; //命令类1
- // EventMsg[1] = 2; //命令,chassis
- // EventMsg[2] = 3; //reset
- // EventMsg[3] = 2; //命令来源:BMC CMD
- // EventMsg[4] = 0; //Reserve
- // EventMsg[5] = 0; //Reserve
- // PostOemEventMessage (EventMsg);
- printf("Not support power control!\n");
- return 0;
- }
- int PDK_DiagInterruptChassis(void)
- {
- printf("power diag chassis\n");
- }
- int PDK_FanControl(void)
- {
- ;
- }
- //设置IP地址
- /*
- * 函数名称 : int setip(char *ip)
- * 函数功能 : 设置系统IP地址
- * 参 数 :
- *char *ip :设置的IP地址,以点分十进制的字符串方式表示,如“192.168.0.5”
- * 返 回 值 : 0 : 成功 ; -1 : 失败
- */
- int setip(char *ip)
- {
- struct ifreq temp;
- struct sockaddr_in *addr;
- int fd = 0;
- int ret = -1;
- strcpy(temp.ifr_name, "eth0");
- if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
- {
- return -1;
- }
- addr = (struct sockaddr_in *)&(temp.ifr_addr);
- addr->sin_family = AF_INET;
- addr->sin_addr.s_addr = inet_addr(ip);
- ret = ioctl(fd, SIOCSIFADDR, &temp);
- close(fd);
- if(ret < 0)
- return -1;
- return 0;
- }
- //获取IP地址
- /*
- * 函数名称 : char * getip(char *ip_buf)
- * 函数功能 : 获取系統IP地址
- * 参 数 :
- *char *ip_buf :用来存放IP地址的内存空间
- * 返 回 值 : ip_buf : 存放IP地址的内存地址
- */
- char* getip(char *ip_buf)
- {
- struct ifreq temp;
- struct sockaddr_in *myaddr;
- int fd = 0;
- int ret = -1;
- strcpy(temp.ifr_name, "eth0");
- if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
- {
- return NULL;
- }
- ret = ioctl(fd, SIOCGIFADDR, &temp);
- close(fd);
- if(ret < 0)
- return NULL;
- myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
- strcpy(ip_buf, (char*)inet_ntoa(myaddr->sin_addr));
- return ip_buf;
- }
- char* getnetmask(char *netmask_buf)
- {
- struct ifreq temp;
- struct sockaddr_in *myaddr;
- int fd = 0;
- int ret = -1;
- strcpy(temp.ifr_name, "eth0");
- if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
- {
- return NULL;
- }
- ret = ioctl(fd, SIOCGIFNETMASK, &temp);
- close(fd);
- if(ret < 0)
- return NULL;
- myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
- strcpy(netmask_buf, (char*)inet_ntoa(myaddr->sin_addr));
- return netmask_buf;
- }
- char* getbroadcast(char *broadcast_buf)
- {
- struct ifreq temp;
- struct sockaddr_in *myaddr;
- int fd = 0;
- int ret = -1;
- strcpy(temp.ifr_name, "eth0");
- if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
- {
- return NULL;
- }
- ret = ioctl(fd, SIOCGIFBRDADDR, &temp);
- close(fd);
- if(ret < 0)
- return NULL;
- myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
- strcpy(broadcast_buf, (char*)inet_ntoa(myaddr->sin_addr));
- return broadcast_buf;
- }
- char* getmac(char *mac_buf)
- {
- struct ifreq temp;
- struct sockaddr_in *myaddr;
- int fd = 0;
- int ret = -1;
- strcpy(temp.ifr_name, "eth0");
- if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
- {
- return NULL;
- }
- if(ioctl(fd,SIOCGIFHWADDR,&temp)<0)
- {
- printf("Get mac address ioctl fail!\n");
- }
- else
- {
- sprintf(mac_buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
- (unsigned char)temp.ifr_hwaddr.sa_data[0],
- (unsigned char)temp.ifr_hwaddr.sa_data[1],
- (unsigned char)temp.ifr_hwaddr.sa_data[2],
- (unsigned char)temp.ifr_hwaddr.sa_data[3],
- (unsigned char)temp.ifr_hwaddr.sa_data[4],
- (unsigned char)temp.ifr_hwaddr.sa_data[5]);
- }
- close(fd);
- return mac_buf;
- }
- int getSensorHistory(uint8_t sensorNum, uint8_t *phistoryBuf)
- {
- int i =0;
- for(i=0;i<SENSOR_NUMBERS;i++)
- {
- if(gSensorHistoryInfo[i].SensorNum == sensorNum)
- {
- memcpy(phistoryBuf, gSensorHistoryInfo[i].History, HISTORY_DATA_SIZE);
- return 0;
- }
- }
-
- if(i >= SENSOR_NUMBERS)
- {
- printf("Warning: Can't find sensorNum!\n");
- return -1;
- }
- }
- pthread_mutex_t api_bridge_mutex;
- int API_BridgeInternal(MsgPkt_T* pReqPkt, MsgPkt_T* pResPkt, uint8_t DestAddr, int Channel)
- {
-
- IPMIMsgHdr_T* pReqMsgHdr;
- IPMIMsgHdr_T* pResMsgHdr;
- uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
- int RetVal;
- int fd_BridgeQue;
- uint8_t PBTbl;
-
- pthread_mutex_lock(&api_bridge_mutex);
-
- fd_BridgeQue = open (BRIDGE_QUEUE, O_RDWR);
- if(-1 == fd_BridgeQue)
- {
- printf("%s: Open %s fifo failed! \n", __FUNCTION__, BRIDGE_QUEUE);
- close(fd_BridgeQue);
- pthread_mutex_unlock(&api_bridge_mutex);
- return -1;
- }
-
- if(NULL != pReqPkt)
- {
- memcpy(&(pReqPkt->Data[sizeof(IPMIMsgHdr_T)]), pReqPkt->Data, pReqPkt->Size);
- pReqPkt->Size += sizeof(IPMIMsgHdr_T);
- pReqMsgHdr = (IPMIMsgHdr_T*)pReqPkt->Data;
- }
- else
- {
- printf("Warning: Message Packet to be bridged is NULL\r\n");
- close(fd_BridgeQue);
- pthread_mutex_unlock(&api_bridge_mutex);
- return -1;
- }
- if(NULL != pResPkt)
- {
- pResMsgHdr = (IPMIMsgHdr_T*)pResPkt->Data;
- }
- else
- {
- printf("Warning: Message Packet to be bridged is NULL\r\n");
- close(fd_BridgeQue);
- pthread_mutex_unlock(&api_bridge_mutex);
- return -1;
- }
- /* Format IPMI message header */
- pReqMsgHdr->ResAddr = DestAddr;
- pReqMsgHdr->NetFnLUN = pReqPkt->NetFnLUN;
- pReqMsgHdr->ChkSum = ~(pReqMsgHdr->ResAddr + pReqMsgHdr->NetFnLUN) + 1;
-
- if(Channel == PRIMARY_IPMB_CHANNEL)
- {
- pReqMsgHdr->ReqAddr = g_BMCInfo.PrimaryIPMBAddr; //PRIMARY_IPMB_ADDR;
- }
- else if(Channel == SECONDARY_IPMB_CHANNEL)
- {
- pReqMsgHdr->ReqAddr = g_BMCInfo.SecondaryIPMBAddr; //PRIMARY_IPMB_ADDR;
- }
- else
- {
- printf ("Warning: Invalid IPMB Channel: %d\r\n", Channel);
- pthread_mutex_unlock(&api_bridge_mutex);
- close(fd_BridgeQue);
- return -1;
- }
-
- pResPkt->NetFnLUN = pReqPkt->NetFnLUN + 0x40;
- pResPkt->Cmd = pReqPkt->Cmd;
-
- pReqMsgHdr->Cmd = pReqPkt->Cmd;
-
- pResMsgHdr->ResAddr = pReqMsgHdr->ReqAddr;
- pResMsgHdr->ChkSum = ~(pResMsgHdr->ResAddr + pResMsgHdr->NetFnLUN) + 1;
- pResMsgHdr->ReqAddr = pReqMsgHdr->ResAddr;
- pResMsgHdr->RqSeqLUN = pReqMsgHdr->RqSeqLUN;
- pResMsgHdr->Cmd = pReqMsgHdr->Cmd;
-
- PBTbl = (Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL ;
- /* Store in the table for response tracking */
- while(TRUE)
- {
- if (FALSE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used)
- {
- m_PendingBridgedResTbl[PBTbl][SeqNum].TimeOut = DEFAULT_TIMEOUT;
-
- m_PendingBridgedResTbl[PBTbl][SeqNum].ChannelNum = pReqPkt->Channel;
- m_PendingBridgedResTbl[PBTbl][SeqNum].OriginSrc = ORIGIN_INT_REQ;
- g_BMCInfo.SendMsgSeqNum = SeqNum;
- // printf("g_BMCInfo.SendMsgSeqNum %d\n", g_BMCInfo.SendMsgSeqNum);
- /* Format Sequence Number */
- pReqMsgHdr->RqSeqLUN = ((g_BMCInfo.SendMsgSeqNum) << 2) & 0xFC;
- pResMsgHdr->RqSeqLUN = pReqMsgHdr->RqSeqLUN + 0x40;
-
- memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, pReqMsgHdr, sizeof (IPMIMsgHdr_T));
- memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pResMsgHdr, sizeof (IPMIMsgHdr_T));
- m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ = fd_BridgeQue;
-
- /* Store Session ID for final response to the origin for KCS*/
- //m_PendingBridgedResTbl[SeqNum].SrcSessionID = pReqPkt->SessionID;
-
- m_PendingBridgedResTbl[PBTbl][SeqNum].Used = TRUE;
- //printf( "---> oemApi.c: Bridged message added index = %d.\n", SeqNum );
-
- break;
- }
- else
- {
- SeqNum = (SeqNum + 1) & 0x3F;
- if(SeqNum == g_BMCInfo.SendMsgSeqNum)
- {
- printf ("Warning: Pending Bridge Response Table is full \n");
- close(fd_BridgeQue);
- pthread_mutex_unlock(&api_bridge_mutex);
- return -1;
- }
- }
- }
-
- /* Format message packet */
- pReqPkt->Channel = Channel;
- pReqPkt->Param = PARAM_BRIDGE;
-
- /* Recalculate the checksum */
- pReqPkt->Data [pReqPkt->Size] = CalculateCheckSum2 (pReqPkt->Data, pReqPkt->Size);
- pReqPkt->Size++;
-
- if(Channel == PRIMARY_IPMB_CHANNEL)
- {
- pReqPkt->SrcQ = gFd_PrimaryIpmbIfcQ;
- }
- else if(Channel == SECONDARY_IPMB_CHANNEL)
- {
- pReqPkt->SrcQ = gFd_SecondaryIpmbIfcQ;
- }
- else
- {
- printf("Warning: Invalid Channel %d\n", Channel);
- close(fd_BridgeQue);
- pthread_mutex_unlock(&api_bridge_mutex);
- return -1;
- }
-
- /* Post Message to the bridge queue */
- if(0 != PostMsg(pReqPkt->SrcQ, pReqPkt) )
- {
- printf ("Warning: oemApi.c : Error posting message to Queue %p \n", pReqPkt->SrcQ);
- close(fd_BridgeQue);
- pthread_mutex_unlock(&api_bridge_mutex);
- return -1;
- }
-
- m_PendingBridgedResTbl[PBTbl][SeqNum].ResDataOk = 1;
-
- RetVal = GetMsg (fd_BridgeQue, pResPkt, 3); //3s
- // int i;
- // printf("Bridge recv: ");
- // for(i=0;i<pResPkt->Size;i++)
- // {
- // printf("%#x ", pResPkt->Data[i]);
- // }
- // printf("\n");
- //remove(BRIDGE_QUEUE);
- close(fd_BridgeQue);
- pthread_mutex_unlock(&api_bridge_mutex);
- if(RetVal != 0)
- {
- return -1;
- }
-
- memcpy(pResPkt->Data, &(pResPkt->Data[sizeof(IPMIMsgHdr_T)]), pResPkt->Size - sizeof(IPMIMsgHdr_T)-1);
- pResPkt->Size = pResPkt->Size - sizeof(IPMIMsgHdr_T)-1; //remove header & checksum2
- return 0;
- }
- /***************** Flash 保存非易失数据 *******************/
- int FlushSDRToFlash()
- {
- uint32_t writeLen = 0;
- uint32_t offset = 0;
- uint32_t sdrSize =
- sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
-
- pthread_mutex_lock(&Flash_Mutex);
- while(sdrSize > 0)
- {
- if(sdrSize > 4*1024)
- writeLen = 4*1024;
- else
- writeLen = sdrSize;
- sf_sector_erase(5, SDR_FLASH_ADDR+offset);
- sf_write(5, SDR_FLASH_ADDR+offset, g_BMCInfo.pSDR+offset, writeLen);
- offset += writeLen;
- sdrSize -= writeLen;
- }
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int GetSDRFromFlash()
- {
- uint32_t sdrSize =
- sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
-
- pthread_mutex_lock(&Flash_Mutex);
- sf_read(5, SDR_FLASH_ADDR, g_BMCInfo.pSDR, sdrSize);
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int FlushSELToFlash()
- {
- uint32_t writeLen = 0;
- uint32_t offset = 0;
- uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
- 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 > 256)
- writeLen = 256;
- else
- writeLen = selSize;
- 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);
- 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);
- memcpy(g_BMCInfo.pSEL, (uint8_t*)0x08040000, selSize);
- return 0;
- }
- int FlushIPMIToFlash()
- {
- uint32_t writeLen = 0;
- uint32_t offset = 0;
- uint32_t ipmiSize = sizeof(IPMIConfig_T);
- pthread_mutex_lock(&Flash_Mutex);
- while(ipmiSize > 0)
- {
- if(ipmiSize > 4*1024)
- writeLen = 4*1024;
- else
- writeLen = ipmiSize;
- sf_sector_erase(5, IPMI_CFG_FLASH_ADDR+offset);
- sf_write(5, IPMI_CFG_FLASH_ADDR+offset, ((uint8_t*)&g_BMCInfo.IpmiConfig)+offset, writeLen);
- offset += writeLen;
- ipmiSize -= writeLen;
- }
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int GetIPMIFromFlash()
- {
- uint32_t ipmiSize = sizeof(IPMIConfig_T);
- pthread_mutex_lock(&Flash_Mutex);
- sf_read(5, IPMI_CFG_FLASH_ADDR, (uint8_t*)&g_BMCInfo.IpmiConfig, ipmiSize);
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int FlushFRUToFlash()
- {
- uint32_t fruSize = sizeof(OemFRUData_T);
- pthread_mutex_lock(&Flash_Mutex);
- sf_sector_erase(5, FRU_FLASH_ADDR);
- sf_write(5, FRU_FLASH_ADDR, (uint8_t*)&g_BMCInfo.FRU, fruSize);
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int GetFRUFromFlash()
- {
- uint32_t fruSize = sizeof(OemFRUData_T);
- pthread_mutex_lock(&Flash_Mutex);
- sf_read(5, FRU_FLASH_ADDR, (uint8_t*)&g_BMCInfo.FRU, fruSize);
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int FlushSensorHistoryToFlash()
- {
- uint32_t writeLen = 0;
- uint32_t offset = 0;
- uint32_t sensorSize = SENSOR_NUMBERS*sizeof(SensorHistoryInfo_T);
- printf("FlushSensorHistoryToFlash()\n" );
- pthread_mutex_lock(&Flash_Mutex);
- while(sensorSize > 0)
- {
- if(sensorSize > 4*1024)
- writeLen = 4*1024;
- else
- writeLen = sensorSize;
- sf_sector_erase(5, SENSOR_HISTORY_FLASH_ADDR+offset);
- sf_write(5, SENSOR_HISTORY_FLASH_ADDR+offset, ((uint8_t*)gSensorHistoryInfo)+offset, writeLen);
- offset += writeLen;
- sensorSize -= writeLen;
- }
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int GetSensorHistoryFromFlash()
- {
- uint32_t sensorSize = SENSOR_NUMBERS*sizeof(SensorHistoryInfo_T);
- printf("GetSensorHistoryFromFlash()\n");
- pthread_mutex_lock(&Flash_Mutex);
- sf_read(5, SENSOR_HISTORY_FLASH_ADDR, (uint8_t*)gSensorHistoryInfo, sensorSize);
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int FlushUserInfoTbl(void)
- {
- pthread_mutex_lock(&Flash_Mutex);
- sf_sector_erase(5, USERTBL_FLASH_ADDR);
- sf_write(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int UpdateUserInfoTble(void)
- {
- pthread_mutex_lock(&Flash_Mutex);
- sf_read(5, USERTBL_FLASH_ADDR, (uint8_t*)g_BMCInfo.UserInfoTbl, sizeof(UserInfo_T)*MAX_USER_NUM);
- pthread_mutex_unlock(&Flash_Mutex);
- return 0;
- }
- int UpdateFlash(void)
- {
- FlushSDRToFlash();
- //FlushSELToFlash();
- FlushIPMIToFlash();
- FlushFRUToFlash();
- return 0;
- }
- int InitChannelTab(void)
- {
- int i;
- //primary IPMB channel
- g_BMCInfo.ChannelTab[0].ChannelNumber = 0;
- g_BMCInfo.ChannelTab[0].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
- g_BMCInfo.ChannelTab[0].ChannelMedium = 1; //IPMB, reference IPMIv2.0 Table 6-3
- g_BMCInfo.ChannelTab[0].SessionSupport = 0; //session less
- g_BMCInfo.ChannelTab[0].ActiveSession = 0;
- g_BMCInfo.ChannelTab[0].ProtocolVendorId[0] = 0x12;
- g_BMCInfo.ChannelTab[0].ProtocolVendorId[1] = 0x34;
- g_BMCInfo.ChannelTab[0].ProtocolVendorId[2] = 0x56;
- g_BMCInfo.ChannelTab[0].AuxiliaryInfo[0] = 0xff;
- g_BMCInfo.ChannelTab[0].AuxiliaryInfo[1] = 0xff;
- //LAN chennel
- g_BMCInfo.ChannelTab[1].ChannelNumber = 1;
- g_BMCInfo.ChannelTab[1].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
- g_BMCInfo.ChannelTab[1].ChannelMedium = 4; //802.3 LAN, reference IPMIv2.0 Table 6-3
- g_BMCInfo.ChannelTab[1].SessionSupport = 2; //muti session
- g_BMCInfo.ChannelTab[1].ActiveSession = 0;
- g_BMCInfo.ChannelTab[1].ProtocolVendorId[0] = 0x12;
- g_BMCInfo.ChannelTab[1].ProtocolVendorId[1] = 0x34;
- g_BMCInfo.ChannelTab[1].ProtocolVendorId[2] = 0x56;
- g_BMCInfo.ChannelTab[1].AuxiliaryInfo[0] = 0xff;
- g_BMCInfo.ChannelTab[1].AuxiliaryInfo[1] = 0xff;
- //Secondary IPMB channel
- g_BMCInfo.ChannelTab[2].ChannelNumber = 6;
- g_BMCInfo.ChannelTab[2].ChannelProtocol = 1;//Used for IPMB, serial/modem Basic Mode, and LAN.reference IPMIv2.0 Table 6-2
- g_BMCInfo.ChannelTab[2].ChannelMedium = 1; //IPMB, reference IPMIv2.0 Table 6-3
- g_BMCInfo.ChannelTab[2].SessionSupport = 0; //session less
- g_BMCInfo.ChannelTab[2].ActiveSession = 0;
- g_BMCInfo.ChannelTab[2].ProtocolVendorId[0] = 0x12;
- g_BMCInfo.ChannelTab[2].ProtocolVendorId[1] = 0x34;
- g_BMCInfo.ChannelTab[2].ProtocolVendorId[2] = 0x56;
- g_BMCInfo.ChannelTab[2].AuxiliaryInfo[0] = 0xff;
- g_BMCInfo.ChannelTab[2].AuxiliaryInfo[1] = 0xff;
- for(i=3;i<15;i++)
- {
- g_BMCInfo.ChannelTab[i].ChannelNumber = 0xf;
- }
- }
- ChannelInfo_T* getChannelInfo(uint8_t ChannelNum)
- {
- int i;
- for(i=0;i<15;i++)
- {
- if(g_BMCInfo.ChannelTab[i].ChannelNumber == ChannelNum)
- {
- return (ChannelInfo_T*)&g_BMCInfo.ChannelTab[i];
- }
- }
- return NULL;
- }
|