1 /****************************************************************************
2  * boot/nuttx/include/mcuboot_config/mcuboot_config.h
3  *
4  * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  ****************************************************************************/
19 
20 #ifndef __BOOT_NUTTX_INCLUDE_MCUBOOT_CONFIG_MCUBOOT_CONFIG_H
21 #define __BOOT_NUTTX_INCLUDE_MCUBOOT_CONFIG_MCUBOOT_CONFIG_H
22 
23 /****************************************************************************
24  * Included Files
25  ****************************************************************************/
26 
27 #include <nuttx/config.h>
28 
29 #ifdef CONFIG_MCUBOOT_WATCHDOG
30 #  include "watchdog/watchdog.h"
31 #endif
32 
33 /****************************************************************************
34  * Pre-processor Definitions
35  ****************************************************************************/
36 
37 /* Signature types
38  *
39  * You must choose exactly one signature type.
40  */
41 
42 /* Uncomment for RSA signature support */
43 
44 /* #define MCUBOOT_SIGN_RSA */
45 
46 /* Uncomment for ECDSA signatures using curve P-256. */
47 
48 /* #define MCUBOOT_SIGN_EC256 */
49 
50 /* Upgrade mode
51  *
52  * The default is to support A/B image swapping with rollback.  Other modes
53  * with simpler code path, which only supports overwriting the existing image
54  * with the update image or running the newest image directly from its flash
55  * partition, are also available.
56  *
57  * You can enable only one mode at a time from the list below to override
58  * the default upgrade mode.
59  */
60 
61 /* Use image swap without using scratch area.*/
62 
63 #ifdef CONFIG_MCUBOOT_SWAP_USING_MOVE
64 #  define MCUBOOT_SWAP_USING_MOVE 1
65 #endif
66 
67 /* Enable the overwrite-only code path. */
68 
69 #ifdef CONFIG_MCUBOOT_OVERWRITE_ONLY
70 #  define MCUBOOT_OVERWRITE_ONLY
71 #endif
72 
73 /* Only erase and overwrite those primary slot sectors needed
74  * to install the new image, rather than the entire image slot.
75  */
76 
77 #ifdef CONFIG_MCUBOOT_OVERWRITE_ONLY_FAST
78 #  define MCUBOOT_OVERWRITE_ONLY_FAST
79 #endif
80 
81 /* Enable the direct-xip code path. */
82 
83 #ifdef CONFIG_MCUBOOT_DIRECT_XIP
84 #  define MCUBOOT_DIRECT_XIP
85 #endif
86 
87 /* Enable the revert mechanism in direct-xip mode. */
88 
89 #ifdef CONFIG_MCUBOOT_DIRECT_XIP_REVERT
90 #  define MCUBOOT_DIRECT_XIP_REVERT
91 #endif
92 
93 /* Enable the ram-load code path. */
94 
95 #ifdef CONFIG_MCUBOOT_RAM_LOAD
96 #  define MCUBOOT_RAM_LOAD
97 #endif
98 
99 /* Enable bootstrapping the erased primary slot from the secondary slot */
100 
101 #ifdef CONFIG_MCUBOOT_BOOTSTRAP
102 #  define MCUBOOT_BOOTSTRAP
103 #endif
104 
105 /* Cryptographic settings
106  *
107  * You must choose between mbedTLS and Tinycrypt as source of
108  * cryptographic primitives. Other cryptographic settings are also
109  * available.
110  */
111 
112 #ifdef CONFIG_MCUBOOT_USE_MBED_TLS
113 #  define MCUBOOT_USE_MBED_TLS
114 #endif
115 
116 #ifdef CONFIG_MCUBOOT_USE_TINYCRYPT
117 #  define MCUBOOT_USE_TINYCRYPT
118 #endif
119 
120 /* Always check the signature of the image in the primary slot before
121  * booting, even if no upgrade was performed. This is recommended if the boot
122  * time penalty is acceptable.
123  */
124 
125 #define MCUBOOT_VALIDATE_PRIMARY_SLOT
126 
127 /* Flash abstraction */
128 
129 /* Uncomment if your flash map API supports flash_area_get_sectors().
130  * See the flash APIs for more details.
131  */
132 
133 #define MCUBOOT_USE_FLASH_AREA_GET_SECTORS
134 
135 /* Default maximum number of flash sectors per image slot; change
136  * as desirable.
137  */
138 
139 #define MCUBOOT_MAX_IMG_SECTORS 512
140 
141 /* Default number of separately updateable images; change in case of
142  * multiple images.
143  */
144 
145 #define MCUBOOT_IMAGE_NUMBER 1
146 
147 /* Logging */
148 
149 /* If logging is enabled the following functions must be defined by the
150  * platform:
151  *
152  *    MCUBOOT_LOG_MODULE_REGISTER(domain)
153  *      Register a new log module and add the current C file to it.
154  *
155  *    MCUBOOT_LOG_MODULE_DECLARE(domain)
156  *      Add the current C file to an existing log module.
157  *
158  *    MCUBOOT_LOG_ERR(...)
159  *    MCUBOOT_LOG_WRN(...)
160  *    MCUBOOT_LOG_INF(...)
161  *    MCUBOOT_LOG_DBG(...)
162  *
163  * The function priority is:
164  *
165  *    MCUBOOT_LOG_ERR > MCUBOOT_LOG_WRN > MCUBOOT_LOG_INF > MCUBOOT_LOG_DBG
166  */
167 
168 #ifdef CONFIG_MCUBOOT_ENABLE_LOGGING
169 #  define MCUBOOT_HAVE_LOGGING
170 #endif
171 
172 /* Assertions */
173 
174 /* Uncomment if your platform has its own mcuboot_config/mcuboot_assert.h.
175  * If so, it must provide an ASSERT macro for use by bootutil. Otherwise,
176  * "assert" is used.
177  */
178 
179 /* #define MCUBOOT_HAVE_ASSERT_H 1 */
180 
181 /* Watchdog feeding */
182 
183 /* This macro might be implemented if the OS / HW watchdog is enabled while
184  * doing a swap upgrade and the time it takes for a swapping is long enough
185  * to cause an unwanted reset. If implementing this, the OS main.c must also
186  * enable the watchdog (if required)!
187  */
188 
189 #ifdef CONFIG_MCUBOOT_WATCHDOG
190 
191 #ifndef CONFIG_MCUBOOT_WATCHDOG_DEVPATH
192 #  define CONFIG_MCUBOOT_WATCHDOG_DEVPATH "/dev/watchdog0"
193 #endif
194 
195 #ifndef CONFIG_MCUBOOT_WATCHDOG_TIMEOUT
196 #  define CONFIG_MCUBOOT_WATCHDOG_TIMEOUT 10000      /* Watchdog timeout in ms */
197 #endif
198 
199 #  define MCUBOOT_WATCHDOG_FEED()       do                           \
200                                           {                          \
201                                             mcuboot_watchdog_feed(); \
202                                           }                          \
203                                         while (0)
204 
205 #else
206 #  define MCUBOOT_WATCHDOG_FEED()       do                           \
207                                           {                          \
208                                           }                          \
209                                         while (0)
210 #endif
211 
212 #endif /* __BOOT_NUTTX_INCLUDE_MCUBOOT_CONFIG_MCUBOOT_CONFIG_H */
213