main.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. #include <umf_debug.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <types.h>
  6. #include <fcntl.h>
  7. #include <sys/mman.h>
  8. #include <linux/rtc.h>
  9. #include <sys/ioctl.h>
  10. #include <sys/time.h>
  11. #include <ucontext.h>
  12. #include "kmf_ioctl.h"
  13. #include "main_app.h"
  14. #include "main_app_external.h"
  15. #include "main_guiobj_table.h"
  16. #include "al_fw.h"
  17. #include "drv_kmf_interface.h"
  18. #include "app_data_setting.h"
  19. #include "app_change_board.h"
  20. #include "app_guiobj_source.h"
  21. #include "app_audio.h"
  22. #include "umf_event.h"
  23. #include "umf_ioctl.h"
  24. #include "app_factory.h"
  25. #include "pin_config.h"
  26. #include "mid_upgrade.h"
  27. #include "nvm_ioctl.h"
  28. #if defined(CONFIG_UMF_ONLYONECOPY_DATASECTION)
  29. #include "sismmio.h"
  30. #endif
  31. #ifdef SUPPORT_HDMI_SWITCH_EDID
  32. #include "hdmi_switch.h"
  33. #endif
  34. #include "util_ioctl.h"
  35. #include "svn.h"
  36. #include "timestamp.h"
  37. #include "cust_nvm_cfg.h"
  38. #ifdef CONFIG_SUPPORT_MIRACAST
  39. #ifdef CONFIG_SUPPORT_MULTI_DONGLE
  40. #include "wfd_if.h"
  41. #endif
  42. #endif
  43. #ifdef CONFIG_SUPPORT_BOOT_MOVIE
  44. #include "../../../../middleware/media/filesystem/AL_Multimedia_FileSystem_Lib_Access.h"
  45. #include "AL_Multimedia_Player_IF.h"
  46. #include "mid_dtv_display.h"
  47. #include "app_video.h"
  48. #ifdef CONFIG_ENABLE_UMF_MODULES
  49. #include "umf_mod.h"
  50. #endif
  51. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  52. #include "mmap_malloc.h"
  53. #endif
  54. extern void PQ_Init(void);
  55. #endif
  56. // ---------------------------------------------------------------------
  57. // Macro definition
  58. // ---------------------------------------------------------------------
  59. #define MAIN_DEBUG
  60. #ifdef MAIN_DEBUG
  61. #undef DEBF
  62. #define DEBF(fmt, arg...) UMFDBG(0,fmt, ##arg)
  63. #else
  64. #define DEBF(fmt, arg...)
  65. #endif // #idef IDTV_APP_DEBUG
  66. #define SISKMF_DEV_FILE "/dev/kmf"
  67. #define SISRTC_DEV_FILE "/dev/rtc"
  68. #define SISAUDIO_DEV_FILE "/dev/audiorx"
  69. #define SIS_DEMUX_DEVICE "/dev/sisdemux0"
  70. typedef struct _UMFDev_t
  71. {
  72. int kmfdev;
  73. int rtcdev;
  74. int audiodev;
  75. int dtvdev;
  76. }UMFDev_t, *PUMFDev_t;
  77. int kmfdev;
  78. int dtvdev;
  79. int audiodev;
  80. int rtcdev;
  81. UMFDev_t g_umfdev;
  82. KMFShareData_t *g_pKMFShareData;
  83. #if (defined(SUPPORT_FACTORY_AUTO_TEST) || defined(SUPPORT_FACTORY_AUTO_TEST_MODE2))
  84. UINT8 gacSpecialFileStatus;
  85. #endif
  86. UINT32 gFlashModuleCheckSum = 0;
  87. // ---------------------------------------------------------------------
  88. // Extern function declaration
  89. // ---------------------------------------------------------------------
  90. extern void MID_DTVCI_DebugInit(void);
  91. extern void MID_Subtitle_constructor(); // constructor function for DTV & Media Subtitle
  92. #if (defined(SUPPORT_FACTORY_AUTO_TEST) || defined(SUPPORT_FACTORY_AUTO_TEST_MODE2))
  93. void tv_GetACSpecialFileStatus(UINT8* SpecialFileStatus)
  94. {
  95. if(SpecialFileStatus == NULL)
  96. return;
  97. //SpecialFileStatus == 0x01 ; FACTEST.CTV
  98. //SpecialFileStatus == 0x02 ; FACBURN.CTV
  99. //SpecialFileStatus == 0x03 ; FACTEST.CTV & FACBURN.CTV
  100. ioctl(kmfdev, KMF_IOC_GetACSpecilFileStatus, SpecialFileStatus);
  101. }
  102. #endif
  103. UINT32 tvGetModuleCheckSum(void)
  104. {
  105. UINT32 checksum = 0;
  106. UINT16 index;
  107. for(index = FLASH_ID_BOOTROM;index<FLASH_ID_END;index++)
  108. {
  109. if(index == FLASH_ID_CAP_LOGO)
  110. continue;
  111. checksum += Mid_CmnGetFlashModuleCheckSum(index);
  112. }
  113. DEBF("\nSystem GetChecksum: 0x%x\n",checksum);
  114. gFlashModuleCheckSum = checksum;
  115. return checksum;
  116. }
  117. void umf_GetData(void)
  118. {
  119. sisdbgconf1 = g_pKMFShareData->dbgconf1;
  120. sisdbgconf2 = g_pKMFShareData->dbgconf2;
  121. //sisdbgconf1 |= 0x400;
  122. }
  123. void Enable_Debug_Message(UINT32 DBGStatus)
  124. {
  125. ioctl(kmfdev, KMF_IOC_SetDBGStatus, &DBGStatus);
  126. tv_UpdateDBGStatus();
  127. umf_GetData();
  128. }
  129. int umf_MapKMFShareData(PUMFDev_t pumfdev)
  130. {
  131. g_pKMFShareData = (KMFShareData_t *) mmap(0, sizeof(KMFShareData_t), PROT_READ|PROT_WRITE,
  132. MAP_LOCKED|MAP_SHARED, pumfdev->kmfdev, 0);
  133. if (g_pKMFShareData == (void *)-1)
  134. {
  135. DEBF("umf_MapKMFShareData mmap fail!\n");
  136. g_pKMFShareData = NULL;
  137. return -1;
  138. }
  139. msync(g_pKMFShareData, sizeof(KMFShareData_t), MS_SYNC);
  140. return 0;
  141. }
  142. void tv_SetSysTimetoRTC(void)
  143. {
  144. // Set current linux time to RTC driver.
  145. PUMFDev_t pumfdev = &g_umfdev;
  146. struct tm *ptm;
  147. time_t currsec;
  148. UINT32 tempSec=0;
  149. //time(&currsec);
  150. //AL_Time_GetCurTimeInSecs(&tempSec);
  151. AL_Time_GetRawTimeInSecs(&tempSec);
  152. currsec=tempSec;
  153. currsec += 1;
  154. ptm = localtime(&currsec);
  155. ioctl(pumfdev->rtcdev, RTC_SET_TIME, (struct rtc_time*)ptm);
  156. }
  157. void tv_SetBaseTimetoSystem(time_t rtcsec)
  158. {
  159. // total secs since 1970-01-01 00:00:00 +0000 (UTC)
  160. struct timeval temp;
  161. temp.tv_sec = rtcsec;//set system time from RTC
  162. temp.tv_usec = 0;
  163. settimeofday(&temp, NULL);
  164. AL_Time_UpdateRTC();
  165. }
  166. void tv_GetRTCTimetoSys(void)
  167. {
  168. // when TV boot, get RTC driver time and set it to linux system
  169. PUMFDev_t pumfdev = &g_umfdev;
  170. struct rtc_time rtctm = {0};
  171. struct tm tmtemp = {0};
  172. struct timeval temp;
  173. time_t rtcsec;
  174. ioctl(pumfdev->rtcdev, RTC_RD_TIME, &rtctm);
  175. 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,
  176. rtctm.tm_mday, rtctm.tm_hour, rtctm.tm_min, rtctm.tm_sec, rtctm.tm_isdst);
  177. if (rtctm.tm_year+1900 < 2008 || rtctm.tm_year+1900 > 2047)
  178. {
  179. memset(&rtctm, 0, sizeof(struct rtc_time));
  180. //default : 2008-1-1 Sun 00:00 AM
  181. rtctm.tm_year = 2008-1900;
  182. rtctm.tm_mon = 0;
  183. rtctm.tm_mday = 1;
  184. rtctm.tm_wday = 0;
  185. rtctm.tm_hour = 0;
  186. rtctm.tm_min = 0;
  187. rtctm.tm_sec = 0;
  188. ioctl(pumfdev->rtcdev, RTC_SET_TIME, &rtctm);
  189. }
  190. memcpy(&tmtemp, &rtctm, sizeof(struct rtc_time));
  191. rtcsec = mktime(&tmtemp);
  192. if (rtcsec != (time_t)-1)
  193. {
  194. temp.tv_sec = rtcsec;//set system time from RTC
  195. temp.tv_usec = 0;
  196. settimeofday(&temp, NULL);
  197. }
  198. }
  199. #ifdef CONFIG_SUPPORT_BOOT_MOVIE
  200. #define BOOT_MOVIE_FOLDER "/bootmovie"
  201. #define BOOT_MOVIE_FILE "animation.mp4"
  202. static char FolderName[64] = { 0 };
  203. static char FileName[64] = { 0 };
  204. static BOOL bBootMovieStart = FALSE, bBootMovieInit = FALSE, bBootMovieFinish = FALSE, bBootMovieFail = FALSE;
  205. static int LoadBootMovieFromFlash(void)
  206. {
  207. UINT32 flashSize = Cmd_LookupFlashtableSize((UINT8 *) "BMovie");
  208. UINT8 *pBuf = NULL;
  209. char file_path[64] = { 0 };
  210. FILE *pFileOut;
  211. int retval = SP_ERR_FAILURE;
  212. if (flashSize)
  213. {
  214. pBuf = (UINT8 *) malloc(sizeof(UINT8) * (flashSize + 1));
  215. if (pBuf)
  216. {
  217. if (Cmd_LookupFlashtableAddr((UINT8 *) "BMovie", (UINT32) pBuf, flashSize) == 0)
  218. {
  219. snprintf(file_path, 64, "mkdir %s", BOOT_MOVIE_FOLDER);
  220. system(file_path);
  221. memset(file_path, 0, sizeof(file_path));
  222. snprintf(file_path, 64, "%s/%s", BOOT_MOVIE_FOLDER, BOOT_MOVIE_FILE);
  223. pFileOut = fopen(file_path, "w");
  224. if (pFileOut)
  225. {
  226. fwrite((void *) pBuf, 1, flashSize, pFileOut);
  227. fclose(pFileOut);
  228. retval = SP_SUCCESS;
  229. UMFDBG(0, "%s write file_path=%s flashSize=%d success!!!\n", __FUNCTION__, file_path, flashSize);
  230. }
  231. else
  232. {
  233. printf("%s open file_path=%s fail errno=%s!!!\n", __FUNCTION__, file_path,
  234. (char *) strerror(errno));
  235. }
  236. }
  237. free(pBuf);
  238. }
  239. else
  240. {
  241. printf("%s BootMovie malloc buf fail!!!\n", __FUNCTION__);
  242. }
  243. }
  244. else
  245. {
  246. printf("%s BootMovie flashSize=0!!!\n", __FUNCTION__);
  247. }
  248. return retval;
  249. }
  250. static const char *getActiveFolderPath(void)
  251. {
  252. return FolderName;
  253. }
  254. static FileSystem_FileType_t getActiveFileType(void)
  255. {
  256. return VIDEO_FILETYPE;
  257. }
  258. static const char *getActiveFileName(void)
  259. {
  260. return FileName;
  261. }
  262. static int InitMpegEngine(char *const pFolderName, char *const pFileName)
  263. {
  264. APP_Audio_SetMute(TRUE, FALSE, APP_MUTE_MODE_STATEMAX, APP_SOURCE_MAX);
  265. APP_Video_Set_DISP_DTVSetVideoMute_ByUserSetting();
  266. memset(FolderName, 0, 64);
  267. snprintf(FolderName, 64, "%s", pFolderName);
  268. memset(FileName, 0, 64);
  269. snprintf(FileName, 64, "%s", pFileName);
  270. // Check file is exist or not
  271. char szFullPath[64] = { 0 };
  272. snprintf(szFullPath, 64, "%s/%s", pFolderName, pFileName);
  273. if (AL_Multimedia_FileSystem_IsFileExist(szFullPath) != TRUE)
  274. {
  275. printf("%s AL_Multimedia_FileSystem_IsFileExist!!!\n", __FUNCTION__);
  276. return SP_ERR_FAILURE;
  277. }
  278. //Init to Hook system
  279. AL_PLAYER_Hook_Func_List_t Hook_Api;
  280. Hook_Api.FileSystem_GetActiveFolderPath = getActiveFolderPath;
  281. Hook_Api.FileSystem_GetFileType = getActiveFileType;
  282. Hook_Api.FileSystem_GetActiveFileName = getActiveFileName;
  283. Hook_Api.FileSystem_BgMusic_GetFileName = NULL;
  284. Hook_Api.FileSystem_BgMusic_GetFolderPath = NULL;
  285. Hook_Api.FileSystem_BgPhoto_GetFileName = NULL;
  286. Hook_Api.FileSystem_BgPhoto_GetFolderPath = NULL;
  287. if (AL_Multimedia_Player_HookFileSystemAPI(Hook_Api) != AL_PLAYER_SUCCESS)
  288. {
  289. printf("%s BootMovie malloc buf fail!!!\n", __FUNCTION__);
  290. return SP_ERR_FAILURE;
  291. }
  292. return SP_SUCCESS;
  293. }
  294. static int StopMpegEngine(void)
  295. {
  296. AL_Multimeida_Player_IF_Uninit();
  297. return SP_SUCCESS;
  298. }
  299. static int PlayBootMovieFile(void)
  300. {
  301. AL_PLAYER_CtrlCmd_Info_t Player_Cmd_Info;
  302. AL_PLAYER_t AL_ret;
  303. Cmd_VipOverScanEn(FALSE);
  304. Cmd_VipAdjust(VIP_ASPECT_RATIO, ASPECT_FULL);
  305. AL_ret = AL_Multimedia_Player_RequestCommand(PLAYER_OPEN_SELECT_FILE, NULL);
  306. if (AL_ret != 0)
  307. {
  308. printf("%s PLAYER_OPEN_SELECT_FILE fail!!!\n", __FUNCTION__);
  309. return SP_ERR_FAILURE;
  310. }
  311. while (!bBootMovieInit)
  312. {
  313. if (bBootMovieFail)
  314. {
  315. return SP_ERR_FAILURE;
  316. }
  317. usleep(500000);
  318. }
  319. APP_Audio_SetMute(FALSE, FALSE, APP_MUTE_MODE_STATEMAX, APP_SOURCE_MEDIA);
  320. MID_DISP_DTVSetVideoUnmute();
  321. Player_Cmd_Info.Play_Param.FileType = getActiveFileType();
  322. Player_Cmd_Info.Play_Param.Play_Info.Video_Config.Program_Index = 0; //the app calculate the program from 0
  323. AL_ret = AL_Multimedia_Player_RequestCommand(PLAYER_PLAY, &Player_Cmd_Info);
  324. if (AL_ret != 0)
  325. {
  326. printf("%s PLAYER_PLAY fail!!!\n", __FUNCTION__);
  327. return SP_ERR_FAILURE;
  328. }
  329. while (!bBootMovieFinish)
  330. {
  331. if (bBootMovieFail)
  332. {
  333. return SP_ERR_FAILURE;
  334. }
  335. usleep(500000);
  336. }
  337. return SP_SUCCESS;
  338. }
  339. static void RemoveBootMovieFile(void)
  340. {
  341. char file_path[64] = { 0 };
  342. snprintf(file_path, 64, "rm -rf %s", BOOT_MOVIE_FOLDER);
  343. system(file_path);
  344. }
  345. static void SetPictureSetting(void)
  346. {
  347. PQ_Init();
  348. APP_Video_SetPictureMode(g_stPictureData.stPictureModeSourceTab[APP_STORAGE_SOURCE_MEDIA].PictureModeIndex);
  349. APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_HUE,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Tint);
  350. APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_SATURTUION,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Saturation);
  351. APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_CONTRAST,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Contrast);
  352. APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_BRIGHTNESS,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Brightness);
  353. APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_SHARPNESS,g_stPictureData.PictureMode[APP_SOURCE_MEDIA].stStandardTab.Sharpness);
  354. APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_COLORTEMP, g_stPictureData.stPictureModeSourceTab[APP_STORAGE_SOURCE_MEDIA].ColorTempIndex);
  355. APP_Video_OSD_PQSet(APP_VIDEO_OSD_ITEM_NR, g_stPictureData.NR);
  356. }
  357. static void SetVolumnSetting(void)
  358. {
  359. TVFE_Audio_Volume_t AUX_Volume_Config;
  360. INT16 i16VolumeValue = 0;
  361. INT16 i16VolumeOffset = 0;
  362. AL_Setting_Read(APP_Data_UserSetting_Handle(), SYS_SET_ID_VARIATIONAL, 0,
  363. sizeof(APP_SETTING_Variational_t), &(g_stVariationalData));
  364. AL_Setting_Read(APP_Data_UserSetting_Handle(), SYS_SET_ID_SYSINFO, 0,
  365. sizeof(APP_SETTING_SystemInfo_t), &(g_stSysInfoData));
  366. #ifdef CONFIG_SUPPORT_SOURCE_VOLUME_CURVE
  367. i16VolumeValue = g_stSysInfoData.szAudioVolumeTab[MEDIA_AUDIOVOLUME_TABLE][g_stVariationalData.Volume];
  368. #else
  369. i16VolumeValue = g_stSysInfoData.szAudioVolumeTab[AUDIOVOLUME_TABLE][g_stVariationalData.Volume];
  370. #endif
  371. i16VolumeOffset = g_arAudioVolumeOffset[APP_SOURCE_MEDIA].OffsetValue;;
  372. AUX_Volume_Config.Vol_Path = TVFE_AUDIO_VOL_MAIN_SD0_PATH;
  373. AUX_Volume_Config.Volume = i16VolumeValue;
  374. TVFE_Audio_Set_Volume(&AUX_Volume_Config, i16VolumeOffset);
  375. }
  376. static void StartBootMovie(void)
  377. {
  378. bBootMovieStart = TRUE;
  379. if (LoadBootMovieFromFlash() == SP_SUCCESS)
  380. {
  381. MID_DISP_DTVDisplayInit();
  382. AL_Setting_Read(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
  383. ITEM_OFFSET(APP_SETTING_FactoryUser_t, Function.SSCAdjust.n_Fun_SSC_Clk_Shift),
  384. sizeof(g_stFactoryUserData.Function.SSCAdjust.n_Fun_SSC_Clk_Shift),
  385. &(g_stFactoryUserData.Function.SSCAdjust.n_Fun_SSC_Clk_Shift));
  386. MID_TVFE_SetLVDS_CLOCK_Shift(g_stFactoryUserData.Function.SSCAdjust.n_Fun_SSC_Clk_Shift);
  387. SetPictureSetting();
  388. SetVolumnSetting();
  389. #if defined(CONFIG_CHIP_8506) || defined(CONFIG_CHIP_512L) || defined(CONFIG_CHIP_6710)
  390. #ifdef CONFIG_ENABLE_UMF_MODULES
  391. MID_DISP_MediaSetSource(INPUT_TYPE_USB);
  392. umf_loadModule(UMFMOD_MEDIA);
  393. umf_loadModule(UMFMOD_PICTURE);
  394. #endif
  395. if (InitMpegEngine(BOOT_MOVIE_FOLDER, BOOT_MOVIE_FILE) == SP_SUCCESS)
  396. {
  397. #ifdef CONFIG_ENABLE_UMF_MODULES
  398. umf_loadModule(UMFMOD_FFMPEG);
  399. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  400. TTOrSubModLoad(FALSE);
  401. #endif
  402. MID_DISP_MediaSetSource(INPUT_TYPE_MEDIA);
  403. extern void av_mmap_uninit(void);
  404. extern void av_mmap_init(void);
  405. av_mmap_uninit();
  406. av_mmap_init();
  407. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  408. /*when play movie, need load subtitle/TTx module.*/
  409. MMap_Init();
  410. #endif
  411. #endif
  412. PlayBootMovieFile();
  413. RemoveBootMovieFile();
  414. }
  415. StopMpegEngine();
  416. #ifdef CONFIG_ENABLE_UMF_MODULES
  417. umf_unloadModule(UMFMOD_FFMPEG);
  418. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  419. TTOrSubModUnload();
  420. #endif
  421. umf_unloadModule(UMFMOD_PICTURE);
  422. umf_unloadModule(UMFMOD_MEDIA);
  423. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  424. MMap_Uninit();
  425. #endif
  426. extern void av_mmap_uninit(void);
  427. av_mmap_uninit();
  428. #endif
  429. #else
  430. if (InitMpegEngine(BOOT_MOVIE_FOLDER, BOOT_MOVIE_FILE) == SP_SUCCESS)
  431. {
  432. PlayBootMovieFile();
  433. RemoveBootMovieFile();
  434. }
  435. StopMpegEngine();
  436. #endif
  437. }
  438. bBootMovieStart = FALSE;
  439. }
  440. void BootMovie_Event_Process(UINT32 event_id)
  441. {
  442. if (!bBootMovieStart)
  443. return;
  444. switch (event_id)
  445. {
  446. case PLAYER_AV_EVENT_DECODE_FINISH:
  447. UMFDBG(0, "%s PLAYER_AV_EVENT_DECODE_FINISH\n", __FUNCTION__);
  448. bBootMovieFinish = TRUE;
  449. break;
  450. case PLAYER_AV_EVENT_INITOK:
  451. UMFDBG(0, "%s PLAYER_AV_EVENT_INITOK\n", __FUNCTION__);
  452. bBootMovieInit = TRUE;
  453. break;
  454. case PLAYER_AV_EVENT_READERROR:
  455. case PLAYER_AV_EVENT_AUDIOUNSUPPORT:
  456. case PLAYER_AV_EVENT_VIDEOUNSUPPORT:
  457. case PLAYER_AV_EVENT_UNSUPPORT:
  458. UMFDBG(0, "%s BootMovieFail!!!\n", __FUNCTION__);
  459. bBootMovieFail = TRUE;
  460. break;
  461. default:
  462. break;
  463. }
  464. }
  465. #endif
  466. #ifdef CONFIG_SUPPORT_MIRACAST
  467. #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)
  468. #define P2pConfig_FILE "/etc/p2p_supplicant.conf"
  469. #elif defined(CONFIG_SUPPORT_MTK7601)
  470. #define P2pConfig_FILE "/etc/PersistentTable.conf"
  471. #endif
  472. typedef struct
  473. {
  474. INT32 size;
  475. UINT8 *data;
  476. } p2p_config_t;
  477. INT32 LoadP2pConfigFromFlash(void)
  478. {
  479. FILE *fp = NULL;
  480. p2p_config_t *p2p_config = NULL;
  481. INT32 size_flash = tv_GetSfsObjFileSize(ENVMPurposeIDP2PConfig);
  482. size_flash = size_flash < 0 ? 0 : size_flash;
  483. p2p_config = malloc(size_flash);
  484. if (p2p_config == NULL)
  485. {
  486. printf("malloc error!!!\n");
  487. return -1;
  488. }
  489. if (size_flash > 0)
  490. {
  491. Cmd_NVMRead(ENVMPurposeIDP2PConfig,FALSE, size_flash, (UINT8 *)p2p_config);
  492. p2p_config->data = (UINT8 *)p2p_config+sizeof(p2p_config_t);
  493. printf("p2p_config:0x%08x ,p2p_config->data::0x%08x\n", (UINT32)p2p_config,(UINT32)p2p_config->data);
  494. #ifdef CONFIG_SUPPORT_MULTI_DONGLE
  495. if(miracast_get_dongle() == Dongle_RTK_8188FTV)
  496. fp = fopen("/etc/RTK_8188FTV/p2p_supplicant.conf", "w+");
  497. else if(miracast_get_dongle() == Dongle_MTK_7601)
  498. fp = fopen("/etc/MTK_7601/p2p_supplicant.conf", "w+");
  499. else
  500. printf("Didn't insert dongle \n");
  501. #else
  502. fp = fopen(P2pConfig_FILE, "w+");
  503. #endif
  504. if (fp == NULL)
  505. {
  506. printf("fopen file ERR\n");
  507. perror("@@@@@@@@@@@@@@@@@@@\n");
  508. free(p2p_config);
  509. p2p_config = NULL;
  510. return -1;
  511. }
  512. INT32 writeRet = 0;
  513. printf("p2p_config->size:%d \n", p2p_config->size);
  514. size_flash = p2p_config->size;
  515. writeRet = fwrite(p2p_config->data, 1, size_flash, fp);
  516. fclose(fp);
  517. if (p2p_config != NULL)
  518. {
  519. free(p2p_config);
  520. p2p_config = NULL;
  521. }
  522. if (writeRet != size_flash)
  523. {
  524. printf("write error!!\n");
  525. return -1;
  526. }
  527. }
  528. free(p2p_config);
  529. return 0;
  530. }
  531. int WriteP2pConfigToFlash(void)
  532. {
  533. INT32 ret = 0;
  534. FILE *fp = NULL;
  535. p2p_config_t *p2p_config = NULL;
  536. int size_file = 0;
  537. int size_read = 0;
  538. #ifdef CONFIG_SUPPORT_MULTI_DONGLE
  539. if(miracast_get_dongle() == Dongle_RTK_8188FTV)
  540. fp = fopen("/etc/RTK_8188FTV/p2p_supplicant.conf", "rb");
  541. else if(miracast_get_dongle() == Dongle_MTK_7601)
  542. fp = fopen("/etc/MTK_7601/p2p_supplicant.conf", "rb");
  543. else
  544. printf("Didn't insert dongle \n");
  545. #else
  546. fp = fopen(P2pConfig_FILE, "rb" );
  547. #endif
  548. if (fp == NULL)
  549. {
  550. printf("[%s:%d] open file error \n", __FUNCTION__, __LINE__);
  551. return SP_ERR_FAILURE;
  552. }
  553. fseek(fp, 0, SEEK_END);
  554. size_file = ftell(fp);
  555. p2p_config =malloc(size_file+sizeof(p2p_config_t));
  556. if (p2p_config == NULL)
  557. {
  558. printf("malloc error!!!\n");
  559. fclose(fp);
  560. return -1;
  561. }
  562. memset(p2p_config, 0, size_file+sizeof(p2p_config_t));
  563. fseek(fp, 0, SEEK_SET);
  564. p2p_config->data = (UINT8 *)p2p_config+sizeof(p2p_config_t);
  565. size_read = fread(p2p_config->data, 1, size_file, fp);
  566. p2p_config->size = size_read;
  567. //p2p_config->data[size_read+4] = '\0';
  568. fclose(fp);
  569. printf("p2p_config= 0x%x size_file:%d size_read:%d \n", (UINT32)p2p_config, size_file, size_read);
  570. ret = Cmd_NVMWrite(ENVMPurposeIDP2PConfig,FALSE, size_read+sizeof(p2p_config_t), (UINT8 *)p2p_config);
  571. if(ret != 0)
  572. {
  573. printf("[error %s %d] (%d)\n",__FUNCTION__,__LINE__,ret);
  574. }
  575. if (p2p_config != NULL)
  576. {
  577. free(p2p_config);
  578. p2p_config = NULL;
  579. }
  580. return SP_SUCCESS;
  581. }
  582. #endif
  583. int umf_Init(void)
  584. {
  585. int retval, umfPid;
  586. //----- Open kmf dev -----
  587. g_umfdev.kmfdev = open(SISKMF_DEV_FILE, O_RDWR);
  588. if (g_umfdev.kmfdev <= 0)
  589. {
  590. DEBF("Unable to open %s\n", SISKMF_DEV_FILE);
  591. //return -1;
  592. }
  593. kmfdev = g_umfdev.kmfdev;
  594. //----- Open rtc dev -----
  595. g_umfdev.rtcdev = open(SISRTC_DEV_FILE, O_RDWR);
  596. if (g_umfdev.rtcdev <= 0)
  597. {
  598. DEBF("Unable to open %s\n", SISRTC_DEV_FILE);
  599. //return -1;
  600. }
  601. rtcdev = g_umfdev.rtcdev;
  602. //----- Open audiorx dev -----
  603. g_umfdev.audiodev = open(SISAUDIO_DEV_FILE, O_RDWR);
  604. if (g_umfdev.audiodev <= 0)
  605. {
  606. DEBF("Unable to open %s\n", SISAUDIO_DEV_FILE);
  607. //return -1;
  608. }
  609. audiodev = g_umfdev.audiodev;
  610. //----- Open dtv dev -----
  611. g_umfdev.dtvdev = open( SIS_DEMUX_DEVICE, O_RDWR );;
  612. if (g_umfdev.dtvdev <= 0)
  613. {
  614. DEBF("Unable to open %s\n", SIS_DEMUX_DEVICE);
  615. //return -1;
  616. }
  617. dtvdev = g_umfdev.dtvdev;
  618. //----- Load data -----
  619. retval = umf_MapKMFShareData(&g_umfdev);
  620. if (retval != 0)
  621. {
  622. DEBF("mmap KMF Share Data Fail\n");
  623. //return retval;
  624. }
  625. umf_GetData();
  626. #if (defined(SUPPORT_FACTORY_AUTO_TEST_MODE2))
  627. tv_GetACSpecialFileStatus(&gacSpecialFileStatus);
  628. if((gacSpecialFileStatus & 0x01) == 0x01)
  629. {
  630. if((gacSpecialFileStatus & 0x02) == 0x02)
  631. {
  632. APP_Factory_SetAutoTestOnOff(FALSE);
  633. }
  634. else
  635. {
  636. APP_Factory_SetAutoTestOnOff(TRUE);
  637. #ifdef SUPPORT_FACTORY_AUTO_TEST_BAR_MENU_DISPLAY_CRC
  638. tvGetModuleCheckSum();
  639. #endif
  640. }
  641. }
  642. #elif defined(SUPPORT_FACTORY_AUTO_TEST)
  643. tv_GetACSpecialFileStatus(&gacSpecialFileStatus);
  644. if((gacSpecialFileStatus & 0x01) == 0x01)
  645. {
  646. APP_Factory_SetAutoTestOnOff(TRUE);
  647. UINT8 retval = 0;
  648. Cmd_mmio_ReadUINT8(0xbe0f0523, &retval);//check upgrade or not
  649. if((retval & 0x0C))
  650. {
  651. Cmd_mmio_WriteUINT8mask(0xbe0f0523, 0x00, 0x0c);
  652. APP_Factory_SetUpgradeandAutoTestFlag(TRUE);
  653. APP_SetPoweronEnterVersion(1);//show the menu of version
  654. }
  655. }
  656. if(APP_Factory_GetAutoTestOnOff()==TRUE)
  657. {
  658. Enable_Debug_Message(0);
  659. }
  660. else
  661. {
  662. // Enable_Debug_Message(1<<MODULEID_UMF);
  663. }
  664. #else
  665. // Enable_Debug_Message(1<<MODULEID_UMF);
  666. #endif
  667. if(!g_pKMFShareData->bUartATx)
  668. {
  669. tv_SetUartATx(FALSE);
  670. }
  671. //--Regist Signal Callback function and UMF PID--
  672. tv_GetRTCTimetoSys();
  673. regist_SignalEvent();
  674. #ifdef CONFIG_AUTO_USB_STORE_IRSEQ
  675. extern int AUTO_IF_Regist_SignalEvent(void);
  676. AUTO_IF_Regist_SignalEvent();
  677. #endif
  678. umfPid = getpid();
  679. ioctl(g_umfdev.kmfdev, KMF_IOC_SET_UMFPID, umfPid);
  680. #ifndef CONFIG_SYSTEM_WATCHDOG_DISABLE
  681. extern void wdog_init(void);
  682. wdog_init();
  683. #endif
  684. event_Init();
  685. #ifdef CONFIG_CI_SUPPORT
  686. extern BOOLEAN STB_CIOpen(UINT8 slot_id);
  687. STB_CIOpen(0);
  688. #endif
  689. #ifdef CONFIG_SUPPORT_MIRACAST
  690. LoadP2pConfigFromFlash();
  691. #endif
  692. Cmd_NVMInital();
  693. DEBF("****** umf_Init finish ****** \n\n");
  694. DEBF("Build code at %s %s \n\n",__TIME__,__DATE__);
  695. return retval;
  696. }
  697. void SW_init(void)
  698. {
  699. /* app user setting initial */
  700. APP_Data_UserSetting_Init();
  701. APPSourceConfigTable_Init();//add for sourceconfig
  702. APP_GOBJ_Source_Get_Support_InputSource_String();//add for new source table
  703. #ifdef CONFIG_SUPPORT_BOOT_MOVIE
  704. 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
  705. #endif
  706. #if (defined(SUPPORT_FACTORY_AUTO_TEST)||defined(SUPPORT_FACTORY_AUTO_TEST_MODE2))
  707. if((gacSpecialFileStatus & 0x02) == 0x02 && FALSE == APP_Factory_GetAutoTestOnOff())
  708. {
  709. g_stFactoryUserData.n_FactSet_BurningMode = 1;
  710. AL_Setting_Write(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
  711. ITEM_OFFSET(APP_SETTING_FactoryUser_t, n_FactSet_BurningMode),
  712. sizeof(g_stFactoryUserData.n_FactSet_BurningMode),&(g_stFactoryUserData.n_FactSet_BurningMode));
  713. AL_Setting_Store(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
  714. ITEM_OFFSET(APP_SETTING_FactoryUser_t, n_FactSet_BurningMode),
  715. sizeof(g_stFactoryUserData.n_FactSet_BurningMode));
  716. Cmd_gpio_WriteOnLevel(GPIO_BL_ON_PIN);
  717. }
  718. else if(APP_Factory_GetAutoTestOnOff()==TRUE)
  719. {
  720. g_stFactoryUserData.n_FactSet_BurningMode = 0;
  721. AL_Setting_Write(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
  722. ITEM_OFFSET(APP_SETTING_FactoryUser_t, n_FactSet_BurningMode),
  723. sizeof(g_stFactoryUserData.n_FactSet_BurningMode),&(g_stFactoryUserData.n_FactSet_BurningMode));
  724. AL_Setting_Store(APP_Data_UserSetting_Handle(), SYS_SET_ID_FACTUSER,
  725. ITEM_OFFSET(APP_SETTING_FactoryUser_t, n_FactSet_BurningMode),
  726. sizeof(g_stFactoryUserData.n_FactSet_BurningMode));
  727. }
  728. #endif
  729. #ifdef SUPPORT_HDMI_SWITCH_EDID
  730. HDMI_Switch_Init();
  731. #endif
  732. #ifdef CONFIG_MOD_PACK_SUB
  733. //when the marco is opened, need call this api after load Subtitle module.
  734. #else
  735. #if defined(CONFIG_MEDIA_ENABLE) || defined(CONFIG_SUPPORT_SUBTITLE)
  736. extern void MID_Subtitle_constructor();
  737. MID_Subtitle_constructor(); // constructor function for DTV & Media Subtitle
  738. #endif
  739. #endif
  740. #ifdef CONFIG_SUPPORT_BOOT_MOVIE
  741. StartBootMovie();
  742. #endif
  743. }
  744. #ifdef CONFIG_CALL_TRACE
  745. extern void direct_trace_print_stacks(void);
  746. extern void direct_set_output_fd(int);
  747. __attribute__((no_instrument_function))
  748. static void dump_cpu_registers(ucontext_t *uc)
  749. {
  750. printf("special registers:\n");
  751. printf(" $pc: 0x%08x\n",(unsigned int)uc->uc_mcontext.pc);
  752. printf(" $ra: 0x%08x\n\n",(unsigned int) uc->uc_mcontext.gregs[31]);
  753. printf("generic registers:\n");
  754. printf(" $zo: 0x%08x $at: 0x%08x $v0: 0x%08x $v1: 0x%08x\n", \
  755. (unsigned int) uc->uc_mcontext.gregs[0], (unsigned int) uc->uc_mcontext.gregs[1], \
  756. (unsigned int) uc->uc_mcontext.gregs[2], (unsigned int) uc->uc_mcontext.gregs[3]);
  757. printf(" $a0: 0x%08x $a1: 0x%08x $a2: 0x%08x $a3: 0x%08x\n", \
  758. (unsigned int) uc->uc_mcontext.gregs[4], (unsigned int) uc->uc_mcontext.gregs[5], \
  759. (unsigned int) uc->uc_mcontext.gregs[6], (unsigned int) uc->uc_mcontext.gregs[7]);
  760. printf(" $t0: 0x%08x $t1: 0x%08x $t2: 0x%08x $t3: 0x%08x\n", \
  761. (unsigned int) uc->uc_mcontext.gregs[8], (unsigned int) uc->uc_mcontext.gregs[9], \
  762. (unsigned int) uc->uc_mcontext.gregs[10], (unsigned int) uc->uc_mcontext.gregs[11]);
  763. printf(" $t4: 0x%08x $t5: 0x%08x $t6: 0x%08x $t7: 0x%08x\n", \
  764. (unsigned int) uc->uc_mcontext.gregs[12], (unsigned int) uc->uc_mcontext.gregs[13], \
  765. (unsigned int) uc->uc_mcontext.gregs[14], (unsigned int) uc->uc_mcontext.gregs[15]);
  766. printf(" $s0: 0x%08x $s1: 0x%08x $s2: 0x%08x $s3: 0x%08x\n", \
  767. (unsigned int) uc->uc_mcontext.gregs[16], (unsigned int) uc->uc_mcontext.gregs[17], \
  768. (unsigned int) uc->uc_mcontext.gregs[18], (unsigned int) uc->uc_mcontext.gregs[19]);
  769. printf(" $s4: 0x%08x $s5: 0x%08x $s6: 0x%08x $s7: 0x%08x\n", \
  770. (unsigned int) uc->uc_mcontext.gregs[20], (unsigned int) uc->uc_mcontext.gregs[21], \
  771. (unsigned int) uc->uc_mcontext.gregs[22], (unsigned int) uc->uc_mcontext.gregs[23]);
  772. printf(" $t8: 0x%08x $t9: 0x%08x $k0: 0x%08x $k1: 0x%08x\n", \
  773. (unsigned int) uc->uc_mcontext.gregs[24], (unsigned int) uc->uc_mcontext.gregs[25], \
  774. (unsigned int) uc->uc_mcontext.gregs[26], (unsigned int) uc->uc_mcontext.gregs[27]);
  775. printf(" $gp: 0x%08x $sp: 0x%08x $fp: 0x%08x\n\n", \
  776. (unsigned int) uc->uc_mcontext.gregs[28], (unsigned int) uc->uc_mcontext.gregs[29], \
  777. (unsigned int) uc->uc_mcontext.gregs[30]);
  778. }
  779. __attribute__((no_instrument_function))
  780. static void signal_handler(int signo, siginfo_t* info, void*ptr)
  781. {
  782. int outfd;
  783. unsigned long long tmp_time;
  784. struct timeval tv;
  785. char output_filename[64];
  786. ucontext_t *uc;
  787. uc = (ucontext_t *) ptr;
  788. printf("\n[SIGNAL HANDLER] Pid: %d Catch SIGNO %d\n\n",getpid(),signo);
  789. dump_cpu_registers(uc);
  790. printf("Call Trace:\n");
  791. direct_trace_print_stacks();
  792. gettimeofday(&tv, NULL);
  793. tmp_time = tv.tv_sec * 1000000 + tv.tv_usec;
  794. memset(output_filename,'\0',64);
  795. sprintf(output_filename,"/mnt/sda1/trace%lld",tmp_time);
  796. outfd = open(output_filename,O_RDWR | O_CREAT);
  797. if (outfd > 0) {
  798. direct_set_output_fd(outfd);
  799. direct_trace_print_stacks();
  800. close(outfd);
  801. printf("[SIGNAL HANDLER] Create %s success.\n", output_filename);
  802. }
  803. system("word 0xbe1cc050 0x00ff0000");
  804. sync();
  805. signal(signo, SIG_DFL);
  806. kill(getpid(),signo);
  807. }
  808. static void signals_initialize(void)
  809. {
  810. unsigned int i;
  811. struct sigaction action;
  812. int sigs_to_handle[] = { SIGHUP, SIGTERM, SIGABRT, SIGFPE,
  813. SIGILL, SIGQUIT, SIGSEGV, SIGTRAP,
  814. SIGBUS, SIGXCPU, SIGXFSZ};
  815. memset(&action, 0, sizeof(action));
  816. action.sa_sigaction = signal_handler;
  817. action.sa_flags = SA_SIGINFO;
  818. for (i = 0; i < (sizeof(sigs_to_handle)>>2); i++)
  819. if(sigaction(sigs_to_handle[i], &action, NULL) < 0)
  820. perror("sigaction");
  821. }
  822. #endif
  823. #if defined(CONFIG_UMF_ONLYONECOPY_DATASECTION)
  824. static void mmap_data_section(void)
  825. {
  826. int fd;
  827. unsigned int i,j;
  828. unsigned char *ptr;
  829. sismmio_ioctl_section_remap remap;
  830. remap.opt=0;
  831. fd = open("/dev/sismmio",O_RDWR);
  832. ioctl(fd, SISMMIO_SECTIION_REMAP, &remap);
  833. ptr = (unsigned char *)remap.vaddr_start;
  834. for (i=0; i < remap.length; i+=getpagesize()){
  835. j = *(volatile unsigned char *)(ptr+i);
  836. j = j;
  837. }
  838. remap.opt=1;
  839. ioctl(fd, SISMMIO_SECTIION_REMAP, &remap);
  840. close(fd);
  841. }
  842. #endif
  843. #ifdef CONFIG_SUPPORT_MONITOR_POWERSAVE
  844. int gcov_power_off_flag = false;
  845. #endif
  846. #ifdef CONFIG_NOT_USEBB
  847. int umf_main(int argc, char* argv[])
  848. #else
  849. int main(int argc, char* argv[])
  850. #endif
  851. {
  852. #if defined(CONFIG_UMF_ONLYONECOPY_DATASECTION)
  853. mmap_data_section();
  854. #endif
  855. #ifdef CONFIG_CALL_TRACE
  856. signals_initialize();
  857. #endif
  858. umf_Init();
  859. /* AFW initialize public module */
  860. AL_FW_Init(FW_MAIN_INIT, MAINAPP_FW_Callback, MAINAPP_FW_GetContext);
  861. SW_init();
  862. MainApp_InitCfg_t stMainAppInit =
  863. {
  864. .pfInitFlow = MAINAPP_InitFlow,
  865. .pGUIObjectTable = MAIN_APP_GUI_Obj_List,
  866. .pfOnTimerUpdate = MAINAPP_OnTimerUpdate,
  867. .pfOnEvent = MAINAPP_OnEvent
  868. };
  869. MAINAPP_Initialize(&stMainAppInit);
  870. /* Debug only */
  871. #ifdef CONFIG_CIPLUS_TEST
  872. MID_DTVCI_DebugInit();
  873. #endif
  874. #ifdef CONFIG_SUPPORT_MONITOR_POWERSAVE
  875. while (gcov_power_off_flag != true)
  876. {
  877. sleep(1);
  878. }
  879. close(g_umfdev.kmfdev);
  880. close(g_umfdev.rtcdev);
  881. close(g_umfdev.audiodev);
  882. close(g_umfdev.dtvdev);
  883. system("./PowerSave &");
  884. #else
  885. while (1)
  886. {
  887. sleep(100);
  888. }
  889. #endif
  890. return 0;
  891. }