Store_KEYS.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:5k
源码类别:

DVD

开发平台:

Others

  1. #include "Config.h" // Global Configuration - do not remove!
  2. #ifdef SUPPORT_KEYS_UPDATE
  3. #ifdef _DEBUG
  4. #undef IFTRACE
  5. #define IFTRACE if (gTraceCore)
  6. #include "DebugDbgMain.h"
  7. #endif
  8. #include "CPUCPU_API.h"
  9. #include "DecoderDecoder.h"
  10. #include "eeprom.h"
  11. #include "UartUart_api.h"
  12. #include "UARTStore_Keys.h"
  13. #include "PlaycoreCoremainCoreGDef.h"
  14. #ifdef STORE_KEYS_IN_FLASH
  15. #ifdef STORE_HDCP_KEYS
  16. CONST _HDCP_KEYS_STRUCT far *HDCP_keys_struct = (_HDCP_KEYS_STRUCT far *)HDCP_KEYS_START_ADDRESS;
  17. CONST BYTE *Scramble_Keys = (BYTE*)HDCP_KEYS_START_ADDRESS + sizeof(_HDCP_KEYS_HEAD);
  18. CONST BYTE *Key_Select_Vector = (BYTE*)HDCP_KEYS_START_ADDRESS + sizeof(_HDCP_KEYS_HEAD)+SCRAMBLE_KEYS_SIZE_IN_BYTE;
  19. CONST BYTE *HDCP_KEYS = (BYTE*)HDCP_KEYS_START_ADDRESS + sizeof(_HDCP_KEYS_HEAD)+SCRAMBLE_KEYS_SIZE_IN_BYTE+KEY_SELECT_VECTOR_SIZE_IN_BYTE;
  20. #endif
  21. #ifdef STORE_DVDA_KEYS
  22. CONST _DVDA_KEYS_STRUCT far *DVDA_keys_struct = (_DVDA_KEYS_STRUCT far *)DVDA_KEYS_START_ADDRESS;
  23. CONST BYTE *DVDA_KEY_TYPE_POINT = (BYTE*)DVDA_KEYS_START_ADDRESS + sizeof(_DVDA_KEYS_HEAD);
  24. CONST BYTE *DVDA_KEYS = (BYTE*)DVDA_KEYS_START_ADDRESS + sizeof(_DVDA_KEYS_HEAD)+1;
  25. #endif
  26. #ifdef STORE_DVDVR_KEYS
  27. CONST _DVDVR_KEYS_STRUCT far *DVDVR_keys_struct = (_DVDVR_KEYS_STRUCT far *)DVDVR_KEYS_START_ADDRESS;
  28. CONST BYTE *DVDVR_KEY_TYPE_POINT = (BYTE*)DVDVR_KEYS_START_ADDRESS + sizeof(_DVDVR_KEYS_HEAD);
  29. CONST BYTE *DVDVR_KEYS = (BYTE*)DVDVR_KEYS_START_ADDRESS + sizeof(_DVDVR_KEYS_HEAD)+1;
  30. #endif
  31. #else // STORE_KEYS_IN_FLASH
  32. #ifdef STORE_HDCP_KEYS
  33. CONST WORD Scramble_Keys_offset = STORE_KEYS_OFFSET_ADDR+HDCP_KEYS_OFFSET+sizeof(_HDCP_KEYS_HEAD);
  34. CONST WORD Key_Select_Vector_offset = STORE_KEYS_OFFSET_ADDR+HDCP_KEYS_OFFSET+sizeof(_HDCP_KEYS_HEAD)+SCRAMBLE_KEYS_SIZE_IN_BYTE;
  35. 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;
  36. #endif
  37. #ifdef STORE_DVDA_KEYS
  38. CONST WORD DVDA_KEYS_offset = STORE_KEYS_OFFSET_ADDR+DVDA_KEYS_OFFSET+sizeof(_DVDA_KEYS_HEAD)+1;
  39. #endif
  40. #ifdef STORE_DVDVR_KEYS
  41. CONST WORD DVDVR_KEYS_offset = STORE_KEYS_OFFSET_ADDR+DVDVR_KEYS_OFFSET+sizeof(_DVDVR_KEYS_HEAD)+1;
  42. #endif
  43. #endif // STORE_KEYS_IN_FLASH
  44. CONST BYTE Store_Keys_Num = STORE_KEYS_NUM;
  45. CONST KEYS_STORE_STRUCT Store_Keys_Map[Store_Keys_Num]={
  46. #ifdef STORE_KEYS_IN_FLASH
  47. #ifdef STORE_HDCP_KEYS
  48. {KEY_TYPE_HDCP, sizeof(_HDCP_KEYS_STRUCT), HDCP_KEYS_OFFSET, HDCP_KEYS_START_ADDRESS},
  49. #endif
  50. #ifdef STORE_DVDA_KEYS
  51. {KEY_TYPE_DVDA, sizeof(_DVDA_KEYS_STRUCT), DVDA_KEYS_OFFSET, DVDA_KEYS_START_ADDRESS},
  52. #endif
  53. #ifdef STORE_DVDVR_KEYS
  54. {KEY_TYPE_DVDVR, sizeof(_DVDVR_KEYS_STRUCT), DVDVR_KEYS_OFFSET, DVDVR_KEYS_START_ADDRESS},
  55. #endif
  56. #else // STORE_KEYS_IN_FLASH
  57. #ifdef STORE_HDCP_KEYS
  58. {KEY_TYPE_HDCP, sizeof(_HDCP_KEYS_STRUCT), HDCP_KEYS_OFFSET, STORE_KEYS_OFFSET_ADDR+HDCP_KEYS_OFFSET},
  59. #endif
  60. #ifdef STORE_DVDA_KEYS
  61. {KEY_TYPE_DVDA, sizeof(_DVDA_KEYS_STRUCT), DVDA_KEYS_OFFSET, STORE_KEYS_OFFSET_ADDR+DVDA_KEYS_OFFSET},
  62. #endif
  63. #ifdef STORE_DVDVR_KEYS
  64. {KEY_TYPE_DVDVR, sizeof(_DVDVR_KEYS_STRUCT), DVDVR_KEYS_OFFSET, STORE_KEYS_OFFSET_ADDR+DVDVR_KEYS_OFFSET},
  65. #endif
  66. #endif // STORE_KEYS_IN_FLASH
  67. };
  68. BYTE* new_keys=(BYTE*)&gns;
  69. void _Key_Save(unsigned short far *flash_sa, BYTE* buffer_s, int size)
  70. {
  71. BYTE buff[2];
  72. int i;
  73. for( i = 0; i < size; i=i+2 ){
  74. buff[0] = buffer_s[i];
  75. buff[1] = buffer_s[i+1];
  76. Nor_Write((unsigned short huge *)flash_sa, (unsigned char far *)buff, 2);
  77. flash_sa++;
  78. }
  79. return;
  80. }
  81. BOOL _save_keys_to_flash(unsigned short far *flash_sa, BYTE* buffer_s, int size)
  82. {
  83. //if ( !CheckAddressWritable((unsigned short far *)flash_sa)){
  84. dbg_printf(("Updating Flash ROMn"));
  85. //Flash Rom
  86. //asm{cli};
  87. Init_FLASH_Burner_API();
  88. Erase_One_Sector( (unsigned short huge *)flash_sa );
  89. _Key_Save(flash_sa, buffer_s, size);
  90. //asm{sti};
  91. //}
  92. return TRUE;
  93. }
  94. BOOL Store_Keys_Save(BYTE* buffer_s)
  95. {
  96. int size = STORE_KEYS_END_OFFSET;
  97. BOOL success;
  98. #ifdef STORE_KEYS_IN_FLASH
  99. success=_save_keys_to_flash((unsigned short far *)STORE_KEYS_START_ADDRESS, buffer_s, size);
  100. if(success)
  101. {
  102. outport(0xA2C,0x28F); //Disable iCashe
  103. success = (memcmp((BYTE*)STORE_KEYS_START_ADDRESS, buffer_s, size)==0);
  104. outport(0xA2C,0x28C); //Enable iCashe
  105. }
  106. #else
  107. success=eeprom_write((WORD)STORE_KEYS_OFFSET_ADDR,buffer_s, STORE_KEYS_END_OFFSET );
  108. #endif//STORE_KEYS_IN_FLASH
  109. if(success)
  110. tr_printf(("Updating keys success!n"));
  111. else
  112. tr_printf(("Updating keys fail!n"));
  113. return success;
  114. }
  115. #endif //SUPPORT_KEYS_UPDATE