Skip to content

Commit

Permalink
Merge branch 'espressif:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 authored Mar 6, 2024
2 parents 6da31c8 + 9f4e8eb commit a5829cf
Show file tree
Hide file tree
Showing 198 changed files with 2,888 additions and 1,195 deletions.
8 changes: 8 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ mainmenu "Espressif IoT Development Framework Configuration"
select FREERTOS_UNICORE
select IDF_TARGET_ARCH_RISCV

config IDF_TARGET_ESP32C61
bool
default "y" if IDF_TARGET="esp32c61"
select FREERTOS_UNICORE
select IDF_TARGET_ARCH_RISCV
select IDF_ENV_FPGA

config IDF_TARGET_LINUX
bool
default "y" if IDF_TARGET="linux"
Expand All @@ -167,6 +174,7 @@ mainmenu "Espressif IoT Development Framework Configuration"
default 0x0012 if IDF_TARGET_ESP32P4
default 0x0011 if IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32C5_BETA3_VERSION # TODO: IDF-9197
default 0x0017 if IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32C5_MP_VERSION # TODO: IDF-9197
default 0x0014 if IDF_TARGET_ESP32C61
default 0xFFFF


Expand Down
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion components/bt/host/nimble/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ config BT_NIMBLE_ENABLE_CONN_REATTEMPT

config BT_NIMBLE_MAX_CONN_REATTEMPT
int "Maximum number connection reattempts"
range 1 7
range 1 255
default 3
depends on BT_NIMBLE_ENABLED && BT_NIMBLE_ENABLE_CONN_REATTEMPT
help
Expand Down
11 changes: 10 additions & 1 deletion components/console/linenoise/linenoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdio_ext.h>
#if !CONFIG_IDF_TARGET_LINUX
// On Linux, we don't need __fbufsize (see comments below), and
// __fbufsize not available on MacOS (which is also considered "Linux" target)
#include <stdio_ext.h> // for __fbufsize
#endif
#include <errno.h>
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -216,9 +220,14 @@ bool linenoiseIsDumbMode(void) {
}

static void flushWrite(void) {
// On Linux, we set stdout to unbuffered mode to facilitate interaction with tools.
// Performance on Linux is not considered as critical as on chip targets. Additionally,
// MacOS does not have __fbufsize.
#if !CONFIG_IDF_TARGET_LINUX
if (__fbufsize(stdout) > 0) {
fflush(stdout);
}
#endif
fsync(fileno(stdout));
}

Expand Down
4 changes: 3 additions & 1 deletion components/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ endif()

idf_component_register(SRCS "cxx_exception_stubs.cpp"
"cxx_guards.cpp"
"cxx_init.cpp"
# Make sure that pthread is in component list
PRIV_REQUIRES pthread)
PRIV_REQUIRES pthread esp_system)

if(NOT CONFIG_CXX_EXCEPTIONS)
set(WRAP_FUNCTIONS
Expand Down Expand Up @@ -54,6 +55,7 @@ else()
target_link_libraries(${COMPONENT_LIB} PUBLIC stdc++ gcc)
endif()
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxa_guard_dummy")
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxx_init_dummy")

# Force libpthread to appear later than libstdc++ in link line since libstdc++ depends on libpthread.
# Furthermore, force libcxx to appear later than libgcc because some libgcc unwind code is wrapped, if C++
Expand Down
50 changes: 50 additions & 0 deletions components/cxx/cxx_init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_private/startup_internal.h"

namespace {
const char *TAG = "C++ init";
}

#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
// workaround for C++ exception large memory allocation
extern "C" void _Unwind_SetEnableExceptionFdeSorting(unsigned char enable);

ESP_SYSTEM_INIT_FN(init_cxx_exceptions, SECONDARY, BIT(0), 205)
{
ESP_EARLY_LOGD(TAG, "Setting C++ exception workarounds.");
_Unwind_SetEnableExceptionFdeSorting(0);
return ESP_OK;
}
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS

/**
* This function overwrites the same function of libsupc++ (part of libstdc++).
* Consequently, libsupc++ will then follow our configured exception emergency pool size.
*
* It will be called even with -fno-exception for user code since the stdlib still uses exceptions.
*/
extern "C" size_t __cxx_eh_arena_size_get(void)
{
#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
ESP_EARLY_LOGD(TAG, "Setting C++ exception emergency pool to %u.", CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE);
return CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE;
#else
ESP_EARLY_LOGD(TAG, "Setting C++ exception emergency pool to 0.");
return 0;
#endif
}

/**
* Dummy function used to force linking this file.
* This works via -u __cxx_init_dummy flag in CMakeLists.txt
*/
extern "C" void __cxx_init_dummy(void)
{
}
12 changes: 11 additions & 1 deletion components/efuse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@ list(APPEND srcs "src/esp_efuse_api.c"
"src/esp_efuse_utility.c"
"src/efuse_controller/keys/${type}/esp_efuse_api_key.c")

idf_component_register(SRCS "${srcs}"
if(BOOTLOADER_BUILD)
idf_component_register(SRCS "${srcs}"
PRIV_REQUIRES bootloader_support soc spi_flash
INCLUDE_DIRS "${include_dirs}"
PRIV_INCLUDE_DIRS "${private_include}")
else()
list(APPEND srcs "src/esp_efuse_startup.c")
idf_component_register(SRCS "${srcs}"
PRIV_REQUIRES bootloader_support soc spi_flash esp_system esp_partition esp_app_format
INCLUDE_DIRS "${include_dirs}"
PRIV_INCLUDE_DIRS "${private_include}")
# Forces the linker to include esp_efuse_startup.c
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_efuse_startup_include_func")
endif()

if(target)
set(TOOL_TARGET -t ${target})
Expand Down
157 changes: 157 additions & 0 deletions components/efuse/src/esp_efuse_startup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "soc/soc_caps.h"
#include "hal/efuse_hal.h"
#include "rom/efuse.h"
#include "esp_efuse.h"
#include "esp_efuse_table.h"
#include "esp_check.h"
#include "esp_efuse_utility.h"
#include "esp_system.h"
#include "esp_flash_encrypt.h"
#include "esp_secure_boot.h"
#include "esp_log.h"
#include "esp_private/startup_internal.h"
#ifdef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
#include "esp_partition.h"
#endif
#include "sdkconfig.h"

#if __has_include("esp_app_desc.h")
#include "esp_app_desc.h"
#endif

static __attribute__((unused)) const char *TAG = "efuse_init";

ESP_SYSTEM_INIT_FN(init_efuse_check, CORE, BIT(0), 1)
{
// (Only for C3): We check if the efuse BLOCK0 has certain coding errors then reset the chip.
if (esp_efuse_check_errors() != ESP_OK) {
esp_restart();
}
return ESP_OK;
}

// It comes after init_show_app_info to print the consistent application information.
ESP_SYSTEM_INIT_FN(init_efuse_show_app_info, CORE, BIT(0), 21)
{
if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) {
ESP_EARLY_LOGI(TAG, "Min chip rev: v%d.%d", CONFIG_ESP_REV_MIN_FULL / 100, CONFIG_ESP_REV_MIN_FULL % 100);
ESP_EARLY_LOGI(TAG, "Max chip rev: v%d.%d %s", CONFIG_ESP_REV_MAX_FULL / 100, CONFIG_ESP_REV_MAX_FULL % 100,
efuse_hal_get_disable_wafer_version_major() ? "(constraint ignored)" : "");
unsigned revision = efuse_hal_chip_revision();
ESP_EARLY_LOGI(TAG, "Chip rev: v%d.%d", revision / 100, revision % 100);
}
return ESP_OK;
}

#ifdef CONFIG_EFUSE_VIRTUAL
static void init_efuse_virtual(void)
{
ESP_LOGW(TAG, "eFuse virtual mode is enabled. If Secure boot or Flash encryption is enabled then it does not provide any security. FOR TESTING ONLY!");
#ifdef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
// For efuse virtual mode we need to seed virtual efuses from flash
// esp_flash must be initialized in advance because here we read the efuse partition.
const esp_partition_t *efuse_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_EFUSE_EM, NULL);
if (efuse_partition) {
esp_efuse_init_virtual_mode_in_flash(efuse_partition->address, efuse_partition->size);
}
#else // !CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
// For efuse virtual mode we need to seed virtual efuses from efuse_regs.
esp_efuse_utility_update_virt_blocks();
#endif // !CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
}
#endif // CONFIG_EFUSE_VIRTUAL

static esp_err_t init_efuse_secure(void)
{
#if CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK
// For anti-rollback case, recheck security version before we boot-up the current application
const esp_app_desc_t *desc = esp_app_get_description();
ESP_RETURN_ON_FALSE(esp_efuse_check_secure_version(desc->secure_version), ESP_FAIL, TAG, "Incorrect secure version of app");
#endif

#ifdef CONFIG_SECURE_FLASH_ENC_ENABLED
esp_flash_encryption_init_checks();
#endif

#if defined(CONFIG_SECURE_BOOT) || defined(CONFIG_SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT)
// Note: in some configs this may read flash, so placed after flash init
esp_secure_boot_init_checks();
#endif

#if SOC_EFUSE_ECDSA_USE_HARDWARE_K
if (esp_efuse_find_purpose(ESP_EFUSE_KEY_PURPOSE_ECDSA_KEY, NULL)) {
// ECDSA key purpose block is present and hence permanently enable
// the hardware TRNG supplied k mode (most secure mode)
ESP_RETURN_ON_ERROR(esp_efuse_write_field_bit(ESP_EFUSE_ECDSA_FORCE_USE_HARDWARE_K), TAG, "Failed to enable hardware k mode");
}
#endif

#if CONFIG_SECURE_DISABLE_ROM_DL_MODE
// Permanently disable ROM download mode
ESP_RETURN_ON_ERROR(esp_efuse_disable_rom_download_mode(), TAG, "Failed to disable ROM download mode");
#endif

#if CONFIG_SECURE_ENABLE_SECURE_ROM_DL_MODE
// Permanently disable ROM secure download mode
ESP_RETURN_ON_ERROR(esp_efuse_enable_rom_secure_download_mode(), TAG, "Failed to enable Secure Download mode");
#endif

#if CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE
// ESP32 only: Permanently disable BASIC ROM Console feature
esp_efuse_disable_basic_rom_console();
#endif
return ESP_OK;
}

// Set efuse ROM_LOG_MODE on first boot
// For CONFIG_BOOT_ROM_LOG_ALWAYS_ON (default) or undefined (ESP32), leave
// ROM_LOG_MODE undefined (no need to call this function during startup)
#if CONFIG_BOOT_ROM_LOG_ALWAYS_OFF
#define ROM_LOG_MODE ESP_EFUSE_ROM_LOG_ALWAYS_OFF
#elif CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW
#define ROM_LOG_MODE ESP_EFUSE_ROM_LOG_ON_GPIO_LOW
#elif CONFIG_BOOT_ROM_LOG_ON_GPIO_HIGH
#define ROM_LOG_MODE ESP_EFUSE_ROM_LOG_ON_GPIO_HIGH
#endif

#ifdef ROM_LOG_MODE
static esp_err_t init_efuse_rom_log(void)
{
// Applicable for any chips except ESP32: Permanently disable ROM startup logs
if (ets_efuse_get_uart_print_control() != ROM_LOG_MODE) {
esp_err_t error = esp_efuse_set_rom_log_scheme(ROM_LOG_MODE);
error = (error == ESP_ERR_NOT_SUPPORTED) ? ESP_OK : error;
ESP_RETURN_ON_ERROR(error, TAG, "Failed to set ROM log scheme");
}
return ESP_OK;
}
#endif // ROM_LOG_MODE

ESP_SYSTEM_INIT_FN(init_efuse, CORE, BIT(0), 140)
{
esp_err_t error = ESP_OK;

#ifdef CONFIG_EFUSE_VIRTUAL
init_efuse_virtual();
#endif

error = init_efuse_secure();
ESP_RETURN_ON_ERROR(error, TAG, "Failed in secure eFuse init");

#ifdef ROM_LOG_MODE
error = init_efuse_rom_log();
#endif

return error;
}

void esp_efuse_startup_include_func(void)
{
// Hook to force the linker to include this file
}
10 changes: 1 addition & 9 deletions components/efuse/src/esp_efuse_utility.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -23,14 +23,6 @@ static volatile unsigned s_burn_counter = 0;
// Array for emulate efuse registers.
#ifdef CONFIG_EFUSE_VIRTUAL
uint32_t virt_blocks[EFUSE_BLK_MAX][COUNT_EFUSE_REG_PER_BLOCK];

#ifndef BOOTLOADER_BUILD
#ifndef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
/* Call the update function to seed virtual efuses during initialization */
__attribute__((constructor)) void esp_efuse_utility_update_virt_blocks(void);
#endif // CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
#endif // NOT BOOTLOADER_BUILD

#endif // CONFIG_EFUSE_VIRTUAL

extern const esp_efuse_range_addr_t range_read_addr_blocks[];
Expand Down
Empty file.
8 changes: 0 additions & 8 deletions components/esp_app_format/esp_app_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "esp_app_desc.h"
#include "sdkconfig.h"

#include "hal/efuse_hal.h"
#include "esp_log.h"
#include "esp_private/startup_internal.h"

Expand Down Expand Up @@ -125,13 +124,6 @@ ESP_SYSTEM_INIT_FN(init_show_app_info, CORE, BIT(0), 20)
esp_app_get_elf_sha256(buf, sizeof(buf));
ESP_EARLY_LOGI(TAG, "ELF file SHA256: %s...", buf);
ESP_EARLY_LOGI(TAG, "ESP-IDF: %s", esp_app_desc.idf_ver);

// TODO: To be moved to the eFuse initialization routine
ESP_EARLY_LOGI(TAG, "Min chip rev: v%d.%d", CONFIG_ESP_REV_MIN_FULL / 100, CONFIG_ESP_REV_MIN_FULL % 100);
ESP_EARLY_LOGI(TAG, "Max chip rev: v%d.%d %s", CONFIG_ESP_REV_MAX_FULL / 100, CONFIG_ESP_REV_MAX_FULL % 100,
efuse_hal_get_disable_wafer_version_major() ? "(constraint ignored)" : "");
unsigned revision = efuse_hal_chip_revision();
ESP_EARLY_LOGI(TAG, "Chip rev: v%d.%d", revision / 100, revision % 100);
}
return ESP_OK;
}
3 changes: 3 additions & 0 deletions components/esp_driver_tsens/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ set(priv_req efuse)
set(public_include "include")
if(CONFIG_SOC_TEMP_SENSOR_SUPPORTED)
list(APPEND srcs "src/temperature_sensor.c")
if(CONFIG_SOC_TEMPERATURE_SENSOR_SUPPORT_ETM)
list(APPEND srcs "src/temperature_sensor_etm.c")
endif()
endif()

idf_component_register(SRCS ${srcs}
Expand Down
Loading

0 comments on commit a5829cf

Please sign in to comment.