1 /* 2 * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __MCUBOOT_CONFIG_H__ 8 #define __MCUBOOT_CONFIG_H__ 9 10 /* 11 * Signature types 12 * 13 * You must choose exactly one signature type - check bootloader.conf 14 * configuration file 15 */ 16 17 /* Uncomment for RSA signature support */ 18 #if defined(CONFIG_ESP_SIGN_RSA) 19 #define MCUBOOT_SIGN_RSA 20 # if (CONFIG_ESP_SIGN_RSA_LEN != 2048 && \ 21 CONFIG_ESP_SIGN_RSA_LEN != 3072) 22 # error "Invalid RSA key size (must be 2048 or 3072)" 23 # else 24 # define MCUBOOT_SIGN_RSA_LEN CONFIG_ESP_SIGN_RSA_LEN 25 # endif 26 #elif defined(CONFIG_ESP_SIGN_EC256) 27 #define MCUBOOT_SIGN_EC256 28 #elif defined(CONFIG_ESP_SIGN_ED25519) 29 #define MCUBOOT_SIGN_ED25519 30 #endif 31 32 #if defined(CONFIG_SECURE_FLASH_ENC_ENABLED) 33 #define MCUBOOT_BOOT_MAX_ALIGN 32 34 #endif 35 36 /* 37 * Upgrade mode 38 * 39 * The default is to support A/B image swapping with rollback. Other modes 40 * with simpler code path, which only supports overwriting the existing image 41 * with the update image or running the newest image directly from its flash 42 * partition, are also available. 43 * 44 * You can enable only one mode at a time from the list below to override 45 * the default upgrade mode. 46 */ 47 48 /* Define to enable the swap-using-move code path. */ 49 #if defined(CONFIG_ESP_BOOT_SWAP_USING_MOVE) 50 #define MCUBOOT_SWAP_USING_MOVE 1 51 #endif 52 53 /* Define to enable the overwrite-only code path. */ 54 #if defined(CONFIG_ESP_BOOT_UPGRADE_ONLY) 55 #define MCUBOOT_OVERWRITE_ONLY 56 /* Uncomment to only erase and overwrite those primary slot sectors needed 57 * to install the new image, rather than the entire image slot. */ 58 /* #define MCUBOOT_OVERWRITE_ONLY_FAST */ 59 #endif 60 61 /* Define to enable the direct-xip code path (CURRENTLY UNSUPPORTED!). */ 62 #if defined(CONFIG_ESP_BOOT_DIRECT_XIP) 63 #define MCUBOOT_DIRECT_XIP 64 #endif 65 66 /* Define to enable the ram-load code path (CURRENTLY UNSUPPORTED!). */ 67 #if defined(CONFIG_ESP_BOOT_RAM_LOAD) 68 #define MCUBOOT_RAM_LOAD 69 #endif 70 71 /* If none of the above paths is defined, define CONFIG_ESP_BOOT_SWAP_USING_SCRATCH. 72 * 73 * Note: MCUBOOT_SWAP_USING_SCRATCH does not have to be defined, as it will be defined 74 * by MCUboot in bootutil_priv.h. 75 */ 76 #if !defined(CONFIG_ESP_BOOT_SWAP_USING_SCRATCH) && \ 77 !defined(CONFIG_ESP_BOOT_SWAP_USING_MOVE) && \ 78 !defined(CONFIG_ESP_BOOT_UPGRADE_ONLY) && \ 79 !defined(CONFIG_ESP_BOOT_DIRECT_XIP) && \ 80 !defined(CONFIG_ESP_BOOT_RAM_LOAD) 81 #define CONFIG_ESP_BOOT_SWAP_USING_SCRATCH 82 #endif 83 84 85 /* 86 * Cryptographic settings 87 * 88 * You must choose between Mbed TLS and Tinycrypt as source of 89 * cryptographic primitives. Other cryptographic settings are also 90 * available. 91 */ 92 93 /* Uncomment to use Mbed TLS cryptographic primitives */ 94 #if defined(CONFIG_ESP_USE_MBEDTLS) 95 #define MCUBOOT_USE_MBED_TLS 96 #else 97 /* MCUboot requires the definition of a crypto lib, 98 * using Tinycrypt as default */ 99 #define MCUBOOT_USE_TINYCRYPT 100 #endif 101 102 /* 103 * Always check the signature of the image in the primary slot before booting, 104 * even if no upgrade was performed. This is recommended if the boot 105 * time penalty is acceptable. 106 */ 107 #define MCUBOOT_VALIDATE_PRIMARY_SLOT 108 109 #ifdef CONFIG_ESP_DOWNGRADE_PREVENTION 110 #define MCUBOOT_DOWNGRADE_PREVENTION 1 111 /* MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER is used later as bool value so it is 112 * always defined, (unlike MCUBOOT_DOWNGRADE_PREVENTION which is only used in 113 * preprocessor condition and my be not defined) */ 114 # ifdef CONFIG_ESP_DOWNGRADE_PREVENTION_SECURITY_COUNTER 115 # define MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER 1 116 # else 117 # define MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER 0 118 # endif 119 #endif 120 121 /* 122 * Flash abstraction 123 */ 124 125 /* Uncomment if your flash map API supports flash_area_get_sectors(). 126 * See the flash APIs for more details. */ 127 #define MCUBOOT_USE_FLASH_AREA_GET_SECTORS 128 129 /* Default maximum number of flash sectors per image slot; change 130 * as desirable. */ 131 #define MCUBOOT_MAX_IMG_SECTORS 512 132 133 /* Default number of separately updateable images; change in case of 134 * multiple images. */ 135 #if defined(CONFIG_ESP_IMAGE_NUMBER) 136 #define MCUBOOT_IMAGE_NUMBER CONFIG_ESP_IMAGE_NUMBER 137 #else 138 #define MCUBOOT_IMAGE_NUMBER 1 139 #endif 140 141 /* 142 * Logging 143 */ 144 145 /* 146 * If logging is enabled the following functions must be defined by the 147 * platform: 148 * 149 * MCUBOOT_LOG_MODULE_REGISTER(domain) 150 * Register a new log module and add the current C file to it. 151 * 152 * MCUBOOT_LOG_MODULE_DECLARE(domain) 153 * Add the current C file to an existing log module. 154 * 155 * MCUBOOT_LOG_ERR(...) 156 * MCUBOOT_LOG_WRN(...) 157 * MCUBOOT_LOG_INF(...) 158 * MCUBOOT_LOG_DBG(...) 159 * 160 * The function priority is: 161 * 162 * MCUBOOT_LOG_ERR > MCUBOOT_LOG_WRN > MCUBOOT_LOG_INF > MCUBOOT_LOG_DBG 163 */ 164 #define MCUBOOT_HAVE_LOGGING 1 165 /* #define MCUBOOT_LOG_LEVEL MCUBOOT_LOG_LEVEL_INFO */ 166 167 /* 168 * Assertions 169 */ 170 171 /* Uncomment if your platform has its own mcuboot_config/mcuboot_assert.h. 172 * If so, it must provide an ASSERT macro for use by bootutil. Otherwise, 173 * "assert" is used. */ 174 #define MCUBOOT_HAVE_ASSERT_H 1 175 176 #ifdef CONFIG_ESP_MCUBOOT_SERIAL 177 #define CONFIG_MCUBOOT_SERIAL 178 #endif 179 180 /* 181 * When a serial recovery process is receiving the image data, this option 182 * enables it to erase flash progressively (by sectors) instead of the 183 * default behavior that is erasing whole image size of flash area after 184 * receiving first frame. 185 * Enabling this options prevents stalling the beginning of transfer 186 * for the time needed to erase large chunk of flash. 187 */ 188 #ifdef CONFIG_ESP_MCUBOOT_ERASE_PROGRESSIVELY 189 #define MCUBOOT_ERASE_PROGRESSIVELY 190 #endif 191 192 /* Serial extensions are not implemented 193 */ 194 #define MCUBOOT_PERUSER_MGMT_GROUP_ENABLED 0 195 196 /* 197 * Watchdog feeding 198 */ 199 200 /* This macro might be implemented if the OS / HW watchdog is enabled while 201 * doing a swap upgrade and the time it takes for a swapping is long enough 202 * to cause an unwanted reset. If implementing this, the OS main.c must also 203 * enable the watchdog (if required)! 204 */ 205 #include <bootloader_wdt.h> 206 #define MCUBOOT_WATCHDOG_FEED() \ 207 do { \ 208 bootloader_wdt_feed(); \ 209 } while (0) 210 211 #define MCUBOOT_CPU_IDLE() \ 212 do { \ 213 } while (0) 214 215 #endif /* __MCUBOOT_CONFIG_H__ */ 216