123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008 |
- #include <umf_debug.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <types.h>
- #include <fcntl.h>
- #include <sys/mman.h>
- #include <linux/rtc.h>
- #include <sys/ioctl.h>
- #include <sys/time.h>
- #include <ucontext.h>
- #include "kmf_ioctl.h"
- #include "main_app.h"
- #include "main_app_external.h"
- #include "main_guiobj_table.h"
- #include "al_fw.h"
- #include "drv_kmf_interface.h"
- #include "app_data_setting.h"
- #include "app_change_board.h"
- #include "app_guiobj_source.h"
- #include "app_audio.h"
- #include "umf_event.h"
- #include "umf_ioctl.h"
- #include "app_factory.h"
- #include "pin_config.h"
- #include "mid_upgrade.h"
- #include "nvm_ioctl.h"
- #if defined(CONFIG_UMF_ONLYONECOPY_DATASECTION)
- #include "sismmio.h"
- #endif
- #ifdef SUPPORT_HDMI_SWITCH_EDID
- #include "hdmi_switch.h"
- #endif
- #include "util_ioctl.h"
- #include "svn.h"
- #include "timestamp.h"
- #include "cust_nvm_cfg.h"
- #ifdef CONFIG_SUPPORT_MIRACAST
- #ifdef CONFIG_SUPPORT_MULTI_DONGLE
- #include "wfd_if.h"
- #endif
- #endif
- #ifdef CONFIG_SUPPORT_BOOT_MOVIE
- #include "../../../../middleware/media/filesystem/AL_Multimedia_FileSystem_Lib_Access.h"
- #include "AL_Multimedia_Player_IF.h"
- #include "mid_dtv_display.h"
- #include "app_video.h"
- #ifdef CONFIG_ENABLE_UMF_MODULES
- #include "umf_mod.h"
- #endif
- #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
- #include "mmap_malloc.h"
- #endif
- extern void PQ_Init(void);
- #endif
- // ---------------------------------------------------------------------
- // Macro definition
- // ---------------------------------------------------------------------
- #define MAIN_DEBUG
- #ifdef MAIN_DEBUG
- #undef DEBF
- #define DEBF(fmt, arg...) UMFDBG(0,fmt, ##arg)
- #else
- #define DEBF(fmt, arg...)
- #endif // #idef IDTV_APP_DEBUG
- #define SISKMF_DEV_FILE "/dev/kmf"
- #define SISRTC_DEV_FILE "/dev/rtc"
- #define SISAUDIO_DEV_FILE "/dev/audiorx"
- #define SIS_DEMUX_DEVICE "/dev/sisdemux0"
- typedef struct _UMFDev_t
- {
- int kmfdev;
- int rtcdev;
- int audiodev;
- int dtvdev;
- }UMFDev_t, *PUMFDev_t;
- int kmfdev;
- int dtvdev;
- int audiodev;
- int rtcdev;
- UMFDev_t g_umfdev;
- KMFShareData_t *g_pKMFShareData;
- #if (defined(SUPPORT_FACTORY_AUTO_TEST) || defined(SUPPORT_FACTORY_AUTO_TEST_MODE2))
- UINT8 gacSpecialFileStatus;
- #endif
- UINT32 gFlashModuleCheckSum = 0;
- // ---------------------------------------------------------------------
- // Extern function declaration
- // ---------------------------------------------------------------------
- extern void MID_DTVCI_DebugInit(void);
- extern void MID_Subtitle_constructor(); // constructor function for DTV & Media Subtitle
- #if (defined(SUPPORT_FACTORY_AUTO_TEST) || defined(SUPPORT_FACTORY_AUTO_TEST_MODE2))
- void tv_GetACSpecialFileStatus(UINT8* SpecialFileStatus)
- {
- if(SpecialFileStatus == NULL)
- return;
- //SpecialFileStatus == 0x01 ; FACTEST.CTV
- //SpecialFileStatus == 0x02 ; FACBURN.CTV
- //SpecialFileStatus == 0x03 ; FACTEST.CTV & FACBURN.CTV
- ioctl(kmfdev, KMF_IOC_GetACSpecilFileStatus, SpecialFileStatus);
- }
- #endif
- UINT32 tvGetModuleCheckSum(void)
- {
- UINT32 checksum = 0;
- UINT16 index;
- for(index = FLASH_ID_BOOTROM;index<FLASH_ID_END;index++)
- {
- if(index == FLASH_ID_CAP_LOGO)
- continue;
- checksum += Mid_CmnGetFlashModuleCheckSum(index);
- }
- DEBF("\nSystem GetChecksum: 0x%x\n",checksum);
- gFlashModuleCheckSum = checksum;
- return checksum;
- }
- void umf_GetData(void)
- {
- sisdbgconf1 = g_pKMFShareData->dbgconf1;
- sisdbgconf2 = g_pKMFShareData->dbgconf2;
- //sisdbgconf1 |= 0x400;
- }
- void Enable_Debug_Message(UINT32 DBGStatus)
- {
- ioctl(kmfdev, KMF_IOC_SetDBGStatus, &DBGStatus);
- tv_UpdateDBGStatus();
- umf_GetData();
- }
- int umf_MapKMFShareData(PUMFDev_t pumfdev)
- {
- g_pKMFShareData = (KMFShareData_t *) mmap(0, sizeof(KMFShareData_t), PROT_READ|PROT_WRITE,
- MAP_LOCKED|MAP_SHARED, pumfdev->kmfdev, 0);
- if (g_pKMFShareData == (void *)-1)
- {
- DEBF("umf_MapKMFShareData mmap fail!\n");
- g_pKMFShareData = NULL;
- return -1;
- }
- msync(g_pKMFShareData, sizeof(KMFShareData_t), MS_SYNC);
- return 0;
- }
- void tv_SetSysTimetoRTC(void)
- {
- // Set current linux time to RTC driver.
- PUMFDev_t pumfdev = &g_umfdev;
- struct tm *ptm;
- time_t currsec;
- UINT32 tempSec=0;
- //time(&currsec);
- //AL_Time_GetCurTimeInSecs(&tempSec);
- AL_Time_GetRawTimeInSecs(&tempSec);
- currsec=tempSec;
- currsec += 1;
- ptm = localtime(&currsec);
- ioctl(pumfdev->rtcdev, RTC_SET_TIME, (struct rtc_time*)ptm);
- }
- void tv_SetBaseTimetoSystem(time_t rtcsec)
- {
- // total secs since 1970-01-01 00:00:00 +0000 (UTC)
- struct timeval temp;
- temp.tv_sec = rtcsec;//set system time from RTC
- temp.tv_usec = 0;
- settimeofday(&temp, NULL);
- AL_Time_UpdateRTC();
- }
- void tv_GetRTCTimetoSys(void)
- {
- // when TV boot, get RTC driver time and set it to linux system
- PUMFDev_t pumfdev = &g_umfdev;
- struct rtc_time rtctm = {0};
- struct tm tmtemp = {0};
- struct timeval temp;
- time_t rtcsec;
- ioctl(pumfdev->rtcdev, RTC_RD_TIME, &rtctm);
- DEBF("%s year=%d, mon=%d, day=%d, hour=%d, min=%d, sec=%d, isdst= %d\n",__FUNCTION__,rtctm.tm_year+1900, rtctm.tm_mon+1,
- rtctm.tm_mday, rtctm.tm_hour, rtctm.tm_min, rtctm.tm_sec, rtctm.tm_isdst);
- if (rtctm.tm_year+1900 < 2008 || rtctm.tm_year+1900 > 2047)
- {
- memset(&rtctm, 0, sizeof(struct rtc_time));
- //default : 2008-1-1 Sun 00:00 AM
- rtctm.tm_year = 2008-1900;
- rtctm.tm_mon = 0;
- rtctm.tm_mday = 1;
- rtctm.tm_wday = 0;
- rtctm.tm_hour = 0;
- rtctm.tm_min = 0;
- rtctm.tm_sec = 0;
- ioctl(pumfdev->rtcdev, RTC_SET_TIME, &rtctm);
- }
- memcpy(&tmtemp, &rtctm, sizeof(struct rtc_time));
- rtcsec = mktime(&tmtemp);
- if (rtcsec != (time_t)-1)
- {
- temp.tv_sec = rtcsec;//set system time from RTC
- temp.tv_usec = 0;
- settimeofday(&temp, NULL);
- }
- }
- #ifdef CONFIG_SUPPORT_BOOT_MOVIE
- #define BOOT_MOVIE_FOLDER "/bootmovie"
- #define BOOT_MOVIE_FILE "animation.mp4"
- static char FolderName[64] = { 0 };
- static char FileName[64] = { 0 };
- static BOOL bBootMovieStart = FALSE, bBootMovieInit = FALSE, bBootMovieFinish = FALSE, bBootMovieFail = FALSE;
- static int LoadBootMovieFromFlash(void)
- {
- UINT32 flashSize = Cmd_LookupFlashtableSize((UINT8 *) "BMovie");
- UINT8 *pBuf = NULL;
- char file_path[64] = { 0 };
- FILE *pFileOut;
- int retval = SP_ERR_FAILURE;
- if (flashSize)
- {
- pBuf = (UINT8 *) malloc(sizeof(UINT8) * (flashSize + 1));
- if (pBuf)
- {
- if (Cmd_LookupFlashtableAddr((UINT8 *) "BMovie", (UINT32) pBuf, flashSize) == 0)
- {
- snprintf(file_path, 64, "mkdir %s", BOOT_MOVIE_FOLDER);
- system(file_path);
- memset(file_path, 0, sizeof(file_path));
- snprintf(file_path, 64, "%s/%s", BOOT_MOVIE_FOLDER, BOOT_MOVIE_FILE);
- pFileOut = fopen(file_path, "w");
- if (pFileOut)
- {
- fwrite((void *) pBuf, 1, flashSize, pFileOut);
- fclose(pFileOut);
- retval = SP_SUCCESS;
- UMFDBG(0, "%s write file_path=%s flashSize=%d success!!!\n", __FUNCTION__, file_path, flashSize);
- }
- else
- {
- printf("%s open file_path=%s fail errno=%s!!!\n", __FUNCTION__, file_path,
- (char *) strerror(errno));
- }
- }
- free(pBuf);
- }
- else
- {
- printf("%s BootMovie malloc buf fail!!!\n", __FUNCTION__);
- }
- }
- else
- {
- printf("%s BootMovie flashSize=0!!!\n", __FUNCTION__);
- }
- return retval;
- }
- static const char *getActiveFolderPath(void)
- {
- return FolderName;
- }
- static FileSystem_FileType_t getActiveFileType(void)
- {
- return VIDEO_FILETYPE;
- }
- static const char *getActiveFileName(void)
- {
- return FileName;
- }
- static int InitMpegEngine(char *const pFolderName, char *const pFileName)
- {
- APP_Audio_SetMute(TRUE, FALSE, APP_MUTE_MODE_STATEMAX, APP_SOURCE_MAX);
- APP_Video_Set_DISP_DTVSetVideoMute_ByUserSetting();
- memset(FolderName, 0, 64);
- snprintf(FolderName, 64, "%s", pFolderName);
- memset(FileName, 0, 64);
- snprintf(FileName, 64, "%s", pFileName);
- // Check file is exist or not
- char szFullPath[64] = { 0 };
- snprintf(szFullPath, 64, "%s/%s", pFolderName, pFileName);
- if (AL_Multimedia_FileSystem_IsFileExist(szFullPath) != TRUE)
- {
- printf("%s AL_Multimedia_FileSystem_IsFileExist!!!\n", __FUNCTION__);
- return SP_ERR_FAILURE;
- }
- //Init to Hook system
- AL_PLAYER_Hook_Func_List_t Hook_Api;
- Hook_Api.FileSystem_GetActiveFolderPath = getActiveFolderPath;
- Hook_Api.FileSystem_GetFileType = getActiveFileType;
- Hook_Api.FileSystem_GetActiveFileName = getActiveFileName;
- Hook_Api.FileSystem_BgMusic_GetFileName = NULL;
- Hook_Api.FileSystem_BgMusic_GetFolderPath = NULL;
- Hook_Api.FileSystem_BgPhoto_GetFileName = NULL;
- Hook_Api.FileSystem_BgPhoto_GetFolderPath = NULL;
- if (AL_Multimedia_Player_HookFileSystemAPI(Hook_Api) != AL_PLAYER_SUCCESS)
- {
- printf("%s BootMovie malloc buf fail!!!\n", __FUNCTION__);
- return SP_ERR_FAILURE;
- }
- return SP_SUCCESS;
- }
- static int StopMpegEngine(void)
- {
- AL_Multimeida_Player_IF_Uninit();
- return SP_SUCCESS;
- }
- static int PlayBootMovieFile(void)
- {
- AL_PLAYER_CtrlCmd_Info_t Player_Cmd_Info;
- AL_PLAYER_t AL_ret;
- Cmd_VipOverScanEn(FALSE);
- Cmd_VipAdjust(VIP_ASPECT_RATIO, ASPECT_FULL);
- AL_ret = AL_Multimedia_Player_RequestCommand(PLAYER_OPEN_SELECT_FILE, NULL);
- if (AL_ret != 0)
- {
- printf("%s PLAYER_OPEN_SELECT_FILE fail!!!\n", __FUNCTION__);
- return SP_ERR_FAILURE;
- }
- while (!bBootMovieInit)
- {
- if (bBootMovieFail)
- {
- return SP_ERR_FAILURE;
- }
- usleep(500000);
- }
- APP_Audio_SetMute(FALSE, FALSE, APP_MUTE_MODE_STATEMAX, APP_SOURCE_MEDIA);
- MID_DISP_DTVSetVideoUnmute();
- Player_Cmd_Info.Play_Param.FileType = getActiveFileType();
- Player_Cmd_Info.Play_Param.Play_Info.Video_Config.Program_Index = 0; //the app calculate the program from 0
- AL_ret = AL_Multimedia_Player_RequestCommand(PLAYER_PLAY, &Player_Cmd_Info);
- if (AL_ret != 0)
- {
- printf("%s PLAYER_PLAY fail!!!\n", __FUNCTION__);
- return SP_ERR_FAILURE;
- }
- while (!bBootMovieFinish)
- {
- if (bBootMovieFail)
- {
- return SP_ERR_FAILURE;
- }
- usleep(500000);
- }
- return SP_SUCCESS;
- }
- static void RemoveBootMovieFile(void)
- {
- char file_path[64] = { 0 };
- snprintf(file_path, 64, "rm -rf %s", BOOT_MOVIE_FOLDER);
- system(file_path);
- }
- static void SetPictureSetting(void)
- {
- PQ_Init();
- APP_Video_SetPictureMode(g_stPictureData.stPictureModeSourceTab[APP_STORAGE_SOURCE_MEDIA].PictureModeIndex);
- APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_HUE,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Tint);
- APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_SATURTUION,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Saturation);
- APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_CONTRAST,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Contrast);
- APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_BRIGHTNESS,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Brightness);
- APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_SHARPNESS,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Sharpness);
- APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_COLORTEMP, g_stPictureData.stPictureModeSourceTab[APP_STORAGE_SOURCE_MEDIA].ColorTempIndex);
- APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_NR, g_stPictureData.NR);
- }
- static void SetVolumnSetting(void)
- {
- TVFE_Audio_Volume_t AUX_Volume_Config;
- INT16 i16VolumeValue = 0;
- INT16 i16VolumeOffset = 0;
- AL_Setting_Read(APP_Data_UserSetting_Handle(), SYS_SET_ID_VARIATIONAL, 0,
- sizeof(APP_SETTING_Variational_t), &(g_stVariationalData));
- AL_Setting_Read(APP_Data_UserSetting_Handle(), SYS_SET_ID_SYSINFO, 0,
- sizeof(APP_SETTING_SystemInfo_t), &(g_stSysInfoData));
- #ifdef CONFIG_SUPPORT_SOURCE_VOLUME_CURVE
- i16VolumeValue = g_stSysInfoData.szAudioVolumeTab[MEDIA_AUDIOVOLUME_TABLE][g_stVariationalData.Volume];
- #else
- i16VolumeValue = g_stSysInfoData.szAudioVolumeTab[AUDIOVOLUME_TABLE][g_stVariationalData.Volume];
- #endif
- i16VolumeOffset = g_arAudioVolumeOffset[APP_SOURCE_MEDIA].OffsetValue;;
- AUX_Volume_Config.Vol_Path = TVFE_AUDIO_VOL_MAIN_SD0_PATH;
- AUX_Volume_Config.Volume = i16VolumeValue;
- TVFE_Audio_Set_Volume(&AUX_Volume_Config, i16VolumeOffset);
- }
- static void StartBootMovie(void)
- {
- bBootMovieStart = TRUE;
- if (LoadBootMovieFromFlash() == SP_SUCCESS)
- {
- MID_DISP_DTVDisplayInit();
- AL_Setting_Read(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
- ITEM_OFFSET(APP_SETTING_FactoryUser_t, Function.SSCAdjust.n_Fun_SSC_Clk_Shift),
- sizeof(g_stFactoryUserData.Function.SSCAdjust.n_Fun_SSC_Clk_Shift),
- &(g_stFactoryUserData.Function.SSCAdjust.n_Fun_SSC_Clk_Shift));
- MID_TVFE_SetLVDS_CLOCK_Shift(g_stFactoryUserData.Function.SSCAdjust.n_Fun_SSC_Clk_Shift);
- SetPictureSetting();
- SetVolumnSetting();
- #if defined(CONFIG_CHIP_8506) || defined(CONFIG_CHIP_512L) || defined(CONFIG_CHIP_6710)
- #ifdef CONFIG_ENABLE_UMF_MODULES
- MID_DISP_MediaSetSource(INPUT_TYPE_USB);
- umf_loadModule(UMFMOD_MEDIA);
- umf_loadModule(UMFMOD_PICTURE);
- #endif
- if (InitMpegEngine(BOOT_MOVIE_FOLDER, BOOT_MOVIE_FILE) == SP_SUCCESS)
- {
- #ifdef CONFIG_ENABLE_UMF_MODULES
- umf_loadModule(UMFMOD_FFMPEG);
- #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
- TTOrSubModLoad(FALSE);
- #endif
- MID_DISP_MediaSetSource(INPUT_TYPE_MEDIA);
- extern void av_mmap_uninit(void);
- extern void av_mmap_init(void);
- av_mmap_uninit();
- av_mmap_init();
- #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
- /*when play movie, need load subtitle/TTx module.*/
- MMap_Init();
- #endif
- #endif
- PlayBootMovieFile();
- RemoveBootMovieFile();
- }
- StopMpegEngine();
- #ifdef CONFIG_ENABLE_UMF_MODULES
- umf_unloadModule(UMFMOD_FFMPEG);
- #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
- TTOrSubModUnload();
- #endif
- umf_unloadModule(UMFMOD_PICTURE);
- umf_unloadModule(UMFMOD_MEDIA);
- #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
- MMap_Uninit();
- #endif
- extern void av_mmap_uninit(void);
- av_mmap_uninit();
- #endif
- #else
- if (InitMpegEngine(BOOT_MOVIE_FOLDER, BOOT_MOVIE_FILE) == SP_SUCCESS)
- {
- PlayBootMovieFile();
- RemoveBootMovieFile();
- }
- StopMpegEngine();
- #endif
- }
- bBootMovieStart = FALSE;
- }
- void BootMovie_Event_Process(UINT32 event_id)
- {
- if (!bBootMovieStart)
- return;
- switch (event_id)
- {
- case PLAYER_AV_EVENT_DECODE_FINISH:
- UMFDBG(0, "%s PLAYER_AV_EVENT_DECODE_FINISH\n", __FUNCTION__);
- bBootMovieFinish = TRUE;
- break;
- case PLAYER_AV_EVENT_INITOK:
- UMFDBG(0, "%s PLAYER_AV_EVENT_INITOK\n", __FUNCTION__);
- bBootMovieInit = TRUE;
- break;
- case PLAYER_AV_EVENT_READERROR:
- case PLAYER_AV_EVENT_AUDIOUNSUPPORT:
- case PLAYER_AV_EVENT_VIDEOUNSUPPORT:
- case PLAYER_AV_EVENT_UNSUPPORT:
- UMFDBG(0, "%s BootMovieFail!!!\n", __FUNCTION__);
- bBootMovieFail = TRUE;
- break;
- default:
- break;
- }
- }
- #endif
- #ifdef CONFIG_SUPPORT_MIRACAST
- #if defined(CONFIG_SUPPORT_RTL8188) || defined(CONFIG_SUPPORT_RTL8188FTV) || defined(CONFIG_SUPPORT_RDA5995) || defined(CONFIG_SUPPORT_NORMAL_MTK7601) || defined(CONFIG_SUPPORT_RTL8723BU) || defined(CONFIG_SUPPORT_RTL8723DU)
- #define P2pConfig_FILE "/etc/p2p_supplicant.conf"
- #elif defined(CONFIG_SUPPORT_MTK7601)
- #define P2pConfig_FILE "/etc/PersistentTable.conf"
- #endif
- typedef struct
- {
- INT32 size;
- UINT8 *data;
- } p2p_config_t;
- INT32 LoadP2pConfigFromFlash(void)
- {
- FILE *fp = NULL;
- p2p_config_t *p2p_config = NULL;
- INT32 size_flash = tv_GetSfsObjFileSize(ENVMPurposeIDP2PConfig);
- size_flash = size_flash < 0 ? 0 : size_flash;
- p2p_config = malloc(size_flash);
- if (p2p_config == NULL)
- {
- printf("malloc error!!!\n");
- return -1;
- }
- if (size_flash > 0)
- {
- Cmd_NVMRead(ENVMPurposeIDP2PConfig,FALSE, size_flash, (UINT8 *)p2p_config);
- p2p_config->data = (UINT8 *)p2p_config+sizeof(p2p_config_t);
- printf("p2p_config:0x%08x ,p2p_config->data::0x%08x\n", (UINT32)p2p_config,(UINT32)p2p_config->data);
- #ifdef CONFIG_SUPPORT_MULTI_DONGLE
- if(miracast_get_dongle() == Dongle_RTK_8188FTV)
- fp = fopen("/etc/RTK_8188FTV/p2p_supplicant.conf", "w+");
- else if(miracast_get_dongle() == Dongle_MTK_7601)
- fp = fopen("/etc/MTK_7601/p2p_supplicant.conf", "w+");
- else
- printf("Didn't insert dongle \n");
- #else
- fp = fopen(P2pConfig_FILE, "w+");
- #endif
- if (fp == NULL)
- {
- printf("fopen file ERR\n");
- perror("@@@@@@@@@@@@@@@@@@@\n");
- free(p2p_config);
- p2p_config = NULL;
- return -1;
- }
- INT32 writeRet = 0;
- printf("p2p_config->size:%d \n", p2p_config->size);
- size_flash = p2p_config->size;
- writeRet = fwrite(p2p_config->data, 1, size_flash, fp);
- fclose(fp);
- if (p2p_config != NULL)
- {
- free(p2p_config);
- p2p_config = NULL;
- }
- if (writeRet != size_flash)
- {
- printf("write error!!\n");
- return -1;
- }
- }
- free(p2p_config);
- return 0;
- }
- int WriteP2pConfigToFlash(void)
- {
- INT32 ret = 0;
- FILE *fp = NULL;
- p2p_config_t *p2p_config = NULL;
- int size_file = 0;
- int size_read = 0;
- #ifdef CONFIG_SUPPORT_MULTI_DONGLE
- if(miracast_get_dongle() == Dongle_RTK_8188FTV)
- fp = fopen("/etc/RTK_8188FTV/p2p_supplicant.conf", "rb");
- else if(miracast_get_dongle() == Dongle_MTK_7601)
- fp = fopen("/etc/MTK_7601/p2p_supplicant.conf", "rb");
- else
- printf("Didn't insert dongle \n");
- #else
- fp = fopen(P2pConfig_FILE, "rb" );
- #endif
- if (fp == NULL)
- {
- printf("[%s:%d] open file error \n", __FUNCTION__, __LINE__);
- return SP_ERR_FAILURE;
- }
- fseek(fp, 0, SEEK_END);
- size_file = ftell(fp);
- p2p_config =malloc(size_file+sizeof(p2p_config_t));
- if (p2p_config == NULL)
- {
- printf("malloc error!!!\n");
- fclose(fp);
- return -1;
- }
- memset(p2p_config, 0, size_file+sizeof(p2p_config_t));
- fseek(fp, 0, SEEK_SET);
- p2p_config->data = (UINT8 *)p2p_config+sizeof(p2p_config_t);
- size_read = fread(p2p_config->data, 1, size_file, fp);
- p2p_config->size = size_read;
- //p2p_config->data[size_read+4] = '\0';
- fclose(fp);
- printf("p2p_config= 0x%x size_file:%d size_read:%d \n", (UINT32)p2p_config, size_file, size_read);
- ret = Cmd_NVMWrite(ENVMPurposeIDP2PConfig,FALSE, size_read+sizeof(p2p_config_t), (UINT8 *)p2p_config);
- if(ret != 0)
- {
- printf("[error %s %d] (%d)\n",__FUNCTION__,__LINE__,ret);
- }
- if (p2p_config != NULL)
- {
- free(p2p_config);
- p2p_config = NULL;
- }
- return SP_SUCCESS;
- }
- #endif
- int umf_Init(void)
- {
- int retval, umfPid;
- //----- Open kmf dev -----
- g_umfdev.kmfdev = open(SISKMF_DEV_FILE, O_RDWR);
- if (g_umfdev.kmfdev <= 0)
- {
- DEBF("Unable to open %s\n", SISKMF_DEV_FILE);
- //return -1;
- }
- kmfdev = g_umfdev.kmfdev;
- //----- Open rtc dev -----
- g_umfdev.rtcdev = open(SISRTC_DEV_FILE, O_RDWR);
- if (g_umfdev.rtcdev <= 0)
- {
- DEBF("Unable to open %s\n", SISRTC_DEV_FILE);
- //return -1;
- }
- rtcdev = g_umfdev.rtcdev;
- //----- Open audiorx dev -----
- g_umfdev.audiodev = open(SISAUDIO_DEV_FILE, O_RDWR);
- if (g_umfdev.audiodev <= 0)
- {
- DEBF("Unable to open %s\n", SISAUDIO_DEV_FILE);
- //return -1;
- }
- audiodev = g_umfdev.audiodev;
- //----- Open dtv dev -----
- g_umfdev.dtvdev = open( SIS_DEMUX_DEVICE, O_RDWR );;
- if (g_umfdev.dtvdev <= 0)
- {
- DEBF("Unable to open %s\n", SIS_DEMUX_DEVICE);
- //return -1;
- }
- dtvdev = g_umfdev.dtvdev;
- //----- Load data -----
- retval = umf_MapKMFShareData(&g_umfdev);
- if (retval != 0)
- {
- DEBF("mmap KMF Share Data Fail\n");
- //return retval;
- }
- umf_GetData();
- #if (defined(SUPPORT_FACTORY_AUTO_TEST_MODE2))
- tv_GetACSpecialFileStatus(&gacSpecialFileStatus);
- if((gacSpecialFileStatus & 0x01) == 0x01)
- {
- if((gacSpecialFileStatus & 0x02) == 0x02)
- {
- APP_Factory_SetAutoTestOnOff(FALSE);
- }
- else
- {
- APP_Factory_SetAutoTestOnOff(TRUE);
- #ifdef SUPPORT_FACTORY_AUTO_TEST_BAR_MENU_DISPLAY_CRC
- tvGetModuleCheckSum();
- #endif
- }
- }
- #elif defined(SUPPORT_FACTORY_AUTO_TEST)
- tv_GetACSpecialFileStatus(&gacSpecialFileStatus);
- if((gacSpecialFileStatus & 0x01) == 0x01)
- {
- APP_Factory_SetAutoTestOnOff(TRUE);
- UINT8 retval = 0;
- Cmd_mmio_ReadUINT8(0xbe0f0523, &retval);//check upgrade or not
- if((retval & 0x0C))
- {
- Cmd_mmio_WriteUINT8mask(0xbe0f0523, 0x00, 0x0c);
- APP_Factory_SetUpgradeandAutoTestFlag(TRUE);
- APP_SetPoweronEnterVersion(1);//show the menu of version
- }
- }
- if(APP_Factory_GetAutoTestOnOff()==TRUE)
- {
- Enable_Debug_Message(0);
- }
- else
- {
- // Enable_Debug_Message(1<<MODULEID_UMF);
- }
- #else
- // Enable_Debug_Message(1<<MODULEID_UMF);
- #endif
- if(!g_pKMFShareData->bUartATx)
- {
- tv_SetUartATx(FALSE);
- }
- //--Regist Signal Callback function and UMF PID--
- tv_GetRTCTimetoSys();
- regist_SignalEvent();
- #ifdef CONFIG_AUTO_USB_STORE_IRSEQ
- extern int AUTO_IF_Regist_SignalEvent(void);
- AUTO_IF_Regist_SignalEvent();
- #endif
- umfPid = getpid();
- ioctl(g_umfdev.kmfdev, KMF_IOC_SET_UMFPID, umfPid);
- #ifndef CONFIG_SYSTEM_WATCHDOG_DISABLE
- extern void wdog_init(void);
- wdog_init();
- #endif
- event_Init();
- #ifdef CONFIG_CI_SUPPORT
- extern BOOLEAN STB_CIOpen(UINT8 slot_id);
- STB_CIOpen(0);
- #endif
- #ifdef CONFIG_SUPPORT_MIRACAST
- LoadP2pConfigFromFlash();
- #endif
- Cmd_NVMInital();
- DEBF("****** umf_Init finish ****** \n\n");
- DEBF("Build code at %s %s \n\n",__TIME__,__DATE__);
- return retval;
- }
- void SW_init(void)
- {
- /* app user setting initial */
- APP_Data_UserSetting_Init();
- APPSourceConfigTable_Init();//add for sourceconfig
- APP_GOBJ_Source_Get_Support_InputSource_String();//add for new source table
- #ifdef CONFIG_SUPPORT_BOOT_MOVIE
- APP_Audio_Initial(); //ifndef CONFIG_SUPPORT_BOOT_MOVIE, move APP_Audio_Initial() from sw_init to here to avoid spending 1.5 secs to wait audio dac ready in boot flow
- #endif
- #if (defined(SUPPORT_FACTORY_AUTO_TEST)||defined(SUPPORT_FACTORY_AUTO_TEST_MODE2))
- if((gacSpecialFileStatus & 0x02) == 0x02 && FALSE == APP_Factory_GetAutoTestOnOff())
- {
- g_stFactoryUserData.n_FactSet_BurningMode = 1;
- AL_Setting_Write(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
- ITEM_OFFSET(APP_SETTING_FactoryUser_t, n_FactSet_BurningMode),
- sizeof(g_stFactoryUserData.n_FactSet_BurningMode),&(g_stFactoryUserData.n_FactSet_BurningMode));
- AL_Setting_Store(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
- ITEM_OFFSET(APP_SETTING_FactoryUser_t, n_FactSet_BurningMode),
- sizeof(g_stFactoryUserData.n_FactSet_BurningMode));
- Cmd_gpio_WriteOnLevel(GPIO_BL_ON_PIN);
- }
- else if(APP_Factory_GetAutoTestOnOff()==TRUE)
- {
- g_stFactoryUserData.n_FactSet_BurningMode = 0;
- AL_Setting_Write(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
- ITEM_OFFSET(APP_SETTING_FactoryUser_t, n_FactSet_BurningMode),
- sizeof(g_stFactoryUserData.n_FactSet_BurningMode),&(g_stFactoryUserData.n_FactSet_BurningMode));
- AL_Setting_Store(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
- ITEM_OFFSET(APP_SETTING_FactoryUser_t, n_FactSet_BurningMode),
- sizeof(g_stFactoryUserData.n_FactSet_BurningMode));
- }
- #endif
- #ifdef SUPPORT_HDMI_SWITCH_EDID
- HDMI_Switch_Init();
- #endif
- #ifdef CONFIG_MOD_PACK_SUB
- //when the marco is opened, need call this api after load Subtitle module.
- #else
- #if defined(CONFIG_MEDIA_ENABLE) || defined(CONFIG_SUPPORT_SUBTITLE)
- extern void MID_Subtitle_constructor();
- MID_Subtitle_constructor(); // constructor function for DTV & Media Subtitle
- #endif
- #endif
- #ifdef CONFIG_SUPPORT_BOOT_MOVIE
- StartBootMovie();
- #endif
- }
- #ifdef CONFIG_CALL_TRACE
- extern void direct_trace_print_stacks(void);
- extern void direct_set_output_fd(int);
- __attribute__((no_instrument_function))
- static void dump_cpu_registers(ucontext_t *uc)
- {
- printf("special registers:\n");
- printf(" $pc: 0x%08x\n",(unsigned int)uc->uc_mcontext.pc);
- printf(" $ra: 0x%08x\n\n",(unsigned int) uc->uc_mcontext.gregs[31]);
- printf("generic registers:\n");
- printf(" $zo: 0x%08x $at: 0x%08x $v0: 0x%08x $v1: 0x%08x\n", \
- (unsigned int) uc->uc_mcontext.gregs[0], (unsigned int) uc->uc_mcontext.gregs[1], \
- (unsigned int) uc->uc_mcontext.gregs[2], (unsigned int) uc->uc_mcontext.gregs[3]);
- printf(" $a0: 0x%08x $a1: 0x%08x $a2: 0x%08x $a3: 0x%08x\n", \
- (unsigned int) uc->uc_mcontext.gregs[4], (unsigned int) uc->uc_mcontext.gregs[5], \
- (unsigned int) uc->uc_mcontext.gregs[6], (unsigned int) uc->uc_mcontext.gregs[7]);
- printf(" $t0: 0x%08x $t1: 0x%08x $t2: 0x%08x $t3: 0x%08x\n", \
- (unsigned int) uc->uc_mcontext.gregs[8], (unsigned int) uc->uc_mcontext.gregs[9], \
- (unsigned int) uc->uc_mcontext.gregs[10], (unsigned int) uc->uc_mcontext.gregs[11]);
- printf(" $t4: 0x%08x $t5: 0x%08x $t6: 0x%08x $t7: 0x%08x\n", \
- (unsigned int) uc->uc_mcontext.gregs[12], (unsigned int) uc->uc_mcontext.gregs[13], \
- (unsigned int) uc->uc_mcontext.gregs[14], (unsigned int) uc->uc_mcontext.gregs[15]);
- printf(" $s0: 0x%08x $s1: 0x%08x $s2: 0x%08x $s3: 0x%08x\n", \
- (unsigned int) uc->uc_mcontext.gregs[16], (unsigned int) uc->uc_mcontext.gregs[17], \
- (unsigned int) uc->uc_mcontext.gregs[18], (unsigned int) uc->uc_mcontext.gregs[19]);
- printf(" $s4: 0x%08x $s5: 0x%08x $s6: 0x%08x $s7: 0x%08x\n", \
- (unsigned int) uc->uc_mcontext.gregs[20], (unsigned int) uc->uc_mcontext.gregs[21], \
- (unsigned int) uc->uc_mcontext.gregs[22], (unsigned int) uc->uc_mcontext.gregs[23]);
- printf(" $t8: 0x%08x $t9: 0x%08x $k0: 0x%08x $k1: 0x%08x\n", \
- (unsigned int) uc->uc_mcontext.gregs[24], (unsigned int) uc->uc_mcontext.gregs[25], \
- (unsigned int) uc->uc_mcontext.gregs[26], (unsigned int) uc->uc_mcontext.gregs[27]);
- printf(" $gp: 0x%08x $sp: 0x%08x $fp: 0x%08x\n\n", \
- (unsigned int) uc->uc_mcontext.gregs[28], (unsigned int) uc->uc_mcontext.gregs[29], \
- (unsigned int) uc->uc_mcontext.gregs[30]);
- }
- __attribute__((no_instrument_function))
- static void signal_handler(int signo, siginfo_t* info, void*ptr)
- {
- int outfd;
- unsigned long long tmp_time;
- struct timeval tv;
- char output_filename[64];
- ucontext_t *uc;
- uc = (ucontext_t *) ptr;
- printf("\n[SIGNAL HANDLER] Pid: %d Catch SIGNO %d\n\n",getpid(),signo);
- dump_cpu_registers(uc);
- printf("Call Trace:\n");
- direct_trace_print_stacks();
- gettimeofday(&tv, NULL);
- tmp_time = tv.tv_sec * 1000000 + tv.tv_usec;
- memset(output_filename,'\0',64);
- sprintf(output_filename,"/mnt/sda1/trace%lld",tmp_time);
- outfd = open(output_filename,O_RDWR | O_CREAT);
- if (outfd > 0) {
- direct_set_output_fd(outfd);
- direct_trace_print_stacks();
- close(outfd);
- printf("[SIGNAL HANDLER] Create %s success.\n", output_filename);
- }
- system("word 0xbe1cc050 0x00ff0000");
- sync();
- signal(signo, SIG_DFL);
- kill(getpid(),signo);
- }
- static void signals_initialize(void)
- {
- unsigned int i;
- struct sigaction action;
- int sigs_to_handle[] = { SIGHUP, SIGTERM, SIGABRT, SIGFPE,
- SIGILL, SIGQUIT, SIGSEGV, SIGTRAP,
- SIGBUS, SIGXCPU, SIGXFSZ};
- memset(&action, 0, sizeof(action));
- action.sa_sigaction = signal_handler;
- action.sa_flags = SA_SIGINFO;
- for (i = 0; i < (sizeof(sigs_to_handle)>>2); i++)
- if(sigaction(sigs_to_handle[i], &action, NULL) < 0)
- perror("sigaction");
- }
- #endif
- #if defined(CONFIG_UMF_ONLYONECOPY_DATASECTION)
- static void mmap_data_section(void)
- {
- int fd;
- unsigned int i,j;
- unsigned char *ptr;
- sismmio_ioctl_section_remap remap;
-
- remap.opt=0;
- fd = open("/dev/sismmio",O_RDWR);
- ioctl(fd, SISMMIO_SECTIION_REMAP, &remap);
- ptr = (unsigned char *)remap.vaddr_start;
- for (i=0; i < remap.length; i+=getpagesize()){
- j = *(volatile unsigned char *)(ptr+i);
- j = j;
- }
- remap.opt=1;
- ioctl(fd, SISMMIO_SECTIION_REMAP, &remap);
- close(fd);
- }
- #endif
- #ifdef CONFIG_SUPPORT_MONITOR_POWERSAVE
- int gcov_power_off_flag = false;
- #endif
- #ifdef CONFIG_NOT_USEBB
- int umf_main(int argc, char* argv[])
- #else
- int main(int argc, char* argv[])
- #endif
- {
-
- #if defined(CONFIG_UMF_ONLYONECOPY_DATASECTION)
- mmap_data_section();
- #endif
- #ifdef CONFIG_CALL_TRACE
- signals_initialize();
- #endif
- umf_Init();
- /* AFW initialize public module */
- AL_FW_Init(FW_MAIN_INIT, MAINAPP_FW_Callback, MAINAPP_FW_GetContext);
- SW_init();
- MainApp_InitCfg_t stMainAppInit =
- {
- .pfInitFlow = MAINAPP_InitFlow,
- .pGUIObjectTable = MAIN_APP_GUI_Obj_List,
- .pfOnTimerUpdate = MAINAPP_OnTimerUpdate,
- .pfOnEvent = MAINAPP_OnEvent
- };
- MAINAPP_Initialize(&stMainAppInit);
- /* Debug only */
- #ifdef CONFIG_CIPLUS_TEST
- MID_DTVCI_DebugInit();
- #endif
- #ifdef CONFIG_SUPPORT_MONITOR_POWERSAVE
- while (gcov_power_off_flag != true)
- {
- sleep(1);
- }
- close(g_umfdev.kmfdev);
- close(g_umfdev.rtcdev);
- close(g_umfdev.audiodev);
- close(g_umfdev.dtvdev);
-
- system("./PowerSave &");
- #else
- while (1)
- {
- sleep(100);
- }
- #endif
- return 0;
- }
|