1 /* 2 * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #pragma once 7 8 #include <stdint.h> 9 #include <esp_err.h> 10 #include "spi_flash_mmap.h" /* including in bootloader for error values */ 11 #include "esp_private/spi_flash_os.h" 12 #include "sdkconfig.h" 13 #include "soc/soc_caps.h" 14 #include "bootloader_flash_override.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /** 21 * @brief Read flash ID by sending RDID command (0x9F) 22 * @return flash raw ID 23 * mfg_id = (ID >> 16) & 0xFF; 24 flash_id = ID & 0xffff; 25 */ 26 uint32_t bootloader_read_flash_id(void); 27 28 /** 29 * @brief Startup flow recommended by XMC. Call at startup before any erase/write operation. 30 * 31 * @return ESP_OK When startup successfully, otherwise ESP_FAIL (indiciating you should reboot before erase/write). 32 */ 33 esp_err_t bootloader_flash_xmc_startup(void); 34 35 /** 36 * @brief Unlock Flash write protect. 37 * Please do not call this function in SDK. 38 * 39 * @note This can be overridden because it's attribute weak. 40 */ 41 esp_err_t __attribute__((weak)) bootloader_flash_unlock(void); 42 43 /** 44 * @brief Reset the flash chip (66H + 99H). 45 * 46 * @return ESP_OK if success, otherwise ESP_FAIL. 47 */ 48 esp_err_t bootloader_flash_reset_chip(void); 49 50 /** 51 * @brief Check if octal flash mode is enabled in eFuse 52 * 53 * @return True if flash is in octal mode, false else 54 */ 55 bool bootloader_flash_is_octal_mode_enabled(void); 56 57 /** 58 * @brief Get the spi flash working mode. 59 * 60 * @return The mode of flash working mode, see `esp_rom_spiflash_read_mode_t` 61 */ 62 esp_rom_spiflash_read_mode_t bootloader_flash_get_spi_mode(void); 63 64 #ifdef __cplusplus 65 } 66 #endif 67