2 * SPDX-FileCopyrightText: 2016 Cesanta Software Limited
4 * SPDX-License-Identifier: GPL-2.0-or-later
6 * SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD
9 #ifndef STUB_FLASHER_H_
10 #define STUB_FLASHER_H_
14 /* Maximum write block size, used for various buffers. */
15 #define MAX_WRITE_BLOCK 0x1000
17 /* Flash geometry constants */
18 #define FLASH_SECTOR_SIZE 4096
19 #define FLASH_BLOCK_SIZE 65536
20 #define FLASH_PAGE_SIZE 256
21 #define FLASH_STATUS_MASK 0xFFFF
22 #define SECTORS_PER_BLOCK (FLASH_BLOCK_SIZE / FLASH_SECTOR_SIZE)
24 /* 32-bit addressing is supported only by ESP32S3 */
25 #if defined(PLATFORM_ESP32_S3)
26 #define FLASH_MAX_SIZE 64*1024*1024
28 #define FLASH_MAX_SIZE 16*1024*1024
31 /* Full set of protocol commands */
33 /* Commands supported by the ESP8266 & ESP32 bootloaders */
34 ESP_FLASH_BEGIN
= 0x02,
35 ESP_FLASH_DATA
= 0x03,
44 /* Commands supported by the ESP32 bootloader */
45 ESP_SPI_SET_PARAMS
= 0x0b,
46 ESP_PIN_READ
= 0x0c, /* ??? */
47 ESP_SPI_ATTACH
= 0x0d,
50 ESP_FLASH_DEFLATED_BEGIN
= 0x10,
51 ESP_FLASH_DEFLATED_DATA
= 0x11,
52 ESP_FLASH_DEFLATED_END
= 0x12,
53 ESP_FLASH_VERIFY_MD5
= 0x13,
55 /* Commands supported by the ESP32S2 and later bootloaders */
56 ESP_GET_SECURITY_INFO
= 0x14,
58 /* Stub-only commands */
59 ESP_ERASE_FLASH
= 0xD0,
60 ESP_ERASE_REGION
= 0xD1,
61 ESP_READ_FLASH
= 0xD2,
62 ESP_RUN_USER_CODE
= 0xD3,
64 /* Flash encryption debug mode supported command */
65 ESP_FLASH_ENCRYPT_DATA
= 0xD4,
68 /* Command request header */
69 typedef struct __attribute__((packed
)) {
71 uint8_t op
; /* maps to esp_command enum */
74 uint8_t data_buf
[32]; /* actually variable length, determined by data_len */
77 /* Command response header */
78 typedef struct __attribute__((packed
)) {
79 uint8_t resp
; /* should be '1' */
80 uint8_t op_ret
; /* Should match 'op' */
81 uint16_t len_ret
; /* Length of result data (can be ignored as SLIP framing helps) */
82 int32_t value
; /* 32-bit response used by some commands */
83 } esp_command_response_t
;
86 /* command response has some (optional) data after it, then 2 (or 4 on ESP32 ROM)
89 typedef struct __attribute__((packed
)) {
90 uint8_t error
; /* non-zero = failed */
91 uint8_t status
; /* status of a failure */
92 } esp_command_data_status_t
;
100 ESP_BAD_DATA_LEN
= 0xC0,
101 ESP_BAD_DATA_CHECKSUM
= 0xC1,
102 ESP_BAD_BLOCKSIZE
= 0xC2,
103 ESP_INVALID_COMMAND
= 0xC3,
104 ESP_FAILED_SPI_OP
= 0xC4,
105 ESP_FAILED_SPI_UNLOCK
= 0xC5,
106 ESP_NOT_IN_FLASH_MODE
= 0xC6,
107 ESP_INFLATE_ERROR
= 0xC7,
108 ESP_NOT_ENOUGH_DATA
= 0xC8,
109 ESP_TOO_MUCH_DATA
= 0xC9,
111 ESP_CMD_NOT_IMPLEMENTED
= 0xFF,
114 #endif /* STUB_FLASHER_H_ */