REFLASHER.C
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:32k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: REFLASHER.C $
- *
- * Description: Interface for creating and manipulating a generic Array.
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 25 $
- * Last Modified by $Author: Mikex $ at $Modtime: 04-04-02 19:23 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/Download/REFLASHER.C $
- *
- * 25 04-04-03 15:13 Mikex
- * add the option about save keys to eeprom
- *
- * 24 04-04-01 23:33 Mikex
- * added HDCP key and DVD-AUDIO key download support
- *
- * 23 4/01/04 10:47a Jimmyp
- * Include Hdcp_keys.h
- *
- * 22 3/31/04 4:44p Jimmyp
- * For HDCP update feature
- *
- * 21 3/19/04 5:03p Terencet
- * fixed can't CD update because of set SDRAM semphore twice
- *
- * 20 3/01/04 6:28p Lotan
- * merge with Divx certification DB
- *
- * 19 11/03/03 6:06p Nmaurer
- * Add protection against ilegal request margins
- *
- * 18 10/30/03 6:07p Leslie
- * Define NBR_SECTORS_AT_A_TIME as NBR_CACHED_CDSECT to speed up CD-Update
- *
- * 17 5/13/03 4:16p Rinata
- * fixed force image
- *
- * 16 5/11/03 5:52p Rinata
- * 1. restore PS just before update CD
- * 2. first search for force.img file if found don't replace "feature
- * select" data
- *
- * 15 5/06/03 3:38p Rinata
- * put code under UPDATE_CD_WITH_PLAYER_SETTING
- *
- * 14 5/01/03 5:51p Rinata
- * update code UPDATE_CD_WITH_PLAYER_SETTING
- *
- * 13 03-04-14 11:23 Leslie
- * Remove margin for Disc Read Block, which is not usefule for I64
- *
- * 12 2/11/03 8:50p Rinata
- * fixed cd-update return data address value ( the lbn )
- *
- * 11 1/27/03 10:42p Rinata
- * CD_UPDATE_MULTIPLE_MODELS
- *
- * 10 03-01-10 12:27 Leslie
- * Memory optimization
- * Update with file-system changes
- *
- * 8 12/09/02 6:06p Leslie
- * Code cleanup
- * Support Error Message display on screen
- * Change SDRAM BASE Address
- *
- * 7 10/31/02 17:02 Hamadk
- *
- * 4 10/24/02 14:28 Hamadk
- * Corrected the address of the SDRAM which is used to hold the image file
- *
- * 3 10/10/02 14:26 Hamadk
- * Increaced sleep time to enable openning the tray after downloading the
- * bin file to the dram
- *
- * 2 27/06/02 11:31 Atai
- * merging with 5e golden version
- *
- * 14 5/28/02 14:15 Rinata
- * add 2 to number of read blocks in discReadBlock in order to avoid bug
- * in Sanyo drive which read error data
- *
- * 13 5/20/02 11:53 Rinata
- * clean code and add comments
- *
- * 12 5/19/02 16:10 Rinata
- * remove warnings
- *
- * 11 5/19/02 15:24 Rinata
- * fix open tray
- *
- * 10 5/16/02 11:21 Rinata
- * prepare new stack for copy and run function which copy reflsher to
- * scratch pad and run it
- *
- * 9 5/14/02 14:48 Rinata
- * make fixes in read from SDRAM
- *
- * 8 5/14/02 8:36 Rinata
- * fixes for reflahser
- *
- * 7 23/04/02 9:29 Nirm
- * - Added dependency in "Config.h".
- *
- * 6 2/28/02 10:12 Rinata
- * DiscReadyDownload get image name from update.ver file
- *
- * 5 3/02/02 12:01 Nirm
- * Switched to using the new File-System.
- *
- * 4 1/31/02 1:04a Tomasp
- * Changed printf->tr_printf
- *
- * 3 16/01/02 11:37 Atai
- * Change debug printing
- *
- * 2 9/01/02 14:52 Nirm
- * Corrected Include-Paths.
- *
- * 2 9/01/02 14:48 Nirm
- * Corrected Include-Paths.
- *
- * 1 26/12/01 14:57 Nirm
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceCore)
- #include "DebugDbgMain.h"
- #endif
- #include "IncludeSysDefs.h"
- #include "CPU/cpu_api.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "PlaycoreCoremain/Corenvg.h"
- #include "PlaycoreAuxCacheAuxCache.h"
- #include "PlaycoreFileSysFileSystem.h"
- #include "PlaycoreScPadscmgr.h"
- #include "DecoderDecoder.h"
- #include "KernelEventDef.h"
- #include "Includestring_ex.h"
- #include "Customerlib_setuplib_setup.h"
- #ifdef SUPPORT_KEYS_UPDATE
- #ifdef STORE_KEYS_IN_FLASH
- #include "UartStore_keys.h"
- #endif//STORE_KEYS_IN_FLASH
- #endif
- #ifdef EXINO2 // ZKR GL080703
- #include "CPUV186treflasherdefs.h"
- #endif // EXINO2
- #ifdef D_QS_UPGRADE_WAY
- #include "customerMercury_Referenceversion.h"
- #endif
- #define MAX_FILE_NAME_LEN 100
- #define NBR_SECTORS_AT_A_TIME (MAX_CACHED_SECTORS - 1) // Aiden_08_20_2004: The max cached sector one time should be 63
- #ifdef DA1_USE_BIG_TRACK_BUFFER // Aiden_11_26_2004: For DA1 Big TB, change the sdram copy address
- #define SDRAM_COPY_ADDR_BASE (OSD_BUFFER_SIZE_CD_AUX + VCB_SIZE_CD_AUX + ACB_SIZE_CD_AUX + SPB_SIZE_CD_AUX + APP_BUFFER_SIZE_CD_AUX + NAV_BUFFER_SIZE_CD_AUX)
- #define SDRAM_COPY_ADDR ((UINT32)SDRAM_COPY_ADDR_BASE << 9UL) // R1 Start: 2260K = 0x11a800 Words
- #else
- #define SDRAM_COPY_ADDR (( (UINT32)DEC_LL_VCD_AUX_REF2_START)<<9ul)// 1438K = 0xB3C00 words
- #endif
- #define BUFF_SIZE 32 // 32 words of 2bytes
- #define COUNT_1_SECTOR (1024/BUFF_SIZE) // Number of buff copies to copy one sector
- #define SDRAM_ADDRESS_POINTER ((1438L << 9 ) - 10) // 0xB3BF6
- #define SD_ADDR_INDICATION 0xF0A1
- #define SDRAM_4M_ADDR 0x200000UL
- #define MK_FP(seg,ofs) ((void __seg *)(seg) + (void __near *)(ofs))
- DWORD g_dwImageFileSize= 0;
- DWORD g_dwImageFileAddr = 0;
- BOOL discCopyToDram(void);
- int DiscReadyDownload(void);
- BOOL DiscDownload(void);
- extern int drv_tray_open( void );
- static void copy_reflsher_and_run(void);
- #ifdef UPDATE_CD_WITH_PLAYER_SETTING
- static BOOL ReplacePlayerSetting(void);
- static BOOL IsImageEOS( unsigned char buff_char );
- static BOOL IsPlayerEOS( unsigned char buff_char );
- #ifdef FORCE_CD_IMAGE_SETTING_UPDATE
- static BOOL IsForceImage = FALSE;
- #endif
- #endif
- #ifdef SUPPORT_KEYS_UPDATE
- #ifdef STORE_KEYS_IN_FLASH
- static BOOL ReplaceHDCPKeys(void);
- #endif//STORE_KEYS_IN_FLASH
- #endif
- static BYTE _CalcCheckSum(void);
- #ifdef AVI_DRM_SUPPORT
- #ifdef STORE_PS_DATA_IN_FLASH
- extern CONST unsigned char default_factory_settings_signature;
- static BOOL _ReplaceDivXDRMMemory(void);
- static BOOL _SearchFactorySetting(UINT32 *dwSettingStartAddr, UINT16 *wSettingOffset);
- #endif // D_STORE_KEYS_IN_FLASH
- #endif // AVI_DRM_SUPPORT
- /**********************************************************************************
- Purpose : copy image data from disv to SDRAM
- Input Parameters : lbn - image data in disc start address
- Return Value : FALSE if fail - else TRUE
- Comment: : SDRAM Start address - 2 bytes - file size
- - 1 bytes - checksum
- - Image code
- **********************************************************************************/
- BOOL discCopyToDram(void)
- {
- unsigned long offset_t; // Target offset
- unsigned long offset_s; // Source offset
- unsigned long i;
- unsigned long count_sum;
- unsigned char discsum = 0;
- unsigned char buff_s[64];
- unsigned short buff_sum[32];
- unsigned short *buff_t;
- unsigned int file_sectors_size =(int)( (g_dwImageFileSize-1) / 2048);
- unsigned int count_lbn = 0;
- BOOL b_res = TRUE;
- unsigned short retry_cnt = 10; // need to retry twice at least because decoder may not be initiliaze in proper CD mode 1 or mode 2
- unsigned long lbn = g_dwImageFileAddr;
- dbg_printf(("START discCopyToDramn"));
-
- /*****************************************************************************
- Aiden_11_26_2004:
- Write to the address 0xB3BF6 (SDRAM_ADDRESS_POINTER) the following data:
- 0xB3BF6: 0xF0A1
- 0xB3BF7: 0xF0A1
- 0xB3BF8: sdram_copy_addr_low
- 0xB3BF9: sdram_copy_addr_high
- In Reflasher code:
- it will read 4 bytes form 0xB3BF6, if first 2 bytes is equal to 0xF0A1,
- then it will use the data from 0xB3BF8 and 0xB3BF9 as SDRAM_COPY_ADDR,
- otherwise it will use the address: (1438L << 9 ) as SDRAM_COPY_ADDR
- Then we can change the sdram_copy_address easily and no need to compile reflasher.h
- ***********************************************************************************/
- buff_sum[0] = SD_ADDR_INDICATION;
- buff_sum[1] = SD_ADDR_INDICATION;
- buff_sum[2] = (SDRAM_COPY_ADDR&0xffff);
- buff_sum[3] = (SDRAM_COPY_ADDR>>16)&0xffff;
-
- tr_printf(("SDRAM copy address = 0x%x 0x%xn",buff_sum[3], buff_sum[2]));
-
- if (DEC_WriteDRAMData( SDRAM_ADDRESS_POINTER, buff_sum, 4) != 4){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)1);
- return FALSE;
- }
-
- /* write image size */
- buff_sum[0] = file_sectors_size & 0xff;
- buff_sum[1] = file_sectors_size >> 8;
- if (DEC_WriteDRAMData( SDRAM_COPY_ADDR, buff_sum, 2) != 2){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)1);
- return FALSE;
- }
- /* Start write image to SDRAM */
- offset_t = SDRAM_COPY_ADDR+ 3;
- while (file_sectors_size) { // Read and copy all the CD .BIN file
- if (!(count_lbn % NBR_SECTORS_AT_A_TIME)) {
- do{
- b_res = TRUE;
- DEC_CacheSector(lbn,NBR_SECTORS_AT_A_TIME);
- /* ilegal request margins */
- if (drv_check_valid_lbn(lbn) == FALSE)
- {
- b_res = FALSE;
- retry_cnt = 0;
- }
- else
- {
- AuxCache_DiscReadBlock( lbn, NBR_SECTORS_AT_A_TIME );
- b_res = DEC_WaitCacheComplete();
- if (!b_res)
- retry_cnt--;
- }
- }while( (!b_res) && retry_cnt);
- }
- offset_s = 0;
- for (i=0;i<32;i++) { // Copy one sector
- if (!AuxCache_GetBytes (lbn, offset_s, 64, buff_s)){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)2);
- return FALSE;
- }
-
- buff_t = (unsigned short*)buff_s;
- if ((offset_t < SDRAM_4M_ADDR) && (offset_t+32 >= SDRAM_4M_ADDR))
- {
- UINT16 temp_size_low;
- UINT16 temp_size_high;
- // Aiden_11_26_2004: if write to SDRAM corss the 4M boundary, HW will write to address 0
- // then OSD will crashed, so write it in 2 times.
- tr_printf(("nMapping crossing 4M n"));
- temp_size_low = SDRAM_4M_ADDR-offset_t;
- temp_size_high = offset_t + 32 - SDRAM_4M_ADDR;
- if (DEC_WriteDRAMData( offset_t, buff_t, temp_size_low) != temp_size_low){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)3);
- return FALSE;
- }
-
- if (DEC_ReadDRAMData( offset_t, buff_sum, temp_size_low) != temp_size_low){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)4);
- return FALSE;
- }
- if (DEC_WriteDRAMData( SDRAM_4M_ADDR, &buff_t[temp_size_low], temp_size_high) != temp_size_high){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)3);
- return FALSE;
- }
-
- if (DEC_ReadDRAMData( SDRAM_4M_ADDR, &buff_sum[temp_size_low], temp_size_high) != temp_size_high){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)4);
- return FALSE;
- }
- }
- else
- {
- if (DEC_WriteDRAMData( offset_t, buff_t, 32) != 32){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)3);
- return FALSE;
- }
-
- if (DEC_ReadDRAMData( offset_t, buff_sum, 32) != 32){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)4);
- return FALSE;
- }
- }
- for (count_sum=0;count_sum<32;count_sum++) {
- if (buff_sum[count_sum] != buff_t[count_sum]) {
- dbg_printf (("ERROR buff_sum != buff_tn"));
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)5);
- return FALSE;
- }
- discsum += (char)(buff_sum[count_sum] & 0x00FF);
- discsum += (char)((buff_sum[count_sum] >> 8) & 0x00FF);
- }
- offset_s += 64;
- offset_t += 32;
- }
- dbg_printf (("."));
- file_sectors_size--;
- lbn ++;
- count_lbn++;
- }
- dbg_printf(("nFOUND sum disc"));
-
- if (!AuxCache_GetBytes (lbn, 0, 1, buff_s)) {
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)6);
- dbg_printf(("ERROR can't read disc check sum wordn"));
- return FALSE;
- }
- else {
- dbg_printf(("READ sum from discn"));
- }
-
- if (discsum != buff_s[0]) {
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)7);
- dbg_printf (("ERROR sdram check sum doens't match disc check sumn"));
- return FALSE;
- }
- buff_sum[0] = discsum;
- #ifdef UPDATE_CD_WITH_PLAYER_SETTING
- #ifdef FORCE_CD_IMAGE_SETTING_UPDATE
- if( IsForceImage == FALSE ) // is "feature select" data should be replace ?
- #endif
- if( ReplacePlayerSetting() == FALSE )
- {
- return FALSE;
- }
- else
- {
- buff_sum[0] = CalcCheckSum();
- }
- #endif
- #ifdef SUPPORT_KEYS_UPDATE
- #ifdef STORE_KEYS_IN_FLASH
- if( ReplaceHDCPKeys() == FALSE )
- {
- return FALSE;
- }
- else
- {
- tr_printf(("HDCP Keys was restoren"));
- buff_sum[0] = _CalcCheckSum();
- }
- #endif //STORE_KEYS_IN_FLASH
- #endif //SUPPORT_KEYS_UPDATE
- #ifdef AVI_DRM_SUPPORT
- #ifdef STORE_PS_DATA_IN_FLASH
- if( _ReplaceDivXDRMMemory() == FALSE )
- {
- return FALSE;
- }
- else
- {
- tr_printf(("DivX DRM Memory was restoren"));
- buff_sum[0] = _CalcCheckSum();
- }
- #endif //D_STORE_KEYS_IN_FLASH
- #endif // AVI_DRM_SUPPORT
- /* write check sum */
- if (DEC_WriteDRAMData( SDRAM_COPY_ADDR+2, buff_sum, 1) != 1){
- ie_send_ex(IE_UI_FP_UPDATE_ERROR, (void *)8);
- return FALSE;
- }
-
- return TRUE;
- }
- #ifdef UPDATE_CD_WITH_PLAYER_SETTING
- /**********************************************************************************
- Purpose : Search for buff_char character in string_buff until search_index
- reached to length
- Input Parameters :
- Description : search_index used as the index runnig on the string
- Return Value : TRUE - String was found, else FALSE
- Comment: :
- **********************************************************************************/
- extern CONST unsigned char lib_setup_signature[];
- extern CONST unsigned char lib_setup_end[];
- static int search_index = 0;
- static BOOL SearchForString( unsigned char buff_char , CONST unsigned char *string_buff, int length )
- {
- if( string_buff[search_index] == buff_char )
- {
- search_index ++;
- if( search_index >= length )
- {
- // player setting erea found
- return TRUE;
- }
- }
- else
- {
- search_index = 0;
- if( string_buff[search_index] == buff_char )
- {
- search_index ++;
- }
- }
- return FALSE;
- }
- /**********************************************************************************
- Purpose : Search for EOS ( End Of Set ) string using image_eos_index index
- Input Parameters :
- Description : image_eos_index used as teh index runnig on the string
- Return Value : TRUE - String was found, else FALSE
- Comment: :
- **********************************************************************************/
- static int image_eos_index = 0;
- static BOOL IsImageEOS( unsigned char buff_char )
- {
- if( ( *((&EOS_Macro.endOfSettings0) + image_eos_index) ) == buff_char )
- {
- image_eos_index ++;
- if( image_eos_index >= 10 ) // is all string "END OF SET" found ?
- {
- // player setting erea found
- dbg_printf(("IsImageEOS return TRUE n"));
- return TRUE;
- }
- }
- else
- {
- image_eos_index = 0;
- if( ( *((&EOS_Macro.endOfSettings0) + image_eos_index) ) == buff_char )
- {
- image_eos_index ++;
- }
- }
- return FALSE;
- }
- /**********************************************************************************
- Purpose : Search for EOS ( End Of Set ) string using player_eos_index index
- Input Parameters :
- Description : player_eos_index used as the index runnig on the string
- Return Value : TRUE - String was found, else FALSE
- Comment: :
- **********************************************************************************/
- static int player_eos_index = 0;
- static BOOL IsPlayerEOS( unsigned char buff_char )
- {
- if( ( *((&EOS_Macro.endOfSettings0) + player_eos_index) ) == buff_char )
- {
- player_eos_index ++;
- if( player_eos_index >= 10 )
- {
- // player setting erea found
- dbg_printf(("IsPlayerEOS return TRUE n"));
- return TRUE;
- }
- }
- else
- {
- player_eos_index = 0;
- if( ( *((&EOS_Macro.endOfSettings0) + player_eos_index) ) == buff_char )
- {
- player_eos_index ++;
- }
- }
- return FALSE;
- }
- /**********************************************************************************
- Purpose : Replace player configuration setting in cd-image with curret player setting
- Input Parameters :
- Description : read cd-image data from SDRAM searching for the "configuration setting"
- data and replace it with the player configuration data.
- The algorithm to copy the "feature select" erea is :
- Copy "feature select" area bits from player until EOS will be found on player
- "feature select" data or on cd-image "feature select" data or FSA end was found.
- Return Value : TRUE - replacment successed, else FALSE
- Comment: :
- **********************************************************************************/
- static BOOL ReplacePlayerSetting(void)
- {
- unsigned int image_sectors_size;
- UINT32 dram_addr = SDRAM_COPY_ADDR+3;
- UINT32 setting_start_addr = NULL;
- UINT16 i_sectors,i_buff,x;
- UINT16 *buff;
- unsigned char buff_s[BUFF_SIZE*2];
- int byte_count = 0;
-
- buff= (unsigned short*)buff_s;
- search_index = 0;
- if (!(DEC_ReadDRAMData(SDRAM_COPY_ADDR, buff, 2) == 2))
- return FALSE;
- image_sectors_size = buff[0] + (buff[1] << 8 );
- for (i_sectors=0; i_sectors< image_sectors_size ; i_sectors++) { // Process REFLASH_CODE_SIZE CD sectors
- for (i_buff=0; i_buff<COUNT_1_SECTOR; i_buff++) { // Copy 1 CD sector
- /* read image from SDRAM */
- if (!(DEC_ReadDRAMData(dram_addr, buff, BUFF_SIZE) == BUFF_SIZE))
- return FALSE;
-
- // Search for the player setting erea
- for( x=0; x < 64; x++)
- {
- if( setting_start_addr == NULL )
- {
- if( SearchForString(buff_s[x], lib_setup_signature, 33) )
- {
- dbg_printf(("Find lib_setup_signature n"));
- setting_start_addr = dram_addr + (UINT32)x/2;
- search_index = 0;
- image_eos_index = 0;
- player_eos_index = 0;
- }
- }
- else
- {
- BOOL isImageEnd = IsImageEOS( buff_s[x]);
- BOOL isPlayerEnd = IsPlayerEOS( *(&lib_setup_signature[33]+byte_count) );
- BOOL isFSAEnd = SearchForString(buff_s[x],lib_setup_end, 32);
- byte_count ++;
- if( isImageEnd || isPlayerEnd || isFSAEnd ) // Is EOS or FSA end was found ?
- {
- dbg_printf(("Find FSA or EOS n"));
- byte_count = byte_count - 9; // minus size of EOS string
- {
- UINT32 current_player_setting_size = (&(lib_setup_end[31]) - &(lib_setup_signature[32]))/2;
- if( byte_count/2 <= current_player_setting_size ) // is byte_count offset is before FSA end ?
- {
- // replace can be done
- CONST unsigned char *setting_data;
- dbg_printf(("Start replacement n"));
- setting_data = (unsigned char*)(&(lib_setup_signature[32]));
-
- if( byte_count/2 < 64 )
- {
- if (DEC_WriteDRAMData( setting_start_addr, setting_data, byte_count/2) != byte_count/2)
- return FALSE;
- dbg_printf(("Replace done n"));
- return TRUE;
- }
- else
- {
- // buff size is not enouph - not need it now ...
- return FALSE;
- }
- }
- else
- {
- return FALSE;
- }
- }
- break;
- }
- }
- }
- // continue reading from SDRAM addressed in words
- dram_addr += BUFF_SIZE;
- }
- }
- return TRUE;
- }
- #endif
- /**********************************************************************************
- Purpose : Calculate check sum
- Input Parameters : none
- Description :
- Return Value : checksum number
- Comment: :
- **********************************************************************************/
- static BYTE _CalcCheckSum(void)
- {
- unsigned int image_sectors_size;
- UINT32 dram_addr = SDRAM_COPY_ADDR+3;
- UINT16 i_sectors,i_buff,x;
- UINT16 *buff;
- BYTE discsum = 0;
- unsigned char buff_s[BUFF_SIZE*2];
- buff= (unsigned short*)buff_s;
-
- buff= (unsigned short*)buff_s;
- if (!(DEC_ReadDRAMData(SDRAM_COPY_ADDR, buff, 2) == 2))
- return FALSE;
- image_sectors_size = buff[0] + (buff[1] << 8 );
- for (i_sectors=0; i_sectors< image_sectors_size ; i_sectors++) { // Process REFLASH_CODE_SIZE CD sectors
- for (i_buff=0; i_buff<COUNT_1_SECTOR; i_buff++) { // Copy 1 CD sector
- /* read image from SDRAM and calculate checksum */
- if (!(DEC_ReadDRAMData(dram_addr, buff, BUFF_SIZE) == BUFF_SIZE))
- return FALSE;
-
- for( x=0; x < 64; x++)
- {
- discsum += buff_s[x];
- }
- dram_addr += BUFF_SIZE; // SDRAM addressed in words
- }
- }
- return discsum;
- }
- /**********************************************************************************
- Purpose :
- Input Parameters :
- Description :
- Return Value :
- Comment: :
- **********************************************************************************/
- #ifdef CD_UPDATE_MULTIPLE_DIRECTORIES
- static void SetImageModelPath(WCHAR *ImageDirectory )
- {
- wcscpy( ImageDirectory, L" "); // set root directory as default
- IFDEF(Decoder_Macro.bNO_ANALOG_6CHANNEL)
- // 2 Channel
- switch(HW_Macro.eDacType)
- {
- case CS4392:
- wcscpy( ImageDirectory ,L"VADDIS6E\2CH\CS4392");
- break;
- case AK4382A:
- wcscpy( ImageDirectory ,L"VADDIS6E\2CH\AK4382A");
- break;
- }
- ELSE // 6 Channel
- switch(HW_Macro.eDacType)
- {
- case AK4356:
- wcscpy( ImageDirectory ,L"VADDIS6E\6CH\AK4356");
- break;
- case PCM1606:
- wcscpy( ImageDirectory ,L"VADDIS6E\6CH\PCM1606");
- break;
- }
- ENDIF
- }
- #endif //CD_UPDATE_MULTIPLE_DIRECTORIES
- /**********************************************************************************
- Purpose : identfy if disc is CD Update
- Input Parameters : none
- Description : search for the file update.ver if exist read from it the
- image file name
- Return Value : return image file start address or FLASE if fail read it
- Comment: :
- **********************************************************************************/
- int DiscReadyDownload(void)
- {
- BOOL bSuccess= FALSE;
- DWORD dwFileAddr;
- LPWSTR pImageFilename;
- LPSTR pszExtension;
- UINT16 uFilenameLegth;
- UINT16 hFindFile;
- FindData fdCDUpdateInfo;
-
- g_dwImageFileSize= 0;
- if (! FileSys_selectType(eAny) || ! FileSys_initialize(FALSE)) {
- return FALSE;
- }
- #ifdef D_QS_UPGRADE_WAY
- pImageFilename = g_upgrade_file_name;
- uFilenameLegth= wcslen((LPCWSTR)g_upgrade_file_name);
- #else
- FileSys_getFileLocation(L"UPDATE.VER" , &dwFileAddr);
- #ifdef CD_UPDATE_MULTIPLE_DIRECTORIES
- SetImageModelPath(fdCDUpdateInfo.szFileID); // set image directory
- FileSys_goToRootDir(); // start search path from root directory
- FileSys_setPathDelimiter( '\');
- FileSys_changeDir(fdCDUpdateInfo.szFileID);
- /* we reached this point we are in the requested directory or in the root
- directory , there should not be any image.bld there */
- #endif // CD_UPDATE_MULTIPLE_DIRECTORIES
- /* read image file name */
- AuxCache_GetBytes(dwFileAddr, 0, MAX_FILE_NAME_LEN, (BYTE*)fdCDUpdateInfo.szFileID);
- pszExtension= strrchr((LPCSTR)fdCDUpdateInfo.szFileID, '.');
- if (NULL != pszExtension)
- *pszExtension= 0;
- uFilenameLegth= strlen((LPCSTR)fdCDUpdateInfo.szFileID);
- pImageFilename= (LPWSTR)malloc((1 + uFilenameLegth) * sizeof(WCHAR));
-
- if (NULL == pImageFilename)
- return FALSE;
- _str2wcs((LPCSTR)fdCDUpdateInfo.szFileID, pImageFilename,
- ((1 + uFilenameLegth) * sizeof(WCHAR)));
- #ifdef CD_UPDATE_MULTIPLE_MODELS
- // update image name with player UNIQUE_BUILD_ID
- pImageFilename[uFilenameLegth-1] = 0x30 + (Model_Macro.uniqueBuildID%10);
- pImageFilename[uFilenameLegth-2] = 0x30 + (Model_Macro.uniqueBuildID/10);
- #endif // CD_UPDATE_MULTIPLE_MODELS
- #ifdef FORCE_CD_IMAGE_SETTING_UPDATE
- /* If update.ver contains the string "force" or "force.img" it should directly
- load force.img to the flash without modifying FSA. */
- IsForceImage = FALSE;
- if (0 == _wcsnicmp( L"force" , pImageFilename, 5))
- {
- IsForceImage = TRUE;
- }
- #endif //FORCE_CD_IMAGE_SETTING_UPDATE
- #endif //D_QS_UPGRADE_WAY
- /* search for Image file name in CD , not sensetive case */
- hFindFile= FileSys_findFirstFile(FILESYS_WILDCARD_SEARCH, &fdCDUpdateInfo);
- do
- {
- if (0 == _wcsnicmp(pImageFilename, fdCDUpdateInfo.szFileID, uFilenameLegth))
- {
- FileSys_findClose(hFindFile);
- g_dwImageFileAddr = fdCDUpdateInfo.dwStartAddr;
- g_dwImageFileSize= fdCDUpdateInfo.cbFileSizeLow;
- bSuccess= TRUE;
- break;
- }
- } while (FileSys_findNextFile(hFindFile, &fdCDUpdateInfo));
- // <<< ZKR GL080703 : Support new version string display with firmware upgrade menu.
- #ifdef EXINO2
- if ( bSuccess )
- {
- extern CONST char g_pszVersionString[];
- DWORD dwLBN;
- DWORD dwOffset;
- CHAR csVersion[VERSION_STRING_SZ];
- DWORD dwVersionOffset = (g_dwImageFileSize-VERSION_STRING_SZ-1L/*CHECKSUM_SZ*/);
- dwLBN = g_dwImageFileAddr + ( dwVersionOffset / SECTOR_SIZE );
- dwOffset = ( dwVersionOffset % SECTOR_SIZE );
- if (!AuxCache_GetBytes(dwLBN, dwOffset, VERSION_STRING_SZ, csVersion)) {
- tr_printf(("Can't read the version on CDn"));
- return FALSE;
- }
- tr_printf(("nCurrent Version : %s", (char *)(g_pszVersionString+VERSION_SIGNATURE_SZ)));
- tr_printf(("nNew Version : %s", csVersion));
- if (strlen(csVersion) >= (SC_VERSION_MSG_SZ<<2)) {
- tr_printf(("ERROR version strlen >= SC_VERSION_MSG_SZ"));
- return FALSE;
- }
- // Save new version string into scpad.
- csVersion[strlen(csVersion)] = 0;
- // SEC BK.LIM080803: 18 Characters are enabled for version string
- sc_SetBytes(SC_VERSION_MSG_ADDR, 0, VERSION_STRING_SZ-14, (BYTE *)csVersion);
- }
- #endif // EXINO2
- // ZKR GL080703 >>>
- free(pImageFilename);
- return bSuccess;
- }
- /**********************************************************************************
- Purpose : copy image to SDRAM and download reflasher program into scratch pad
- Input Parameters : disc_addr - start address of image file
- Description : Copy image to SDRAM , copy reflasher program to RAM and jump to
- teh reflasher program which read the image from SDRAM and burn it.
- Return Value : if successed should never return
- Comment: :
- **********************************************************************************/
- BOOL DiscDownload(void)
- {
- if (discCopyToDram())
- {
- BYTE i;
-
- #if defined(RESTORE_PS_ON_CD_UPDATE)||defined(EXINO2)
- PS_RestoreFactoryDefault();
- #endif
- drv_tray_open();
- #ifdef D_QSI_LOADER
- for (i = 0; i < 3; i++)
- usleep(5000000UL);
- #else
- usleep(5000000UL);
- #endif
- #ifdef D_FLASH_UPDATA_OPEN//tecobest gxd 20050724 for do not open after flash updated
- for(i=0;i<10;i++)
- {
- usleep(1000000L);
- if(TrayLL_IsTrayOpened())
- break;
- }
- #endif
- dbg_printf(("Start to Copy Reflasher to SRAMn"));
- cpu_disable_all_interrupts();
- asm // prepare new stack
- {
- mov ax,0
- mov ss,ax
- mov sp,0x200
- mov bp,0x200
- }
- copy_reflsher_and_run();
- }
- dbg_printf (("nERROR discCopyToDramn"));
- return FALSE;
- }
- /**********************************************************************************
- Purpose : copy reflasher to RAM and run it
- Input Parameters : none
- Return Value : if successed should never return
- Comment: :
- **********************************************************************************/
- static void copy_reflsher_and_run(void)
- {
- unsigned long i;
- void (*ReflashFromRam)(void);
- unsigned short *flash_address;
- flash_address = (unsigned short *)cpu_get_reflasher_base_address();
- for(i=0;i<cpu_reflasher_length();i++)
- {
- *flash_address++ = reflasher[i];
- }
- ReflashFromRam = (void (*)(void))cpu_get_reflasher_base_address();
- (*ReflashFromRam)(); // never return from here
- }
- #ifdef SUPPORT_KEYS_UPDATE
- #ifdef STORE_KEYS_IN_FLASH
- /**********************************************************************************
- Purpose : Replace player configuration setting in cd-image with curret player setting
- Input Parameters :
- Description : read cd-image data from SDRAM searching for the "configuration setting"
- data and replace it with the player configuration data.
- The algorithm to copy the "feature select" erea is :
- Copy "feature select" area bits from player until EOS will be found on player
- "feature select" data or on cd-image "feature select" data or FSA end was found.
- Return Value : TRUE - replacment successed, else FALSE
- Comment: :
- **********************************************************************************/
- static BOOL ReplaceHDCPKeys(void)
- {
- UINT32 offset;
- UINT32 dram_addr = SDRAM_COPY_ADDR+3;
- unsigned int *buff_s = (unsigned int *)STORE_KEYS_START_ADDRESS;
- offset = ((UINT32)STORE_KEYS_SEG - 0x4000UL) >> 1;
- offset <<= 0x8; //hansj 04/08/2005
- if (DEC_WriteDRAMData( dram_addr + offset, buff_s, STORE_KEYS_SIZE) != STORE_KEYS_SIZE)
- return FALSE;
- return TRUE;
- }
- #endif//STORE_KEYS_IN_FLASH
- #endif //SUPPORT_KEYS_UPDATE
- #ifdef AVI_DRM_SUPPORT
- #ifdef STORE_PS_DATA_IN_FLASH
- /****************************************************************************************************
- * Function : _ReplaceDivXDRMMemory
- * Input :
- * Output :
- * Return : FALSE - failed, TRUE - else
- * Description : Protect the DRM memory not to change during CD-update
- ****************************************************************************************************/
- static BOOL _ReplaceDivXDRMMemory(void)
- {
- UINT32 dwDramAddr;
- UINT16 wOffset;
- BOOL bOddFlag;
- unsigned int *buff_s = (unsigned int *)MK_FP(PS_SEG, 0);
- UINT8 TempBuf[PACKED_ALLOCATION_BYTES + 2];
- if (!_SearchFactorySetting(&dwDramAddr, &wOffset))
- return FALSE;
- dwDramAddr += (wOffset/2);
- bOddFlag = (0 != wOffset%2);
- if (DEC_ReadDRAMData(dwDramAddr, (UINT16*)&TempBuf[0], (PACKED_ALLOCATION_BYTES+2)/2) != (PACKED_ALLOCATION_BYTES+2)/2)
- return FALSE;
- if (bOddFlag)
- memcpy(&TempBuf[1], (UINT8*)buff_s, PACKED_ALLOCATION_BYTES);
- else
- memcpy(&TempBuf[0], (UINT8*)buff_s, PACKED_ALLOCATION_BYTES);
- if (DEC_WriteDRAMData(dwDramAddr, (UINT16*)&TempBuf[0], (PACKED_ALLOCATION_BYTES+2)/2) != (PACKED_ALLOCATION_BYTES+2)/2)
- return FALSE;
-
- return TRUE;
- }
- static BOOL _SearchFactorySetting(UINT32 *dwSettingStartAddr, UINT16 *wSettingOffset)
- {
- UINT16 wImageSectorsSize;
- UINT16 wSectorCount;
- unsigned char cBuff[BUFF_SIZE*2];
- UINT16 wBuffCount, wBuffOffset;
- UINT32 dwDramAddr = SDRAM_COPY_ADDR+3;
- UINT16 wSettingIndex = 0;
- unsigned char *string_buff = (unsigned char *)&default_factory_settings_signature;
- UINT16 wSettingLength = 33;
- UINT16 wBuff[2];
-
- if (!(DEC_ReadDRAMData(SDRAM_COPY_ADDR, (UINT16*)&wBuff[0], 2) == 2))
- return FALSE;
- wImageSectorsSize = wBuff[0] + (wBuff[1] << 8 );
- for (wSectorCount=0; wSectorCount<wImageSectorsSize; wSectorCount++)
- {
- for (wBuffCount=0; wBuffCount<COUNT_1_SECTOR; wBuffCount++)
- {
- // read image from SDRAM
- if (!(DEC_ReadDRAMData(dwDramAddr, (UINT16*)&cBuff[0], BUFF_SIZE) == BUFF_SIZE))
- return FALSE;
-
- // Search for the factory setting area
- for( wBuffOffset=0; wBuffOffset< 64; wBuffOffset++)
- {
- if (string_buff[wSettingIndex] == cBuff[wBuffOffset])
- {
- wSettingIndex++;
- }
- else
- {
- wSettingIndex = 0;
- }
- if (wSettingIndex >= wSettingLength)
- {
- *dwSettingStartAddr = dwDramAddr;
- *wSettingOffset = wBuffOffset + 1;
- return TRUE;
- }
- }
- // continue reading from SDRAM addressed in words
- dwDramAddr += BUFF_SIZE;
- }
- }
- return FALSE;
- }
- #endif // D_SUPPORT_KEYS_UPDATE
- #endif // AVI_DRM_SUPPORT