|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | #include "sdkconfig.h" |
16 | | -#include "esp_attr.h" |
17 | | -#include "spi_flash.h" |
18 | | -#include "esp_log.h" |
19 | | -#include "esp_system.h" |
20 | | -#include "esp8266/eagle_soc.h" |
21 | | -#include "esp8266/rom_functions.h" |
22 | | -#include "esp_image_format.h" |
23 | | - |
24 | | -#define PERIPHS_SPI_FLASH_USRREG (0x60000200 + 0x1c) |
25 | | -#define PERIPHS_SPI_FLASH_CTRL (0x60000200 + 0x08) |
26 | | -#define PERIPHS_IO_MUX_CONF_U (0x60000800) |
27 | | - |
28 | | -#define SPI0_CLK_EQU_SYSCLK BIT8 |
29 | | -#define SPI_FLASH_CLK_EQU_SYSCLK BIT12 |
30 | 16 |
|
31 | | -static const char *TAG = "chip_boot"; |
| 17 | +#ifndef CONFIG_BOOTLOADER_INIT_SPI_FLASH |
| 18 | +#include "spi_flash.h" |
32 | 19 |
|
33 | 20 | /* |
34 | | - * @brief initialize the chip including flash I/O and chip cache according to |
35 | | - * boot parameters which are stored at the flash |
| 21 | + * @brief initialize the chip |
36 | 22 | */ |
37 | | -void chip_boot(size_t start_addr) |
| 23 | +void chip_boot(void) |
38 | 24 | { |
39 | | - int ret; |
40 | | - uint32_t freqdiv, flash_size; |
41 | | - uint32_t freqbits; |
42 | | - esp_image_header_t fhdr; |
43 | | - |
44 | | - uint32_t flash_map_table[FALSH_SIZE_MAP_MAX] = { |
45 | | - 1 * 1024 * 1024, |
46 | | - 2 * 1024 * 1024, |
47 | | - 4 * 1024 * 1024, |
48 | | - 8 * 1024 * 1024, |
49 | | - 16 * 1024 * 1024 |
50 | | - }; |
51 | | - uint32_t flash_map_table_size = sizeof(flash_map_table) / sizeof(flash_map_table[0]); |
52 | | - |
53 | | - extern esp_spi_flash_chip_t flashchip; |
54 | | - extern void phy_get_bb_evm(void); |
55 | | - extern void cache_init(uint8_t); |
56 | | - extern void user_spi_flash_dio_to_qio_pre_init(void); |
57 | | - |
58 | | - phy_get_bb_evm(); |
59 | | - |
60 | | - SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_USRREG, BIT5); |
61 | | - |
62 | | - ret = spi_flash_read(start_addr, &fhdr, sizeof(esp_image_header_t)); |
63 | | - if (ret) { |
64 | | - ESP_EARLY_LOGE(TAG, "SPI flash read result %d\n", ret); |
65 | | - } |
66 | | - |
67 | | - if (3 > fhdr.spi_speed) |
68 | | - freqdiv = fhdr.spi_speed + 2; |
69 | | - else if (0x0F == fhdr.spi_speed) |
70 | | - freqdiv = 1; |
71 | | - else |
72 | | - freqdiv = 2; |
73 | | - |
74 | | - if (fhdr.spi_size < flash_map_table_size) { |
75 | | - flash_size = flash_map_table[fhdr.spi_size]; |
76 | | - ESP_EARLY_LOGD(TAG, "SPI flash size is %d\n", flash_size); |
77 | | - } else { |
78 | | - flash_size = 0; |
79 | | - ESP_EARLY_LOGE(TAG, "SPI size error is %d\n", fhdr.spi_size); |
80 | | - } |
81 | | - flashchip.chip_size = flash_size; |
82 | | - |
83 | | - if (1 >= freqdiv) { |
84 | | - freqbits = SPI_FLASH_CLK_EQU_SYSCLK; |
85 | | - SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_CTRL, SPI_FLASH_CLK_EQU_SYSCLK); |
86 | | - SET_PERI_REG_MASK(PERIPHS_IO_MUX_CONF_U, SPI0_CLK_EQU_SYSCLK); |
87 | | - } else { |
88 | | - freqbits = ((freqdiv - 1) << 8) + ((freqdiv / 2 - 1) << 4) + (freqdiv - 1); |
89 | | - CLEAR_PERI_REG_MASK(PERIPHS_SPI_FLASH_CTRL, SPI_FLASH_CLK_EQU_SYSCLK); |
90 | | - CLEAR_PERI_REG_MASK(PERIPHS_IO_MUX_CONF_U, SPI0_CLK_EQU_SYSCLK); |
91 | | - } |
92 | | - SET_PERI_REG_BITS(PERIPHS_SPI_FLASH_CTRL, 0xfff, freqbits, 0); |
| 25 | + extern void esp_spi_flash_init(uint32_t spi_speed, uint32_t spi_mode); |
93 | 26 |
|
94 | | - if (fhdr.spi_mode == ESP_IMAGE_SPI_MODE_QIO) { |
95 | | - ESP_EARLY_LOGD(TAG, "SPI flash enable QIO mode\n"); |
96 | | - user_spi_flash_dio_to_qio_pre_init(); |
97 | | - } |
| 27 | + esp_spi_flash_init(CONFIG_SPI_FLASH_FREQ, CONFIG_SPI_FLASH_MODE); |
98 | 28 | } |
| 29 | +#endif /* CONFIG_BOOTLOADER_INIT_SPI_FLASH */ |
0 commit comments