2022-10-27 06:55:07 -04:00
| Supported Targets | ESP32 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- |
2022-05-20 05:50:08 -04:00
2018-11-15 16:02:34 -05:00
# OTA Tool Example
2020-06-16 07:01:44 -04:00
This example demonstrates common operations the OTA tool [otatool.py ](../../../../components/app_update/otatool.py ) allows the user to perform:
2018-11-15 16:02:34 -05:00
- reading, writing and erasing OTA partitions,
- switching boot partitions, and
- switching to factory partition.
2019-05-26 23:10:00 -04:00
Users taking a look at this example should focus on the contents of the Python script [otatool_example.py ](otatool_example.py ) or shell script [otatool_example.sh ](otatool_example.sh ). The scripts contain
programmatic invocation of the tool's functions via the Python API and command-line interface, respectively. Note
that on Windows, the shell script example requires a POSIX-compatible environment via MSYS2/Git Bash/WSL etc.
2018-11-15 16:02:34 -05:00
The built application in this example outputs the currently running partition, whose output is used to verify if the tool switched OTA
partitions succesfully. The built application binary is written to all OTA partitions at the start of the example to be able to determine the running
partition for all switches performed.
## How to use example
### Build and Flash
2019-05-26 23:10:00 -04:00
Before running either of the example scripts, it is necessary to build and flash the firmware using the usual means:
2018-11-15 16:02:34 -05:00
2019-05-26 23:10:00 -04:00
```bash
2018-11-15 16:02:34 -05:00
idf.py build flash
```
### Running [otatool_example.py](otatool_example.py)
2019-05-26 23:10:00 -04:00
The example can be executed by running the script [otatool_example.py ](otatool_example.py ) or [otatool_example.sh ](otatool_example.sh ).
2018-11-15 16:02:34 -05:00
2019-05-26 23:10:00 -04:00
Python script:
2018-11-15 16:02:34 -05:00
```bash
2019-05-26 23:10:00 -04:00
python otatool_example.py
2018-11-15 16:02:34 -05:00
```
2019-05-26 23:10:00 -04:00
Shell script:
```
./otatool_example.sh
2018-11-15 16:02:34 -05:00
```
2020-06-16 07:01:44 -04:00
The script searches for valid target devices connected to the host and performs the operations on the first one it finds. This could present problems if there
2019-05-26 23:10:00 -04:00
are multiple viable target devices attached to the host. To perform the operations on a specific device, specify the port it is attached to during script invocation ("/dev/ttyUSB2" for example):
2018-11-15 16:02:34 -05:00
2019-05-26 23:10:00 -04:00
Python script:
2018-11-15 16:02:34 -05:00
```bash
python otatool_example.py --port /dev/ttyUSB2
```
2019-05-26 23:10:00 -04:00
Shell script:
```
./otatool_example.sh /dev/ttyUSB2
```
2018-11-15 16:02:34 -05:00
## Example output
Running the script produces the following output:
```
Writing factory firmware to ota_0
Writing factory firmware to ota_1
2019-05-26 23:10:00 -04:00
Switching to factory app
Switching to OTA slot 0
Switching to OTA slot 1 (twice in a row)
Switching to OTA slot 0 (twice in a row)
Switching to factory app
Switching to OTA slot 1
Partition tool operations performed successfully
2018-11-15 16:02:34 -05:00
```