#include #include #include #include #include #include "pnlset2bin.h" #define CustomerLOGO 1 #define PanelSet_Header "PanelSet_Ascii_Version" #if 0 static long filelength(FILE * pFile) { long ret; long oldpos; oldpos = ftell(pFile); fseek(pFile, 0, SEEK_END); ret = ftell(pFile); fseek(pFile, oldpos, SEEK_SET); return ret; } #endif uint StrToHexNumber(char* szText, uint* pNumber, uint nMax) { uint i,nValue= 0; i= 0; while( i='0' && szText[i]<= '9' ) nValue= (nValue<<4) | (szText[i]-'0'); else if( szText[i] >='a' && szText[i]<= 'f' ) nValue= (nValue<<4) | (szText[i]-'a'+10); else if( szText[i] >='A' && szText[i]<= 'F' ) nValue= (nValue<<4) | (szText[i]-'A'+10); else break; i++; } *pNumber= nValue; return i; } uint StrToDecimalNumber(char* szText, uint* pNumber, uint nMax) { uint i,nValue= 0; i= 0; while( i='0' && szText[i]<= '9' ) nValue= (nValue*10) + (szText[i]-'0'); else break; i++; } *pNumber= nValue; return i; } bool GetBit(const unsigned char pByte[], uint nBitIndex) { uint nQuot,nRem; nQuot= nBitIndex >> 3; nRem= nBitIndex & 0x7; return (pByte[nQuot] >> nRem) & 0x01; } uint GetBitData(const unsigned char pByte[], uint nBitIndex, uint nBitWidth) { uint i,nBit,nValue= 0; for(i=0; i> 3; nRem= nBitIndex & 0x7; nMask= (1 << nRem) & 0xff; if( bValue ) { pByte[nQuot]|= nMask; } else { nMask= ~nMask; pByte[nQuot]&= nMask; } } void SetBitData(unsigned char pByte[], uint nBitIndex, uint nBitWidth, uint nData) { uint i; for(i=0; i>i)&0x1); } void PrintUsage(void) { fprintf(stderr, "\n"); fprintf(stderr, "pnlset2bin v0.01\n"); fprintf(stderr, "Usage: pnlset2bin inputINIfile outputBINfile\n"); fprintf(stderr, "Example: pnlset2bin panelset.ini panelset.bin\n"); fprintf(stderr, "\n"); } int cmN_getFileOneLineDataAscii(FILE *fpIn,char *pData, int maxLen) { //return is get len not add null int i; char line[maxLen]; while(fgets(line, maxLen, fpIn)){ if(strncmp(line, PanelSet_Header, strlen(PanelSet_Header)) == 0) break; } for(i=0; i= maxLen) //end size { return i; // not add null } if(line[i] == 0x0A )//line end ** OK { pData[i] = 0x00; return i; } if((isascii(line[i]))&&(!iscntrl(line[i]))) { pData[i] = line[i]; } else { pData[i] = 0x20; } } return 0; // fail } int cmN_getLineAsciiData_PanelSetVer2(char *pInData, char *pOutData, int Len) { //return is get len and add null int i, num, start; int headLen; headLen = (int)strlen(PANELSET_VERSION2_NAME_HEADER); if (!strncmp(PANELSET_VERSION2_NAME_HEADER,pInData, headLen)) { num = 0; start = 0; for(i=headLen; i=PANELSET_VERSION2_NAME_MAX_LEN) { break; } } //move 0x20 at last for(i=(num - 1); i>= 0;i--) { if(pOutData[i] != 0x20) { if(i == 0) { return 1;//fix all is empty } else { return (i+1); } } } } else { return 0; // fail } return 0; // fail } #if 0 DWORD ini2bin(char* pInFile, char *pOutFile) { FILE *InFile,*OutFile; DWORD isFill = TRUE, isAdd = TRUE; //for many VIP merge //add MMIO int i, len, tmp, mmioflag=0, optionflag=0; DWORD tempDW = 0; BRVIP_FLASH BrvipFlash; char ptr[0x100]; unsigned int data,data1,data2,data3; unsigned long ULData[2000],ULSize; char pExist[PB_MAX_END];//for check only memset(pExist, 0, sizeof(char)); InFile = fopen(pInFile,"r"); if (InFile == NULL) { fprintf(stderr, "Can't open ini file\n"); return FALSE; } if(isAdd == TRUE) { OutFile = fopen(pOutFile,"ab"); } else { OutFile = fopen(pOutFile,"wb"); } if (OutFile == NULL) { fclose(InFile); fprintf(stderr, "Can't open will write file\n"); return FALSE; } int mergeToSize;//should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add mergeToSize = PANELSET_SIZE; //--2k //; 0x2000=8k;//should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add //---------- for isAdd fill to 8K if( (isFill == TRUE)&&(isAdd) ) { DWORD fileLen, fillLen; fileLen = filelength(OutFile); if(fileLen % PANELSET_SIZE) //---by each size #1 { if( PANELSET_SIZE > 0 ) { int range = mergeToSize;// should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add fillLen = range -(fileLen & (range-1)); } else { fillLen = 0; } fseek( OutFile, 0, SEEK_END); for(i=0; i< fillLen ;i++) { fputc(0xFF,OutFile); } } //fclose(OutFile); } //---------- //?? does need to init "BrvipFlash memset(&BrvipFlash, 0, sizeof(BRVIP_FLASH));//not init value is diff linux 0 windows CC //Reserve01 and Reserve02 //----- ver => tmp = 100; i = cmN_getFileOneLineDataAscii(InFile,ptr, tmp); len = cmN_getLineAsciiData_PanelSetVer2(ptr, ptr+tmp, i); memset(ptr, 0, PANELSET_VERSION2_NAME_MAX_LEN); memcpy(ptr , ptr+tmp, len); if(len == 0) { fclose(InFile); fclose(OutFile); fprintf(stderr, "Error ! \n First line must be PanelSet_Ascii_Version\n"); return FALSE; } for(i=0; i< PANELSET_VERSION2_NAME_MAX_LEN;i++) { BrvipFlash.ScalerRegister.VersionOfAscii_20[i] = ptr[i]; } //----- ver <= //start fill //source from Ics 172.18.252.142\sis1259\brvip\work\utility\utility.c+flash.h while (fscanf(InFile,"%s",ptr) != EOF) { if (!strcmp("[MMIO0]",ptr)) fgetpos(InFile, (fpos_t*)&mmioflag); if (0 != mmioflag && !optionflag) { if (0 == strstr(ptr, "OffsetLast0x14=")) continue; else { optionflag = 1; sscanf(ptr, "OffsetLast0x14=%d", (int*)&tempDW); } } if (EOF == fscanf(InFile," %x\n",&data)) break; if (!strcmp("PanelHorizontalEnd",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalEnd = data; pExist[PB_PanelHorizontalEnd] = 1; } else if (!strcmp("PanelVerticalEnd",ptr)) { BrvipFlash.PanelParameter.PanelVerticalEnd = data; pExist[PB_PanelVerticalEnd] = 1; } else if (!strcmp("PanelHorizontalSyncStart",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalSyncStart = (unsigned char)data; pExist[PB_PanelHorizontalSyncStart] = 1; } else if (!strcmp("PanelHorizontalSyncEnd",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalSyncEnd = (unsigned char)data; pExist[PB_PanelHorizontalSyncEnd] = 1; } else if (!strcmp("PanelVerticalSyncStart",ptr)) { BrvipFlash.PanelParameter.PanelVerticalSyncStart = (unsigned char)data; pExist[PB_PanelVerticalSyncStart] = 1; } else if (!strcmp("PanelVerticalSyncEnd",ptr)) { BrvipFlash.PanelParameter.PanelVerticalSyncEnd = (unsigned char)data; pExist[PB_PanelVerticalSyncEnd] = 1; } else if (!strcmp("PanelVerticalMaxEnd",ptr)) { BrvipFlash.PanelParameter.PanelVerticalMaxEnd = (unsigned short)data; pExist[PB_PanelVerticalMaxEnd] = 1; } else if (!strcmp("PanelHorizontalDisplayStart",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalDisplayStart = data; pExist[PB_PanelHorizontalDisplayStart] = 1; } else if (!strcmp("PanelVerticalDisplayStart",ptr)) { BrvipFlash.PanelParameter.PanelVerticalDisplayStart = data; pExist[PB_PanelVerticalDisplayStart] = 1; } else if (!strcmp("PanelHorizontalDisplayEnd",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalDisplayEnd = data; pExist[PB_PanelHorizontalDisplayEnd] = 1; } else if (!strcmp("PanelVerticalDisplayEnd",ptr)) { BrvipFlash.PanelParameter.PanelVerticalDisplayEnd = data; pExist[PB_PanelVerticalDisplayEnd] = 1; } else if (!strcmp("PanelBlueOverScan",ptr)) { BrvipFlash.PanelParameter.PanelBlueOverScan = (unsigned char)data; pExist[PB_PanelBlueOverScan] = 1; } else if (!strcmp("PanelGreenOverScan",ptr)) { BrvipFlash.PanelParameter.PanelGreenOverScan = (unsigned char)data; pExist[PB_PanelGreenOverScan] = 1; } else if (!strcmp("PanelRedOverScan",ptr)) { BrvipFlash.PanelParameter.PanelRedOverScan = (unsigned char)data; pExist[PB_PanelRedOverScan] = 1; } else if (!strcmp("DpyHorizontalDisplayStart",ptr)) { BrvipFlash.DisplayPosition.DpyHorizontalDisplayStart = data; pExist[PB_DpyHorizontalDisplayStart] = 1; } else if (!strcmp("DpyVerticalDisplayStart",ptr)) { BrvipFlash.DisplayPosition.DpyVerticalDisplayStart = data; pExist[PB_DpyVerticalDisplayStart] = 1; } else if (!strcmp("DpyHorizontalDisplayEnd",ptr)) { BrvipFlash.DisplayPosition.DpyHorizontalDisplayEnd = data; pExist[PB_DpyHorizontalDisplayEnd] = 1; } else if (!strcmp("DpyVerticalDisplayEnd",ptr)) { BrvipFlash.DisplayPosition.DpyVerticalDisplayEnd = data; pExist[PB_DpyVerticalDisplayEnd] = 1; } else if (!strcmp("DpyOffset",ptr)) { BrvipFlash.DisplayPosition.DpyOffset = (unsigned char)data; pExist[PB_DpyOffset] = 1; } else if (!strcmp("DpySize",ptr)) { BrvipFlash.DisplayPosition.DpySize = (unsigned char)data; pExist[PB_DpySize] = 1; } else if (!strcmp("DpyLine",ptr)) { BrvipFlash.DisplayPosition.DpyLine = data; pExist[PB_DpyLine] = 1; } else if (!strcmp("Version",ptr)) { BrvipFlash.Version = data; pExist[PB_Version] = 1; } else if (!strcmp("DeviceID",ptr)) { BrvipFlash.DeviceID = (unsigned short)data; pExist[PB_DeviceID] = 1; } else if (!strcmp("VendorID",ptr)) { BrvipFlash.VendorID = (unsigned short)data; pExist[PB_VendorID] = 1; } else if (!strcmp("Dpy00",ptr)) { BrvipFlash.Dpy00 = data; pExist[PB_Dpy00] = 1; } else if (!strcmp("Dpy20",ptr)) { BrvipFlash.Dpy20 = data; pExist[PB_Dpy20] = 1; } else if (!strcmp("Before_MMIOAddress",ptr)) { BrvipFlash.Before_MMIOAddress = data; pExist[PB_Before_MMIOAddress] = 1; } else if (!strcmp("VIPAddress",ptr)) { BrvipFlash.VIPAddress = data; pExist[PB_VIPAddress] = 1; } else if (!strcmp("After_MMIOAddress",ptr)) { BrvipFlash.After_MMIOAddress = data; pExist[PB_After_MMIOAddress] = 1; } else if (!strcmp("SlrReset",ptr)) {; BrvipFlash.ScalerRegister.SlrReset = data; pExist[PB_SlrReset] = 1; } else if (!strcmp("SlrConfig",ptr)) { BrvipFlash.ScalerRegister.SlrConfig = data; pExist[PB_SlrConfig] = 1; } else if (!strcmp("SlrHorizontalFactor",ptr)) { BrvipFlash.ScalerRegister.SlrHorizontalFactor = data; pExist[PB_SlrHorizontalFactor] = 1; } else if (!strcmp("SlrVerticalFactor",ptr)) { BrvipFlash.ScalerRegister.SlrVerticalFactor = data; pExist[PB_SlrVerticalFactor] = 1; } else if (!strcmp("SlrVerticalDown",ptr)) { BrvipFlash.ScalerRegister.SlrVerticalDown = data; pExist[PB_SlrVerticalDown] = 1; } /* else if (!strcmp("SlrLeft",ptr)) { BrvipFlash.ScalerRegister.SlrLeft = data; pExist[PB_SlrLeft] = 1; } else if (!strcmp("SlrRight",ptr)) { BrvipFlash.ScalerRegister.SlrRight = data; pExist[PB_SlrRight] = 1; } else if (!strcmp("SlrLeft0",ptr)) { BrvipFlash.ScalerRegister.SlrLeft0 = data; pExist[PB_SlrLeft0] = 1; } else if (!strcmp("SlrRight0",ptr)) { BrvipFlash.ScalerRegister.SlrRight0 = data; pExist[PB_SlrRight0] = 1; } else if (!strcmp("SlrHorizontalFactor0",ptr)) { BrvipFlash.ScalerRegister.SlrHorizontalFactor0 = data; pExist[PB_SlrHorizontalFactor0] = 1; } */ else if (!strcmp("SlrLine",ptr)) { BrvipFlash.ScalerRegister.SlrLine = data; pExist[PB_SlrLine] = 1; } else if (!strcmp("SlrInc",ptr)) { BrvipFlash.ScalerRegister.SlrInc = data; pExist[PB_SlrInc] = 1; } else if (!strcmp("Gpio_15",ptr)) { BrvipFlash.Gpio_15 = data; pExist[PB_Gpio_15] = 1; } else if (!strcmp("Gpio_16",ptr)) { BrvipFlash.Gpio_16 = data; pExist[PB_Gpio_16] = 1; } else if (!strcmp("PanelBackLight_GPIOPin",ptr)) { BrvipFlash.PanelBackLight_GPIOPin = (unsigned char)data; pExist[PB_PanelBackLight_GPIOPin] = 1; } else if (!strcmp("PanelPower_GPIOPin",ptr)) { BrvipFlash.PanelPower_GPIOPin = (unsigned char)data; pExist[PB_PanelPower_GPIOPin] = 1; } else if (!strcmp("PanelBackLight_ActiveValue",ptr)) { BrvipFlash.PanelBackLight_ActiveValue = (unsigned char)data; pExist[PB_PanelBackLight_ActiveValue] = 1; } else if (!strcmp("PanelPower_ActiveValue",ptr)) { BrvipFlash.PanelPower_ActiveValue = (unsigned char)data; pExist[PB_PanelPower_ActiveValue] = 1; } else if (!strcmp("LCDBackLightOrder",ptr)) { BrvipFlash.LCDBackLightOrder = (DWORD)data; pExist[PB_LCDBackLightOrder] = 1; } else if (!strcmp("LCDBackLight_OtherFrq",ptr)) { BrvipFlash.LCDBackLight_OtherFrq = (DWORD)data; pExist[PB_LCDBackLight_OtherFrq] = 1; } else if (!strcmp("LCDBackLightMap_00",ptr)) { BrvipFlash.LCDBackLightMap_00 = (DWORD)data; pExist[PB_LCDBackLightMap_00] = 1; } else if (!strcmp("LCDBackLightMap_01",ptr)) { BrvipFlash.LCDBackLightMap_01 = (DWORD)data; pExist[PB_LCDBackLightMap_01] = 1; } else if (!strcmp("LCDBackLightMap_02",ptr)) { BrvipFlash.LCDBackLightMap_02 = (DWORD)data; pExist[PB_LCDBackLightMap_02] = 1; } else if (!strcmp("LCDBackLightMap_03",ptr)) { BrvipFlash.LCDBackLightMap_03 = (DWORD)data; pExist[PB_LCDBackLightMap_03] = 1; } else if (!strcmp("LCDBackLightMap_04",ptr)) { BrvipFlash.LCDBackLightMap_04 = (DWORD)data; pExist[PB_LCDBackLightMap_04] = 1; } else if (!strcmp("LCDBackLightMap_05",ptr)) { BrvipFlash.LCDBackLightMap_05 = (DWORD)data; pExist[PB_LCDBackLightMap_05] = 1; } else if (!strcmp("LCDBackLightMap_06",ptr)) { BrvipFlash.LCDBackLightMap_06 = (DWORD)data; pExist[PB_LCDBackLightMap_06] = 1; } else if (!strcmp("LCDBackLightMap_07",ptr)) { BrvipFlash.LCDBackLightMap_07 = (DWORD)data; pExist[PB_LCDBackLightMap_07] = 1; } else if (!strcmp("LCDBackLightMap_08",ptr)) { BrvipFlash.LCDBackLightMap_08 = (DWORD)data; pExist[PB_LCDBackLightMap_08] = 1; } else if (!strcmp("LCDBackLightMap_09",ptr)) { BrvipFlash.LCDBackLightMap_09 = (DWORD)data; pExist[PB_LCDBackLightMap_09] = 1; } else if (!strcmp("LCDBackLightMap_10",ptr)) { BrvipFlash.LCDBackLightMap_10 = (DWORD)data; pExist[PB_LCDBackLightMap_10] = 1; } else if (!strcmp("LCDBackLightMap_11",ptr)) { BrvipFlash.LCDBackLightMap_11 = (DWORD)data; pExist[PB_LCDBackLightMap_11] = 1; } else if (!strcmp("LCDBackLightMap_12",ptr)) { BrvipFlash.LCDBackLightMap_12 = (DWORD)data; pExist[PB_LCDBackLightMap_12] = 1; } else if (!strcmp("LCDBackLightMap_13",ptr)) { BrvipFlash.LCDBackLightMap_13 = (DWORD)data; pExist[PB_LCDBackLightMap_13] = 1; } else if (!strcmp("LCDBackLightMap_14",ptr)) { BrvipFlash.LCDBackLightMap_14 = (DWORD)data; pExist[PB_LCDBackLightMap_14] = 1; } else if (!strcmp("LogoType",ptr)) { BrvipFlash.LogoType = (DWORD)data; pExist[PB_LogoType] = 1; } else if (!strcmp("LogoSize",ptr)) { BrvipFlash.LogoSize = (DWORD)data; pExist[PB_LogoSize] = 1; } else if (!strcmp("PanelBackLight_OffdelayTime",ptr)) { BrvipFlash.PanelBackLight_OffdelayTime = (DWORD)data; pExist[PB_PanelBackLight_OffdelayTime] = 1; } else if (!strcmp("PanelBackPower_OffdelayTime",ptr)) { BrvipFlash.PanelBackPower_OffdelayTime = (DWORD)data; pExist[PB_PanelBackPower_OffdelayTime] = 1; } } fseek(InFile, mmioflag, SEEK_SET); //BrvipFlash.Before_MMIOAddress = 0xbc0b0000+sizeof(BRVIP_FLASH); 07/03/02008 David. BrvipFlash.Before_MMIOAddress = BR_ADDR_VIP+sizeof(BRVIP_FLASH); BrvipFlash.After_MMIOAddress = BrvipFlash.Before_MMIOAddress; ULSize = 0; //fwrite(&BrvipFlash,sizeof(BRVIP_FLASH),1,OutFile); while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF) { if ((data == 0xffffffff)||(data == 0x00000000)) { break; } //fwrite(&data,4,1,OutFile); //fwrite(&data1,4,1,OutFile); //fwrite(&data2,4,1,OutFile); //fwrite(&data3,4,1,OutFile); //BrvipFlash.After_MMIOAddress += 0x10; ULData[ULSize] = data; ULData[ULSize+1] = data1; ULData[ULSize+2] = data2; ULData[ULSize+3] = data3; ULSize += 4; } data=0xffffffff; //fwrite(&data,4,1,OutFile); //fwrite(&data,4,1,OutFile); //fwrite(&data,4,1,OutFile); //fwrite(&data,4,1,OutFile); //BrvipFlash.After_MMIOAddress += 0x10; ULData[ULSize] = data; ULData[ULSize+1] = data; ULData[ULSize+2] = data; ULData[ULSize+3] = data; ULSize += 4; BrvipFlash.After_MMIOAddress += (ULSize*4); printf("Before_MMIOAddress %x\n",(unsigned int)BrvipFlash.Before_MMIOAddress); printf("ULSize %x\n",(unsigned int)ULSize); printf("After_MMIOAddress %x\n",(unsigned int)BrvipFlash.After_MMIOAddress); fwrite(&BrvipFlash,sizeof(BRVIP_FLASH),1,OutFile); fwrite(ULData,4*ULSize,1,OutFile); while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF) { if ((data == 0xffffffff)||(data == 0x00000000)) { break; } fwrite(&data,4,1,OutFile); fwrite(&data1,4,1,OutFile); fwrite(&data2,4,1,OutFile); fwrite(&data3,4,1,OutFile); } data=0xffffffff; fwrite(&data,4,1,OutFile); fwrite(&data,4,1,OutFile); fwrite(&data,4,1,OutFile); fwrite(&data,4,1,OutFile); #ifdef SET_338_VIP while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF) { if ((data == 0xffffffff)||(data == 0x00000000)) { break; } fwrite(&data,4,1,OutFile); fwrite(&data1,4,1,OutFile); fwrite(&data2,4,1,OutFile); fwrite(&data3,4,1,OutFile); } data=0xffffffff; fwrite(&data,4,1,OutFile); fwrite(&data,4,1,OutFile); fwrite(&data,4,1,OutFile); fwrite(&data,4,1,OutFile); #endif //SET_338_VIP fclose(InFile); //--------- Option if (optionflag) { if(PANELSET_SIZE != PANELSET_NOW_USE_FIX_SIZE) { fprintf(stderr, "Error! \nPanelSet Size change !\n Driver must update for this"); fclose(OutFile); return FALSE; } DWORD fileLen, fillLen; fgetpos(OutFile,(fpos_t*)&fileLen); fileLen = fileLen % mergeToSize; if(fileLen >= (PANELSET_OPTION_D_OFFSET)) //0x7ec { fprintf(stderr, "Error! \nPanelSet Size change ! Over ox 7 e c\n Tool must update"); fclose(OutFile); return FALSE; } fillLen = (PANELSET_OPTION_D_OFFSET - fileLen); if(PANELSET_OPTION_D_OFFSET < fileLen) //avoid { fillLen = 0; fprintf(stderr, "Error! \nPanelSet Error size \n Tool must update"); } // OutFile = fopen(pOutFile,"ab"); for(i=0; i< fillLen ;i++) { fputc(0xFF,OutFile); } fwrite(&tempDW,4,1,OutFile); } //--------- fclose(OutFile); if(isFill == TRUE) { OutFile = fopen(pOutFile,"ab"); if (OutFile == NULL) { fprintf(stderr, "Can't open will write2 file\n"); return FALSE; } DWORD fileLen, fillLen; fileLen = filelength(OutFile); if(fileLen % PANELSET_SIZE) //---by each size #2 { #ifdef FILL_MEM_BY_INI if( PANELSET_SIZE > 0 ) { int range; if(isAdd) { range = mergeToSize;// should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add } else { range = PANELSET_SIZE;// general case } fillLen = range -(fileLen & (range-1)); } else fillLen = 0; #else fillLen = 0x1000 -(fileLen & 0x0fff); #endif //FILL_MEM_BY_INI fseek( OutFile, 0, SEEK_END); for(i=0; i< fillLen ;i++) { fputc(0xFF,OutFile); } } fclose(OutFile); } //check lost only for(i=0; i PANELSET_SIZE) { free(line_buff); free(outbuff); return -1; } memcpy(output_mem+mem_offset, outbuff, outbuff_idx); free(line_buff); free(outbuff); return outbuff_idx; } #endif /* return writed size if success else -1 */ int ini2binmem(char* pInFile, char *pOutData, int nBufSize) { FILE *InFile; int i, len, tmp, mmioflag=0; //, optionflag=0; int i2c0_fileoffset = 0, i2c1_fileoffset = 0; int writeOffset = 0; // DWORD tempDW = 0; BRVIP_FLASH BrvipFlash; char ptr[0x100]; unsigned int data,data1,data2,data3; unsigned long ULData[2000],ULSize; char pExist[PB_MAX_END];//for check only memset(pExist, 0, sizeof(char)); memset(pOutData, 0xFF, nBufSize); if (nBufSize < PANELSET_SIZE) { fprintf(stderr, "Out buffer is too small\n"); return -1; } InFile = fopen(pInFile,"r"); if (InFile == NULL) { fprintf(stderr, "Can't open ini file\n"); return -1; } /* int mergeToSize;//should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add mergeToSize = PANELSET_SIZE; //--2k //; 0x2000=8k;//should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add */ //?? does need to init "BrvipFlash memset(&BrvipFlash, 0, sizeof(BRVIP_FLASH));//not init value is diff linux 0 windows CC //Reserve01 and Reserve02 //----- ver => tmp = 100; i = cmN_getFileOneLineDataAscii(InFile,ptr, tmp); len = cmN_getLineAsciiData_PanelSetVer2(ptr, ptr+tmp, i); memset(ptr, 0, PANELSET_VERSION2_NAME_MAX_LEN); memcpy(ptr , ptr+tmp, len); if(len == 0) { fclose(InFile); fprintf(stderr, "Error ! \n First line must be PanelSet_Ascii_Version\n"); return -1; } for(i=0; i< PANELSET_VERSION2_NAME_MAX_LEN;i++) { BrvipFlash.ScalerRegister.VersionOfAscii_20[i] = ptr[i]; } //----- ver <= //start fill //source from Ics 172.18.252.142\sis1259\brvip\work\utility\utility.c+flash.h while (fscanf(InFile,"%s",ptr) != EOF) { if (!strcmp("[MMIO0]",ptr)) fgetpos(InFile, (fpos_t*)&mmioflag); if (!strcmp("[I2C0]",ptr)) fgetpos(InFile, (fpos_t*)&i2c0_fileoffset); if (!strcmp("[I2C1]",ptr)) fgetpos(InFile, (fpos_t*)&i2c1_fileoffset); #if 0 //gaia, 2013.05.02 ya! i don't know what is this.. if (0 != mmioflag && !optionflag) { if (0 == strstr(ptr, "OffsetLast0x14=")) continue; else { optionflag = 1; sscanf(ptr, "OffsetLast0x14=%d", (int*)&tempDW); } } #endif if (EOF == fscanf(InFile," %x\n",&data)) break; if (!strcmp("PanelHorizontalEnd",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalEnd = data; pExist[PB_PanelHorizontalEnd] = 1; } else if (!strcmp("PanelVerticalEnd",ptr)) { BrvipFlash.PanelParameter.PanelVerticalEnd = data; pExist[PB_PanelVerticalEnd] = 1; } else if (!strcmp("PanelHorizontalSyncStart",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalSyncStart = (unsigned char)data; pExist[PB_PanelHorizontalSyncStart] = 1; } else if (!strcmp("PanelHorizontalSyncEnd",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalSyncEnd = (unsigned char)data; pExist[PB_PanelHorizontalSyncEnd] = 1; } else if (!strcmp("PanelVerticalSyncStart",ptr)) { BrvipFlash.PanelParameter.PanelVerticalSyncStart = (unsigned char)data; pExist[PB_PanelVerticalSyncStart] = 1; } else if (!strcmp("PanelVerticalSyncEnd",ptr)) { BrvipFlash.PanelParameter.PanelVerticalSyncEnd = (unsigned char)data; pExist[PB_PanelVerticalSyncEnd] = 1; } else if (!strcmp("PanelVerticalMaxEnd",ptr)) { BrvipFlash.PanelParameter.PanelVerticalMaxEnd = (unsigned short)data; pExist[PB_PanelVerticalMaxEnd] = 1; } else if (!strcmp("PanelHorizontalDisplayStart",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalDisplayStart = data; pExist[PB_PanelHorizontalDisplayStart] = 1; } else if (!strcmp("PanelVerticalDisplayStart",ptr)) { BrvipFlash.PanelParameter.PanelVerticalDisplayStart = data; pExist[PB_PanelVerticalDisplayStart] = 1; } else if (!strcmp("PanelHorizontalDisplayEnd",ptr)) { BrvipFlash.PanelParameter.PanelHorizontalDisplayEnd = data; pExist[PB_PanelHorizontalDisplayEnd] = 1; } else if (!strcmp("PanelVerticalDisplayEnd",ptr)) { BrvipFlash.PanelParameter.PanelVerticalDisplayEnd = data; pExist[PB_PanelVerticalDisplayEnd] = 1; } else if (!strcmp("PanelBlueOverScan",ptr)) { BrvipFlash.PanelParameter.PanelBlueOverScan = (unsigned char)data; pExist[PB_PanelBlueOverScan] = 1; } else if (!strcmp("PanelGreenOverScan",ptr)) { BrvipFlash.PanelParameter.PanelGreenOverScan = (unsigned char)data; pExist[PB_PanelGreenOverScan] = 1; } else if (!strcmp("PanelRedOverScan",ptr)) { BrvipFlash.PanelParameter.PanelRedOverScan = (unsigned char)data; pExist[PB_PanelRedOverScan] = 1; } else if (!strcmp("DpyHorizontalDisplayStart",ptr)) { BrvipFlash.DisplayPosition.DpyHorizontalDisplayStart = data; pExist[PB_DpyHorizontalDisplayStart] = 1; } else if (!strcmp("DpyVerticalDisplayStart",ptr)) { BrvipFlash.DisplayPosition.DpyVerticalDisplayStart = data; pExist[PB_DpyVerticalDisplayStart] = 1; } else if (!strcmp("DpyHorizontalDisplayEnd",ptr)) { BrvipFlash.DisplayPosition.DpyHorizontalDisplayEnd = data; pExist[PB_DpyHorizontalDisplayEnd] = 1; } else if (!strcmp("DpyVerticalDisplayEnd",ptr)) { BrvipFlash.DisplayPosition.DpyVerticalDisplayEnd = data; pExist[PB_DpyVerticalDisplayEnd] = 1; } else if (!strcmp("DpyOffset",ptr)) { BrvipFlash.DisplayPosition.DpyOffset = (unsigned short)data; pExist[PB_DpyOffset] = 1; } else if (!strcmp("DpySize",ptr)) { BrvipFlash.DisplayPosition.DpySize = (unsigned short)data; pExist[PB_DpySize] = 1; } else if (!strcmp("DpyLine",ptr)) { BrvipFlash.DisplayPosition.DpyLine = data; pExist[PB_DpyLine] = 1; } else if (!strcmp("Version",ptr)) { BrvipFlash.Version = data; pExist[PB_Version] = 1; } else if (!strcmp("DeviceID",ptr)) { BrvipFlash.DeviceID = (unsigned short)data; pExist[PB_DeviceID] = 1; } else if (!strcmp("VendorID",ptr)) { BrvipFlash.VendorID = (unsigned short)data; pExist[PB_VendorID] = 1; } else if (!strcmp("Dpy00",ptr)) { BrvipFlash.Dpy00 = data; pExist[PB_Dpy00] = 1; } else if (!strcmp("Dpy20",ptr)) { BrvipFlash.Dpy20 = data; pExist[PB_Dpy20] = 1; } else if (!strcmp("Before_MMIOAddress",ptr)) { BrvipFlash.Before_MMIOAddress = data; pExist[PB_Before_MMIOAddress] = 1; } else if (!strcmp("VIPAddress",ptr)) { BrvipFlash.VIPAddress = data; pExist[PB_VIPAddress] = 1; } else if (!strcmp("After_MMIOAddress",ptr)) { BrvipFlash.After_MMIOAddress = data; pExist[PB_After_MMIOAddress] = 1; } else if (!strcmp("SlrReset",ptr)) {; BrvipFlash.ScalerRegister.SlrReset = data; pExist[PB_SlrReset] = 1; } else if (!strcmp("SlrConfig",ptr)) { BrvipFlash.ScalerRegister.SlrConfig = data; pExist[PB_SlrConfig] = 1; } else if (!strcmp("SlrHorizontalFactor",ptr)) { BrvipFlash.ScalerRegister.SlrHorizontalFactor = data; pExist[PB_SlrHorizontalFactor] = 1; } else if (!strcmp("SlrVerticalFactor",ptr)) { BrvipFlash.ScalerRegister.SlrVerticalFactor = data; pExist[PB_SlrVerticalFactor] = 1; } else if (!strcmp("SlrVerticalDown",ptr)) { BrvipFlash.ScalerRegister.SlrVerticalDown = data; pExist[PB_SlrVerticalDown] = 1; } /* else if (!strcmp("SlrLeft",ptr)) { BrvipFlash.ScalerRegister.SlrLeft = data; pExist[PB_SlrLeft] = 1; } else if (!strcmp("SlrRight",ptr)) { BrvipFlash.ScalerRegister.SlrRight = data; pExist[PB_SlrRight] = 1; } else if (!strcmp("SlrLeft0",ptr)) { BrvipFlash.ScalerRegister.SlrLeft0 = data; pExist[PB_SlrLeft0] = 1; } else if (!strcmp("SlrRight0",ptr)) { BrvipFlash.ScalerRegister.SlrRight0 = data; pExist[PB_SlrRight0] = 1; } else if (!strcmp("SlrHorizontalFactor0",ptr)) { BrvipFlash.ScalerRegister.SlrHorizontalFactor0 = data; pExist[PB_SlrHorizontalFactor0] = 1; } */ else if (!strcmp("SlrLine",ptr)) { BrvipFlash.ScalerRegister.SlrLine = data; pExist[PB_SlrLine] = 1; } else if (!strcmp("SlrInc",ptr)) { BrvipFlash.ScalerRegister.SlrInc = data; pExist[PB_SlrInc] = 1; } #if 0 else if (!strcmp("Gpio_15",ptr)) { BrvipFlash.Gpio_15 = data; pExist[PB_Gpio_15] = 1; } else if (!strcmp("Gpio_16",ptr)) { BrvipFlash.Gpio_16 = data; pExist[PB_Gpio_16] = 1; } #else else if (!strcmp("PanelBackLight_GPIOmode",ptr)) { BrvipFlash.PanelBackLight_GPIOPin = (unsigned char)data; //pExist[PB_PanelBackLight_GPIOmode] = 1; } else if (!strcmp("PanelPower_GPIOmode",ptr)) { BrvipFlash.PanelPower_GPIOPin = (unsigned char)data; //pExist[PB_PanelPower_GPIOmode] = 1; } #endif else if (!strcmp("PanelBackLight_GPIOPin",ptr)) { BrvipFlash.PanelBackLight_GPIOPin = (unsigned char)data; pExist[PB_PanelBackLight_GPIOPin] = 1; } else if (!strcmp("PanelPower_GPIOPin",ptr)) { BrvipFlash.PanelPower_GPIOPin = (unsigned char)data; pExist[PB_PanelPower_GPIOPin] = 1; } else if (!strcmp("PanelBackLight_ActiveValue",ptr)) { BrvipFlash.PanelBackLight_ActiveValue = (unsigned char)data; pExist[PB_PanelBackLight_ActiveValue] = 1; } else if (!strcmp("PanelPower_ActiveValue",ptr)) { BrvipFlash.PanelPower_ActiveValue = (unsigned char)data; pExist[PB_PanelPower_ActiveValue] = 1; } else if (!strcmp("LCDBackLightOrder",ptr)) { BrvipFlash.LCDBackLightOrder = (DWORD)data; pExist[PB_LCDBackLightOrder] = 1; } else if (!strcmp("LCDBackLight_OtherFrq",ptr)) { BrvipFlash.LCDBackLight_OtherFrq = (DWORD)data; pExist[PB_LCDBackLight_OtherFrq] = 1; } else if (!strcmp("LCDBackLightMap_00",ptr)) { BrvipFlash.LCDBackLightMap_00 = (DWORD)data; pExist[PB_LCDBackLightMap_00] = 1; } else if (!strcmp("LCDBackLightMap_01",ptr)) { BrvipFlash.LCDBackLightMap_01 = (DWORD)data; pExist[PB_LCDBackLightMap_01] = 1; } else if (!strcmp("LCDBackLightMap_02",ptr)) { BrvipFlash.LCDBackLightMap_02 = (DWORD)data; pExist[PB_LCDBackLightMap_02] = 1; } else if (!strcmp("LCDBackLightMap_03",ptr)) { BrvipFlash.LCDBackLightMap_03 = (DWORD)data; pExist[PB_LCDBackLightMap_03] = 1; } else if (!strcmp("LCDBackLightMap_04",ptr)) { BrvipFlash.LCDBackLightMap_04 = (DWORD)data; pExist[PB_LCDBackLightMap_04] = 1; } else if (!strcmp("LCDBackLightMap_05",ptr)) { BrvipFlash.LCDBackLightMap_05 = (DWORD)data; pExist[PB_LCDBackLightMap_05] = 1; } else if (!strcmp("LCDBackLightMap_06",ptr)) { BrvipFlash.LCDBackLightMap_06 = (DWORD)data; pExist[PB_LCDBackLightMap_06] = 1; } else if (!strcmp("LCDBackLightMap_07",ptr)) { BrvipFlash.LCDBackLightMap_07 = (DWORD)data; pExist[PB_LCDBackLightMap_07] = 1; } else if (!strcmp("LCDBackLightMap_08",ptr)) { BrvipFlash.LCDBackLightMap_08 = (DWORD)data; pExist[PB_LCDBackLightMap_08] = 1; } else if (!strcmp("LCDBackLightMap_09",ptr)) { BrvipFlash.LCDBackLightMap_09 = (DWORD)data; pExist[PB_LCDBackLightMap_09] = 1; } else if (!strcmp("LCDBackLightMap_10",ptr)) { BrvipFlash.LCDBackLightMap_10 = (DWORD)data; pExist[PB_LCDBackLightMap_10] = 1; } else if (!strcmp("LCDBackLightMap_11",ptr)) { BrvipFlash.LCDBackLightMap_11 = (DWORD)data; pExist[PB_LCDBackLightMap_11] = 1; } else if (!strcmp("LCDBackLightMap_12",ptr)) { BrvipFlash.LCDBackLightMap_12 = (DWORD)data; pExist[PB_LCDBackLightMap_12] = 1; } else if (!strcmp("LCDBackLightMap_13",ptr)) { BrvipFlash.LCDBackLightMap_13 = (DWORD)data; pExist[PB_LCDBackLightMap_13] = 1; } else if (!strcmp("LCDBackLightMap_14",ptr)) { BrvipFlash.LCDBackLightMap_14 = (DWORD)data; pExist[PB_LCDBackLightMap_14] = 1; } else if (!strcmp("LogoType",ptr)) { BrvipFlash.LogoType = (DWORD)data; pExist[PB_LogoType] = 1; } else if (!strcmp("LogoSize",ptr)) { BrvipFlash.LogoSize = (DWORD)data; pExist[PB_LogoSize] = 1; } else if (!strcmp("PanelBackLight_OffdelayTime",ptr)) { BrvipFlash.PanelBackLight_OffdelayTime = (DWORD)data; pExist[PB_PanelBackLight_OffdelayTime] = 1; } else if (!strcmp("PanelBackPower_OffdelayTime",ptr)) { BrvipFlash.PanelBackPower_OffdelayTime = (DWORD)data; pExist[PB_PanelBackPower_OffdelayTime] = 1; } } fseek(InFile, mmioflag, SEEK_SET); //BrvipFlash.Before_MMIOAddress = 0xbc0b0000+sizeof(BRVIP_FLASH); 07/03/02008 David. BrvipFlash.Before_MMIOAddress = BR_ADDR_VIP+sizeof(BRVIP_FLASH); BrvipFlash.After_MMIOAddress = BrvipFlash.Before_MMIOAddress; ULSize = 0; //fwrite(&BrvipFlash,sizeof(BRVIP_FLASH),1,OutFile); while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF) { if ((data == 0xffffffff)||(data == 0x00000000)) { break; } //fwrite(&data,4,1,OutFile); //fwrite(&data1,4,1,OutFile); //fwrite(&data2,4,1,OutFile); //fwrite(&data3,4,1,OutFile); //BrvipFlash.After_MMIOAddress += 0x10; ULData[ULSize] = data; ULData[ULSize+1] = data1; ULData[ULSize+2] = data2; ULData[ULSize+3] = data3; ULSize += 4; } data=0xffffffff; //fwrite(&data,4,1,OutFile); //fwrite(&data,4,1,OutFile); //fwrite(&data,4,1,OutFile); //fwrite(&data,4,1,OutFile); //BrvipFlash.After_MMIOAddress += 0x10; ULData[ULSize] = data; ULData[ULSize+1] = data; ULData[ULSize+2] = data; ULData[ULSize+3] = data; ULSize += 4; BrvipFlash.After_MMIOAddress += (ULSize*4); printf("Before_MMIOAddress %x\n",(unsigned int)BrvipFlash.Before_MMIOAddress); printf("ULSize %x",(unsigned int)ULSize); printf("After_MMIOAddress %x\n",(unsigned int)BrvipFlash.After_MMIOAddress); //memcpy(pOutData+writeOffset, &BrvipFlash, sizeof(BRVIP_FLASH)); //write it later writeOffset += sizeof(BRVIP_FLASH); memcpy(pOutData+writeOffset, ULData, 4*ULSize); writeOffset += 4*ULSize; while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF) { if ((data == 0xffffffff)||(data == 0x00000000)) { break; } memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data1, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data2, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data3, 4); writeOffset += 4; } data=0xffffffff; memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; #ifdef SET_338_VIP while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF) { if ((data == 0xffffffff)||(data == 0x00000000)) { break; } memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data1, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data2, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data3, 4); writeOffset += 4; } data=0xffffffff; memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; memcpy(pOutData+writeOffset, &data, 4); writeOffset += 4; #endif //SET_338_VIP #if 1 if(i2c0_fileoffset){ int tmp_write_size = write_i2c_data_to_bin(InFile, i2c0_fileoffset, pOutData, writeOffset); if(tmp_write_size > 0){ BrvipFlash.I2C0_IndexAddress = (short)writeOffset; writeOffset += tmp_write_size; } } if(i2c1_fileoffset){ int tmp_write_size = write_i2c_data_to_bin(InFile, i2c1_fileoffset, pOutData, writeOffset); if(tmp_write_size > 0){ BrvipFlash.I2C1_IndexAddress = (short)writeOffset; writeOffset += tmp_write_size; } } #endif fclose(InFile); /* store brvip after save all struct data */ memcpy(pOutData, &BrvipFlash, sizeof(BRVIP_FLASH)); #if 0 //gaia, 2013.05.02 ya! i don't know what is this.. //--------- Option if (optionflag) { if(PANELSET_SIZE != PANELSET_NOW_USE_FIX_SIZE) { fprintf(stderr, "Error! \nPanelSet Size change !\n Driver must update for this"); return -1; } DWORD fileLen; fileLen = writeOffset % mergeToSize; if(fileLen >= (PANELSET_OPTION_D_OFFSET)) //0x7ec { fprintf(stderr, "Error! \nPanelSet Size change ! Over ox 7 e c\n Tool must update"); return -1; } writeOffset = PANELSET_OPTION_D_OFFSET; memcpy(pOutData+writeOffset, &tempDW,4); } //--------- //check lost only for(i=0; i //< Just capture what we need..... > //< DataOffSet: > //< Width: > //< Height: > //<=================================================================> //for(i=0;i<14;i++) // printf("0x%02x ",(char)BMPFILEHEADER[i]); //printf("\n"); dataoffset=(((BMPFILEHEADER[13]<<8)+BMPFILEHEADER[12])<<16)+(BMPFILEHEADER[11]<<8)+BMPFILEHEADER[10]; //printf("dataoffset=%d\n",dataoffset); fseek( fin, 14, SEEK_SET);//fseekresult=fseek( fin, 14, SEEK_SET); numread =fread( BMPINFOSIZE, sizeof( char ), 4, fin ); if(numread!=4) { fprintf(stderr, "Error:read BMP Info Header error!!"); fclose(fout); fclose(fin); free(READLINE); free(ZERO); return 0; } #if 0 //fgets( BMPINFOSIZE, 4, fin ); size=(((BMPINFOSIZE[3]<<8)+BMPINFOSIZE[2])<<16)+(BMPINFOSIZE[1]<<8)+BMPINFOSIZE[0]; #endif fseek( fin, 18, SEEK_SET);//fseekresult=fseek( fin, 18, SEEK_SET); numread=fread( WIDTH, sizeof( char ), 4, fin ); if(numread!=4) { fprintf(stderr, "Error:read BMP Info Header error!!"); fclose(fout); fclose(fin); free(READLINE); free(ZERO); return 0; } width=(((WIDTH[3]<<8)+WIDTH[2])<<16)+(WIDTH[1]<<8)+WIDTH[0]; fseek( fin, 22, SEEK_SET);//fseekresult=fseek( fin, 22, SEEK_SET); numread=fread( HEIGHT, sizeof( char ), 4, fin ); if(numread!=4) { fprintf(stderr, "Error:read BMP Info Header error!!"); fclose(fout); fclose(fin); free(READLINE); free(ZERO); return 0; } height=(((HEIGHT[3]<<8)+HEIGHT[2])<<16)+(HEIGHT[1]<<8)+HEIGHT[0]; printf("Input BMP width=%d,height=%d\n",width,height); fseek( fin, 28, SEEK_SET);//fseekresult=fseek( fin, 28, SEEK_SET); numread=fread( MYWORD, sizeof( char ), 2, fin ); if(numread!=2) { fprintf(stderr, "Error:read BMP Info Header error!!"); fclose(fout); fclose(fin); free(READLINE); free(ZERO); return 0; } icolor=(MYWORD[1]<<8)+MYWORD[0]; printf("icolor=%d\n",icolor); //<======================== Read Data ================================> //< (GBR)(GBR)(GBR)...................................................> //< (RBG)(RBG)........................................................> //<===================================================================> outwidth=(((width*3)+255)/256)*256; //outwidth=line_offset*256; if((width*3)%4) line_length_pad=(4-((width*3)%4)); else line_length_pad=0; printf("line_length_pad=%d\n",line_length_pad); fin_index=dataoffset+(height-1)*width*3+(height-1)*line_length_pad; align_offset=outwidth-width*3-line_length_pad; printf("align_offset=%d,outwidth=%d\n",align_offset,outwidth); // for(i=height-1;i>0;i--) for(i=0;i