1 /*
2  * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include "sdkconfig.h"
10 #include "esp_image_format.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /**
17  * @brief Update the flash id in g_rom_flashchip(global esp_rom_spiflash_chip_t structure).
18  *
19  * @return None
20  */
21 void bootloader_flash_update_id(void);
22 
23 /**
24  * @brief Update the flash size in g_rom_flashchip (global esp_rom_spiflash_chip_t structure).
25  *
26  * @param size The size to store, in bytes.
27  * @return None
28  */
29 void bootloader_flash_update_size(uint32_t size);
30 
31 /**
32  * @brief Set the flash CS setup and hold time.
33  *
34  * @note CS setup time is recomemded to be 1.5T, and CS hold time is recommended to be 2.5T.
35  *       cs_setup = 1, cs_setup_time = 0; cs_hold = 1, cs_hold_time = 1.
36  *
37  * @return None
38  */
39 void bootloader_flash_cs_timing_config(void);
40 
41 /**
42  * @brief Configure SPI flash clock.
43  *
44  * @note This function only set clock frequency for SPI0.
45  *
46  * @param pfhdr Pointer to App image header, from where to fetch flash settings.
47  *
48  * @return None
49  */
50 void bootloader_flash_clock_config(const esp_image_header_t* pfhdr);
51 
52 /**
53  * @brief Configure SPI flash gpio, include the IO matrix and drive strength configuration.
54  *
55  * @param pfhdr Pointer to App image header, from where to fetch flash settings.
56  *
57  * @return None
58  */
59 void bootloader_flash_gpio_config(const esp_image_header_t* pfhdr);
60 
61 /**
62  * @brief Configure SPI flash read dummy based on different mode and frequency.
63  *
64  * @param pfhdr Pointer to App image header, from where to fetch flash settings.
65  *
66  * @return None
67  */
68 void bootloader_flash_dummy_config(const esp_image_header_t* pfhdr);
69 
70 #ifdef CONFIG_IDF_TARGET_ESP32
71 /**
72  * @brief Return the pin number used for custom SPI flash and/or SPIRAM WP pin
73  *
74  * Can be determined by eFuse values in most cases, or overriden in configuration
75  *
76  * This value is only meaningful if the other SPI flash pins are overriden via eFuse.
77  *
78  * This value is only meaningful if flash is set to QIO or QOUT mode, or if
79  * SPIRAM is enabled.
80  *
81  * @return Pin number to use, or -1 if the default should be kept
82  */
83 int bootloader_flash_get_wp_pin(void);
84 #endif
85 
86 #ifdef __cplusplus
87 }
88 #endif
89