e299c7b818dcc53cd6d9746769bbb17d96671127
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc8830 / secure_boot.h
1 #ifndef _SECURE_BOOT_H_
2 #define _SECURE_BOOT_H_
3
4 #define KEY_INFO_SIZ    (512)
5 #define CUSTOM_DATA_SIZ (1024)
6 #define VLR_INFO_SIZ    (512)
7 #define VLR_INFO_OFF    (512)
8
9 #if defined(CONFIG_SPX30G)
10 #define INTER_RAM_BEGIN                 0x50003000
11 #else
12 #define INTER_RAM_BEGIN                 0x50005000
13 #endif
14 #define CONFIG_SEC_LOAD_LEN             0xC00
15 #define CONFIG_SYS_NAND_U_BOOT_LOAD_LEN 0x80000
16
17 #define KEY_INFO_OFF (INTER_RAM_BEGIN + CONFIG_SPL_LOAD_LEN - KEY_INFO_SIZ - VLR_INFO_SIZ)
18 #define VLR_INFO_OFF (CONFIG_SYS_NAND_U_BOOT_START + CONFIG_SYS_NAND_U_BOOT_SIZE - VLR_INFO_SIZ)
19
20 #ifdef CONFIG_NAND_SPL
21 #define panic(x...)  do{}while(0)
22 #define printf(x...) do{}while(0)
23 #endif
24
25 #define MIN_UNIT        (512)
26 #define HEADER_NAME "SPRD-SECUREFLAG"
27
28 #define VLR_NAME (0x3A524C56)
29 #define PUK_NAME (0x3A4B5550)
30 #define CODE_NAME (0x45444F43)
31
32 #define PUBLIC
33 #define SHA1HashSize 20
34 typedef unsigned int uint32_t;
35 typedef unsigned char uint8_t;
36 /*
37 * This structure will hold context information for the SHA-1
38 * hashing operation
39 */
40 typedef struct SHA1Context32 {
41         unsigned int Intermediate_Hash[5];      /* Message Digest */
42         unsigned int Length_Low;        /* Message length in bits */
43         unsigned int Length_High;       /* Message length in bits */
44         /* Index into message block array */
45         unsigned int Message_Block_Index;
46         unsigned int W[80];     /* 512-bit message blocks */
47 } SHA1Context_32;
48
49 typedef struct {
50         uint32_t tag_name;
51         uint32_t tag_offset;
52         uint32_t tag_size;
53         uint8_t reserved[4];
54 } tag_info_t;
55
56 typedef struct {
57         uint8_t header_magic[16];
58         uint32_t header_ver;
59         uint32_t tags_number;
60         uint8_t header_ver_padding[8];
61         tag_info_t tag[3];
62         uint8_t reserved[432];
63 } header_info_t;
64
65 typedef struct {
66         struct {
67                 uint32_t e;
68                 uint8_t m[128];
69                 uint8_t r2[128];
70         } key;
71         uint8_t reserved[4];
72 } bsc_info_t;
73
74 #define VLR_MAGIC (0x524C56FF)
75 typedef struct {
76         uint32_t magic;
77         uint8_t hash[128];
78         uint32_t setting;
79         uint32_t length;
80         uint8_t reserved[20];
81 } vlr_info_t;
82
83 typedef struct {
84         uint32_t intermediate_hash[5];
85         uint32_t length_low;
86         uint32_t length_high;
87         uint32_t msg_block_idx;
88         uint32_t W[80];
89 } sha1context_32;
90
91 typedef struct {
92         uint32_t ver;
93         uint8_t cap;
94         void (*efuse_init) (void);
95         void (*efuse_close) (void);
96          uint32_t(*efuse_read) (uint32_t block_id, uint32_t * data);
97          uint32_t(*sha1reset_32) (sha1context_32 *);
98          uint32_t(*sha1input_32) (sha1context_32 *, const uint32_t *, uint32_t);
99          uint32_t(*sha1result_32) (sha1context_32 *, uint8_t *);
100         void (*rsa_modpower) (uint32_t * p, uint32_t * m, uint32_t * r2, uint32_t e);
101 } rom_callback_func_t;
102
103 typedef struct {
104         rom_callback_func_t *rom_callback;
105         void (*secure_check) (uint8_t * data, uint32_t data_len, uint8_t * data_hash, uint8_t * data_key);
106 } sec_callback_func_t;
107
108 void secure_check(uint8_t * data, uint32_t data_len, uint8_t * data_hash, uint8_t * data_key);
109 int cal_md5(void *data, uint32_t len, void *harsh_data);
110 int secureboot_enabled(void);
111
112 /*
113 * Function Prototypes
114 */
115 PUBLIC int SHA1Reset_32(SHA1Context_32 *);
116 PUBLIC int SHA1Input_32(SHA1Context_32 *, const unsigned int *message, unsigned int len);
117 PUBLIC int SHA1Result_32(SHA1Context_32 * context, unsigned char *Message_Digest);
118
119 #endif