diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index 7d9ad3872..985b1d8bf 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -96,5 +96,19 @@ else() 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() diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 6c75e6a74..413d8aba0 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -168,6 +168,40 @@ menu "ESP32-specific" The workaround is not required for ESP32 revision 3 and above. + menu "SPIRAM cache workaround debugging" + + choice SPIRAM_CACHE_WORKAROUND_STRATEGY + prompt "Workaround strategy" + depends on SPIRAM_CACHE_WORKAROUND + default SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW + help + Select the workaround strategy. Note that the strategy for precompiled + libraries (libgcc, newlib, bt, wifi) is not affected by this selection. + + Unless you know you need a different strategy, it's suggested you stay + with the default MEMW strategy. Note that DUPLDST can interfere with hardware + encryption and this will be automatically disabled if this workaround is selected. + 'Insert nops' is the workaround that was used in older esp-idf versions. This workaround + still can cause faulty data transfers from/to SPI RAM in some situation. + + config SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW + bool "Insert memw after vulnerable instructions (default)" + + config SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST + bool "Duplicate LD/ST for 32-bit, memw for 8/16 bit" + + config SPIRAM_CACHE_WORKAROUND_STRATEGY_NOPS + bool "Insert nops between vulnerable loads/stores (old strategy, obsolete)" + endchoice + + #This needs to be Y only for the dupldst workaround + config SPIRAM_WORKAROUND_NEED_VOLATILE_SPINLOCK + bool + default "y" if SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST + + + endmenu + config SPIRAM_BANKSWITCH_ENABLE bool "Enable bank switching for >4MiB external RAM" default y diff --git a/components/esp32/Makefile.projbuild b/components/esp32/Makefile.projbuild index d13dbe2d0..476cead53 100644 --- a/components/esp32/Makefile.projbuild +++ b/components/esp32/Makefile.projbuild @@ -1,9 +1,24 @@ # Enable psram cache bug workaround in compiler if selected + ifdef CONFIG_SPIRAM_CACHE_WORKAROUND -CFLAGS+=-mfix-esp32-psram-cache-issue -CXXFLAGS+=-mfix-esp32-psram-cache-issue -LDFLAGS+=-mfix-esp32-psram-cache-issue +SPIRAM_CACHE_WORKAROUND_FLAGS = -mfix-esp32-psram-cache-issue + +ifdef CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST +SPIRAM_CACHE_WORKAROUND_FLAGS += -mfix-esp32-psram-cache-strategy=dupldst endif +ifdef CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW +SPIRAM_CACHE_WORKAROUND_FLAGS += -mfix-esp32-psram-cache-strategy=memw +endif +ifdef CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_NOPS +SPIRAM_CACHE_WORKAROUND_FLAGS += -mfix-esp32-psram-cache-strategy=nops +endif + +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))","") diff --git a/components/esp32/project_include.cmake b/components/esp32/project_include.cmake index aa0ac286f..e53f24038 100644 --- a/components/esp32/project_include.cmake +++ b/components/esp32/project_include.cmake @@ -4,6 +4,16 @@ if(CONFIG_SPIRAM_CACHE_WORKAROUND) # non-IDF CMakeLists.txt file is imported into a component) don't depend # on the esp32 component so don't get the extra flag. This handles that case. idf_build_set_property(COMPILE_OPTIONS "-mfix-esp32-psram-cache-issue" APPEND) + # 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) + idf_build_set_property(COMPILE_OPTIONS "-mfix-esp32-psram-cache-strategy=dupldst" APPEND) + endif() + if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMW) + idf_build_set_property(COMPILE_OPTIONS "-mfix-esp32-psram-cache-strategy=memw" APPEND) + endif() + if(CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_NOPS) + idf_build_set_property(COMPILE_OPTIONS "-mfix-esp32-psram-cache-strategy=nops" APPEND) + endif() endif() # Check toolchain is configured properly in cmake diff --git a/components/freertos/include/freertos/portmacro.h b/components/freertos/include/freertos/portmacro.h index 183d38a4d..4ed2d5688 100644 --- a/components/freertos/include/freertos/portmacro.h +++ b/components/freertos/include/freertos/portmacro.h @@ -133,6 +133,12 @@ typedef unsigned portBASE_TYPE UBaseType_t; #include "sdkconfig.h" #include "esp_attr.h" +#ifdef CONFIG_SPIRAM_WORKAROUND_NEED_VOLATILE_SPINLOCK +#define NEED_VOLATILE_MUX volatile +#else +#define NEED_VOLATILE_MUX +#endif + /* "mux" data structure (spinlock) */ typedef struct { /* owner field values: @@ -142,12 +148,12 @@ typedef struct { * * Any value other than portMUX_FREE_VAL, CORE_ID_PRO, CORE_ID_APP indicates corruption */ - uint32_t owner; + NEED_VOLATILE_MUX uint32_t owner; /* count field: * If mux is unlocked, count should be zero. * If mux is locked, count is non-zero & represents the number of recursive locks on the mux. */ - uint32_t count; + NEED_VOLATILE_MUX uint32_t count; #ifdef CONFIG_FREERTOS_PORTMUX_DEBUG const char *lastLockedFn; int lastLockedLine; diff --git a/components/mbedtls/Kconfig b/components/mbedtls/Kconfig index 7514d7621..217a5ae0e 100644 --- a/components/mbedtls/Kconfig +++ b/components/mbedtls/Kconfig @@ -132,6 +132,7 @@ menu "mbedTLS" config MBEDTLS_HARDWARE_AES bool "Enable hardware AES acceleration" default y + depends on !SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST help Enable hardware accelerated AES encryption & decryption. @@ -141,6 +142,7 @@ menu "mbedTLS" config MBEDTLS_HARDWARE_MPI bool "Enable hardware MPI (bignum) acceleration" default n + depends on !SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST help Enable hardware accelerated multiple precision integer operations. @@ -162,6 +164,7 @@ menu "mbedTLS" config MBEDTLS_HARDWARE_SHA bool "Enable hardware SHA acceleration" default y + depends on !SPIRAM_CACHE_WORKAROUND_STRATEGY_DUPLDST help Enable hardware accelerated SHA1, SHA256, SHA384 & SHA512 in mbedTLS. diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index 43f4d3270..81f00a554 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -394,6 +394,21 @@ function run_tests() grep -q '"command"' build/compile_commands.json || failure "compile_commands.json missing or has no no 'commands' in it" (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-issue) && failure "All commands in compile_commands.json should use PSRAM cache workaround" rm -r build + #Test for various strategies + for strat in MEMW NOPS DUPLDST; do + rm -r build sdkconfig.defaults sdkconfig sdkconfig.defaults.esp32 + stratlc=`echo $strat | tr A-Z a-z` + mkdir build && touch build/sdkconfig + echo "CONFIG_ESP32_SPIRAM_SUPPORT=y" > sdkconfig.defaults + echo "CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_$strat=y" >> sdkconfig.defaults + echo "CONFIG_SPIRAM_CACHE_WORKAROUND=y" >> sdkconfig.defaults + # note: we do 'reconfigure' here, as we just need to run cmake + idf.py reconfigure + grep -q '"command"' build/compile_commands.json || failure "compile_commands.json missing or has no no 'commands' in it" + (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-strategy=$stratlc) && failure "All commands in compile_commands.json should use PSRAM cache workaround strategy $strat when selected" + echo ${PWD} + rm -r sdkconfig.defaults build + done print_status "Cleaning Python bytecode" idf.py clean > /dev/null diff --git a/tools/test_idf_tools/test_idf_tools.py b/tools/test_idf_tools/test_idf_tools.py index f9f7dc5c9..ef804953b 100755 --- a/tools/test_idf_tools/test_idf_tools.py +++ b/tools/test_idf_tools/test_idf_tools.py @@ -71,7 +71,7 @@ class TestUsage(unittest.TestCase): idf_tools.main(['list']) output = output_stream.getvalue() - xtensa_esp32_elf_version = 'esp-2019r2-8.2.0' + xtensa_esp32_elf_version = 'esp-2020r2-8.2.0' esp32ulp_version = '2.28.51.20170517' self.assertIn('* xtensa-esp32-elf:', output) diff --git a/tools/toolchain_versions.mk b/tools/toolchain_versions.mk index 9d3463ff2..ba15d521c 100644 --- a/tools/toolchain_versions.mk +++ b/tools/toolchain_versions.mk @@ -1,6 +1,6 @@ -SUPPORTED_TOOLCHAIN_COMMIT_DESC = esp-2019r2 +SUPPORTED_TOOLCHAIN_COMMIT_DESC = esp-2020r2 SUPPORTED_TOOLCHAIN_GCC_VERSIONS = 8.2.0 -CURRENT_TOOLCHAIN_COMMIT_DESC = esp-2019r2 -CURRENT_TOOLCHAIN_COMMIT_DESC_SHORT = esp-2019r2 +CURRENT_TOOLCHAIN_COMMIT_DESC = esp-2020r2 +CURRENT_TOOLCHAIN_COMMIT_DESC_SHORT = esp-2020r2 CURRENT_TOOLCHAIN_GCC_VERSION = 8.2.0 diff --git a/tools/tools.json b/tools/tools.json index 7be054a19..36b13b9ef 100644 --- a/tools/tools.json +++ b/tools/tools.json @@ -22,36 +22,36 @@ "versions": [ { "linux-amd64": { - "sha256": "e6d47c1dbd8c8cbfe37271e5e2aac53ee88c9e347ae937e22bf0c73f530efbdf", - "size": 85459985, - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz" + "sha256": "6c73b9e9d252810a63ca5e94b497c6c09fb8c903fe9c477f385bdc2ab4d2187e", + "size": 85520229, + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz" }, "linux-armel": { - "sha256": "54a199c28f591da2466b21741911bc2ba77ddf82d3d2b66c6ce03c1a0c6835f0", - "size": 83647538, - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-armel.tar.gz" + "sha256": "51dd318c4f2ac1fe2b206d029e1d2080c922107cc56e4a3802b1acafd7b436db", + "size": 83672167, + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-armel.tar.gz" }, "linux-i686": { - "sha256": "36a9648c414dbd1c518c687ce5587d9f8eaa94324f45d92e9ec31a1433a04df8", - "size": 87438500, - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-i686.tar.gz" + "sha256": "a003c7bc9b9f0dd82170480aadd62c0586fc6e3d69119c637c957125164f40e5", + "size": 87467927, + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-i686.tar.gz" }, "macos": { - "sha256": "dc62be8dd16c6d9d28d64e2b3f831fa208f3548c2ca73cdbcbdf68f474d59521", - "size": 92150978, - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-macos.tar.gz" + "sha256": "48b288e3e5c60623851616bf545b8e4fc5382dc980d6b9682373f11013fe5776", + "size": 92201363, + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-macos.tar.gz" }, - "name": "esp-2019r2-8.2.0", + "name": "esp-2020r2-8.2.0", "status": "recommended", "win32": { - "sha256": "c9d5776a22516f0825a7c68d835ffacc2392f913136893b7646e1288937cc65e", - "size": 103850448, - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip" + "sha256": "f2ba6bdb1c4b2178955e5e7a204552bb754709e02eaf9d8febe770d46629db8f", + "size": 103885422, + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-win32.zip" }, "win64": { - "sha256": "c9d5776a22516f0825a7c68d835ffacc2392f913136893b7646e1288937cc65e", - "size": 103850448, - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip" + "sha256": "036ae8c737e7a4ced7121881f10747cf7b18914648ef611c78b3d543a0f00d8f", + "size": 106505186, + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-win64.zip" } } ] diff --git a/tools/windows/windows_install_prerequisites.sh b/tools/windows/windows_install_prerequisites.sh index baf183898..6148dfbad 100644 --- a/tools/windows/windows_install_prerequisites.sh +++ b/tools/windows/windows_install_prerequisites.sh @@ -42,7 +42,7 @@ if [ -n "$IDF_PATH" ]; then fi # Automatically download precompiled toolchain, unpack at /opt/xtensa-esp32-elf/ -TOOLCHAIN_ZIP=xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip +TOOLCHAIN_ZIP=xtensa-esp32-elf-gcc8_2_0-esp-2020r2-win32.zip echo "Downloading precompiled toolchain ${TOOLCHAIN_ZIP}..." cd ~ curl -LO --retry 10 https://dl.espressif.com/dl/${TOOLCHAIN_ZIP}