Store_KEYS.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:5k
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef SUPPORT_KEYS_UPDATE
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceCore)
- #include "DebugDbgMain.h"
- #endif
- #include "CPUCPU_API.h"
- #include "DecoderDecoder.h"
- #include "eeprom.h"
- #include "UartUart_api.h"
- #include "UARTStore_Keys.h"
- #include "PlaycoreCoremainCoreGDef.h"
- #ifdef STORE_KEYS_IN_FLASH
- #ifdef STORE_HDCP_KEYS
- CONST _HDCP_KEYS_STRUCT far *HDCP_keys_struct = (_HDCP_KEYS_STRUCT far *)HDCP_KEYS_START_ADDRESS;
- CONST BYTE *Scramble_Keys = (BYTE*)HDCP_KEYS_START_ADDRESS + sizeof(_HDCP_KEYS_HEAD);
- CONST BYTE *Key_Select_Vector = (BYTE*)HDCP_KEYS_START_ADDRESS + sizeof(_HDCP_KEYS_HEAD)+SCRAMBLE_KEYS_SIZE_IN_BYTE;
- CONST BYTE *HDCP_KEYS = (BYTE*)HDCP_KEYS_START_ADDRESS + sizeof(_HDCP_KEYS_HEAD)+SCRAMBLE_KEYS_SIZE_IN_BYTE+KEY_SELECT_VECTOR_SIZE_IN_BYTE;
- #endif
- #ifdef STORE_DVDA_KEYS
- CONST _DVDA_KEYS_STRUCT far *DVDA_keys_struct = (_DVDA_KEYS_STRUCT far *)DVDA_KEYS_START_ADDRESS;
- CONST BYTE *DVDA_KEY_TYPE_POINT = (BYTE*)DVDA_KEYS_START_ADDRESS + sizeof(_DVDA_KEYS_HEAD);
- CONST BYTE *DVDA_KEYS = (BYTE*)DVDA_KEYS_START_ADDRESS + sizeof(_DVDA_KEYS_HEAD)+1;
- #endif
- #ifdef STORE_DVDVR_KEYS
- CONST _DVDVR_KEYS_STRUCT far *DVDVR_keys_struct = (_DVDVR_KEYS_STRUCT far *)DVDVR_KEYS_START_ADDRESS;
- CONST BYTE *DVDVR_KEY_TYPE_POINT = (BYTE*)DVDVR_KEYS_START_ADDRESS + sizeof(_DVDVR_KEYS_HEAD);
- CONST BYTE *DVDVR_KEYS = (BYTE*)DVDVR_KEYS_START_ADDRESS + sizeof(_DVDVR_KEYS_HEAD)+1;
- #endif
- #else // STORE_KEYS_IN_FLASH
- #ifdef STORE_HDCP_KEYS
- CONST WORD Scramble_Keys_offset = STORE_KEYS_OFFSET_ADDR+HDCP_KEYS_OFFSET+sizeof(_HDCP_KEYS_HEAD);
- CONST WORD Key_Select_Vector_offset = STORE_KEYS_OFFSET_ADDR+HDCP_KEYS_OFFSET+sizeof(_HDCP_KEYS_HEAD)+SCRAMBLE_KEYS_SIZE_IN_BYTE;
- CONST WORD HDCP_KEYS_offset = STORE_KEYS_OFFSET_ADDR+HDCP_KEYS_OFFSET+sizeof(_HDCP_KEYS_HEAD)+SCRAMBLE_KEYS_SIZE_IN_BYTE+KEY_SELECT_VECTOR_SIZE_IN_BYTE;
- #endif
- #ifdef STORE_DVDA_KEYS
- CONST WORD DVDA_KEYS_offset = STORE_KEYS_OFFSET_ADDR+DVDA_KEYS_OFFSET+sizeof(_DVDA_KEYS_HEAD)+1;
- #endif
- #ifdef STORE_DVDVR_KEYS
- CONST WORD DVDVR_KEYS_offset = STORE_KEYS_OFFSET_ADDR+DVDVR_KEYS_OFFSET+sizeof(_DVDVR_KEYS_HEAD)+1;
- #endif
- #endif // STORE_KEYS_IN_FLASH
- CONST BYTE Store_Keys_Num = STORE_KEYS_NUM;
- CONST KEYS_STORE_STRUCT Store_Keys_Map[Store_Keys_Num]={
- #ifdef STORE_KEYS_IN_FLASH
- #ifdef STORE_HDCP_KEYS
- {KEY_TYPE_HDCP, sizeof(_HDCP_KEYS_STRUCT), HDCP_KEYS_OFFSET, HDCP_KEYS_START_ADDRESS},
- #endif
- #ifdef STORE_DVDA_KEYS
- {KEY_TYPE_DVDA, sizeof(_DVDA_KEYS_STRUCT), DVDA_KEYS_OFFSET, DVDA_KEYS_START_ADDRESS},
- #endif
- #ifdef STORE_DVDVR_KEYS
- {KEY_TYPE_DVDVR, sizeof(_DVDVR_KEYS_STRUCT), DVDVR_KEYS_OFFSET, DVDVR_KEYS_START_ADDRESS},
- #endif
- #else // STORE_KEYS_IN_FLASH
- #ifdef STORE_HDCP_KEYS
- {KEY_TYPE_HDCP, sizeof(_HDCP_KEYS_STRUCT), HDCP_KEYS_OFFSET, STORE_KEYS_OFFSET_ADDR+HDCP_KEYS_OFFSET},
- #endif
- #ifdef STORE_DVDA_KEYS
- {KEY_TYPE_DVDA, sizeof(_DVDA_KEYS_STRUCT), DVDA_KEYS_OFFSET, STORE_KEYS_OFFSET_ADDR+DVDA_KEYS_OFFSET},
- #endif
- #ifdef STORE_DVDVR_KEYS
- {KEY_TYPE_DVDVR, sizeof(_DVDVR_KEYS_STRUCT), DVDVR_KEYS_OFFSET, STORE_KEYS_OFFSET_ADDR+DVDVR_KEYS_OFFSET},
- #endif
- #endif // STORE_KEYS_IN_FLASH
- };
- BYTE* new_keys=(BYTE*)&gns;
- void _Key_Save(unsigned short far *flash_sa, BYTE* buffer_s, int size)
- {
- BYTE buff[2];
- int i;
-
- for( i = 0; i < size; i=i+2 ){
- buff[0] = buffer_s[i];
- buff[1] = buffer_s[i+1];
- Nor_Write((unsigned short huge *)flash_sa, (unsigned char far *)buff, 2);
- flash_sa++;
- }
-
- return;
- }
- BOOL _save_keys_to_flash(unsigned short far *flash_sa, BYTE* buffer_s, int size)
- {
- //if ( !CheckAddressWritable((unsigned short far *)flash_sa)){
- dbg_printf(("Updating Flash ROMn"));
- //Flash Rom
- //asm{cli};
- Init_FLASH_Burner_API();
- Erase_One_Sector( (unsigned short huge *)flash_sa );
- _Key_Save(flash_sa, buffer_s, size);
- //asm{sti};
- //}
-
- return TRUE;
- }
- BOOL Store_Keys_Save(BYTE* buffer_s)
- {
- int size = STORE_KEYS_END_OFFSET;
- BOOL success;
-
- #ifdef STORE_KEYS_IN_FLASH
- success=_save_keys_to_flash((unsigned short far *)STORE_KEYS_START_ADDRESS, buffer_s, size);
- if(success)
- {
- outport(0xA2C,0x28F); //Disable iCashe
- success = (memcmp((BYTE*)STORE_KEYS_START_ADDRESS, buffer_s, size)==0);
- outport(0xA2C,0x28C); //Enable iCashe
- }
- #else
- success=eeprom_write((WORD)STORE_KEYS_OFFSET_ADDR,buffer_s, STORE_KEYS_END_OFFSET );
- #endif//STORE_KEYS_IN_FLASH
- if(success)
- tr_printf(("Updating keys success!n"));
- else
- tr_printf(("Updating keys fail!n"));
- return success;
- }
- #endif //SUPPORT_KEYS_UPDATE