48 #include "dsm_control.h" 49 #include "dsm_client.h" 54 #define OTA_DBG(X) STB_SPDebugWrite X 59 #define OTA_NVM_TASK_STACK 1024 60 #define OTA_NVM_TASK_PRIORITY 6 61 #define DSMCC_TASK_PRIORITY 6 62 #define MAX_NVM_MSGS 30 95 static H_DsmControl dsmcc_control = NULL;
96 static H_DsmCarousel dsmcc_carousel = NULL;
97 static void *wait_sem = NULL;
98 static void *dsm_mutex = NULL;
99 static BOOLEAN continue_with_download = FALSE;
100 static void* ota_nvm_queue = NULL;
101 static U32BIT total_image_size;
102 static U32BIT saved_image_size;
104 static F_SSU_VERSION_CALLBACK ssu_version_cb = NULL;
107 static void* MemAlloc(U32BIT memSize);
108 static void MemFree(
void* ptr);
109 static BOOLEAN ParseSsuSelectorBytes( U8BIT *selPtr, U8BIT selLen );
110 static void SsuStatusEvent( H_DsmCarousel carouselRef, E_UCLoadStatus status, U_StatusRef sr, U32BIT data );
111 static BOOLEAN SsuWanted( U32BIT grp_id, U32BIT grp_size, S_SsuModelVersion *smv );
112 static H_UsrRef SsuStartModule( E_ModuleType mtyp, U8BIT *name );
113 static BOOLEAN SsuWantModuleData( H_UsrRef usrRef, U32BIT moduleRef,
114 U32BIT offset, U32BIT size, U32BIT crc );
115 static void SsuSaveModuleData( H_UsrRef usrRef, U32BIT moduleRef, U32BIT offset, U32BIT size, U8BIT *data );
116 static H_DsmControl DsmccOpen(
void);
117 static U32BIT GetOui(
void);
118 static void NvmSaveTask(
void *param);
134 U16BIT download_pid, F_SSU_VERSION_CALLBACK version_cb)
139 ASSERT(path != INVALID_RES_ID)
143 if (dsmcc_control == NULL)
147 dsmcc_control = DsmccOpen();
148 if (dsmcc_control != NULL)
150 if (wait_sem == NULL)
159 if (dsm_mutex == NULL)
164 if (ota_nvm_queue == NULL)
168 STB_OSCreateTask(NvmSaveTask, NULL, OTA_NVM_TASK_STACK, OTA_NVM_TASK_PRIORITY,
169 (U8BIT *)
"OTA Nvm Task");
176 OTA_DBG((
"%s: Failed to create a DSMCC controller to start the download", __FUNCTION__));
177 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_OTA_SW_UPGRADE, EV_TYPE_OTA_SW_UPGRADE_ERROR, NULL, 0);
183 total_image_size = 0;
184 saved_image_size = 0;
185 ssu_version_cb = version_cb;
189 DSMCC_SetTunedTransportInfo(dsmcc_control, onet_id, tran_id,
STB_DPGetPathDemux(path));
191 if (serv_id != DVB_INVALID_ID)
193 OTA_DBG((
"%s: Start DSMCC on service ID %u", __FUNCTION__, serv_id));
194 retval = DSMCC_StartSsu(dsmcc_control, serv_id, GetOui());
198 OTA_DBG((
"%s: Start DSMCC on PID %u", __FUNCTION__, download_pid));
199 retval = DSMCC_StartSsuWithPid(dsmcc_control, download_pid, GetOui());
206 OTA_DBG((
"%s: Failed to start DSMCC", __FUNCTION__));
207 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_OTA_SW_UPGRADE, EV_TYPE_OTA_SW_UPGRADE_ERROR, NULL, 0);
224 if (dsmcc_control != NULL)
227 continue_with_download = FALSE;
232 if (dsmcc_control != NULL)
234 OTA_DBG((
"%s: Stopping DSMCC", __FUNCTION__));
235 DSMCC_Stop(dsmcc_control, RST_MODE_FORCE);
236 DSMCC_Close(dsmcc_control);
237 dsmcc_control = NULL;
254 static U32BIT last_pc = 0xFFFFFFFF;
261 if ((dsmcc_control == NULL) || (total_image_size == 0))
268 percent = ((saved_image_size / 1024) * 100) / (total_image_size / 1024);
270 if (percent != last_pc)
273 OTA_DBG((
"%s: saved=%lu total=%lu percent=%lu", __FUNCTION__, saved_image_size,
274 total_image_size, percent));
283 return (U8BIT)percent;
298 if (dsmcc_control != NULL)
301 continue_with_download = status;
318 static void* MemAlloc(U32BIT memSize)
322 FUNCTION_START(MemAlloc);
326 FUNCTION_FINISH(MemAlloc);
335 static void MemFree(
void* ptr)
337 FUNCTION_START(MemFree);
341 FUNCTION_FINISH(MemFree);
344 static BOOLEAN ParseSsuSelectorBytes( U8BIT *selPtr, U8BIT selLen )
346 FUNCTION_START(ParseSsuSelectorBytes);
347 USE_UNWANTED_PARAM(selPtr);
348 USE_UNWANTED_PARAM(selLen);
349 FUNCTION_FINISH(ParseSsuSelectorBytes);
364 static void SsuStatusEvent( H_DsmCarousel carouselRef, E_UCLoadStatus status, U_StatusRef sr, U32BIT data )
368 FUNCTION_START(SsuStatusEvent);
369 USE_UNWANTED_PARAM(sr);
373 case SSU_NOT_AVAILABLE:
375 OTA_DBG((
"%s: SSU_NOT_AVAILABLE", __FUNCTION__));
376 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_OTA_SW_UPGRADE, EV_TYPE_OTA_SW_UPGRADE_NOTFOUND, NULL, 0);
377 dsmcc_carousel = carouselRef;
382 OTA_DBG((
"%s: SSU_CRSL_READY", __FUNCTION__));
383 dsmcc_carousel = carouselRef;
385 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_OTA_SW_UPGRADE, EV_TYPE_OTA_SW_UPGRADE_DOWNLOADING, NULL, 0);
386 total_image_size = data;
389 case SSU_LOAD_STARTING:
391 OTA_DBG((
"%s: SSU_LOAD_STARTING", __FUNCTION__));
392 msg.type = MSG_START;
397 case SSU_LOAD_COMPLETE:
399 OTA_DBG((
"%s: SSU_LOAD_COMPLETE", __FUNCTION__));
404 case SSU_LOAD_ABORTED:
406 OTA_DBG((
"%s: SSU_LOAD_ABORTED", __FUNCTION__));
407 msg.type = MSG_ERROR;
413 OTA_DBG((
"%s: SSU_CRSL_DONE, saved_image_size=%lu, total_image_size=%lu", __FUNCTION__,
414 saved_image_size, total_image_size));
415 if (saved_image_size != total_image_size)
417 msg.type = MSG_ERROR;
428 OTA_DBG((
"%s: SSU_CRSL_ABORT", __FUNCTION__));
429 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_OTA_SW_UPGRADE, EV_TYPE_OTA_SW_UPGRADE_NOTFOUND, NULL, 0);
430 msg.type = MSG_ABORT;
431 saved_image_size = total_image_size;
435 case SSU_CRSL_UNLOAD:
437 OTA_DBG((
"%s: SSU_CRSL_UNLOAD", __FUNCTION__));
442 OTA_DBG((
"%s: Invalid status %d", __FUNCTION__, status));
447 FUNCTION_FINISH(SsuStatusEvent);
458 static BOOLEAN SsuWanted( U32BIT grp_id, U32BIT grp_size, S_SsuModelVersion *smv )
460 BOOLEAN result = FALSE;
461 BOOLEAN valid_download = TRUE;
463 FUNCTION_START(SsuWanted);
465 if (ssu_version_cb != NULL)
468 valid_download = (*ssu_version_cb)(grp_id, grp_size, smv->hw_model, smv->hw_version,
469 smv->sw_model, smv->sw_version);
475 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_OTA_SW_UPGRADE, EV_TYPE_OTA_SW_UPGRADE_FOUND, NULL, 0);
480 result = continue_with_download;
481 total_image_size = grp_size;
482 saved_image_size = 0;
483 OTA_DBG((
"%s: continue=%u, total=%lu", __FUNCTION__, result, total_image_size));
486 FUNCTION_FINISH(SsuWanted);
500 static H_UsrRef SsuStartModule( E_ModuleType mtyp, U8BIT *name )
502 H_UsrRef retval = NULL;
504 FUNCTION_START(SsuStartModule);
508 ota_upg_mod.mtyp = (U8BIT)mtyp;
509 ota_upg_mod.name = name;
510 retval = &ota_upg_mod;
515 OTA_DBG((
"STB_UPGStart failed"));
519 FUNCTION_FINISH(SsuStartModule);
536 static BOOLEAN SsuWantModuleData( H_UsrRef usrRef, U32BIT moduleRef,
537 U32BIT offset, U32BIT size, U32BIT crc )
539 FUNCTION_START(SsuWantModuleData);
540 USE_UNWANTED_PARAM(usrRef);
541 USE_UNWANTED_PARAM(moduleRef);
542 USE_UNWANTED_PARAM(offset);
543 USE_UNWANTED_PARAM(size);
544 USE_UNWANTED_PARAM(crc);
545 #ifdef TODO_CHECK_NVM 548 FUNCTION_FINISH(SsuWantModuleData);
563 static void SsuSaveModuleData( H_UsrRef usrRef, U32BIT moduleRef, U32BIT offset, U32BIT size, U8BIT *data )
567 FUNCTION_START(SsuSaveModuleData);
569 USE_UNWANTED_PARAM(usrRef);
572 msg.moduleRef = moduleRef;
577 OTA_DBG((
"%s: saved=%lu total=%lu", __FUNCTION__, saved_image_size, total_image_size));
580 saved_image_size += size;
582 FUNCTION_FINISH(SsuSaveModuleData);
585 static H_DsmControl DsmccOpen(
void)
587 S_DsmccConfig config;
589 FUNCTION_START(DsmccOpen);
591 config.taskPriority = DSMCC_TASK_PRIORITY;
592 config.sectionBuffPoolSize = 180;
593 config.sectionBuffCacheSize = 16;
594 config.memAlloc = MemAlloc;
595 config.memFree = MemFree;
596 config.parsePmtInit = NULL;
597 config.parseDataBroadcastId = NULL;
598 config.parseSsuSelectorBytes = ParseSsuSelectorBytes;
599 config.parsePmtDone = NULL;
600 config.ssuFuncs.status = SsuStatusEvent;
601 config.ssuFuncs.wanted = SsuWanted;
602 config.ssuFuncs.startModule = SsuStartModule;
603 config.ssuFuncs.wantModuleData = SsuWantModuleData;
604 config.ssuFuncs.saveModuleData = SsuSaveModuleData;
605 config.notifyAitInfo = NULL;
606 config.controlFlags = GET_PMT_DIRECT_FROM_HW_FLAG;
608 FUNCTION_FINISH(DsmccOpen);
610 return DSMCC_Open( &config );
613 static U32BIT GetOui(
void)
618 FUNCTION_START(GetOui);
623 oui = (oui << 8) | *oui_str++;
624 oui = (oui << 8) | *oui_str;
631 FUNCTION_FINISH(GetOui);
636 static void NvmSaveTask(
void *param)
640 FUNCTION_START(NvmSaveTask);
641 USE_UNWANTED_PARAM(param);
645 while (msg.type != MSG_QUIT)
658 OTA_DBG((
"%s: SAVING moduleRef=%x offset=%d size=%d", __FUNCTION__, msg.moduleRef,
659 msg.offset, msg.size));
660 if (!
STB_UPGWrite(ota_upg_mod.mtyp, msg.offset, msg.size, msg.data))
662 OTA_DBG((
"%s: Failed to write OTA at offset %d bytes=%d", __FUNCTION__,
663 msg.offset, msg.size));
669 if (dsmcc_control != NULL)
671 DSMCC_SsuUnloadModule(dsmcc_control, dsmcc_carousel, msg.moduleRef);
680 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_OTA_SW_UPGRADE, EV_TYPE_OTA_SW_UPGRADE_COMPLETED, NULL, 0);
686 STB_ERSendEvent(FALSE, FALSE, EV_CLASS_OTA_SW_UPGRADE, EV_TYPE_OTA_SW_UPGRADE_ERROR, NULL, 0);
692 if (dsmcc_control != NULL)
694 DSMCC_Stop(dsmcc_control,RST_MODE_FORCE);
703 if (dsmcc_control != NULL)
705 DSMCC_Stop(dsmcc_control,RST_MODE_FORCE);
714 FUNCTION_FINISH(NvmSaveTask);
BOOLEAN STB_OTAStartLoader(U8BIT path, U16BIT onet_id, U16BIT tran_id, U16BIT serv_id, U16BIT download_pid, F_SSU_VERSION_CALLBACK version_cb)
Starts the over-the-air download process.
API interfacing the midware with Intellibyte loader library.
Function prototypes for HW control.
U8BIT * STB_HWGetOUI(void)
Returns the number of smart card slots on the platorm.
Header file - macros and function prototypes for public use.
void * STB_OSCreateSemaphore(void)
Create a Semaphore.
void * STB_AppGetMemory(U32BIT bytes)
Attempts to allocate memory from the application heap.
BOOLEAN STB_UPGFinish(U8BIT image_type, BOOLEAN upgrade_successful)
Finalises the upgrade performing all the required actions needed when all the upgrade data have been ...
void STB_OSSemaphoreSignal(void *semaphore)
Signal a Semaphore to Release it by decrementing its counter.
U8BIT STB_OTAGetProgress(void)
Returns the SSU download progress as a percentage.
void STB_OSMutexUnlock(void *mutex)
Unlock a mutex (a.k.a. 'leave', 'signal' or 'release')
void STB_OSSemaphoreWait(void *semaphore)
Wait on Semaphore Indefinity or Until Released.
void STB_ERSendEvent(BOOLEAN latched, BOOLEAN repeat, U16BIT path_class, U16BIT type, void *data, U32BIT data_size)
Sends an event to event reporting control module.
Debug functions header file.
Header file - macros and function prototypes for public use.
void STB_OSMutexLock(void *mutex)
Lock a mutex (a.k.a. 'enter', 'wait' or 'get').
void STB_OTAStopLoader(void)
Stops the download, if still in progress, but should also be called when the update process has compl...
Header file - Function prototypes for Event Reporting.
BOOLEAN STB_OSWriteQueue(void *queue, void *msg, U16BIT msg_size, U16BIT timeout)
Write a message to the queue.
Header file - Function prototypes for operating system.
System Wide Global Technical Data Type Definitions.
void STB_AppFreeMemory(void *addr)
Releases previously allocated application heap memory.
void * STB_OSCreateTask(void(*function)(void *), void *param, U32BIT stack, U8BIT priority, U8BIT *name)
Create a New Task to the calling process. Upon success, the created task runs on its own stack...
void * STB_OSCreateQueue(U16BIT msg_size, U16BIT msg_max)
Create Queue of given number of messages and size of message.
Header file - Function prototypes for heap memory.
void * STB_OSCreateMutex(void)
Create a mutex.
BOOLEAN STB_OSReadQueue(void *queue, void *msg, U16BIT msg_size, U16BIT timeout)
Read a message from a queue.
BOOLEAN STB_UPGStart(U8BIT image_type, U8BIT *filename)
Specifies the file path that STB_UPWrite would write to and STB_UPGRead would read from when performi...
void STB_OTAContinueDownload(BOOLEAN status)
This function should be called to unblock the download process. This can be used to in the case where...
BOOLEAN STB_UPGWrite(U8BIT image_type, U32BIT offset, U32BIT size, U8BIT *buffer)
Writes size bytes to the upgrade storage area specified by image_type.
U8BIT STB_DPGetPathDemux(U8BIT path)
Returns the demux path ID acquired by the given decode path.
Functions for writing upgrade modules to non volatile memory.