From e565224149430f8892159ecfbf5c7bb5ab416d83 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Mon, 5 Aug 2024 18:43:39 +0200 Subject: [PATCH] feat(bootloader_support): added bootloader_support mocks --- tools/mocks/bootloader_support/CMakeLists.txt | 18 ++++++++ .../bootloader_support/mock/mock_config.yaml | 12 ++++++ .../mock_build_test/CMakeLists.txt | 1 + .../mock_build_test/main/CMakeLists.txt | 2 +- .../mock_build_test/main/mock_build_test.c | 43 +++++++++++++++++-- 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 tools/mocks/bootloader_support/CMakeLists.txt create mode 100644 tools/mocks/bootloader_support/mock/mock_config.yaml diff --git a/tools/mocks/bootloader_support/CMakeLists.txt b/tools/mocks/bootloader_support/CMakeLists.txt new file mode 100644 index 0000000000..6ee08a04a1 --- /dev/null +++ b/tools/mocks/bootloader_support/CMakeLists.txt @@ -0,0 +1,18 @@ +# NOTE: This kind of mocking currently works on Linux targets only. +# On Espressif chips, too many dependencies are missing at the moment. +message(STATUS "building BOOTLOADER SUPPORT MOCKS") + +idf_component_get_property(original_bootloader_support_dir bootloader_support COMPONENT_OVERRIDEN_DIR) + +# Note: bootloader_memory_utils.h, bootloader_util.h and esp_app_format.h are not mocked +# since they only contain inline functions which we cannot mock without changing the build system. +idf_component_mock(INCLUDE_DIRS "${original_bootloader_support_dir}/include" + MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/bootloader_clock.h" + MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/bootloader_common.h" + MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/bootloader_mem.h" + MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/bootloader_random.h" + MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/esp_flash_encrypt.h" + MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/esp_flash_partitions.h" + MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/esp_image_format.h" + MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/esp_secure_boot.h" + ) diff --git a/tools/mocks/bootloader_support/mock/mock_config.yaml b/tools/mocks/bootloader_support/mock/mock_config.yaml new file mode 100644 index 0000000000..3a79a4c896 --- /dev/null +++ b/tools/mocks/bootloader_support/mock/mock_config.yaml @@ -0,0 +1,12 @@ +:cmock: + :plugins: + - expect + - expect_any_args + - return_thru_ptr + - array + - ignore + - ignore_arg + - callback + :strippables: + # esp_secure_boot_verify_sbv2_signature_block uses an ets type that is not yet available + - ['(?:esp_secure_boot_verify_sbv2_signature_block\s*\(+.*?\)+)'] diff --git a/tools/test_apps/linux_compatible/mock_build_test/CMakeLists.txt b/tools/test_apps/linux_compatible/mock_build_test/CMakeLists.txt index fbe6bfee78..97af0e1aee 100644 --- a/tools/test_apps/linux_compatible/mock_build_test/CMakeLists.txt +++ b/tools/test_apps/linux_compatible/mock_build_test/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(COMPONENTS main) +list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/bootloader_support) list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_wifi) list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_netif) list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_event) diff --git a/tools/test_apps/linux_compatible/mock_build_test/main/CMakeLists.txt b/tools/test_apps/linux_compatible/mock_build_test/main/CMakeLists.txt index fdf94912ad..5cf5ad9156 100644 --- a/tools/test_apps/linux_compatible/mock_build_test/main/CMakeLists.txt +++ b/tools/test_apps/linux_compatible/mock_build_test/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "mock_build_test.c" INCLUDE_DIRS "." - PRIV_REQUIRES driver esp_wifi) + PRIV_REQUIRES driver esp_wifi bootloader_support) diff --git a/tools/test_apps/linux_compatible/mock_build_test/main/mock_build_test.c b/tools/test_apps/linux_compatible/mock_build_test/main/mock_build_test.c index 9f64ecbd62..68311f564f 100644 --- a/tools/test_apps/linux_compatible/mock_build_test/main/mock_build_test.c +++ b/tools/test_apps/linux_compatible/mock_build_test/main/mock_build_test.c @@ -30,6 +30,14 @@ #include "Mockrmt_common.h" #include "Mockrmt_tx.h" #include "Mockrmt_rx.h" +#include "Mockbootloader_clock.h" +#include "Mockbootloader_common.h" +#include "Mockbootloader_mem.h" +#include "Mockbootloader_random.h" +#include "Mockesp_flash_encrypt.h" +#include "Mockesp_flash_partitions.h" +#include "Mockesp_image_format.h" +#include "Mockesp_secure_boot.h" /* Test that mock functions exist and that required definitions are available */ void app_main(void) @@ -102,9 +110,9 @@ void app_main(void) esp_wifi_set_mode_IgnoreAndReturn(ESP_OK); esp_wifi_set_config_IgnoreAndReturn(ESP_OK); esp_wifi_start_IgnoreAndReturn(ESP_OK); - ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); - ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, NULL) ); - ESP_ERROR_CHECK(esp_wifi_start() ); + ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); + ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, NULL)); + ESP_ERROR_CHECK(esp_wifi_start()); esp_wifi_connect_IgnoreAndReturn(ESP_OK); esp_wifi_connect(); @@ -130,5 +138,34 @@ void app_main(void) esp_now_init_IgnoreAndReturn(ESP_OK); ESP_ERROR_CHECK(esp_now_init()); + // Bootloader Support + bootloader_clock_configure_Ignore(); + bootloader_clock_configure(); + + bootloader_configure_spi_pins_Ignore(); + bootloader_configure_spi_pins(0); + + bootloader_init_mem_Ignore(); + bootloader_init_mem(); + + bootloader_random_enable_Ignore(); + bootloader_random_enable(); + + esp_flash_encryption_enabled_IgnoreAndReturn(true); + bool flash_encrypted = esp_flash_encryption_enabled(); + (void)flash_encrypted; + + esp_partition_main_flash_region_safe_IgnoreAndReturn(true); + bool region_is_safe = esp_partition_main_flash_region_safe(0, 0); + (void) region_is_safe; + + esp_image_verify_bootloader_IgnoreAndReturn(ESP_OK); + esp_err_t bootloader_is_ok = esp_image_verify_bootloader(NULL); + (void)bootloader_is_ok; + + esp_secure_boot_cfg_verify_release_mode_IgnoreAndReturn(true); + bool release_mode_enabled = esp_secure_boot_cfg_verify_release_mode(); + (void)release_mode_enabled; + printf("Mock build test done\n"); }