• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 #include "blt_fw_sign.h"
19 #include "blt_common.h"
20 #include "drivers.h"
21 #include "proj_lib/firmware_encrypt.h"
22 #include "tl_common.h"
23 
24 /**
25  * @brief		This function is used to check digital signature of firmware
26  * @param[in]	none
27  * @return      none
28  */
blt_firmware_signature_check(void)29 void blt_firmware_signature_check(void)
30 {
31     unsigned int flash_mid;
32     unsigned char flash_uid[16];
33     unsigned char signature_enc_key[16];
34     int flag = flash_read_mid_uid_with_check(&flash_mid, flash_uid);
35     if (flag == 0) {  // reading flash UID error
36         while (1) {
37         }
38     }
39 
40     firmware_encrypt_based_on_uid(flash_uid, signature_enc_key);
41 
42     /* must using "0x20000000 | address" when reading flash data by address pointer */
43     if (memcmp(signature_enc_key,
44                (u8 *)(FLASH_R_BASE_ADDR | (flash_sector_calibration + CALIB_OFFSET_FIRMWARE_SIGNKEY)),
45                16)) {  // signature not match
46         while (1) {
47         }
48         // user can change the code here to stop firmware running
49     }
50 }
51