sec_sign_header.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef SECIMGHEADER_H
  2. #define SECIMGHEADER_H
  3. /**************************************************************************
  4. * SIGN CFG PARSING
  5. **************************************************************************/
  6. #define CUSTOM_NAME "CUSTOM_NAME"
  7. #define IMAGE_VERSION "IMAGE_VERSION"
  8. /* in order to speedup verification, you can customize the image size
  9. which should be signed and checked at boot time */
  10. #define VERIFY_OFFSET "VERIFY_OFFSET"
  11. #define VERIFY_LENGTH "VERIFY_LENGTH"
  12. /**************************************************************************
  13. * SEC IMAGE HEADER FORMAT
  14. **************************************************************************/
  15. #define SEC_IMG_MAGIC (0x53535353)
  16. #define SEC_IMG_MAGIC_LEN (4)
  17. #define SEC_IMG_HEADER_SIZE (64)
  18. #define HASH_SIZE (20)
  19. #define RSA_KEY_SIZE (128)
  20. #define SIG_LEN (RSA_KEY_SIZE)
  21. #define HASH_SIG_LEN (HASH_SIZE+SIG_LEN)
  22. /* HASH + SIGNATURE */
  23. /* Legacy (before W1151) */
  24. typedef struct _SEC_IMG_HEADER_V1 {
  25. unsigned int magic_number;
  26. unsigned char cust_name[16];
  27. unsigned int image_version;
  28. unsigned int image_length;
  29. unsigned int image_offset;
  30. unsigned int sign_offset;
  31. unsigned int sign_length;
  32. unsigned int signature_offset;
  33. unsigned int signature_length;
  34. unsigned char dummy[16];
  35. } SEC_IMG_HEADER_V1;
  36. /* New (After W1151) */
  37. typedef struct _SEC_IMG_HEADER_V2 {
  38. unsigned int magic_number;
  39. /* After WK1151, the size of customer name will be changed from 16
  40. bytes to 32 bytes due to customer's request. To distinguish between the
  41. old version and new version, the simplest way is to check the value of
  42. signature_length.
  43. Flash tool downloads images by using new format
  44. => Tool can find the image is old because signature_length is all 0x00.
  45. Therefore, Flash tool will automatically apply old image format */
  46. unsigned char cust_name[32];
  47. unsigned int image_version;
  48. unsigned int image_length;
  49. unsigned int image_offset;
  50. unsigned int sign_offset;
  51. unsigned int sign_length;
  52. unsigned int signature_offset;
  53. unsigned int signature_length;
  54. } SEC_IMG_HEADER_V2, SEC_IMG_HEADER_V3, SEC_IMG_HEADER;
  55. typedef struct _SEC_IMG_HEADER_V4 {
  56. unsigned int magic_number;
  57. unsigned char cust_name[32];
  58. unsigned int image_verion;
  59. unsigned int signature_length;
  60. unsigned int image_offset;
  61. unsigned int ext_magic;
  62. unsigned int ext_hdr_length;
  63. unsigned int image_length_high;
  64. unsigned int image_length_low;
  65. } SEC_IMG_HEADER_V4;
  66. typedef union {
  67. SEC_IMG_HEADER_V1 v1;
  68. SEC_IMG_HEADER_V2 v2;
  69. SEC_IMG_HEADER_V3 v3;
  70. SEC_IMG_HEADER_V4 v4;
  71. /*this implies all */
  72. SEC_IMG_HEADER va;
  73. } SEC_IMG_HEADER_U;
  74. typedef enum {
  75. SEC_HDR_V1 = 1,
  76. SEC_HDR_V2 = 2,
  77. SEC_HDR_V3 = 3,
  78. SEC_HDR_V4 = 4,
  79. UNSET
  80. } SEC_IMG_HEADER_VER;
  81. /**************************************************************************
  82. * IMAGE HEADER CHECK OPERATION
  83. **************************************************************************/
  84. #define SEC_USBDL_WRITE_IMAGE_HEADER 0x11
  85. #define SEC_USBDL_WRITE_IMAGE_SIGNATURE_HASH 0x22
  86. #define SEC_USBDL_IMAGE_INFO_CHECK_RESULT 0x33
  87. #define SEC_USBDL_WRITE_IMAGE_NAME 0x44
  88. #define SEC_USBDL_WRITE_IMAGE_OFFSET 0x55
  89. #define SEC_USBDL_WRITE_TYPE 0x66
  90. #define SEC_USBDL_WRITE_IMAGE_EXTENSION 0x77
  91. #define SEC_USBDL_IMAGE_NAME_LEN 16
  92. #define SEC_USBDL_IMAGE_INFO_RESULT_PASS 0x5555
  93. #define SEC_USBDL_IMAGE_INFO_RESULT_FAIL 0x4444
  94. #endif /* SECIMGHEADER_H */