• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  ******************************************************************************
3  *
4  * @file patch.h
5  *
6  * @brief offer the interface for the patch function based on the FPB of the cortex arm-m4;
7  *
8  ******************************************************************************
9  * @attention
10   #####Copyright (c) 2019 GOODIX
11   All rights reserved.
12 
13     Redistribution and use in source and binary forms, with or without
14     modification, are permitted provided that the following conditions are met:
15   * Redistributions of source code must retain the above copyright
16     notice, this list of conditions and the following disclaimer.
17   * Redistributions in binary form must reproduce the above copyright
18     notice, this list of conditions and the following disclaimer in the
19     documentation and/or other materials provided with the distribution.
20   * Neither the name of GOODIX nor the names of its contributors may be used
21     to endorse or promote products derived from this software without
22     specific prior written permission.
23 
24   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34   POSSIBILITY OF SUCH DAMAGE.
35  *****************************************************************************************
36  */
37 
38 #ifndef __PATCH_H_
39 #define __PATCH_H_
40 
41 /*
42  * ENUMERATIONS
43  ****************************************************************************************
44  */
45 enum {
46     BIT_HCI_SEND_2_CONTROLLER,
47     BIT_HAL_XQSPI_SET_XIP_PRESENT_STATUS,
48     BIT_LL_XQSPI_INIT,
49     BIT_HAL_EXFLASH_WRITE,
50     BIT_HAL_EXFLASH_ERASE,
51     BIT_HAL_EXFLASH_READ,
52     BIT_BLE_BM_SET_SEC_INFO,
53     BIT_KE_TASK_SCHEDULE,
54 };
55 
56 
57 /*
58  * MACRO DECLARATIONS
59  ****************************************************************************************
60  */
PATCH_ENABLE_FLAG(uint32_t BIT)61 static inline uint32_t PATCH_ENABLE_FLAG(uint32_t BIT)
62 {
63     return (1 << BIT);
64 }
65 
66 #define ENCRYPT_PATCH               ((PATCH_ENABLE_FLAG(BIT_HCI_SEND_2_CONTROLLER) | \
67                                      PATCH_ENABLE_FLAG(BIT_HAL_EXFLASH_WRITE)     | \
68                                      PATCH_ENABLE_FLAG(BIT_HAL_EXFLASH_ERASE)     | \
69                                      PATCH_ENABLE_FLAG(BIT_HAL_EXFLASH_READ)      | \
70                                      PATCH_ENABLE_FLAG(BIT_BLE_BM_SET_SEC_INFO))  | \
71                                      PATCH_ENABLE_FLAG(BIT_KE_TASK_SCHEDULE))
72 
73 
74 #define NO_ENCRYPT_PATCH            ((PATCH_ENABLE_FLAG(BIT_HCI_SEND_2_CONTROLLER) | \
75                                      PATCH_ENABLE_FLAG(BIT_HAL_EXFLASH_WRITE)     | \
76                                      PATCH_ENABLE_FLAG(BIT_HAL_EXFLASH_ERASE)     | \
77                                      PATCH_ENABLE_FLAG(BIT_BLE_BM_SET_SEC_INFO))  | \
78                                      PATCH_ENABLE_FLAG(BIT_KE_TASK_SCHEDULE))
79 
80 /**
81  *****************************************************************************************
82  * @brief  Apply Cold Patch
83  *         This function is used for cold patch
84  *****************************************************************************************
85  */
86 extern void cold_patch_apply(void);
87 
88 /**
89  *****************************************************************************************
90  * @brief  Patch Enabling Function
91  *         This function can not be used directly. It needs to be registered with FPB unit
92  *         and automatically enabled by the system.
93  *****************************************************************************************
94  */
95 extern void fpb_patch_enable(void);
96 
97 /**
98  *****************************************************************************************
99  * @brief  Patch Enabling Function for encrypt
100  *         This function can not be used directly. It needs to be registered with FPB unit
101  *         and automatically enabled by the system.
102  *****************************************************************************************
103  */
104 extern void fpb_encrypt_mode_patch_enable(void);
105 
106 #endif  // __PATCH_H_
107 
108