feat(spi_flash): Adds esp_flash_set_dangerous_write_protection

This commit is contained in:
Konstantin Kondrashov
2024-08-14 10:40:05 +03:00
parent 02d61c1c5a
commit 0d4787fb3a
2 changed files with 39 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -95,7 +95,27 @@ esp_err_t esp_flash_app_enable_os_functions(esp_flash_t* chip);
*/
esp_err_t esp_flash_app_disable_os_functions(esp_flash_t* chip);
/**
* @brief Set or clear dangerous write protection check on the flash chip.
*
* This function sets the runtime option to allow or disallow writing to
* dangerous areas such as the bootloader and partition table. If
* CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set, this function allows
* the caller to toggle the protection for specific areas.
*
* If CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is set, there is no protection
* check in the system, and this function does nothing.
*
* @param chip The flash chip on which to set the write protection. Only
* "esp_flash_default_chip" is supported.
* @param protect Set to true to enable protection against writing in dangerous
* areas (bootloader, partition table). Set to false to disable
* the protection.
* @return
* - ESP_OK: Successful operation.
* - ESP_ERR_INVALID_ARG: The chip argument is null.
*/
esp_err_t esp_flash_set_dangerous_write_protection(esp_flash_t *chip, const bool protect);
#ifdef __cplusplus
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -350,6 +350,22 @@ esp_err_t esp_flash_app_enable_os_functions(esp_flash_t* chip)
return ESP_OK;
}
esp_err_t esp_flash_set_dangerous_write_protection(esp_flash_t *chip, const bool protect)
{
#if !CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED
if (chip == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (chip->os_func_data != NULL) {
((app_func_arg_t*)chip->os_func_data)->no_protect = !protect;
}
#else
(void)chip;
(void)protect;
#endif
return ESP_OK;
}
// The goal of this part is to manually insert one valid task execution interval, if the time since
// last valid interval exceed the limitation (CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS).
//