From 2cacb0bd56f44cf5230499c9c56b1c46bc62f948 Mon Sep 17 00:00:00 2001 From: armando Date: Tue, 2 Jun 2026 11:13:54 +0800 Subject: [PATCH] change(flash): deprecate bootloader_flash_priv.h --- .../test_app_update/main/test_switch_ota.c | 2 +- .../test_app_update/main/utils_update.c | 2 +- .../include/bootloader_flash_override.h | 22 ++- .../esp_private/bootloader_flash_internal.h | 149 +++++++++++++++++- .../src/bootloader_flash_config_esp32.c | 3 +- .../src/bootloader_flash_config_esp32c2.c | 3 +- .../src/bootloader_flash_config_esp32c3.c | 3 +- .../src/bootloader_flash_config_esp32c5.c | 3 +- .../src/bootloader_flash_config_esp32c6.c | 3 +- .../src/bootloader_flash_config_esp32c61.c | 3 +- .../src/bootloader_flash_config_esp32h2.c | 3 +- .../src/bootloader_flash_config_esp32h21.c | 3 +- .../src/bootloader_flash_config_esp32h4.c | 3 +- .../src/bootloader_flash_config_esp32p4.c | 3 +- .../src/bootloader_flash_config_esp32s2.c | 3 +- .../src/bootloader_flash_config_esp32s31.c | 3 +- .../bootloader_flash/src/flash_qio_mode.c | 3 +- .../src/bootloader_common.c | 2 +- .../bootloader_support/src/bootloader_init.c | 2 +- .../src/bootloader_utility_tee.c | 2 +- .../src/esp32/bootloader_esp32.c | 1 - .../src/esp32c2/bootloader_esp32c2.c | 2 +- .../src/esp32c3/bootloader_esp32c3.c | 1 - .../src/esp32c5/bootloader_esp32c5.c | 2 +- .../src/esp32c6/bootloader_esp32c6.c | 2 +- .../src/esp32c61/bootloader_esp32c61.c | 2 +- .../src/esp32h2/bootloader_esp32h2.c | 2 +- .../src/esp32h21/bootloader_esp32h21.c | 2 +- .../src/esp32h4/bootloader_esp32h4.c | 2 +- .../src/esp32p4/bootloader_esp32p4.c | 2 +- .../src/esp32s2/bootloader_esp32s2.c | 1 - .../src/esp32s3/bootloader_esp32s3.c | 2 +- .../src/esp32s31/bootloader_esp32s31.c | 2 +- .../src/flash_encryption/flash_encrypt.c | 2 +- components/efuse/src/esp_efuse_utility.c | 2 +- .../src/bootloader_sha_flash.c | 4 +- .../src/secure_boot_v1/secure_boot.c | 2 +- .../secure_boot_signatures_app.c | 2 +- .../secure_boot_signatures_bootloader.c | 2 +- .../src/secure_boot_v2/secure_boot.c | 2 +- .../secure_boot_signatures_app.c | 2 +- .../secure_boot_signatures_bootloader.c | 2 +- components/esp_mspi/spi_flash_hpm_enable.c | 2 - .../attestation/esp_att_utils_part_info.c | 2 +- .../tee_flash_mgr/include/esp_tee_flash.h | 2 +- .../release-6.x/6.1/peripherals.rst | 10 ++ .../release-6.x/6.1/peripherals.rst | 10 ++ .../main/bootloader_start.c | 1 - .../bootloader_flash_qio_custom.c | 1 - 49 files changed, 241 insertions(+), 50 deletions(-) diff --git a/components/app_update/test_apps/test_app_update/main/test_switch_ota.c b/components/app_update/test_apps/test_app_update/main/test_switch_ota.c index f2150c1ae8b..4ab6fb983f7 100644 --- a/components/app_update/test_apps/test_app_update/main/test_switch_ota.c +++ b/components/app_update/test_apps/test_app_update/main/test_switch_ota.c @@ -9,7 +9,7 @@ #include "esp_system.h" #include "bootloader_common.h" -#include "../bootloader_flash/include/bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "esp_log.h" #include "esp_ota_ops.h" #include "unity.h" diff --git a/components/app_update/test_apps/test_app_update/main/utils_update.c b/components/app_update/test_apps/test_app_update/main/utils_update.c index 8171258389c..b4e0bae4cfa 100644 --- a/components/app_update/test_apps/test_app_update/main/utils_update.c +++ b/components/app_update/test_apps/test_app_update/main/utils_update.c @@ -10,7 +10,7 @@ #include "esp_partition.h" #include "esp_flash_partitions.h" #include "esp_image_format.h" -#include "../bootloader_flash/include/bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "esp_sleep.h" #include "esp_ota_ops.h" #include "esp_err.h" diff --git a/components/bootloader_support/bootloader_flash/include/bootloader_flash_override.h b/components/bootloader_support/bootloader_flash/include/bootloader_flash_override.h index 75caf28bae3..ade007b77cc 100644 --- a/components/bootloader_support/bootloader_flash/include/bootloader_flash_override.h +++ b/components/bootloader_support/bootloader_flash/include/bootloader_flash_override.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -16,6 +16,26 @@ extern "C" { typedef unsigned (*bootloader_flash_read_status_fn_t)(void); typedef void (*bootloader_flash_write_status_fn_t)(unsigned); +/** + * @brief Execute a user command on the flash + * + * @param command The command value to execute. + * @param mosi_data MOSI data to send + * @param mosi_len Length of MOSI data, in bits + * @param miso_len Length of MISO data to receive, in bits + * @return Received MISO data + */ +uint32_t bootloader_execute_flash_command(uint8_t command, uint32_t mosi_data, uint8_t mosi_len, uint8_t miso_len); + +/** + * @brief Read the SFDP of the flash + * + * @param sfdp_addr Address of the parameter to read + * @param miso_byte_num Bytes to read + * @return The read SFDP, little endian, 4 bytes at most + */ +uint32_t bootloader_flash_read_sfdp(uint32_t sfdp_addr, unsigned int miso_byte_num); + typedef struct __attribute__((packed)) { const char *manufacturer; diff --git a/components/bootloader_support/bootloader_flash/include/esp_private/bootloader_flash_internal.h b/components/bootloader_support/bootloader_flash/include/esp_private/bootloader_flash_internal.h index f79cefbdbd8..3c337110d0a 100644 --- a/components/bootloader_support/bootloader_flash/include/esp_private/bootloader_flash_internal.h +++ b/components/bootloader_support/bootloader_flash/include/esp_private/bootloader_flash_internal.h @@ -1,17 +1,161 @@ /* - * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #pragma once + #include -#include +#include +#include +#include "esp_err.h" +#include "sdkconfig.h" +#include "bootloader_flash.h" +#include "bootloader_flash_override.h" #include "soc/soc_caps.h" +#include "soc/ext_mem_defs.h" #ifdef __cplusplus extern "C" { #endif +//-------------------------------- Utilities -------------------------------- // +/** + * This file provides a Flash API for bootloader_support code, + * that can be used from bootloader or app code. + * This header is available to source code in the ESP-IDF components only. + */ + +#define FLASH_SECTOR_SIZE 0x1000 +#define FLASH_BLOCK_SIZE 0x10000 + +#define MMAP_ALIGNED_MASK (CONFIG_MMU_PAGE_SIZE - 1) +#define MMU_FLASH_MASK (~(CONFIG_MMU_PAGE_SIZE - 1)) +#define MMU_FLASH_MASK_FROM_VAL(PAGE_SZ) (~((PAGE_SZ) - 1)) +#define MMU_DROM_END_ENTRY_VADDR_FROM_VAL(PAGE_SZ) (SOC_DRAM_FLASH_ADDRESS_HIGH - (PAGE_SZ)) + +/** + * MMU mapping must always be in the unit of a CONFIG_MMU_PAGE_SIZE + * This macro is a helper for you to get needed page nums to be mapped. e.g.: + * Let's say CONFIG_MMU_PAGE_SIZE is 64KB. + * - v_start = 0x4200_0004 + * - size = 4 * 64KB + * + * You should map from 0x4200_0000, then map 5 pages. + */ +#define GET_REQUIRED_MMU_PAGES(size, v_start) ((size + (v_start - (v_start & MMU_FLASH_MASK)) + CONFIG_MMU_PAGE_SIZE - 1) / CONFIG_MMU_PAGE_SIZE) + +/** + * @brief Get number of free pages + * + * @return Number of free pages + */ +uint32_t bootloader_mmap_get_free_pages(void); + +/** + * @brief Map a region of flash to data memory + * + * @important In bootloader code, only one region can be bootloader_mmaped at once. The previous region must be bootloader_munmapped before another region is mapped. + * + * @important In app code, these functions are not thread safe. + * + * Call bootloader_munmap once for each successful call to bootloader_mmap. + * + * In esp-idf app, this function maps directly to spi_flash_mmap with the @ref + * spi_flash_mmap_flag_t::SPI_FLASH_MMAP_FLAG_BLOCKS_WRITE flag set. When XIP on PSRAM (`CONFIG_SPIRAM_XIP_FROM_PSRAM`) enabled, flash erasing/writing + * will be blocked until unmap. + * + * @param offset - Starting flash offset to map to memory. + * @param length - Length of data to map. + * + * @return Pointer to mapped data memory (at src_addr), or NULL + * if an allocation error occurred. + */ +const void *bootloader_mmap(uint32_t src_addr, uint32_t size); + + +/** + * @brief Unmap a previously mapped region of flash + * + * Call bootloader_munmap once for each successful call to bootloader_mmap. + */ +void bootloader_munmap(const void *mapping); + +/** + * @brief Read data from Flash. + * + * + * @note All of src, dest and size have to be 4-byte aligned. + * + * @param src source address of the data in Flash. + * @param dest pointer to the destination buffer + * @param size length of data + * @param allow_decrypt If true and flash encryption is enabled, data on flash + * will be decrypted transparently as part of the read. + * + * @return ESP_OK on success, ESP_ERR_FLASH_OP_FAIL on SPI failure, + * ESP_ERR_FLASH_OP_TIMEOUT on SPI timeout. + */ +esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size, bool allow_decrypt); + + +/** + * @brief Write data to Flash. + * + * @note All of dest_addr, src and size have to be 4-byte aligned. If write_encrypted is set, dest_addr and size must be 32-byte aligned. + * + * @note In bootloader, when write_encrypted == true, the src buffer is encrypted in place. + * + * @note [ESP-TEE] Using this API from the TEE will return an error if the dest_addr lies + * within the active TEE partition range. + * + * @param dest_addr Destination address to write in Flash. + * @param src Pointer to the data to write to flash + * @param size Length of data in bytes. + * @param write_encrypted If true, data will be written encrypted on flash. + * + * @return ESP_OK on success, ESP_ERR_FLASH_OP_FAIL on SPI failure, + * ESP_ERR_FLASH_OP_TIMEOUT on SPI timeout. + */ +esp_err_t bootloader_flash_write(size_t dest_addr, void *src, size_t size, bool write_encrypted); + +/** + * @brief Erase the Flash sector. + * + * @param sector Sector number, the count starts at sector 0, 4KB per sector. + * + * @return esp_err_t + */ +esp_err_t bootloader_flash_erase_sector(size_t sector); + +/** + * @brief Erase the Flash range. + * + * @note [ESP-TEE] Using this API from the TEE will return an error if the start_addr lies + * within the active TEE partition range. + * + * @param start_addr start address of flash offset + * @param size sector aligned size to be erased + * + * @return esp_err_t + */ +esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size); + +/** + * @brief Enable the flash write protect (WEL bit). + */ +void bootloader_enable_wp(void); + +/** + * @brief Once this function is called, + * any on-going internal operations will be terminated and the device will return to its default power-on + * state and lose all the current volatile settings, such as Volatile Status Register bits, Write Enable Latch + * (WEL) status, Program/Erase Suspend status, etc. + */ +void bootloader_spi_flash_reset(void); + +//-------------------------------- Init APIs -------------------------------- // +//For SDK usage only /** * @brief Initialize spi_flash in bootloader and print flash info * @@ -33,6 +177,7 @@ void bootloader_flash_hardware_init(void); */ void bootloader_init_mspi_clock(void); + #ifdef __cplusplus } #endif diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32.c index 35adbdf5df0..5939f984bad 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32.c @@ -25,7 +25,8 @@ #include "flash_qio_mode.h" #include "bootloader_common.h" #include "bootloader_flash_config.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #define FLASH_CLK_IO MSPI_IOMUX_PIN_NUM_CLK diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c2.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c2.c index 309d608a7b7..e0679b1dcd9 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c2.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c2.c @@ -17,7 +17,8 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #include "soc/spi_pins.h" #include "hal/mmu_hal.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c3.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c3.c index 06a70ba2c6c..3a0b23d111b 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c3.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c3.c @@ -19,7 +19,8 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/mmu_ll.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c5.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c5.c index ec604b44585..e226c09f7c4 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c5.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c5.c @@ -22,7 +22,8 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/mmu_ll.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c6.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c6.c index 37dd92f217f..0d315dfcf80 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c6.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c6.c @@ -18,7 +18,8 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/mmu_ll.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c61.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c61.c index 7cc94ec24ab..e9e308fff1a 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c61.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32c61.c @@ -18,7 +18,8 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/mmu_ll.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h2.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h2.c index 55b3c5d9f78..287de75f364 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h2.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h2.c @@ -18,7 +18,8 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/mmu_ll.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h21.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h21.c index 91c737c0694..e36d81a8c00 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h21.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h21.c @@ -12,7 +12,8 @@ #include "esp_rom_gpio.h" #include "flash_qio_mode.h" #include "bootloader_flash_config.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/cache_hal.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h4.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h4.c index 485b75cfef8..3ceb0e87116 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h4.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32h4.c @@ -20,7 +20,8 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/mmu_ll.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32p4.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32p4.c index 7adc3199ae6..0cce8f14964 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32p4.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32p4.c @@ -16,7 +16,7 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/mmu_ll.h" @@ -24,6 +24,7 @@ #include "hal/cache_hal.h" #include "hal/cache_ll.h" #include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" void IRAM_ATTR bootloader_flash_update_id(void) { diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32s2.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32s2.c index 046f42d37a7..25101bbc718 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32s2.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32s2.c @@ -20,7 +20,8 @@ #include "soc/soc_caps.h" #include "flash_qio_mode.h" #include "bootloader_flash_config.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" #include "bootloader_common.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" diff --git a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32s31.c b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32s31.c index f9ac78c2b1a..249d09c66d9 100644 --- a/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32s31.c +++ b/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_esp32s31.c @@ -16,7 +16,7 @@ #include "flash_qio_mode.h" #include "bootloader_flash_config.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_init.h" #include "hal/mmu_hal.h" #include "hal/mmu_ll.h" @@ -25,6 +25,7 @@ #include "hal/cache_ll.h" #include "hal/clk_tree_ll.h" #include "esp_private/bootloader_flash_internal.h" +#include "spi_flash_defs.h" void IRAM_ATTR bootloader_flash_update_id(void) { diff --git a/components/bootloader_support/bootloader_flash/src/flash_qio_mode.c b/components/bootloader_support/bootloader_flash/src/flash_qio_mode.c index 4b0ec90ef6e..d3eed199e49 100644 --- a/components/bootloader_support/bootloader_flash/src/flash_qio_mode.c +++ b/components/bootloader_support/bootloader_flash/src/flash_qio_mode.c @@ -8,7 +8,7 @@ #include "bootloader_flash_config.h" #include "flash_qio_mode.h" #include "sdkconfig.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "esp_log.h" #include "esp_err.h" #include "esp_attr.h" @@ -19,6 +19,7 @@ #include "soc/io_mux_reg.h" #include "esp_private/spi_flash_os.h" #include "bootloader_flash_override.h" +#include "spi_flash_defs.h" ESP_LOG_ATTR_TAG(TAG, "qio_mode"); diff --git a/components/bootloader_support/src/bootloader_common.c b/components/bootloader_support/src/bootloader_common.c index 0c40d39efa4..7fd5f72d4bb 100644 --- a/components/bootloader_support/src/bootloader_common.c +++ b/components/bootloader_support/src/bootloader_common.c @@ -15,7 +15,7 @@ #include "esp_rom_sys.h" #include "esp_flash_partitions.h" #include "esp_image_format.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_common.h" #include "bootloader_utility.h" #include "bootloader_sha_flash.h" diff --git a/components/bootloader_support/src/bootloader_init.c b/components/bootloader_support/src/bootloader_init.c index 610d0cf2540..2090359d386 100644 --- a/components/bootloader_support/src/bootloader_init.c +++ b/components/bootloader_support/src/bootloader_init.c @@ -9,7 +9,7 @@ #include "esp_attr.h" #include "esp_log.h" #include "bootloader_init.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_flash_config.h" #include "bootloader_random.h" #include "bootloader_clock.h" diff --git a/components/bootloader_support/src/bootloader_utility_tee.c b/components/bootloader_support/src/bootloader_utility_tee.c index 8a22f01978f..b9eee7d95d8 100644 --- a/components/bootloader_support/src/bootloader_utility_tee.c +++ b/components/bootloader_support/src/bootloader_utility_tee.c @@ -16,7 +16,7 @@ #include "esp_image_format.h" #include "bootloader_config.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_utility.h" #include "bootloader_utility_tee.h" diff --git a/components/bootloader_support/src/esp32/bootloader_esp32.c b/components/bootloader_support/src/esp32/bootloader_esp32.c index af973a33f69..8dc6b9439e0 100644 --- a/components/bootloader_support/src/esp32/bootloader_esp32.c +++ b/components/bootloader_support/src/esp32/bootloader_esp32.c @@ -16,7 +16,6 @@ #include "bootloader_flash_config.h" #include "bootloader_mem.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_cpu.h" #include "soc/dport_reg.h" diff --git a/components/bootloader_support/src/esp32c2/bootloader_esp32c2.c b/components/bootloader_support/src/esp32c2/bootloader_esp32c2.c index 8ab40e7ddd0..fd5fa10cf51 100644 --- a/components/bootloader_support/src/esp32c2/bootloader_esp32c2.c +++ b/components/bootloader_support/src/esp32c2/bootloader_esp32c2.c @@ -30,7 +30,7 @@ #include "bootloader_flash_config.h" #include "bootloader_mem.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c b/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c index d13a9102751..25d68a8f3a6 100644 --- a/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c +++ b/components/bootloader_support/src/esp32c3/bootloader_esp32c3.c @@ -34,7 +34,6 @@ #include "soc/regi2c_lp_bias.h" #include "soc/regi2c_bias.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" #include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32c5/bootloader_esp32c5.c b/components/bootloader_support/src/esp32c5/bootloader_esp32c5.c index b8b53a851aa..dceab82df5a 100644 --- a/components/bootloader_support/src/esp32c5/bootloader_esp32c5.c +++ b/components/bootloader_support/src/esp32c5/bootloader_esp32c5.c @@ -31,7 +31,7 @@ #include "bootloader_mem.h" #include "esp_private/regi2c_ctrl.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32c6/bootloader_esp32c6.c b/components/bootloader_support/src/esp32c6/bootloader_esp32c6.c index 71007a966d6..c08ecaed593 100644 --- a/components/bootloader_support/src/esp32c6/bootloader_esp32c6.c +++ b/components/bootloader_support/src/esp32c6/bootloader_esp32c6.c @@ -33,7 +33,7 @@ #include "soc/regi2c_lp_bias.h" #include "soc/regi2c_bias.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32c61/bootloader_esp32c61.c b/components/bootloader_support/src/esp32c61/bootloader_esp32c61.c index a7d81d59041..6e6de3a89c6 100644 --- a/components/bootloader_support/src/esp32c61/bootloader_esp32c61.c +++ b/components/bootloader_support/src/esp32c61/bootloader_esp32c61.c @@ -33,7 +33,7 @@ #include "soc/regi2c_lp_bias.h" #include "soc/regi2c_bias.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32h2/bootloader_esp32h2.c b/components/bootloader_support/src/esp32h2/bootloader_esp32h2.c index e58dbe10f29..b0a080b7965 100644 --- a/components/bootloader_support/src/esp32h2/bootloader_esp32h2.c +++ b/components/bootloader_support/src/esp32h2/bootloader_esp32h2.c @@ -32,7 +32,7 @@ #include "soc/regi2c_lp_bias.h" #include "soc/regi2c_bias.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32h21/bootloader_esp32h21.c b/components/bootloader_support/src/esp32h21/bootloader_esp32h21.c index a1e8dad905b..93e10a88657 100644 --- a/components/bootloader_support/src/esp32h21/bootloader_esp32h21.c +++ b/components/bootloader_support/src/esp32h21/bootloader_esp32h21.c @@ -32,7 +32,7 @@ #include "soc/regi2c_lp_bias.h" #include "soc/regi2c_bias.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32h4/bootloader_esp32h4.c b/components/bootloader_support/src/esp32h4/bootloader_esp32h4.c index e4fa4c0d6dd..30d26b1bdd1 100644 --- a/components/bootloader_support/src/esp32h4/bootloader_esp32h4.c +++ b/components/bootloader_support/src/esp32h4/bootloader_esp32h4.c @@ -30,7 +30,7 @@ #include "esp_private/regi2c_ctrl.h" #include "soc/hp_system_reg.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32p4/bootloader_esp32p4.c b/components/bootloader_support/src/esp32p4/bootloader_esp32p4.c index e5c17522ee5..98ed4397afe 100644 --- a/components/bootloader_support/src/esp32p4/bootloader_esp32p4.c +++ b/components/bootloader_support/src/esp32p4/bootloader_esp32p4.c @@ -33,7 +33,7 @@ #include "soc/regi2c_lp_bias.h" #include "soc/regi2c_bias.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c b/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c index b18965768bc..43ea21c1e7d 100644 --- a/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c +++ b/components/bootloader_support/src/esp32s2/bootloader_esp32s2.c @@ -16,7 +16,6 @@ #include "bootloader_flash_config.h" #include "bootloader_mem.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_rom_gpio.h" #include "esp_rom_efuse.h" diff --git a/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c b/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c index de6ff9cfdca..9fada00243a 100644 --- a/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c +++ b/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c @@ -33,7 +33,7 @@ #include "bootloader_flash_config.h" #include "bootloader_mem.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_private/bootloader_flash_internal.h" #include "esp_efuse.h" diff --git a/components/bootloader_support/src/esp32s31/bootloader_esp32s31.c b/components/bootloader_support/src/esp32s31/bootloader_esp32s31.c index 12cc192fb72..99a43e3c5f1 100644 --- a/components/bootloader_support/src/esp32s31/bootloader_esp32s31.c +++ b/components/bootloader_support/src/esp32s31/bootloader_esp32s31.c @@ -16,7 +16,7 @@ #include "bootloader_flash_config.h" #include "bootloader_mem.h" #include "bootloader_console.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_soc.h" #include "esp_efuse.h" #include "esp_private/bootloader_flash_internal.h" diff --git a/components/bootloader_support/src/flash_encryption/flash_encrypt.c b/components/bootloader_support/src/flash_encryption/flash_encrypt.c index 6fcd8987818..670b90ee92c 100644 --- a/components/bootloader_support/src/flash_encryption/flash_encrypt.c +++ b/components/bootloader_support/src/flash_encryption/flash_encrypt.c @@ -5,7 +5,7 @@ */ #include -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_random.h" #include "esp_image_format.h" #include "esp_flash_encrypt.h" diff --git a/components/efuse/src/esp_efuse_utility.c b/components/efuse/src/esp_efuse_utility.c index d2f5cf17bc1..9dde930319f 100644 --- a/components/efuse/src/esp_efuse_utility.c +++ b/components/efuse/src/esp_efuse_utility.c @@ -390,7 +390,7 @@ void esp_efuse_init_virtual_mode_in_ram(void) #ifdef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH -#include "../bootloader_flash/include/bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" static uint32_t esp_efuse_flash_offset = 0; static uint32_t esp_efuse_flash_size = 0; diff --git a/components/esp_image_verify/src/bootloader_sha_flash.c b/components/esp_image_verify/src/bootloader_sha_flash.c index f515e018919..07427f2d22d 100644 --- a/components/esp_image_verify/src/bootloader_sha_flash.c +++ b/components/esp_image_verify/src/bootloader_sha_flash.c @@ -5,7 +5,7 @@ */ #include #include "esp_log.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_sha.h" #include "bootloader_sha_flash.h" #include "spi_flash_mmap.h" @@ -57,7 +57,7 @@ static esp_err_t bootloader_sha_flash_contents(esp_sha_type type, uint32_t flash return ESP_ERR_NO_MEM; } uint32_t max_image_len; - if (__builtin_mul_overflow(max_pages, SPI_FLASH_MMU_PAGE_SIZE, &max_image_len)) { + if (__builtin_mul_overflow(max_pages, CONFIG_MMU_PAGE_SIZE, &max_image_len)) { max_image_len = UINT32_MAX; } uint32_t partial_image_len = MIN(len, max_image_len); /* Read the image that fits in the free MMU pages */ diff --git a/components/esp_image_verify/src/secure_boot_v1/secure_boot.c b/components/esp_image_verify/src/secure_boot_v1/secure_boot.c index a509df859ee..46491c448e3 100644 --- a/components/esp_image_verify/src/secure_boot_v1/secure_boot.c +++ b/components/esp_image_verify/src/secure_boot_v1/secure_boot.c @@ -17,7 +17,7 @@ #include "sdkconfig.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_random.h" #include "esp_image_format.h" #include "esp_secure_boot.h" diff --git a/components/esp_image_verify/src/secure_boot_v1/secure_boot_signatures_app.c b/components/esp_image_verify/src/secure_boot_v1/secure_boot_signatures_app.c index 8f713c88bd5..0cdcbbdcdc3 100644 --- a/components/esp_image_verify/src/secure_boot_v1/secure_boot_signatures_app.c +++ b/components/esp_image_verify/src/secure_boot_v1/secure_boot_signatures_app.c @@ -5,7 +5,7 @@ */ #include "sdkconfig.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_sha.h" #include "bootloader_sha_flash.h" #include "esp_log.h" diff --git a/components/esp_image_verify/src/secure_boot_v1/secure_boot_signatures_bootloader.c b/components/esp_image_verify/src/secure_boot_v1/secure_boot_signatures_bootloader.c index 3c9f2a42abf..3dca1162ac3 100644 --- a/components/esp_image_verify/src/secure_boot_v1/secure_boot_signatures_bootloader.c +++ b/components/esp_image_verify/src/secure_boot_v1/secure_boot_signatures_bootloader.c @@ -5,7 +5,7 @@ */ #include "sdkconfig.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_sha.h" #include "bootloader_sha_flash.h" #include "esp_log.h" diff --git a/components/esp_image_verify/src/secure_boot_v2/secure_boot.c b/components/esp_image_verify/src/secure_boot_v2/secure_boot.c index b585ddecaff..3e38b6bed22 100644 --- a/components/esp_image_verify/src/secure_boot_v2/secure_boot.c +++ b/components/esp_image_verify/src/secure_boot_v2/secure_boot.c @@ -8,7 +8,7 @@ #include "sdkconfig.h" #include "esp_log.h" #include "esp_secure_boot.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_sha.h" #include "bootloader_sha_flash.h" #include "esp_image_format.h" diff --git a/components/esp_image_verify/src/secure_boot_v2/secure_boot_signatures_app.c b/components/esp_image_verify/src/secure_boot_v2/secure_boot_signatures_app.c index 677ec78b39c..d6b4241973a 100644 --- a/components/esp_image_verify/src/secure_boot_v2/secure_boot_signatures_app.c +++ b/components/esp_image_verify/src/secure_boot_v2/secure_boot_signatures_app.c @@ -5,7 +5,7 @@ */ #include "sdkconfig.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_sha.h" #include "bootloader_sha_flash.h" #include "bootloader_signature.h" diff --git a/components/esp_image_verify/src/secure_boot_v2/secure_boot_signatures_bootloader.c b/components/esp_image_verify/src/secure_boot_v2/secure_boot_signatures_bootloader.c index 50f61a5fcfb..cd30e9da3d2 100644 --- a/components/esp_image_verify/src/secure_boot_v2/secure_boot_signatures_bootloader.c +++ b/components/esp_image_verify/src/secure_boot_v2/secure_boot_signatures_bootloader.c @@ -7,7 +7,7 @@ #include #include "esp_fault.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "bootloader_sha.h" #include "bootloader_sha_flash.h" #include "bootloader_signature.h" diff --git a/components/esp_mspi/spi_flash_hpm_enable.c b/components/esp_mspi/spi_flash_hpm_enable.c index 071661a04db..d25d2f4bb95 100644 --- a/components/esp_mspi/spi_flash_hpm_enable.c +++ b/components/esp_mspi/spi_flash_hpm_enable.c @@ -65,8 +65,6 @@ extern uint32_t bootloader_flash_execute_command_common( uint8_t mosi_len, uint32_t mosi_data, uint8_t miso_len); -extern uint32_t IRAM_ATTR bootloader_flash_read_sfdp(uint32_t sfdp_addr, unsigned int miso_byte_num); - //-----------------For flash chips which enter HPM via command-----------------------// /** diff --git a/components/esp_tee/subproject/components/attestation/esp_att_utils_part_info.c b/components/esp_tee/subproject/components/attestation/esp_att_utils_part_info.c index dbe4b639896..e39a92c7d47 100644 --- a/components/esp_tee/subproject/components/attestation/esp_att_utils_part_info.c +++ b/components/esp_tee/subproject/components/attestation/esp_att_utils_part_info.c @@ -39,7 +39,7 @@ #endif #define DECLARE_PRIVATE_IDENTIFIERS #include "psa/crypto.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "esp_attestation_utils.h" #include "esp_macros.h" diff --git a/components/esp_tee/subproject/components/tee_flash_mgr/include/esp_tee_flash.h b/components/esp_tee/subproject/components/tee_flash_mgr/include/esp_tee_flash.h index 379818c0a6f..e32ec09e347 100644 --- a/components/esp_tee/subproject/components/tee_flash_mgr/include/esp_tee_flash.h +++ b/components/esp_tee/subproject/components/tee_flash_mgr/include/esp_tee_flash.h @@ -9,7 +9,7 @@ #include "esp_err.h" -#include "bootloader_flash_priv.h" +#include "esp_private/bootloader_flash_internal.h" #include "esp_flash_partitions.h" #include "esp_image_format.h" diff --git a/docs/en/migration-guides/release-6.x/6.1/peripherals.rst b/docs/en/migration-guides/release-6.x/6.1/peripherals.rst index b9fab2807aa..ef43d709d3c 100644 --- a/docs/en/migration-guides/release-6.x/6.1/peripherals.rst +++ b/docs/en/migration-guides/release-6.x/6.1/peripherals.rst @@ -9,6 +9,16 @@ LCD - The :cpp:member:`esp_lcd_dpi_panel_event_callbacks_t::on_refresh_done` callback has been deprecated. Please use :cpp:member:`esp_lcd_dpi_panel_event_callbacks_t::on_frame_buf_complete` to know when a frame buffer can be safely reused. - The VSYNC timing event for the MIPI DSI DPI panel is now reported by :cpp:member:`esp_lcd_dpi_panel_event_callbacks_t::on_vsync`. +SPI Flash +--------- + +- ``bootloader_flash_priv.h`` header file is deprecated. Its contents have been split into two headers: + + - ``bootloader_flash_override.h`` for the utility APIs intended for custom flash chip support, such as ``bootloader_execute_flash_command``, ``bootloader_flash_read_sfdp``, and the status register read/write helpers. This header is not considered a stable API, but it remains available to applications and custom bootloader components. + - ``esp_private/bootloader_flash_internal.h`` for the APIs that are internal to ESP-IDF, such as ``bootloader_mmap``, ``bootloader_munmap``, and ``bootloader_flash_read``. These may change without notice. + + The deprecated ``bootloader_flash_priv.h`` still includes both headers, so existing code keeps compiling until the header is removed. + UART ----- diff --git a/docs/zh_CN/migration-guides/release-6.x/6.1/peripherals.rst b/docs/zh_CN/migration-guides/release-6.x/6.1/peripherals.rst index a844504c89d..a39fbb80b36 100644 --- a/docs/zh_CN/migration-guides/release-6.x/6.1/peripherals.rst +++ b/docs/zh_CN/migration-guides/release-6.x/6.1/peripherals.rst @@ -9,6 +9,16 @@ LCD - :cpp:member:`esp_lcd_dpi_panel_event_callbacks_t::on_refresh_done` 回调已废弃。请使用 :cpp:member:`esp_lcd_dpi_panel_event_callbacks_t::on_frame_buf_complete` 判断帧缓冲区何时可以被安全复用。 - MIPI DSI DPI 面板的 VSYNC 时序事件现在通过 :cpp:member:`esp_lcd_dpi_panel_event_callbacks_t::on_vsync` 回调上报。 +SPI Flash +--------- + +- ``bootloader_flash_priv.h`` 头文件已废弃,其内容已拆分到两个头文件中: + + - ``bootloader_flash_override.h``:面向自定义 flash 芯片支持的工具类 API,例如 ``bootloader_execute_flash_command``、``bootloader_flash_read_sfdp`` 以及状态寄存器读写辅助函数。该头文件不被视为稳定 API,但应用程序和自定义 bootloader 组件仍可使用。 + - ``esp_private/bootloader_flash_internal.h``:ESP-IDF 内部使用的 API,例如 ``bootloader_mmap``、``bootloader_munmap`` 和 ``bootloader_flash_read``,这些 API 可能在不另行通知的情况下发生变更。 + + 已废弃的 ``bootloader_flash_priv.h`` 仍会包含上述两个头文件,因此在该头文件被移除之前,现有代码可以继续正常编译。 + UART ------ diff --git a/examples/custom_bootloader/bootloader_multiboot/bootloader_components/main/bootloader_start.c b/examples/custom_bootloader/bootloader_multiboot/bootloader_components/main/bootloader_start.c index 28314e763f3..9eaf0489f8b 100644 --- a/examples/custom_bootloader/bootloader_multiboot/bootloader_components/main/bootloader_start.c +++ b/examples/custom_bootloader/bootloader_multiboot/bootloader_components/main/bootloader_start.c @@ -11,7 +11,6 @@ #include "bootloader_init.h" #include "bootloader_utility.h" #include "bootloader_common.h" -#include "bootloader_flash_priv.h" #include "esp_app_desc.h" #define MAX_PARTITIONS 8 diff --git a/examples/storage/custom_flash_driver/bootloader_components/bootloader_flash/bootloader_flash_qio_custom.c b/examples/storage/custom_flash_driver/bootloader_components/bootloader_flash/bootloader_flash_qio_custom.c index 9c572a20f59..b3835968f5f 100644 --- a/examples/storage/custom_flash_driver/bootloader_components/bootloader_flash/bootloader_flash_qio_custom.c +++ b/examples/storage/custom_flash_driver/bootloader_components/bootloader_flash/bootloader_flash_qio_custom.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ #include "bootloader_flash_override.h" -#include "bootloader_flash_priv.h" #include "bootloader_flash_custom.h" #include "esp_rom_spiflash.h" #include "esp_attr.h"