void Error (char *error, ...) { va_list argptr; if (usemodem) { printf ("\n"); printf ("\n"STR_DROPDTR"\n"); OUTPUT(uart+MODEM_CONTROL_REGISTER, INPUT(uart+MODEM_CONTROL_REGISTER)&~MCR_DTR); delay (1250); OUTPUT( uart + MODEM_CONTROL_REGISTER, INPUT( uart + MODEM_CONTROL_REGISTER ) | MCR_DTR ); ModemCommand("+++"); delay (1250); ModemCommand(shutdown); delay (1250); } ShutdownPort (); if (vectorishooked) setvect (doomcom.intnum,olddoomvect); if (error) { va_start (argptr,error); vprintf (error,argptr); va_end (argptr); printf ("\n"); exit (1); } printf (STR_CLEANEXIT"\n"); exit (0); }
////////////////////////////////////////////////////////////////////// // This is the high level download function for the Download Mode. // // Inputs: Fuses (platformsettings) and the TIM. // Outputs: Returns a pointer to the next image which we will transfer // control to. // // It mainly determines the download mode (TIM or FBF) and calls the // appropriate download routine. ////////////////////////////////////////////////////////////////////// pIMAGE_INFO_3_4_0 DetermineModeAndDownload( pFUSE_SET pFuses, pTIM pTIM_h ) { pIMAGE_INFO_3_4_0 pBootImageInfo = NULL; FUNC_STATUS fs_Retval; volatile pProtocolISR pPortInterrupt; volatile pProtocolCmd pCommand; int start_time =0, cur_time=0; fs_Retval.ErrorCode = GeneralError; #if ZIMI_PB05 int mTimeOut; extern UINT_T back_image_key; if(back_image_key) //Onkey + reset mTimeOut =4; else mTimeOut =1; #endif InitDefaultPort( pFuses ); //time_count_enable = 0; // The download port is opened. Get all the images and burn them to flash. // Start by trying to get a TIM followed by individual files. // If that fails, then try getting an FBF bundle. // If that fails as well, then treat this a a fatal error. start_time = GetOSCR0(); do { pPortInterrupt = getProtocolISR(); if(time_count_enable) { cur_time = GetOSCR0(); if(OSCR0IntervalInSec(start_time, cur_time) >mTimeOut) //xyl define { pBootImageInfo = NULL; goto shutdown; } } if (upload_times == 0) { goto disconnect; // no upload any more } if(pPortInterrupt->PreambleReceived == FALSE) { #if I2C resetTimer(); // reset charger 32s timer for key pressed download #endif fs_Retval.ErrorCode = SeqError; continue; } time_count_enable= 0; start_time = GetOSCR0(); while (pPortInterrupt->CommandReceived == FALSE) { cur_time = GetOSCR0(); if(OSCR0IntervalInSec(start_time, cur_time) > PROTOCOL_WAITTIME) //wait for command { pBootImageInfo = NULL; goto shutdown; } } pCommand = getProtocolCmd(); switch(pCommand->Command) { case GetVersionCmd: // Used to differentiate from UPLOAD. isDownload = TRUE; #if I2C #if OLED_SUPPORT || LED_DISPLAY SoftwareUpgrade_Start(); #endif #endif // Request the TIM first as originally implemented. // The new TIM is stored at pTIM_h->pConstTIM. // USB DMA can not access SQU, so OBM download DKB_NTIM to DDR, and then copy it to SQU // it will be fixed on Y0 board fs_Retval = HandleRequest( DDR_DOWNLOAD_AREA_ADDR, TIMIDENTIFIER ); //fs_Retval = HandleRequest( (UINT_T)pTIM_h->pConsTIM, TIMIDENTIFIER ); if (fs_Retval.ErrorCode == NoError) { // Before we call the TIM Download function which actually does the downloading, // copy the tim from its download location to its load address. memcpy(pTIM_h->pConsTIM, DDR_DOWNLOAD_AREA_ADDR, 1024); // pTIM_h is the newly downloaded TIM. // It has a list of all the images that need to be downloaded and burned. // The DownloadImages function will use DDR to hold the images while writing them to flash. pBootImageInfo = TIMDownloadMain( pTIM_h ); } else // download failed { FatalError(fs_Retval.ErrorCode); } break; case UploadDataHeaderCmd: // UPLOAD_DATA_AREA is in DDR // upload size limitted 0x1d00000 - 0x1000 fs_Retval = HandleRequest( (UINT_T)UPLOAD_DATA_AREA, NULL); if (fs_Retval.ErrorCode == NoError) // upload successfully { upload_times--; fs_Retval.ErrorCode = GeneralError; // wait for next upload upload_nand_spare = FALSE; // clear it } else // upload failed { FatalError(fs_Retval.ErrorCode); } // Does not matter if we had an error. Boot anyway. break; default: unknown_protocol_command(getProtocolCmd()); FatalError(UnknownProtocolCmd); } }while (fs_Retval.ErrorCode != NoError); disconnect: HandleDisconnect(); shutdown: ShutdownPort(CI2_USB_D); return pBootImageInfo; }