|
7 | 7 | #include <stdint.h> |
8 | 8 | #include "esp_system.h" |
9 | 9 |
|
10 | | -// ESP flashing protocol commands. |
| 10 | +// ESP flashing protocol commands |
11 | 11 | typedef enum { |
12 | | - ET2_CMD_FLASH_BEGIN = 0x02, |
13 | | - ET2_CMD_FLASH_DATA = 0x03, |
14 | | - ET2_CMD_FLASH_END = 0x04, |
15 | | - ET2_CMD_MEM_BEGIN = 0x05, |
16 | | - ET2_CMD_MEM_END = 0x06, |
17 | | - ET2_CMD_MEM_DATA = 0x07, |
18 | | - ET2_CMD_SYNC = 0x08, |
19 | | - ET2_CMD_WRITE_REG = 0x09, |
20 | | - ET2_CMD_READ_REG = 0x0A, |
21 | | - // Supported by ESP32-S2 and later. |
22 | | - ET2_CMD_SEC_INFO = 0x14, |
23 | | - // Supported by stub only |
24 | | - ET2_CMD_ERASE_FLASH = 0xD0, |
25 | | - ET2_CMD_ERASE_REGION = 0xD1, |
26 | | - ET2_CMD_READ_FLASH = 0xD2, |
27 | | - ET2_CMD_RUN_USER_CODE = 0xD3, |
| 12 | + ET2_CMD_FLASH_BEGIN = 0x02, |
| 13 | + ET2_CMD_FLASH_DATA = 0x03, |
| 14 | + ET2_CMD_FLASH_END = 0x04, |
| 15 | + ET2_CMD_MEM_BEGIN = 0x05, |
| 16 | + ET2_CMD_MEM_END = 0x06, |
| 17 | + ET2_CMD_MEM_DATA = 0x07, |
| 18 | + ET2_CMD_SYNC = 0x08, |
| 19 | + ET2_CMD_WRITE_REG = 0x09, |
| 20 | + ET2_CMD_READ_REG = 0x0A, |
| 21 | + ET2_CMD_SPI_SET_PARAMS = 0x0B, |
| 22 | + ET2_CMD_SPI_ATTACH = 0x0D, |
| 23 | + ET2_CMD_READ_FLASH_SLOW = 0x0E, |
| 24 | + ET2_CMD_CHANGE_BAUDRATE = 0x0F, |
| 25 | + ET2_CMD_DEFL_BEGIN = 0x10, |
| 26 | + ET2_CMD_DEFL_DATA = 0x11, |
| 27 | + ET2_CMD_DEFL_END = 0x12, |
| 28 | + ET2_CMD_SPI_FLASH_MD5 = 0x13, |
| 29 | + ET2_CMD_SEC_INFO = 0x14, |
| 30 | + ET2_CMD_ERASE_FLASH = 0xD0, |
| 31 | + ET2_CMD_ERASE_REGION = 0xD1, |
| 32 | + ET2_CMD_READ_FLASH = 0xD2, |
| 33 | + ET2_CMD_RUN_USER_CODE = 0xD3, |
| 34 | + ET2_CMD_FLASH_ENCRYPT_DATA = 0xD4, |
28 | 35 | } et2_cmd_t; |
29 | 36 |
|
30 | | -// Set interface used to a UART. |
| 37 | +// Set interface used to a UART |
31 | 38 | esp_err_t et2_setif_uart(uart_port_t uart); |
32 | | -// Try to connect to and synchronize with the ESP32. |
| 39 | + |
| 40 | +// Try to connect to and synchronize with the ESP32 |
33 | 41 | esp_err_t et2_sync(); |
34 | | -// Detect an ESP32 and, if present, read its chip ID. |
35 | | -// If a pointer is NULL, the property is not read. |
| 42 | + |
| 43 | +// Detect an ESP32 and, if present, read its chip ID |
| 44 | +// If a pointer is NULL, the property is not read |
36 | 45 | esp_err_t et2_detect(uint32_t* chip_id); |
37 | | -// Upload and start a flasher stub. |
| 46 | + |
| 47 | +// Upload and start the flasher stub |
38 | 48 | esp_err_t et2_run_stub(); |
39 | 49 |
|
40 | | -// Write to a range of memory. |
| 50 | +// Write to a range of memory |
41 | 51 | esp_err_t et2_mem_write(uint32_t addr, void const* wdata, uint32_t len); |
42 | | -// Write to a range of FLASH. |
43 | | -esp_err_t et2_flash_write(uint32_t flash_off, void const* wdata, uint32_t len); |
44 | 52 |
|
45 | | -// Send MEM_BEGIN command to initiate memory writes. |
| 53 | +// Write application to RAM (sending end command restarts the target into the loaded application) |
46 | 54 | esp_err_t et2_cmd_mem_begin(uint32_t size, uint32_t blocks, uint32_t blocksize, uint32_t offset); |
47 | | -// Send MEM_DATA command to send memory write payload. |
48 | 55 | esp_err_t et2_cmd_mem_data(void const* data, uint32_t data_len, uint32_t seq); |
49 | | -// Send MEM_END command to restart into application. |
50 | 56 | esp_err_t et2_cmd_mem_end(uint32_t entrypoint); |
51 | | -// Send FLASH_BEGIN command to initiate memory writes. |
| 57 | + |
| 58 | +// Write uncompressed data to flash |
52 | 59 | esp_err_t et2_cmd_flash_begin(uint32_t size, uint32_t offset); |
53 | | -// Send FLASH_BLOCK command to send memory write payload. |
54 | 60 | esp_err_t et2_cmd_flash_data(const uint8_t* data, uint32_t data_len, uint32_t seq); |
55 | | -// Send FLASH_FINISH command to restart into application. |
56 | 61 | esp_err_t et2_cmd_flash_finish(bool reboot); |
57 | 62 |
|
| 63 | +// Write compressed data to flash |
| 64 | +esp_err_t et2_cmd_deflate_begin(uint32_t uncompressed_size, uint32_t compressed_size, uint32_t offset); |
| 65 | +esp_err_t et2_cmd_deflate_data(const uint8_t* data, uint32_t data_len, uint32_t seq); |
| 66 | +esp_err_t et2_cmd_deflate_finish(bool reboot); |
| 67 | + |
| 68 | +// Read a register |
58 | 69 | esp_err_t et2_cmd_read_reg(uint32_t address, uint32_t* out_value); |
| 70 | + |
| 71 | +// Read uncompressed data from flash |
59 | 72 | esp_err_t et2_cmd_read_flash(uint32_t offset, uint32_t length, uint8_t* out_data); |
60 | 73 |
|
61 | | -void et2_test(void); |
| 74 | +// Erase entire flash |
| 75 | +esp_err_t et2_cmd_erase_flash(void); |
| 76 | + |
| 77 | +// Erase a region of flash |
| 78 | +esp_err_t et2_cmd_erase_region(uint32_t offset, uint32_t length); |
0 commit comments