1 // Copyright 2018 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include "sdkconfig.h" 18 #include "esp_image_format.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /** 25 * @brief Update the flash id in g_rom_flashchip(global esp_rom_spiflash_chip_t structure). 26 * 27 * @return None 28 */ 29 void bootloader_flash_update_id(void); 30 31 /** 32 * @brief Update the flash size in g_rom_flashchip (global esp_rom_spiflash_chip_t structure). 33 * 34 * @param size The size to store, in bytes. 35 * @return None 36 */ 37 void bootloader_flash_update_size(uint32_t size); 38 39 /** 40 * @brief Set the flash CS setup and hold time. 41 * 42 * @note CS setup time is recomemded to be 1.5T, and CS hold time is recommended to be 2.5T. 43 * cs_setup = 1, cs_setup_time = 0; cs_hold = 1, cs_hold_time = 1. 44 * 45 * @return None 46 */ 47 void bootloader_flash_cs_timing_config(void); 48 49 /** 50 * @brief Configure SPI flash clock. 51 * 52 * @note This function only set clock frequency for SPI0. 53 * 54 * @param pfhdr Pointer to App image header, from where to fetch flash settings. 55 * 56 * @return None 57 */ 58 void bootloader_flash_clock_config(const esp_image_header_t* pfhdr); 59 60 /** 61 * @brief Configure SPI flash gpio, include the IO matrix and drive strength configuration. 62 * 63 * @param pfhdr Pointer to App image header, from where to fetch flash settings. 64 * 65 * @return None 66 */ 67 void bootloader_flash_gpio_config(const esp_image_header_t* pfhdr); 68 69 /** 70 * @brief Configure SPI flash read dummy based on different mode and frequency. 71 * 72 * @param pfhdr Pointer to App image header, from where to fetch flash settings. 73 * 74 * @return None 75 */ 76 void bootloader_flash_dummy_config(const esp_image_header_t* pfhdr); 77 78 #ifdef CONFIG_IDF_TARGET_ESP32 79 /** 80 * @brief Return the pin number used for custom SPI flash and/or SPIRAM WP pin 81 * 82 * Can be determined by eFuse values in most cases, or overriden in configuration 83 * 84 * This value is only meaningful if the other SPI flash pins are overriden via eFuse. 85 * 86 * This value is only meaningful if flash is set to QIO or QOUT mode, or if 87 * SPIRAM is enabled. 88 * 89 * @return Pin number to use, or -1 if the default should be kept 90 */ 91 int bootloader_flash_get_wp_pin(void); 92 #endif 93 94 #ifdef __cplusplus 95 } 96 #endif 97