@@ -203,18 +203,24 @@ static esp_loader_error_t spi_flash_command(spi_flash_cmd_t cmd, void *data_tx,
203203
204204static esp_loader_error_t detect_flash_size (size_t * flash_size )
205205{
206+ static const uint8_t size_ids [] = {0x12 , 0x13 , 0x14 , 0x15 , 0x16 , 0x17 , 0x18 , 0x19 ,
207+ 0x1A , 0x1B , 0x1C , 0x20 , 0x21 , 0x22 , 0x32 , 0x33 ,
208+ 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39 , 0x3A
209+ };
206210 uint32_t flash_id = 0 ;
207211
208212 RETURN_ON_ERROR ( spi_flash_command (SPI_FLASH_READ_ID , NULL , 0 , & flash_id , 24 ) );
209- uint32_t size_id = flash_id >> 16 ;
213+ uint8_t size_id = flash_id >> 16 ;
210214
211- if (size_id < 0x12 || size_id > 0x18 ) {
212- return ESP_LOADER_ERROR_UNSUPPORTED_CHIP ;
215+ // Try finding the size id within supported size ids
216+ for (size_t i = 0 ; i < sizeof (size_ids ) / sizeof (size_ids [0 ]); i ++ ) {
217+ if (size_id == size_ids [i ]) {
218+ * flash_size = 1 << size_id ;
219+ return ESP_LOADER_SUCCESS ;
220+ }
213221 }
214222
215- * flash_size = 1 << size_id ;
216-
217- return ESP_LOADER_SUCCESS ;
223+ return ESP_LOADER_ERROR_UNSUPPORTED_CHIP ;
218224}
219225
220226static uint32_t calc_erase_size (const target_chip_t target , const uint32_t offset ,
0 commit comments