Clean up MSP_STATUS for DJI O4 (#3107)
[ExpressLRS.git] / src / lib / SerialUpdate / stub_flasher.h
blob22ea680db6d7d3eae0041279171540657891c441
1 /*
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
7 */
9 #ifndef STUB_FLASHER_H_
10 #define STUB_FLASHER_H_
12 #include <stdint.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
27 #else
28 #define FLASH_MAX_SIZE 16*1024*1024
29 #endif
31 /* Full set of protocol commands */
32 typedef enum {
33 /* Commands supported by the ESP8266 & ESP32 bootloaders */
34 ESP_FLASH_BEGIN = 0x02,
35 ESP_FLASH_DATA = 0x03,
36 ESP_FLASH_END = 0x04,
37 ESP_MEM_BEGIN = 0x05,
38 ESP_MEM_END = 0x06,
39 ESP_MEM_DATA = 0x07,
40 ESP_SYNC = 0x08,
41 ESP_WRITE_REG = 0x09,
42 ESP_READ_REG = 0x0a,
44 /* Commands supported by the ESP32 bootloader */
45 ESP_SPI_SET_PARAMS = 0x0b,
46 ESP_PIN_READ = 0x0c, /* ??? */
47 ESP_SPI_ATTACH = 0x0d,
48 ESP_SPI_READ = 0x0e,
49 ESP_SET_BAUD = 0x0f,
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,
66 } esp_command;
68 /* Command request header */
69 typedef struct __attribute__((packed)) {
70 uint8_t zero;
71 uint8_t op; /* maps to esp_command enum */
72 uint16_t data_len;
73 int32_t checksum;
74 uint8_t data_buf[32]; /* actually variable length, determined by data_len */
75 } esp_command_req_t;
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)
87 bytes of status.
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;
94 /* Error codes */
95 typedef enum {
96 ESP_UPDATE_OK = 0,
98 ESP_BAD_MD5 = 0x63,
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,
112 } esp_command_error;
114 #endif /* STUB_FLASHER_H_ */