1 /*
2  * Copyright (c) 2016-2019 Espressif Systems (Shanghai) PTE LTD
3  * All rights reserved
4  *
5  * This file is part of the esptool.py binary flasher stub.
6  *
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
17  * Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /* Flasher command handlers, called from stub_flasher.c
21 
22    Commands related to writing flash are in stub_write_flash_xxx.
23 */
24 #pragma once
25 #include "stub_flasher.h"
26 #include "rom_functions.h"
27 #include <stdbool.h>
28 
29 int handle_flash_erase(uint32_t addr, uint32_t len);
30 
31 void handle_flash_read(uint32_t addr, uint32_t len, uint32_t block_size, uint32_t max_in_flight);
32 
33 int handle_flash_get_md5sum(uint32_t addr, uint32_t len);
34 
35 int handle_flash_read_chip_id();
36 
37 esp_command_error handle_spi_set_params(uint32_t *args, int *status);
38 
39 esp_command_error handle_spi_attach(uint32_t hspi_config_arg);
40 
41 esp_command_error handle_mem_begin(uint32_t size, uint32_t offset);
42 
43 esp_command_error handle_mem_data(void *data, uint32_t length);
44 
45 esp_command_error handle_mem_finish(void);
46 
47 typedef struct {
48     uint32_t addr;
49     uint32_t value;
50     uint32_t mask;
51     uint32_t delay_us;
52 } write_reg_args_t;
53 
54 esp_command_error handle_write_reg(const write_reg_args_t *cmd_buf, uint32_t num_commands);
55 
56 /* Enabling 32-bit flash memory addressing for ESP32S3 */
57 #if defined(ESP32S3)
58 esp_rom_spiflash_result_t SPIRead4B(int spi_num, SpiFlashRdMode mode, uint32_t flash_addr, uint8_t* buf, int len);
59 #endif // ESP32S3
60 
61 /* Get security info command only on ESP32S2 and later */
62 #if ESP32S2_OR_LATER && !ESP8684
63 esp_command_error handle_get_security_info(void);
64 #endif // ESP32S2_OR_LATER
65