main.c 26 KB

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