mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'refactor/movements_from_target_components_2' into 'master'
refactoring: Movements from target components 2 Closes IDF-2162 See merge request espressif/esp-idf!12687
This commit is contained in:
commit
85e1c94070
@ -687,7 +687,7 @@ UT_C3_FLASH_SUSPEND:
|
||||
|
||||
UT_S3:
|
||||
extends: .unit_test_esp32s3_template
|
||||
parallel: 25
|
||||
parallel: 26
|
||||
tags:
|
||||
- ESP32S3_IDF
|
||||
- UT_T1_1
|
||||
|
@ -1,3 +1,3 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES cmock)
|
||||
PRIV_REQUIRES cmock driver)
|
||||
|
@ -2,7 +2,7 @@ idf_component_register(SRCS "esp_ota_ops.c"
|
||||
"esp_app_desc.c"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES spi_flash partition_table bootloader_support
|
||||
PRIV_REQUIRES esptool_py)
|
||||
PRIV_REQUIRES esptool_py efuse)
|
||||
|
||||
# esp_app_desc structure is added as an undefined symbol because otherwise the
|
||||
# linker will ignore this structure as it has no other files depending on it.
|
||||
|
@ -11,8 +11,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_partition.h"
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "esp_partition.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp_flash_partitions.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
@ -4,4 +4,5 @@ idf_component_register(SRCS "commands.c"
|
||||
"argtable3/argtable3.c"
|
||||
"linenoise/linenoise.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES vfs)
|
||||
REQUIRES vfs
|
||||
PRIV_REQUIRES driver)
|
||||
|
@ -821,17 +821,21 @@ TEST_CASE("GPIO input and output of USB pins test", "[gpio]")
|
||||
// test pin
|
||||
gpio_set_level(pin, 0);
|
||||
// tested voltage is around 0v
|
||||
esp_rom_delay_us(10);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(pin), 0, "get level error! the level should be low!");
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
gpio_set_level(pin, 1);
|
||||
esp_rom_delay_us(10);
|
||||
// tested voltage is around 3.3v
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(pin), 1, "get level error! the level should be high!");
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
gpio_set_level(pin, 0);
|
||||
esp_rom_delay_us(10);
|
||||
// tested voltage is around 0v
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(pin), 0, "get level error! the level should be low!");
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
gpio_set_level(pin, 1);
|
||||
esp_rom_delay_us(10);
|
||||
// tested voltage is around 3.3v
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(pin), 1, "get level error! the level should be high!");
|
||||
}
|
||||
|
@ -3,82 +3,14 @@ if(NOT "${target}" STREQUAL "esp32")
|
||||
return()
|
||||
endif()
|
||||
|
||||
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
# [refactor-todo] propagate these requirements for compatibility
|
||||
# remove in the future
|
||||
set(legacy_reqs driver efuse soc)
|
||||
endif()
|
||||
|
||||
if(BOOTLOADER_BUILD)
|
||||
# For bootloader, all we need from esp32 is headers
|
||||
idf_component_register(INCLUDE_DIRS include REQUIRES xtensa)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
|
||||
else()
|
||||
# Regular app build
|
||||
set(srcs
|
||||
"cache_sram_mmu.c"
|
||||
"dport_access.c"
|
||||
"esp_himem.c"
|
||||
"spiram.c"
|
||||
"spiram_psram.c")
|
||||
|
||||
set(include_dirs "include")
|
||||
|
||||
set(requires driver efuse soc xtensa) #unfortunately rom/uart uses SOC registers directly
|
||||
|
||||
# app_update is added here because cpu_start.c uses esp_ota_get_app_description() function.
|
||||
# esp_timer is added here because cpu_start.c uses esp_timer
|
||||
set(priv_requires app_trace app_update bootloader_support esp_system log mbedtls nvs_flash pthread
|
||||
spi_flash vfs espcoredump esp_common perfmon esp_timer esp_ipc esp_pm)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "${include_dirs}"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}"
|
||||
idf_component_register(INCLUDE_DIRS include
|
||||
REQUIRES xtensa "${legacy_reqs}"
|
||||
REQUIRED_IDF_TARGETS esp32)
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")
|
||||
|
||||
# Process the template file through the linker script generation mechanism, and use the output for linking the
|
||||
# final binary
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in"
|
||||
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32.project.ld")
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
|
||||
|
||||
idf_build_get_property(config_dir CONFIG_DIR)
|
||||
# Preprocess esp32.ld linker script to include configuration, becomes esp32_out.ld
|
||||
set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
|
||||
add_custom_command(
|
||||
OUTPUT esp32_out.ld
|
||||
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32_out.ld -I ${config_dir} ${LD_DIR}/esp32.ld
|
||||
MAIN_DEPENDENCY ${LD_DIR}/esp32.ld
|
||||
DEPENDS ${sdkconfig_header}
|
||||
COMMENT "Generating linker script..."
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(esp32_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld)
|
||||
add_dependencies(${COMPONENT_LIB} esp32_linker_script)
|
||||
|
||||
if(CONFIG_SPIRAM_CACHE_WORKAROUND)
|
||||
# Note: Adding as a PUBLIC compile option here causes this option to propagate to all
|
||||
# components that depend on esp32.
|
||||
#
|
||||
# To handle some corner cases, the same flag is set in project_include.cmake
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
|
||||
# also, make sure we link with this option so correct toolchain libs are pulled in
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
|
||||
# set strategy selected
|
||||
# note that we don't need to set link options as the library linked is independent of this
|
||||
if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST)
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
|
||||
endif()
|
||||
if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW)
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
|
||||
endif()
|
||||
if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_NOPS)
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
|
||||
|
@ -2,33 +2,5 @@
|
||||
# Component Makefile
|
||||
#
|
||||
|
||||
COMPONENT_SRCDIRS := .
|
||||
|
||||
#Linker scripts used to link the final application.
|
||||
#Warning: These linker scripts are only used when the normal app is compiled; the bootloader
|
||||
#specifies its own scripts.
|
||||
LINKER_SCRIPTS += $(COMPONENT_BUILD_DIR)/esp32.project.ld esp32.peripherals.ld
|
||||
|
||||
#ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the
|
||||
#linker will ignore panic_highint_hdl.S as it has no other files depending on any
|
||||
#symbols in it.
|
||||
COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/ld \
|
||||
-T esp32_out.ld \
|
||||
-u ld_include_panic_highint_hdl \
|
||||
$(addprefix -T ,$(LINKER_SCRIPTS)) \
|
||||
|
||||
# final linking of project ELF depends on all binary libraries, and
|
||||
# all linker scripts (except esp32_out.ld, as this is code generated here.)
|
||||
COMPONENT_ADD_LINKER_DEPS := $(addprefix ld/, $(filter-out $(COMPONENT_BUILD_DIR)/esp32.project.ld, $(LINKER_SCRIPTS))) \
|
||||
$(COMPONENT_BUILD_DIR)/esp32.project.ld
|
||||
|
||||
# Preprocess esp32.ld linker script into esp32_out.ld
|
||||
#
|
||||
# The library doesn't really depend on esp32_out.ld, but it
|
||||
# saves us from having to add the target to a Makefile.projbuild
|
||||
$(COMPONENT_LIBRARY): esp32_out.ld
|
||||
|
||||
esp32_out.ld: $(COMPONENT_PATH)/ld/esp32.ld ../include/sdkconfig.h
|
||||
$(CC) -I ../include -C -P -x c -E $< -o $@
|
||||
|
||||
COMPONENT_EXTRA_CLEAN := esp32_out.ld $(COMPONENT_BUILD_DIR)/esp32.project.ld
|
||||
COMPONENT_ADD_LINKER_DEPS := $(COMPONENT_PATH) ld/esp32.peripherals.ld
|
||||
COMPONENT_ADD_LDFLAGS := -T $(COMPONENT_PATH)/ld/esp32.peripherals.ld
|
||||
|
@ -1,7 +0,0 @@
|
||||
if(IDF_TARGET STREQUAL "esp32")
|
||||
idf_component_register(SRC_DIRS .
|
||||
PRIV_INCLUDE_DIRS .
|
||||
PRIV_REQUIRES cmock test_utils mbedtls ulp esp_common
|
||||
)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_test_dport_xt_highint5")
|
||||
endif()
|
@ -1,8 +0,0 @@
|
||||
#
|
||||
#Component Makefile
|
||||
#
|
||||
|
||||
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive \
|
||||
-u ld_include_test_dport_xt_highint5 \
|
||||
|
||||
COMPONENT_SRCDIRS := .
|
@ -1,66 +1,15 @@
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
|
||||
if(NOT "${target}" STREQUAL "esp32c3")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(BOOTLOADER_BUILD)
|
||||
# For bootloader, all we need from esp32c3 is headers
|
||||
idf_component_register(INCLUDE_DIRS include REQUIRES riscv)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32c3.peripherals.ld")
|
||||
else()
|
||||
# Regular app build
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
# [refactor-todo] propagate these requirements for compatibility
|
||||
# remove in the future
|
||||
set(legacy_reqs driver efuse soc)
|
||||
endif()
|
||||
|
||||
set(srcs "dport_access.c"
|
||||
"esp_hmac.c"
|
||||
"esp_ds.c"
|
||||
"esp_crypto_lock.c"
|
||||
"memprot.c")
|
||||
set(include_dirs "include")
|
||||
|
||||
set(requires driver efuse soc riscv) #unfortunately rom/uart uses SOC registers directly
|
||||
|
||||
# driver is a public requirement because esp_sleep.h uses gpio_num_t & touch_pad_t
|
||||
# app_update is added here because cpu_start.c uses esp_ota_get_app_description() function.
|
||||
# esp_timer is added here because cpu_start.c uses esp_timer
|
||||
set(priv_requires
|
||||
app_trace app_update bootloader_support log mbedtls nvs_flash
|
||||
pthread spi_flash vfs espcoredump esp_common esp_timer)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "${include_dirs}"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}"
|
||||
idf_component_register(REQUIRES riscv "${legacy_reqs}"
|
||||
REQUIRED_IDF_TARGETS esp32c3)
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32c3_out.ld")
|
||||
|
||||
# Process the template file through the linker script generation mechanism, and use the output for linking the
|
||||
# final binary
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.project.ld.in"
|
||||
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32c3.project.ld")
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32c3.peripherals.ld")
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
|
||||
|
||||
idf_build_get_property(config_dir CONFIG_DIR)
|
||||
# Preprocess esp32c3.ld linker script to include configuration, becomes esp32c3_out.ld
|
||||
set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
|
||||
add_custom_command(
|
||||
OUTPUT esp32c3_out.ld
|
||||
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32c3_out.ld -I ${config_dir} ${LD_DIR}/esp32c3.ld
|
||||
MAIN_DEPENDENCY ${LD_DIR}/esp32c3.ld
|
||||
DEPENDS ${sdkconfig_header}
|
||||
COMMENT "Generating linker script..."
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(esp32c3_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32c3_out.ld)
|
||||
add_dependencies(${COMPONENT_LIB} esp32c3_linker_script)
|
||||
|
||||
# disable stack protection in files which are involved in initialization of that feature
|
||||
set_source_files_properties(
|
||||
cpu_start.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
-fno-stack-protector)
|
||||
endif()
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32c3.peripherals.ld")
|
||||
|
@ -1,9 +0,0 @@
|
||||
if(IDF_TARGET STREQUAL "esp32c3")
|
||||
idf_component_register(SRC_DIRS .
|
||||
INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR}
|
||||
REQUIRES unity test_utils esp_common mbedtls
|
||||
)
|
||||
|
||||
idf_build_set_property(COMPILE_DEFINITIONS "-DESP_TIMER_DYNAMIC_OVERFLOW_VAL" APPEND)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_test_dport_xt_highint5")
|
||||
endif()
|
@ -1,4 +0,0 @@
|
||||
#
|
||||
# Component Makefile (not used for tests, but CI checks test parity between GNU Make & CMake)
|
||||
#
|
||||
COMPONENT_CONFIG_ONLY := 1
|
@ -1,80 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "esp_types.h"
|
||||
#include "esp32c3/clk.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "idf_performance.h"
|
||||
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "sha/sha_dma.h"
|
||||
|
||||
/* Note: Most of the SHA functions are called as part of mbedTLS, so
|
||||
are tested as part of mbedTLS tests. Only esp_sha() is different.
|
||||
*/
|
||||
|
||||
#define TAG "sha_test"
|
||||
|
||||
TEST_CASE("Test esp_sha()", "[hw_crypto]")
|
||||
{
|
||||
const size_t BUFFER_SZ = 32 * 1024 + 6; // NB: not an exact multiple of SHA block size
|
||||
|
||||
int64_t begin, end;
|
||||
uint32_t us_sha1;
|
||||
uint8_t sha1_result[20] = { 0 };
|
||||
void *buffer = heap_caps_malloc(BUFFER_SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
|
||||
TEST_ASSERT_NOT_NULL(buffer);
|
||||
memset(buffer, 0xEE, BUFFER_SZ);
|
||||
|
||||
const uint8_t sha1_expected[20] = { 0xc7, 0xbb, 0xd3, 0x74, 0xf2, 0xf6, 0x20, 0x86,
|
||||
0x61, 0xf4, 0x50, 0xd5, 0xf5, 0x18, 0x44, 0xcc,
|
||||
0x7a, 0xb7, 0xa5, 0x4a };
|
||||
|
||||
begin = esp_timer_get_time();
|
||||
esp_sha(SHA1, buffer, BUFFER_SZ, sha1_result);
|
||||
end = esp_timer_get_time();
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(sha1_expected, sha1_result, sizeof(sha1_expected));
|
||||
us_sha1 = end - begin;
|
||||
ESP_LOGI(TAG, "esp_sha() 32KB SHA1 in %u us", us_sha1);
|
||||
|
||||
free(buffer);
|
||||
|
||||
TEST_PERFORMANCE_CCOMP_LESS_THAN(TIME_SHA1_32KB, "%dus", us_sha1);
|
||||
}
|
||||
|
||||
TEST_CASE("Test esp_sha() function with long input", "[hw_crypto]")
|
||||
{
|
||||
const void* ptr;
|
||||
spi_flash_mmap_handle_t handle;
|
||||
uint8_t sha1_espsha[20] = { 0 };
|
||||
uint8_t sha1_mbedtls[20] = { 0 };
|
||||
uint8_t sha256_espsha[32] = { 0 };
|
||||
uint8_t sha256_mbedtls[32] = { 0 };
|
||||
|
||||
const size_t LEN = 1024 * 1024;
|
||||
|
||||
/* mmap() 1MB of flash, we don't care what it is really */
|
||||
esp_err_t err = spi_flash_mmap(0x0, LEN, SPI_FLASH_MMAP_DATA, &ptr, &handle);
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX32(ESP_OK, err);
|
||||
TEST_ASSERT_NOT_NULL(ptr);
|
||||
|
||||
/* Compare esp_sha() result to the mbedTLS result, should always be the same */
|
||||
|
||||
esp_sha(SHA1, ptr, LEN, sha1_espsha);
|
||||
int r = mbedtls_sha1_ret(ptr, LEN, sha1_mbedtls);
|
||||
TEST_ASSERT_EQUAL(0, r);
|
||||
|
||||
esp_sha(SHA2_256, ptr, LEN, sha256_espsha);
|
||||
r = mbedtls_sha256_ret(ptr, LEN, sha256_mbedtls, 0);
|
||||
TEST_ASSERT_EQUAL(0, r);
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha1_espsha, sha1_mbedtls, sizeof(sha1_espsha), "SHA1 results should match");
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha256_espsha, sha256_mbedtls, sizeof(sha256_espsha), "SHA256 results should match");
|
||||
}
|
@ -1,66 +1,15 @@
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
|
||||
if(NOT "${target}" STREQUAL "esp32h2")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(BOOTLOADER_BUILD)
|
||||
# For bootloader, all we need from esp32h2 is headers
|
||||
idf_component_register(INCLUDE_DIRS include REQUIRES riscv)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32h2.peripherals.ld")
|
||||
else()
|
||||
# Regular app build
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
# [refactor-todo] propagate these requirements for compatibility
|
||||
# remove in the future
|
||||
set(legacy_reqs driver efuse soc)
|
||||
endif()
|
||||
|
||||
set(srcs "dport_access.c"
|
||||
"esp_hmac.c"
|
||||
"esp_ds.c"
|
||||
"esp_crypto_lock.c"
|
||||
"memprot.c")
|
||||
set(include_dirs "include")
|
||||
|
||||
set(requires driver efuse soc riscv) #unfortunately rom/uart uses SOC registers directly
|
||||
|
||||
# driver is a public requirement because esp_sleep.h uses gpio_num_t & touch_pad_t
|
||||
# app_update is added here because cpu_start.c uses esp_ota_get_app_description() function.
|
||||
# esp_timer is added here because cpu_start.c uses esp_timer
|
||||
set(priv_requires
|
||||
app_trace app_update bootloader_support log mbedtls nvs_flash
|
||||
pthread spi_flash vfs espcoredump esp_common esp_timer)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "${include_dirs}"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}"
|
||||
idf_component_register(REQUIRES riscv "${legacy_reqs}"
|
||||
REQUIRED_IDF_TARGETS esp32h2)
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32h2_out.ld")
|
||||
|
||||
# Process the template file through the linker script generation mechanism, and use the output for linking the
|
||||
# final binary
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32h2.project.ld.in"
|
||||
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32h2.project.ld")
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32h2.peripherals.ld")
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
|
||||
|
||||
idf_build_get_property(config_dir CONFIG_DIR)
|
||||
# Preprocess esp32h2.ld linker script to include configuration, becomes esp32h2_out.ld
|
||||
set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
|
||||
add_custom_command(
|
||||
OUTPUT esp32h2_out.ld
|
||||
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32h2_out.ld -I ${config_dir} ${LD_DIR}/esp32h2.ld
|
||||
MAIN_DEPENDENCY ${LD_DIR}/esp32h2.ld
|
||||
DEPENDS ${sdkconfig_header}
|
||||
COMMENT "Generating linker script..."
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(esp32h2_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32h2_out.ld)
|
||||
add_dependencies(${COMPONENT_LIB} esp32h2_linker_script)
|
||||
|
||||
# disable stack protection in files which are involved in initialization of that feature
|
||||
set_source_files_properties(
|
||||
cpu_start.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
-fno-stack-protector)
|
||||
endif()
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32h2.peripherals.ld")
|
||||
|
@ -1,9 +0,0 @@
|
||||
if(IDF_TARGET STREQUAL "esp32h2")
|
||||
idf_component_register(SRC_DIRS .
|
||||
INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR}
|
||||
REQUIRES unity test_utils esp_common mbedtls
|
||||
)
|
||||
|
||||
idf_build_set_property(COMPILE_DEFINITIONS "-DESP_TIMER_DYNAMIC_OVERFLOW_VAL" APPEND)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_test_dport_xt_highint5")
|
||||
endif()
|
@ -1,4 +0,0 @@
|
||||
#
|
||||
# Component Makefile (not used for tests, but CI checks test parity between GNU Make & CMake)
|
||||
#
|
||||
COMPONENT_CONFIG_ONLY := 1
|
File diff suppressed because one or more lines are too long
@ -1,382 +0,0 @@
|
||||
// Copyright 2020 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 "unity.h"
|
||||
#include "esp32h2/rom/efuse.h"
|
||||
#include "esp32h2/rom/digital_signature.h"
|
||||
#include "esp32h2/rom/hmac.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_ds.h"
|
||||
|
||||
#define NUM_RESULTS 10
|
||||
#define DS_MAX_BITS (ETS_DS_MAX_BITS)
|
||||
|
||||
typedef struct {
|
||||
uint8_t iv[ETS_DS_IV_LEN];
|
||||
ets_ds_p_data_t p_data;
|
||||
uint8_t expected_c[ETS_DS_C_LEN];
|
||||
uint8_t hmac_key_idx;
|
||||
uint32_t expected_results[NUM_RESULTS][DS_MAX_BITS/32];
|
||||
} encrypt_testcase_t;
|
||||
|
||||
// Generated header (components/esp32s2/test/gen_digital_signature_tests.py) defines
|
||||
// NUM_HMAC_KEYS, test_hmac_keys, NUM_MESSAGES, NUM_CASES, test_messages[], test_cases[]
|
||||
#include "digital_signature_test_cases.h"
|
||||
|
||||
_Static_assert(NUM_RESULTS == NUM_MESSAGES, "expected_results size should be the same as NUM_MESSAGES in generated header");
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption data NULL", "[hw_crypto] [ds]")
|
||||
{
|
||||
const char iv [32];
|
||||
esp_ds_p_data_t p_data;
|
||||
const char key [32];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_encrypt_params(NULL, iv, &p_data, key));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption iv NULL", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t data;
|
||||
esp_ds_p_data_t p_data;
|
||||
const char key [32];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_encrypt_params(&data, NULL, &p_data, key));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption p_data NULL", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t data;
|
||||
const char iv [32];
|
||||
const char key [32];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_encrypt_params(&data, iv, NULL, key));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption key NULL", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t data;
|
||||
const char iv [32];
|
||||
esp_ds_p_data_t p_data;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_encrypt_params(&data, iv, &p_data, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption", "[hw_crypto] [ds]")
|
||||
{
|
||||
for (int i = 0; i < NUM_CASES; i++) {
|
||||
printf("Encrypting test case %d...\n", i);
|
||||
const encrypt_testcase_t *t = &test_cases[i];
|
||||
esp_ds_data_t result = { };
|
||||
esp_ds_p_data_t p_data;
|
||||
|
||||
memcpy(p_data.Y, t->p_data.Y, ESP_DS_SIGNATURE_MAX_BIT_LEN/8);
|
||||
memcpy(p_data.M, t->p_data.M, ESP_DS_SIGNATURE_MAX_BIT_LEN/8);
|
||||
memcpy(p_data.Rb, t->p_data.Rb, ESP_DS_SIGNATURE_MAX_BIT_LEN/8);
|
||||
p_data.M_prime = t->p_data.M_prime;
|
||||
p_data.length = t->p_data.length;
|
||||
|
||||
esp_err_t r = esp_ds_encrypt_params(&result, t->iv, &p_data,
|
||||
test_hmac_keys[t->hmac_key_idx]);
|
||||
printf("Encrypting test case %d done\n", i);
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, r);
|
||||
TEST_ASSERT_EQUAL(t->p_data.length, result.rsa_length);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(t->iv, result.iv, ETS_DS_IV_LEN);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(t->expected_c, result.c, ETS_DS_C_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature start Invalid message", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = { };
|
||||
ds_data.rsa_length = ESP_DS_RSA_3072;
|
||||
esp_ds_context_t *ctx;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(NULL, &ds_data, HMAC_KEY1, &ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature start Invalid data", "[hw_crypto] [ds]")
|
||||
{
|
||||
const char *message = "test";
|
||||
esp_ds_context_t *ctx;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, NULL, HMAC_KEY1, &ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature start Invalid context", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_3072;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY1, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature RSA length 0", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 0;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY1, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature RSA length too long", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 128;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY1, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature start HMAC key out of range", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_3072;
|
||||
esp_ds_context_t *ctx;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY5 + 1, &ctx));
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY0 - 1, &ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature finish Invalid signature ptr", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_context_t *ctx = NULL;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_finish_sign(NULL, ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature finish Invalid context", "[hw_crypto] [ds]")
|
||||
{
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_finish_sign(signature_data, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking Invalid message", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = { };
|
||||
ds_data.rsa_length = ESP_DS_RSA_3072;
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(NULL, &ds_data, HMAC_KEY1, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking Invalid data", "[hw_crypto] [ds]")
|
||||
{
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, NULL, HMAC_KEY1, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking Invalid signature ptr", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_3072;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY1, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking RSA length 0", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 0;
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY1, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking RSA length too long", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 128;
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY1, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking HMAC key out of range", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 127;
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY5 + 1, signature_data));
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY0 - 1, signature_data));
|
||||
}
|
||||
|
||||
#if CONFIG_IDF_ENV_FPGA
|
||||
|
||||
// Burn eFuse blocks 1, 2 and 3. Block 0 is used for HMAC tests already.
|
||||
static void burn_hmac_keys(void)
|
||||
{
|
||||
printf("Burning %d HMAC keys to efuse...\n", NUM_HMAC_KEYS);
|
||||
for (int i = 0; i < NUM_HMAC_KEYS; i++) {
|
||||
// TODO: vary the purpose across the keys
|
||||
ets_efuse_purpose_t purpose = ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE;
|
||||
ets_efuse_write_key(ETS_EFUSE_BLOCK_KEY1 + i,
|
||||
purpose,
|
||||
test_hmac_keys[i], 32);
|
||||
}
|
||||
/* verify the keys are what we expect (possibly they're already burned, doesn't matter but they have to match) */
|
||||
uint8_t block_compare[32];
|
||||
for (int i = 0; i < NUM_HMAC_KEYS; i++) {
|
||||
printf("Checking key %d...\n", i);
|
||||
memcpy(block_compare, (void *)ets_efuse_get_read_register_address(ETS_EFUSE_BLOCK_KEY1 + i), 32);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(test_hmac_keys[i], block_compare, 32);
|
||||
}
|
||||
}
|
||||
|
||||
// This test uses the HMAC_KEY0 eFuse key which hasn't been burned by burn_hmac_keys().
|
||||
// HMAC_KEY0 is usually used for HMAC upstream (user access) tests.
|
||||
TEST_CASE("Digital Signature wrong HMAC key purpose (FPGA only)", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_3072;
|
||||
esp_ds_context_t *ctx;
|
||||
const char *message = "test";
|
||||
|
||||
// HMAC fails in that case because it checks for the correct purpose
|
||||
TEST_ASSERT_EQUAL(ESP32H2_ERR_HW_CRYPTO_DS_HMAC_FAIL, esp_ds_start_sign(message, &ds_data, HMAC_KEY0, &ctx));
|
||||
}
|
||||
|
||||
// This test uses the HMAC_KEY0 eFuse key which hasn't been burned by burn_hmac_keys().
|
||||
// HMAC_KEY0 is usually used for HMAC upstream (user access) tests.
|
||||
TEST_CASE("Digital Signature Blocking wrong HMAC key purpose (FPGA only)", "[hw_crypto] [ds]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_3072;
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
// HMAC fails in that case because it checks for the correct purpose
|
||||
TEST_ASSERT_EQUAL(ESP32H2_ERR_HW_CRYPTO_DS_HMAC_FAIL, esp_ds_sign(message, &ds_data, HMAC_KEY0, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Operation (FPGA only)", "[hw_crypto] [ds]")
|
||||
{
|
||||
burn_hmac_keys();
|
||||
|
||||
for (int i = 0; i < NUM_CASES; i++) {
|
||||
printf("Running test case %d...\n", i);
|
||||
const encrypt_testcase_t *t = &test_cases[i];
|
||||
|
||||
// copy encrypt parameter test case into ds_data structure
|
||||
esp_ds_data_t ds_data = { };
|
||||
memcpy(ds_data.iv, t->iv, ETS_DS_IV_LEN);
|
||||
memcpy(ds_data.c, t->expected_c, ETS_DS_C_LEN);
|
||||
ds_data.rsa_length = t->p_data.length;
|
||||
|
||||
for (int j = 0; j < NUM_MESSAGES; j++) {
|
||||
uint8_t signature[DS_MAX_BITS/8] = { 0 };
|
||||
printf(" ... message %d\n", j);
|
||||
|
||||
esp_ds_context_t *esp_ds_ctx;
|
||||
esp_err_t ds_r = esp_ds_start_sign(test_messages[j],
|
||||
&ds_data,
|
||||
t->hmac_key_idx + 1,
|
||||
&esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
|
||||
ds_r = esp_ds_finish_sign(signature, esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(t->expected_results[j], signature, sizeof(signature));
|
||||
}
|
||||
|
||||
ets_hmac_invalidate_downstream(ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking Operation (FPGA only)", "[hw_crypto] [ds]")
|
||||
{
|
||||
burn_hmac_keys();
|
||||
|
||||
for (int i = 0; i < NUM_CASES; i++) {
|
||||
printf("Running test case %d...\n", i);
|
||||
const encrypt_testcase_t *t = &test_cases[i];
|
||||
|
||||
// copy encrypt parameter test case into ds_data structure
|
||||
esp_ds_data_t ds_data = { };
|
||||
memcpy(ds_data.iv, t->iv, ETS_DS_IV_LEN);
|
||||
memcpy(ds_data.c, t->expected_c, ETS_DS_C_LEN);
|
||||
ds_data.rsa_length = t->p_data.length;
|
||||
|
||||
uint8_t signature[DS_MAX_BITS/8] = { 0 };
|
||||
|
||||
esp_err_t ds_r = esp_ds_sign(test_messages[0],
|
||||
&ds_data,
|
||||
t->hmac_key_idx + 1,
|
||||
signature);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(t->expected_results[0], signature, sizeof(signature));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Invalid Data (FPGA only)", "[hw_crypto] [ds]")
|
||||
{
|
||||
burn_hmac_keys();
|
||||
|
||||
// Set up a valid test case
|
||||
const encrypt_testcase_t *t = &test_cases[0];
|
||||
esp_ds_data_t ds_data = { };
|
||||
memcpy(ds_data.iv, t->iv, ETS_DS_IV_LEN);
|
||||
memcpy(ds_data.c, t->expected_c, ETS_DS_C_LEN);
|
||||
ds_data.rsa_length = t->p_data.length;
|
||||
|
||||
uint8_t signature[DS_MAX_BITS/8] = { 0 };
|
||||
const uint8_t zero[DS_MAX_BITS/8] = { 0 };
|
||||
|
||||
// Corrupt the IV one bit at a time, rerun and expect failure
|
||||
for (int bit = 0; bit < 128; bit++) {
|
||||
printf("Corrupting IV bit %d...\n", bit);
|
||||
ds_data.iv[bit / 8] ^= 1 << (bit % 8);
|
||||
esp_ds_context_t *esp_ds_ctx;
|
||||
|
||||
esp_err_t ds_r = esp_ds_start_sign(test_messages[0], &ds_data, t->hmac_key_idx + 1, &esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
ds_r = esp_ds_finish_sign(signature, esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP32H2_ERR_HW_CRYPTO_DS_INVALID_DIGEST, ds_r);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(zero, signature, DS_MAX_BITS/8);
|
||||
|
||||
ds_data.iv[bit / 8] ^= 1 << (bit % 8);
|
||||
}
|
||||
|
||||
// Corrupt encrypted key data one bit at a time, rerun and expect failure
|
||||
printf("Corrupting C...\n");
|
||||
for (int bit = 0; bit < ETS_DS_C_LEN * 8; bit++) {
|
||||
printf("Corrupting C bit %d...\n", bit);
|
||||
ds_data.c[bit / 8] ^= 1 << (bit % 8);
|
||||
esp_ds_context_t *esp_ds_ctx;
|
||||
|
||||
esp_err_t ds_r = esp_ds_start_sign(test_messages[0], &ds_data, t->hmac_key_idx + 1, &esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
ds_r = esp_ds_finish_sign(signature, esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP32H2_ERR_HW_CRYPTO_DS_INVALID_DIGEST, ds_r);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(zero, signature, DS_MAX_BITS/8);
|
||||
|
||||
ds_data.c[bit / 8] ^= 1 << (bit % 8);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CONFIG_IDF_ENV_FPGA
|
@ -1,80 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "esp_types.h"
|
||||
#include "esp32h2/clk.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "idf_performance.h"
|
||||
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "sha/sha_dma.h"
|
||||
|
||||
/* Note: Most of the SHA functions are called as part of mbedTLS, so
|
||||
are tested as part of mbedTLS tests. Only esp_sha() is different.
|
||||
*/
|
||||
|
||||
#define TAG "sha_test"
|
||||
|
||||
TEST_CASE("Test esp_sha()", "[hw_crypto]")
|
||||
{
|
||||
const size_t BUFFER_SZ = 32 * 1024 + 6; // NB: not an exact multiple of SHA block size
|
||||
|
||||
int64_t begin, end;
|
||||
uint32_t us_sha1;
|
||||
uint8_t sha1_result[20] = { 0 };
|
||||
void *buffer = heap_caps_malloc(BUFFER_SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
|
||||
TEST_ASSERT_NOT_NULL(buffer);
|
||||
memset(buffer, 0xEE, BUFFER_SZ);
|
||||
|
||||
const uint8_t sha1_expected[20] = { 0xc7, 0xbb, 0xd3, 0x74, 0xf2, 0xf6, 0x20, 0x86,
|
||||
0x61, 0xf4, 0x50, 0xd5, 0xf5, 0x18, 0x44, 0xcc,
|
||||
0x7a, 0xb7, 0xa5, 0x4a };
|
||||
|
||||
begin = esp_timer_get_time();
|
||||
esp_sha(SHA1, buffer, BUFFER_SZ, sha1_result);
|
||||
end = esp_timer_get_time();
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(sha1_expected, sha1_result, sizeof(sha1_expected));
|
||||
us_sha1 = end - begin;
|
||||
ESP_LOGI(TAG, "esp_sha() 32KB SHA1 in %u us", us_sha1);
|
||||
|
||||
free(buffer);
|
||||
|
||||
TEST_PERFORMANCE_CCOMP_LESS_THAN(TIME_SHA1_32KB, "%dus", us_sha1);
|
||||
}
|
||||
|
||||
TEST_CASE("Test esp_sha() function with long input", "[hw_crypto]")
|
||||
{
|
||||
const void* ptr;
|
||||
spi_flash_mmap_handle_t handle;
|
||||
uint8_t sha1_espsha[20] = { 0 };
|
||||
uint8_t sha1_mbedtls[20] = { 0 };
|
||||
uint8_t sha256_espsha[32] = { 0 };
|
||||
uint8_t sha256_mbedtls[32] = { 0 };
|
||||
|
||||
const size_t LEN = 1024 * 1024;
|
||||
|
||||
/* mmap() 1MB of flash, we don't care what it is really */
|
||||
esp_err_t err = spi_flash_mmap(0x0, LEN, SPI_FLASH_MMAP_DATA, &ptr, &handle);
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX32(ESP_OK, err);
|
||||
TEST_ASSERT_NOT_NULL(ptr);
|
||||
|
||||
/* Compare esp_sha() result to the mbedTLS result, should always be the same */
|
||||
|
||||
esp_sha(SHA1, ptr, LEN, sha1_espsha);
|
||||
int r = mbedtls_sha1_ret(ptr, LEN, sha1_mbedtls);
|
||||
TEST_ASSERT_EQUAL(0, r);
|
||||
|
||||
esp_sha(SHA2_256, ptr, LEN, sha256_espsha);
|
||||
r = mbedtls_sha256_ret(ptr, LEN, sha256_mbedtls, 0);
|
||||
TEST_ASSERT_EQUAL(0, r);
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha1_espsha, sha1_mbedtls, sizeof(sha1_espsha), "SHA1 results should match");
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha256_espsha, sha256_mbedtls, sizeof(sha256_espsha), "SHA256 results should match");
|
||||
}
|
@ -1,63 +1,15 @@
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
|
||||
if(NOT "${target}" STREQUAL "esp32s2")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(BOOTLOADER_BUILD)
|
||||
# For bootloader, all we need from esp32s2 is headers
|
||||
idf_component_register(INCLUDE_DIRS include REQUIRES xtensa)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s2.peripherals.ld")
|
||||
else()
|
||||
# Regular app build
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
# [refactor-todo] propagate these requirements for compatibility
|
||||
# remove in the future
|
||||
set(legacy_reqs driver efuse soc)
|
||||
endif()
|
||||
|
||||
set(srcs "memprot.c"
|
||||
"dport_access.c"
|
||||
"spiram.c"
|
||||
"spiram_psram.c"
|
||||
"esp_crypto_lock.c"
|
||||
"esp_hmac.c"
|
||||
"esp_ds.c")
|
||||
|
||||
set(include_dirs "include")
|
||||
|
||||
set(requires driver efuse xtensa)
|
||||
|
||||
# app_update is added here because cpu_start.c uses esp_ota_get_app_description() function.
|
||||
# esp_timer is added here because cpu_start.c uses esp_timer
|
||||
set(priv_requires
|
||||
app_trace app_update bootloader_support esp_system log mbedtls nvs_flash
|
||||
pthread spi_flash vfs espcoredump esp_common esp_timer)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "${include_dirs}"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}"
|
||||
idf_component_register(REQUIRES xtensa "${legacy_reqs}"
|
||||
REQUIRED_IDF_TARGETS esp32s2)
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32s2_out.ld")
|
||||
|
||||
# Process the template file through the linker script generation mechanism, and use the output for linking the
|
||||
# final binary
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/ld/esp32s2.project.ld.in"
|
||||
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32s2.project.ld")
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s2.peripherals.ld")
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
|
||||
|
||||
idf_build_get_property(config_dir CONFIG_DIR)
|
||||
# Preprocess esp32s2.ld linker script to include configuration, becomes esp32s2_out.ld
|
||||
set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
|
||||
add_custom_command(
|
||||
OUTPUT esp32s2_out.ld
|
||||
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32s2_out.ld -I ${config_dir} ${LD_DIR}/esp32s2.ld
|
||||
MAIN_DEPENDENCY ${LD_DIR}/esp32s2.ld
|
||||
DEPENDS ${sdkconfig_header}
|
||||
COMMENT "Generating linker script..."
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(esp32s2_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32s2_out.ld)
|
||||
add_dependencies(${COMPONENT_LIB} esp32s2_linker_script)
|
||||
endif()
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s2.peripherals.ld")
|
||||
|
@ -1,85 +0,0 @@
|
||||
// Copyright 2015-2017 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.
|
||||
|
||||
|
||||
#ifndef __ESP_SPIRAM_H
|
||||
#define __ESP_SPIRAM_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize spiram interface/hardware. Normally called from cpu_start.c.
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_spiram_init(void);
|
||||
|
||||
/**
|
||||
* @brief Configure Cache/MMU for access to external SPI RAM.
|
||||
*
|
||||
* Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT
|
||||
* option is enabled. Applications which need to enable SPI RAM at run time
|
||||
* can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later.
|
||||
*
|
||||
* @attention this function must be called with flash cache disabled.
|
||||
*/
|
||||
void esp_spiram_init_cache(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and
|
||||
* (in case of a dual-core system) the app CPU is online. This test overwrites the
|
||||
* memory with crap, so do not call after e.g. the heap allocator has stored important
|
||||
* stuff in SPI RAM.
|
||||
*
|
||||
* @return true on success, false on failed memory test
|
||||
*/
|
||||
bool esp_spiram_test(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Add the initialized SPI RAM to the heap allocator.
|
||||
*/
|
||||
esp_err_t esp_spiram_add_to_heapalloc(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the size of the attached SPI RAM chip selected in menuconfig
|
||||
*
|
||||
* @return Size in bytes, or 0 if no external RAM chip support compiled in.
|
||||
*/
|
||||
size_t esp_spiram_get_size(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever
|
||||
* cache is disabled, because disabling cache on the ESP32 discards the data in the SPI
|
||||
* RAM cache.
|
||||
*
|
||||
* This is meant for use from within the SPI flash code.
|
||||
*/
|
||||
void esp_spiram_writeback_cache(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,6 +0,0 @@
|
||||
if(IDF_TARGET STREQUAL "esp32s2")
|
||||
idf_component_register(SRC_DIRS .
|
||||
PRIV_INCLUDE_DIRS .
|
||||
PRIV_REQUIRES cmock test_utils nvs_flash mbedtls ulp esp_common
|
||||
)
|
||||
endif()
|
@ -1,4 +0,0 @@
|
||||
#
|
||||
# Component Makefile
|
||||
#
|
||||
COMPONENT_CONFIG_ONLY := 1
|
@ -1,379 +0,0 @@
|
||||
// Copyright 2020 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 "unity.h"
|
||||
#include "esp32s2/rom/efuse.h"
|
||||
#include "esp32s2/rom/digital_signature.h"
|
||||
#include "esp32s2/rom/aes.h"
|
||||
#include "esp32s2/rom/sha.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_ds.h"
|
||||
|
||||
#define NUM_RESULTS 10
|
||||
|
||||
typedef struct {
|
||||
uint8_t iv[ETS_DS_IV_LEN];
|
||||
ets_ds_p_data_t p_data;
|
||||
uint8_t expected_c[ETS_DS_C_LEN];
|
||||
uint8_t hmac_key_idx;
|
||||
uint32_t expected_results[NUM_RESULTS][4096/32];
|
||||
} encrypt_testcase_t;
|
||||
|
||||
// Generated header (gen_digital_signature_tests.py) defines
|
||||
// NUM_HMAC_KEYS, test_hmac_keys, NUM_MESSAGES, NUM_CASES, test_messages[], test_cases[]
|
||||
// Some adaptations were made: removed the 512 bit case and changed RSA lengths to the enums from esp_ds.h
|
||||
#include "digital_signature_test_cases.h"
|
||||
|
||||
_Static_assert(NUM_RESULTS == NUM_MESSAGES, "expected_results size should be the same as NUM_MESSAGES in generated header");
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption data NULL", "[hw_crypto]")
|
||||
{
|
||||
const char iv [32];
|
||||
esp_ds_p_data_t p_data;
|
||||
const char key [32];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_encrypt_params(NULL, iv, &p_data, key));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption iv NULL", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t data;
|
||||
esp_ds_p_data_t p_data;
|
||||
const char key [32];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_encrypt_params(&data, NULL, &p_data, key));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption p_data NULL", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t data;
|
||||
const char iv [32];
|
||||
const char key [32];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_encrypt_params(&data, iv, NULL, key));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption key NULL", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t data;
|
||||
const char iv [32];
|
||||
esp_ds_p_data_t p_data;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_encrypt_params(&data, iv, &p_data, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Parameter Encryption", "[hw_crypto]")
|
||||
{
|
||||
for (int i = 0; i < NUM_CASES; i++) {
|
||||
printf("Encrypting test case %d...\n", i);
|
||||
const encrypt_testcase_t *t = &test_cases[i];
|
||||
esp_ds_data_t result = { };
|
||||
esp_ds_p_data_t p_data;
|
||||
|
||||
memcpy(p_data.Y, t->p_data.Y, 4096/8);
|
||||
memcpy(p_data.M, t->p_data.M, 4096/8);
|
||||
memcpy(p_data.Rb, t->p_data.Rb, 4096/8);
|
||||
p_data.M_prime = t->p_data.M_prime;
|
||||
p_data.length = t->p_data.length;
|
||||
|
||||
esp_err_t r = esp_ds_encrypt_params(&result, t->iv, &p_data,
|
||||
test_hmac_keys[t->hmac_key_idx]);
|
||||
printf("Encrypting test case %d done\n", i);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, r);
|
||||
TEST_ASSERT_EQUAL(t->p_data.length, result.rsa_length);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(t->iv, result.iv, ETS_DS_IV_LEN);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(t->expected_c, result.c, ETS_DS_C_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature start Invalid message", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = { };
|
||||
ds_data.rsa_length = ESP_DS_RSA_4096;
|
||||
esp_ds_context_t *ctx;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(NULL, &ds_data, HMAC_KEY1, &ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature start Invalid data", "[hw_crypto]")
|
||||
{
|
||||
const char *message = "test";
|
||||
esp_ds_context_t *ctx;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, NULL, HMAC_KEY1, &ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature start Invalid context", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_4096;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY1, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature RSA length 0", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 0;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY1, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature RSA length too long", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 128;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY1, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature start HMAC key out of range", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_4096;
|
||||
esp_ds_context_t *ctx;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY5 + 1, &ctx));
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_start_sign(message, &ds_data, HMAC_KEY0 - 1, &ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature finish Invalid signature ptr", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_context_t *ctx = NULL;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_finish_sign(NULL, ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature finish Invalid context", "[hw_crypto]")
|
||||
{
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_finish_sign(signature_data, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking Invalid message", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = { };
|
||||
ds_data.rsa_length = ESP_DS_RSA_4096;
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(NULL, &ds_data, HMAC_KEY1, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking Invalid data", "[hw_crypto]")
|
||||
{
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, NULL, HMAC_KEY1, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking Invalid signature ptr", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_4096;
|
||||
const char *message = "test";
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY1, NULL));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking RSA length 0", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 0;
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY1, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking RSA length too long", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 128;
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY1, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking HMAC key out of range", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = 127;
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY5 + 1, signature_data));
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_ds_sign(message, &ds_data, HMAC_KEY0 - 1, signature_data));
|
||||
}
|
||||
|
||||
#if CONFIG_IDF_ENV_FPGA
|
||||
|
||||
static void burn_hmac_keys(void)
|
||||
{
|
||||
printf("Burning %d HMAC keys to efuse...\n", NUM_HMAC_KEYS);
|
||||
for (int i = 0; i < NUM_HMAC_KEYS; i++) {
|
||||
// TODO: vary the purpose across the keys
|
||||
ets_efuse_purpose_t purpose = ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE;
|
||||
|
||||
// starting from block 1, block 0 occupied with HMAC upstream test key
|
||||
int ets_status = ets_efuse_write_key(ETS_EFUSE_BLOCK_KEY1 + i,
|
||||
purpose,
|
||||
test_hmac_keys[i], 32);
|
||||
|
||||
if (ets_status == ESP_OK) {
|
||||
printf("written DS test key to block [%d]!\n", ETS_EFUSE_BLOCK_KEY1 + i);
|
||||
} else {
|
||||
printf("writing DS test key to block [%d] failed, maybe written already\n", ETS_EFUSE_BLOCK_KEY1 + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature wrong HMAC key purpose (FPGA only)", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_4096;
|
||||
esp_ds_context_t *ctx;
|
||||
const char *message = "test";
|
||||
|
||||
// HMAC fails in that case because it checks for the correct purpose
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL, esp_ds_start_sign(message, &ds_data, HMAC_KEY0, &ctx));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking wrong HMAC key purpose (FPGA only)", "[hw_crypto]")
|
||||
{
|
||||
esp_ds_data_t ds_data = {};
|
||||
ds_data.rsa_length = ESP_DS_RSA_4096;
|
||||
const char *message = "test";
|
||||
uint8_t signature_data [128 * 4];
|
||||
|
||||
// HMAC fails in that case because it checks for the correct purpose
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL, esp_ds_sign(message, &ds_data, HMAC_KEY0, signature_data));
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Operation (FPGA only)", "[hw_crypto]")
|
||||
{
|
||||
burn_hmac_keys();
|
||||
|
||||
for (int i = 0; i < NUM_CASES; i++) {
|
||||
printf("Running test case %d...\n", i);
|
||||
const encrypt_testcase_t *t = &test_cases[i];
|
||||
|
||||
// copy encrypt parameter test case into ds_data structure
|
||||
esp_ds_data_t ds_data = { };
|
||||
memcpy(ds_data.iv, t->iv, ETS_DS_IV_LEN);
|
||||
memcpy(ds_data.c, t->expected_c, ETS_DS_C_LEN);
|
||||
ds_data.rsa_length = t->p_data.length;
|
||||
|
||||
for (int j = 0; j < NUM_MESSAGES; j++) {
|
||||
uint8_t signature[4096/8] = { 0 };
|
||||
printf(" ... message %d\n", j);
|
||||
esp_ds_context_t *esp_ds_ctx;
|
||||
|
||||
esp_err_t ds_r = esp_ds_start_sign(test_messages[j],
|
||||
&ds_data,
|
||||
t->hmac_key_idx + 1,
|
||||
&esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
|
||||
ds_r = esp_ds_finish_sign(signature, esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(t->expected_results[j], signature, sizeof(signature));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Digital Signature Blocking Operation (FPGA only)", "[hw_crypto]")
|
||||
{
|
||||
burn_hmac_keys();
|
||||
|
||||
for (int i = 0; i < NUM_CASES; i++) {
|
||||
printf("Running test case %d...\n", i);
|
||||
const encrypt_testcase_t *t = &test_cases[i];
|
||||
|
||||
// copy encrypt parameter test case into ds_data structure
|
||||
esp_ds_data_t ds_data = { };
|
||||
memcpy(ds_data.iv, t->iv, ETS_DS_IV_LEN);
|
||||
memcpy(ds_data.c, t->expected_c, ETS_DS_C_LEN);
|
||||
ds_data.rsa_length = t->p_data.length;
|
||||
|
||||
uint8_t signature[4096/8] = { 0 };
|
||||
esp_ds_context_t *esp_ds_ctx;
|
||||
|
||||
esp_err_t ds_r = esp_ds_start_sign(test_messages[0],
|
||||
&ds_data,
|
||||
t->hmac_key_idx + 1,
|
||||
&esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
|
||||
ds_r = esp_ds_finish_sign(signature, esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(t->expected_results[0], signature, sizeof(signature));
|
||||
}
|
||||
}
|
||||
TEST_CASE("Digital Signature Invalid Data (FPGA only)", "[hw_crypto]")
|
||||
{
|
||||
burn_hmac_keys();
|
||||
|
||||
// Set up a valid test case
|
||||
const encrypt_testcase_t *t = &test_cases[0];
|
||||
esp_ds_data_t ds_data = { };
|
||||
memcpy(ds_data.iv, t->iv, ETS_DS_IV_LEN);
|
||||
memcpy(ds_data.c, t->expected_c, ETS_DS_C_LEN);
|
||||
ds_data.rsa_length = t->p_data.length;
|
||||
|
||||
uint8_t signature[4096/8] = { 0 };
|
||||
const uint8_t zero[4096/8] = { 0 };
|
||||
|
||||
// Corrupt the IV one bit at a time, rerun and expect failure
|
||||
for (int bit = 0; bit < 128; bit++) {
|
||||
printf("Corrupting IV bit %d...\n", bit);
|
||||
ds_data.iv[bit / 8] ^= 1 << (bit % 8);
|
||||
esp_ds_context_t *esp_ds_ctx;
|
||||
|
||||
esp_err_t ds_r = esp_ds_start_sign(test_messages[0], &ds_data, t->hmac_key_idx + 1, &esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
ds_r = esp_ds_finish_sign(signature, esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST, ds_r);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(zero, signature, 4096/8);
|
||||
|
||||
ds_data.iv[bit / 8] ^= 1 << (bit % 8);
|
||||
}
|
||||
|
||||
// Corrupt encrypted key data one bit at a time, rerun and expect failure
|
||||
printf("Corrupting C...\n");
|
||||
for (int bit = 0; bit < ETS_DS_C_LEN * 8; bit++) {
|
||||
printf("Corrupting C bit %d...\n", bit);
|
||||
ds_data.c[bit / 8] ^= 1 << (bit % 8);
|
||||
esp_ds_context_t *esp_ds_ctx;
|
||||
|
||||
esp_err_t ds_r = esp_ds_start_sign(test_messages[0], &ds_data, t->hmac_key_idx + 1, &esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ds_r);
|
||||
ds_r = esp_ds_finish_sign(signature, esp_ds_ctx);
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST, ds_r);
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(zero, signature, 4096/8);
|
||||
|
||||
ds_data.c[bit / 8] ^= 1 << (bit % 8);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CONFIG_IDF_ENV_FPGA
|
@ -1,103 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "esp_types.h"
|
||||
#include "esp32s2/clk.h"
|
||||
#include "esp_log.h"
|
||||
#include "ccomp_timer.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "idf_performance.h"
|
||||
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
#include "sha/sha_dma.h"
|
||||
|
||||
/* Note: Most of the SHA functions are called as part of mbedTLS, so
|
||||
are tested as part of mbedTLS tests. Only esp_sha() is different.
|
||||
*/
|
||||
|
||||
#define TAG "sha_test"
|
||||
|
||||
TEST_CASE("Test esp_sha()", "[hw_crypto]")
|
||||
{
|
||||
const size_t BUFFER_SZ = 32 * 1024 + 6; // NB: not an exact multiple of SHA block size
|
||||
|
||||
uint32_t us_sha1, us_sha512;
|
||||
uint8_t sha1_result[20] = { 0 };
|
||||
uint8_t sha512_result[64] = { 0 };
|
||||
void *buffer = heap_caps_malloc(BUFFER_SZ, MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
|
||||
TEST_ASSERT_NOT_NULL(buffer);
|
||||
memset(buffer, 0xEE, BUFFER_SZ);
|
||||
|
||||
const uint8_t sha1_expected[20] = { 0xc7, 0xbb, 0xd3, 0x74, 0xf2, 0xf6, 0x20, 0x86,
|
||||
0x61, 0xf4, 0x50, 0xd5, 0xf5, 0x18, 0x44, 0xcc,
|
||||
0x7a, 0xb7, 0xa5, 0x4a };
|
||||
const uint8_t sha512_expected[64] = { 0xc7, 0x7f, 0xda, 0x8c, 0xb3, 0x58, 0x14, 0x8a,
|
||||
0x52, 0x3b, 0x46, 0x04, 0xc0, 0x85, 0xc5, 0xf0,
|
||||
0x46, 0x64, 0x14, 0xd5, 0x96, 0x7a, 0xa2, 0x80,
|
||||
0x20, 0x9c, 0x04, 0x27, 0x7d, 0x3b, 0xf9, 0x1f,
|
||||
0xb2, 0xa3, 0x45, 0x3c, 0xa1, 0x6a, 0x8d, 0xdd,
|
||||
0x35, 0x5e, 0x35, 0x57, 0x76, 0x22, 0x74, 0xd8,
|
||||
0x1e, 0x07, 0xc6, 0xa2, 0x9e, 0x3b, 0x65, 0x75,
|
||||
0x80, 0x7d, 0xe6, 0x6e, 0x47, 0x61, 0x2c, 0x94 };
|
||||
|
||||
ccomp_timer_start();;
|
||||
esp_sha(SHA1, buffer, BUFFER_SZ, sha1_result);
|
||||
us_sha1 = ccomp_timer_stop();
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(sha1_expected, sha1_result, sizeof(sha1_expected));
|
||||
ESP_LOGI(TAG, "esp_sha() 32KB SHA1 in %u us", us_sha1);
|
||||
|
||||
ccomp_timer_start();;
|
||||
esp_sha(SHA2_512, buffer, BUFFER_SZ, sha512_result);
|
||||
us_sha512 = ccomp_timer_stop();
|
||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(sha512_expected, sha512_result, sizeof(sha512_expected));
|
||||
ESP_LOGI(TAG, "esp_sha() 32KB SHA512 in %u us", us_sha512);
|
||||
|
||||
free(buffer);
|
||||
|
||||
TEST_PERFORMANCE_CCOMP_LESS_THAN(TIME_SHA1_32KB, "%dus", us_sha1);
|
||||
TEST_PERFORMANCE_CCOMP_LESS_THAN(TIME_SHA512_32KB, "%dus", us_sha512);
|
||||
}
|
||||
|
||||
TEST_CASE("Test esp_sha() function with long input", "[hw_crypto]")
|
||||
{
|
||||
const void* ptr;
|
||||
spi_flash_mmap_handle_t handle;
|
||||
uint8_t sha1_espsha[20] = { 0 };
|
||||
uint8_t sha1_mbedtls[20] = { 0 };
|
||||
uint8_t sha256_espsha[32] = { 0 };
|
||||
uint8_t sha256_mbedtls[32] = { 0 };
|
||||
uint8_t sha512_espsha[64] = { 0 };
|
||||
uint8_t sha512_mbedtls[64] = { 0 };
|
||||
|
||||
const size_t LEN = 1024 * 1024;
|
||||
|
||||
/* mmap() 1MB of flash, we don't care what it is really */
|
||||
esp_err_t err = spi_flash_mmap(0x0, LEN, SPI_FLASH_MMAP_DATA, &ptr, &handle);
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX32(ESP_OK, err);
|
||||
TEST_ASSERT_NOT_NULL(ptr);
|
||||
|
||||
/* Compare esp_sha() result to the mbedTLS result, should always be the same */
|
||||
|
||||
esp_sha(SHA1, ptr, LEN, sha1_espsha);
|
||||
int r = mbedtls_sha1_ret(ptr, LEN, sha1_mbedtls);
|
||||
TEST_ASSERT_EQUAL(0, r);
|
||||
|
||||
esp_sha(SHA2_256, ptr, LEN, sha256_espsha);
|
||||
r = mbedtls_sha256_ret(ptr, LEN, sha256_mbedtls, 0);
|
||||
TEST_ASSERT_EQUAL(0, r);
|
||||
|
||||
esp_sha(SHA2_512, ptr, LEN, sha512_espsha);
|
||||
r = mbedtls_sha512_ret(ptr, LEN, sha512_mbedtls, 0);
|
||||
TEST_ASSERT_EQUAL(0, r);
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha1_espsha, sha1_mbedtls, sizeof(sha1_espsha), "SHA1 results should match");
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha256_espsha, sha256_mbedtls, sizeof(sha256_espsha), "SHA256 results should match");
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha512_espsha, sha512_mbedtls, sizeof(sha512_espsha), "SHA512 results should match");
|
||||
}
|
@ -1,182 +0,0 @@
|
||||
/*
|
||||
This code tests the interaction between PSRAM and SPI flash routines.
|
||||
*/
|
||||
|
||||
#include <esp_types.h>
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/xtensa_api.h"
|
||||
#include "unity.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/io_mux_reg.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_spi_flash.h"
|
||||
#include "esp_partition.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
#if CONFIG_SPIRAM
|
||||
|
||||
#if CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC
|
||||
#define USE_CAPS_ALLOC 1
|
||||
#endif // CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC
|
||||
|
||||
#define TSTSZ (16*1024)
|
||||
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
|
||||
volatile static int res[2], err[2];
|
||||
|
||||
void tstMem(void *arg) {
|
||||
volatile unsigned char *mem=(volatile unsigned char*)arg;
|
||||
int p=0;
|
||||
while(1) {
|
||||
for (int i=0; i<TSTSZ; i++) {
|
||||
mem[i]=(i^p);
|
||||
}
|
||||
for (int i=0; i<TSTSZ; i++) {
|
||||
if (mem[i]!=((i^p)&0xff)) {
|
||||
printf("Core %d mem err! Got %x espected %x at addr %p\n", xPortGetCoreID(), mem[i], (i^p)&0xff, &mem[i]);
|
||||
err[xPortGetCoreID()]++;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
res[xPortGetCoreID()]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Spiram cache flush on mmap", "[spiram]")
|
||||
{
|
||||
void *mem[2];
|
||||
res[0]=0; res[1]=0;
|
||||
#if USE_CAPS_ALLOC
|
||||
printf("Allocating SPI RAM chunk...\n");
|
||||
mem[0]=heap_caps_malloc(TSTSZ, MALLOC_CAP_SPIRAM);
|
||||
mem[1]=heap_caps_malloc(TSTSZ, MALLOC_CAP_SPIRAM);
|
||||
#else
|
||||
mem[0]=(void*)SOC_EXTRAM_DATA_LOW;
|
||||
mem[1]=(void*)SOC_EXTRAM_DATA_LOW+TSTSZ;
|
||||
#endif
|
||||
assert(mem[0]);
|
||||
assert(mem[1]);
|
||||
TaskHandle_t th[2];
|
||||
err[0]=0; err[1]=0;
|
||||
printf("Creating tasks\n");
|
||||
xTaskCreatePinnedToCore(tstMem , "tskone" , 2048, mem[0], 3, &th[0], 0);
|
||||
xTaskCreatePinnedToCore(tstMem , "tsktwo" , 2048, mem[1], 3, &th[1], 1);
|
||||
|
||||
for (int l=0; l<10; l++) {
|
||||
for (int p=0; p<4096*1024; p+=65536) {
|
||||
const void *out;
|
||||
spi_flash_mmap_handle_t h;
|
||||
spi_flash_mmap(p, 65536, SPI_FLASH_MMAP_DATA, &out, &h);
|
||||
spi_flash_munmap(h);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Checked memory %d and %d times. Errors: %d and %d\n", res[0], res[1], err[0], err[1]);
|
||||
|
||||
vTaskDelete(th[0]);
|
||||
vTaskDelete(th[1]);
|
||||
#if USE_CAPS_ALLOC
|
||||
free(mem[0]);
|
||||
free(mem[1]);
|
||||
#endif
|
||||
TEST_ASSERT(err[0]==0);
|
||||
TEST_ASSERT(err[1]==0);
|
||||
}
|
||||
|
||||
|
||||
#define CYCLES 1024
|
||||
|
||||
TEST_CASE("Spiram cache flush on write/read", "[spiram]")
|
||||
{
|
||||
void *mem[2];
|
||||
res[0]=0; res[1]=0;
|
||||
#if USE_CAPS_ALLOC
|
||||
printf("Allocating SPI RAM chunk...\n");
|
||||
mem[0]=heap_caps_malloc(TSTSZ, MALLOC_CAP_SPIRAM);
|
||||
mem[1]=heap_caps_malloc(TSTSZ, MALLOC_CAP_SPIRAM);
|
||||
#else
|
||||
mem[0]=(void*)SOC_EXTRAM_DATA_LOW;
|
||||
mem[1]=(void*)SOC_EXTRAM_DATA_LOW+TSTSZ;
|
||||
#endif
|
||||
assert(mem[0]);
|
||||
assert(mem[1]);
|
||||
TaskHandle_t th[2];
|
||||
const esp_partition_t* part = get_test_data_partition();
|
||||
assert(part!=NULL);
|
||||
|
||||
printf("Erasing sector...\n");
|
||||
esp_partition_erase_range(part, 0, 64*1024);
|
||||
printf("Erased.\n");
|
||||
printf("Creating tasks\n");
|
||||
xTaskCreatePinnedToCore(tstMem , "tskone" , 2048, mem[0], 3, &th[0], 0);
|
||||
xTaskCreatePinnedToCore(tstMem , "tsktwo" , 2048, mem[1], 3, &th[1], 1);
|
||||
char buf[512];
|
||||
|
||||
const void *out;
|
||||
spi_flash_mmap_handle_t handle;
|
||||
esp_partition_mmap(part, 0, 512, SPI_FLASH_MMAP_DATA, &out, &handle);
|
||||
for (int i=0; i<CYCLES; i++) {
|
||||
esp_partition_write(part, 0, buf, 512);
|
||||
esp_partition_read(part, 0, buf, 512);
|
||||
vTaskDelay(1);
|
||||
}
|
||||
spi_flash_munmap(handle);
|
||||
|
||||
printf("Checked memory %d and %d times.\n", res[0], res[1]);
|
||||
|
||||
vTaskDelete(th[0]);
|
||||
vTaskDelete(th[1]);
|
||||
#if USE_CAPS_ALLOC
|
||||
free(mem[0]);
|
||||
free(mem[1]);
|
||||
#endif
|
||||
}
|
||||
#endif // !CONFIG_FREERTOS_UNICORE
|
||||
|
||||
IRAM_ATTR TEST_CASE("Spiram memcmp weirdness at 80MHz", "[spiram]") {
|
||||
char *mem1=malloc(0x10000);
|
||||
#if USE_CAPS_ALLOC
|
||||
char *mem2=heap_caps_malloc(0x10000, MALLOC_CAP_SPIRAM);
|
||||
#else
|
||||
char *mem2=(void*)SOC_EXTRAM_DATA_LOW;
|
||||
#endif
|
||||
|
||||
#if !CONFIG_SPIRAM_SPEED_80M
|
||||
printf("**** WARNING **** Spi memory isn't running at 80MHz, so this test is somewhat meaningless.\n");
|
||||
#endif
|
||||
|
||||
printf("RAM: Got %p and %p\n", mem1, mem2);
|
||||
assert(mem1);
|
||||
assert(mem2);
|
||||
for (int i=0; i<0x10000; i++) mem1[i]=i^0xAAAAAAAA;
|
||||
|
||||
for (int cycle=1; cycle<100; cycle++) {
|
||||
memcpy(mem2, mem1, 0x10000);
|
||||
if (memcmp(mem1, mem2, 0x10000)!=0) {
|
||||
printf("Memcmp failed! Cycle %d\n", cycle);
|
||||
for (int i=0; i<0x10000; i++) {
|
||||
if (mem1[i]!=mem2[i]) {
|
||||
printf("Found real difference at index %d: 0x%x vs 0x%x\n", i, mem1[i], mem2[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(mem1);
|
||||
#if USE_CAPS_ALLOC
|
||||
free(mem2);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // CONFIG_SPIRAM
|
@ -1,72 +1,15 @@
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
|
||||
|
||||
if(NOT "${target}" STREQUAL "esp32s3")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(BOOTLOADER_BUILD)
|
||||
# For bootloader, all we need from esp32s3 is headers
|
||||
idf_component_register(INCLUDE_DIRS include REQUIRES xtensa)
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s3.peripherals.ld")
|
||||
else()
|
||||
# Regular app build
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
# [refactor-todo] propagate these requirements for compatibility
|
||||
# remove in the future
|
||||
set(legacy_reqs driver efuse soc)
|
||||
endif()
|
||||
|
||||
set(srcs "dport_access.c"
|
||||
"esp_crypto_lock.c"
|
||||
"memprot.c"
|
||||
"spiram.c"
|
||||
"spi_timing_config.c")
|
||||
set(include_dirs "include")
|
||||
|
||||
set(requires driver efuse soc xtensa) #unfortunately rom/uart uses SOC registers directly
|
||||
|
||||
# driver is a public requirement because esp_sleep.h uses gpio_num_t & touch_pad_t
|
||||
# app_update is added here because cpu_start.c uses esp_ota_get_app_description() function.
|
||||
# esp_timer is added here because cpu_start.c uses esp_timer
|
||||
set(priv_requires app_trace app_update bootloader_support log mbedtls nvs_flash pthread
|
||||
spi_flash vfs espcoredump esp_common perfmon esp_timer esp_ipc)
|
||||
|
||||
if(CONFIG_SPIRAM_MODE_QUAD)
|
||||
list(APPEND srcs "spiram_psram.c")
|
||||
elseif(CONFIG_SPIRAM_MODE_OCT)
|
||||
list(APPEND srcs "opiram_psram.c")
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "${include_dirs}"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}"
|
||||
idf_component_register(REQUIRES xtensa "${legacy_reqs}"
|
||||
REQUIRED_IDF_TARGETS esp32s3)
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32s3_out.ld")
|
||||
|
||||
# Process the template file through the linker script generation mechanism, and use the output for linking the
|
||||
# final binary
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32s3.project.ld.in"
|
||||
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32s3.project.ld")
|
||||
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s3.peripherals.ld")
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
|
||||
|
||||
idf_build_get_property(config_dir CONFIG_DIR)
|
||||
# Preprocess esp32s3.ld linker script to include configuration, becomes esp32s3_out.ld
|
||||
set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
|
||||
add_custom_command(
|
||||
OUTPUT esp32s3_out.ld
|
||||
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp32s3_out.ld -I ${config_dir} ${LD_DIR}/esp32s3.ld
|
||||
MAIN_DEPENDENCY ${LD_DIR}/esp32s3.ld
|
||||
DEPENDS ${sdkconfig_header}
|
||||
COMMENT "Generating linker script..."
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(esp32s3_linker_script DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/esp32s3_out.ld)
|
||||
add_dependencies(${COMPONENT_LIB} esp32s3_linker_script)
|
||||
|
||||
# disable stack protection in files which are involved in initialization of that feature
|
||||
set_source_files_properties(
|
||||
cpu_start.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
-fno-stack-protector)
|
||||
endif()
|
||||
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32s3.peripherals.ld")
|
||||
|
@ -1,90 +0,0 @@
|
||||
// Copyright 2015-2020 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.
|
||||
|
||||
|
||||
#ifndef __ESP_SPIRAM_H
|
||||
#define __ESP_SPIRAM_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize spiram interface/hardware. Normally called from cpu_start.c.
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_spiram_init(void);
|
||||
|
||||
/**
|
||||
* @brief Configure Cache/MMU for access to external SPI RAM.
|
||||
*
|
||||
* Normally this function is called from cpu_start, if CONFIG_SPIRAM_BOOT_INIT
|
||||
* option is enabled. Applications which need to enable SPI RAM at run time
|
||||
* can disable CONFIG_SPIRAM_BOOT_INIT, and call this function later.
|
||||
*
|
||||
* @attention this function must be called with flash cache disabled.
|
||||
*/
|
||||
void esp_spiram_init_cache(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Memory test for SPI RAM. Should be called after SPI RAM is initialized and
|
||||
* (in case of a dual-core system) the app CPU is online. This test overwrites the
|
||||
* memory with crap, so do not call after e.g. the heap allocator has stored important
|
||||
* stuff in SPI RAM.
|
||||
*
|
||||
* @return true on success, false on failed memory test
|
||||
*/
|
||||
bool esp_spiram_test(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Add the initialized SPI RAM to the heap allocator.
|
||||
*/
|
||||
esp_err_t esp_spiram_add_to_heapalloc(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the size of the attached SPI RAM chip selected in menuconfig
|
||||
*
|
||||
* @return Size in bytes, or 0 if no external RAM chip support compiled in.
|
||||
*/
|
||||
size_t esp_spiram_get_size(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Force a writeback of the data in the SPI RAM cache. This is to be called whenever
|
||||
* cache is disabled, because disabling cache on the ESP32 discards the data in the SPI
|
||||
* RAM cache.
|
||||
*
|
||||
* This is meant for use from within the SPI flash code.
|
||||
*/
|
||||
void esp_spiram_writeback_cache(void);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reserve a pool of internal memory for specific DMA/internal allocations
|
||||
*
|
||||
* @param size Size of reserved pool in bytes
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NO_MEM when no memory available for pool
|
||||
*/
|
||||
esp_err_t esp_spiram_reserve_dma_pool(size_t size);
|
||||
|
||||
|
||||
#endif
|
@ -5,9 +5,6 @@
|
||||
#if __has_include("soc/soc.h")
|
||||
#include "soc/soc.h"
|
||||
#endif
|
||||
#if __has_include("esp_ds.h")
|
||||
#include "esp_ds.h"
|
||||
#endif
|
||||
#if __has_include("esp_efuse.h")
|
||||
#include "esp_efuse.h"
|
||||
#endif
|
||||
@ -59,6 +56,9 @@
|
||||
#if __has_include("nvs.h")
|
||||
#include "nvs.h"
|
||||
#endif
|
||||
#if __has_include("soc/esp32s2/esp_ds.h")
|
||||
#include "soc/esp32s2/esp_ds.h"
|
||||
#endif
|
||||
#if __has_include("ulp_common.h")
|
||||
#include "ulp_common.h"
|
||||
#endif
|
||||
@ -740,7 +740,7 @@ static const esp_err_msg_t esp_err_msg_table[] = {
|
||||
ERR_TBL_IT(ESP_ERR_HW_CRYPTO_BASE), /* 49152 0xc000 Starting number of HW cryptography
|
||||
module error codes */
|
||||
# endif
|
||||
// components/esp32s2/include/esp_ds.h
|
||||
// components/esp_hw_support/include/soc/esp32s2/esp_ds.h
|
||||
# ifdef ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL
|
||||
ERR_TBL_IT(ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL), /* 49153 0xc001 HMAC peripheral problem */
|
||||
# endif
|
||||
|
@ -2,12 +2,11 @@ idf_build_get_property(target IDF_TARGET)
|
||||
|
||||
set(priv_requires efuse)
|
||||
set(requires soc)
|
||||
set(priv_requires efuse bootloader_support spi_flash)
|
||||
if(${target} STREQUAL "esp32")
|
||||
list(APPEND requires efuse)
|
||||
endif()
|
||||
|
||||
set(priv_requires efuse)
|
||||
|
||||
set(srcs "compare_set.c" "cpu_util.c")
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
list(APPEND srcs "esp_async_memcpy.c"
|
||||
@ -25,11 +24,35 @@ else()
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS include include/soc
|
||||
INCLUDE_DIRS include include/soc include/soc/${target}
|
||||
PRIV_INCLUDE_DIRS port/include
|
||||
REQUIRES ${requires}
|
||||
PRIV_REQUIRES ${priv_requires}
|
||||
PRIV_REQUIRES "${priv_requires}"
|
||||
LDFRAGMENTS linker.lf)
|
||||
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
add_subdirectory(port/${target})
|
||||
|
||||
if(CONFIG_IDF_TARGET_ESP32 AND CONFIG_SPIRAM_CACHE_WORKAROUND AND NOT BOOTLOADER_BUILD)
|
||||
# Note: Adding as a PUBLIC compile option here causes this option to propagate to all
|
||||
# components that depend on esp32.
|
||||
#
|
||||
# To handle some corner cases, the same flag is set in project_include.cmake
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
|
||||
# also, make sure we link with this option so correct toolchain libs are pulled in
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
|
||||
# set strategy selected
|
||||
# note that we don't need to set link options as the library linked is independent of this
|
||||
if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST)
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=dupldst)
|
||||
endif()
|
||||
if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW)
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=memw)
|
||||
endif()
|
||||
if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_NOPS)
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-strategy=nops)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -17,16 +17,3 @@ CFLAGS+=$(SPIRAM_CACHE_WORKAROUND_FLAGS)
|
||||
CXXFLAGS+=$(SPIRAM_CACHE_WORKAROUND_FLAGS)
|
||||
LDFLAGS+=$(SPIRAM_CACHE_WORKAROUND_FLAGS)
|
||||
endif
|
||||
|
||||
|
||||
|
||||
# Enable dynamic esp_timer overflow value if building unit tests
|
||||
ifneq ("$(filter esp32,$(TEST_COMPONENTS_LIST))","")
|
||||
CPPFLAGS += -DESP_TIMER_DYNAMIC_OVERFLOW_VAL
|
||||
endif
|
||||
ESP32_LINKER_SCRIPT_TEMPLATE := $(COMPONENT_PATH)/ld/esp32.project.ld.in
|
||||
ESP32_LINKER_SCRIPT_OUTPUT_DIR := $(realpath $(BUILD_DIR_BASE)/esp32)
|
||||
|
||||
# Target to generate linker script generator from fragments presented by each of
|
||||
# the components
|
||||
$(eval $(call ldgen_process_template, $(ESP32_LINKER_SCRIPT_TEMPLATE), $(ESP32_LINKER_SCRIPT_OUTPUT_DIR)/esp32.project.ld))
|
@ -3,7 +3,17 @@ COMPONENT_ADD_INCLUDEDIRS := . include port/$(IDF_TARGET)/ include/soc port/$(ID
|
||||
COMPONENT_ADD_LDFRAGMENTS := linker.lf
|
||||
|
||||
ifdef IS_BOOTLOADER_BUILD
|
||||
COMPONENT_OBJEXCLUDE += clk_ctrl_os.o mac_addr.o sp_async_memcpy.o intr_alloc.o sleep_modes.o regi2c_ctrl.o
|
||||
COMPONENT_OBJEXCLUDE += clk_ctrl_os.o \
|
||||
intr_alloc.o \
|
||||
sleep_modes.o \
|
||||
esp_async_memcpy.o \
|
||||
mac_addr.o \
|
||||
regi2c_ctrl.o \
|
||||
port/$(IDF_TARGET)/dport_access.o \
|
||||
port/$(IDF_TARGET)/cache_sram_mmu.o \
|
||||
port/$(IDF_TARGET)/esp_himem.o \
|
||||
port/$(IDF_TARGET)/spiram.o \
|
||||
port/$(IDF_TARGET)/spiram_psram.o
|
||||
endif
|
||||
|
||||
COMPONENT_OBJEXCLUDE += esp_async_memcpy.o
|
||||
|
@ -108,9 +108,8 @@ esp_err_t esp_spiram_reserve_dma_pool(size_t size);
|
||||
*/
|
||||
bool esp_spiram_is_initialized(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __ESP_SPIRAM_H
|
@ -20,6 +20,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_attr.h"
|
||||
|
||||
#ifdef __cplusplus
|
@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "esp_attr.h"
|
||||
|
||||
#ifdef __cplusplus
|
@ -15,6 +15,8 @@
|
||||
#ifndef _ESP_DPORT_ACCESS_H_
|
||||
#define _ESP_DPORT_ACCESS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
@ -15,6 +15,8 @@
|
||||
#ifndef _ESP_DPORT_ACCESS_H_
|
||||
#define _ESP_DPORT_ACCESS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
@ -11,5 +11,13 @@ set(srcs
|
||||
"rtc_wdt.c"
|
||||
"chip_info.c")
|
||||
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
list(APPEND srcs "cache_sram_mmu.c"
|
||||
"dport_access.c"
|
||||
"esp_himem.c"
|
||||
"spiram.c"
|
||||
"spiram_psram.c")
|
||||
endif()
|
||||
|
||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||
target_sources(${COMPONENT_LIB} PRIVATE "${srcs}")
|
||||
|
@ -11,6 +11,10 @@
|
||||
#include "esp_err.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
PSRAM_CACHE_F80M_S40M = 0,
|
||||
PSRAM_CACHE_F40M_S40M,
|
||||
@ -59,4 +63,8 @@ psram_size_t psram_get_size(void);
|
||||
*/
|
||||
esp_err_t psram_enable(psram_cache_mode_t mode, psram_vaddr_mode_t vaddrmode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -9,7 +9,12 @@ set(srcs "cpu_util_esp32c3.c"
|
||||
)
|
||||
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
list(APPEND srcs "../async_memcpy_impl_gdma.c")
|
||||
list(APPEND srcs "../async_memcpy_impl_gdma.c"
|
||||
"memprot.c"
|
||||
"esp_hmac.c"
|
||||
"esp_crypto_lock.c"
|
||||
"esp_ds.c"
|
||||
"dport_access.c")
|
||||
endif()
|
||||
|
||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||
|
@ -9,7 +9,12 @@ set(srcs "cpu_util_esp32h2.c"
|
||||
)
|
||||
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
list(APPEND srcs "../async_memcpy_impl_gdma.c")
|
||||
list(APPEND srcs "../async_memcpy_impl_gdma.c"
|
||||
"memprot.c"
|
||||
"esp_hmac.c"
|
||||
"esp_crypto_lock.c"
|
||||
"esp_ds.c"
|
||||
"dport_access.c")
|
||||
endif()
|
||||
|
||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||
@ -17,8 +22,3 @@ add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||
target_sources(${COMPONENT_LIB} PRIVATE "${srcs}")
|
||||
target_include_directories(${COMPONENT_LIB} PUBLIC . private_include)
|
||||
target_include_directories(${COMPONENT_LIB} PRIVATE ../hal)
|
||||
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/rtc_clk.c" PROPERTIES
|
||||
COMPILE_FLAGS "-fno-jump-tables -fno-tree-switch-conversion")
|
||||
endif()
|
||||
|
@ -14,7 +14,14 @@ set(srcs
|
||||
)
|
||||
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
list(APPEND srcs "async_memcpy_impl_cp_dma.c")
|
||||
list(APPEND srcs "async_memcpy_impl_cp_dma.c"
|
||||
"memprot.c"
|
||||
"esp_hmac.c"
|
||||
"esp_crypto_lock.c"
|
||||
"esp_ds.c"
|
||||
"dport_access.c"
|
||||
"spiram.c"
|
||||
"spiram_psram.c")
|
||||
endif()
|
||||
|
||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||
|
@ -13,7 +13,18 @@ set(srcs
|
||||
)
|
||||
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
list(APPEND srcs "../async_memcpy_impl_gdma.c")
|
||||
list(APPEND srcs "../async_memcpy_impl_gdma.c"
|
||||
"dport_access.c"
|
||||
"esp_crypto_lock.c"
|
||||
"memprot.c"
|
||||
"spiram.c")
|
||||
|
||||
if(CONFIG_SPIRAM_MODE_QUAD)
|
||||
list(APPEND srcs "spiram_psram.c")
|
||||
elseif(CONFIG_SPIRAM_MODE_OCT)
|
||||
list(APPEND srcs "opiram_psram.c")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user