File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 11/*
2- * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
@@ -95,7 +95,27 @@ esp_err_t esp_flash_app_enable_os_functions(esp_flash_t* chip);
9595 */
9696esp_err_t esp_flash_app_disable_os_functions (esp_flash_t * chip );
9797
98-
98+ /**
99+ * @brief Set or clear dangerous write protection check on the flash chip.
100+ *
101+ * This function sets the runtime option to allow or disallow writing to
102+ * dangerous areas such as the bootloader and partition table. If
103+ * CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set, this function allows
104+ * the caller to toggle the protection for specific areas.
105+ *
106+ * If CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is set, there is no protection
107+ * check in the system, and this function does nothing.
108+ *
109+ * @param chip The flash chip on which to set the write protection. Only
110+ * "esp_flash_default_chip" is supported.
111+ * @param protect Set to true to enable protection against writing in dangerous
112+ * areas (bootloader, partition table). Set to false to disable
113+ * the protection.
114+ * @return
115+ * - ESP_OK: Successful operation.
116+ * - ESP_ERR_INVALID_ARG: The chip argument is null.
117+ */
118+ esp_err_t esp_flash_set_dangerous_write_protection (esp_flash_t * chip , const bool protect );
99119
100120#ifdef __cplusplus
101121}
Original file line number Diff line number Diff line change 11/*
2- * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
@@ -350,6 +350,22 @@ esp_err_t esp_flash_app_enable_os_functions(esp_flash_t* chip)
350350 return ESP_OK ;
351351}
352352
353+ esp_err_t esp_flash_set_dangerous_write_protection (esp_flash_t * chip , const bool protect )
354+ {
355+ #if !CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED
356+ if (chip == NULL ) {
357+ return ESP_ERR_INVALID_ARG ;
358+ }
359+ if (chip -> os_func_data != NULL ) {
360+ ((app_func_arg_t * )chip -> os_func_data )-> no_protect = !protect ;
361+ }
362+ #else
363+ (void )chip ;
364+ (void )protect ;
365+ #endif
366+ return ESP_OK ;
367+ }
368+
353369// The goal of this part is to manually insert one valid task execution interval, if the time since
354370// last valid interval exceed the limitation (CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS).
355371//
You can’t perform that action at this time.
0 commit comments