mirror of
https://github.com/espressif/esptool.git
synced 2025-10-20 13:23:38 +08:00
feat(esp32-s3): Support >16MB quad flash chips
Adds support for the W25Q256 and GD25Q256 flash chips. Closes https://github.com/espressif/esptool/issues/883
This commit is contained in:

committed by
Radim Karniš

parent
cb5e850934
commit
67a91cbfef
@@ -291,10 +291,19 @@ target_esp32s3:
|
||||
script:
|
||||
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32S3 --chip esp32s3 --baud 115200
|
||||
|
||||
target_esp32s3_32MB:
|
||||
target_esp32s3_32MB_octal:
|
||||
extends: .target_esptool_test
|
||||
tags:
|
||||
- esptool_esp32s3_32MB_target
|
||||
- esptool_esp32s3_32MB_octal_target
|
||||
variables:
|
||||
ESPTOOL_TEST_FLASH_SIZE: "32"
|
||||
script:
|
||||
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32S3_32MB --chip esp32s3 --baud 115200
|
||||
|
||||
target_esp32s3_32MB_quad:
|
||||
extends: .target_esptool_test
|
||||
tags:
|
||||
- esptool_esp32s3_32MB_quad_target
|
||||
variables:
|
||||
ESPTOOL_TEST_FLASH_SIZE: "32"
|
||||
script:
|
||||
|
@@ -834,7 +834,11 @@ def main(argv=None, esp=None):
|
||||
if flash_size is not None: # Secure download mode
|
||||
esp.flash_set_parameters(flash_size_bytes(flash_size))
|
||||
# Check if stub supports chosen flash size
|
||||
if esp.IS_STUB and flash_size in ("32MB", "64MB", "128MB"):
|
||||
if (
|
||||
esp.IS_STUB
|
||||
and esp.CHIP_NAME != "ESP32-S3"
|
||||
and flash_size_bytes(flash_size) > 16 * 1024 * 1024
|
||||
):
|
||||
print(
|
||||
"WARNING: Flasher stub doesn't fully support flash size larger "
|
||||
"than 16MB, in case of failure use --no-stub."
|
||||
@@ -858,7 +862,7 @@ def main(argv=None, esp=None):
|
||||
args.size = flash_size_bytes(size_str)
|
||||
|
||||
if esp.IS_STUB and hasattr(args, "address") and hasattr(args, "size"):
|
||||
if args.address + args.size > 0x1000000:
|
||||
if esp.CHIP_NAME != "ESP32-S3" and args.address + args.size > 0x1000000:
|
||||
print(
|
||||
"WARNING: Flasher stub doesn't fully support flash size larger "
|
||||
"than 16MB, in case of failure use --no-stub."
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -6,9 +6,8 @@
|
||||
* SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*/
|
||||
|
||||
#ifndef STUB_FLASHER_H_
|
||||
#define STUB_FLASHER_H_
|
||||
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Maximum write block size, used for various buffers. */
|
||||
@@ -22,8 +21,9 @@
|
||||
#define SECTORS_PER_BLOCK (FLASH_BLOCK_SIZE / FLASH_SECTOR_SIZE)
|
||||
|
||||
/* 32-bit addressing is supported only by ESP32S3 */
|
||||
#if defined(ESP32S3)
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
#define FLASH_MAX_SIZE 64*1024*1024
|
||||
extern bool large_flash_mode;
|
||||
#else
|
||||
#define FLASH_MAX_SIZE 16*1024*1024
|
||||
#endif
|
||||
@@ -108,5 +108,3 @@ typedef enum {
|
||||
|
||||
ESP_CMD_NOT_IMPLEMENTED = 0xFF,
|
||||
} esp_command_error;
|
||||
|
||||
#endif /* STUB_FLASHER_H_ */
|
||||
|
@@ -49,7 +49,7 @@ int handle_flash_erase(uint32_t addr, uint32_t len) {
|
||||
|
||||
while (len > 0 && (addr % FLASH_BLOCK_SIZE != 0)) {
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
if (large_flash_mode) {
|
||||
if (esp_rom_opiflash_erase_sector(addr / FLASH_SECTOR_SIZE) != 0) return 0x35;
|
||||
} else {
|
||||
if (SPIEraseSector(addr / FLASH_SECTOR_SIZE) != 0) return 0x35;
|
||||
@@ -63,7 +63,7 @@ int handle_flash_erase(uint32_t addr, uint32_t len) {
|
||||
|
||||
while (len > FLASH_BLOCK_SIZE) {
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
if (large_flash_mode) {
|
||||
if (esp_rom_opiflash_erase_block_64k(addr / FLASH_BLOCK_SIZE) != 0) return 0x36;
|
||||
} else {
|
||||
if (SPIEraseBlock(addr / FLASH_BLOCK_SIZE) != 0) return 0x36;
|
||||
@@ -77,7 +77,7 @@ int handle_flash_erase(uint32_t addr, uint32_t len) {
|
||||
|
||||
while (len > 0) {
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
if (large_flash_mode) {
|
||||
if (esp_rom_opiflash_erase_sector(addr / FLASH_SECTOR_SIZE) != 0) return 0x37;
|
||||
} else {
|
||||
if (SPIEraseSector(addr / FLASH_SECTOR_SIZE) != 0) return 0x37;
|
||||
@@ -112,7 +112,7 @@ void handle_flash_read(uint32_t addr, uint32_t len, uint32_t block_size,
|
||||
uint32_t n = len - num_sent;
|
||||
if (n > block_size) n = block_size;
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
if (large_flash_mode) {
|
||||
res = SPIRead4B(1, addr, buf, n);
|
||||
} else {
|
||||
res = SPIRead(addr, (uint32_t *)buf, n);
|
||||
@@ -152,7 +152,7 @@ int handle_flash_get_md5sum(uint32_t addr, uint32_t len) {
|
||||
n = FLASH_SECTOR_SIZE;
|
||||
}
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
if (large_flash_mode) {
|
||||
res = SPIRead4B(1, addr, buf, n);
|
||||
} else {
|
||||
res = SPIRead(addr, (uint32_t *)buf, n);
|
||||
|
@@ -123,6 +123,26 @@ static void disable_watchdogs()
|
||||
}
|
||||
#endif // WITH_USB_JTAG_SERIAL
|
||||
|
||||
#if ESP32S3 && !ESP32S3BETA2
|
||||
bool large_flash_mode = false;
|
||||
|
||||
bool flash_larger_than_16mb()
|
||||
{
|
||||
uint32_t flash_id;
|
||||
esp_rom_opiflash_exec_cmd(1, SPI_FLASH_FASTRD_MODE,
|
||||
CMD_RDID, 8,
|
||||
0, 0,
|
||||
0,
|
||||
NULL, 0,
|
||||
(uint8_t *)&flash_id, 24,
|
||||
ESP_ROM_OPIFLASH_SEL_CS0,
|
||||
false);
|
||||
|
||||
uint8_t flid_lowbyte = (flash_id >> 16) & 0xFF;
|
||||
return ((flid_lowbyte >= 0x19 && flid_lowbyte < 0x30) || (flid_lowbyte >= 0x39)); // See DETECTED_FLASH_SIZES in esptool
|
||||
}
|
||||
#endif // ESP32S3
|
||||
|
||||
static void stub_handle_rx_byte(char byte)
|
||||
{
|
||||
int16_t r = SLIP_recv_byte(byte, (slip_state_t *)&ub.state);
|
||||
@@ -490,9 +510,11 @@ void stub_main()
|
||||
spi_flash_attach(spiconfig, 0);
|
||||
#endif
|
||||
#if ESP32S3 && !ESP32S3BETA2
|
||||
// Initialize OPI flash driver only when flash is detected octal. Otherwise, we don't need to
|
||||
// initialize such a driver
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
large_flash_mode = ets_efuse_flash_octal_mode() || flash_larger_than_16mb();
|
||||
|
||||
// Initialize OPI flash driver only when flash is detected octal or quad larger than 16MB.
|
||||
// Otherwise, we don't need to initialize such a driver
|
||||
if (large_flash_mode) {
|
||||
static const esp_rom_opiflash_def_t flash_driver = OPIFLASH_DRIVER();
|
||||
esp_rom_opiflash_legacy_driver_init(&flash_driver);
|
||||
esp_rom_opiflash_wait_idle();
|
||||
|
@@ -214,7 +214,7 @@ esp_command_error handle_flash_begin(uint32_t total_size, uint32_t offset) {
|
||||
fs.last_error = ESP_OK;
|
||||
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
if (large_flash_mode) {
|
||||
esp_rom_opiflash_wait_idle();
|
||||
} else {
|
||||
if (SPIUnlock() != 0) {
|
||||
@@ -266,7 +266,7 @@ static void start_next_erase(void)
|
||||
spi_write_enable();
|
||||
spi_wait_ready();
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
if (large_flash_mode) {
|
||||
if (block_erase) {
|
||||
if (fs.next_erase_sector * FLASH_SECTOR_SIZE < (1 << 24)) {
|
||||
esp_rom_opiflash_wait_idle();
|
||||
@@ -354,7 +354,7 @@ void handle_flash_data(void *data_buf, uint32_t length) {
|
||||
|
||||
/* do the actual write */
|
||||
#if defined(ESP32S3) && !defined(ESP32S3BETA2)
|
||||
if (ets_efuse_flash_octal_mode()) {
|
||||
if (large_flash_mode){
|
||||
res = SPIWrite4B(1, fs.next_write, data_buf, length);
|
||||
} else {
|
||||
res = SPIWrite(fs.next_write, data_buf, length);
|
||||
|
Reference in New Issue
Block a user