umf_mod.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <sys/mman.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <string.h>
  9. #include <errno.h>
  10. #include <time.h>
  11. #include <sys/ioctl.h>
  12. #include "types.h"
  13. #include "nvm_ioctl.h"
  14. #include "umf_mod.h"
  15. #include "umf_debug.h"
  16. #include <umf_debug.h>
  17. #include "subcustomer_setting.h"
  18. #include "al_setting.h"
  19. #include "app_data_setting.h"
  20. #if defined(CONFIG_UMF_ONLYONECOPY_DATASECTION)
  21. #include "sismmio.h"
  22. #endif
  23. #ifdef CONFIG_ENABLE_UMF_LANGUAGE_MODULES
  24. #include "umf_langmod.h"
  25. #include "subcustomer_setting.h"
  26. #include "al_setting.h"
  27. #include "app_data_setting.h"
  28. #endif
  29. #include "kmf_ioctl.h"
  30. #include "ap_extern.h"
  31. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  32. #include "mmap_malloc.h"
  33. #include "al_teletext.h"
  34. #ifdef CONFIG_MOD_PACK_SUB
  35. #include "mid_sub.h"
  36. #endif
  37. #endif
  38. #define MOD_DEBUG
  39. #ifdef MOD_DEBUG
  40. #undef DEBF
  41. #define DEBF(fmt, arg...) UMFDBG(0,fmt, ##arg)
  42. #else
  43. #define DEBF(fmt, arg...)
  44. #endif
  45. #ifdef CONFIG_ENABLE_UMF_MODULES
  46. #define MEASURE_LOADING_TIME
  47. #define MODULE_INFO_FILE "/tmp/mod.info"
  48. typedef struct
  49. {
  50. INT32 fd;
  51. UINT32 gotRtInfo;
  52. UINT32 vma; /* module runtime address(4k alignment) in umf VMA */
  53. UINT32 size; /* module size */
  54. UINT32 dataSegStart; /* start address of data section and bss section */
  55. UINT32 dataSegSize; /* sizeof data section and bss section */
  56. UINT32 bLoaded;
  57. } ModRtInfo_t;
  58. typedef struct
  59. {
  60. UMFMOD_ID eModID; /* module's ID */
  61. UINT8 *pModFlashName; /* module's tag in flash image, refer to mergedir/flash_layout.gyp */
  62. UINT8 *pModFSFile; /* file's name after load module data from flash */
  63. UINT8 *pModSegName; /* module segment name, refer to aps/application/customer/appfolder/umflink.ld */
  64. ModRtInfo_t stModRtInfo; /* it's a slot to store runtime information when this module is loaded */
  65. } ModuleParam_t;
  66. #ifdef CONFIG_ENABLE_UMF_LANGUAGE_MODULES
  67. static UMFMOD_ID g_LangModeIndex = UMFMOD_MAX;
  68. static Boolean g_AllLangIsMemory = FALSE;
  69. #endif
  70. /* module informations & configuration area */
  71. static ModuleParam_t stModParam[UMFMOD_MAX] =
  72. {
  73. #ifdef CONFIG_MOD_PACK_MEDIA
  74. {UMFMOD_MEDIA, (UINT8 *)"ModMedia", (UINT8 *)"/tmp/umf.media", (UINT8 *)".media", {-1, 0, 0, 0, 0, 0, 0}},
  75. #else
  76. {-1, NULL, NULL, NULL, {-1, 0, 0, 0, 0, 0, 0}},
  77. #endif
  78. #ifdef CONFIG_MOD_PACK_PICLIB
  79. {UMFMOD_PICTURE, (UINT8 *)"ModPicture", (UINT8 *)"/tmp/umf.picture", (UINT8 *)".picture", {-1, 0, 0, 0, 0, 0, 0}},
  80. #else
  81. {-1, NULL, NULL, NULL, {-1, 0, 0, 0, 0, 0, 0}},
  82. #endif
  83. #ifdef CONFIG_MOD_PACK_RUNAV
  84. {UMFMOD_FFMPEG, (UINT8 *)"ModFfmpeg", (UINT8 *)"/tmp/umf.ffmpeg", (UINT8 *)".ffmpeg", {-1, 0, 0, 0, 0, 0, 0}},
  85. #else
  86. {-1, NULL, NULL, NULL, {-1, 0, 0, 0, 0, 0, 0}},
  87. #endif
  88. #ifdef CONFIG_MOD_PACK_ATV
  89. {UMFMOD_ATV, (UINT8 *)"ModAtv", (UINT8 *)"/tmp/umf.atv", (UINT8 *)".atv", {-1, 0, 0, 0, 0, 0, 0}},
  90. #else
  91. {-1, NULL, NULL, NULL, {-1, 0, 0, 0, 0, 0, 0}},
  92. #endif
  93. #ifdef CONFIG_MOD_PACK_DTV
  94. {UMFMOD_DTV, (UINT8 *)"ModDtv", (UINT8 *)"/tmp/umf.dtv", (UINT8 *)".dtv", {-1, 0, 0, 0, 0, 0, 0}},
  95. #else
  96. {-1, NULL, NULL, NULL, {-1, 0, 0, 0, 0, 0, 0}},
  97. #endif
  98. #ifdef CONFIG_MOD_PACK_TT
  99. {UMFMOD_TT, (UINT8 *)"ModTT", (UINT8 *)"/tmp/umf.teletext", (UINT8 *)".teletext", {-1, 0, 0, 0, 0, 0, 0}},
  100. #else
  101. {-1, NULL, NULL, NULL, {-1, 0, 0, 0, 0, 0, 0}},
  102. #endif
  103. #ifdef CONFIG_MOD_PACK_SUB
  104. {UMFMOD_SUB, (UINT8 *)"ModSub", (UINT8 *)"/tmp/umf.subtitle", (UINT8 *)".subtitle", {-1, 0, 0, 0, 0, 0, 0}},
  105. #else
  106. {-1, NULL, NULL, NULL, {-1, 0, 0, 0, 0, 0, 0}},
  107. #endif
  108. #ifdef CONFIG_ENABLE_UMF_LANGUAGE_MODULES
  109. /*langMode begin(This context is auto generated by ./tools/gen_LangMode.py please don't modify.)*/
  110. {UMFMOD_TV_IDL_Spanish, (UINT8 *)"Spanish", (UINT8 *)"/tmp/umf.TV_IDL_Spanish", (UINT8 *)".TV_IDL_Spanish", {-1, 0, 0, 0, 0, 0, 0}},
  111. {UMFMOD_TV_IDL_French, (UINT8 *)"French", (UINT8 *)"/tmp/umf.TV_IDL_French", (UINT8 *)".TV_IDL_French", {-1, 0, 0, 0, 0, 0, 0}},
  112. {UMFMOD_TV_IDL_German, (UINT8 *)"German", (UINT8 *)"/tmp/umf.TV_IDL_German", (UINT8 *)".TV_IDL_German", {-1, 0, 0, 0, 0, 0, 0}},
  113. {UMFMOD_TV_IDL_Italian, (UINT8 *)"Italian", (UINT8 *)"/tmp/umf.TV_IDL_Italian", (UINT8 *)".TV_IDL_Italian", {-1, 0, 0, 0, 0, 0, 0}},
  114. {UMFMOD_TV_IDL_Portuguese, (UINT8 *)"Portuguese", (UINT8 *)"/tmp/umf.TV_IDL_Portuguese", (UINT8 *)".TV_IDL_Portuguese", {-1, 0, 0, 0, 0, 0, 0}},
  115. {UMFMOD_TV_IDL_Polish, (UINT8 *)"Polish", (UINT8 *)"/tmp/umf.TV_IDL_Polish", (UINT8 *)".TV_IDL_Polish", {-1, 0, 0, 0, 0, 0, 0}},
  116. {UMFMOD_TV_IDL_Russian, (UINT8 *)"Russian", (UINT8 *)"/tmp/umf.TV_IDL_Russian", (UINT8 *)".TV_IDL_Russian", {-1, 0, 0, 0, 0, 0, 0}},
  117. {UMFMOD_TV_IDL_Finnish, (UINT8 *)"Finnish", (UINT8 *)"/tmp/umf.TV_IDL_Finnish", (UINT8 *)".TV_IDL_Finnish", {-1, 0, 0, 0, 0, 0, 0}},
  118. {UMFMOD_TV_IDL_Swedish, (UINT8 *)"Swedish", (UINT8 *)"/tmp/umf.TV_IDL_Swedish", (UINT8 *)".TV_IDL_Swedish", {-1, 0, 0, 0, 0, 0, 0}},
  119. {UMFMOD_TV_IDL_Greek, (UINT8 *)"Greek", (UINT8 *)"/tmp/umf.TV_IDL_Greek", (UINT8 *)".TV_IDL_Greek", {-1, 0, 0, 0, 0, 0, 0}},
  120. {UMFMOD_TV_IDL_Dutch, (UINT8 *)"Dutch", (UINT8 *)"/tmp/umf.TV_IDL_Dutch", (UINT8 *)".TV_IDL_Dutch", {-1, 0, 0, 0, 0, 0, 0}},
  121. {UMFMOD_TV_IDL_English, (UINT8 *)"English", (UINT8 *)"/tmp/umf.TV_IDL_English", (UINT8 *)".TV_IDL_English", {-1, 0, 0, 0, 0, 0, 0}},
  122. {UMFMOD_TV_IDL_Schinese, (UINT8 *)"Schinese", (UINT8 *)"/tmp/umf.TV_IDL_Schinese", (UINT8 *)".TV_IDL_Schinese", {-1, 0, 0, 0, 0, 0, 0}},
  123. /*langMode end.(This context is auto generated by ./tools/gen_LangMode.py please don't modify.)*/
  124. #endif
  125. };
  126. extern int LzDecode(void *inFile, void *outFile, size_t inFileSize, unsigned char reserveMm);
  127. static ModuleParam_t* umf_findModule(UMFMOD_ID eID)
  128. {
  129. ModuleParam_t *pModParam = NULL;
  130. UINT32 iter = 0;
  131. FILE *fp = NULL;
  132. INT8 tmpModSegName[80];
  133. UINT32 size = 0;
  134. UINT32 vma = 0;
  135. UINT32 dataSegStart = 0;
  136. UINT32 dataSegEnd = 0;
  137. INT32 found = 0;
  138. while (iter < UMFMOD_MAX)
  139. {
  140. if (stModParam[iter].eModID == eID)
  141. {
  142. pModParam = &stModParam[iter];
  143. break;
  144. }
  145. iter++;
  146. }
  147. if (iter < UMFMOD_MAX && !pModParam->stModRtInfo.gotRtInfo)
  148. {
  149. if (pModParam->stModRtInfo.fd == -1)
  150. {
  151. fp = fopen(MODULE_INFO_FILE, "r");
  152. if (fp == NULL)
  153. {
  154. printf("[%s,%d]open %s fail.\n", __FUNCTION__, __LINE__, MODULE_INFO_FILE);
  155. return NULL;
  156. }
  157. while (!feof(fp))
  158. {
  159. memset(tmpModSegName, 0, 80);
  160. fscanf(fp, "%80s %x %x %x %x", tmpModSegName, &size, &vma, &dataSegStart, &dataSegEnd);
  161. if (strcmp(tmpModSegName, (INT8*)stModParam[iter].pModSegName) == 0)
  162. {
  163. found = 1;
  164. pModParam->stModRtInfo.vma = vma;
  165. pModParam->stModRtInfo.size = size;
  166. pModParam->stModRtInfo.dataSegStart = dataSegStart;
  167. pModParam->stModRtInfo.dataSegSize = dataSegEnd - dataSegStart;
  168. UMFDBG(0, "Module:%s\tVMA:0x%08x Size:0x%08x DataSegStart:0x%08x DataSegEnd:0x%08x\n",
  169. (char*)&tmpModSegName, vma, size, dataSegStart, dataSegEnd);
  170. pModParam->stModRtInfo.gotRtInfo = 1;
  171. break;
  172. }
  173. }
  174. fclose(fp);
  175. if (!found)
  176. {
  177. return NULL;
  178. }
  179. }
  180. }
  181. return pModParam;
  182. }
  183. INT32 umf_loadModule(UMFMOD_ID eID)
  184. {
  185. UMFDBG(0, "Enter %s\n", __FUNCTION__);
  186. ModuleParam_t *pMod = umf_findModule(eID);
  187. void *ptr = NULL;
  188. void *dataPtr = NULL;
  189. UINT32 modSizeC = 0; /* compressed size */
  190. UINT32 modSizeNC = 0; /* uncompressed size */
  191. void *pSrcBuf = NULL;
  192. UINT8 *destBuf = NULL;
  193. UINT32 u32FlashSize = 0; /*This is flash driver information*/
  194. unsigned char reserveMm = FALSE;
  195. #if defined(CONFIG_CHIP_512L) || defined (CONFIG_SUPPORT_64M_DTV) || defined (CONFIG_RUNAV_USE_RESERVE_MEMORY)
  196. input_type_t eInputType = INPUT_TYPE_DISABLE;
  197. MID_DISP_DTVGetInputType(&eInputType);
  198. #endif
  199. #ifdef MEASURE_LOADING_TIME
  200. struct timespec pre_tp, post_tp;
  201. struct timespec result;
  202. clock_gettime(CLOCK_MONOTONIC, &pre_tp);
  203. #endif
  204. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  205. static UMFMOD_ID pre_id = UMFMOD_MAX;
  206. #endif
  207. if (!pMod)
  208. {
  209. printf("[%s,%d]find module fail,eID:%d\n", __FUNCTION__, __LINE__, eID);
  210. return -1;
  211. }
  212. if (pMod->stModRtInfo.bLoaded) /* this module has been loaded */
  213. {
  214. printf("[%s,%d]this module has been loaded,eID:%d\n", __FUNCTION__, __LINE__, eID);
  215. return 0;
  216. }
  217. void* pMAP = NULL;
  218. int fd = 0;
  219. FlashTableSearch_t flashtable = {0};
  220. flashtable.pTag = (void *)(pMod->pModFlashName);
  221. flashtable.Addr = 0;
  222. flashtable.Flashddr = 0;
  223. flashtable.size = 0;
  224. ioctl(kmfdev, KMF_IOC_LookupFlashTable, &flashtable);
  225. if ((fd=open("/dev/mem", O_RDWR | O_DSYNC)) < 0)
  226. {
  227. UMFDBG(0, "[%s,%d] open /dev/mem fail. error:%s\n", __FUNCTION__,__LINE__, strerror(errno));
  228. return -1;
  229. }
  230. u32FlashSize = Cmd_GetFlashSize();
  231. pMAP = mmap(0, u32FlashSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x1c000000);
  232. pSrcBuf = pMAP+(flashtable.Flashddr&0x00ffffff);
  233. modSizeC = flashtable.size;
  234. printf("[%s:%d] ++++++++++++++++++++modSizeNC: %d, modSizeC: %d\n",__FUNCTION__,__LINE__,*(UINT32*)pSrcBuf, modSizeC);
  235. modSizeNC = *(UINT32*)pSrcBuf;
  236. printf("pMod->pModFlashName is %s\n\n",pMod->pModFlashName);
  237. if (pMod->stModRtInfo.size != modSizeNC)
  238. {
  239. UMFDBG(0, "Size not equal, maybe this module don't we need?(%d,%d)\n",
  240. pMod->stModRtInfo.size, modSizeNC);
  241. goto FAIL2;
  242. }
  243. if((pMod->stModRtInfo.fd = open((INT8*)pMod->pModFSFile, O_RDWR|O_CREAT|O_SYNC)) < 0)
  244. {
  245. UMFDBG(0, "[%s,%d] open %s fail. error:%s\n", __FUNCTION__,__LINE__,
  246. pMod->pModFSFile,strerror(errno));
  247. goto FAIL2;
  248. }
  249. /* create a empty file with length modSizeNC and a space tail */
  250. if(-1 == lseek(pMod->stModRtInfo.fd, (off_t)(modSizeNC - 1), SEEK_SET))
  251. {
  252. UMFDBG(0, "[%s,%d] lseek fail. error:%s\n", __FUNCTION__,__LINE__,strerror(errno));
  253. goto FAIL1;
  254. }
  255. if(1 != write(pMod->stModRtInfo.fd, " ", 1))
  256. {
  257. UMFDBG(0, "[%s,%d] write file fail. error:%s\n", __FUNCTION__,__LINE__,strerror(errno));
  258. goto FAIL1;
  259. }
  260. if((destBuf = mmap(NULL, pMod->stModRtInfo.size,
  261. PROT_READ|PROT_WRITE, MAP_SHARED, pMod->stModRtInfo.fd, 0)) == MAP_FAILED)
  262. {
  263. printf("[%s,%d]mmap fail. error: %s\n", __FUNCTION__, __LINE__,strerror(errno));
  264. goto FAIL1;
  265. }
  266. else
  267. {
  268. memset(destBuf, 0, modSizeNC);
  269. }
  270. #if defined(CONFIG_CHIP_512L) || defined (CONFIG_SUPPORT_64M_DTV)
  271. #ifdef CONFIG_DVB_SYSTEM_DVBT2_SUPPORT //TT2C
  272. if ((eInputType == INPUT_TYPE_MEDIA) || (eInputType == INPUT_TYPE_USB))
  273. {
  274. reserveMm = TRUE; //compression use t2 demod reserved mem
  275. }
  276. #ifdef CONFIG_SUPPORT_PVR
  277. else
  278. {
  279. reserveMm = TRUE;
  280. }
  281. #endif
  282. #else //TCS
  283. #ifdef CONFIG_SUPPORT_PVR
  284. if (eInputType != INPUT_TYPE_USB)
  285. {
  286. reserveMm = TRUE;
  287. }
  288. #endif
  289. #endif
  290. /*when use subtitle reverse memory, need mmap uninit by TT and subtitle module.*/
  291. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  292. if ((!(pre_id == UMFMOD_TT && eID == UMFMOD_SUB)) && (eID <= UMFMOD_SUB) )
  293. {
  294. #ifdef CONFIG_MOD_PACK_TT
  295. AL_TTX_Stop();
  296. #endif
  297. TTOrSubModUnload();
  298. }
  299. #endif
  300. #endif
  301. #if ((defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)) && (defined CONFIG_ENABLE_UMF_LANGUAGE_MODULES)
  302. if (eID > UMFMOD_SUB && eID < UMFMOD_MAX)
  303. {
  304. reserveMm = 2;
  305. }
  306. #endif
  307. #ifdef CONFIG_RUNAV_USE_RESERVE_MEMORY
  308. if(((eInputType == INPUT_TYPE_MEDIA) || (eInputType == INPUT_TYPE_USB)) && eID == UMFMOD_FFMPEG)
  309. reserveMm = TRUE;
  310. #endif
  311. if (0 != LzDecode((UINT8 *)pSrcBuf + sizeof(INT32), (void *)destBuf, modSizeC - sizeof(INT32), reserveMm))
  312. {
  313. printf("[%s,%d]decompress %s error!\n", __FUNCTION__, __LINE__, pMod->pModFlashName);
  314. munmap(destBuf, pMod->stModRtInfo.size);
  315. goto FAIL1;
  316. }
  317. munmap(destBuf, pMod->stModRtInfo.size);
  318. /* now mapping this module to umf's VMA */
  319. if((ptr = mmap((void*)pMod->stModRtInfo.vma, pMod->stModRtInfo.size - pMod->stModRtInfo.dataSegSize,
  320. PROT_READ|PROT_EXEC, MAP_PRIVATE, pMod->stModRtInfo.fd, 0)) != (void*)pMod->stModRtInfo.vma)
  321. {
  322. printf("[%s,%d]the mapped address(%p) don't we needed(0x%08x), module loading fail!.\n",
  323. __FUNCTION__, __LINE__, ptr, pMod->stModRtInfo.vma);
  324. goto FAIL1;
  325. }
  326. if (pMod->stModRtInfo.dataSegSize)
  327. {
  328. if((dataPtr = mmap((void*)pMod->stModRtInfo.dataSegStart, pMod->stModRtInfo.dataSegSize,
  329. PROT_READ|PROT_WRITE, MAP_PRIVATE, pMod->stModRtInfo.fd,
  330. pMod->stModRtInfo.dataSegStart - pMod->stModRtInfo.vma)) != (void*)pMod->stModRtInfo.dataSegStart)
  331. {
  332. printf("[%s,%d]the mapped address(%p) don't we needed(0x%08x), module loading fail!.\n",
  333. __FUNCTION__, __LINE__, dataPtr, pMod->stModRtInfo.dataSegStart);
  334. goto FAIL1;
  335. }
  336. }
  337. pMod->stModRtInfo.bLoaded = 1;
  338. #ifdef MEASURE_LOADING_TIME
  339. clock_gettime(CLOCK_MONOTONIC, &post_tp);
  340. result.tv_sec = post_tp.tv_sec - pre_tp.tv_sec;
  341. result.tv_nsec = post_tp.tv_nsec - pre_tp.tv_nsec;
  342. printf("load module(%s) from flash(FlashSize:%d Kb, DRAMSize:%d Kb), spend time:%.3f s\n",
  343. pMod->pModFlashName, modSizeC / 1024, modSizeNC / 1024,
  344. ((unsigned long) (result.tv_sec * 1000000000L + result.tv_nsec)) / 1000000000.0);
  345. #endif
  346. close(fd);
  347. munmap(pMAP, u32FlashSize);
  348. pMAP = NULL;
  349. pSrcBuf = NULL;
  350. printf("\n\n[UMF Module]:load module %s successfull!\n\n", pMod->pModFSFile);
  351. #if defined CONFIG_UMF_ONLYONECOPY_DATASECTION && !defined CONFIG_CORE_DUMP
  352. {
  353. int fd;
  354. unsigned int i,j;
  355. unsigned char *ptr;
  356. sismmio_ioctl_section_remap remap;
  357. remap.vaddr_start = pMod->stModRtInfo.dataSegStart;
  358. remap.length = pMod->stModRtInfo.dataSegSize;
  359. ptr = (unsigned char *)remap.vaddr_start;
  360. for (i = 0; i < remap.length; i += getpagesize()){
  361. j = *(volatile unsigned char *)(ptr + i);
  362. j = j;
  363. }
  364. fd = open("/dev/sismmio",O_RDWR);
  365. remap.opt = 1;
  366. ioctl(fd, SISMMIO_SECTIION_REMAP, &remap);
  367. close(fd);
  368. }
  369. #endif
  370. UMFDBG(0, "Exit %s\n", __FUNCTION__);
  371. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  372. pre_id = eID;
  373. #endif
  374. return 0;
  375. FAIL1:
  376. if (ptr)
  377. {
  378. munmap(ptr, pMod->stModRtInfo.size - pMod->stModRtInfo.dataSegSize);
  379. }
  380. if (dataPtr)
  381. {
  382. munmap(dataPtr, pMod->stModRtInfo.dataSegSize);
  383. }
  384. close(pMod->stModRtInfo.fd);
  385. pMod->stModRtInfo.fd = -1;
  386. FAIL2:
  387. close(fd);
  388. munmap(pMAP, u32FlashSize);
  389. pMAP = NULL;
  390. pSrcBuf = NULL;
  391. printf("\n\n[UMF Module]:load module %s Fail!\n\n", pMod->pModFSFile);
  392. UMFDBG(0, "Exit %s\n", __FUNCTION__);
  393. return -1;
  394. }
  395. INT32 umf_checkModuleLoaded(UMFMOD_ID eID)
  396. {
  397. UMFDBG(0, "Enter %s\n", __FUNCTION__);
  398. ModuleParam_t *pMod = umf_findModule(eID);
  399. if (!pMod)
  400. {
  401. printf("[%s,%d]find module fail,eID:%d\n", __FUNCTION__, __LINE__, eID);
  402. return -1;
  403. }
  404. if (pMod->stModRtInfo.bLoaded)/* this module has been loaded */
  405. {
  406. return 1;
  407. }
  408. else
  409. {
  410. return 0;
  411. }
  412. }
  413. INT32 umf_unloadModule(UMFMOD_ID eID)
  414. {
  415. UMFDBG(0, "Enter %s\n", __FUNCTION__);
  416. ModuleParam_t *pMod = umf_findModule(eID);
  417. if (!pMod)
  418. {
  419. printf("[%s,%d]find module fail,eID:%d\n", __FUNCTION__, __LINE__, eID);
  420. UMFDBG(0, "Exit %s\n", __FUNCTION__);
  421. return -1;
  422. }
  423. if (pMod->stModRtInfo.bLoaded)/* this module has been loaded */
  424. {
  425. UMFDBG(0, "Module: %d,Modulename:%s,\tVMA:0x%08x Size:0x%08x\n",
  426. eID,pMod->pModFlashName, pMod->stModRtInfo.vma, pMod->stModRtInfo.size);
  427. munmap((void*)pMod->stModRtInfo.vma, pMod->stModRtInfo.size - pMod->stModRtInfo.dataSegSize);
  428. if (pMod->stModRtInfo.dataSegSize)
  429. {
  430. munmap((void*)pMod->stModRtInfo.dataSegStart, pMod->stModRtInfo.dataSegSize);
  431. }
  432. close(pMod->stModRtInfo.fd);
  433. pMod->stModRtInfo.fd = -1;
  434. unlink((INT8*)pMod->pModFSFile);
  435. pMod->stModRtInfo.bLoaded = 0;
  436. /*After unload ffmpeg module, need call av_mmap_uninit().*/
  437. #ifdef CONFIG_RUNAV_USE_RESERVE_MEMORY
  438. if (eID == UMFMOD_FFMPEG)
  439. {
  440. extern void av_mmap_uninit(void);
  441. av_mmap_uninit();
  442. }
  443. #endif
  444. }
  445. UMFDBG(0, "Exit %s\n", __FUNCTION__);
  446. return 0;
  447. }
  448. /*load language by user interface*/
  449. #ifdef CONFIG_ENABLE_UMF_LANGUAGE_MODULES
  450. #if 0
  451. INT32 umf_loadAllLangModule(void)
  452. {
  453. UINT32 i = 0;
  454. UINT32 u32tablesize = 0;
  455. if (g_AllLangIsMemory == TRUE)
  456. {
  457. return 0;
  458. }
  459. u32tablesize = sizeof(u8LangModeMapping)/sizeof(u8LangModeMapping[0]);
  460. for (i = 0; i < u32tablesize; i++)
  461. {
  462. if (g_LangModeIndex == (UMFMOD_ID)u8LangModeMapping[i][1])
  463. {
  464. continue;
  465. }
  466. umf_loadModule(u8LangModeMapping[i][1]);
  467. }
  468. g_AllLangIsMemory = TRUE;
  469. return 0;
  470. }
  471. INT32 umf_unloadAllLangModule(void)
  472. {
  473. UINT32 i = 0;
  474. UINT32 u32tablesize = 0;
  475. if (g_AllLangIsMemory == FALSE)
  476. {
  477. return 0;
  478. }
  479. u32tablesize = sizeof(u8LangModeMapping)/sizeof(u8LangModeMapping[0]);
  480. for (i = 0; i < u32tablesize; i++)
  481. {
  482. if (g_LangModeIndex == (UMFMOD_ID)u8LangModeMapping[i][1])
  483. {
  484. continue;
  485. }
  486. umf_unloadModule(u8LangModeMapping[i][1]);
  487. }
  488. g_AllLangIsMemory = FALSE;
  489. return 0;
  490. }
  491. #endif
  492. INT32 umf_loadLangModuleByUILang(INT8 eLangName)
  493. {
  494. UMFMOD_ID eModeID = UMFMOD_MAX;
  495. UINT32 i = 0;
  496. UINT32 u32tablesize = 0;
  497. if (g_AllLangIsMemory)
  498. {
  499. return 0;
  500. }
  501. u32tablesize = sizeof(u8LangModeMapping)/sizeof(u8LangModeMapping[0]);
  502. for (i = 0; i < u32tablesize; i++)
  503. {
  504. if (u8LangModeMapping[i][0] == eLangName)
  505. {
  506. eModeID = u8LangModeMapping[i][1];
  507. break;
  508. }
  509. }
  510. printf("\n\ni = %d, u32tablesize is %d\n\n",i, u32tablesize);
  511. if (i < u32tablesize)
  512. {
  513. if (g_LangModeIndex > UMFMOD_ATV
  514. && g_LangModeIndex < UMFMOD_MAX
  515. && g_LangModeIndex != eModeID)
  516. {
  517. umf_unloadModule(g_LangModeIndex);
  518. }
  519. g_LangModeIndex = eModeID;
  520. umf_loadModule(eModeID);
  521. }
  522. g_AllLangIsMemory = FALSE;
  523. return 0;
  524. }
  525. #endif
  526. #if (defined CONFIG_MOD_PACK_TT) || (defined CONFIG_MOD_PACK_SUB)
  527. Boolean TTOrSubModLoad(Boolean MMapInit)
  528. {
  529. Boolean LoadFlag = TRUE;
  530. if (MMap_CheckInit() == TRUE)
  531. {
  532. printf("\n====[%s, %d]===TT/SUB module has been loaded and mmap~~\n",__FUNCTION__,__LINE__);
  533. LoadFlag = FALSE;
  534. return LoadFlag;
  535. }
  536. #ifdef CONFIG_MOD_PACK_TT
  537. if (umf_checkModuleLoaded(UMFMOD_TT) == 0)
  538. {
  539. if (umf_loadModule(UMFMOD_TT) != 0)
  540. {
  541. printf("\n====[%s, %d]===load TT module fail~~\n",__FUNCTION__,__LINE__);
  542. LoadFlag = FALSE;
  543. }
  544. }
  545. #endif
  546. #ifdef CONFIG_MOD_PACK_SUB
  547. if (umf_checkModuleLoaded(UMFMOD_SUB) == 0)
  548. {
  549. if (umf_loadModule(UMFMOD_SUB) != 0)
  550. {
  551. printf("\n====[%s, %d]===load SUB module fail~~\n",__FUNCTION__,__LINE__);
  552. LoadFlag = FALSE;
  553. }
  554. }
  555. #endif
  556. if (LoadFlag == TRUE)
  557. {
  558. #ifdef CONFIG_MOD_PACK_SUB
  559. MID_Subtitle_constructor();
  560. #endif
  561. if (MMapInit == TRUE)
  562. {
  563. if (MMap_Init() != 0)
  564. {
  565. LoadFlag = FALSE;
  566. printf("\n====[%s, %d]===mmap fail~~\n",__FUNCTION__,__LINE__);
  567. }
  568. }
  569. }
  570. return LoadFlag;
  571. }
  572. Boolean TTOrSubModUnload(void)
  573. {
  574. Boolean UnloadFlag = TRUE;
  575. #ifdef CONFIG_MOD_PACK_TT
  576. if (umf_checkModuleLoaded(UMFMOD_TT) == 1)
  577. {
  578. if (umf_unloadModule(UMFMOD_TT) != 0)
  579. {
  580. printf("\n====[%s, %d]===unload TT module fail~~\n",__FUNCTION__,__LINE__);
  581. UnloadFlag = FALSE;
  582. }
  583. }
  584. #endif
  585. #ifdef CONFIG_MOD_PACK_SUB
  586. if (umf_checkModuleLoaded(UMFMOD_SUB) == 1)
  587. {
  588. MID_Subtitle_destructor();
  589. if (umf_unloadModule(UMFMOD_SUB) != 0)
  590. {
  591. printf("\n====[%s, %d]===unload SUB module fail~~\n",__FUNCTION__,__LINE__);
  592. UnloadFlag = FALSE;
  593. }
  594. }
  595. #endif
  596. if (UnloadFlag == TRUE)
  597. {
  598. MMap_Uninit();
  599. }
  600. return UnloadFlag;
  601. }
  602. #endif
  603. #endif