diff --git a/components/bootloader_support/CMakeLists.txt b/components/bootloader_support/CMakeLists.txt index 9a180ed66c..63a77922b8 100644 --- a/components/bootloader_support/CMakeLists.txt +++ b/components/bootloader_support/CMakeLists.txt @@ -9,6 +9,7 @@ set(srcs "src/bootloader_utility.c" "src/esp_image_format.c" "src/flash_encrypt.c" + "src/secure_boot.c" "src/flash_partitions.c" "src/flash_qio_mode.c" "src/bootloader_flash_config_${IDF_TARGET}.c" diff --git a/components/bootloader_support/include/esp_secure_boot.h b/components/bootloader_support/include/esp_secure_boot.h index 3eb4db0165..71e905962b 100644 --- a/components/bootloader_support/include/esp_secure_boot.h +++ b/components/bootloader_support/include/esp_secure_boot.h @@ -214,6 +214,17 @@ typedef struct { uint8_t digest[64]; } esp_secure_boot_iv_digest_t; +/** @brief Check the secure boot V2 during startup + * + * @note This function is called automatically during app startup, + * it doesn't need to be called from the app. + * + * Verifies the secure boot config during startup: + * + * - Correct any insecure secure boot settings + */ +void esp_secure_boot_init_checks(void); + #ifdef __cplusplus } #endif diff --git a/components/bootloader_support/src/secure_boot.c b/components/bootloader_support/src/secure_boot.c new file mode 100644 index 0000000000..6f377f714b --- /dev/null +++ b/components/bootloader_support/src/secure_boot.c @@ -0,0 +1,29 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "sdkconfig.h" +#include "esp_log.h" +#include "esp_efuse.h" +#include "esp_efuse_table.h" +#include "esp_secure_boot.h" + +#ifndef BOOTLOADER_BUILD +static __attribute__((unused)) const char *TAG = "secure_boot"; + +void esp_secure_boot_init_checks(void) +{ + +} +#endif // not BOOTLOADER_BUILD diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index 3ad549d267..c75b083f30 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -39,6 +39,7 @@ #include "esp_timer.h" #include "esp_efuse.h" #include "esp_flash_encrypt.h" +#include "esp_secure_boot.h" /***********************************************/ // Headers for other components init functions @@ -48,7 +49,6 @@ #include "esp_core_dump.h" #include "esp_app_trace.h" #include "esp_private/dbg_stubs.h" -#include "esp_flash_encrypt.h" #include "esp_pm.h" #include "esp_private/pm_impl.h" #include "esp_pthread.h" @@ -276,6 +276,10 @@ static void do_core_init(void) esp_flash_encryption_init_checks(); #endif +#ifdef CONFIG_SECURE_BOOT + esp_secure_boot_init_checks(); +#endif + esp_err_t err; #if CONFIG_SECURE_DISABLE_ROM_DL_MODE