• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __UPG_CHECK_SECURE_H__
17 #define __UPG_CHECK_SECURE_H__
18 
19 #include <upg_common.h>
20 
21 #define RSA_2048_LEN  256
22 #define RSA_KEY_LEN   512
23 #define ECC_KEY_LEN   64
24 #define ECC_256_LEN   32
25 #define HI_BLOCK_SIZE 0x100
26 
27 #if defined(CONFIG_FLASH_ENCRYPT_SUPPORT)
28 #define FLASH_ADDR_NUM 3
29 #define TOTAL_SIZE_NUM 3
30 #define FLASH_FLAG_NUM 3
31 #else
32 #define FLASH_ADDR_NUM 2
33 #define TOTAL_SIZE_NUM 2
34 #define FLASH_FLAG_NUM 2
35 #endif
36 
37 #define UPG_SEC_BOOT_FLAG 0x42
38 
39 typedef struct {
40     uintptr_t flash_addr[FLASH_ADDR_NUM];
41     uintptr_t total_size[TOTAL_SIZE_NUM];
42     hi_u32 buffer_count;
43     hi_bool flash_flag[FLASH_FLAG_NUM];
44     hi_u16 pad;
45     hi_u8 *key_n;
46     hi_u8 *key_e;
47     hi_u8 *sign;
48     hi_u32 key_len;
49     hi_padding_mode pad_mode;
50 } upg_verify_param;
51 
52 hi_u32 upg_check_upg_file_code(hi_u32 flash_addr, hi_upg_head *upg_head);
53 hi_u32 upg_check_upg_file_head(hi_upg_head *upg_head);
54 hi_u32 upg_check_upg_file(hi_u32 flash_addr, hi_upg_head *upg_head);
55 hi_u32 upg_hash_one_content(hi_u32 flash_addr, hi_u32 total_size, hi_u8 *hash, hi_u32 hash_size);
56 hi_u32 upg_is_secure_efuse(hi_bool *secure_flag);
57 
58 #endif /* __UPG_CHECK_SECURE_H__ */
59 
60